mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Do not use habit color as primary color on dark themes
This commit is contained in:
@@ -21,11 +21,13 @@ package org.isoron.uhabits;
|
|||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.isoron.uhabits.helpers.ColorHelper;
|
import org.isoron.uhabits.helpers.ColorHelper;
|
||||||
|
import org.isoron.uhabits.helpers.UIHelper;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
public class ShowHabitActivity extends BaseActivity
|
public class ShowHabitActivity extends BaseActivity
|
||||||
@@ -44,11 +46,17 @@ public class ShowHabitActivity extends BaseActivity
|
|||||||
if(actionBar != null && getHabit() != null)
|
if(actionBar != null && getHabit() != null)
|
||||||
{
|
{
|
||||||
actionBar.setTitle(getHabit().name);
|
actionBar.setTitle(getHabit().name);
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 21 &&
|
||||||
|
UIHelper.getStyledBoolean(this, R.attr.useHabitColorAsPrimary))
|
||||||
{
|
{
|
||||||
int androidColor = ColorHelper.getColor(this, getHabit().color);
|
int androidColor = ColorHelper.getColor(this, getHabit().color);
|
||||||
ColorDrawable drawable = new ColorDrawable(androidColor);
|
ColorDrawable drawable = new ColorDrawable(androidColor);
|
||||||
actionBar.setBackgroundDrawable(drawable);
|
actionBar.setBackgroundDrawable(drawable);
|
||||||
|
|
||||||
|
int color = ColorHelper.getColor(this, habit.color);
|
||||||
|
int darkerHabitColor = ColorHelper.mixColors(color, Color.BLACK, 0.75f);
|
||||||
|
getWindow().setStatusBarColor(darkerHabitColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.fragments;
|
|||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@@ -170,15 +169,6 @@ public class ShowHabitFragment extends Fragment
|
|||||||
|
|
||||||
private void updateHeaders(View view)
|
private void updateHeaders(View view)
|
||||||
{
|
{
|
||||||
if(habit == null | activity == null) return;
|
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
|
||||||
{
|
|
||||||
int color = ColorHelper.getColor(getActivity(), habit.color);
|
|
||||||
int darkerHabitColor = ColorHelper.mixColors(color, Color.BLACK, 0.75f);
|
|
||||||
activity.getWindow().setStatusBarColor(darkerHabitColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateColor(view, R.id.tvHistory);
|
updateColor(view, R.id.tvHistory);
|
||||||
updateColor(view, R.id.tvOverview);
|
updateColor(view, R.id.tvOverview);
|
||||||
updateColor(view, R.id.tvStrength);
|
updateColor(view, R.id.tvStrength);
|
||||||
@@ -188,7 +178,7 @@ public class ShowHabitFragment extends Fragment
|
|||||||
|
|
||||||
private void updateColor(View view, int viewId)
|
private void updateColor(View view, int viewId)
|
||||||
{
|
{
|
||||||
if(habit == null) return;
|
if(habit == null || activity == null) return;
|
||||||
|
|
||||||
TextView textView = (TextView) view.findViewById(viewId);
|
TextView textView = (TextView) view.findViewById(viewId);
|
||||||
int androidColor = ColorHelper.getColor(activity, habit.color);
|
int androidColor = ColorHelper.getColor(activity, habit.color);
|
||||||
|
|||||||
@@ -181,4 +181,13 @@ public abstract class UIHelper
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getStyledBoolean(Context context, int attrId)
|
||||||
|
{
|
||||||
|
int[] attrs = new int[]{ attrId };
|
||||||
|
TypedArray ta = context.obtainStyledAttributes(attrs);
|
||||||
|
boolean bool = ta.getBoolean(0, false);
|
||||||
|
ta.recycle();
|
||||||
|
|
||||||
|
return bool;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<item name="fadedTextColor">@color/grey_600</item>
|
<item name="fadedTextColor">@color/grey_600</item>
|
||||||
<item name="inactiveCheckmarkColor">@color/grey_300</item>
|
<item name="inactiveCheckmarkColor">@color/grey_300</item>
|
||||||
<item name="secondaryTextColor">@color/grey_800</item>
|
<item name="secondaryTextColor">@color/grey_800</item>
|
||||||
|
<item name="useHabitColorAsPrimary">true</item>
|
||||||
<item name="palette">@array/lightPalette</item>
|
<item name="palette">@array/lightPalette</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@
|
|||||||
<item name="fadedTextColor">@color/grey_500</item>
|
<item name="fadedTextColor">@color/grey_500</item>
|
||||||
<item name="inactiveCheckmarkColor">@color/grey_700</item>
|
<item name="inactiveCheckmarkColor">@color/grey_700</item>
|
||||||
<item name="secondaryTextColor">@color/grey_100</item>
|
<item name="secondaryTextColor">@color/grey_100</item>
|
||||||
|
<item name="useHabitColorAsPrimary">false</item>
|
||||||
|
|
||||||
<item name="palette">@array/darkPalette</item>
|
<item name="palette">@array/darkPalette</item>
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -26,6 +26,6 @@
|
|||||||
<attr name="secondaryTextColor" format="reference"/>
|
<attr name="secondaryTextColor" format="reference"/>
|
||||||
<attr name="inactiveCheckmarkColor" format="reference"/>
|
<attr name="inactiveCheckmarkColor" format="reference"/>
|
||||||
<attr name="highlightedBackgroundColor" format="reference"/>
|
<attr name="highlightedBackgroundColor" format="reference"/>
|
||||||
|
<attr name="useHabitColorAsPrimary" format="boolean"/>
|
||||||
<attr name="palette" format="reference"/>
|
<attr name="palette" format="reference"/>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user