Skip to content

Commit b025122

Browse files
author
martin
committed
init commit
0 parents  commit b025122

File tree

116 files changed

+10411
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+10411
-0
lines changed

.gitignore

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project
2+
## https://raw.githubusercontent.com/github/gitignore/master/Android.gitignore
3+
4+
gradle.properties
5+
6+
# Built application files
7+
*.apk
8+
*.ap_
9+
10+
# Files for the Dalvik VM
11+
*.dex
12+
13+
# Java class files
14+
*.class
15+
16+
# Generated files
17+
bin/
18+
gen/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Proguard folder generated by Eclipse
24+
proguard/
25+
26+
# Log Files
27+
*.log
28+
29+
# Android Studio Navigation editor temp files
30+
.navigation/
31+
32+
# Android Studio captures folder
33+
captures/
34+
35+
# Windows thumbnail db
36+
Thumbs.db
37+
38+
# OSX files
39+
.DS_Store
40+
41+
# Eclipse project files
42+
.classpath
43+
.project
44+
.metadata/
45+
46+
# Android Studio
47+
*.iml
48+
.idea
49+
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
50+
51+
# Gradle files
52+
.gradle/
53+
.gradle
54+
build/
55+
56+
#NDK
57+
obj/
58+
59+
60+
# Optional - for older project format, add this section to your gitignore file:
61+
/*/out
62+
/*/*/build
63+
/*/*/production
64+
*.iws
65+
*.ipr
66+
*~
67+
*.swp
68+
69+
70+
# Update: Since Android Studio 1.0, new projects are created with this gitignore file:
71+
/local.properties
72+
/.idea/workspace.xml
73+
/.idea/libraries
74+
/build
75+
76+
77+
# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
78+
.idea/workspace.xml
79+
.idea/tasks.xml
80+
.idea/datasources.xml
81+
.idea/dataSources.ids
82+
83+
gradle/
84+
gradlew
85+
gradlew.bat

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
6+
7+
defaultConfig {
8+
applicationId "com.imnjh.imagepickersample"
9+
minSdkVersion rootProject.ext.minSdk
10+
targetSdkVersion rootProject.ext.targetSdk
11+
versionCode 1
12+
versionName "1.0"
13+
ndk {
14+
abiFilters "armeabi"
15+
}
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
compile project(':imagepicker')
27+
compile 'com.github.bumptech.glide:glide:3.7.0'
28+
compile 'com.facebook.fresco:fresco:0.10.0+'
29+
compile 'com.facebook.fresco:imagepipeline-okhttp3:0.10.0+'
30+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/niejunhong/Develop/android-sdk-macosx/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.imnjh.imagepicker;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.imnjh.imagepicker", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.imnjh.imagepickersample"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
6+
<application
7+
android:name=".app.PickerApplication"
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
17+
<category android:name="android.intent.category.LAUNCHER"/>
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.imnjh.imagepickersample;
2+
3+
import java.util.ArrayList;
4+
5+
import android.app.Activity;
6+
import android.content.Intent;
7+
import android.os.Bundle;
8+
import android.support.v7.app.AppCompatActivity;
9+
import android.view.View;
10+
import android.widget.Button;
11+
import android.widget.CheckBox;
12+
import android.widget.GridView;
13+
import android.widget.TextView;
14+
15+
import com.imnjh.imagepicker.SImagePicker;
16+
import com.imnjh.imagepicker.activity.PhotoPickerActivity;
17+
import com.imnjh.imagepickersample.adapter.PickAdapter;
18+
import com.imnjh.imagepickersample.cache.CacheManager;
19+
20+
public class MainActivity extends AppCompatActivity {
21+
22+
public static final String AVATAR_FILE_NAME = "avatar.png";
23+
public static final int REQUEST_CODE_AVATAR = 100;
24+
public static final int REQUEST_CODE_IMAGE = 101;
25+
26+
private Button pickHeadBtn;
27+
private Button pickImageBtn;
28+
private Button pickImageWithLimitBtn;
29+
private GridView gridView;
30+
private PickAdapter pickAdapter;
31+
private TextView originalView;
32+
private CheckBox showCamera;
33+
34+
35+
@Override
36+
protected void onCreate(Bundle savedInstanceState) {
37+
super.onCreate(savedInstanceState);
38+
setContentView(R.layout.activity_main);
39+
initUI();
40+
}
41+
42+
private void initUI() {
43+
pickAdapter = new PickAdapter(this);
44+
gridView = (GridView) findViewById(R.id.image_grid);
45+
gridView.setAdapter(pickAdapter);
46+
showCamera = (CheckBox) findViewById(R.id.show_camera);
47+
originalView = (TextView) findViewById(R.id.original);
48+
pickHeadBtn = (Button) findViewById(R.id.pick_head_icon);
49+
pickImageBtn = (Button) findViewById(R.id.pick_image);
50+
pickImageWithLimitBtn = (Button) findViewById(R.id.pick_image_with_limit);
51+
pickHeadBtn.setOnClickListener(new View.OnClickListener() {
52+
@Override
53+
public void onClick(View view) {
54+
SImagePicker
55+
.from(MainActivity.this)
56+
.pickMode(SImagePicker.MODE_AVATAR)
57+
.showCamera(showCamera.isChecked())
58+
.cropFilePath(
59+
CacheManager.getInstance().getImageInnerCache()
60+
.getAbsolutePath(AVATAR_FILE_NAME))
61+
.forResult(REQUEST_CODE_AVATAR);
62+
}
63+
});
64+
pickImageBtn.setOnClickListener(new View.OnClickListener() {
65+
@Override
66+
public void onClick(View v) {
67+
SImagePicker
68+
.from(MainActivity.this)
69+
.maxCount(9)
70+
.rowCount(3)
71+
.showCamera(showCamera.isChecked())
72+
.pickMode(SImagePicker.MODE_IMAGE)
73+
.forResult(REQUEST_CODE_IMAGE);
74+
}
75+
});
76+
pickImageWithLimitBtn.setOnClickListener(new View.OnClickListener() {
77+
@Override
78+
public void onClick(View v) {
79+
SImagePicker
80+
.from(MainActivity.this)
81+
.maxCount(9)
82+
.rowCount(3)
83+
.pickMode(SImagePicker.MODE_IMAGE)
84+
.fileInterceptor(new SingleFileLimitInterceptor())
85+
.forResult(REQUEST_CODE_IMAGE);
86+
}
87+
});
88+
}
89+
90+
@Override
91+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
92+
super.onActivityResult(requestCode, resultCode, data);
93+
if (resultCode == Activity.RESULT_OK) {
94+
final ArrayList<String> pathList =
95+
data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT_SELECTION);
96+
final boolean original =
97+
data.getBooleanExtra(PhotoPickerActivity.EXTRA_RESULT_ORIGINAL, false);
98+
pickAdapter.setNewData(pathList);
99+
originalView.setText("原图:" + original);
100+
}
101+
}
102+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.imnjh.imagepickersample;
2+
3+
import android.graphics.Matrix;
4+
import android.graphics.Rect;
5+
6+
import com.facebook.drawee.drawable.ScalingUtils;
7+
8+
/**
9+
* Created on 6/6/16.
10+
*
11+
* @author yingyi.xu@rush.im (Yingyi Xu)
12+
*/
13+
public class ScaleTypeFillCenterInside extends ScalingUtils.AbstractScaleType {
14+
15+
public static final ScalingUtils.ScaleType INSTANCE = new ScaleTypeFillCenterInside();
16+
17+
@Override
18+
public void getTransformImpl(
19+
Matrix outTransform,
20+
Rect parentRect,
21+
int childWidth,
22+
int childHeight,
23+
float focusX,
24+
float focusY,
25+
float scaleX,
26+
float scaleY) {
27+
float scale = Math.min(scaleX, scaleY);
28+
float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
29+
float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
30+
outTransform.setScale(scale, scale);
31+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
32+
}
33+
}

0 commit comments

Comments
 (0)