mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 17:57:16 +00:00
Reconfigurable sync widget
This commit is contained in:
parent
abaa194b61
commit
5b4fcad9d3
3 changed files with 20 additions and 3 deletions
|
@ -55,6 +55,10 @@ public class ActivityWidgetSync extends ActivityBase {
|
|||
appWidgetId = extras.getInt(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetSync.this);
|
||||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
|
||||
getSupportActionBar().setSubtitle(R.string.title_widget_title_sync);
|
||||
setContentView(R.layout.activity_widget_sync);
|
||||
|
||||
|
@ -113,7 +117,9 @@ public class ActivityWidgetSync extends ActivityBase {
|
|||
}
|
||||
});
|
||||
|
||||
btnColor.setColor(Color.TRANSPARENT);
|
||||
// Initialize
|
||||
cbSemiTransparent.setChecked(semi);
|
||||
btnColor.setColor(background);
|
||||
|
||||
setResult(RESULT_CANCELED, resultValue);
|
||||
}
|
||||
|
|
|
@ -50,13 +50,20 @@ public class WidgetSync extends AppWidgetProvider {
|
|||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
|
||||
|
||||
if (version <= 1550)
|
||||
semi = true; // Legacy
|
||||
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_sync);
|
||||
views.setOnClickPendingIntent(R.id.ivSync, pi);
|
||||
views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24);
|
||||
|
||||
if (background == Color.TRANSPARENT) {
|
||||
if (!semi && version > 1550)
|
||||
if (semi)
|
||||
views.setInt(R.id.widget, "setBackgroundResource", R.drawable.widget_background);
|
||||
else
|
||||
views.setInt(R.id.widget, "setBackgroundColor", background);
|
||||
views.setInt(R.id.ivSync, "setColorFilter",
|
||||
context.getResources().getColor(R.color.colorWidgetForeground));
|
||||
} else {
|
||||
float lum = (float) ColorUtils.calculateLuminance(background);
|
||||
|
||||
|
@ -69,6 +76,9 @@ public class WidgetSync extends AppWidgetProvider {
|
|||
views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK);
|
||||
}
|
||||
|
||||
int dp6 = Helper.dp2pixels(context, 6);
|
||||
views.setViewPadding(R.id.widget, dp6, dp6, dp6, dp6);
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
|
|
|
@ -7,4 +7,5 @@
|
|||
android:previewImage="@drawable/widget_preview_sync"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="0"
|
||||
android:widgetCategory="home_screen" />
|
||||
android:widgetCategory="home_screen"
|
||||
android:widgetFeatures="reconfigurable" />
|
||||
|
|
Loading…
Reference in a new issue