Skip to content

Commit 1672060

Browse files
authored
Select Image From Gallery
1 parent c58129a commit 1672060

34 files changed

+916
-0
lines changed

SelectImage/SelectImage.iml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="SelectImage" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="inheritedJdk" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>

SelectImage/app/app.iml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":app" />
7+
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.5.3" />
8+
<option name="LAST_KNOWN_AGP_VERSION" value="3.5.3" />
9+
</configuration>
10+
</facet>
11+
<facet type="android" name="Android">
12+
<configuration>
13+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
14+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
15+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
16+
<afterSyncTasks>
17+
<task>generateDebugSources</task>
18+
</afterSyncTasks>
19+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
20+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
21+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
22+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
23+
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
24+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
25+
</configuration>
26+
</facet>
27+
</component>
28+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
29+
<output url="file://$MODULE_DIR$/build/intermediates/javac/debug/classes" />
30+
<output-test url="file://$MODULE_DIR$/build/intermediates/javac/debugUnitTest/classes" />
31+
<exclude-output />
32+
<content url="file://$MODULE_DIR$">
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debug/out" isTestSource="false" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debug/compileDebugAidl/out" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debug/compileDebugRenderscript/out" isTestSource="false" generated="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" generated="true" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" generated="true" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugAndroidTest/out" isTestSource="true" generated="true" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debugAndroidTest/compileDebugAndroidTestAidl/out" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debugAndroidTest/compileDebugAndroidTestRenderscript/out" isTestSource="true" generated="true" />
43+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
44+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" generated="true" />
45+
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugUnitTest/out" isTestSource="true" generated="true" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
67+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
68+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
69+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
70+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
84+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
85+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
86+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
87+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
88+
<excludeFolder url="file://$MODULE_DIR$/build" />
89+
</content>
90+
<orderEntry type="jdk" jdkName="Android API 30 Platform" jdkType="Android SDK" />
91+
<orderEntry type="sourceFolder" forTests="false" />
92+
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.12@jar" level="project" />
93+
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-integration:1.3@jar" level="project" />
94+
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-library:1.3@jar" level="project" />
95+
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3@jar" level="project" />
96+
<orderEntry type="library" scope="TEST" name="Gradle: com.squareup:javawriter:2.1.1@jar" level="project" />
97+
<orderEntry type="library" scope="TEST" name="Gradle: javax.inject:javax.inject:1@jar" level="project" />
98+
<orderEntry type="library" scope="TEST" name="Gradle: com.google.code.findbugs:jsr305:2.0.1@jar" level="project" />
99+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.ext:junit:1.1.2@aar" level="project" />
100+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.espresso:espresso-core:3.3.0@aar" level="project" />
101+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:runner:1.3.0@aar" level="project" />
102+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:core:1.3.0@aar" level="project" />
103+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:monitor:1.3.0@aar" level="project" />
104+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.espresso:espresso-idling-resource:3.3.0@aar" level="project" />
105+
<orderEntry type="library" name="Gradle: androidx.collection:collection:1.1.0@jar" level="project" />
106+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.1.0@jar" level="project" />
107+
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.1.0@jar" level="project" />
108+
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.1.0@jar" level="project" />
109+
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout-solver:2.0.4@jar" level="project" />
110+
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout:2.0.4@aar" level="project" />
111+
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.2.0@aar" level="project" />
112+
<orderEntry type="library" name="Gradle: androidx.cursoradapter:cursoradapter:1.0.0@aar" level="project" />
113+
<orderEntry type="library" name="Gradle: androidx.fragment:fragment:1.1.0@aar" level="project" />
114+
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat-resources:1.2.0@aar" level="project" />
115+
<orderEntry type="library" name="Gradle: androidx.drawerlayout:drawerlayout:1.0.0@aar" level="project" />
116+
<orderEntry type="library" name="Gradle: androidx.viewpager:viewpager:1.0.0@aar" level="project" />
117+
<orderEntry type="library" name="Gradle: androidx.loader:loader:1.0.0@aar" level="project" />
118+
<orderEntry type="library" name="Gradle: androidx.activity:activity:1.0.0@aar" level="project" />
119+
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable-animated:1.1.0@aar" level="project" />
120+
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable:1.1.0@aar" level="project" />
121+
<orderEntry type="library" name="Gradle: androidx.customview:customview:1.0.0@aar" level="project" />
122+
<orderEntry type="library" name="Gradle: androidx.core:core:1.3.1@aar" level="project" />
123+
<orderEntry type="library" name="Gradle: androidx.versionedparcelable:versionedparcelable:1.1.0@aar" level="project" />
124+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.1.0@aar" level="project" />
125+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.1.0@aar" level="project" />
126+
<orderEntry type="library" name="Gradle: androidx.savedstate:savedstate:1.0.0@aar" level="project" />
127+
<orderEntry type="library" name="Gradle: androidx.interpolator:interpolator:1.0.0@aar" level="project" />
128+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata:2.0.0@aar" level="project" />
129+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata-core:2.0.0@aar" level="project" />
130+
<orderEntry type="library" name="Gradle: androidx.arch.core:core-runtime:2.0.0@aar" level="project" />
131+
</component>
132+
</module>

SelectImage/app/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 30
5+
buildToolsVersion "30.0.3"
6+
defaultConfig {
7+
applicationId "com.anni.selectimage"
8+
minSdkVersion 19
9+
targetSdkVersion 30
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
implementation fileTree(dir: 'libs', include: ['*.jar'])
24+
implementation 'androidx.appcompat:appcompat:1.2.0'
25+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
26+
testImplementation 'junit:junit:4.12'
27+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
28+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
29+
}

SelectImage/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.anni.selectimage;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
25+
assertEquals("com.anni.selectimage", appContext.getPackageName());
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.anni.selectimage">
4+
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".MainActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.anni.selectimage;
2+
3+
import androidx.annotation.Nullable;
4+
import androidx.appcompat.app.AppCompatActivity;
5+
6+
import android.content.ContentResolver;
7+
import android.content.Intent;
8+
import android.net.Uri;
9+
import android.os.Bundle;
10+
import android.view.View;
11+
import android.widget.Button;
12+
import android.widget.TextView;
13+
import android.widget.Toast;
14+
15+
import java.io.File;
16+
import java.text.CharacterIterator;
17+
import java.text.StringCharacterIterator;
18+
19+
public class MainActivity extends AppCompatActivity {
20+
21+
TextView select;
22+
Button selectimage;
23+
private static final int IMAGEPICK_GALLERY_REQUEST = 300;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_main);
29+
select=findViewById(R.id.selectit);
30+
selectimage=findViewById(R.id.selecti);
31+
selectimage.setOnClickListener(new View.OnClickListener() {
32+
@Override
33+
public void onClick(View v) {
34+
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
35+
galleryIntent.setType("image/*");
36+
startActivityForResult(galleryIntent, IMAGEPICK_GALLERY_REQUEST);
37+
}
38+
});
39+
}
40+
Uri imageuri;
41+
42+
@Override
43+
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
44+
super.onActivityResult(requestCode, resultCode, data);
45+
if(requestCode==IMAGEPICK_GALLERY_REQUEST){
46+
imageuri=data.getData(); Uri uri = data.getData();
47+
ContentResolver cr = this.getContentResolver();
48+
String mime = cr.getType(uri);
49+
File file = new File(mime);
50+
long length = file.length() / 1024;
51+
Toast.makeText(MainActivity.this,""+humanReadableByteCountSI(length),Toast.LENGTH_LONG).show();
52+
}
53+
54+
}
55+
public static String humanReadableByteCountSI(long bytes) {
56+
if (-1000 < bytes && bytes < 1000) {
57+
return bytes + " B";
58+
}
59+
CharacterIterator ci = new StringCharacterIterator("kMGTPE");
60+
while (bytes <= -999_950 || bytes >= 999_950) {
61+
bytes /= 1000;
62+
ci.next();
63+
}
64+
return String.format("%.1f %cB", bytes / 1000.0, ci.current());
65+
}
66+
67+
}

0 commit comments

Comments
 (0)