Skip to content

Commit e5cfb21

Browse files
committed
Fixing bugs
1 parent ff2fcc7 commit e5cfb21

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

app/src/main/java/io/github/ratul/topactivity/ui/MainActivity.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.github.ratul.topactivity.service.*;
3838
import io.github.ratul.topactivity.model.TypefaceSpan;
3939
import java.io.*;
40+
import android.util.DisplayMetrics;
4041

4142
/**
4243
* Created by Wen on 16/02/2017.
@@ -48,20 +49,17 @@ public class MainActivity extends Activity implements OnCheckedChangeListener {
4849
CompoundButton mWindowSwitch, mNotificationSwitch, mAccessibilitySwitch;
4950
private BroadcastReceiver mReceiver;
5051
private int theme;
51-
public static MainActivity INSTANCE;
52-
53-
@Override
54-
protected void onPostCreate(Bundle savedInstanceState) {
55-
super.onPostCreate(savedInstanceState);
56-
INSTANCE = this;
57-
if (AccessibilityMonitoringService.getInstance() == null && DatabaseUtil.hasAccess())
58-
startService(new Intent().setClass(this, AccessibilityMonitoringService.class));
59-
}
52+
public static MainActivity INSTANCE;
6053

6154
@Override
6255
protected void onCreate(Bundle savedInstanceState) {
6356
super.onCreate(savedInstanceState);
6457
setContentView(R.layout.activity_main);
58+
INSTANCE = this;
59+
if (AccessibilityMonitoringService.getInstance() == null && DatabaseUtil.hasAccess())
60+
startService(new Intent().setClass(this, AccessibilityMonitoringService.class));
61+
62+
DatabaseUtil.setDisplayWidth(getScreenWidth(this));
6563

6664
theme = FancyDialog.DARK_THEME;
6765
DialogTheme.setupColors(this, theme);
@@ -91,6 +89,19 @@ protected void onCreate(Bundle savedInstanceState) {
9189
mReceiver = new UpdateSwitchReceiver();
9290
registerReceiver(mReceiver, new IntentFilter(ACTION_STATE_CHANGED));
9391
}
92+
93+
public static int getScreenWidth(Activity activity) {
94+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
95+
WindowMetrics windowMetrics = activity.getWindowManager().getCurrentWindowMetrics();
96+
Insets insets = windowMetrics.getWindowInsets()
97+
.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars());
98+
return windowMetrics.getBounds().width() - insets.left - insets.right;
99+
} else {
100+
DisplayMetrics displayMetrics = new DisplayMetrics();
101+
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
102+
return displayMetrics.widthPixels;
103+
}
104+
}
94105

95106
@Override
96107
protected void onNewIntent(Intent intent) {

app/src/main/java/io/github/ratul/topactivity/ui/ShortcutHandlerActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ShortcutHandlerActivity extends Activity {
3737
@Override
3838
protected void onCreate(Bundle savedInstanceState) {
3939
super.onCreate(savedInstanceState);
40+
DatabaseUtil.setDisplayWidth(MainActivity.getScreenWidth(this));
4041

4142
if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) {
4243
Intent intent = new Intent(this, MainActivity.class);

app/src/main/java/io/github/ratul/topactivity/utils/DatabaseUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
public class DatabaseUtil {
3030
private static SharedPreferences sp = App.getApp().getSharedPreferences("io.github.ratul.topactivity", 0);
3131

32+
public static int getDisplayWidth() {
33+
return sp.getInt("width", 720);
34+
}
35+
36+
public static boolean setDisplayWidth(int width) {
37+
return sp.edit().putInt("width", width).commit();
38+
}
39+
3240
public static boolean isShowWindow() {
3341
return sp.getBoolean("is_show_window", false);
3442
}

app/src/main/java/io/github/ratul/topactivity/utils/WindowUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void init(final Context context) {
7070
PixelFormat.TRANSLUCENT);
7171

7272
sWindowParams.gravity = Gravity.CENTER;
73-
sWindowParams.width = (context.getDisplay().getWidth() / 2) + 300;
73+
sWindowParams.width = (DatabaseUtil.getDisplayWidth() / 2) + 300;
7474
sWindowParams.windowAnimations = android.R.style.Animation_Toast;
7575

7676
sView = LayoutInflater.from(context).inflate(R.layout.window_tasks,

app/src/main/res/drawable/layers.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@
1010
android:strokeColor="@color/layerColor"
1111
android:strokeWidth="1.5"
1212
android:strokeLineCap="round"
13-
android:strokeLineJoin="round"
14-
android:fillType="evenOdd" />
13+
android:strokeLineJoin="round" />
1514
<path
1615
android:fillColor="#00000000"
1716
android:pathData="M19.995,4.2m-1.922,0a1.922,1.922 0,1 1,3.844 0a1.922,1.922 0,1 1,-3.844 0"
1817
android:strokeColor="@color/layerColor"
1918
android:strokeWidth="1.5"
2019
android:strokeLineCap="round"
21-
android:strokeLineJoin="round"
22-
android:fillType="evenOdd" />
20+
android:strokeLineJoin="round" />
2321
<path
2422
android:fillColor="#00000000"
2523
android:pathData="M14.9245,3.1201L7.6568,3.1201C4.6453,3.1201 2.778,5.2529 2.778,8.2643L2.778,16.3467C2.778,19.3581 4.6087,21.4817 7.6568,21.4817L16.2609,21.4817C19.2723,21.4817 21.1396,19.3581 21.1396,16.3467L21.1396,9.3078"
2624
android:strokeColor="@color/layerColor"
2725
android:strokeWidth="1.5"
2826
android:strokeLineCap="round"
29-
android:strokeLineJoin="round"
30-
android:fillType="evenOdd" />
27+
android:strokeLineJoin="round" />
3128
</vector>
3229

0 commit comments

Comments
 (0)