List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:org.getlantern.firetweet.util.Utils.java
public static int getActionBarHeight(@Nullable android.support.v7.app.ActionBar actionBar) { if (actionBar == null) return 0; final Context context = actionBar.getThemedContext(); final TypedValue tv = new TypedValue(); final int height = actionBar.getHeight(); if (height > 0) return height; if (context.getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); }// w ww. j a v a 2s .c om return 0; }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) { if (mDelegates != null && !mDelegates.isEmpty()) { if (mKnownDrawableIdTags != null) { final String cachedTagName = mKnownDrawableIdTags.get(resId); if (SKIP_DRAWABLE_TAG.equals(cachedTagName) || (cachedTagName != null && mDelegates.get(cachedTagName) == null)) { // If we don't have a delegate for the drawable tag, or we've been set to // skip it, fail fast and return null if (DEBUG) { Log.d(TAG, "[loadDrawableFromDelegates] Skipping drawable: " + context.getResources().getResourceName(resId)); }// ww w . ja v a2 s .co m return null; } } else { // Create an id cache as we'll need one later mKnownDrawableIdTags = new SparseArray<>(); } if (mTypedValue == null) { mTypedValue = new TypedValue(); } final TypedValue tv = mTypedValue; final Resources res = context.getResources(); res.getValue(resId, tv, true); final long key = (((long) tv.assetCookie) << 32) | tv.data; Drawable dr = getCachedDelegateDrawable(context, key); if (dr != null) { if (DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Returning cached drawable: " + context.getResources().getResourceName(resId)); } // We have a cached drawable, return it! return dr; } if (tv.string != null && tv.string.toString().endsWith(".xml")) { // If the resource is an XML file, let's try and parse it try { final XmlPullParser parser = res.getXml(resId); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final String tagName = parser.getName(); // Add the tag name to the cache mKnownDrawableIdTags.append(resId, tagName); // Now try and find a delegate for the tag name and inflate if found final InflateDelegate delegate = mDelegates.get(tagName); if (delegate != null) { dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme()); } if (dr != null) { // Add it to the drawable cache dr.setChangingConfigurations(tv.changingConfigurations); if (addCachedDelegateDrawable(context, key, dr) && DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Saved drawable to cache: " + context.getResources().getResourceName(resId)); } } } catch (Exception e) { Log.e(TAG, "Exception while inflating drawable", e); } } if (dr == null) { // If we reach here then the delegate inflation of the resource failed. Mark it as // bad so we skip the id next time mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG); } return dr; } return null; }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** * Called from one of constructors of this view to perform its initialization. * <p>/*from w w w .j av a 2 s . co m*/ * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view instance. The * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data * from the current theme provided by the specified <var>context</var>. */ @SuppressWarnings("ResourceType") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mContext = context; setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); this.inflateHierarchy(context, R.layout.ui_search_view); this.mProgressBarAnimator = createProgressBarAnimator(); this.mDefaultRevealAnimationHandler = createRevealAnimationHandler(); ColorStateList tintList = null; PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN; /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_SearchView_android_queryHint) { setQueryHint(typedArray.getText(index)); } else if (index == R.styleable.Ui_SearchView_uiTint) { tintList = typedArray.getColorStateList(index); } else if (index == R.styleable.Ui_SearchView_uiTintMode) { tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0), tintList != null ? PorterDuff.Mode.SRC_IN : null); } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) { mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) { mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) { final int resId = typedArray.getResourceId(index, 0); if (resId != 0) { mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context, resId); } } } typedArray.recycle(); } if (tintList != null || tintMode != null) { this.mTintInfo = new SearchTintInfo(); this.mTintInfo.tintList = tintList; this.mTintInfo.hasTintList = tintList != null; this.mTintInfo.tintMode = tintMode; this.mTintInfo.hasTintMode = tintMode != null; } final Resources.Theme theme = context.getTheme(); final TypedValue typedValue = new TypedValue(); if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) { if (mTintInfo == null) { this.mTintInfo = new SearchTintInfo(); } if (typedValue.resourceId > 0) { mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(), typedValue.resourceId, theme); } else { mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data); } mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null; } this.applyTint(); this.mRevealAnimationHandler = mDefaultRevealAnimationHandler; }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
public HListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (LOG_ENABLED) { Log.i(LOG_TAG, "defStyle: " + defStyle); }//from www . j a v a 2s. c o m final Resources.Theme theme = context.getTheme(); TypedArray array = theme.obtainStyledAttributes(attrs, R.styleable.HListView, defStyle, 0); CharSequence[] entries = null; Drawable dividerDrawable = null; Drawable overscrollHeader = null; Drawable overscrollFooter = null; int dividerWidth = 0; boolean headerDividersEnabled = true; boolean footerDividersEnabled = true; int measureWithChild = -1; if (null != array) { entries = array.getTextArray(R.styleable.HListView_android_entries); dividerDrawable = array.getDrawable(R.styleable.HListView_android_divider); overscrollHeader = array.getDrawable(R.styleable.HListView_hlv_overScrollHeader); overscrollFooter = array.getDrawable(R.styleable.HListView_hlv_overScrollFooter); dividerWidth = array.getDimensionPixelSize(R.styleable.HListView_hlv_dividerWidth, 0); headerDividersEnabled = array.getBoolean(R.styleable.HListView_hlv_headerDividersEnabled, true); footerDividersEnabled = array.getBoolean(R.styleable.HListView_hlv_footerDividersEnabled, true); measureWithChild = array.getInteger(R.styleable.HListView_hlv_measureWithChild, -1); array.recycle(); if (LOG_ENABLED) { Log.d(LOG_TAG, "divider: " + dividerDrawable); Log.d(LOG_TAG, "overscrollHeader: " + overscrollHeader); Log.d(LOG_TAG, "overscrollFooter: " + overscrollFooter); Log.d(LOG_TAG, "dividerWith: " + dividerWidth); Log.d(LOG_TAG, "headerDividersEnabled: " + headerDividersEnabled); Log.d(LOG_TAG, "footerDividersEnabled: " + footerDividersEnabled); Log.d(LOG_TAG, "measureWithChild: " + measureWithChild); } } if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries)); } if (dividerDrawable != null) { // If a divider is specified use its intrinsic height for divider height setDivider(dividerDrawable); } if (overscrollHeader != null) { setOverscrollHeader(overscrollHeader); } if (overscrollFooter != null) { setOverscrollFooter(overscrollFooter); } // Use the height specified, zero being the default if (dividerWidth != 0) { setDividerWidth(dividerWidth); } mHeaderDividersEnabled = headerDividersEnabled; mFooterDividersEnabled = footerDividersEnabled; mMeasureWithChild = measureWithChild; }
From source file:org.akop.ararat.view.CrosswordView.java
public CrosswordView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode()) { setLayerType(View.LAYER_TYPE_HARDWARE, null); }// ww w . j av a 2 s .c o m // Set drawing defaults Resources r = context.getResources(); DisplayMetrics dm = r.getDisplayMetrics(); int cellFillColor = NORMAL_CELL_FILL_COLOR; int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR; int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR; int selectedWordFillColor = SELECTED_WORD_FILL_COLOR; int selectedCellFillColor = SELECTED_CELL_FILL_COLOR; int markedCellFillColor = MARKED_CELL_FILL_COLOR; int numberTextColor = NUMBER_TEXT_COLOR; int cellStrokeColor = CELL_STROKE_COLOR; int circleStrokeColor = CIRCLE_STROKE_COLOR; int answerTextColor = ANSWER_TEXT_COLOR; mScaledDensity = dm.scaledDensity; float numberTextSize = NUMBER_TEXT_SIZE * mScaledDensity; mAnswerTextSize = ANSWER_TEXT_SIZE * mScaledDensity; mCellSize = CELL_SIZE * dm.density; mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density; mIsEditable = true; mInputMode = INPUT_MODE_KEYBOARD; mSkipOccupiedOnType = false; mSelectFirstUnoccupiedOnNav = true; mMaxBitmapSize = DEFAULT_MAX_BITMAP_DIMENSION; // Read supplied attributes if (attrs != null) { Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.CrosswordView, 0, 0); mCellSize = a.getDimension(R.styleable.CrosswordView_cellSize, mCellSize); mNumberTextPadding = a.getDimension(R.styleable.CrosswordView_numberTextPadding, mNumberTextPadding); numberTextSize = a.getDimension(R.styleable.CrosswordView_numberTextSize, numberTextSize); mAnswerTextSize = a.getDimension(R.styleable.CrosswordView_answerTextSize, mAnswerTextSize); answerTextColor = a.getColor(R.styleable.CrosswordView_answerTextColor, answerTextColor); cellFillColor = a.getColor(R.styleable.CrosswordView_defaultCellFillColor, cellFillColor); cheatedCellFillColor = a.getColor(R.styleable.CrosswordView_cheatedCellFillColor, cheatedCellFillColor); mistakeCellFillColor = a.getColor(R.styleable.CrosswordView_mistakeCellFillColor, mistakeCellFillColor); selectedWordFillColor = a.getColor(R.styleable.CrosswordView_selectedWordFillColor, selectedWordFillColor); selectedCellFillColor = a.getColor(R.styleable.CrosswordView_selectedCellFillColor, selectedCellFillColor); markedCellFillColor = a.getColor(R.styleable.CrosswordView_markedCellFillColor, markedCellFillColor); cellStrokeColor = a.getColor(R.styleable.CrosswordView_cellStrokeColor, cellStrokeColor); circleStrokeColor = a.getColor(R.styleable.CrosswordView_circleStrokeColor, circleStrokeColor); numberTextColor = a.getColor(R.styleable.CrosswordView_numberTextColor, numberTextColor); mIsEditable = a.getBoolean(R.styleable.CrosswordView_editable, mIsEditable); mSkipOccupiedOnType = a.getBoolean(R.styleable.CrosswordView_skipOccupiedOnType, mSkipOccupiedOnType); mSelectFirstUnoccupiedOnNav = a.getBoolean(R.styleable.CrosswordView_selectFirstUnoccupiedOnNav, mSelectFirstUnoccupiedOnNav); a.recycle(); } mRevealSetsCheatFlag = true; mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION; // Init paints mCellFillPaint = new Paint(); mCellFillPaint.setColor(cellFillColor); mCellFillPaint.setStyle(Paint.Style.FILL); mCheatedCellFillPaint = new Paint(); mCheatedCellFillPaint.setColor(cheatedCellFillColor); mCheatedCellFillPaint.setStyle(Paint.Style.FILL); mMistakeCellFillPaint = new Paint(); mMistakeCellFillPaint.setColor(mistakeCellFillColor); mMistakeCellFillPaint.setStyle(Paint.Style.FILL); mSelectedWordFillPaint = new Paint(); mSelectedWordFillPaint.setColor(selectedWordFillColor); mSelectedWordFillPaint.setStyle(Paint.Style.FILL); mSelectedCellFillPaint = new Paint(); mSelectedCellFillPaint.setColor(selectedCellFillColor); mSelectedCellFillPaint.setStyle(Paint.Style.FILL); mMarkedCellFillPaint = new Paint(); mMarkedCellFillPaint.setColor(markedCellFillColor); mMarkedCellFillPaint.setStyle(Paint.Style.FILL); mCellStrokePaint = new Paint(); mCellStrokePaint.setColor(cellStrokeColor); mCellStrokePaint.setStyle(Paint.Style.STROKE); // mCellStrokePaint.setStrokeWidth(1); mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCircleStrokePaint.setColor(circleStrokeColor); mCircleStrokePaint.setStyle(Paint.Style.STROKE); mCircleStrokePaint.setStrokeWidth(1); mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberTextPaint.setColor(numberTextColor); mNumberTextPaint.setTextAlign(Paint.Align.CENTER); mNumberTextPaint.setTextSize(numberTextSize); // Compute number height mNumberTextPaint.getTextBounds("0", 0, "0".length(), mTempRect); mNumberTextHeight = mTempRect.height(); mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberStrokePaint.setColor(cellFillColor); mNumberStrokePaint.setTextAlign(Paint.Align.CENTER); mNumberStrokePaint.setTextSize(numberTextSize); mNumberStrokePaint.setStyle(Paint.Style.STROKE); mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * mScaledDensity); mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mAnswerTextPaint.setColor(answerTextColor); mAnswerTextPaint.setTextSize(mAnswerTextSize); // Init rest of the values mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth(); mPuzzleCells = EMPTY_CELLS; mPuzzleWidth = 0; mPuzzleHeight = 0; mAllowedChars = EMPTY_CHARS; mRenderScale = 0; mBitmapOffset = new PointF(); mCenteredOffset = new PointF(); mTranslationBounds = new RectF(); mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); mGestureDetector = new GestureDetector(context, new GestureListener()); mContentRect = new RectF(); mPuzzleRect = new RectF(); mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG); mScroller = new Scroller(context, null, true); mZoomer = new Zoomer(context); mUndoBuffer = new Stack<>(); setFocusableInTouchMode(mIsEditable && mInputMode != INPUT_MODE_NONE); setOnKeyListener(this); }
From source file:org.connectbot.views.CheckableMenuItem.java
public CheckableMenuItem(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mRootView = inflate(context, R.layout.view_checkablemenuitem, this); mTitle = (TextView) mRootView.findViewById(R.id.title); mSummary = (TextView) mRootView.findViewById(R.id.summary); mSwitch = (SwitchCompat) findViewById(R.id.checkbox_switch); setFocusable(true);//from w w w .j av a 2 s . co m mAccessHelper = new ExploreByTouchHelper(this) { private final Rect mTmpRect = new Rect(); @Override protected int getVirtualViewAt(float x, float y) { return HOST_ID; } @Override protected void getVisibleVirtualViews(List<Integer> virtualViewIds) { } @Override protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) { if (virtualViewId != HOST_ID) { // TODO(kroot): remove this when the bug is fixed. event.setContentDescription(PLACEHOLDER_STRING); return; } event.setContentDescription(mTitle.getText() + " " + mSummary.getText()); event.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME); event.setChecked(isChecked()); } @Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { if (virtualViewId != HOST_ID) { // TODO(kroot): remove this when the bug is fixed. node.setBoundsInParent(mPlaceHolderRect); node.setContentDescription(PLACEHOLDER_STRING); return; } mTmpRect.set(0, 0, CheckableMenuItem.this.getWidth(), CheckableMenuItem.this.getHeight()); node.setBoundsInParent(mTmpRect); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); node.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME); node.setCheckable(true); node.setChecked(isChecked()); node.addChild(mTitle); node.addChild(mSummary); } @Override protected boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments) { if (virtualViewId != HOST_ID) { return false; } if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) { mSwitch.toggle(); sendAccessibilityEvent(mRootView, AccessibilityEventCompat.CONTENT_CHANGE_TYPE_UNDEFINED); return true; } return false; } }; ViewCompat.setAccessibilityDelegate(mRootView, mAccessHelper); setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mSwitch.toggle(); } }); if (attrs != null) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CheckableMenuItem, 0, 0); @DrawableRes int iconRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_icon, 0); @StringRes int titleRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_title, 0); @StringRes int summaryRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_summary, 0); typedArray.recycle(); ImageView icon = (ImageView) mRootView.findViewById(R.id.icon); mTitle.setText(titleRes); if (iconRes != 0) { Resources resources = context.getResources(); Resources.Theme theme = context.getTheme(); Drawable iconDrawable = VectorDrawableCompat.create(resources, iconRes, theme); icon.setImageDrawable(iconDrawable); } if (summaryRes != 0) { mSummary.setText(summaryRes); } } }
From source file:com.gelakinetic.mtgfam.helpers.ImageGetterHelper.java
/** * This function returns a custom ImageGetter which replaces glyphs with text. * This could have been a new subclass of ImageGetter with a constructor that takes a resource, but I guess * I didn't feel like writing it that way on that day. * * @param context the context to get resources to get drawables from * @return a custom ImageGetter/*from w w w. j av a2 s . c om*/ */ public static ImageGetter GlyphGetter(final Context context) { return new ImageGetter() { public Drawable getDrawable(String source) { Drawable d = null; source = source.replace("/", ""); if (source.equalsIgnoreCase("w")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_w);//ContextCompat.getDrawable(context, R.drawable.glyph_w, null); } else if (source.equalsIgnoreCase("u")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_u); } else if (source.equalsIgnoreCase("b")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_b); } else if (source.equalsIgnoreCase("r")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_r); } else if (source.equalsIgnoreCase("g")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_g); } else if (source.equalsIgnoreCase("t")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_tap); } else if (source.equalsIgnoreCase("q")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_untap); } else if (source.equalsIgnoreCase("wu") || source.equalsIgnoreCase("uw")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_wu); } else if (source.equalsIgnoreCase("ub") || source.equalsIgnoreCase("bu")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_ub); } else if (source.equalsIgnoreCase("br") || source.equalsIgnoreCase("rb")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_br); } else if (source.equalsIgnoreCase("rg") || source.equalsIgnoreCase("gr")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_rg); } else if (source.equalsIgnoreCase("gw") || source.equalsIgnoreCase("wg")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_gw); } else if (source.equalsIgnoreCase("wb") || source.equalsIgnoreCase("bw")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_wb); } else if (source.equalsIgnoreCase("bg") || source.equalsIgnoreCase("gb")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_bg); } else if (source.equalsIgnoreCase("gu") || source.equalsIgnoreCase("ug")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_gu); } else if (source.equalsIgnoreCase("ur") || source.equalsIgnoreCase("ru")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_ur); } else if (source.equalsIgnoreCase("rw") || source.equalsIgnoreCase("wr")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_rw); } else if (source.equalsIgnoreCase("2w") || source.equalsIgnoreCase("w2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_w2); } else if (source.equalsIgnoreCase("2u") || source.equalsIgnoreCase("u2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_u2); } else if (source.equalsIgnoreCase("2b") || source.equalsIgnoreCase("b2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_b2); } else if (source.equalsIgnoreCase("2r") || source.equalsIgnoreCase("r2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_r2); } else if (source.equalsIgnoreCase("2g") || source.equalsIgnoreCase("g2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_g2); } else if (source.equalsIgnoreCase("s")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_s); } else if (source.equalsIgnoreCase("pw") || source.equalsIgnoreCase("wp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pw); } else if (source.equalsIgnoreCase("pu") || source.equalsIgnoreCase("up")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pu); } else if (source.equalsIgnoreCase("pb") || source.equalsIgnoreCase("bp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pb); } else if (source.equalsIgnoreCase("pr") || source.equalsIgnoreCase("rp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pr); } else if (source.equalsIgnoreCase("pg") || source.equalsIgnoreCase("gp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pg); } else if (source.equalsIgnoreCase("p")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_p)); } else if (source.equalsIgnoreCase("+oo")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_inf); } else if (source.equalsIgnoreCase("100")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_100); } else if (source.equalsIgnoreCase("1000000")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_1000000); } else if (source.equalsIgnoreCase("hr") || source.equalsIgnoreCase("rh")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_hr); } else if (source.equalsIgnoreCase("hw") || source.equalsIgnoreCase("wh")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_hw); } else if (source.equalsIgnoreCase("c")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_c); } else if (source.equalsIgnoreCase("chaos")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_chaos)); } else if (source.equalsIgnoreCase("z")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_z); } else if (source.equalsIgnoreCase("y")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_y); } else if (source.equalsIgnoreCase("x")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_x); } else if (source.equalsIgnoreCase("h")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_half); } else if (source.equalsIgnoreCase("pwk")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_pwk)); } else if (source.equalsIgnoreCase("e")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_e)); } else { for (int i = 0; i < drawableNumbers.length; i++) { if (source.equals(Integer.valueOf(i).toString())) { d = ContextCompat.getDrawable(context, drawableNumbers[i]); } } } if (d == null) { return null; } d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; }
From source file:com.android.ex.chips.RecipientEditTextView.java
private void setChipDimensions(final Context context, final AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecipientEditTextView, 0, 0); final Resources r = getContext().getResources(); mChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_chipBackground); if (mChipBackground == null) mChipBackground = ContextCompat.getDrawable(context, R.drawable.circle_background_chips); mChipBackgroundPressed = a.getDrawable(R.styleable.RecipientEditTextView_chipBackgroundPressed); if (mChipBackgroundPressed == null) mChipBackgroundPressed = ContextCompat.getDrawable(context, R.drawable.chip_background_selected); mChipDelete = a.getDrawable(R.styleable.RecipientEditTextView_chipDelete); if (mChipDelete == null) mChipDelete = ContextCompat.getDrawable(context, R.drawable.chip_delete); mChipPadding = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipPadding, -1); if (mChipPadding == -1) mChipPadding = (int) r.getDimension(R.dimen.chip_padding); mAlternatesLayout = a.getResourceId(R.styleable.RecipientEditTextView_chipAlternatesLayout, -1); if (mAlternatesLayout == -1) mAlternatesLayout = R.layout.chips_alternate_item; mDefaultContactPhoto = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture); mMoreItem = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.more_item, null); mChipHeight = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipHeight, -1); if (mChipHeight == -1) mChipHeight = r.getDimension(R.dimen.chip_height); mChipFontSize = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipFontSize, -1); if (mChipFontSize == -1) mChipFontSize = r.getDimension(R.dimen.chip_text_size); mInvalidChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_invalidChipBackground); if (mInvalidChipBackground == null) mInvalidChipBackground = ContextCompat.getDrawable(context, R.drawable.chip_background_invalid); mLineSpacingExtra = r.getDimension(R.dimen.line_spacing_extra); mMaxLines = r.getInteger(R.integer.chips_max_lines); final TypedValue tv = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); a.recycle();/*from www . j a va 2 s.c o m*/ }
From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java
public TimePickerClockDelegate(TimePicker delegator, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(delegator, context); // process style attributes final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes);/* w w w . j av a2s. c o m*/ final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); mSelectHours = res.getString(R.string.select_hours); mSelectMinutes = res.getString(R.string.select_minutes); String[] amPmStrings = DateTimeUtilsCompat.getBestAmPmStrings(mCurrentLocale); mAmText = amPmStrings[0]; mPmText = amPmStrings[1]; final int layoutResourceId = a.getResourceId(R.styleable.TimePicker_layout, R.layout.time_picker_holo); final View mainView = inflater.inflate(layoutResourceId, delegator); mHeaderView = mainView.findViewById(R.id.time_header); mHeaderView.setBackground(a.getDrawable(R.styleable.TimePicker_headerBackground)); // Set up hour/minute labels. mHourView = (TextView) mHeaderView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(context, R.string.select_hours)); mSeparatorView = (TextView) mHeaderView.findViewById(R.id.separator); mMinuteView = (TextView) mHeaderView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mMinuteView, new ClickActionDelegate(context, R.string.select_minutes)); final int headerTimeTextAppearance = a.getResourceId(R.styleable.TimePicker_headerTimeTextAppearance, 0); if (headerTimeTextAppearance != 0) { mHourView.setTextAppearance(context, headerTimeTextAppearance); mSeparatorView.setTextAppearance(context, headerTimeTextAppearance); mMinuteView.setTextAppearance(context, headerTimeTextAppearance); } // Now that we have text appearances out of the way, make sure the hour // and minute views are correctly sized. mHourView.setMinWidth(computeStableWidth(mHourView, 24)); mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60)); // TODO: This can be removed once we support themed color state lists. final int headerSelectedTextColor = a.getColor(R.styleable.TimePicker_headerSelectedTextColor, res.getColor(R.color.timepicker_default_selector_color_material)); mHourView.setTextColor(ViewStateUtils.addStateIfMissing(mHourView.getTextColors(), android.R.attr.state_selected, headerSelectedTextColor)); mMinuteView.setTextColor(ViewStateUtils.addStateIfMissing(mMinuteView.getTextColors(), android.R.attr.state_selected, headerSelectedTextColor)); // Set up AM/PM labels. // Set up AM/PM labels. mAmPmLayout = mHeaderView.findViewById(R.id.ampm_layout); mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label); mAmLabel.setText(mAmText); mAmLabel.setOnClickListener(mClickListener); mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label); mPmLabel.setText(mPmText); mPmLabel.setOnClickListener(mClickListener); final int headerAmPmTextAppearance = a.getResourceId(R.styleable.TimePicker_headerAmPmTextAppearance, 0); if (headerAmPmTextAppearance != 0) { mAmLabel.setTextAppearance(context, headerAmPmTextAppearance); mPmLabel.setTextAppearance(context, headerAmPmTextAppearance); } a.recycle(); // Pull disabled alpha from theme. final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true); mDisabledAlpha = outValue.getFloat(); mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker); setupListeners(); mAllowAutoAdvance = true; // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); // Initialize with current time final Calendar calendar = Calendar.getInstance(mCurrentLocale); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); }