List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:com.miz.functions.MizLib.java
/** * Add a padding with a height of the ActionBar to the top of a given View * @param c/*w w w.j a v a 2 s. c o m*/ * @param v */ public static void addActionBarPadding(Context c, View v) { int mActionBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) v.setPadding(0, mActionBarHeight, 0, 0); }
From source file:com.miz.functions.MizLib.java
/** * Add a padding with a height of the ActionBar to the bottom of a given View * @param c//from w w w . j a v a 2 s .c om * @param v */ public static void addActionBarPaddingBottom(Context c, View v) { int mActionBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) v.setPadding(0, 0, 0, mActionBarHeight); }
From source file:com.miz.functions.MizLib.java
/** * Add a margin with a height of the ActionBar to the top of a given View contained in a FrameLayout * @param c//from w ww . j a v a 2 s .c om * @param v */ public static void addActionBarMargin(Context c, View v) { int mActionBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setMargins(0, mActionBarHeight, 0, 0); v.setLayoutParams(params); }
From source file:com.miz.functions.MizLib.java
/** * Add a margin with a height of the ActionBar to the top of a given View contained in a FrameLayout * @param c/* w w w .j a v a 2 s . c o m*/ * @param v */ public static void addActionBarMarginBottom(Context c, View v) { int mActionBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setMargins(0, 0, 0, mActionBarHeight); v.setLayoutParams(params); }
From source file:com.lab47billion.appchooser.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); _context = context;//www . j a va 2 s. c o m // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true); mTextPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = mSideItems; try { mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (mTextColor == null) { mTextColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize); mNormalTextSize = a.getDimension(R.styleable.HorizontalPicker_normalTextSize, 20); mSelectedTextSize = a.getDimension(R.styleable.HorizontalPicker_selectedTextSize, -1); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); if (mNormalTextSize > -1) { setTextSize(mNormalTextSize); } if (mSelectedTextSize == -1) { mSelectedTextSize = mNormalTextSize; } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt(); mBoringMetrics = new BoringLayout.Metrics(); mBoringMetrics.ascent = fontMetricsInt.ascent; mBoringMetrics.bottom = fontMetricsInt.bottom; mBoringMetrics.descent = fontMetricsInt.descent; mBoringMetrics.leading = fontMetricsInt.leading; mBoringMetrics.top = fontMetricsInt.top; mBoringMetrics.width = mItemWidth; setWillNotDraw(false); mFlingScrollerX = new OverScroller(context); mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mOverscrollDistance = configuration.getScaledOverscrollDistance(); mPreviousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); /*mTouchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper);*/ }
From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java
private boolean initializePanelMenu() { Context context = mActivity;//getContext(); // If we have an action bar, initialize the menu with a context themed for it. if (wActionBar != null) { TypedValue outValue = new TypedValue(); Resources.Theme currentTheme = context.getTheme(); currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true); final int targetThemeRes = outValue.resourceId; if (targetThemeRes != 0 /*&& context.getThemeResId() != targetThemeRes*/) { context = new ContextThemeWrapper(context, targetThemeRes); }/*from w w w .java 2s .com*/ } mMenu = new MenuBuilder(context); mMenu.setCallback(this); return true; }
From source file:com.miz.functions.MizLib.java
/** * Add a padding with a combined height of the ActionBar and Status bar to the top of a given View * @param c/*w w w.j a v a 2s . com*/ * @param v */ public static void addActionBarAndStatusBarPadding(Context c, View v) { int mActionBarHeight = 0, mStatusBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) if (hasKitKat()) mStatusBarHeight = convertDpToPixels(c, 25); v.setPadding(0, mActionBarHeight + mStatusBarHeight, 0, 0); }
From source file:com.miz.functions.MizLib.java
/** * Add a margin with a combined height of the ActionBar and Status bar to the top of a given View contained in a FrameLayout * @param c/*from w w w . j ava 2 s .c om*/ * @param v */ public static void addActionBarAndStatusBarMargin(Context c, View v) { int mActionBarHeight = 0, mStatusBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) if (hasKitKat()) mStatusBarHeight = convertDpToPixels(c, 25); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setMargins(0, mActionBarHeight + mStatusBarHeight, 0, 0); v.setLayoutParams(params); }
From source file:com.owen.view.views.PieChart.java
/** * Class constructor taking a context and an attribute set. This constructor * is used by the layout engine to construct a {@link com.owen.view.views.PieChart} from a set of * XML attributes./* w ww . jav a 2s . c om*/ * * @param context * @param attrs An attribute set which can contain attributes from * {@link PieChart} as well as attributes inherited * from {@link android.view.View}. */ public PieChart(Context context, AttributeSet attrs) { super(context, attrs); // attrs contains the raw values for the XML attributes // that were specified in the layout, which don't include // attributes set by styles or themes, and which may have // unresolved references. Call obtainStyledAttributes() // to get the final values for each attribute. // // This call uses R.styleable.PieChart, which is an array of // the custom attributes that were declared in attrs.xml. TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PieChart, 0, 0); try { // Retrieve the values from the TypedArray and store into // fields of this class. // // The R.styleable.PieChart_* constants represent the index for // each custom attribute in the R.styleable.PieChart array. mShowText = a.getBoolean(R.styleable.PieChart_pie_showText, false); mTextY = a.getDimension(R.styleable.PieChart_pie_labelY, 0.0f); mTextWidth = a.getDimension(R.styleable.PieChart_pie_labelWidth, 0.0f); mTextHeight = a.getDimension(R.styleable.PieChart_pie_labelHeight, 0.0f); mTextPos = a.getInteger(R.styleable.PieChart_pie_labelPosition, 0); mTextColor = a.getColor(R.styleable.PieChart_pie_labelColor, 0xff000000); mHighlightStrength = a.getFloat(R.styleable.PieChart_pie_highlightStrength, 1.0f); mPieRotation = a.getInt(R.styleable.PieChart_pie_pieRotation, 0); mPointerRadius = a.getDimension(R.styleable.PieChart_pie_pointerRadius, 2.0f); mAutoCenterInSlice = a.getBoolean(R.styleable.PieChart_pie_autoCenterPointerInSlice, false); } finally { // release the TypedArray so that it can be reused. a.recycle(); } init(); }
From source file:nuclei.ui.view.ButtonBarView.java
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ButtonBarView, defStyleAttr, defStyleRes);// w ww .j a v a2s.c o m final boolean bottom = a.getBoolean(R.styleable.ButtonBarView_bottom, false); final int layout = a.getResourceId(R.styleable.ButtonBarView_control_layout, bottom ? R.layout.cyto_view_button_bar_bottom : R.layout.cyto_view_button_bar); final View view = LayoutInflater.from(context).inflate(layout, this, false); addView(view); mButtons = (LinearLayout) view.findViewById(R.id.buttons); mOrientation = a.getInt(R.styleable.ButtonBarView_control_orientation, 1); switch (mOrientation) { case 1: mButtons.setOrientation(LinearLayout.HORIZONTAL); break; case 2: mButtons.setOrientation(LinearLayout.VERTICAL); break; } mSelectedTint = a.getColor(R.styleable.ButtonBarView_selected_color, ResourcesCompat.getColor(getResources(), R.color.black, context.getTheme())); mUnselectedTint = a.getColor(R.styleable.ButtonBarView_unselected_color, ResourcesCompat.getColor(getResources(), R.color.grey, context.getTheme())); if (a.hasValue(R.styleable.ButtonBarView_buttons_background)) { final int color = a.getColor(R.styleable.ButtonBarView_buttons_background, Color.WHITE); View v = view.findViewById(R.id.buttons_container); if (v != null) v.setBackgroundColor(color); else mButtons.setBackgroundColor(color); } a.recycle(); }