Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Commit 0e8269b

Browse files
committed
Added MIUI alert about the overlay disappearing.
1 parent 18d3a6a commit 0e8269b

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

app/src/main/java/com/lorenzomoscati/np/Activity/TabbedActivity.java

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import android.accessibilityservice.AccessibilityServiceInfo;
88
import android.annotation.SuppressLint;
9+
import android.content.ComponentName;
910
import android.content.Context;
1011
import android.content.DialogInterface;
1112
import android.content.Intent;
13+
import android.content.pm.PackageManager;
1214
import android.content.pm.ServiceInfo;
1315
import android.net.Uri;
1416
import android.os.Bundle;
@@ -35,13 +37,16 @@
3537
public class TabbedActivity extends AppCompatActivity {
3638

3739
private ViewPager viewPager;
40+
Context mContext;
3841

3942
@Override
4043
protected void onCreate(Bundle savedInstanceState) {
4144

4245
super.onCreate(savedInstanceState);
4346

4447
setContentView(R.layout.activity_tabbed);
48+
49+
mContext = this;
4550

4651
// Creates the configuration directories
4752
createDirectories();
@@ -144,7 +149,7 @@ public void onClick(View v) {
144149
}
145150

146151
});
147-
152+
148153
// Shows the bar
149154
bar.show();
150155

@@ -153,14 +158,17 @@ public void onClick(View v) {
153158
// If Doze is on for the app a snackBar is shown
154159
else if (checkDozeOn()) {
155160

156-
Snackbar bar = Snackbar.make(viewPager, "Please turn off battery optimization", Snackbar.LENGTH_INDEFINITE);
161+
// Sets the title and length (infinite)
162+
Snackbar bar = Snackbar.make(viewPager, getString(R.string.battery_optimization), Snackbar.LENGTH_INDEFINITE);
157163

158-
bar.setAction("Disable", new View.OnClickListener() {
164+
// Sets the button to disable it
165+
bar.setAction(getString(R.string.disable), new View.OnClickListener() {
159166

160167
@SuppressLint("BatteryLife")
161168
@Override
162169
public void onClick(View v) {
163170

171+
// Creates the intent to the settings page
164172
Intent intent = new Intent();
165173
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
166174
intent.setData(Uri.parse("package:" + getPackageName()));
@@ -170,9 +178,36 @@ public void onClick(View v) {
170178

171179
});
172180

181+
// Shows the bar
173182
bar.show();
174183

175184
}
185+
186+
// If the app is running on MIUI a snackBar is shown
187+
else if (checkMIUI(getApplicationContext())) {
188+
189+
// Sets the title and length (infinite)
190+
Snackbar bar = Snackbar.make(viewPager, getString(R.string.miui_note), Snackbar.LENGTH_INDEFINITE);
191+
192+
bar.setAction(getString(R.string.more_info), new View.OnClickListener() {
193+
194+
@Override
195+
public void onClick(View v) {
196+
197+
new AlertDialog.Builder(mContext)
198+
.setTitle(getString(R.string.overlay_disappearing))
199+
.setMessage(getString(R.string.overlay_disappearing_desc))
200+
.setPositiveButton(getString(R.string.understood), null)
201+
.show();
202+
203+
}
204+
205+
});
206+
207+
// Shows the bar
208+
bar.show();
209+
210+
}
176211

177212
}
178213

@@ -199,6 +234,21 @@ private boolean checkDozeOn() {
199234
return !Objects.requireNonNull(pm).isIgnoringBatteryOptimizations(getPackageName());
200235

201236
}
237+
238+
private boolean isIntentResolved(Context ctx, Intent intent ){
239+
240+
return (intent!=null && ctx.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null);
241+
242+
}
243+
244+
private boolean checkMIUI(Context ctx) {
245+
246+
return isIntentResolved(ctx, new Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT))
247+
|| isIntentResolved(ctx, new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")))
248+
|| isIntentResolved(ctx, new Intent("miui.intent.action.POWER_HIDE_MODE_APP_LIST").addCategory(Intent.CATEGORY_DEFAULT))
249+
|| isIntentResolved(ctx, new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.powercenter.PowerSettings")));
250+
251+
}
202252

203253
// Method that checks the status of the accessibility service
204254
private static boolean isAccessibilityServiceEnabled(Context context) {

app/src/main/java/com/lorenzomoscati/np/Fragments/AboutFragment.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,10 @@ public void onClick(DialogInterface dialog, int which) {
139139
public void onClick(DialogInterface dialog, int which) {
140140

141141
if (detailsList != null) {
142-
143-
try {
144-
145-
BillingFlowParams params = BillingFlowParams.newBuilder().setSkuDetails(detailsList.get(current)).build();
146-
billingClient.launchBillingFlow(getActivity(), params);
147142

148-
}
143+
BillingFlowParams params = BillingFlowParams.newBuilder().setSkuDetails(detailsList.get(current)).build();
144+
billingClient.launchBillingFlow(getActivity(), params);
149145

150-
catch (IndexOutOfBoundsException ignored) {
151-
152-
Toast.makeText(getContext(), R.string.donation_error, Toast.LENGTH_LONG).show();
153-
154-
}
155-
156-
157146
}
158147

159148
else {
@@ -190,25 +179,25 @@ public void onBillingSetupFinished(BillingResult billingResult) {
190179
// If the billing client is successful the data is loaded
191180
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
192181

193-
Toast.makeText(getContext(), R.string.billing_connected, Toast.LENGTH_SHORT).show();
182+
//Toast.makeText(getContext(), R.string.billing_connected, Toast.LENGTH_SHORT).show();
194183
loadData();
195184

196185
}
197186

198-
else {
187+
/*else {
199188
200189
// If there is an error, a debug message is toasted
201190
Toast.makeText(getContext(), billingResult.getDebugMessage(), Toast.LENGTH_SHORT).show();
202191
203-
}
192+
}*/
204193

205194
}
206195

207196
@Override
208197
public void onBillingServiceDisconnected() {
209198

210199
// If the service is disconnected, the user is notified via a toast
211-
Toast.makeText(getContext(), R.string.billing_disconnected, Toast.LENGTH_SHORT).show();
200+
//Toast.makeText(getContext(), R.string.billing_disconnected, Toast.LENGTH_SHORT).show();
212201

213202
}
214203

@@ -240,7 +229,7 @@ private void loadData() {
240229
@Override
241230
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
242231

243-
Toast.makeText(getContext(), skuDetailsList.size()+ " lol", Toast.LENGTH_SHORT).show();
232+
//Toast.makeText(getContext(), skuDetailsList.size()+ " lol", Toast.LENGTH_SHORT).show();
244233

245234
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
246235

@@ -254,11 +243,11 @@ public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> s
254243

255244
}
256245

257-
else {
246+
/*else {
258247
259248
Toast.makeText(getContext(), R.string.billing_notReady, Toast.LENGTH_SHORT).show();
260249
261-
}
250+
}*/
262251

263252
}
264253

app/src/main/res/layout/fragment_about.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
android:layout_marginEnd="16dp"
141141
android:layout_marginBottom="8dp"
142142
android:text="@string/Telegram_group"
143-
android:textColor="@color/colorPrimaryDark"
143+
android:textColor="@color/colorTextLight"
144144
app:layout_constraintBottom_toBottomOf="parent"
145145
app:layout_constraintEnd_toEndOf="parent"
146146
app:layout_constraintStart_toStartOf="parent"

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<color name="colorPrimary">#FFFFFF</color>
4-
<color name="colorPrimaryDark">#FFFFFF</color>
4+
<color name="colorPrimaryDark">#212121</color>
55
<color name="colorAccent">#1A73E8</color>
66
<color name="colorTextDark">#212121</color>
77
<color name="colorTextLight">#FFFFFF</color>

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,11 @@
9797
<string name="notch_shape">Notch shape</string>
9898
<string name="notch_title_def">TextView</string>
9999
<string name="notch">Notch</string>
100+
<string name="battery_optimization">Please turn off battery optimization</string>
101+
<string name="disable">Disable</string>
102+
<string name="miui_note">Note for MIUI ROMs</string>
103+
<string name="more_info">More Info</string>
104+
<string name="overlay_disappearing">Overlay Disappearing</string>
105+
<string name="understood">Understood</string>
106+
<string name="overlay_disappearing_desc"><![CDATA[This is a common problem on MIUI. In order to not face this: configure the overlay and after doing it, close the Notch Pie app from recent apps and go to Settings > > Additional settings > Accessibility and then turn off and on again Notch Pie service.]]></string>
100107
</resources>

0 commit comments

Comments
 (0)