-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.1" | ||
defaultConfig { | ||
applicationId "com.larry.demoluban" | ||
minSdkVersion 15 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.0.1' | ||
testCompile 'junit:junit:4.12' | ||
compile project(':luban') | ||
// compile 'com.github.AlbertLarry:LuBan:1.0' | ||
compile 'com.squareup.picasso:picasso:2.3.2' | ||
} |
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 D:\coder\as-2.2.3\as-sdk/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.larry.demoluban; | ||
|
||
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.larry.demoluban", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.larry.demoluban"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<application | ||
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.larry.demoluban; | ||
|
||
import android.content.ContentResolver; | ||
import android.content.Intent; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
|
||
import com.larry.luban.Luban; | ||
import com.larry.luban.OnCompressListener; | ||
import com.squareup.picasso.Picasso; | ||
|
||
import java.io.File; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private static final int OPEN_GALLERY_CODE = 0x001; | ||
private ImageView imageView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
imageView = (ImageView) findViewById(R.id.imageView); | ||
imageView.setOnClickListener(this); | ||
} | ||
|
||
/** | ||
* 打开相册 | ||
*/ | ||
public void openGallery() { | ||
// tempFile="a.jpeg"; | ||
Intent intent = new Intent(Intent.ACTION_PICK);// 打开相册 | ||
intent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*"); | ||
// intent.putExtra("output", Uri.fromFile(tempFile)); | ||
startActivityForResult(intent, OPEN_GALLERY_CODE); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
openGallery(); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
Log.i("way","origin size ="+getFileByUri(data.getData()).getUsableSpace()); | ||
Luban.get(this).load(getFileByUri(data.getData())).putGear(Luban.THIRD_GEAR) | ||
.setCompressListener(new OnCompressListener() { | ||
@Override | ||
public void onStart() { | ||
} | ||
|
||
@Override | ||
public void onSuccess(final File file) { | ||
Log.i("way","origin size ="+file.getUsableSpace()); | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
Picasso.with(MainActivity.this).load(file).into(imageView); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
Log.i("way", "error"); | ||
} | ||
}).launch(); | ||
} | ||
|
||
/** | ||
* 通过Uri返回File文件 | ||
* 注意:通过相机的是类似content://media/external/images/media/97596 | ||
* 通过相册选择的:file:///storage/sdcard0/DCIM/Camera/IMG_20150423_161955.jpg | ||
* 通过查询获取实际的地址 | ||
* | ||
* @param uri | ||
* @return | ||
*/ | ||
public File getFileByUri(Uri uri) { | ||
String path = null; | ||
if ("file".equals(uri.getScheme())) { | ||
path = uri.getEncodedPath(); | ||
if (path != null) { | ||
path = Uri.decode(path); | ||
ContentResolver cr = getContentResolver(); | ||
StringBuffer buff = new StringBuffer(); | ||
buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=").append("'" + path + "'").append(")"); | ||
Cursor cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA}, buff.toString(), null, null); | ||
int index = 0; | ||
int dataIdx = 0; | ||
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { | ||
index = cur.getColumnIndex(MediaStore.Images.ImageColumns._ID); | ||
index = cur.getInt(index); | ||
dataIdx = cur.getColumnIndex(MediaStore.Images.ImageColumns.DATA); | ||
path = cur.getString(dataIdx); | ||
} | ||
cur.close(); | ||
if (index == 0) { | ||
} else { | ||
Uri u = Uri.parse("content://media/external/images/media/" + index); | ||
System.out.println("temp uri is :" + u); | ||
} | ||
} | ||
if (path != null) { | ||
return new File(path); | ||
} | ||
} else if ("content".equals(uri.getScheme())) { | ||
// 4.2.2以后 | ||
String[] proj = {MediaStore.Images.Media.DATA}; | ||
Cursor cursor = getContentResolver().query(uri, proj, null, null, null); | ||
if (cursor.moveToFirst()) { | ||
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); | ||
path = cursor.getString(columnIndex); | ||
} | ||
cursor.close(); | ||
|
||
return new File(path); | ||
} else { | ||
Log.i("way", "Uri Scheme:" + uri.getScheme()); | ||
} | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/activity_main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="com.larry.demoluban.MainActivity"> | ||
|
||
<ImageView | ||
android:layout_width="match_parent" | ||
android:id="@+id/imageView" | ||
android:src="@mipmap/ic_launcher" | ||
android:layout_height="match_parent" /> | ||
</RelativeLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |