|
1 | 1 | package org.woheller69.weather.activities; |
2 | 2 |
|
3 | | -import android.appwidget.AppWidgetManager; |
4 | | -import android.appwidget.AppWidgetProviderInfo; |
5 | | -import android.content.ComponentName; |
6 | | -import android.content.Context; |
7 | 3 | import android.content.DialogInterface; |
8 | 4 | import android.content.Intent; |
9 | 5 | import android.content.SharedPreferences; |
|
25 | 21 | import androidx.appcompat.widget.Toolbar; |
26 | 22 |
|
27 | 23 | import android.os.Looper; |
28 | | -import android.os.PowerManager; |
29 | | -import android.provider.Settings; |
30 | 24 | import android.view.Menu; |
31 | 25 | import android.view.MenuItem; |
32 | | -import android.widget.Toast; |
33 | 26 |
|
34 | 27 |
|
| 28 | +import org.woheller69.freeDroidWarn.FreeDroidWarn; |
35 | 29 | import org.woheller69.weather.BuildConfig; |
36 | 30 | import org.woheller69.weather.R; |
37 | 31 | import org.woheller69.weather.database.SQLiteHelper; |
@@ -64,22 +58,8 @@ protected void onCreate(Bundle savedInstanceState) { |
64 | 58 | super.onCreate(savedInstanceState); |
65 | 59 |
|
66 | 60 | mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); |
67 | | -/* int promptCount = mSharedPreferences.getInt("battery_optimization_prompt_count", 0); |
68 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkAppWidget()) { |
69 | | - PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
70 | | - if (!powerManager.isIgnoringBatteryOptimizations(getPackageName())) { |
71 | | - Toast.makeText(this, "Needs permission Ignore... "+promptCount, Toast.LENGTH_SHORT).show(); |
72 | | - if (promptCount < 3) { |
73 | | - SharedPreferences.Editor editor = mSharedPreferences.edit(); |
74 | | - editor.putInt("battery_optimization_prompt_count", promptCount + 1); |
75 | | - editor.apply(); |
76 | | -
|
77 | | - startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:"+getPackageName()))); |
78 | | - } |
79 | | - } |
80 | | - }*/ |
81 | | - AppWidgetManager.getInstance(this).getInstalledProviders(); |
82 | 61 | mHandler = new Handler(Looper.getMainLooper()); |
| 62 | + FreeDroidWarn.showWarningOnUpgrade(this, BuildConfig.VERSION_CODE); |
83 | 63 | prefManager = new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(this)); |
84 | 64 | if (prefManager.showStarDialog(this)) { |
85 | 65 | AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); |
@@ -252,20 +232,4 @@ protected void onPause() { |
252 | 232 | isVisible=false; |
253 | 233 | } |
254 | 234 |
|
255 | | - public boolean checkAppWidget(){ |
256 | | - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); |
257 | | - List<AppWidgetProviderInfo> providers = appWidgetManager.getInstalledProviders(); |
258 | | - |
259 | | - for (AppWidgetProviderInfo info : providers) { |
260 | | - ComponentName provider = info.provider; |
261 | | - if (provider.getPackageName().equals(getPackageName())) { |
262 | | - int[] widgetIds = appWidgetManager.getAppWidgetIds(provider); |
263 | | - if (widgetIds.length > 0) { |
264 | | - // At least one instance of this widget is on the home screen |
265 | | - return true; |
266 | | - } |
267 | | - } |
268 | | - } |
269 | | - return false; |
270 | | - } |
271 | 235 | } |
0 commit comments