New UI
This commit is contained in:
parent
fbd5e8bb61
commit
3f3818efb7
270 changed files with 7441 additions and 6502 deletions
|
@ -4,29 +4,17 @@ import android.annotation.TargetApi;
|
|||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.preference.Preference;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Switch;
|
||||
|
||||
import code.name.monkey.appthemehelper.ATH;
|
||||
import code.name.monkey.appthemehelper.R;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.common.views.ATESwitch;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import code.name.monkey.appthemehelper.R;
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class ATESwitchPreference extends SwitchPreference {
|
||||
|
||||
static final boolean COMPAT_MODE = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
|
||||
|
||||
private ATESwitch mSwitch;
|
||||
public class ATESwitchPreference extends ATEPreference {
|
||||
|
||||
public ATESwitchPreference(Context context) {
|
||||
super(context);
|
||||
|
@ -51,64 +39,20 @@ public class ATESwitchPreference extends SwitchPreference {
|
|||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setLayoutResource(R.layout.ate_preference_custom);
|
||||
if (COMPAT_MODE) {
|
||||
setWidgetLayoutResource(R.layout.ate_preference_switch);
|
||||
} else {
|
||||
try {
|
||||
Field canRecycleLayoutField = Preference.class.getDeclaredField("mCanRecycleLayout");
|
||||
canRecycleLayoutField.setAccessible(true);
|
||||
canRecycleLayoutField.setBoolean(this, true);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Field hasSpecifiedLayout = Preference.class.getDeclaredField("mHasSpecifiedLayout");
|
||||
hasSpecifiedLayout.setAccessible(true);
|
||||
hasSpecifiedLayout.setBoolean(this, true);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
Field canRecycleLayoutField = Preference.class.getDeclaredField("mCanRecycleLayout");
|
||||
canRecycleLayoutField.setAccessible(true);
|
||||
canRecycleLayoutField.setBoolean(this, true);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Field hasSpecifiedLayout = Preference.class.getDeclaredField("mHasSpecifiedLayout");
|
||||
hasSpecifiedLayout.setAccessible(true);
|
||||
hasSpecifiedLayout.setBoolean(this, true);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
if (COMPAT_MODE) {
|
||||
mSwitch = (ATESwitch) view.findViewById(R.id.switchWidget);
|
||||
mSwitch.setChecked(isChecked());
|
||||
} else {
|
||||
View parentSwitch = findSwitchView(view);
|
||||
if (parentSwitch != null) {
|
||||
ATH.setTint(parentSwitch, ThemeStore.accentColor(view.getContext()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private View findSwitchView(View view) {
|
||||
if (view instanceof ViewGroup) {
|
||||
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
|
||||
View child = ((ViewGroup) view).getChildAt(i);
|
||||
if (child instanceof Switch || child instanceof SwitchCompat) {
|
||||
return child;
|
||||
} else if (child instanceof ViewGroup) {
|
||||
View potentialSwitch = findSwitchView(child);
|
||||
if (potentialSwitch != null) return potentialSwitch;
|
||||
}
|
||||
}
|
||||
} else if (view instanceof Switch || view instanceof SwitchCompat) {
|
||||
return view;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {
|
||||
super.setChecked(checked);
|
||||
if (COMPAT_MODE) {
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setChecked(checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package code.name.monkey.appthemehelper.util;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.design.widget.NavigationView;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public final class NavigationViewUtil {
|
||||
|
||||
private NavigationViewUtil() {
|
||||
}
|
||||
|
||||
public static void setItemIconColors(@NonNull NavigationView navigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
|
||||
final ColorStateList iconSl = new ColorStateList(
|
||||
new int[][]{
|
||||
new int[]{-android.R.attr.state_checked},
|
||||
new int[]{android.R.attr.state_checked}
|
||||
},
|
||||
new int[]{
|
||||
normalColor,
|
||||
selectedColor
|
||||
});
|
||||
navigationView.setItemIconTintList(iconSl);
|
||||
}
|
||||
|
||||
public static void setItemTextColors(@NonNull NavigationView navigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
|
||||
final ColorStateList textSl = new ColorStateList(
|
||||
new int[][]{
|
||||
new int[]{-android.R.attr.state_checked},
|
||||
new int[]{android.R.attr.state_checked}
|
||||
},
|
||||
new int[]{
|
||||
normalColor,
|
||||
selectedColor
|
||||
});
|
||||
navigationView.setItemTextColor(textSl);
|
||||
}
|
||||
|
||||
public static void setItemIconColors(@NonNull BottomNavigationView bottomNavigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
|
||||
final ColorStateList iconSl = new ColorStateList(
|
||||
new int[][]{
|
||||
new int[]{-android.R.attr.state_checked},
|
||||
new int[]{android.R.attr.state_checked}
|
||||
},
|
||||
new int[]{
|
||||
normalColor,
|
||||
selectedColor
|
||||
});
|
||||
bottomNavigationView.setItemIconTintList(iconSl);
|
||||
}
|
||||
|
||||
public static void setItemTextColors(@NonNull BottomNavigationView bottomNavigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
|
||||
final ColorStateList textSl = new ColorStateList(
|
||||
new int[][]{
|
||||
new int[]{-android.R.attr.state_checked},
|
||||
new int[]{android.R.attr.state_checked}
|
||||
},
|
||||
new int[]{
|
||||
normalColor,
|
||||
selectedColor
|
||||
});
|
||||
bottomNavigationView.setItemTextColor(textSl);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<code.name.monkey.appthemehelper.common.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/switchWidget"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:button="@drawable/ate_switch"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
android:id="@+id/switchWidget"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:button="@drawable/ate_switch"
|
||||
android:clickable="false"
|
||||
android:focusable="false" />
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<code.name.monkey.appthemehelper.common.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
android:id="@android:id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false" />
|
Loading…
Add table
Add a link
Reference in a new issue