Skip to content

Commit ff039c3

Browse files
committed
see 02/13 log
1 parent b84426a commit ff039c3

File tree

10 files changed

+142
-19
lines changed

10 files changed

+142
-19
lines changed

utilcode/README-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ implementation 'com.blankj:utilcode:1.23.5'
1111
* ### Activity 相关 -> [ActivityUtils.java][activity.java] -> [Demo][activity.demo]
1212
```
1313
getActivityByView : 根据视图获取 Activity
14+
getActivityByContext : 根据上下文获取 Activity
1415
isActivityExists : 判断 Activity 是否存在
1516
startActivity : 启动 Activity
1617
startActivityForResult : 启动 Activity 为返回结果

utilcode/lib/src/main/java/com/blankj/utilcode/util/ActivityUtils.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ private ActivityUtils() {
3939
* @param view The view.
4040
* @return the activity by view.
4141
*/
42-
public static Activity getActivityByView(@NonNull final View view) {
43-
Context context = view.getContext();
42+
public static Activity getActivityByView(@NonNull View view) {
43+
return getActivityByContext(view.getContext());
44+
}
45+
46+
/**
47+
* Return the activity by context.
48+
*
49+
* @param context The context.
50+
* @return the activity by context.
51+
*/
52+
public static Activity getActivityByContext(@NonNull Context context) {
4453
while (context instanceof ContextWrapper) {
4554
if (context instanceof Activity) {
4655
return (Activity) context;

utilcode/lib/src/main/java/com/blankj/utilcode/util/CrashUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void uncaughtException(final Thread t, final Throwable e) {
8787
"\nApp VersionCode : " + versionCode +
8888
"\n************* Log Head ****************\n\n";
8989
sb.append(head)
90-
.append(ThreadUtils.getFullStackTrace(e));
90+
.append(ThrowableUtils.getFullStackTrace(e));
9191
final String crashInfo = sb.toString();
9292
final String fullPath = (dir == null ? defaultDir : dir) + time + ".txt";
9393
if (createOrExistsFile(fullPath)) {

utilcode/lib/src/test/java/com/blankj/utilcode/util/http/nodeServer/app.js

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "nodeserver",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC"
11+
}

utilcode/pkg/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
<activity
153153
android:name=".feature.rom.RomActivity"
154154
android:launchMode="singleTop" />
155+
<activity
156+
android:name=".feature.screen.ScreenActivity"
157+
android:launchMode="singleTop" />
155158
<activity
156159
android:name=".feature.sdcard.SDCardActivity"
157160
android:launchMode="singleTop" />

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/CoreUtilActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.blankj.utilcode.pkg.feature.process.ProcessActivity
2727
import com.blankj.utilcode.pkg.feature.reflect.ReflectActivity
2828
import com.blankj.utilcode.pkg.feature.resource.ResourceActivity
2929
import com.blankj.utilcode.pkg.feature.rom.RomActivity
30+
import com.blankj.utilcode.pkg.feature.screen.ScreenActivity
3031
import com.blankj.utilcode.pkg.feature.sdcard.SDCardActivity
3132
import com.blankj.utilcode.pkg.feature.snackbar.SnackbarActivity
3233
import com.blankj.utilcode.pkg.feature.spStatic.SPStaticActivity
@@ -157,6 +158,10 @@ class CoreUtilActivity : BaseTitleBarActivity() {
157158
RomActivity.start(this)
158159
}
159160

161+
fun screenClick(view: View) {
162+
ScreenActivity.start(this)
163+
}
164+
160165
fun sdcardClick(view: View) {
161166
SDCardActivity.start(this)
162167
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.blankj.utilcode.pkg.feature.screen
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.os.Build
6+
import android.os.Bundle
7+
import android.view.View
8+
import com.blankj.lib.base.BaseTitleBarActivity
9+
import com.blankj.utilcode.pkg.R
10+
import com.blankj.utilcode.util.PermissionUtils
11+
import com.blankj.utilcode.util.ScreenUtils
12+
import com.blankj.utilcode.util.SpanUtils
13+
import kotlinx.android.synthetic.main.activity_screen.*
14+
15+
16+
/**
17+
* ```
18+
* author: Blankj
19+
* blog : http://blankj.com
20+
* time : 2019/01/29
21+
* desc : demo about RomUtils
22+
* ```
23+
*/
24+
class ScreenActivity : BaseTitleBarActivity() {
25+
26+
companion object {
27+
fun start(context: Context) {
28+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
29+
PermissionUtils.requestWriteSettings(object : PermissionUtils.SimpleCallback {
30+
override fun onGranted() {
31+
val starter = Intent(context, ScreenActivity::class.java)
32+
context.startActivity(starter)
33+
}
34+
35+
override fun onDenied() {
36+
start(context)
37+
}
38+
})
39+
} else {
40+
val starter = Intent(context, ScreenActivity::class.java)
41+
context.startActivity(starter)
42+
}
43+
}
44+
}
45+
46+
override fun bindTitle(): CharSequence {
47+
return getString(R.string.demo_screen)
48+
}
49+
50+
override fun initData(bundle: Bundle?) {}
51+
52+
override fun bindLayout(): Int {
53+
return R.layout.activity_screen
54+
}
55+
56+
override fun initView(savedInstanceState: Bundle?, contentView: View) {
57+
screenFullscreenBtn.setOnClickListener(this);
58+
screenNonFullscreenBtn.setOnClickListener(this);
59+
screenToggleFullscreenBtn.setOnClickListener(this);
60+
screenLandscapeBtn.setOnClickListener(this);
61+
screenPortraitBtn.setOnClickListener(this);
62+
screenScreenshotBtn.setOnClickListener(this);
63+
screenSetSleepDurationBtn.setOnClickListener(this);
64+
updateAboutScreen();
65+
}
66+
67+
override fun doBusiness() {}
68+
69+
override fun onWidgetClick(view: View) {
70+
when (view.id) {
71+
R.id.screenFullscreenBtn -> ScreenUtils.setFullScreen(this)
72+
R.id.screenNonFullscreenBtn -> ScreenUtils.setNonFullScreen(this)
73+
R.id.screenToggleFullscreenBtn -> ScreenUtils.toggleFullScreen(this)
74+
R.id.screenLandscapeBtn -> ScreenUtils.setLandscape(this)
75+
R.id.screenPortraitBtn -> ScreenUtils.setPortrait(this)
76+
R.id.screenScreenshotBtn -> screenScreenshotIv.setImageBitmap(ScreenUtils.screenShot(this))
77+
R.id.screenSetSleepDurationBtn -> ScreenUtils.setSleepDuration(100000)
78+
}
79+
updateAboutScreen()
80+
}
81+
82+
private fun updateAboutScreen() {
83+
SpanUtils.with(screenAboutTv)
84+
.appendLine("getScreenWidth: " + ScreenUtils.getScreenWidth())
85+
.appendLine("getScreenHeight: " + ScreenUtils.getScreenHeight())
86+
.appendLine("isLandscape: " + ScreenUtils.isLandscape())
87+
.appendLine("isPortrait: " + ScreenUtils.isPortrait())
88+
.appendLine("getScreenRotation: " + ScreenUtils.getScreenRotation(this))
89+
.appendLine("isScreenLock: " + ScreenUtils.isScreenLock())
90+
.appendLine("getSleepDuration: " + ScreenUtils.getSleepDuration())
91+
.append("isTablet: " + ScreenUtils.isTablet())
92+
.create()
93+
}
94+
}

utilcode/pkg/src/main/res/layout/activity_screen.xml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,71 +11,64 @@
1111
android:orientation="vertical">
1212

1313
<ImageView
14-
android:id="@+id/iv_screenshot"
14+
android:id="@+id/screenScreenshotIv"
1515
android:layout_width="match_parent"
1616
android:layout_height="match_parent" />
1717

1818
<TextView
19-
android:id="@+id/tv_about_screen"
19+
android:id="@+id/screenAboutTv"
2020
style="@style/TextStyle"
2121
android:layout_width="match_parent"
2222
android:layout_height="wrap_content" />
2323

2424
<Button
25-
android:id="@+id/btn_set_fullscreen"
25+
android:id="@+id/screenFullscreenBtn"
2626
style="@style/WideBtnStyle"
2727
android:layout_width="match_parent"
2828
android:layout_height="wrap_content"
2929
android:text="@string/screen_set_fullscreen" />
3030

3131
<Button
32-
android:id="@+id/btn_set_non_fullscreen"
32+
android:id="@+id/screenNonFullscreenBtn"
3333
style="@style/WideBtnStyle"
3434
android:layout_width="match_parent"
3535
android:layout_height="wrap_content"
3636
android:text="@string/screen_set_non_fullscreen" />
3737

3838
<Button
39-
android:id="@+id/btn_toggle_fullscreen"
39+
android:id="@+id/screenToggleFullscreenBtn"
4040
style="@style/WideBtnStyle"
4141
android:layout_width="match_parent"
4242
android:layout_height="wrap_content"
4343
android:text="@string/screen_toggle_fullscreen" />
4444

4545
<Button
46-
android:id="@+id/btn_set_landscape"
46+
android:id="@+id/screenLandscapeBtn"
4747
style="@style/WideBtnStyle"
4848
android:layout_width="match_parent"
4949
android:layout_height="wrap_content"
5050
android:text="@string/screen_set_landscape" />
5151

5252
<Button
53-
android:id="@+id/btn_set_portrait"
53+
android:id="@+id/screenPortraitBtn"
5454
style="@style/WideBtnStyle"
5555
android:layout_width="match_parent"
5656
android:layout_height="wrap_content"
5757
android:text="@string/screen_set_portrait" />
5858

5959
<Button
60-
android:id="@+id/btn_screenshot"
60+
android:id="@+id/screenScreenshotBtn"
6161
style="@style/WideBtnStyle"
6262
android:layout_width="match_parent"
6363
android:layout_height="wrap_content"
6464
android:text="@string/screen_screenshot" />
6565

6666
<Button
67-
android:id="@+id/btn_set_sleep_duration"
67+
android:id="@+id/screenSetSleepDurationBtn"
6868
style="@style/WideBtnStyle"
6969
android:layout_width="match_parent"
7070
android:layout_height="wrap_content"
7171
android:text="@string/screen_set_sleep_duration" />
7272

73-
<Button
74-
android:id="@+id/btn_test_adapt_screen"
75-
style="@style/WideBtnStyle"
76-
android:layout_width="match_parent"
77-
android:layout_height="wrap_content"
78-
android:text="@string/screen_test_adapt_screen" />
79-
8073
</LinearLayout>
8174
</ScrollView>

utilcode/pkg/src/main/res/layout/activity_util_core.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@
161161
android:onClick="romClick"
162162
android:text="@string/demo_rom" />
163163

164+
<Button
165+
style="@style/WideBtnStyle"
166+
android:layout_width="match_parent"
167+
android:layout_height="wrap_content"
168+
android:onClick="screenClick"
169+
android:text="@string/demo_screen" />
170+
164171
<Button
165172
style="@style/WideBtnStyle"
166173
android:layout_width="match_parent"

0 commit comments

Comments
 (0)