Skip to content

Commit

Permalink
see 04/21 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Apr 21, 2017
1 parent eab53cc commit 9468a64
Show file tree
Hide file tree
Showing 17 changed files with 2,220 additions and 1,714 deletions.
1,513 changes: 760 additions & 753 deletions README-CN.md

Large diffs are not rendered by default.

1,501 changes: 758 additions & 743 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ dependencies {
debugCompile "com.squareup.leakcanary:leakcanary-android:$LEAKCANARY_VERSION"
releaseCompile leakCanary
testCompile leakCanary
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,43 @@ public void updateDrawState(TextPaint ds) {
TextView tvAboutSpannable = (TextView) findViewById(R.id.tv_about_spannable);
// 响应点击事件的话必须设置以下属性
tvAboutSpannable.setMovementMethod(LinkMovementMethod.getInstance());
tvAboutSpannable.setText(SpannableStringUtils
.getBuilder("测试SpannableStringUtils\n")
.setBold().setForegroundColor(Color.YELLOW).setBackgroundColor(Color.GRAY).setAlign(Layout.Alignment.ALIGN_CENTER)
tvAboutSpannable.setText(new SpannableStringUtils.Builder()
.appendLine("测试SpannableStringUtils").setBold().setForegroundColor(Color.YELLOW).setBackgroundColor(Color.GRAY).setAlign(Layout.Alignment.ALIGN_CENTER)
.append("测试")
.append("前景色").setForegroundColor(Color.GREEN)
.append("背景色\n").setBackgroundColor(Color.RED)
.append("测试首行缩进\n").setLeadingMargin(30, 50)
.append("测试引用\n").setQuoteColor(Color.YELLOW)
.append("测试列表项\n").setBullet(30, Color.YELLOW)
.appendLine("背景色").setBackgroundColor(Color.RED)
.appendLine("测试首行缩进").setLeadingMargin(30, 50)
.appendLine("测试引用").setQuoteColor(Color.BLACK)
.appendLine("测试列表项").setBullet(30, Color.BLACK)
.appendLine("测试32dp字体").setFontSize(36, true)
.append("测试")
.append("2倍字体\n").setProportion(2)
.appendLine("2倍字体").setFontProportion(2)
.append("测试")
.append("横向2倍字体\n").setXProportion(2)
.appendLine("横向2倍字体").setFontXProportion(2)
.append("测试")
.append("删除线").setStrikethrough()
.append("下划线\n").setUnderline()
.appendLine("下划线").setUnderline()
.append("测试")
.append("上标").setSuperscript()
.append("下标\n").setSubscript()
.appendLine("下标").setSubscript()
.append("测试")
.append("粗体").setBold()
.append("斜体").setItalic()
.append("粗斜体\n").setBoldItalic()
.append("monospace font\n").setFontFamily("monospace")
.append("serif font\n").setFontFamily("serif")
.append("sans-serif font\n").setFontFamily("sans-serif")
.append("测试正常对齐\n").setAlign(Layout.Alignment.ALIGN_NORMAL)
.append("测试居中对齐\n").setAlign(Layout.Alignment.ALIGN_CENTER)
.append("测试相反对齐\n").setAlign(Layout.Alignment.ALIGN_OPPOSITE)
.appendLine("粗斜体").setBoldItalic()
.appendLine("monospace font").setFontFamily("monospace")
.appendLine("serif font").setFontFamily("serif")
.appendLine("sans-serif font").setFontFamily("sans-serif")
.appendLine("测试正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL)
.appendLine("测试居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER)
.appendLine("测试相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE)
.append("测试")
.append("图片\n").setResourceId(R.mipmap.ic_launcher)
.appendLine("图片").setResourceId(R.mipmap.ic_launcher)
.append("测试")
.append("点击事件\n").setClickSpan(clickableSpan)
.appendLine("点击事件").setClickSpan(clickableSpan)
.append("测试")
.append("Url\n").setUrl("https://github.com/Blankj/AndroidUtilCode")
.appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode")
.append("测试")
.append("模糊字体\n").setBlur(3, BlurMaskFilter.Blur.NORMAL)
.append("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL)
.create()
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<dimen name="spacing_16">16dp</dimen>
<dimen name="font_32">32sp</dimen>
<dimen name="font_26">26sp</dimen>
</resources>
7 changes: 4 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
</style>

<style name="TextStyle">
<item name="android:textSize">@dimen/font_32</item>
<item name="android:textSize">@dimen/font_26</item>
</style>

<style name="WideBtnStyle" parent="TextStyle">
<item name="android:textAllCaps" tools:targetApi="ice_cream_sandwich">false</item>
<style name="WideBtnStyle">
<item name="android:textAllCaps">false</item>
<item name="android:textSize">@dimen/font_26</item>
</style>
</resources>
3 changes: 2 additions & 1 deletion update_log.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* 17/04/21 发布Version1.4.0
* 17/04/20 SpannableStringUtils新增设置字体尺寸
* 17/03/29 修改README
* 17/03/28 新增BaseActivity
* 17/03/27 更新LogUtils
* 17/03/26 更新LogUtils
* 17/03/25 更新LogUtils
Expand Down
10 changes: 5 additions & 5 deletions utilcode/project.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#project
project.name=ALog
project.name=UtilCode
project.groupId=com.blankj
project.artifactId=alog
project.artifactId=utilcode
project.packaging=aar
project.siteUrl=https://github.com/Blankj/ALog
project.gitUrl=https://github.com/Blankj/ALog.git
project.siteUrl=https://github.com/Blankj/AndroidUtilCode
project.gitUrl=https://github.com/Blankj/AndroidUtilCode.git

#javadoc
javadoc.name=ALog
javadoc.name=UtilCode
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static void setColor(Activity activity, int color, int statusBarAlpha) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
decorView.getChildAt(0).setFitsSystemWindows(false);
int count = decorView.getChildCount();
if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
decorView.getChildAt(count - 1).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
Expand Down
138 changes: 138 additions & 0 deletions utilcode/src/main/java/com/blankj/utilcode/util/PermissionUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.blankj.utilcode.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import java.util.ArrayList;
import java.util.List;

/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2017/04/16
* desc : 权限相关工具类
* </pre>
*/
public final class PermissionUtils {

private static int mRequestCode = -1;

private static OnPermissionListener mOnPermissionListener;

public interface OnPermissionListener {

void onPermissionGranted();

void onPermissionDenied(String[] deniedPermissions);
}

public abstract static class RationaleHandler {
private Context context;
private int requestCode;
private String[] permissions;

protected abstract void showRationale();

void showRationale(Context context, int requestCode, String[] permissions) {
this.context = context;
this.requestCode = requestCode;
this.permissions = permissions;
showRationale();
}

@TargetApi(Build.VERSION_CODES.M)
public void requestPermissionsAgain() {
((Activity) context).requestPermissions(permissions, requestCode);
}
}

@TargetApi(Build.VERSION_CODES.M)
public static void requestPermissions(Context context, int requestCode
, String[] permissions, OnPermissionListener listener) {
requestPermissions(context, requestCode, permissions, listener, null);
}

@TargetApi(Build.VERSION_CODES.M)
public static void requestPermissions(Context context, int requestCode
, String[] permissions, OnPermissionListener listener, RationaleHandler handler) {
if (context instanceof Activity) {
mRequestCode = requestCode;
mOnPermissionListener = listener;
String[] deniedPermissions = getDeniedPermissions(context, permissions);
if (deniedPermissions.length > 0) {
boolean rationale = shouldShowRequestPermissionRationale(context, deniedPermissions);
if (rationale && handler != null) {
handler.showRationale(context, requestCode, deniedPermissions);
} else {
((Activity) context).requestPermissions(deniedPermissions, requestCode);
}
} else {
if (mOnPermissionListener != null)
mOnPermissionListener.onPermissionGranted();
}
} else {
throw new RuntimeException("Context must be an Activity");
}
}

/**
* 请求权限结果,对应Activity中onRequestPermissionsResult()方法。
*/
public static void onRequestPermissionsResult(Activity context, int requestCode, String[] permissions, int[]
grantResults) {
if (mRequestCode != -1 && requestCode == mRequestCode) {
if (mOnPermissionListener != null) {
String[] deniedPermissions = getDeniedPermissions(context, permissions);
if (deniedPermissions.length > 0) {
mOnPermissionListener.onPermissionDenied(deniedPermissions);
} else {
mOnPermissionListener.onPermissionGranted();
}
}
}
}

/**
* 获取请求权限中需要授权的权限
*/
private static String[] getDeniedPermissions(Context context, String[] permissions) {
List<String> deniedPermissions = new ArrayList<>();
for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_DENIED) {
deniedPermissions.add(permission);
}
}
return deniedPermissions.toArray(new String[deniedPermissions.size()]);
}

/**
* 是否彻底拒绝了某项权限
*/
public static boolean hasAlwaysDeniedPermission(Context context, String... deniedPermissions) {
for (String deniedPermission : deniedPermissions) {
if (!shouldShowRequestPermissionRationale(context, deniedPermission)) {
return true;
}
}
return false;
}

/**
* 是否有权限需要说明提示
*/
private static boolean shouldShowRequestPermissionRationale(Context context, String... deniedPermissions) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
boolean rationale;
for (String permission : deniedPermissions) {
rationale = ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission);
if (rationale) return true;
}
return false;
}
}
Loading

0 comments on commit 9468a64

Please sign in to comment.