Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edited MakePopUp, edited TakeCard #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Card/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Card/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.card">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
Expand All @@ -11,6 +15,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Card">
<activity
android:name=".TakeCardActivity"
android:exported="false"/>
<activity
android:name=".UpdateActivity"
android:exported="false" />
Expand Down Expand Up @@ -39,6 +46,19 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<provider
android:authorities="com.example.card"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />

</provider>

</application>

</manifest>
2 changes: 1 addition & 1 deletion Card/app/src/main/java/com/example/card/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
btn_make.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, MyCardActivity.class);
Intent intent = new Intent(MainActivity.this, MakePopUpActivity.class);
startActivity(intent);
}
});
Expand Down
86 changes: 82 additions & 4 deletions Card/app/src/main/java/com/example/card/MakePopUpActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
package com.example.card;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;

import com.gun0912.tedpermission.PermissionListener;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class MakePopUpActivity extends AppCompatActivity {
private Button btn_addInfo, btn_takeCard;
Uri providerURI;
String imageFilePath;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -29,13 +50,70 @@ public void onClick(View view) {
btn_takeCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MakePopUpActivity.this, TakeCardActivity.class);
startActivity(intent);
/*권한 설정 동의 안내
TedPermission.with(getApplicationContext())
.setPermissionListener(permissionListener)
.setRationaleMessage("카메라를 사용하기 위하여 접근 권한이 필요합니다.")
.setDeniedMessage("[설정] > [권한] 에서 권한을 허용할 수 있습니다.")
.setPermissions(Manifest.permission.CAMERA)
.check();*/
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {

}
if (photoFile != null) {
providerURI = FileProvider.getUriForFile(getApplicationContext(), getPackageName(), photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, providerURI);
launcher.launch(intent);
}
}
}
});
}

PermissionListener permissionListener = new PermissionListener() {
@Override
public void onPermissionGranted() {
//Toast.makeText(getApplicationContext(), "권한이 허용됨", Toast.LENGTH_SHORT).show();
}

}
@Override
public void onPermissionDenied(List<String> deniedPermissions) {
//Toast.makeText(getApplicationContext(), "권한이 거부됨", Toast.LENGTH_SHORT).show();
}
};

ActivityResultLauncher<Intent> launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>()
{
@Override
public void onActivityResult(ActivityResult result)
{
if (result.getResultCode() == RESULT_OK)
{
Intent intent = new Intent(MakePopUpActivity.this, TakeCardActivity.class);
intent.putExtra("str_uri", imageFilePath);
startActivity(intent);
}
}
});

private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);

File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
imageFilePath = image.getAbsolutePath();
return image;
}

}
}
147 changes: 146 additions & 1 deletion Card/app/src/main/java/com/example/card/TakeCardActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,151 @@
package com.example.card;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;

import com.gun0912.tedpermission.PermissionListener;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TakeCardActivity extends AppCompatActivity {
}
ImageView imgView;
Button btn_cancel;
Uri providerURI;
String imageFilePath;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_takecard);

imgView = findViewById(R.id.imgView);
btn_cancel = findViewById(R.id.btn_cancel);

Intent intent = getIntent();
imageFilePath = intent.getStringExtra("str_uri");

Bitmap bitmap = BitmapFactory.decodeFile(imageFilePath);
ExifInterface exif = null;

try {
exif = new ExifInterface(imageFilePath);
} catch (IOException e) {
e.printStackTrace();
}

int exifOrientation;
int exifDegree;

if (exif != null) {
exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
exifDegree = exifOrientationToDegrees(exifOrientation);
} else {
exifDegree = 0;
}
imgView.setImageBitmap(rotate(bitmap, exifDegree));

btn_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {

}
if (photoFile != null) {
providerURI = FileProvider.getUriForFile(getApplicationContext(), getPackageName(), photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, providerURI);
launcher.launch(intent);
}
}
}
});
}

ActivityResultLauncher<Intent> launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>()
{
@Override
public void onActivityResult(ActivityResult result)
{
if (result.getResultCode() == RESULT_OK)
{
Bitmap bitmap = BitmapFactory.decodeFile(imageFilePath);
ExifInterface exif = null;

try {
exif = new ExifInterface(imageFilePath);
} catch (IOException e) {
e.printStackTrace();
}

int exifOrientation;
int exifDegree;

if (exif != null) {
exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
exifDegree = exifOrientationToDegrees(exifOrientation);
} else {
exifDegree = 0;
}
imgView.setImageBitmap(rotate(bitmap, exifDegree));
}
}
});

private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);

File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
imageFilePath = image.getAbsolutePath();
return image;
}

private int exifOrientationToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}

private Bitmap rotate(Bitmap bitmap, float degree) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

}
36 changes: 36 additions & 0 deletions Card/app/src/main/res/layout/activity_takecard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TakeCardActivity">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgView"
android:src="@mipmap/ic_launcher"
android:layout_marginTop="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<Button
android:id="@+id/btn_ok"
android:layout_width="170dp"
android:layout_height="50dp"
android:layout_above="@+id/btn_cancel"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:text="명함으로 등록하기" />

<Button
android:id="@+id/btn_cancel"
android:layout_width="170dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:text="다시 찍기" />

</RelativeLayout>
19 changes: 19 additions & 0 deletions Card/app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path
name="cache"
path="." /> <!--Context.getCacheDir() 내부 저장소-->
<files-path
name="files"
path="." /> <!--Context.getFilesDir() 내부 저장소-->

<external-path
name="external"
path="."/> <!-- Environment.getExternalStorageDirectory() 외부 저장소-->
<external-cache-path
name="external-cache"
path="."/> <!-- Context.getExternalCacheDir() 외부 저장소-->
<external-files-path
name="external-files"
path="."/> <!-- Context.getExternalFilesDir() 외부 저장소-->
</paths>