Skip to content

Commit

Permalink
Everything is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
shpark0308 committed Mar 17, 2021
1 parent d1a4859 commit d31aacd
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 1,178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

Expand All @@ -28,21 +27,12 @@
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class LoginActivity extends AppCompatActivity {

// 구글로그인 result 상수
private static final int RC_SIGN_IN = 900;
// 구글api클라이언트
private GoogleSignInClient googleSignInClient;
// 파이어베이스 인증 객체 생성
private FirebaseAuth firebaseAuth;
// 구글 로그인 버튼
private SignInButton buttonGoogle;


Expand All @@ -53,13 +43,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

// 파이어베이스 인증 객체 선언
firebaseAuth = FirebaseAuth.getInstance();

buttonGoogle = findViewById(R.id.sign_in_btn);

// Google 로그인을 앱에 통합
// GoogleSignInOptions 개체를 구성할 때 requestIdToken을 호출
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken( "841121443421-acfgdidgg607m9hkra1g4ergecg66pqk.apps.googleusercontent.com")
.requestEmail()
Expand All @@ -80,22 +67,16 @@ public void onClick(View view) {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

// 구글로그인 버튼 응답
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// 구글 로그인 성공
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.d("sksksksksksk", "firebaseAuthWithGoogle:" + account.getId());
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
Log.w("라라라라라", "Google sign in failed", e);
}
}
}

// 사용자가 정상적으로 로그인한 후에 GoogleSignInAccount 개체에서 ID 토큰을 가져와서
// Firebase 사용자 인증 정보로 교환하고 Firebase 사용자 인증 정보를 사용해 Firebase에 인증합니다.
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
Expand All @@ -104,44 +85,31 @@ private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// 로그인 성공
Toast.makeText(LoginActivity.this, "성공", Toast.LENGTH_SHORT).show();

FirebaseUser currentUser = firebaseAuth.getCurrentUser();

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
// 이미 로그인한 적 있을 때
if (snapshot.hasChild("user/" + currentUser.getUid())) {
//User Exists , No Need To add new data.
//Get previous data from firebase. Take previous data as soon as possible..
Intent main = new Intent(getApplicationContext(), MainActivity.class);
startActivity(main);
}
// 처음 로그인 했을 때
else {
Intent nickname = new Intent(getApplicationContext(), NicknameActivity.class);
startActivity(nickname);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

} else {
// 로그인 실패
Toast.makeText(LoginActivity.this, "실패", Toast.LENGTH_SHORT).show();
}

}
});
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
import android.net.Uri;
import android.text.TextUtils;

/**
* 이미지 저장 후 미디어 스캐닝을 수행해줄 때 사용하는 유틸 클래스
*/

public class MediaScanner {
private Context mContext;
private static volatile MediaScanner mMediaInstance = null;
private MediaScannerConnection mMediaScanner;
//private MediaScannerConnection.MediaScannerConnectionClient mMediaScannerClient;

private String mFilePath;

public static MediaScanner getInstance( Context context ) {
Expand Down Expand Up @@ -42,12 +38,10 @@ private MediaScanner(Context context) {
mediaScanClient = new MediaScannerConnection.MediaScannerConnectionClient(){
@Override public void onMediaScannerConnected() {
mMediaScanner.scanFile(mFilePath, null);
// mFilePath = path;
}

@Override public void onScanCompleted(String path, Uri uri) {
System.out.println("::::MediaScan Success::::");

mMediaScanner.disconnect();
}
};
Expand All @@ -62,7 +56,5 @@ public void mediaScanning(final String path) {

if( !mMediaScanner.isConnected() )
mMediaScanner.connect();

//mMediaScanner.scanFile( path,null );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ protected void onCreate(Bundle savedInstanceState) {
EditText nickname = (EditText) findViewById(R.id.nickname);
ImageButton start = (ImageButton) findViewById(R.id.start_btn);

//라디오 그룹 설정
radioGroup = (RadioGroup) findViewById(R.id.selectProfile);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
import android.graphics.Matrix;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

//import com.example.amongearth_hackaton.customview.OverlayView;
import com.example.amongearth.env.ImageUtils;
import com.example.amongearth.env.Logger;
import com.example.amongearth.env.Utils;
Expand Down Expand Up @@ -54,22 +52,14 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_yolo);

// cameraButton = findViewById(R.id.cameraButton);
detectButton = findViewById(R.id.detectButton);
imageView = findViewById(R.id.imageView);
// Glide.with(this).load(R.raw.recycle).into(imageView);

// textView = findViewById(R.id.textView);
// cameraButton.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, DetectorActivity.class)));

detectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Handler handler = new Handler();

// 버튼 누르면 움직이게?
Glide.with(YoloActivity.this).load(R.raw.recycle).into(imageView);

final Comparator<Classifier.Recognition> cmpAsc = new Comparator<Classifier.Recognition>() {
@Override
public int compare(Classifier.Recognition rhs, Classifier.Recognition lhs) {
Expand All @@ -84,23 +74,14 @@ public void run() {
handler.post(new Runnable() {
@Override
public void run() {
// handleResult(cropBitmap, results);
Log.d("ResultLabel1", results.toString());
Collections.sort(results, cmpAsc); // Confidence 값 정렬
Collections.reverse(results); // 역순! Confidence 가장 큰 값이 가장 앞에 오도록!
// Log.d("ResultLabel2", results.get(0).getTitle()); // Label!! // 인식된게 하나도 없을 때 오류가 난다,,
// 인식된게 하나도 없을 때 nothing을 출력하도록 예외처리
Collections.sort(results, cmpAsc);
Collections.reverse(results);
String label = "";
try {
//textView.setText(results.get(0).getTitle());
label = results.get(0).getTitle();
// throw new Exception();
}catch(Exception e){
//textView.setText("nothing");
label = "nothing";
}
// textView.setText(results.get(0).getTitle());
// String label = results.get(0).getTitle();
switch (label) {
case "paper":
Intent intent0 = new Intent(getApplicationContext(), PaperActivity.class);
Expand Down Expand Up @@ -178,20 +159,9 @@ public void run() {
Intent intent = getIntent();
String imgPath = intent.getStringExtra("imgPath");

// Bundle b = intent.getExtras();
// this.sourceBitmap = (Bitmap)b.get("imgBitmap");

//Log.d("imgPath", imgPath);
// String imgPath="";

//this.sourceBitmap = Utils.getBitmapFromAsset(YoloActivity.this, imgPath);

this.sourceBitmap = BitmapFactory.decodeFile(imgPath);

this.cropBitmap = Utils.processBitmap(sourceBitmap, TF_OD_API_INPUT_SIZE);

/*this.imageView.setImageBitmap(cropBitmap); // 이미지 출력!*/

initBox();
}

Expand All @@ -205,7 +175,6 @@ public void run() {

private static final String TF_OD_API_LABELS_FILE = "file:///android_asset/custom.txt";

// Minimum detection confidence to track a detection.
private static final boolean MAINTAIN_ASPECT = false;
private Integer sensorOrientation = 90;

Expand All @@ -214,7 +183,6 @@ public void run() {
private Matrix frameToCropTransform;
private Matrix cropToFrameTransform;
private MultiBoxTracker tracker;
// private OverlayView trackingOverlay;

protected int previewWidth = 0;
protected int previewHeight = 0;
Expand All @@ -224,11 +192,10 @@ public void run() {

private Button detectButton;
private ImageView imageView;
//private TextView textView;

private void initBox() {
previewHeight = TF_OD_API_INPUT_SIZE; // 416
previewWidth = TF_OD_API_INPUT_SIZE; // 416
previewHeight = TF_OD_API_INPUT_SIZE;
previewWidth = TF_OD_API_INPUT_SIZE;
frameToCropTransform =
ImageUtils.getTransformationMatrix(
previewWidth, previewHeight,
Expand All @@ -239,18 +206,8 @@ private void initBox() {
frameToCropTransform.invert(cropToFrameTransform);

tracker = new MultiBoxTracker(this);
// trackingOverlay = findViewById(R.id.tracking_overlay);
// trackingOverlay.addCallback(
// new OverlayView.DrawCallback() {
// @Override
// public void drawCallback(Canvas canvas) {
// tracker.draw(canvas);
// }
// });

tracker.setFrameConfiguration(TF_OD_API_INPUT_SIZE, TF_OD_API_INPUT_SIZE, sensorOrientation);

// YoloV4 Classifier init
try {
detector =
YoloV4Classifier.create(
Expand All @@ -268,29 +225,4 @@ private void initBox() {
finish();
}
}

// private void handleResult(Bitmap bitmap, List<Classifier.Recognition> results) { // 이미지 빨간색 바운딩 박스!
// final Canvas canvas = new Canvas(bitmap);
// final Paint paint = new Paint();
// paint.setColor(Color.RED);
// paint.setStyle(Paint.Style.STROKE);
// paint.setStrokeWidth(2.0f);
//
// final List<Classifier.Recognition> mappedRecognitions =
// new LinkedList<Classifier.Recognition>();
//
// for (final Classifier.Recognition result : results) {
// final RectF location = result.getLocation();
// if (location != null && result.getConfidence() >= MINIMUM_CONFIDENCE_TF_OD_API) {
// canvas.drawRect(location, paint);
//// cropToFrameTransform.mapRect(location);
////
//// result.setLocation(location);
//// mappedRecognitions.add(result);
// }
// }
//// tracker.trackResults(mappedRecognitions, new Random().nextInt());
//// trackingOverlay.postInvalidate();
// imageView.setImageBitmap(bitmap);
// }
}
Loading

0 comments on commit d31aacd

Please sign in to comment.