diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 3 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 6 | ||||
-rw-r--r-- | src/com/cyngn/theme/perapptheming/PerAppThemeListView.java | 9 | ||||
-rw-r--r-- | src/com/cyngn/theme/util/Utils.java | 31 | ||||
-rw-r--r-- | src/com/cyngn/theme/widget/LatoTextView.java | 47 |
5 files changed, 72 insertions, 24 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 5fce6fa..a40a338 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -520,8 +520,7 @@ public class ChooserActivity extends FragmentActivity v.getLocationOnScreen(coordinates); final int top = coordinates[1]; final int bottom = coordinates[1] + v.getHeight(); - final int statusBarHeight = res.getDimensionPixelSize( - com.android.internal.R.dimen.status_bar_height); + final int statusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); int selectorTop = getWindowManager().getDefaultDisplay().getHeight() - height; if (bottom > selectorTop) { slideContentIntoView(bottom - selectorTop, height); diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index bd69d35..585dd67 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -616,7 +616,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb private void adjustScrollViewPaddingTop() { Resources res = getResources(); int extraPadding = - res.getDimensionPixelSize(R.dimen.system_bar_height) / 2; + res.getDimensionPixelSize(R.dimen.navigation_bar_height) / 2; mScrollView.setPadding(mScrollView.getPaddingLeft(), mScrollView.getPaddingTop() + extraPadding, mScrollView.getPaddingRight(), mScrollView.getPaddingBottom()); @@ -688,7 +688,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb (LinearLayout.LayoutParams) child.getLayoutParams(); if (child == mStatusBarCard) { int statusBarHeight = getResources() - .getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); + .getDimensionPixelSize(R.dimen.status_bar_height); lparams.setMargins(0, top + statusBarHeight, 0, 0); } else { lparams.setMargins(0, top, 0, 0); @@ -780,7 +780,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int paddingTop = (int) r.getDimension(R.dimen.collapsed_theme_page_padding_top); if (!Utils.hasNavigationBar(getActivity())) { paddingTop += - r.getDimensionPixelSize(R.dimen.system_bar_height) / 2; + r.getDimensionPixelSize(R.dimen.navigation_bar_height) / 2; } mScrollView.setPadding(0, paddingTop, 0, 0); diff --git a/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java b/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java index 646cb49..5a4424f 100644 --- a/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java +++ b/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java @@ -4,10 +4,12 @@ package com.cyngn.theme.perapptheming; import android.content.Context; +import android.content.res.Resources; import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.ListView; import com.cyngn.theme.chooser.R; +import com.cyngn.theme.util.Utils; public class PerAppThemeListView extends ListView { private int mMinHeight; @@ -23,8 +25,11 @@ public class PerAppThemeListView extends ListView { public PerAppThemeListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View); - mMinHeight = a.getDimensionPixelSize(com.android.internal.R.styleable.View_minHeight, 0); + final Resources res = getResources(); + TypedArray a = context.obtainStyledAttributes(attrs, + Utils.getResourceDeclareStyleableIntArray("com.android.internal", "View")); + int resId = res.getIdentifier("View_minHeight", "styleable", "android"); + mMinHeight = a.getDimensionPixelSize(resId, 0); a.recycle(); a = context.obtainStyledAttributes(attrs, R.styleable.PerAppThemeListView); diff --git a/src/com/cyngn/theme/util/Utils.java b/src/com/cyngn/theme/util/Utils.java index 720a542..68c4211 100644 --- a/src/com/cyngn/theme/util/Utils.java +++ b/src/com/cyngn/theme/util/Utils.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.Field; import java.util.List; import java.util.Map; @@ -515,4 +516,34 @@ public class Utils { && homeInfo.packageName.equals(component.getPackageName()) && homeInfo.name.equals(component.getClassName()); } + + /** + * Returns the resource-IDs for all attributes specified in the given + * <declare-styleable>-resource tag as an int array. + * stackoverflow.com/questions/13816596/accessing-declare-styleable-resources-programatically + * + * @param name + * @return + */ + public static final int[] getResourceDeclareStyleableIntArray(String pkgName, String name) { + try { + //use reflection to access the resource class + Field[] fields2 = + Class.forName(pkgName + ".R$styleable").getFields(); + + //browse all fields + for (Field f : fields2) { + //pick matching field + if (f.getName().equals(name)) { + //return as int array + int[] ret = (int[])f.get(null); + return ret; + } + } + } + catch (Throwable t) { + } + + return null; + } } diff --git a/src/com/cyngn/theme/widget/LatoTextView.java b/src/com/cyngn/theme/widget/LatoTextView.java index 2c74eaa..fe39e5c 100644 --- a/src/com/cyngn/theme/widget/LatoTextView.java +++ b/src/com/cyngn/theme/widget/LatoTextView.java @@ -10,6 +10,7 @@ import android.content.res.TypedArray; import android.graphics.Typeface; import android.util.AttributeSet; import android.widget.TextView; +import com.cyngn.theme.util.Utils; import java.io.File; @@ -52,6 +53,10 @@ public class LatoTextView extends TextView { private static Typeface[] sLatoLightTypeface; private static final Object sLock = new Object(); + // Retrieving these attributes is done via reflection so let's just do this once and share + // it amongst the other instances of LatoTextView + private static int[] sTextViewStyleAttributes; + public LatoTextView(Context context) { this(context, null); } @@ -100,29 +105,37 @@ public class LatoTextView extends TextView { } final Resources.Theme theme = context.getTheme(); - TypedArray a = theme.obtainStyledAttributes( - attrs, com.android.internal.R.styleable.TextView, defStyle, 0); - String fontFamily = "sans-serif"; - int styleIndex = Typeface.NORMAL; - if (a != null) { - int n = a.getIndexCount(); - for (int i = 0; i < n; i++) { - int attr = a.getIndex(i); + if (sTextViewStyleAttributes == null) { + sTextViewStyleAttributes = + Utils.getResourceDeclareStyleableIntArray("com.android.internal", "TextView"); + } - switch (attr) { - case com.android.internal.R.styleable.TextView_fontFamily: - fontFamily = a.getString(attr); - break; + if (sTextViewStyleAttributes != null) { + TypedArray a = + theme.obtainStyledAttributes(attrs, sTextViewStyleAttributes, defStyle, 0); + String fontFamily = "sans-serif"; + int styleIndex = Typeface.NORMAL; + if (a != null) { + int n = a.getIndexCount(); + for (int i = 0; i < n; i++) { + int attr = a.getIndex(i); - case com.android.internal.R.styleable.TextView_textStyle: + final Resources res = getResources(); + int attrFontFamily = + res.getIdentifier("TextView_fontFamily", "styleable", "android"); + int attrTextStyle = + res.getIdentifier("TextView_textStyle", "styleable", "android"); + if (attr == attrFontFamily) { + fontFamily = a.getString(attr); + } else if (attr == attrTextStyle) { styleIndex = a.getInt(attr, styleIndex); - break; + } } + a.recycle(); } - a.recycle(); - } - setTypefaceFromAttrs(fontFamily, styleIndex); + setTypefaceFromAttrs(fontFamily, styleIndex); + } } private void setTypefaceFromAttrs(String familyName, int styleIndex) { |