support primary color picker

This commit is contained in:
kosyak 2023-10-24 02:28:07 +02:00
parent 663a0feecb
commit d1d23e4627
21 changed files with 358 additions and 19 deletions

View file

@ -89,6 +89,8 @@ dependencies {
implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation 'com.splitwise:tokenautocomplete:3.0.2' implementation 'com.splitwise:tokenautocomplete:3.0.2'
implementation 'com.github.kizitonwose.colorpreference:support:1.1.0'
} }
ext { ext {

View file

@ -46,6 +46,10 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
this.mTheme = ThemeHelper.find(this); this.mTheme = ThemeHelper.find(this);
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(override, true);
}
setTheme(this.mTheme); setTheme(this.mTheme);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_import_backup); binding = DataBindingUtil.setContentView(this, R.layout.activity_import_backup);

View file

@ -1,29 +1,18 @@
package eu.siacs.conversations.medialib.activities package eu.siacs.conversations.medialib.activities
import android.Manifest
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.Activity import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Bitmap.CompressFormat
import android.graphics.Color import android.graphics.Color
import android.graphics.Point import android.graphics.Point
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler 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.ImageView
import android.widget.RelativeLayout
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.view.marginTop
import androidx.exifinterface.media.ExifInterface import androidx.exifinterface.media.ExifInterface
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide 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.dialogs.ResizeDialog
import eu.siacs.conversations.medialib.extensions.* import eu.siacs.conversations.medialib.extensions.*
import eu.siacs.conversations.medialib.helpers.* import eu.siacs.conversations.medialib.helpers.*
import eu.siacs.conversations.medialib.models.FileDirItem
import eu.siacs.conversations.medialib.models.FilterItem import eu.siacs.conversations.medialib.models.FilterItem
import eu.siacs.conversations.utils.ThemeHelper
import java.io.* import java.io.*
import java.lang.Float.max import java.lang.Float.max
import java.util.UUID import java.util.UUID
@ -97,6 +86,12 @@ class EditActivity : AppCompatActivity(), CropImageView.OnCropImageCompleteListe
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setTheme(ThemeHelper.find(this))
val override = ThemeHelper.findThemeOverrideStyle(this)
if (override != null) {
theme.applyStyle(override, true)
}
binding = ActivityEditBinding.inflate(layoutInflater) binding = ActivityEditBinding.inflate(layoutInflater)
val view = binding.root val view = binding.root
setContentView(view) setContentView(view)

View file

@ -23,6 +23,10 @@ public class AboutActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setTheme(ThemeHelper.find(this)); setTheme(ThemeHelper.find(this));
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(override, true);
}
setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar(findViewById(R.id.toolbar));

View file

@ -21,6 +21,7 @@ import android.content.Intent;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -35,6 +36,7 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -59,10 +61,12 @@ import android.widget.PopupMenu;
import android.widget.TextView.OnEditorActionListener; import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.view.inputmethod.InputConnectionCompat; import androidx.core.view.inputmethod.InputConnectionCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat; import androidx.core.view.inputmethod.InputContentInfoCompat;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
@ -202,6 +206,8 @@ public class ConversationFragment extends XmppFragment
private ConversationsActivity activity; private ConversationsActivity activity;
private Vibrator vibrator; private Vibrator vibrator;
private boolean reInitRequiredOnStart = true; private boolean reInitRequiredOnStart = true;
@ColorInt
private int primaryColor = -1;
private ActionMode selectionActionMode; private ActionMode selectionActionMode;
private final OnClickListener clickToMuc = private final OnClickListener clickToMuc =
@ -3090,8 +3096,15 @@ public class ConversationFragment extends XmppFragment
this.binding.textSendButton.setTag(action); this.binding.textSendButton.setTag(action);
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null) { if (activity != null) {
this.binding.textSendButton.setImageResource( int imageResource = SendButtonTool.getSendButtonImageResource(activity, action, status);
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; 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;
}
} }

View file

@ -80,6 +80,11 @@ public abstract class LocationActivity extends ActionBarActivity implements Loca
final Context ctx = getApplicationContext(); final Context ctx = getApplicationContext();
setTheme(ThemeHelper.find(this)); setTheme(ThemeHelper.find(this));
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(override, true);
}
final PackageManager packageManager = ctx.getPackageManager(); final PackageManager packageManager = ctx.getPackageManager();
hasLocationFeature = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) || hasLocationFeature = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) ||
packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) ||

View file

@ -54,6 +54,10 @@ public class MemorizingActivity extends AppCompatActivity implements OnClickList
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
LOGGER.log(Level.FINE, "onCreate"); LOGGER.log(Level.FINE, "onCreate");
setTheme(ThemeHelper.find(this)); setTheme(ThemeHelper.find(this));
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(override, true);
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getLayoutInflater().inflate(R.layout.toolbar, findViewById(android.R.id.content)); getLayoutInflater().inflate(R.layout.toolbar, findViewById(android.R.id.content));
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar(findViewById(R.id.toolbar));

View file

@ -59,6 +59,12 @@ public class RecordingActivity extends Activity implements View.OnClickListener
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.findDialog(this)); setTheme(ThemeHelper.findDialog(this));
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(override, true);
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_recording); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_recording);
this.binding.cancelButton.setOnClickListener(this); this.binding.cancelButton.setOnClickListener(this);

View file

@ -42,6 +42,7 @@ import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; 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.service.CameraManager;
import eu.siacs.conversations.ui.util.SettingsUtils; import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.ui.widget.ScannerView; import eu.siacs.conversations.ui.widget.ScannerView;
import eu.siacs.conversations.utils.ThemeHelper;
/** /**
* @author Andreas Schildbach * @author Andreas Schildbach
*/ */
@SuppressWarnings("deprecation") @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 String INTENT_EXTRA_RESULT = "result";
public static final int REQUEST_SCAN_QR_CODE = 0x0987; 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) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(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); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
setContentView(R.layout.activity_scan); setContentView(R.layout.activity_scan);

View file

@ -1,7 +1,6 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -29,7 +28,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
@ -37,6 +35,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; 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.SettingsUtils;
import eu.siacs.conversations.ui.util.StyledAttributes; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.ThemeHelper;
import eu.siacs.conversations.utils.TimeFrameUtils; import eu.siacs.conversations.utils.TimeFrameUtils;
import eu.siacs.conversations.xmpp.InvalidJid;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
public class SettingsActivity extends XmppActivity implements OnSharedPreferenceChangeListener { 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 AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion";
public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final String BROADCAST_LAST_ACTIVITY = "last_activity";
public static final String THEME = "theme"; 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 SHOW_DYNAMIC_TAGS = "show_dynamic_tags";
public static final String OMEMO_SETTING = "omemo"; public static final String OMEMO_SETTING = "omemo";
public static final String PREVENT_SCREENSHOTS = "prevent_screenshots"; public static final String PREVENT_SCREENSHOTS = "prevent_screenshots";
@ -86,6 +86,7 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
} }
mSettingsFragment.setActivityIntent(getIntent()); mSettingsFragment.setActivityIntent(getIntent());
this.mTheme = findTheme(); this.mTheme = findTheme();
setTheme(this.mTheme); setTheme(this.mTheme);
getWindow() getWindow()
.getDecorView() .getDecorView()
@ -517,6 +518,11 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
if (this.mTheme != theme) { if (this.mTheme != theme) {
recreate(); 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)) { } else if (name.equals(PREVENT_SCREENSHOTS)) {
SettingsUtils.applyScreenshotPreventionSetting(this); SettingsUtils.applyScreenshotPreventionSetting(this);
} else if (UnifiedPushDistributor.PREFERENCES.contains(name)) { } else if (UnifiedPushDistributor.PREFERENCES.contains(name)) {

View file

@ -33,6 +33,7 @@ import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.utils.ProvisioningUtils; import eu.siacs.conversations.utils.ProvisioningUtils;
import eu.siacs.conversations.utils.SignupUtils; import eu.siacs.conversations.utils.SignupUtils;
import eu.siacs.conversations.utils.ThemeHelper;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import okhttp3.Call; import okhttp3.Call;
@ -94,6 +95,13 @@ public class UriHandlerActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_uri_handler);
} }

View file

@ -61,6 +61,7 @@ import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -107,6 +108,7 @@ public abstract class XmppActivity extends ActionBarActivity {
private boolean isCameraFeatureAvailable = false; private boolean isCameraFeatureAvailable = false;
protected int mTheme; protected int mTheme;
protected Integer mThemeOverrideStyle;
protected boolean mUsingEnterKey = false; protected boolean mUsingEnterKey = false;
protected boolean mUseTor = false; protected boolean mUseTor = false;
protected Toast mToast; protected Toast mToast;
@ -226,6 +228,10 @@ public abstract class XmppActivity extends ActionBarActivity {
} }
this.mUsingEnterKey = usingEnterKey(); this.mUsingEnterKey = usingEnterKey();
this.mUseTor = useTor(); this.mUseTor = useTor();
if (!Objects.equals(mThemeOverrideStyle, ThemeHelper.findThemeOverrideStyle(this))) {
recreate();
}
} }
public void connectToBackend() { public void connectToBackend() {
@ -478,6 +484,11 @@ public abstract class XmppActivity extends ActionBarActivity {
this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
this.mTheme = findTheme(); this.mTheme = findTheme();
setTheme(this.mTheme); setTheme(this.mTheme);
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(override, true);
mThemeOverrideStyle = override;
}
} }
protected boolean isCameraFeatureAvailable() { protected boolean isCameraFeatureAvailable() {

View file

@ -8,6 +8,7 @@ import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Outline; import android.graphics.Outline;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Spannable; import android.text.Spannable;
@ -18,6 +19,7 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewOutlineProvider; import android.view.ViewOutlineProvider;
@ -30,12 +32,16 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.cheogram.android.SwipeDetector; import com.cheogram.android.SwipeDetector;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import org.checkerframework.checker.units.qual.C;
import java.net.URI; import java.net.URI;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -102,6 +108,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private Set<SwipeDetector.Action> allowedSwipeActions; private Set<SwipeDetector.Action> allowedSwipeActions;
@ColorInt
private int primaryColor = -1;
public MessageAdapter(final XmppActivity activity, final List<Message> messages, final boolean forceNames) { public MessageAdapter(final XmppActivity activity, final List<Message> messages, final boolean forceNames) {
super(activity, 0, messages); super(activity, 0, messages);
@ -959,14 +967,20 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else { } else {
bubble = activity.getThemeResource(R.attr.message_bubble_received_monochrome, R.drawable.message_bubble_received_white); bubble = activity.getThemeResource(R.attr.message_bubble_received_monochrome, R.drawable.message_bubble_received_white);
} }
viewHolder.message_box.setBackgroundResource(bubble);
} else { } else {
if (mergeableWithNext) { if (mergeableWithNext) {
bubble = activity.getThemeResource(R.attr.message_bubble_received_green_non_last, R.drawable.message_bubble_received_non_last); bubble = activity.getThemeResource(R.attr.message_bubble_received_green_non_last, R.drawable.message_bubble_received_non_last);
} else { } else {
bubble = activity.getThemeResource(R.attr.message_bubble_received_green, R.drawable.message_bubble_received); 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); viewHolder.encryption.setVisibility(View.GONE);
} else { } else {
if (mergeableWithNext) { if (mergeableWithNext) {
@ -1066,6 +1080,17 @@ public class MessageAdapter extends ArrayAdapter<Message> {
Toast.makeText(activity, R.string.no_application_found_to_display_location, Toast.LENGTH_SHORT).show(); 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() { public void updatePreferences() {
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity);
this.mUseGreenBackground = p.getBoolean("use_green_background", activity.getResources().getBoolean(R.bool.use_green_background)); this.mUseGreenBackground = p.getBoolean("use_green_background", activity.getResources().getBoolean(R.bool.use_green_background));

View file

@ -177,6 +177,30 @@ public class SendButtonTool {
return getThemeResource(activity, R.attr.ic_send_text_offline, R.drawable.ic_send_text_offline); 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) { private static int getThemeResource(Activity activity, int r_attr_name, int r_drawable_def) {
int[] attrs = {r_attr_name}; int[] attrs = {r_attr_name};
TypedArray ta = activity.getTheme().obtainStyledAttributes(attrs); TypedArray ta = activity.getTheme().obtainStyledAttributes(attrs);

View file

@ -34,11 +34,14 @@ import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.TypedValue; import android.util.TypedValue;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes; import androidx.annotation.StyleRes;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -49,6 +52,9 @@ import eu.siacs.conversations.ui.SettingsActivity;
public class ThemeHelper { public class ThemeHelper {
@ColorInt
private static Integer currentColorOverride = null;
public static int find(final Context context) { public static int find(final Context context) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
final Resources resources = context.getResources(); 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<colorsArray.length;i++) {
if (colorsArray[i].equals(hex)) {
index = i + 1;
break;
}
}
switch (index) {
case 1: return R.style.OverlayPrimary1;
case 2: return R.style.OverlayPrimary2;
case 3: return R.style.OverlayPrimary3;
case 4: return R.style.OverlayPrimary4;
case 5: return R.style.OverlayPrimary5;
case 6: return R.style.OverlayPrimary6;
case 7: return R.style.OverlayPrimary7;
case 8: return R.style.OverlayPrimary8;
case 9: return R.style.OverlayPrimary9;
case 10: return R.style.OverlayPrimary10;
case 11: return R.style.OverlayPrimary11;
case 12: return R.style.OverlayPrimary12;
case 13: return R.style.OverlayPrimary13;
case 14: return R.style.OverlayPrimary14;
case 15: return R.style.OverlayPrimary15;
case 16: return R.style.OverlayPrimary16;
case 17: return R.style.OverlayPrimary17;
case 18: return R.style.OverlayPrimary18;
default:
return null;
}
}
public static int findDialog(Context context) { public static int findDialog(Context context) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
final Resources resources = context.getResources(); final Resources resources = context.getResources();

View file

@ -49,4 +49,44 @@
<color name="crop_image_view_background">#BB000000</color> <color name="crop_image_view_background">#BB000000</color>
<color name="editor_draw_default_color">#000000</color> <color name="editor_draw_default_color">#000000</color>
<color name="primary_override_1">#e91e63</color>
<color name="primary_override_1_dark">#b41249</color>
<color name="primary_override_2">#9c27b0</color>
<color name="primary_override_2_dark">#751d84</color>
<color name="primary_override_3">#673ab7</color>
<color name="primary_override_3_dark">#4d2c89</color>
<color name="primary_override_4">#3f51b5</color>
<color name="primary_override_4_dark">#2f3d88</color>
<color name="primary_override_5">#2196f3</color>
<color name="primary_override_5_dark">#0b72c4</color>
<color name="primary_override_6">#03a9f4</color>
<color name="primary_override_6_dark">#027fb7</color>
<color name="primary_override_7">#00bcd4</color>
<color name="primary_override_7_dark">#008d9f</color>
<color name="primary_override_8">#009688</color>
<color name="primary_override_8_dark">#007066</color>
<color name="primary_override_9">#43A047</color>
<color name="primary_override_9_dark">#327835</color>
<color name="primary_override_10">#8bc34a</color>
<color name="primary_override_10_dark">#699732</color>
<color name="primary_override_11">#cddc39</color>
<color name="primary_override_11_dark">#a3b11f</color>
<color name="primary_override_12">#ffeb3b</color>
<color name="primary_override_12_dark">#ebd300</color>
<color name="primary_override_13">#ffc107</color>
<color name="primary_override_13_dark">#c49300</color>
<color name="primary_override_14">#ff9800</color>
<color name="primary_override_14_dark">#bf7200</color>
<color name="primary_override_15">#ff5722</color>
<color name="primary_override_15_dark">#d93400</color>
<color name="primary_override_16">#795548</color>
<color name="primary_override_16_dark">#5b4036</color>
<color name="primary_override_17">#9e9e9e</color>
<color name="primary_override_17_dark">#767676</color>
<color name="primary_override_18">#607d8b</color>
<color name="primary_override_18_dark">#485e68</color>
</resources> </resources>

View file

@ -575,7 +575,9 @@
<string name="pref_broadcast_last_activity_summary">Lets your contacts know when you use Conversations</string> <string name="pref_broadcast_last_activity_summary">Lets your contacts know when you use Conversations</string>
<string name="pref_privacy">Privacy</string> <string name="pref_privacy">Privacy</string>
<string name="pref_theme_options">Theme</string> <string name="pref_theme_options">Theme</string>
<string name="pref_theme_override_color">Accent color</string>
<string name="pref_theme_options_summary">Select the color palette</string> <string name="pref_theme_options_summary">Select the color palette</string>
<string name="pref_theme_override_color_summary">Select preferred accent color (it applies to messages bubbles, toolbars and other UI elements)</string>
<string name="pref_theme_automatic">Automatic</string> <string name="pref_theme_automatic">Automatic</string>
<string name="pref_theme_light">Light</string> <string name="pref_theme_light">Light</string>
<string name="pref_theme_dark">Dark</string> <string name="pref_theme_dark">Dark</string>

View file

@ -11,4 +11,25 @@
<item>dark</item> <item>dark</item>
</string-array> </string-array>
<string-array name="themeColorsOverride">
<item>#e91e63</item>
<item>#9c27b0</item>
<item>#673ab7</item>
<item>#3f51b5</item>
<item>#2196f3</item>
<item>#03a9f4</item>
<item>#00bcd4</item>
<item>#009688</item>
<item>#43A047</item>
<item>#8bc34a</item>
<item>#cddc39</item>
<item>#ffeb3b</item>
<item>#ffc107</item>
<item>#ff9800</item>
<item>#ff5722</item>
<item>#795548</item>
<item>#9e9e9e</item>
<item>#607d8b</item>
</string-array>
</resources> </resources>

View file

@ -442,4 +442,94 @@
<item name="TextSizeTitle">56sp</item> <item name="TextSizeTitle">56sp</item>
</style> </style>
<style name="OverlayPrimary1">
<item name="colorPrimary">@color/primary_override_1</item>
<item name="colorPrimaryDark">@color/primary_override_1_dark</item>
</style>
<style name="OverlayPrimary2">
<item name="colorPrimary">@color/primary_override_2</item>
<item name="colorPrimaryDark">@color/primary_override_2_dark</item>
</style>
<style name="OverlayPrimary3">
<item name="colorPrimary">@color/primary_override_3</item>
<item name="colorPrimaryDark">@color/primary_override_3_dark</item>
</style>
<style name="OverlayPrimary4">
<item name="colorPrimary">@color/primary_override_4</item>
<item name="colorPrimaryDark">@color/primary_override_4_dark</item>
</style>
<style name="OverlayPrimary5">
<item name="colorPrimary">@color/primary_override_5</item>
<item name="colorPrimaryDark">@color/primary_override_5_dark</item>
</style>
<style name="OverlayPrimary6">
<item name="colorPrimary">@color/primary_override_6</item>
<item name="colorPrimaryDark">@color/primary_override_6_dark</item>
</style>
<style name="OverlayPrimary7">
<item name="colorPrimary">@color/primary_override_7</item>
<item name="colorPrimaryDark">@color/primary_override_7_dark</item>
</style>
<style name="OverlayPrimary8">
<item name="colorPrimary">@color/primary_override_8</item>
<item name="colorPrimaryDark">@color/primary_override_8_dark</item>
</style>
<style name="OverlayPrimary9">
<item name="colorPrimary">@color/primary_override_9</item>
<item name="colorPrimaryDark">@color/primary_override_9_dark</item>
</style>
<style name="OverlayPrimary10">
<item name="colorPrimary">@color/primary_override_10</item>
<item name="colorPrimaryDark">@color/primary_override_10_dark</item>
</style>
<style name="OverlayPrimary11">
<item name="colorPrimary">@color/primary_override_11</item>
<item name="colorPrimaryDark">@color/primary_override_11_dark</item>
</style>
<style name="OverlayPrimary12">
<item name="colorPrimary">@color/primary_override_12</item>
<item name="colorPrimaryDark">@color/primary_override_12_dark</item>
</style>
<style name="OverlayPrimary13">
<item name="colorPrimary">@color/primary_override_13</item>
<item name="colorPrimaryDark">@color/primary_override_13_dark</item>
</style>
<style name="OverlayPrimary14">
<item name="colorPrimary">@color/primary_override_14</item>
<item name="colorPrimaryDark">@color/primary_override_14_dark</item>
</style>
<style name="OverlayPrimary15">
<item name="colorPrimary">@color/primary_override_15</item>
<item name="colorPrimaryDark">@color/primary_override_15_dark</item>
</style>
<style name="OverlayPrimary16">
<item name="colorPrimary">@color/primary_override_16</item>
<item name="colorPrimaryDark">@color/primary_override_16_dark</item>
</style>
<style name="OverlayPrimary17">
<item name="colorPrimary">@color/primary_override_17</item>
<item name="colorPrimaryDark">@color/primary_override_17_dark</item>
</style>
<style name="OverlayPrimary18">
<item name="colorPrimary">@color/primary_override_18</item>
<item name="colorPrimaryDark">@color/primary_override_18_dark</item>
</style>
</resources> </resources>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/color_background_secondary" android:background="?attr/color_background_secondary"
android:key="main_screen"> android:key="main_screen">
@ -182,6 +183,13 @@
android:key="theme" android:key="theme"
android:summary="@string/pref_theme_options_summary" android:summary="@string/pref_theme_options_summary"
android:title="@string/pref_theme_options" /> android:title="@string/pref_theme_options" />
<com.kizitonwose.colorpreference.ColorPreference
android:defaultValue="?colorPrimary"
android:key="themeOverrideColor"
android:summary="@string/pref_theme_override_color_summary"
android:title="@string/pref_theme_override_color"
app:colorChoices="@array/themeColorsOverride"
app:colorShape="circle" />
<ListPreference <ListPreference
android:defaultValue="@string/quick_action" android:defaultValue="@string/quick_action"
android:dialogTitle="@string/choose_quick_action" android:dialogTitle="@string/choose_quick_action"

View file

@ -83,6 +83,12 @@ public class ChooseCountryActivity extends ActionBarActivity implements CountryA
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setTheme(ThemeHelper.find(this)); setTheme(ThemeHelper.find(this));
Integer override = ThemeHelper.findThemeOverrideStyle(this);
if (override != null) {
getTheme().applyStyle(R.style.OverlayPrimaryColorRed, true);
}
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_choose_country); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_choose_country);
setSupportActionBar((Toolbar) this.binding.toolbar); setSupportActionBar((Toolbar) this.binding.toolbar);
configureActionBar(getSupportActionBar()); configureActionBar(getSupportActionBar());