Skip to content

Commit 5cdc7f0

Browse files
committed
see 09/27 log
1 parent 6906ccd commit 5cdc7f0

34 files changed

+1427
-910
lines changed
Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
package com.blankj.utilcode.utils;
2-
3-
import android.content.Context;
4-
import android.content.Intent;
5-
import android.os.Bundle;
6-
7-
/**
8-
* <pre>
9-
* author: Blankj
10-
* blog : http://blankj.com
11-
* time : 2016/9/23
12-
* desc : Activity工具类
13-
* </pre>
14-
*/
15-
public class ActivityUtils {
16-
17-
private ActivityUtils() {
18-
throw new UnsupportedOperationException("u can't fuck me...");
19-
}
20-
21-
/**
22-
* 判断是否存在指定Activity
23-
*
24-
* @param context 上下文
25-
* @param packageName 包名
26-
* @param className activity全路径类名
27-
* @return {@code true}: 是<br>{@code false}: 否
28-
*/
29-
public static boolean isExistActivity(Context context, String packageName, String className) {
30-
Intent intent = new Intent();
31-
intent.setClassName(packageName, className);
32-
return !(context.getPackageManager().resolveActivity(intent, 0) == null ||
33-
intent.resolveActivity(context.getPackageManager()) == null ||
34-
context.getPackageManager().queryIntentActivities(intent, 0).size() == 0);
35-
}
36-
37-
/**
38-
* 打开指定的Activity
39-
*
40-
* @param context 上下文
41-
* @param packageName 包名
42-
* @param className 全类名
43-
*/
44-
public static void launchActivity(Context context, String packageName, String className) {
45-
launchActivity(context, packageName, className, null);
46-
}
47-
48-
/**
49-
* 打开指定的Activity
50-
*
51-
* @param context 上下文
52-
* @param packageName 包名
53-
* @param className 全类名
54-
* @param bundle bundle
55-
*/
56-
public static void launchActivity(Context context, String packageName, String className, Bundle bundle) {
57-
context.startActivity(IntentUtils.getComponentNameIntent(packageName, className, bundle));
58-
}
59-
}
1+
package com.blankj.utilcode.utils;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
7+
/**
8+
* <pre>
9+
* author: Blankj
10+
* blog : http://blankj.com
11+
* time : 2016/9/23
12+
* desc : Activity工具类
13+
* </pre>
14+
*/
15+
public class ActivityUtils {
16+
17+
private ActivityUtils() {
18+
throw new UnsupportedOperationException("u can't instantiate me...");
19+
}
20+
21+
/**
22+
* 判断是否存在指定Activity
23+
*
24+
* @param context 上下文
25+
* @param packageName 包名
26+
* @param className activity全路径类名
27+
* @return {@code true}: 是<br>{@code false}: 否
28+
*/
29+
public static boolean isExistActivity(Context context, String packageName, String className) {
30+
Intent intent = new Intent();
31+
intent.setClassName(packageName, className);
32+
return !(context.getPackageManager().resolveActivity(intent, 0) == null ||
33+
intent.resolveActivity(context.getPackageManager()) == null ||
34+
context.getPackageManager().queryIntentActivities(intent, 0).size() == 0);
35+
}
36+
37+
/**
38+
* 打开指定的Activity
39+
*
40+
* @param context 上下文
41+
* @param packageName 包名
42+
* @param className 全类名
43+
*/
44+
public static void launchActivity(Context context, String packageName, String className) {
45+
launchActivity(context, packageName, className, null);
46+
}
47+
48+
/**
49+
* 打开指定的Activity
50+
*
51+
* @param context 上下文
52+
* @param packageName 包名
53+
* @param className 全类名
54+
* @param bundle bundle
55+
*/
56+
public static void launchActivity(Context context, String packageName, String className, Bundle bundle) {
57+
context.startActivity(IntentUtils.getComponentIntent(packageName, className, bundle));
58+
}
59+
}
Lines changed: 140 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,140 @@
1-
package com.blankj.utilcode.utils;
2-
3-
import android.app.Activity;
4-
import android.content.Context;
5-
import android.os.Build;
6-
import android.util.TypedValue;
7-
import android.view.Window;
8-
import android.view.WindowManager;
9-
10-
import java.lang.reflect.Method;
11-
12-
/**
13-
* <pre>
14-
* author: Blankj
15-
* blog : http://blankj.com
16-
* time : 2016/9/23
17-
* desc : 栏相关工具类
18-
* </pre>
19-
*/
20-
public class BarUtils {
21-
private BarUtils() {
22-
throw new UnsupportedOperationException("u can't fuck me...");
23-
}
24-
25-
/**
26-
* 设置透明状态栏(api大于19方可使用)
27-
* <p>可在Activity的onCreat()中调用</p>
28-
* <p>需在顶部控件布局中加入以下属性让内容出现在状态栏之下</p>
29-
* <p>android:clipToPadding="true"</p>
30-
* <p>android:fitsSystemWindows="true"</p>
31-
*
32-
* @param activity activity
33-
*/
34-
public static void setTransparentStatusBar(Activity activity) {
35-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
36-
//透明状态栏
37-
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
38-
//透明导航栏
39-
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
40-
}
41-
}
42-
43-
/**
44-
* 隐藏状态栏
45-
* <p>也就是设置全屏,一定要在setContentView之前调用,否则报错</p>
46-
* <p>此方法Activity可以继承AppCompatActivity</p>
47-
* <p>启动的时候状态栏会显示一下再隐藏,比如QQ的欢迎界面</p>
48-
* <p>在配置文件中Activity加属性android:theme="@android:style/Theme.NoTitleBar.Fullscreen"</p>
49-
* <p>如加了以上配置Activity不能继承AppCompatActivity,会报错</p>
50-
*
51-
* @param activity activity
52-
*/
53-
public static void hideStatusBar(Activity activity) {
54-
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
55-
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
56-
WindowManager.LayoutParams.FLAG_FULLSCREEN);
57-
}
58-
59-
/**
60-
* 获取状态栏高度
61-
*
62-
* @param context 上下文
63-
* @return 状态栏高度
64-
*/
65-
public static int getStatusBarHeight(Context context) {
66-
int result = 0;
67-
int resourceId = context.getResources()
68-
.getIdentifier("status_bar_height", "dimen", "android");
69-
if (resourceId > 0) {
70-
result = context.getResources().getDimensionPixelSize(resourceId);
71-
}
72-
return result;
73-
}
74-
75-
/**
76-
* 判断状态栏是否存在
77-
*
78-
* @param activity activity
79-
* @return {@code true}: 存在<br>{@code false}: 不存在
80-
*/
81-
public static boolean isStatusBarExists(Activity activity) {
82-
WindowManager.LayoutParams params = activity.getWindow().getAttributes();
83-
return (params.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != WindowManager.LayoutParams.FLAG_FULLSCREEN;
84-
}
85-
86-
/**
87-
* 获取ActionBar高度
88-
*
89-
* @param activity activity
90-
* @return ActionBar高度
91-
*/
92-
public static int getActionBarHeight(Activity activity) {
93-
TypedValue tv = new TypedValue();
94-
if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
95-
return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
96-
}
97-
return 0;
98-
}
99-
100-
/**
101-
* 显示通知栏
102-
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
103-
*
104-
* @param context 上下文
105-
* @param isSettingPanel {@code true}: 打开设置<br>{@code false}: 打开通知
106-
*/
107-
public static void showNotificationBar(Context context, boolean isSettingPanel) {
108-
String methodName = (Build.VERSION.SDK_INT <= 16) ? "expand"
109-
: (isSettingPanel ? "expandSettingsPanel" : "expandNotificationsPanel");
110-
invokePanels(context, methodName);
111-
}
112-
113-
/**
114-
* 隐藏通知栏
115-
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
116-
*
117-
* @param context 上下文
118-
*/
119-
public static void hideNotificationBar(Context context) {
120-
String methodName = (Build.VERSION.SDK_INT <= 16) ? "collapse" : "collapsePanels";
121-
invokePanels(context, methodName);
122-
}
123-
124-
/**
125-
* 反射唤醒通知栏
126-
*
127-
* @param context 上下文
128-
* @param methodName 方法名
129-
*/
130-
private static void invokePanels(Context context, String methodName) {
131-
try {
132-
Object service = context.getSystemService("statusbar");
133-
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
134-
Method expand = statusBarManager.getMethod(methodName);
135-
expand.invoke(service);
136-
} catch (Exception e) {
137-
e.printStackTrace();
138-
}
139-
}
140-
}
1+
package com.blankj.utilcode.utils;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.os.Build;
6+
import android.util.TypedValue;
7+
import android.view.Window;
8+
import android.view.WindowManager;
9+
10+
import java.lang.reflect.Method;
11+
12+
/**
13+
* <pre>
14+
* author: Blankj
15+
* blog : http://blankj.com
16+
* time : 2016/9/23
17+
* desc : 栏相关工具类
18+
* </pre>
19+
*/
20+
public class BarUtils {
21+
private BarUtils() {
22+
throw new UnsupportedOperationException("u can't instantiate me...");
23+
}
24+
25+
/**
26+
* 设置透明状态栏(api大于19方可使用)
27+
* <p>可在Activity的onCreat()中调用</p>
28+
* <p>需在顶部控件布局中加入以下属性让内容出现在状态栏之下</p>
29+
* <p>android:clipToPadding="true"</p>
30+
* <p>android:fitsSystemWindows="true"</p>
31+
*
32+
* @param activity activity
33+
*/
34+
public static void setTransparentStatusBar(Activity activity) {
35+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
36+
//透明状态栏
37+
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
38+
//透明导航栏
39+
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
40+
}
41+
}
42+
43+
/**
44+
* 隐藏状态栏
45+
* <p>也就是设置全屏,一定要在setContentView之前调用,否则报错</p>
46+
* <p>此方法Activity可以继承AppCompatActivity</p>
47+
* <p>启动的时候状态栏会显示一下再隐藏,比如QQ的欢迎界面</p>
48+
* <p>在配置文件中Activity加属性android:theme="@android:style/Theme.NoTitleBar.Fullscreen"</p>
49+
* <p>如加了以上配置Activity不能继承AppCompatActivity,会报错</p>
50+
*
51+
* @param activity activity
52+
*/
53+
public static void hideStatusBar(Activity activity) {
54+
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
55+
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
56+
WindowManager.LayoutParams.FLAG_FULLSCREEN);
57+
}
58+
59+
/**
60+
* 获取状态栏高度
61+
*
62+
* @param context 上下文
63+
* @return 状态栏高度
64+
*/
65+
public static int getStatusBarHeight(Context context) {
66+
int result = 0;
67+
int resourceId = context.getResources()
68+
.getIdentifier("status_bar_height", "dimen", "android");
69+
if (resourceId > 0) {
70+
result = context.getResources().getDimensionPixelSize(resourceId);
71+
}
72+
return result;
73+
}
74+
75+
/**
76+
* 判断状态栏是否存在
77+
*
78+
* @param activity activity
79+
* @return {@code true}: 存在<br>{@code false}: 不存在
80+
*/
81+
public static boolean isStatusBarExists(Activity activity) {
82+
WindowManager.LayoutParams params = activity.getWindow().getAttributes();
83+
return (params.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != WindowManager.LayoutParams.FLAG_FULLSCREEN;
84+
}
85+
86+
/**
87+
* 获取ActionBar高度
88+
*
89+
* @param activity activity
90+
* @return ActionBar高度
91+
*/
92+
public static int getActionBarHeight(Activity activity) {
93+
TypedValue tv = new TypedValue();
94+
if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
95+
return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
96+
}
97+
return 0;
98+
}
99+
100+
/**
101+
* 显示通知栏
102+
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
103+
*
104+
* @param context 上下文
105+
* @param isSettingPanel {@code true}: 打开设置<br>{@code false}: 打开通知
106+
*/
107+
public static void showNotificationBar(Context context, boolean isSettingPanel) {
108+
String methodName = (Build.VERSION.SDK_INT <= 16) ? "expand"
109+
: (isSettingPanel ? "expandSettingsPanel" : "expandNotificationsPanel");
110+
invokePanels(context, methodName);
111+
}
112+
113+
/**
114+
* 隐藏通知栏
115+
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
116+
*
117+
* @param context 上下文
118+
*/
119+
public static void hideNotificationBar(Context context) {
120+
String methodName = (Build.VERSION.SDK_INT <= 16) ? "collapse" : "collapsePanels";
121+
invokePanels(context, methodName);
122+
}
123+
124+
/**
125+
* 反射唤醒通知栏
126+
*
127+
* @param context 上下文
128+
* @param methodName 方法名
129+
*/
130+
private static void invokePanels(Context context, String methodName) {
131+
try {
132+
Object service = context.getSystemService("statusbar");
133+
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
134+
Method expand = statusBarManager.getMethod(methodName);
135+
expand.invoke(service);
136+
} catch (Exception e) {
137+
e.printStackTrace();
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)