Skip to content

Commit e97e82f

Browse files
author
jeanboy
committed
first commit.
0 parents  commit e97e82f

File tree

79 files changed

+6058
-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.

79 files changed

+6058
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gradle
2+
/.idea
3+
*.iml
4+
*.bat
5+
/local.properties
6+
.DS_Store
7+
/build
8+
/captures

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.3"
6+
7+
defaultConfig {
8+
applicationId "com.jeanboy.demo.compress"
9+
minSdkVersion 15
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:23.4.0'
26+
compile project(':lib-bither-compress')
27+
}

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 C:\Develop\Android\sdk/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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.jeanboy.demo.compress;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.jeanboy.demo.compress">
4+
5+
6+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
7+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
8+
9+
<application
10+
android:allowBackup="true"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<activity android:name=".MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.jeanboy.demo.compress;
2+
3+
import android.annotation.TargetApi;
4+
import android.app.Activity;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import android.graphics.Bitmap;
8+
import android.net.Uri;
9+
import android.os.Build;
10+
import android.os.Bundle;
11+
import android.provider.MediaStore;
12+
import android.support.v7.app.AppCompatActivity;
13+
import android.util.Log;
14+
import android.view.View;
15+
16+
import net.bither.util.NativeUtil;
17+
18+
import java.io.File;
19+
import java.io.IOException;
20+
21+
public class MainActivity extends AppCompatActivity {
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
setContentView(R.layout.activity_main);
27+
}
28+
29+
public static final int REQUEST_PICK_IMAGE = 10011;
30+
public static final int REQUEST_KITKAT_PICK_IMAGE = 10012;
31+
32+
public void pickFromGallery(View v) {
33+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
34+
startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"),
35+
REQUEST_PICK_IMAGE);
36+
} else {
37+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
38+
intent.addCategory(Intent.CATEGORY_OPENABLE);
39+
intent.setType("image/*");
40+
startActivityForResult(intent, REQUEST_KITKAT_PICK_IMAGE);
41+
}
42+
}
43+
44+
@Override
45+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
46+
super.onActivityResult(requestCode, resultCode, data);
47+
if (resultCode == Activity.RESULT_OK) {
48+
switch (requestCode) {
49+
50+
case REQUEST_PICK_IMAGE:
51+
if (data != null) {
52+
Uri uri = data.getData();
53+
compressImage(uri);
54+
} else {
55+
Log.e("======", "========图片为空======");
56+
}
57+
break;
58+
case REQUEST_KITKAT_PICK_IMAGE:
59+
if (data != null) {
60+
Uri uri = ensureUriPermission(this, data);
61+
compressImage(uri);
62+
} else {
63+
Log.e("======", "====-----==图片为空======");
64+
}
65+
break;
66+
}
67+
}
68+
}
69+
70+
@SuppressWarnings("ResourceType")
71+
@TargetApi(Build.VERSION_CODES.KITKAT)
72+
public static Uri ensureUriPermission(Context context, Intent intent) {
73+
Uri uri = intent.getData();
74+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
75+
final int takeFlags = intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
76+
context.getContentResolver().takePersistableUriPermission(uri, takeFlags);
77+
}
78+
return uri;
79+
}
80+
81+
82+
public void compressImage(Uri uri) {
83+
Log.e("===compressImage===", "====开始====uri==" + uri.getPath());
84+
try {
85+
File saveFile = new File(getExternalCacheDir(), "compress_final_" + System.currentTimeMillis() + ".jpg");
86+
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
87+
88+
Log.e("===compressImage===", "====开始==压缩==saveFile==" + saveFile.getAbsolutePath());
89+
NativeUtil.compressBitmap(bitmap, saveFile.getAbsolutePath());
90+
Log.e("===compressImage===", "====完成==压缩==saveFile==" + saveFile.getAbsolutePath());
91+
92+
} catch (IOException e) {
93+
e.printStackTrace();
94+
}
95+
96+
}
97+
}
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+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:paddingBottom="@dimen/activity_vertical_margin"
7+
android:paddingLeft="@dimen/activity_horizontal_margin"
8+
android:paddingRight="@dimen/activity_horizontal_margin"
9+
android:paddingTop="@dimen/activity_vertical_margin"
10+
tools:context="com.jeanboy.demo.compress.MainActivity">
11+
12+
<Button
13+
android:id="@+id/btn_from_gallery"
14+
style="@style/Widget.AppCompat.Button"
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:onClick="pickFromGallery"
18+
android:text="从相册选取" />
19+
</RelativeLayout>
3.34 KB
Loading
2.15 KB
Loading

0 commit comments

Comments
 (0)