Skip to content

Commit

Permalink
重构调用方式,添加远程仓库依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
liqi committed Mar 16, 2017
1 parent bc6c81f commit 882a237
Show file tree
Hide file tree
Showing 20 changed files with 469 additions and 199 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//配置Jitpack插件
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

allprojects {
repositories {
jcenter()
//配置Jitpack插件
maven {url "https://jitpack.io" }
}
}

Expand Down
6 changes: 3 additions & 3 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
compileSdkVersion 24
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.liqi.photographutils"
minSdkVersion 10
targetSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand All @@ -22,6 +22,6 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:appcompat-v7:24.1.1'
compile project(':utils')
}
100 changes: 85 additions & 15 deletions demo/src/main/java/com/liqi/photographutils/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
package com.liqi.photographutils;

import android.Manifest;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.liql.photograph.PhotographDispose;
import com.liql.photograph.interfa.OnPhotographGetData;
import com.liql.photograph.PhotographStaticUtils;
import com.liql.photograph.interfa.OnDisposeOuterListener;
import com.liql.photograph.interfa.OnPhotographGetDataListener;
import com.liql.photograph.utils.ImageDispose;

import java.io.File;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnPhotographGetData<File> {
private final String FILE_PATH = "photograph/demo";
public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnPhotographGetDataListener<File> {
private final String COMPRESSPATH = "photograph/compresspath";
private final String IMAGEPATH = "photograph/imagepath";
private final long IMAGESIZE = 1024 * 1024;
private final int NEED_CAMERA = 200;
//图库和照相机处理操作对象暴露接口
private OnDisposeOuterListener mOnDisposeOuterListener;
private Button mButtonDepot, mButtonCamera;
private ImageView mImageView;
//图库和照相机处理对象
private PhotographDispose mPhotographDispose;
private ProgressDialog mDialog;
private int mTag = -1;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -32,31 +43,83 @@ protected void onCreate(Bundle savedInstanceState) {
mButtonCamera = (Button) findViewById(R.id.button_camera);
mButtonCamera.setOnClickListener(this);
mImageView = (ImageView) findViewById(R.id.imageView);
//获取照片处理对象
mPhotographDispose = new PhotographDispose(this, this);
//设置照片处理后存储在本地的路径
mPhotographDispose.setPath(FILE_PATH);
//设置照片压缩之后的大小,默认是1024*1024
mPhotographDispose.setImageSize(1024 * 1024);

mOnDisposeOuterListener = PhotographStaticUtils.getPhotographBuilder(this)
//设置图片压缩路径
.setCompressPath(COMPRESSPATH)
//设置照片暂时存路径
.setImagePath(IMAGEPATH)
//设置是否删除没有压缩的拍照照片(默认是拍一张删一张)
.setDelePGImage(false)
//设置处理好的图片路径接口
.setOnPhotographGetDataListener(this)
//设置图片压缩大小(默认是1M)
.setImageSize(IMAGESIZE)
//构建图库和照相机处理操作对象暴露接口(OnDisposeOuterListener)
.builder();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
showDialog("图片处理中...").show();
mPhotographDispose.onActivityResult(requestCode, data);
mOnDisposeOuterListener.onActivityResult(requestCode, data);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case NEED_CAMERA:
// 如果权限被拒绝,grantResults 为空
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
switch (mTag){
case 1:
mOnDisposeOuterListener.startPhoto();
break;
case 2:
mOnDisposeOuterListener.startCamera();
break;
}
} else {
Toast.makeText(this, "改功能需要相机和读写文件权限", Toast.LENGTH_SHORT).show();
}
break;
}
}

@Override
public void onClick(View v) {
switch (v.getId()) {
//打开图库
case R.id.button_depot:
mPhotographDispose.startPhoto();
mTag = 1;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//检测是否有相机和读写文件权限
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, NEED_CAMERA);
} else {
mOnDisposeOuterListener.startPhoto();
}
} else {
mOnDisposeOuterListener.startPhoto();
}
break;
//打开照相机
case R.id.button_camera:
mPhotographDispose.startCamera();
mTag = 2;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//检测是否有相机和读写文件权限
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.CAMERA}, NEED_CAMERA);
} else {
mOnDisposeOuterListener.startCamera();
}
} else {
mOnDisposeOuterListener.startCamera();
}
break;
}
}
Expand Down Expand Up @@ -92,4 +155,11 @@ protected void closeDialog() {
if (null != mDialog && mDialog.isShowing())
mDialog.dismiss();
}

@Override
protected void onDestroy() {
super.onDestroy();
//防止内存泄漏,请求在界面kill掉调用
mOnDisposeOuterListener.clear();
}
}
8 changes: 6 additions & 2 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@

<Button
android:id="@+id/button_depot"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal"
android:text="从图库选择照片"/>

<Button
android:id="@+id/button_camera"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="调用相机拍摄照片"/>
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
7 changes: 4 additions & 3 deletions utils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

android {
compileSdkVersion 23
compileSdkVersion 24
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 10
targetSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand All @@ -21,5 +22,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:appcompat-v7:24.1.1'
}
12 changes: 10 additions & 2 deletions utils/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">

<!--7.0需要的Uri权限提供-->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.liql.photograph.utils"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
</application>

</manifest>
14 changes: 7 additions & 7 deletions utils/src/main/java/com/liql/photograph/GalleryAddressTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
/**
*  "获取图库地址"工具类
*/
public class GalleryAddressTool {
class GalleryAddressTool {
/**
* 获取Android版本4.4版本以上的路径地址
*
* @param context
* @param uri
* @return
*/
public static String getPath(final Context context, final Uri uri) {
static String getPath(final Context context, final Uri uri) {

final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

Expand Down Expand Up @@ -102,7 +102,7 @@ else if ("file".equalsIgnoreCase(uri.getScheme())) {
* (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
public static String getDataColumn(Context context, Uri uri,
static String getDataColumn(Context context, Uri uri,
String selection, String[] selectionArgs) {

Cursor cursor = null;
Expand All @@ -128,7 +128,7 @@ public static String getDataColumn(Context context, Uri uri,
* The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
*/
public static boolean isExternalStorageDocument(Uri uri) {
static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri
.getAuthority());
}
Expand All @@ -138,7 +138,7 @@ public static boolean isExternalStorageDocument(Uri uri) {
* The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
public static boolean isDownloadsDocument(Uri uri) {
static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri
.getAuthority());
}
Expand All @@ -148,7 +148,7 @@ public static boolean isDownloadsDocument(Uri uri) {
* The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
public static boolean isMediaDocument(Uri uri) {
static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri
.getAuthority());
}
Expand All @@ -158,7 +158,7 @@ public static boolean isMediaDocument(Uri uri) {
* The Uri to check.
* @return Whether the Uri authority is Google Photos.
*/
public static boolean isGooglePhotosUri(Uri uri) {
static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri
.getAuthority());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import android.net.Uri;
import android.provider.MediaStore;

import com.liql.photograph.interfa.OnPhotoSDKDispose;
import com.liql.photograph.interfa.OnPhotographDispose;
import com.liql.photograph.interfa.OnPhotoSDKDisposeListener;
import com.liql.photograph.interfa.OnPhotographDisposeListener;

/**
* SDK低于19相册处理对象
Expand All @@ -15,14 +15,14 @@
*
* @param <T>
*/
public class PhotoSDKBottom<T> implements OnPhotoSDKDispose<T> {
private OnPhotographDispose<T> onPhotographDispose;
class PhotoSDKBottomListener<T> implements OnPhotoSDKDisposeListener<T> {
private OnPhotographDisposeListener<T> mOnPhotographDisposeListener;
private Activity activity;

PhotoSDKBottom(Activity activity,
OnPhotographDispose<T> onPhotographDispose) {
PhotoSDKBottomListener(Activity activity,
OnPhotographDisposeListener<T> onPhotographDisposeListener) {
this.activity = activity;
this.onPhotographDispose = onPhotographDispose;
this.mOnPhotographDisposeListener = onPhotographDisposeListener;
}

@Override
Expand All @@ -47,8 +47,8 @@ public T getPhotoData(Uri uri) {

String path = cursor.getString(column_index);
cursor.close();
if (null != onPhotographDispose) {
return onPhotographDispose.getPhotographDisposeData(path);
if (null != mOnPhotographDisposeListener) {
return mOnPhotographDisposeListener.getPhotographDisposeData(path);
}
return null;
} else
Expand Down
Loading

0 comments on commit 882a237

Please sign in to comment.