Fix theming issues on pre-lollipop devices

pull/935/head
Alex Baker 4 years ago
parent 1375b652db
commit 8fd3ff4ea8

@ -30,6 +30,7 @@ import org.tasks.filters.NavigationDrawerSubheader;
import org.tasks.locale.Locale;
import org.tasks.preferences.SyncPreferences;
import org.tasks.themes.CustomIcons;
import org.tasks.themes.DrawableUtil;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeColor;
@ -115,8 +116,9 @@ public class FilterViewHolder extends RecyclerView.ViewHolder {
text.setChecked(selected);
}
icon.setImageResource(getIcon(filter));
icon.setColorFilter(getColor(filter));
int icon = getIcon(filter);
this.icon.setImageDrawable(DrawableUtil.getWrapped(activity, icon));
DrawableCompat.setTint(this.icon.getDrawable(), getColor(filter));
text.setText(filter.listingTitle);
if (count == null || count == 0) {

@ -168,12 +168,16 @@ public abstract class BaseListSettingsActivity extends ThemedInjectingAppCompatA
Drawable leftDrawable = getLeftDrawable(color);
if (selectedColor == 0) {
themeColor = this.themeColor;
DrawableCompat.setTint(leftDrawable, ContextCompat.getColor(this, android.R.color.transparent));
DrawableCompat.setTint(
leftDrawable, ContextCompat.getColor(this, android.R.color.transparent));
clear.setVisibility(View.GONE);
} else {
themeColor = newThemeColor(this, selectedColor);
DrawableCompat.setTint(
((LayerDrawable) leftDrawable).getDrawable(0), themeColor.getPrimaryColor());
leftDrawable instanceof LayerDrawable
? ((LayerDrawable) leftDrawable).getDrawable(0)
: leftDrawable,
themeColor.getPrimaryColor());
clear.setVisibility(View.VISIBLE);
}
themeColor.apply(toolbar);

@ -1,19 +1,17 @@
package org.tasks.dialogs;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import org.tasks.Callback;
import org.tasks.R;
import org.tasks.themes.DrawableUtil;
public class IconPickerHolder extends RecyclerView.ViewHolder {
@ -47,11 +45,8 @@ public class IconPickerHolder extends RecyclerView.ViewHolder {
public void bind(int index, int icon, int tint, float alpha, boolean isEnabled) {
this.index = index;
this.isEnabled = isEnabled;
imageView.setImageResource(icon);
imageView.setAlpha(alpha);
Drawable drawable = imageView.getDrawable();
DrawableCompat.setTint(
drawable instanceof LayerDrawable ? ((LayerDrawable) drawable).getDrawable(0) : drawable,
tint);
imageView.setImageDrawable(DrawableUtil.getWrapped(context, icon));
DrawableUtil.setTint(imageView.getDrawable(), tint);
}
}

@ -3,8 +3,6 @@ package org.tasks.injection
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
@ -19,6 +17,7 @@ import com.todoroo.astrid.api.Filter
import org.tasks.R
import org.tasks.dialogs.DialogBuilder
import org.tasks.preferences.Device
import org.tasks.themes.DrawableUtil
import javax.inject.Inject
@ -33,9 +32,9 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() {
tintIcons(pref.getPreference(i), color)
}
} else {
val icon: Drawable? = pref.icon
if (icon != null) {
DrawableCompat.setTint(icon, color)
if (pref.icon != null) {
pref.icon = DrawableUtil.wrap(pref.icon);
DrawableCompat.setTint(pref.icon, color)
}
}
}
@ -75,11 +74,10 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() {
.show()
}
protected fun tintIcon(resId: Int, tint: Int) {
protected fun tintColorPreference(resId: Int, tint: Int) {
val pref = findPreference(resId)
val icon = DrawableCompat.wrap(pref.icon.mutate())
DrawableCompat.setTint(if (icon is LayerDrawable) icon.getDrawable(0) else icon, tint)
pref.icon = icon
pref.icon = DrawableUtil.getWrapped(context!!, R.drawable.color_picker)
DrawableUtil.setTint(pref.icon, tint)
}
protected fun requires(@StringRes prefGroup: Int, check: Boolean, vararg resIds: Int) {

@ -386,7 +386,7 @@ class LookAndFeel : InjectingPreferenceFragment(), Preference.OnPreferenceChange
palette: ColorPickerAdapter.Palette,
requestCode: Int
) {
tintIcon(prefId, color)
tintColorPreference(prefId, color)
findPreference(prefId).setOnPreferenceClickListener {
if (palette == ColorPickerAdapter.Palette.COLORS) {
newColorWheel(this, requestCode, color)

@ -147,7 +147,7 @@ class ScrollableWidget : InjectingPreferenceFragment() {
}
private fun updateColor() {
tintIcon(R.string.p_widget_color_v2, widgetPreferences.color)
tintColorPreference(R.string.p_widget_color_v2, widgetPreferences.color)
}
private fun updateFilter() {

@ -19,6 +19,7 @@ import org.tasks.caldav.CaldavAccountSettingsActivity;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.etesync.EteSyncAccountSettingsActivity;
import org.tasks.preferences.fragments.SynchronizationKt;
import org.tasks.themes.DrawableUtil;
public class AddAccountDialog {
public static void showAddAccountDialog(Activity activity, DialogBuilder dialogBuilder) {
@ -42,7 +43,7 @@ public class AddAccountDialog {
view.<TextView>findViewById(R.id.text1).setText(services[position]);
view.<TextView>findViewById(R.id.text2).setText(descriptions[position]);
ImageView icon = view.findViewById(R.id.image_view);
icon.setImageResource(icons[position]);
icon.setImageDrawable(DrawableUtil.getWrapped(getContext(), icons[position]));
if (position == 1) {
DrawableCompat.setTint(
icon.getDrawable(), ContextCompat.getColor(getContext(), R.color.icon_tint));

@ -1,15 +1,10 @@
package org.tasks.tags;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -19,6 +14,7 @@ import kotlin.jvm.functions.Function2;
import org.tasks.R;
import org.tasks.data.TagData;
import org.tasks.tags.CheckBoxTriStates.State;
import org.tasks.themes.DrawableUtil;
public class TagPickerViewHolder extends RecyclerView.ViewHolder {
@ -76,14 +72,8 @@ public class TagPickerViewHolder extends RecyclerView.ViewHolder {
icon = R.drawable.ic_outline_label_24px;
}
}
Drawable original = ContextCompat.getDrawable(context, icon);
Drawable wrapped = DrawableCompat.wrap(original.mutate());
DrawableCompat.setTint(wrapped, color);
if (atLeastJellybeanMR1()) {
text.setCompoundDrawablesRelativeWithIntrinsicBounds(wrapped, null, null, null);
} else {
text.setCompoundDrawablesWithIntrinsicBounds(wrapped, null, null, null);
}
DrawableUtil.setLeftDrawable(context, text, icon);
DrawableUtil.setTint(DrawableUtil.getLeftDrawable(text), color);
}
private void updateCheckbox(State state) {

@ -4,14 +4,16 @@ import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import org.jetbrains.annotations.NotNull;
public class DrawableUtil {
public static Drawable getWrapped(Context context, @DrawableRes int resId) {
return DrawableCompat.wrap(ContextCompat.getDrawable(context, resId).mutate());
return wrap(ContextCompat.getDrawable(context, resId));
}
public static void setLeftDrawable(Context context, TextView tv, @DrawableRes int resId) {
@ -28,4 +30,14 @@ public class DrawableUtil {
? tv.getCompoundDrawablesRelative()[0]
: tv.getCompoundDrawables()[0];
}
public static Drawable wrap(@NotNull Drawable icon) {
return DrawableCompat.wrap(icon.mutate());
}
public static void setTint(Drawable drawable, int tint) {
DrawableCompat.setTint(
drawable instanceof LayerDrawable ? ((LayerDrawable) drawable).getDrawable(0) : drawable,
tint);
}
}

@ -3,13 +3,12 @@ package org.tasks.widget;
import android.app.Activity;
import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.widget.ImageView;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
@ -27,6 +26,7 @@ import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
import org.tasks.intents.TaskIntents;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.themes.DrawableUtil;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
@ -55,7 +55,10 @@ public class ShortcutConfigActivity extends ThemedInjectingAppCompatActivity
TextInputEditText shortcutName;
@BindView(R.id.color)
ImageView colorIcon;
TextView colorIcon;
@BindView(R.id.clear)
View clear;
private Filter selectedFilter;
private int selectedTheme;
@ -139,9 +142,10 @@ public class ShortcutConfigActivity extends ThemedInjectingAppCompatActivity
}
private void updateTheme() {
clear.setVisibility(View.GONE);
ThemeColor color = themeCache.getThemeColor(getThemeIndex());
DrawableCompat.setTint(
((LayerDrawable) colorIcon.getDrawable()).getDrawable(0), color.getPrimaryColor());
DrawableUtil.setLeftDrawable(this, colorIcon, R.drawable.color_picker);
DrawableUtil.setTint(DrawableUtil.getLeftDrawable(colorIcon), color.getPrimaryColor());
color.apply(toolbar);
color.applyToSystemBars(this);
}

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size
android:height="24dp"
android:width="24dp" />
<solid android:color="#FF000000" />
</shape>
</item>
<item>
<shape android:shape="oval">
<size
android:height="25dp"
android:width="25dp" />
<solid android:color="@android:color/transparent" />
<stroke
android:color="@color/text_tertiary"
android:width="1dp" />
</shape>
</item>
</layer-list>

@ -1,27 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:height="24dp"
android:width="24dp" />
<size
android:height="24dp"
android:width="24dp" />
<solid android:color="#FF000000" />
</shape>
</item>
<item>
<shape android:shape="oval">
<size
android:height="25dp"
android:width="25dp" />
<solid android:color="@android:color/transparent" />
<stroke
android:color="@color/text_tertiary"
android:width="1dp" />
</shape>
</item>
</layer-list>
<solid android:color="#FF000000" />
</shape>

@ -2,15 +2,14 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
style="@style/TagSettingsRow"
app:layout_constraintStart_toStartOf="@+id/shortcut_name_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/shortcut_name_layout">
<include layout="@layout/list_settings_color" />
@ -22,11 +21,6 @@
style="@style/TagSettingsRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="@dimen/keyline_first"
android:layout_marginEnd="@dimen/keyline_first"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_first"
android:hint="@string/display_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/shortcut_list_layout"
@ -44,11 +38,6 @@
style="@style/TagSettingsRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginStart="@dimen/keyline_first"
android:layout_marginEnd="@dimen/keyline_first"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_first"
android:hint="@string/list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

@ -6,10 +6,7 @@
android:layout_width="@dimen/icon_picker_size"
android:layout_height="@dimen/icon_picker_size"
android:padding="8dp"
android:tint="@color/icon_tint"
android:alpha="@dimen/alpha_secondary"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_outline_label_24px"
android:background="?attr/selectableItemBackgroundBorderless"
tools:ignore="ContentDescription"/>

@ -37,8 +37,7 @@
android:layout_alignParentStart="true"
android:layout_gravity="center_vertical"
android:alpha="@dimen/alpha_secondary"
android:scaleType="center"
android:tint="@color/icon_tint"/>
android:scaleType="center"/>
<CheckedTextView
android:id="@+id/text"

@ -9,17 +9,14 @@
<Preference
android:key="@string/p_theme_color"
android:icon="@drawable/color_picker"
android:title="@string/color" />
<Preference
android:key="@string/p_theme_accent"
android:icon="@drawable/color_picker"
android:title="@string/accent" />
<Preference
android:key="@string/p_theme_launcher"
android:icon="@drawable/color_picker"
android:title="@string/launcher_icon" />
<PreferenceCategory

@ -27,7 +27,6 @@
<Preference
android:key="@string/p_widget_color_v2"
android:icon="@drawable/color_picker"
android:title="@string/color" />
<SwitchPreferenceCompat

Loading…
Cancel
Save