From d1d23e4627a1ba93242d69ee51de97fcf755143a Mon Sep 17 00:00:00 2001 From: kosyak Date: Tue, 24 Oct 2023 02:28:07 +0200 Subject: [PATCH] support primary color picker --- build.gradle | 2 + .../ui/ImportBackupActivity.java | 4 + .../medialib/activities/EditActivity.kt | 19 ++-- .../siacs/conversations/ui/AboutActivity.java | 4 + .../ui/ConversationFragment.java | 28 +++++- .../conversations/ui/LocationActivity.java | 5 ++ .../conversations/ui/MemorizingActivity.java | 4 + .../conversations/ui/RecordingActivity.java | 6 ++ .../siacs/conversations/ui/ScanActivity.java | 10 ++- .../conversations/ui/SettingsActivity.java | 12 ++- .../conversations/ui/UriHandlerActivity.java | 8 ++ .../siacs/conversations/ui/XmppActivity.java | 11 +++ .../ui/adapter/MessageAdapter.java | 27 +++++- .../conversations/ui/util/SendButtonTool.java | 24 +++++ .../conversations/utils/ThemeHelper.java | 46 ++++++++++ src/main/res/values/colors.xml | 40 +++++++++ src/main/res/values/strings.xml | 2 + src/main/res/values/theme-settings.xml | 21 +++++ src/main/res/values/themes.xml | 90 +++++++++++++++++++ src/main/res/xml/preferences.xml | 8 ++ .../ui/ChooseCountryActivity.java | 6 ++ 21 files changed, 358 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index ff2044485..21883b18a 100644 --- a/build.gradle +++ b/build.gradle @@ -89,6 +89,8 @@ dependencies { implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.splitwise:tokenautocomplete:3.0.2' + + implementation 'com.github.kizitonwose.colorpreference:support:1.1.0' } ext { diff --git a/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java b/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java index 6e4815159..0e4772862 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java @@ -46,6 +46,10 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override protected void onCreate(final Bundle savedInstanceState) { this.mTheme = ThemeHelper.find(this); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } setTheme(this.mTheme); super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_import_backup); diff --git a/src/main/java/eu/siacs/conversations/medialib/activities/EditActivity.kt b/src/main/java/eu/siacs/conversations/medialib/activities/EditActivity.kt index 96a8c962d..e0b70e277 100644 --- a/src/main/java/eu/siacs/conversations/medialib/activities/EditActivity.kt +++ b/src/main/java/eu/siacs/conversations/medialib/activities/EditActivity.kt @@ -1,29 +1,18 @@ package eu.siacs.conversations.medialib.activities -import android.Manifest import android.annotation.TargetApi import android.app.Activity -import android.content.Intent -import android.content.pm.PackageManager import android.graphics.Bitmap -import android.graphics.Bitmap.CompressFormat import android.graphics.Color import android.graphics.Point import android.net.Uri import android.os.Build import android.os.Bundle import android.os.Handler -import android.provider.MediaStore -import android.view.ViewGroup.MarginLayoutParams -import android.view.WindowInsets -import android.view.WindowManager import android.widget.ImageView -import android.widget.RelativeLayout -import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.net.toUri -import androidx.core.view.marginTop import androidx.exifinterface.media.ExifInterface import androidx.recyclerview.widget.LinearLayoutManager import com.bumptech.glide.Glide @@ -46,8 +35,8 @@ import eu.siacs.conversations.medialib.dialogs.OtherAspectRatioDialog import eu.siacs.conversations.medialib.dialogs.ResizeDialog import eu.siacs.conversations.medialib.extensions.* import eu.siacs.conversations.medialib.helpers.* -import eu.siacs.conversations.medialib.models.FileDirItem import eu.siacs.conversations.medialib.models.FilterItem +import eu.siacs.conversations.utils.ThemeHelper import java.io.* import java.lang.Float.max import java.util.UUID @@ -97,6 +86,12 @@ class EditActivity : AppCompatActivity(), CropImageView.OnCropImageCompleteListe override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + setTheme(ThemeHelper.find(this)) + val override = ThemeHelper.findThemeOverrideStyle(this) + if (override != null) { + theme.applyStyle(override, true) + } + binding = ActivityEditBinding.inflate(layoutInflater) val view = binding.root setContentView(view) diff --git a/src/main/java/eu/siacs/conversations/ui/AboutActivity.java b/src/main/java/eu/siacs/conversations/ui/AboutActivity.java index 917512a02..59a60f282 100644 --- a/src/main/java/eu/siacs/conversations/ui/AboutActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/AboutActivity.java @@ -23,6 +23,10 @@ public class AboutActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setTheme(ThemeHelper.find(this)); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } setContentView(R.layout.activity_about); setSupportActionBar(findViewById(R.id.toolbar)); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 9ff365f2c..6eb4ce3d7 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -35,6 +36,7 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; +import android.util.TypedValue; import android.view.ActionMode; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -59,10 +61,12 @@ import android.widget.PopupMenu; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; +import androidx.annotation.ColorInt; import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.content.res.AppCompatResources; import androidx.core.view.inputmethod.InputConnectionCompat; import androidx.core.view.inputmethod.InputContentInfoCompat; import androidx.databinding.DataBindingUtil; @@ -202,6 +206,8 @@ public class ConversationFragment extends XmppFragment private ConversationsActivity activity; private Vibrator vibrator; private boolean reInitRequiredOnStart = true; + @ColorInt + private int primaryColor = -1; private ActionMode selectionActionMode; private final OnClickListener clickToMuc = @@ -3090,8 +3096,15 @@ public class ConversationFragment extends XmppFragment this.binding.textSendButton.setTag(action); final Activity activity = getActivity(); if (activity != null) { - this.binding.textSendButton.setImageResource( - SendButtonTool.getSendButtonImageResource(activity, action, status)); + int imageResource = SendButtonTool.getSendButtonImageResource(activity, action, status); + boolean shouldBePrimary = SendButtonTool.shouldSendButtonBePrimary(action, status); + Drawable image = AppCompatResources.getDrawable(getContext(), imageResource); + if (shouldBePrimary) { + image.setTint(getOrCalculatePrimaryColor()); + } + + + this.binding.textSendButton.setImageDrawable(image); } } @@ -3812,4 +3825,15 @@ public class ConversationFragment extends XmppFragment } return activity; } + + @ColorInt + private int getOrCalculatePrimaryColor() { + if (primaryColor != -1) return primaryColor; + + TypedValue typedValue = new TypedValue(); + getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); + primaryColor = typedValue.data; + + return primaryColor; + } } diff --git a/src/main/java/eu/siacs/conversations/ui/LocationActivity.java b/src/main/java/eu/siacs/conversations/ui/LocationActivity.java index 2627e0e59..49ca027c0 100644 --- a/src/main/java/eu/siacs/conversations/ui/LocationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/LocationActivity.java @@ -80,6 +80,11 @@ public abstract class LocationActivity extends ActionBarActivity implements Loca final Context ctx = getApplicationContext(); setTheme(ThemeHelper.find(this)); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } + final PackageManager packageManager = ctx.getPackageManager(); hasLocationFeature = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) || packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || diff --git a/src/main/java/eu/siacs/conversations/ui/MemorizingActivity.java b/src/main/java/eu/siacs/conversations/ui/MemorizingActivity.java index 23f3c82d8..56056f505 100644 --- a/src/main/java/eu/siacs/conversations/ui/MemorizingActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/MemorizingActivity.java @@ -54,6 +54,10 @@ public class MemorizingActivity extends AppCompatActivity implements OnClickList public void onCreate(Bundle savedInstanceState) { LOGGER.log(Level.FINE, "onCreate"); setTheme(ThemeHelper.find(this)); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } super.onCreate(savedInstanceState); getLayoutInflater().inflate(R.layout.toolbar, findViewById(android.R.id.content)); setSupportActionBar(findViewById(R.id.toolbar)); diff --git a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java index ad8684b72..e6e61b773 100644 --- a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java @@ -59,6 +59,12 @@ public class RecordingActivity extends Activity implements View.OnClickListener @Override protected void onCreate(Bundle savedInstanceState) { setTheme(ThemeHelper.findDialog(this)); + + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } + super.onCreate(savedInstanceState); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_recording); this.binding.cancelButton.setOnClickListener(this); diff --git a/src/main/java/eu/siacs/conversations/ui/ScanActivity.java b/src/main/java/eu/siacs/conversations/ui/ScanActivity.java index 95505647d..dca4daacf 100644 --- a/src/main/java/eu/siacs/conversations/ui/ScanActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ScanActivity.java @@ -42,6 +42,7 @@ import android.view.View; import android.view.WindowManager; import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -62,12 +63,13 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.ui.service.CameraManager; import eu.siacs.conversations.ui.util.SettingsUtils; import eu.siacs.conversations.ui.widget.ScannerView; +import eu.siacs.conversations.utils.ThemeHelper; /** * @author Andreas Schildbach */ @SuppressWarnings("deprecation") -public final class ScanActivity extends Activity implements SurfaceTextureListener, ActivityCompat.OnRequestPermissionsResultCallback { +public final class ScanActivity extends AppCompatActivity implements SurfaceTextureListener, ActivityCompat.OnRequestPermissionsResultCallback { public static final String INTENT_EXTRA_RESULT = "result"; public static final int REQUEST_SCAN_QR_CODE = 0x0987; @@ -167,6 +169,12 @@ public final class ScanActivity extends Activity implements SurfaceTextureListen public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setTheme(ThemeHelper.find(this)); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } + vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); setContentView(R.layout.activity_scan); diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 605851c7b..3bd33f660 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -1,7 +1,6 @@ package eu.siacs.conversations.ui; import android.app.FragmentManager; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -29,7 +28,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.KeyStoreException; @@ -37,6 +35,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -50,8 +49,8 @@ import eu.siacs.conversations.services.UnifiedPushDistributor; import eu.siacs.conversations.ui.util.SettingsUtils; import eu.siacs.conversations.ui.util.StyledAttributes; import eu.siacs.conversations.utils.GeoHelper; +import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.utils.TimeFrameUtils; -import eu.siacs.conversations.xmpp.InvalidJid; import eu.siacs.conversations.xmpp.Jid; public class SettingsActivity extends XmppActivity implements OnSharedPreferenceChangeListener { @@ -65,6 +64,7 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion"; public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final String THEME = "theme"; + public static final String THEME_OVERRIDE_COLOR = "themeOverrideColor"; public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; public static final String OMEMO_SETTING = "omemo"; public static final String PREVENT_SCREENSHOTS = "prevent_screenshots"; @@ -86,6 +86,7 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference } mSettingsFragment.setActivityIntent(getIntent()); this.mTheme = findTheme(); + setTheme(this.mTheme); getWindow() .getDecorView() @@ -517,6 +518,11 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference if (this.mTheme != theme) { recreate(); } + } else if (name.equals(THEME_OVERRIDE_COLOR)) { + final Integer currentOverrideStyle = ThemeHelper.findThemeOverrideStyle(this); + if (!Objects.equals(this.mThemeOverrideStyle, currentOverrideStyle)) { + recreate(); + } } else if (name.equals(PREVENT_SCREENSHOTS)) { SettingsUtils.applyScreenshotPreventionSetting(this); } else if (UnifiedPushDistributor.PREFERENCES.contains(name)) { diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index 1e0cf41d3..75cb0994e 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -33,6 +33,7 @@ import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.utils.ProvisioningUtils; import eu.siacs.conversations.utils.SignupUtils; +import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.xmpp.Jid; import okhttp3.Call; @@ -94,6 +95,13 @@ public class UriHandlerActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setTheme(ThemeHelper.find(this)); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + } + + this.binding = DataBindingUtil.setContentView(this, R.layout.activity_uri_handler); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 80b96f825..e91789a5f 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -61,6 +61,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.RejectedExecutionException; import eu.siacs.conversations.Config; @@ -107,6 +108,7 @@ public abstract class XmppActivity extends ActionBarActivity { private boolean isCameraFeatureAvailable = false; protected int mTheme; + protected Integer mThemeOverrideStyle; protected boolean mUsingEnterKey = false; protected boolean mUseTor = false; protected Toast mToast; @@ -226,6 +228,10 @@ public abstract class XmppActivity extends ActionBarActivity { } this.mUsingEnterKey = usingEnterKey(); this.mUseTor = useTor(); + + if (!Objects.equals(mThemeOverrideStyle, ThemeHelper.findThemeOverrideStyle(this))) { + recreate(); + } } public void connectToBackend() { @@ -478,6 +484,11 @@ public abstract class XmppActivity extends ActionBarActivity { this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); this.mTheme = findTheme(); setTheme(this.mTheme); + Integer override = ThemeHelper.findThemeOverrideStyle(this); + if (override != null) { + getTheme().applyStyle(override, true); + mThemeOverrideStyle = override; + } } protected boolean isCameraFeatureAvailable() { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 7c8b9e418..5f38b9154 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -8,6 +8,7 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Outline; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.os.Build; import android.preference.PreferenceManager; import android.text.Spannable; @@ -18,6 +19,7 @@ import android.text.style.ForegroundColorSpan; import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.util.DisplayMetrics; +import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.view.ViewOutlineProvider; @@ -30,12 +32,16 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.ColorInt; +import androidx.appcompat.content.res.AppCompatResources; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import com.cheogram.android.SwipeDetector; import com.google.common.base.Strings; +import org.checkerframework.checker.units.qual.C; + import java.net.URI; import java.util.HashSet; import java.util.List; @@ -102,6 +108,8 @@ public class MessageAdapter extends ArrayAdapter { private Set allowedSwipeActions; + @ColorInt + private int primaryColor = -1; public MessageAdapter(final XmppActivity activity, final List messages, final boolean forceNames) { super(activity, 0, messages); @@ -959,14 +967,20 @@ public class MessageAdapter extends ArrayAdapter { } else { bubble = activity.getThemeResource(R.attr.message_bubble_received_monochrome, R.drawable.message_bubble_received_white); } + + viewHolder.message_box.setBackgroundResource(bubble); } else { if (mergeableWithNext) { bubble = activity.getThemeResource(R.attr.message_bubble_received_green_non_last, R.drawable.message_bubble_received_non_last); } else { bubble = activity.getThemeResource(R.attr.message_bubble_received_green, R.drawable.message_bubble_received); } + + Drawable bubbleDrawable = AppCompatResources.getDrawable(getContext(), bubble); + bubbleDrawable.setTint(getOrCalculatePrimaryColor()); + viewHolder.message_box.setBackground(bubbleDrawable); } - viewHolder.message_box.setBackgroundResource(bubble); + viewHolder.encryption.setVisibility(View.GONE); } else { if (mergeableWithNext) { @@ -1066,6 +1080,17 @@ public class MessageAdapter extends ArrayAdapter { Toast.makeText(activity, R.string.no_application_found_to_display_location, Toast.LENGTH_SHORT).show(); } + @ColorInt + private int getOrCalculatePrimaryColor() { + if (primaryColor != -1) return primaryColor; + + TypedValue typedValue = new TypedValue(); + getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); + primaryColor = typedValue.data; + + return primaryColor; + } + public void updatePreferences() { SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); this.mUseGreenBackground = p.getBoolean("use_green_background", activity.getResources().getBoolean(R.bool.use_green_background)); diff --git a/src/main/java/eu/siacs/conversations/ui/util/SendButtonTool.java b/src/main/java/eu/siacs/conversations/ui/util/SendButtonTool.java index 8f118541b..c3d022b5e 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/SendButtonTool.java +++ b/src/main/java/eu/siacs/conversations/ui/util/SendButtonTool.java @@ -177,6 +177,30 @@ public class SendButtonTool { return getThemeResource(activity, R.attr.ic_send_text_offline, R.drawable.ic_send_text_offline); } + public static boolean shouldSendButtonBePrimary(SendButtonAction action, Presence.Status status) { + switch (action) { + case TEXT: + case RECORD_VIDEO: + case TAKE_PHOTO: + case RECORD_VOICE: + case SEND_LOCATION: + case CANCEL: + case CHOOSE_PICTURE: + switch (status) { + case CHAT: + case ONLINE: + return true; + case AWAY: + case XA: + case DND: + default: + return false; + } + } + + return false; + } + private static int getThemeResource(Activity activity, int r_attr_name, int r_drawable_def) { int[] attrs = {r_attr_name}; TypedArray ta = activity.getTheme().obtainStyledAttributes(attrs); diff --git a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java index 17311cb0c..28a3716bd 100644 --- a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java @@ -34,11 +34,14 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Color; import android.os.Build; import android.preference.PreferenceManager; import android.util.TypedValue; import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.Nullable; import androidx.annotation.StyleRes; import androidx.core.content.ContextCompat; @@ -49,6 +52,9 @@ import eu.siacs.conversations.ui.SettingsActivity; public class ThemeHelper { + @ColorInt + private static Integer currentColorOverride = null; + public static int find(final Context context) { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final Resources resources = context.getResources(); @@ -64,6 +70,46 @@ public class ThemeHelper { } } + @Nullable + public static Integer findThemeOverrideStyle(final Context context) { + final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + int currentColorOverride = sharedPreferences.getInt(SettingsActivity.THEME_OVERRIDE_COLOR, -1); + + String hex = "#" + Integer.toHexString(currentColorOverride).substring(2); + String[] colorsArray = context.getResources().getStringArray(R.array.themeColorsOverride); + int index = -1; + + for (int i = 0;i#BB000000 #000000 + + + #e91e63 + #b41249 + #9c27b0 + #751d84 + #673ab7 + #4d2c89 + #3f51b5 + #2f3d88 + #2196f3 + #0b72c4 + #03a9f4 + #027fb7 + #00bcd4 + #008d9f + #009688 + #007066 + #43A047 + #327835 + #8bc34a + #699732 + #cddc39 + #a3b11f + #ffeb3b + #ebd300 + #ffc107 + #c49300 + #ff9800 + #bf7200 + #ff5722 + #d93400 + #795548 + #5b4036 + #9e9e9e + #767676 + #607d8b + #485e68 + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 21f3a584e..6eaad8464 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -575,7 +575,9 @@ Lets your contacts know when you use Conversations Privacy Theme + Accent color Select the color palette + Select preferred accent color (it applies to messages bubbles, toolbars and other UI elements) Automatic Light Dark diff --git a/src/main/res/values/theme-settings.xml b/src/main/res/values/theme-settings.xml index b770b1b26..3998f42f5 100644 --- a/src/main/res/values/theme-settings.xml +++ b/src/main/res/values/theme-settings.xml @@ -11,4 +11,25 @@ dark + + #e91e63 + #9c27b0 + #673ab7 + #3f51b5 + #2196f3 + #03a9f4 + #00bcd4 + #009688 + #43A047 + #8bc34a + #cddc39 + #ffeb3b + #ffc107 + #ff9800 + #ff5722 + #795548 + #9e9e9e + #607d8b + + diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index 08d23429a..15c3eba92 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -442,4 +442,94 @@ 56sp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index efa0a6dca..d4b49da9d 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -1,5 +1,6 @@ @@ -182,6 +183,13 @@ android:key="theme" android:summary="@string/pref_theme_options_summary" android:title="@string/pref_theme_options" /> +