Backport dark theme to pre-lollipop devices

pull/84/head
Alinson S. Xavier 10 years ago
parent 3de702ced2
commit b42565b770

@ -21,6 +21,7 @@ package org.isoron.uhabits.helpers;
import android.content.Context; import android.content.Context;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -37,7 +38,8 @@ import java.util.GregorianCalendar;
public class ListHabitsHelper public class ListHabitsHelper
{ {
private int inactiveColor; private final int lowContrastColor;
private final int mediumContrastColor;
private final Context context; private final Context context;
private final HabitListLoader loader; private final HabitListLoader loader;
@ -48,7 +50,8 @@ public class ListHabitsHelper
this.context = context; this.context = context;
this.loader = loader; this.loader = loader;
inactiveColor = UIHelper.getStyledColor(context, R.attr.lowContrastTextColor); lowContrastColor = UIHelper.getStyledColor(context, R.attr.lowContrastTextColor);
mediumContrastColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
fontawesome = Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf"); fontawesome = Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
} }
@ -95,7 +98,7 @@ public class ListHabitsHelper
public int getActiveColor(Habit habit) public int getActiveColor(Habit habit)
{ {
int activeColor = ColorHelper.getColor(context, habit.color); int activeColor = ColorHelper.getColor(context, habit.color);
if(habit.isArchived()) activeColor = inactiveColor; if(habit.isArchived()) activeColor = mediumContrastColor;
return activeColor; return activeColor;
} }
@ -129,12 +132,12 @@ public class ListHabitsHelper
if (score < Score.HALF_STAR_CUTOFF) if (score < Score.HALF_STAR_CUTOFF)
{ {
tvStar.setText(context.getString(R.string.fa_star_o)); tvStar.setText(context.getString(R.string.fa_star_o));
tvStar.setTextColor(inactiveColor); tvStar.setTextColor(lowContrastColor);
} }
else if (score < Score.FULL_STAR_CUTOFF) else if (score < Score.FULL_STAR_CUTOFF)
{ {
tvStar.setText(context.getString(R.string.fa_star_half_o)); tvStar.setText(context.getString(R.string.fa_star_half_o));
tvStar.setTextColor(inactiveColor); tvStar.setTextColor(lowContrastColor);
} }
else else
{ {
@ -156,13 +159,13 @@ public class ListHabitsHelper
case 1: case 1:
tvCheck.setText(R.string.fa_check); tvCheck.setText(R.string.fa_check);
tvCheck.setTextColor(inactiveColor); tvCheck.setTextColor(lowContrastColor);
tvCheck.setTag(R.string.toggle_key, 1); tvCheck.setTag(R.string.toggle_key, 1);
break; break;
case 0: case 0:
tvCheck.setText(R.string.fa_times); tvCheck.setText(R.string.fa_times);
tvCheck.setTextColor(inactiveColor); tvCheck.setTextColor(lowContrastColor);
tvCheck.setTag(R.string.toggle_key, 0); tvCheck.setTag(R.string.toggle_key, 0);
break; break;
} }
@ -197,13 +200,23 @@ public class ListHabitsHelper
public void updateHabitCardBackground(View view, boolean isSelected) public void updateHabitCardBackground(View view, boolean isSelected)
{ {
if (isSelected) if (android.os.Build.VERSION.SDK_INT >= 21)
view.setBackgroundResource(R.drawable.selected_box);
else
{ {
if (android.os.Build.VERSION.SDK_INT >= 21) if (isSelected)
view.setBackgroundResource(R.drawable.selected_box);
else
view.setBackgroundResource(R.drawable.ripple); view.setBackgroundResource(R.drawable.ripple);
else view.setBackgroundResource(R.drawable.card_background); }
else
{
Drawable background;
if (isSelected)
background = UIHelper.getStyledDrawable(context, R.attr.selectedBackground);
else
background = UIHelper.getStyledDrawable(context, R.attr.cardBackground);
view.setBackgroundDrawable(background);
} }
} }

@ -25,6 +25,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Debug; import android.os.Debug;
import android.os.Looper; import android.os.Looper;
@ -187,6 +188,16 @@ public abstract class UIHelper
return color; return color;
} }
public static Drawable getStyledDrawable(Context context, int attrId)
{
int[] attrs = new int[]{ attrId };
TypedArray ta = context.obtainStyledAttributes(attrs);
Drawable drawable = ta.getDrawable(0);
ta.recycle();
return drawable;
}
public static boolean getStyledBoolean(Context context, int attrId) public static boolean getStyledBoolean(Context context, int attrId)
{ {
int[] attrs = new int[]{ attrId }; int[] attrs = new int[]{ attrId };

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="0dp"
android:bottom="0dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="@color/black" />
</shape>
</item>
<item
android:top="0dp"
android:bottom="1dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="@color/black" />
</shape>
</item>
<item
android:top="0dp"
android:bottom="1.5dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="@color/black"/>
</shape>
</item>
<item
android:top="0.5dp"
android:bottom="1.5dp"
android:left="0.5dp"
android:right="0.5dp">
<shape>
<solid android:color="@color/black"/>
</shape>
</item>
</layer-list>

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="0dp"
android:bottom="0dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="#202020" />
</shape>
</item>
<item
android:top="0dp"
android:bottom="1dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="#101010" />
</shape>
</item>
<item
android:top="0dp"
android:bottom="1.5dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="#202020"/>
</shape>
</item>
<item
android:top="0.5dp"
android:bottom="1.5dp"
android:left="0.5dp"
android:right="0.5dp">
<shape>
<solid android:color="@color/grey_850"/>
</shape>
</item>
</layer-list>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="40dp">
<shape android:shape="rectangle" >
<gradient
android:startColor="@color/black"
android:endColor="@color/black"
android:angle="270"/>
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle" >
<solid android:color="@color/black" />
</shape>
</item>
</layer-list>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="40dp">
<shape android:shape="rectangle" >
<gradient
android:startColor="#30000000"
android:endColor="#00000000"
android:angle="270"/>
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle" >
<solid android:color="#202020" />
</shape>
</item>
</layer-list>

@ -20,7 +20,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="40dp"> <item android:top="44dp">
<shape android:shape="rectangle" > <shape android:shape="rectangle" >
<gradient <gradient
android:startColor="#30000000" android:startColor="#30000000"

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/black" />
<stroke android:width="2dip" android:color="@color/grey_500"/>
</shape>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/grey_800" />
<stroke android:width="2dip" android:color="@color/grey_500"/>
</shape>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/grey_100" />
<stroke android:width="2dip" android:color="@color/grey_500"/>
</shape>

@ -34,4 +34,9 @@
<attr name="highContrastReverseTextColor" format="reference"/> <attr name="highContrastReverseTextColor" format="reference"/>
<attr name="mediumContrastReverseTextColor" format="reference"/> <attr name="mediumContrastReverseTextColor" format="reference"/>
<attr name="lowContrastReverseTextColor" format="reference"/> <attr name="lowContrastReverseTextColor" format="reference"/>
<!-- Pre-Lollipop -->
<attr name="cardBackground" format="reference"/>
<attr name="headerBackground" format="reference"/>
<attr name="selectedBackground" format="reference"/>
</resources> </resources>

@ -22,6 +22,62 @@
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"> <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:spinnerItemStyle">@style/dialogFormText</item> <item name="android:spinnerItemStyle">@style/dialogFormText</item>
<item name="android:spinnerDropDownItemStyle">@style/dialogFormSpinnerDropDown</item> <item name="android:spinnerDropDownItemStyle">@style/dialogFormSpinnerDropDown</item>
<item name="selectedBackground">@drawable/selected_box_light</item>
<item name="headerBackground">@drawable/habits_list_header_light_background</item>
<item name="cardBackground">@drawable/card_light_background</item>
<item name="cardBackgroundColor">@color/white</item>
<item name="windowBackgroundColor">@color/grey_200</item>
<item name="headerBackgroundColor">@color/grey_200</item>
<item name="android:textColor">@color/grey_800</item>
<item name="useHabitColorAsPrimary">true</item>
<item name="palette">@array/lightPalette</item>
<item name="highContrastReverseTextColor">@color/white</item>
<item name="mediumContrastReverseTextColor">@color/grey_500</item>
<item name="lowContrastReverseTextColor">@color/grey_700</item>
<item name="highContrastTextColor">@color/grey_800</item>
<item name="mediumContrastTextColor">@color/grey_500</item>
<item name="lowContrastTextColor">@color/grey_300</item>
<item name="aboutScreenColor">@color/blue_700</item>
</style>
<style name="AppBaseThemeDark" parent="android:Theme.Holo">
<item name="selectedBackground">@drawable/selected_box_dark</item>
<item name="headerBackground">@drawable/habits_list_header_dark_background</item>
<item name="cardBackground">@drawable/card_dark_background</item>
<item name="cardBackgroundColor">@color/grey_850</item>
<item name="windowBackgroundColor">@color/grey_900</item>
<item name="headerBackgroundColor">@color/grey_900</item>
<item name="android:textColor">@color/grey_100</item>
<item name="useHabitColorAsPrimary">false</item>
<item name="highContrastTextColor">@color/grey_100</item>
<item name="mediumContrastTextColor">@color/grey_500</item>
<item name="lowContrastTextColor">@color/grey_800</item>
<item name="highContrastReverseTextColor">@color/grey_900</item>
<item name="mediumContrastReverseTextColor">@color/grey_700</item>
<item name="lowContrastReverseTextColor">@color/grey_300</item>
<item name="palette">@array/darkPalette</item>
<item name="aboutScreenColor">@color/blue_300</item>
</style>
<style name="AppBaseThemeDark.PureBlack">
<item name="selectedBackground">@drawable/selected_box_amoled</item>
<item name="headerBackground">@drawable/habits_list_header_amoled_background</item>
<item name="cardBackground">@drawable/card_amoled_background</item>
<item name="cardBackgroundColor">@color/black</item>
<item name="windowBackgroundColor">@color/black</item>
<item name="headerBackgroundColor">@color/black</item>
<item name="lowContrastTextColor">@color/grey_900</item>
<item name="highContrastReverseTextColor">@color/black</item>
</style> </style>
<style name="time_label"> <style name="time_label">
@ -56,7 +112,7 @@
<item name="android:layout_marginBottom">3dp</item> <item name="android:layout_marginBottom">3dp</item>
<item name="android:layout_marginLeft">3dp</item> <item name="android:layout_marginLeft">3dp</item>
<item name="android:layout_marginRight">3dp</item> <item name="android:layout_marginRight">3dp</item>
<item name="android:background">@color/white</item> <item name="android:background">?cardBackground</item>
</style> </style>
<style name="Card" parent="CardCommon"> <style name="Card" parent="CardCommon">

@ -25,7 +25,7 @@
</style> </style>
<style name="ListHabits.Header"> <style name="ListHabits.Header">
<item name="android:background">@drawable/habits_list_header_background</item> <item name="android:background">?headerBackground</item>
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentTop">true</item> <item name="android:layout_alignParentTop">true</item>
@ -38,6 +38,7 @@
<item name="android:layout_height">match_parent</item> <item name="android:layout_height">match_parent</item>
<item name="android:gravity">center</item> <item name="android:gravity">center</item>
<item name="android:textSize">16sp</item> <item name="android:textSize">16sp</item>
<item name="android:background">@color/transparent</item>
</style> </style>
<style name="ListHabits.Label"> <style name="ListHabits.Label">

Loading…
Cancel
Save