Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Jan 19, 2017
0 parents commit b025122
Show file tree
Hide file tree
Showing 116 changed files with 10,411 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
## http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project
## https://raw.githubusercontent.com/github/gitignore/master/Android.gitignore

gradle.properties

# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

# Eclipse project files
.classpath
.project
.metadata/

# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.

# Gradle files
.gradle/
.gradle
build/

#NDK
obj/


# Optional - for older project format, add this section to your gitignore file:
/*/out
/*/*/build
/*/*/production
*.iws
*.ipr
*~
*.swp


# Update: Since Android Studio 1.0, new projects are created with this gitignore file:
/local.properties
/.idea/workspace.xml
/.idea/libraries
/build


# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
.idea/workspace.xml
.idea/tasks.xml
.idea/datasources.xml
.idea/dataSources.ids

gradle/
gradlew
gradlew.bat
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.imnjh.imagepickersample"
minSdkVersion rootProject.ext.minSdk
targetSdkVersion rootProject.ext.targetSdk
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile project(':imagepicker')
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.facebook.fresco:fresco:0.10.0+'
compile 'com.facebook.fresco:imagepipeline-okhttp3:0.10.0+'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/niejunhong/Develop/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# 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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.imnjh.imagepicker;

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.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.imnjh.imagepicker", appContext.getPackageName());
}
}
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.imnjh.imagepickersample"
xmlns:android="http://schemas.android.com/apk/res/android">


<application
android:name=".app.PickerApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
102 changes: 102 additions & 0 deletions app/src/main/java/com/imnjh/imagepickersample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.imnjh.imagepickersample;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.TextView;

import com.imnjh.imagepicker.SImagePicker;
import com.imnjh.imagepicker.activity.PhotoPickerActivity;
import com.imnjh.imagepickersample.adapter.PickAdapter;
import com.imnjh.imagepickersample.cache.CacheManager;

public class MainActivity extends AppCompatActivity {

public static final String AVATAR_FILE_NAME = "avatar.png";
public static final int REQUEST_CODE_AVATAR = 100;
public static final int REQUEST_CODE_IMAGE = 101;

private Button pickHeadBtn;
private Button pickImageBtn;
private Button pickImageWithLimitBtn;
private GridView gridView;
private PickAdapter pickAdapter;
private TextView originalView;
private CheckBox showCamera;


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

private void initUI() {
pickAdapter = new PickAdapter(this);
gridView = (GridView) findViewById(R.id.image_grid);
gridView.setAdapter(pickAdapter);
showCamera = (CheckBox) findViewById(R.id.show_camera);
originalView = (TextView) findViewById(R.id.original);
pickHeadBtn = (Button) findViewById(R.id.pick_head_icon);
pickImageBtn = (Button) findViewById(R.id.pick_image);
pickImageWithLimitBtn = (Button) findViewById(R.id.pick_image_with_limit);
pickHeadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SImagePicker
.from(MainActivity.this)
.pickMode(SImagePicker.MODE_AVATAR)
.showCamera(showCamera.isChecked())
.cropFilePath(
CacheManager.getInstance().getImageInnerCache()
.getAbsolutePath(AVATAR_FILE_NAME))
.forResult(REQUEST_CODE_AVATAR);
}
});
pickImageBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SImagePicker
.from(MainActivity.this)
.maxCount(9)
.rowCount(3)
.showCamera(showCamera.isChecked())
.pickMode(SImagePicker.MODE_IMAGE)
.forResult(REQUEST_CODE_IMAGE);
}
});
pickImageWithLimitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SImagePicker
.from(MainActivity.this)
.maxCount(9)
.rowCount(3)
.pickMode(SImagePicker.MODE_IMAGE)
.fileInterceptor(new SingleFileLimitInterceptor())
.forResult(REQUEST_CODE_IMAGE);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
final ArrayList<String> pathList =
data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT_SELECTION);
final boolean original =
data.getBooleanExtra(PhotoPickerActivity.EXTRA_RESULT_ORIGINAL, false);
pickAdapter.setNewData(pathList);
originalView.setText("原图:" + original);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.imnjh.imagepickersample;

import android.graphics.Matrix;
import android.graphics.Rect;

import com.facebook.drawee.drawable.ScalingUtils;

/**
* Created on 6/6/16.
*
* @author yingyi.xu@rush.im (Yingyi Xu)
*/
public class ScaleTypeFillCenterInside extends ScalingUtils.AbstractScaleType {

public static final ScalingUtils.ScaleType INSTANCE = new ScaleTypeFillCenterInside();

@Override
public void getTransformImpl(
Matrix outTransform,
Rect parentRect,
int childWidth,
int childHeight,
float focusX,
float focusY,
float scaleX,
float scaleY) {
float scale = Math.min(scaleX, scaleY);
float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
outTransform.setScale(scale, scale);
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
}
Loading

0 comments on commit b025122

Please sign in to comment.