Skip to content

Commit

Permalink
优化dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Jul 9, 2018
1 parent 7994579 commit 56d075b
Show file tree
Hide file tree
Showing 20 changed files with 373 additions and 117 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,52 @@ Base是针对于Android开发封装好一些常用的基类,主要包括通用
<dependency>
<groupId>com.king.base</groupId>
<artifactId>base</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<type>pom</type>
</dependency>
//base-adapter
<dependency>
<groupId>com.king.base</groupId>
<artifactId>adapter</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<type>pom</type>
</dependency>
//base-util
<dependency>
<groupId>com.king.base</groupId>
<artifactId>util</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<type>pom</type>
</dependency>
```
### Gradle:
```gradle
//base
compile 'com.king.base:base:3.1.0'
compile 'com.king.base:base:3.1.1'
//base-adapter
compile 'com.king.base:adapter:1.1.1'
compile 'com.king.base:adapter:1.1.2'
//base-util
compile 'com.king.base:util:1.1.1'
compile 'com.king.base:util:1.1.2'
```
### Lvy:
```lvy
//base
<dependency org='com.king.base' name='base' rev='3.1.0'>
<dependency org='com.king.base' name='base' rev='3.1.1'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
//base-adapter
<dependency org='com.king.base' name='adapter' rev='1.1.1'>
<dependency org='com.king.base' name='adapter' rev='1.1.2'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
//base-util
<dependency org='com.king.base' name='util' rev='1.1.1'>
<dependency org='com.king.base' name='util' rev='1.1.2'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
```
Expand All @@ -87,7 +88,7 @@ allprojects {
```gradle
//base
provided 'com.android.support:appcompat-v7:25.3.+'
provided 'com.king.base:util:1.1.1'
provided 'com.king.base:util:1.1.2'
```

```gradle
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/king/base/app/FrameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;

import com.king.base.BaseInterface;
import com.king.base.ContentActivity;
import com.king.base.app.fragment.ListFragment;
import com.king.base.app.fragment.RecyclerFragment;
Expand All @@ -15,7 +14,7 @@ public class FrameActivity extends ContentActivity {

@Override
protected void switchFragment(Intent intent) {
int keyFragment = intent.getIntExtra(BaseInterface.KEY_FRAGMENT,0);
int keyFragment = intent.getIntExtra(com.king.base.Constants.KEY_FRAGMENT,0);
switch (keyFragment){
case Constants.FRAGMENT_LIST:
replaceFragment(ListFragment.newInstance());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/king/base/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void addListeners() {

private void startFrameActivity(int keyFragment){
Intent intent = new Intent(this,FrameActivity.class);
intent.putExtra(KEY_FRAGMENT,keyFragment);
intent.putExtra(com.king.base.Constants.KEY_FRAGMENT,keyFragment);
startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ public void onRefresh(SuperSwipeRefreshLayout.Direction direction) {
}
}
});

adapter.setOnItemClicklistener(new HolderRecyclerAdapter.OnItemClicklistener() {
adapter.setOnItemClickListener(new HolderRecyclerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View v, int position) {
showToast("position:" + position);
showToast("position:" + position);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion base-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ publish {
userOrg = 'jenly'//bintray.com用户名
groupId = 'com.king.base'//jcenter上的路径
artifactId = 'adapter'//项目名称
publishVersion = '1.1.1'//版本号
publishVersion = '1.1.2'//版本号
desc = 'BaseAdapter for Android'//描述
website = 'https://github.com/jenly1314/Base'//网站
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Jenly <a href="mailto:[email protected]">Jenly</a>
*
*/
public abstract class ViewHolderRecyclerAdapter<T, V> extends HolderRecyclerAdapter<T,ViewHolder> {
public abstract class ViewHolderRecyclerAdapter<T> extends HolderRecyclerAdapter<T,ViewHolder> {

public ViewHolderRecyclerAdapter(Context context, List<T> listData) {
super(context, listData);
Expand Down
2 changes: 1 addition & 1 deletion base-util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ publish {
userOrg = 'jenly'//bintray.com用户名
groupId = 'com.king.base'//jcenter上的路径
artifactId = 'util'//项目名称
publishVersion = '1.1.1'//版本号
publishVersion = '1.1.2'//版本号
desc = 'BaseUtil for Android'//描述
website = 'https://github.com/jenly1314/Base'//网站
}
6 changes: 3 additions & 3 deletions base-util/src/main/java/com/king/base/util/SystemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ public static void installApk(Context context,String path){
public static void installApk(Context context,File file){

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uriData = null;
String type = "application/vnd.android.package-archive";
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
uriData = FileProvider.getUriForFile(
context, context.getPackageName() + ".fileProvider", file);
}else{
Expand All @@ -291,7 +291,7 @@ public static void installApk(Context context,File file){
public static void uninstallApk(Context context,String packageName){

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uriData = Uri.parse("package:" + packageName);
intent.setData(uriData);
context.startActivity(intent);
Expand Down
118 changes: 118 additions & 0 deletions base-util/src/main/java/com/king/base/util/UriUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.king.base.util;

import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.annotation.RequiresApi;

/**
* @author Jenly <a href="mailto:[email protected]">Jenly</a>
*/
public class UriUtils {

/**
* 根据Uri获取图片的绝对路径
*
* @param context 上下文对象
* @param uri
* @return 如果Uri对应的图片存在, 那么返回该文件的绝对路径, 否则返回null
*/
public static String getPath(Context context, Uri uri) {
int sdkVersion = Build.VERSION.SDK_INT;
if (sdkVersion >= 19) { // api >= 19
return getRealPathFromUriAboveApi19(context, uri);
} else { // api < 19
return getRealPathFromUriBelowAPI19(context, uri);
}
}

/**
* 适配api19以下(不包括api19),根据uri获取图片的绝对路径
*
* @param context 上下文对象
* @param uri 图片的Uri
* @return 如果Uri对应的图片存在, 那么返回该图片的绝对路径, 否则返回null
*/
private static String getRealPathFromUriBelowAPI19(Context context, Uri uri) {
return getDataColumn(context, uri, null, null);
}

/**
* 适配api19及以上,根据uri获取图片的绝对路径
*
* @param context 上下文对象
* @param uri 图片的Uri
* @return 如果Uri对应的图片存在, 那么返回该图片的绝对路径, 否则返回null
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private static String getRealPathFromUriAboveApi19(Context context, Uri uri) {
String filePath = null;
if (DocumentsContract.isDocumentUri(context, uri)) {
// 如果是document类型的 uri, 则通过document id来进行处理
String documentId = DocumentsContract.getDocumentId(uri);
if (isMediaDocument(uri)) { // MediaProvider
// 使用':'分割
String id = documentId.split(":")[1];

String selection = MediaStore.Images.Media._ID + "=?";
String[] selectionArgs = {id};
filePath = getDataColumn(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection, selectionArgs);
} else if (isDownloadsDocument(uri)) { // DownloadsProvider
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId));
filePath = getDataColumn(context, contentUri, null, null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())){
// 如果是 content 类型的 Uri
filePath = getDataColumn(context, uri, null, null);
} else if ("file".equals(uri.getScheme())) {
// 如果是 file 类型的 Uri,直接获取图片对应的路径
filePath = uri.getPath();
}
return filePath;
}

/**
* 获取数据库表中的 _data 列,即返回Uri对应的文件路径
* @return
*/
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
String path = null;

String[] projection = new String[]{MediaStore.Images.Media.DATA};
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
path = cursor.getString(columnIndex);
}
} catch (Exception e) {
if (cursor != null) {
cursor.close();
}
}
return path;
}

/**
* @param uri the Uri to check
* @return Whether the Uri authority is MediaProvider
*/
private static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}

/**
* @param uri the Uri to check
* @return Whether the Uri authority is DownloadsProvider
*/
private static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}


}
2 changes: 1 addition & 1 deletion base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ publish {
userOrg = 'jenly'//bintray.com用户名
groupId = 'com.king.base'//jcenter上的路径
artifactId = 'base'//项目名称
publishVersion = '3.1.0'//版本号
publishVersion = '3.1.1'//版本号
desc = 'Base for Android'//描述
website = 'https://github.com/jenly1314/Base'//网站
}
Loading

0 comments on commit 56d075b

Please sign in to comment.