diff --git a/ImageZoomSample/.gitignore b/ImageZoomSample/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/ImageZoomSample/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/ImageZoomSample/.idea/gradle.xml b/ImageZoomSample/.idea/gradle.xml new file mode 100644 index 0000000..345c4c2 --- /dev/null +++ b/ImageZoomSample/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/ImageZoomSample/.idea/misc.xml b/ImageZoomSample/.idea/misc.xml new file mode 100644 index 0000000..3963879 --- /dev/null +++ b/ImageZoomSample/.idea/misc.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ImageZoomSample/.idea/modules.xml b/ImageZoomSample/.idea/modules.xml new file mode 100644 index 0000000..8fdad95 --- /dev/null +++ b/ImageZoomSample/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ImageZoomSample/.idea/runConfigurations.xml b/ImageZoomSample/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/ImageZoomSample/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/ImageZoomSample/app/.gitignore b/ImageZoomSample/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/ImageZoomSample/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/ImageZoomSample/app/build.gradle b/ImageZoomSample/app/build.gradle new file mode 100644 index 0000000..0338d10 --- /dev/null +++ b/ImageZoomSample/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "br.com.felix.imagezoomsample" + minSdkVersion 15 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + compile project(":imagezoom") +} diff --git a/ImageZoomSample/app/proguard-rules.pro b/ImageZoomSample/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/ImageZoomSample/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/ImageZoomSample/app/src/androidTest/java/br/com/felix/imagezoomsample/ExampleInstrumentedTest.java b/ImageZoomSample/app/src/androidTest/java/br/com/felix/imagezoomsample/ExampleInstrumentedTest.java new file mode 100644 index 0000000..67e1d0f --- /dev/null +++ b/ImageZoomSample/app/src/androidTest/java/br/com/felix/imagezoomsample/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package br.com.felix.imagezoomsample; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("br.com.felix.imagezoomsample", appContext.getPackageName()); + } +} diff --git a/ImageZoomSample/app/src/main/AndroidManifest.xml b/ImageZoomSample/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..bfb2072 --- /dev/null +++ b/ImageZoomSample/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ImageZoomSample/app/src/main/java/br/com/felix/imagezoomsample/MainActivity.java b/ImageZoomSample/app/src/main/java/br/com/felix/imagezoomsample/MainActivity.java new file mode 100644 index 0000000..ee01c00 --- /dev/null +++ b/ImageZoomSample/app/src/main/java/br/com/felix/imagezoomsample/MainActivity.java @@ -0,0 +1,175 @@ +package br.com.felix.imagezoomsample; + +import android.Manifest; +import android.app.Activity; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v4.content.FileProvider; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.Toast; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class MainActivity extends AppCompatActivity { + + private final int REQUEST_GALERY = 1010, REQUEST_CAMERA = 1020; + private String pictureImagePath = ""; + + private ImageView img1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + img1 = findViewById(R.id.img1); + + Button btnSelect = findViewById(R.id.btnSelect); + btnSelect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + selectImage(); + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + private void selectImage() { + final CharSequence[] items = { + "Camera", + "Gallery", + "Cancel" + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Select type"); + builder.setItems(items, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int item) { + switch (item) { + case 0: + verificarPermissaoCamera(); + break; + case 1: + verificarPermissaoGaleria(); + break; + case 2: + dialog.dismiss(); + break; + } + } + }); + builder.show(); + } + + private void verificarPermissaoCamera() { + int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA); + + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA); + } else { + cameraIntent(); + } + } + + private void verificarPermissaoGaleria() { + int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE); + + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_GALERY); + } else { + galleryIntent(); + } + } + + private void cameraIntent() { + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + String imageFileName = timeStamp + ".jpg"; + File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); + + pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName; + + File file = new File(pictureImagePath); + Uri outputFileUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", file); + + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); + startActivityForResult(intent, REQUEST_CAMERA); + } + + private void galleryIntent() { + Intent intent = new Intent(); + intent.setType("image/*"); + intent.setAction(Intent.ACTION_GET_CONTENT); + startActivityForResult(Intent.createChooser(intent, "Select File"), REQUEST_GALERY); + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + switch (requestCode) { + case REQUEST_CAMERA: + cameraIntent(); + break; + case REQUEST_GALERY: + galleryIntent(); + break; + } + } else { + Toast.makeText(getApplicationContext(), "Permission denied", Toast.LENGTH_LONG).show(); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == Activity.RESULT_OK) { + if (requestCode == REQUEST_GALERY) { + onSelectFromGalleryResult(data); + } else if (requestCode == REQUEST_CAMERA) { + onCaptureImageResult(data); + } + } + } + + private void onSelectFromGalleryResult(Intent data) { + if (data != null) { + try { + Bitmap bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData()); + salvarImagemLocal(bm); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private void onCaptureImageResult(Intent data) { + File imgFile = new File(pictureImagePath); + Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); + salvarImagemLocal(myBitmap); + } + + private void salvarImagemLocal(Bitmap thumbnail) { + img1.setImageBitmap(thumbnail); + } +} diff --git a/ImageZoomSample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/ImageZoomSample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/ImageZoomSample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/ImageZoomSample/app/src/main/res/drawable/hulk_hogan.png b/ImageZoomSample/app/src/main/res/drawable/hulk_hogan.png new file mode 100644 index 0000000..3f32c39 Binary files /dev/null and b/ImageZoomSample/app/src/main/res/drawable/hulk_hogan.png differ diff --git a/ImageZoomSample/app/src/main/res/drawable/ic_launcher_background.xml b/ImageZoomSample/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..01f0af0 --- /dev/null +++ b/ImageZoomSample/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ImageZoomSample/app/src/main/res/drawable/john_cena.png b/ImageZoomSample/app/src/main/res/drawable/john_cena.png new file mode 100644 index 0000000..47a712a Binary files /dev/null and b/ImageZoomSample/app/src/main/res/drawable/john_cena.png differ diff --git a/ImageZoomSample/app/src/main/res/drawable/rey_mysterio.png b/ImageZoomSample/app/src/main/res/drawable/rey_mysterio.png new file mode 100644 index 0000000..0b4b241 Binary files /dev/null and b/ImageZoomSample/app/src/main/res/drawable/rey_mysterio.png differ diff --git a/ImageZoomSample/app/src/main/res/drawable/the_rock.png b/ImageZoomSample/app/src/main/res/drawable/the_rock.png new file mode 100644 index 0000000..fd45ffc Binary files /dev/null and b/ImageZoomSample/app/src/main/res/drawable/the_rock.png differ diff --git a/ImageZoomSample/app/src/main/res/drawable/undertaker.png b/ImageZoomSample/app/src/main/res/drawable/undertaker.png new file mode 100644 index 0000000..e2f86ac Binary files /dev/null and b/ImageZoomSample/app/src/main/res/drawable/undertaker.png differ diff --git a/ImageZoomSample/app/src/main/res/layout/activity_main.xml b/ImageZoomSample/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..10585a3 --- /dev/null +++ b/ImageZoomSample/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,71 @@ + + + +