Skip to content

Commit da20721

Browse files
committed
### 中文 (Chinese)
1. 更新软件图标 2. 修复老版本设备不会自动变换时钟的问题,更换实现方式 3. 修复部分设备无法使用白色主题的问题(感谢 @ohlala85) 4. 安卓4可以点击隐藏导航栏 5. 禁止Gradle将矢量图转换为位图
1 parent 90d2079 commit da20721

37 files changed

Lines changed: 149 additions & 126 deletions

.idea/deploymentTargetDropDown.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
## v1.4
2+
### 中文 (Chinese)
3+
1. 更新软件图标
4+
2. 修复老版本设备不会自动变换时钟的问题,更换实现方式
5+
3. 修复部分设备无法使用白色主题的问题(感谢 @ohlala85
6+
4. 安卓4可以点击隐藏导航栏
7+
5. 禁止Gradle将矢量图转换为位图
8+
9+
## v1.3
10+
111
> 异型屏全屏问题请手动调整,因为我很难保证时间不被遮挡
212
> Please manually adjust the full screen problem of the special-shaped screen, because it is difficult for me to ensure that the time is not blocked
313
4-
## 中文 (Chinese)
14+
### 中文 (Chinese)
515
1. 优化大屏布局
616

7-
## English
17+
### English
818
1. Optimize PC layout

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
这是我第二个使用 Java 编写的安卓软件<br>
44
This is my second Android application written in Java.
55

6-
编写这个软件的目的是利用旧手机。软件向前兼容至安卓2.2,因此您可以在您几乎所有的安卓设备上安装它(前提是您的设备支持安装第三方软件)。<br>
7-
The purpose of making it is to use waste. It is backward compatible with Android 2.2 and can be used on many Android phones.
6+
编写这个软件的目的是利用旧手机。软件向前兼容至 Android 2.3,因此您可以在您几乎所有的安卓设备上安装它(前提是您的设备支持安装第三方软件)。<br>
7+
The purpose of making it is to use waste. It is backward compatible with Android 2.3 and can be used on many Android phones.
88

99
一些代码可能实现得不是那么的好。希望您可以在 issues 内纠正我一些问题。<br>
1010
Some codes may not be implemented well. I hope you can tell me in issues.
1111

1212
对于亮色模式,您可以长按背景启用它。<br>
1313
For a bright theme, you can press and hold the background to enable it.
14+
15+
对于搭载 Android 4.4 以下且拥有导航栏的设备,您可以点击背景将导航栏隐藏。<br>
16+
For devices with a navigation bar under Android 4.4, you can tap the background to hide the navigation bar.
17+
1418
## 关于镜像仓库 | About Image Repositories
1519
本仓库以 [GitLab](https://gitlab.com/Jesse205/Desk-Clock-Lite/) 为主, [Github](https://github.com/Jesse205/Desk-Clock-Lite) 为镜像,暂无 Gitee 镜像。<br>
1620
This repositories mainly uses [GitLab](https://gitlab.com/Jesse205/Desk-Clock-Lite/), [Github](https://github.com/Jesse205/Desk-Clock-Lite) as the image, and there is no Gitee image.

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ android {
1010
applicationId "com.jesse205.deskclock.lite"
1111
minSdk 9
1212
targetSdk 33
13-
versionCode 4
14-
versionName "1.3"
15-
13+
versionCode 5
14+
versionName "1.4"
15+
generatedDensities = []
1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
multiDexEnabled false
1818
}
1919

20+
2021
buildTypes {
2122
release {
2223
minifyEnabled false

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
tools:targetApi="31">
1414
<activity
1515
android:name=".MainActivity"
16+
android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
1617
android:exported="true">
1718
<intent-filter>
1819
<action android:name="android.intent.action.MAIN" />
-825 Bytes
Loading

app/src/main/java/com/jesse205/deskclock/lite/MainActivity.java

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import android.os.Bundle;
99
import android.os.Handler;
1010
import android.preference.PreferenceManager;
11+
import android.util.TypedValue;
1112
import android.view.GestureDetector;
1213
import android.view.MotionEvent;
1314
import android.view.View;
15+
import android.view.ViewTreeObserver;
1416
import android.view.WindowManager;
1517
import android.widget.FrameLayout;
1618
import android.widget.TextView;
@@ -19,7 +21,7 @@
1921
import java.util.Calendar;
2022
import java.util.Date;
2123

22-
public class MainActivity extends Activity implements View.OnTouchListener, GestureDetector.OnGestureListener, Runnable {
24+
public class MainActivity extends Activity implements View.OnTouchListener, GestureDetector.OnGestureListener, Runnable, ViewTreeObserver.OnGlobalLayoutListener {
2325
private boolean lightTheme = false;
2426
private boolean activityStarted = false;
2527
private Handler handler;
@@ -32,11 +34,13 @@ public class MainActivity extends Activity implements View.OnTouchListener, Gest
3234

3335
private SimpleDateFormat timeFormat;
3436
private SimpleDateFormat dateFormat;
35-
37+
private View decorView;
38+
private FrameLayout mainLayout;
3639
private TextView timeView;
3740
private TextView dateView;
41+
private int screenWidthDp;
3842

39-
private Calendar calendar = Calendar.getInstance();
43+
private final Calendar calendar = Calendar.getInstance();
4044

4145
@SuppressLint({"ClickableViewAccessibility", "SimpleDateFormat"})
4246
@Override
@@ -49,18 +53,16 @@ protected void onCreate(Bundle savedInstanceState) {
4953
setTheme(R.style.Theme_DeskClockLite_Light);
5054
else
5155
setTheme(R.style.Theme_DeskClockLite);
52-
56+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
57+
| WindowManager.LayoutParams.FLAG_FULLSCREEN);
58+
decorView = getWindow().getDecorView();
5359
setContentView(R.layout.activity_main);
60+
5461
mGestureDetector = new GestureDetector(this);
5562
mGestureDetector.setIsLongpressEnabled(true);
56-
FrameLayout mainLayout = findViewById(R.id.mainLayout);
57-
mainLayout.setLongClickable(true);
63+
mainLayout = findViewById(R.id.mainLayout);
5864
mainLayout.setOnTouchListener(this);
59-
60-
if (Build.VERSION.SDK_INT < 16)
61-
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
62-
63-
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
65+
mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(this);
6466

6567
timeView = findViewById(R.id.time);
6668
dateView = findViewById(R.id.date);
@@ -69,6 +71,8 @@ protected void onCreate(Bundle savedInstanceState) {
6971
dateFormat = new SimpleDateFormat(getString(R.string.date_template));
7072

7173
handler = new Handler();
74+
75+
7276
}
7377

7478
@Override
@@ -99,8 +103,18 @@ protected void onResume() {
99103
hideSystemUI();
100104
}
101105

106+
private float dp2px(int value) {
107+
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, value, getResources().getDisplayMetrics());
108+
}
109+
110+
private int px2dp(float value) {
111+
final float scale = getResources().getDisplayMetrics().density;
112+
return (int) (value / scale);
113+
}
114+
115+
102116
private void hideSystemUI() {
103-
View decorView = getWindow().getDecorView();
117+
104118
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
105119
// Set the content to appear under the system bars so that the
106120
// content doesn't resize when the system bars hide and show.
@@ -113,6 +127,7 @@ private void hideSystemUI() {
113127
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
114128
visibility |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
115129
}
130+
116131
decorView.setSystemUiVisibility(visibility);
117132
}
118133
}
@@ -153,7 +168,6 @@ public boolean onDown(MotionEvent e) {
153168

154169
@Override
155170
public void onShowPress(MotionEvent e) {
156-
157171
}
158172

159173
@Override
@@ -186,6 +200,8 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
186200
@SuppressLint("ClickableViewAccessibility")
187201
@Override
188202
public boolean onTouch(View v, MotionEvent event) {
203+
if (event.getAction() == MotionEvent.ACTION_UP)
204+
hideSystemUI();
189205
return mGestureDetector.onTouchEvent(event);
190206
}
191207

@@ -195,21 +211,74 @@ public void run() {
195211
String time = timeFormat.format(new Date());
196212
String baseDate = dateFormat.format(new Date());
197213
int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
198-
if (lastTime == null || !lastTime.equals(time)) {
199-
timeView.setText(time);
200-
lastTime = time;
201-
}
202214
if (lastWeekDay != weekDay) {
203215
lastWeekDay = weekDay;
204216
lastWeekDayText = getWeekDayText(weekDay);
205217
}
206218
String date = baseDate + " " + lastWeekDayText;
219+
220+
if (activityStarted)
221+
handler.postDelayed(this, 100);
222+
223+
if (lastTime == null || !lastTime.equals(time)) {
224+
timeView.setText(time);
225+
lastTime = time;
226+
}
207227
if (lastDate == null || !lastDate.equals(date)) {
208228
dateView.setText(date);
209229
lastDate = date;
210230
}
211-
if (activityStarted)
212-
handler.postDelayed(this, 100);
213231
}
214232
}
233+
234+
@Override
235+
public void onGlobalLayout() {
236+
int newScreenWidthDp = px2dp(mainLayout.getMeasuredWidth());
237+
if (newScreenWidthDp != screenWidthDp) {
238+
screenWidthDp = newScreenWidthDp;
239+
int timeSize;
240+
int dateSize;
241+
int dateMarginDp;
242+
if (screenWidthDp >= 1600) {
243+
timeSize = 360;
244+
dateSize = 48;
245+
dateMarginDp = 56;
246+
} else if (screenWidthDp >= 1280) {
247+
timeSize = 288;
248+
dateSize = 34;
249+
dateMarginDp = 40;
250+
} else if (screenWidthDp >= 800) {
251+
timeSize = 192;
252+
dateSize = 20;
253+
dateMarginDp = 24;
254+
} else if (screenWidthDp >= 600) {
255+
timeSize = 144;
256+
dateSize = 20;
257+
dateMarginDp = 24;
258+
} else if (screenWidthDp >= 400) {
259+
timeSize = 96;
260+
dateSize = 18;
261+
dateMarginDp = 16;
262+
} else if (screenWidthDp >= 320) {
263+
timeSize = 80;
264+
dateSize = 18;
265+
dateMarginDp = 16;
266+
} else if (screenWidthDp >= 240) {
267+
timeSize = 60;
268+
dateSize = 16;
269+
dateMarginDp = 16;
270+
} else {
271+
timeSize = 44;
272+
dateSize = 12;
273+
dateMarginDp = 24;
274+
}
275+
int dateMargin = (int) dp2px(dateMarginDp);
276+
timeView.setTextSize(timeSize);
277+
dateView.setTextSize(dateSize);
278+
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dateView.getLayoutParams();
279+
layoutParams.setMargins(dateMargin, dateMargin, dateMargin, dateMargin);
280+
dateView.setLayoutParams(layoutParams);
281+
}
282+
}
283+
215284
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<color xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:color="@android:color/black" />
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
22
android:width="108dp"
33
android:height="108dp"
4-
android:viewportWidth="108"
5-
android:viewportHeight="108"
6-
android:tint="#FFFFFF">
7-
<group android:scaleX="2.61"
8-
android:scaleY="2.61"
9-
android:translateX="22.68"
10-
android:translateY="22.68">
4+
android:viewportWidth="48"
5+
android:viewportHeight="48">
6+
<group android:scaleX="0.5"
7+
android:scaleY="0.5"
8+
android:translateX="12"
9+
android:translateY="12">
1110
<path
12-
android:fillColor="@android:color/white"
13-
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM12.5,7L11,7v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
11+
android:pathData="M24,44C35.046,44 44,35.046 44,24C44,12.954 35.046,4 24,4C12.954,4 4,12.954 4,24C4,35.046 12.954,44 24,44Z"
12+
android:strokeLineJoin="round"
13+
android:strokeWidth="4"
14+
android:fillColor="#00000000"
15+
android:strokeColor="#ffffff"/>
16+
<path
17+
android:pathData="M24.008,12L24.007,24.009L32.487,32.488"
18+
android:strokeLineJoin="round"
19+
android:strokeWidth="4"
20+
android:fillColor="#00000000"
21+
android:strokeColor="#ffffff"
22+
android:strokeLineCap="round"/>
1423
</group>
1524
</vector>

0 commit comments

Comments
 (0)