Skip to content

Commit

Permalink
botão voltar adicionado em ReceptFileActivity. E já é possível voltar…
Browse files Browse the repository at this point in the history
… da tela sem o modo escanear.
  • Loading branch information
AndreRamos7 committed Feb 7, 2021
1 parent 255a746 commit c353477
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.cropdox"
minSdkVersion 17
targetSdkVersion 29
versionCode 16
versionName "13.0.6"
versionCode 17
versionName "13.1"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/java/com/cropdox/CameraActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.widget.Toast;

import com.cropdox.model.FileInfo;
import com.cropdox.processamento.Utilidades;
import com.cropdox.remote.APIUtils;
import com.cropdox.remote.FileService;

Expand All @@ -34,9 +33,7 @@
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
Expand All @@ -47,9 +44,6 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.List;

import io.socket.client.IO;
import io.socket.client.Socket;
Expand Down Expand Up @@ -88,7 +82,7 @@ public class CameraActivity extends AppCompatActivity implements CameraBridgeVie

private Socket mSocket;
private boolean qr_ja_reconhecido;
private Emitter.Listener onNewMessage = new Emitter.Listener() {
/*private Emitter.Listener onNewMessage = new Emitter.Listener() {
@Override
public void call(final Object... args) {
runOnUiThread(new Runnable() {
Expand All @@ -98,7 +92,7 @@ public void run() {
}
});
}
};
};*/
private LinearLayout camera_controles;


Expand All @@ -115,7 +109,7 @@ public void run() {
}

public CameraActivity() {
mSocket.on("mensagem", onNewMessage);
//mSocket.on("mensagem", onNewMessage);
mSocket.connect();
}

Expand Down
67 changes: 48 additions & 19 deletions app/src/main/java/com/cropdox/ReceptFileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -54,7 +55,7 @@
import retrofit2.Callback;

public class ReceptFileActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2,
View.OnClickListener {
View.OnClickListener, View.OnTouchListener {
private ImageView imageView;
private Button btn_enviar;
private String currentPhotoPath;
Expand All @@ -71,7 +72,7 @@ public class ReceptFileActivity extends AppCompatActivity implements CameraBridg

private Socket mSocket;
private boolean qr_ja_reconhecido;

/*
private Emitter.Listener onNewMessage = new Emitter.Listener() {
@Override
public void call(final Object... args) {
Expand All @@ -82,10 +83,11 @@ public void run() {
}
});
}
};
};*/
private LinearLayout camera_controles;
private Bitmap bitmap;
private Button botao_enviar;
private Button close_button;

{
try {
Expand All @@ -100,7 +102,7 @@ public void run() {
}

public ReceptFileActivity() {
mSocket.on("mensagem", onNewMessage);
//mSocket.on("mensagem", onNewMessage);
mSocket.connect();
}

Expand All @@ -114,6 +116,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_recept_file);
imageView = (ImageView) findViewById(R.id.imageView_img_recebida);
botao_enviar = (Button) findViewById(R.id.botao_enviar);
close_button = (Button) findViewById(R.id.close_button);

// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
Expand Down Expand Up @@ -160,7 +163,10 @@ public void onManagerConnected(int status) {

imageView.animate().rotation(imageView.getRotation() - 90).start();
botao_enviar.animate().rotation(botao_enviar.getRotation() - 90).start();
close_button.animate().rotation(close_button.getRotation() - 90).start();
botao_enviar.setOnClickListener(this);
close_button.setOnClickListener(this);
close_button.setOnTouchListener(this);
}

@Override
Expand All @@ -169,18 +175,30 @@ public void onClick(View v) {
modo_QR = true;
botoa_enviado_clicado = true;
enviarImagem();
}else if(v.getId() == R.id.close_button){
finish();
}
}

@Override
public boolean onTouch(View view, MotionEvent event) {
if(view.getId() == R.id.close_button) {
if (event.getAction() == MotionEvent.ACTION_UP) {
view.setBackgroundResource(android.R.drawable.ic_menu_close_clear_cancel);
//clicado = false;
} else if (event.getAction() == MotionEvent.ACTION_DOWN) {
view.setBackgroundResource(android.R.drawable.ic_media_previous);
}
}
return false;
}
void handleSendImage(Intent intent) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
//MediaController mediaController = new MediaController(this.getApplication());
//String fileName = MediaController.fixFileName(MediaController.getFileName(imageUri));

//File photoUpload = new File(imageUri.getPath());
if (imageUri != null) {
//currentPhotoPath = photoUpload.getPath();

InputStream stream = null;
try {
stream = this.getContentResolver().openInputStream(imageUri);
Expand All @@ -203,8 +221,6 @@ void handleSendImage(Intent intent) {
}
}
}


try {
this.saveImage(bitmap);

Expand Down Expand Up @@ -243,23 +259,13 @@ public void onResponse(Call<FileInfo> call, retrofit2.Response<FileInfo> respons
@Override
public void onFailure(Call<FileInfo> call, Throwable t) {
Log.e(GENIAL_LOG, "Erro: " + t.getMessage());
//Toast.makeText(CameraActivity.this, "Erro: " + t.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(ReceptFileActivity.this, "Erro: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
}

@Override
protected void onResume() {
super.onResume();
if(!OpenCVLoader.initDebug()){
Toast.makeText(getApplicationContext(), "There's a problem, yo!", Toast.LENGTH_SHORT);
//OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_4_0, this, baseLoaderCallback);
}else{
baseLoaderCallback.onManagerConnected(baseLoaderCallback.SUCCESS);
}
}

@Override
public void onCameraViewStarted(int width, int height) {}
Expand Down Expand Up @@ -388,5 +394,28 @@ private void saveImage(Bitmap finalBitmap) throws IOException {
}
}

@Override
protected void onPause(){
super.onPause();
modo_QR = false;
botoa_enviado_clicado = false;
botao_enviar.setVisibility(View.VISIBLE);
if(cameraBridgeViewBase != null){
cameraBridgeViewBase.disableView();
}
}

@Override
protected void onResume(){
super.onResume();
botao_enviar.setVisibility(View.VISIBLE);
if(!OpenCVLoader.initDebug()){
Toast.makeText(getApplicationContext(), "There's a problem, yo!", Toast.LENGTH_SHORT);
//OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_4_0, this, baseLoaderCallback);
}else{
baseLoaderCallback.onManagerConnected(baseLoaderCallback.SUCCESS);
}
}


}
22 changes: 17 additions & 5 deletions app/src/main/res/layout/activity_recept_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,36 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/close_button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="56dp"
android:background="@android:drawable/ic_menu_close_clear_cancel"
android:clickable="true"
android:focusable="true"
android:selectAllOnFocus="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<ImageView
android:id="@+id/imageView_img_recebida"
android:layout_width="91dp"
android:layout_height="144dp"
android:layout_marginBottom="40dp"
android:layout_marginBottom="36dp"
android:contentDescription="@string/str_content_img_recebida"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/botao_enviar"
app:layout_constraintHorizontal_bias="0.488"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/close_button"
app:srcCompat="@drawable/icone512" />

<Button
android:id="@+id/botao_enviar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="56dp"
android:layout_marginBottom="92dp"
android:layout_marginEnd="36dp"
android:layout_marginBottom="96dp"
android:background="@drawable/botao_costumizado_iniciar"
android:text="@string/str_button_enviar"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down

0 comments on commit c353477

Please sign in to comment.