mirror of https://github.com/M66B/FairEmail.git
Added day/night mode for sync widget
This commit is contained in:
parent
4d8c514f7b
commit
584147e0c2
|
@ -24,10 +24,12 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
@ -38,6 +40,7 @@ import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
|
|||
public class ActivityWidgetSync extends ActivityBase {
|
||||
private int appWidgetId;
|
||||
|
||||
private CheckBox cbDayNight;
|
||||
private CheckBox cbSemiTransparent;
|
||||
private ViewButtonColor btnColor;
|
||||
private Button btnSave;
|
||||
|
@ -56,13 +59,17 @@ public class ActivityWidgetSync extends ActivityBase {
|
|||
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
|
||||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
|
||||
daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setSubtitle(R.string.title_widget_title_sync);
|
||||
setContentView(R.layout.activity_widget_sync);
|
||||
|
||||
cbDayNight = findViewById(R.id.cbDayNight);
|
||||
cbSemiTransparent = findViewById(R.id.cbSemiTransparent);
|
||||
btnColor = findViewById(R.id.btnColor);
|
||||
btnSave = findViewById(R.id.btnSave);
|
||||
|
@ -70,6 +77,14 @@ public class ActivityWidgetSync extends ActivityBase {
|
|||
final Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
|
||||
cbDayNight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
cbSemiTransparent.setEnabled(!checked);
|
||||
btnColor.setEnabled(!checked);
|
||||
}
|
||||
});
|
||||
|
||||
btnColor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -106,6 +121,7 @@ public class ActivityWidgetSync extends ActivityBase {
|
|||
public void onClick(View view) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetSync.this);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked());
|
||||
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
|
||||
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
|
||||
editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE);
|
||||
|
@ -119,8 +135,12 @@ public class ActivityWidgetSync extends ActivityBase {
|
|||
});
|
||||
|
||||
// Initialize
|
||||
cbDayNight.setChecked(daynight);
|
||||
cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE);
|
||||
cbSemiTransparent.setChecked(semi);
|
||||
cbSemiTransparent.setEnabled(!daynight);
|
||||
btnColor.setColor(background);
|
||||
btnColor.setEnabled(!daynight);
|
||||
|
||||
setResult(RESULT_CANCELED, resultValue);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
@ -48,6 +50,7 @@ public class WidgetSync extends AppWidgetProvider {
|
|||
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
|
||||
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
|
||||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
|
||||
|
@ -57,9 +60,18 @@ public class WidgetSync extends AppWidgetProvider {
|
|||
|
||||
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 (!daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", 0);
|
||||
views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24);
|
||||
} else
|
||||
views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24_dn : R.drawable.twotone_sync_disabled_24_dn);
|
||||
|
||||
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
views.setInt(R.id.background, "setBackgroundColor", Color.WHITE);
|
||||
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", android.R.attr.colorBackground);
|
||||
views.setColorAttr(R.id.ivSync, "setColorFilter", android.R.attr.textColorPrimary);
|
||||
} else if (background == Color.TRANSPARENT) {
|
||||
if (semi)
|
||||
views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background);
|
||||
else
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:textColorPrimary">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10,6.35V4.26c-0.66,0.17 -1.29,0.43 -1.88,0.75l1.5,1.5c0.13,-0.05 0.25,-0.11 0.38,-0.16zM20,12c0,-2.21 -0.91,-4.2 -2.36,-5.64L20,4h-6v6l2.24,-2.24C17.32,8.85 18,10.34 18,12c0,0.85 -0.19,1.65 -0.51,2.38l1.5,1.5C19.63,14.74 20,13.41 20,12zM4.27,4L2.86,5.41l2.36,2.36C4.45,8.99 4,10.44 4,12c0,2.21 0.91,4.2 2.36,5.64L4,20h6v-6l-2.24,2.24C6.68,15.15 6,13.66 6,12c0,-1 0.25,-1.94 0.68,-2.77l8.08,8.08c-0.25,0.13 -0.5,0.24 -0.76,0.34v2.09c0.8,-0.21 1.55,-0.54 2.23,-0.96l2.58,2.58 1.41,-1.41L4.27,4z"/>
|
||||
</vector>
|
|
@ -12,22 +12,35 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbDayNight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:checked="true"
|
||||
android:text="@string/title_widget_day_night"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbSemiTransparent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:checked="true"
|
||||
android:text="@string/title_widget_semi_transparent"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbDayNight" />
|
||||
|
||||
<eu.faircode.email.ViewButtonColor
|
||||
android:id="@+id/btnColor"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:paddingHorizontal="6dp"
|
||||
android:tag="disable"
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
android:id="@+id/background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/widget_background">
|
||||
android:background="?android:colorBackground"
|
||||
android:theme="@style/Theme.AppCompat.DayNight">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/content"
|
||||
|
@ -19,7 +20,6 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/title_widget_title_sync"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/twotone_sync_disabled_24"
|
||||
app:tint="@color/colorWidgetForeground" />
|
||||
android:src="@drawable/twotone_sync_disabled_24" />
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue