@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mFolder == null) return; if (mFolder.getItemCount() == 0 && !mAnimating) return; ArrayList<View> items = mFolder.getItemsInReadingOrder(false); Drawable d; TextView v; // Update our drawing parameters if necessary if (mAnimating) { computePreviewDrawingParams(mAnimParams.drawable); } else { v = (TextView) items.get(0); d = v.getCompoundDrawables()[1]; computePreviewDrawingParams(d); } int nItemsInPreview = Math.min(items.size(), NUM_ITEMS_IN_PREVIEW); if (!mAnimating) { for (int i = nItemsInPreview - 1; i >= 0; i--) { v = (TextView) items.get(i); d = v.getCompoundDrawables()[1]; mParams = computePreviewItemDrawingParams(i, mParams); mParams.drawable = d; drawPreviewItem(canvas, mParams); } } else { drawPreviewItem(canvas, mAnimParams); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (position == 2) { if (convertView == null) { convertView = inflater.inflate(R.layout.drawer_separator, null); } } else { if (convertView == null || convertView.getId() != position) { convertView = inflater.inflate(R.layout.drawer_row, null); if (convertView != null) { TextView textView = (TextView) convertView; convertView.setId(position); textView.setText(stringArray[position]); textView.setCompoundDrawablesWithIntrinsicBounds( drawableArray[position], null, null, null); } } if (convertView != null) { TextView textView = (TextView) convertView; Typeface roboto = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Medium.ttf"); textView.setTypeface(roboto); if (position == selectedItem) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = getContext().getTheme(); theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); int primaryDark = typedValue.data; ((ListView) parent).setSelectionFromTop(position, convertView.getTop()); textView.setTextColor(primaryDark); textView.getCompoundDrawables()[0].setColorFilter(primaryDark, PorterDuff.Mode.SRC_IN); TypedValue backgroundValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.galleryItemBackground, backgroundValue, true); convertView.setBackgroundColor(backgroundValue.data); } else { TypedValue colorValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.textColorPrimary, colorValue, true); textView.setTextColor(colorValue.data); convertView.setBackgroundColor(Color.TRANSPARENT); textView.getCompoundDrawables()[0].clearColorFilter(); } } else return null; } return convertView; }
/** * apply compound property in textView position 0:left, 1:top, 2:right, 3:bottom - REF : drawable * to load as compoundDrawable - BASE64 : decode as base64 and set as CompoundDrawable */ public static void applyCompoundDrawable(View view, DynamicProperty property, int position) { if (view instanceof TextView) { TextView textView = (TextView) view; Drawable[] d = textView.getCompoundDrawables(); switch (property.type) { case REF: { try { d[position] = view.getContext() .getResources() .getDrawable(getDrawableId(view.getContext(), property.getValueString())); } catch (Exception e) { } } break; case BASE64: { d[position] = property.getValueBitmapDrawable(); } break; case DRAWABLE: { d[position] = property.getValueGradientDrawable(); } break; } textView.setCompoundDrawablesWithIntrinsicBounds(d[0], d[1], d[2], d[3]); } }
protected void setupTitle(Context context, String title) { titleView = new TextView(context); titleView.setText(title); titleView.setCompoundDrawablePadding(0); if (mExpanded) { titleView.setCompoundDrawablesWithIntrinsicBounds( null, null, getResources().getDrawable(R.drawable.ic_collapse), null); } else { titleView.setCompoundDrawablesWithIntrinsicBounds( null, null, getResources().getDrawable(R.drawable.ic_expand), null); } MarginLayoutParams params = new MarginLayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, titleView.getCompoundDrawables()[2].getIntrinsicHeight()); params.setMargins( 0, 0, 0, getResources().getDimensionPixelSize(R.dimen.card_expandable_title_bottom_margin)); titleView.setLayoutParams(params); titleView.setOnClickListener(expandClick); titleView.setTextSize( TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.card_expandable_title_text_size)); Utils.setRobotoThin(context, titleView, Typeface.BOLD); titleView.setTypeface(null, Typeface.BOLD); addContentView(titleView); }
private void setTabTitleIconCrossFade(int position, float progress) { final TextView tabTitleView = (TextView) getNeededView(position); Drawable drawable = tabTitleView.getCompoundDrawables()[1]; if (drawable instanceof CrossFadeDrawable) { crossFadeDrawable(drawable, progress); } }
private void setTabTitleIconColor(TextView tabTitleView, int color) { Drawable drawable = tabTitleView.getCompoundDrawables()[1]; if (!(drawable instanceof CrossFadeDrawable)) { tintDrawable(drawable, color); } tabTitleView.setTextColor(color); }
private void initWorkspaceGridSize(View view) { // TextView final int x = mSharePrefManager.getWorkspaceCountCellX(); final int y = mSharePrefManager.getWorkspaceCountCellY(); if (mWorkspaceGridContainer != null) { int count = mWorkspaceGridContainer.getChildCount(); for (int i = 0; i < count; i++) { final View child = mWorkspaceGridContainer.getChildAt(i); child.setEnabled(true); child.setActivated(false); } String strSize = x + "x" + y; TextView checkView = (TextView) mWorkspaceGridContainer.findViewWithTag(strSize); if (checkView != null) { checkView.setActivated(true); final Drawable[] dr = checkView.getCompoundDrawables(); ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(dr[0], dr[1], dr[2], dr[3]); } } // final IResConfigManager resources = mLauncher.getResConfigManager(); // final String[] strArrays = // resources.getStringArray(IResConfigManager.ARRAY_WORKSPACE_GRID_SIZE_VALUES); // int index = -1; // if(strArrays != null){ // // index = getSelectWorkspaceGridSize(strArrays, x, y); // if(index < 0) // index = strArrays.length-1; // //// android.util.Log.i("QsLog", "initWorkspaceGridSize=====" //// +"==index:"+index //// +"==x:"+x //// +"==y:"+y); // // Drawable icon = null; // final TypedArray array = // resources.obtainTypedArray(IResConfigManager.ARRAY_WORKSPACE_GRID_SIZE_PREVIEWS); // if(array != null){ // int n = array.length(); // if(index < n){ // icon = array.getDrawable(index); // } // array.recycle(); // } // // if(icon != null){ // ((TextView)view).setCompoundDrawablesWithIntrinsicBounds(null, icon, null, // null); // } // } }
@Override public void onFinish() { if (listener != null) { listener.onEnd(); } if (textView != null && textView.getVisibility() != View.INVISIBLE && textView.getVisibility() != View.GONE) { textView.getCompoundDrawables()[0].setVisible(false, true); textView.setText(GoodsHelper.END_HOT); } }
public static void a(TextView paramTextView, float paramFloat) { Drawable[] arrayOfDrawable = paramTextView.getCompoundDrawables(); int j = arrayOfDrawable.length; int i = 0; while (i < j) { Drawable localDrawable = arrayOfDrawable[i]; if (localDrawable != null) { localDrawable.setLevel((int) (10.0F * paramFloat) / 5); } i += 1; } paramTextView.setContentDescription( String.format( "%s,%s", new Object[] {a(paramTextView.getContext(), paramFloat), paramTextView.getText()})); }
/** * 对喜欢 回复 删除 分享按钮进行调整 * * @param size * @param top * @param textView */ public static void adjustLeftDrawable(int size, int top, TextView textView) { Drawable drawable = textView.getCompoundDrawables()[0]; drawable.setBounds(0, top, size, top + size); textView.setCompoundDrawables(drawable, null, null, null); }
/** Create a default view to be used for tabs. */ private View createDefaultTabView(int position) { final PagerAdapter adapter = mViewPager.getAdapter(); View view; switch (mTabMode) { case TITLE_ONLY: { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(adapter.getPageTitle(position)); textView.setTextColor(mTabColorize.getDefaultTabColor(position)); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); textView.setTypeface(null, mTextStyle); textView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (mTabBackground != NO_ID) { textView.setBackgroundResource(mTabBackground); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedValue outValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { textView.setAllCaps(mTextAllCaps); } textView.setPadding(mTabPaddingLeft, mTabPaddingTop, mTabPaddingRight, mTabPaddingBottom); if (position == mViewPager.getCurrentItem()) { textView.setTextColor(mTabColorize.getSelectedTabColor(position)); textView.setSelected(true); } view = textView; break; } case ICON_ONLY: { ImageView imageView = new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (mTabBackground != NO_ID) { imageView.setBackgroundResource(mTabBackground); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedValue outValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); imageView.setBackgroundResource(outValue.resourceId); } // Drawable drawable = ContextCompat.getDrawable(getContext(), // ((IconTabProvider) adapter).getPageIconResId(position)).mutate(); Drawable drawable = ContextCompat.getDrawable( getContext(), ((IconTabProvider) adapter).getPageIconResId(position)); if (mIconCrossFade && drawable instanceof StateListDrawable) { try { StateListDrawable stateListDrawable = (StateListDrawable) drawable; int fadingIndex = StateListDrawableHelper.getStateDrawableIndex( stateListDrawable, new int[] {android.R.attr.state_selected}); Drawable fading = StateListDrawableHelper.getStateDrawable(stateListDrawable, fadingIndex); int baseIndex = StateListDrawableHelper.getStateDrawableIndex(stateListDrawable, new int[] {0}); Drawable base = StateListDrawableHelper.getStateDrawable(stateListDrawable, baseIndex); CrossFadeDrawable cd = new CrossFadeDrawable(); cd.setFading(fading); // tintDrawable(cd.getFading().mutate(), // mTabColorize.getSelectedTabColor(position)); tintDrawable(cd.getFading(), mTabColorize.getSelectedTabColor(position)); cd.setBase(base); // tintDrawable(cd.getBase().mutate(), // mTabColorize.getDefaultTabColor(position)); tintDrawable(cd.getBase(), mTabColorize.getDefaultTabColor(position)); imageView.setImageDrawable(cd); } catch (Exception e) { imageView.setImageDrawable(drawable); } } else { imageView.setImageDrawable(drawable); } imageView.setPadding( mTabPaddingLeft, mTabPaddingTop, mTabPaddingRight, mTabPaddingBottom); if (position == mViewPager.getCurrentItem()) { Drawable d = imageView.getDrawable(); if (d instanceof CrossFadeDrawable) { crossFadeDrawable(d, 1); } else { tintDrawable(d, mTabColorize.getSelectedTabColor(position)); } imageView.setSelected(true); } else { tintDrawable(imageView.getDrawable(), mTabColorize.getDefaultTabColor(position)); } view = imageView; break; } case BOTH: { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(adapter.getPageTitle(position)); textView.setTextColor(mTabColorize.getDefaultTabColor(position)); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); textView.setTypeface(null, mTextStyle); textView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (mTabBackground != NO_ID) { textView.setBackgroundResource(mTabBackground); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedValue outValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { textView.setAllCaps(mTextAllCaps); } textView.setPadding(mTabPaddingLeft, mTabPaddingTop, mTabPaddingRight, mTabPaddingBottom); // Drawable drawable = ContextCompat.getDrawable(getContext(), // ((IconTabProvider) adapter).getPageIconResId(position)).mutate(); Drawable drawable = ContextCompat.getDrawable( getContext(), ((IconTabProvider) adapter).getPageIconResId(position)); if (mIconCrossFade && drawable instanceof StateListDrawable) { try { StateListDrawable stateListDrawable = (StateListDrawable) drawable; int fadingIndex = StateListDrawableHelper.getStateDrawableIndex( stateListDrawable, new int[] {android.R.attr.state_selected}); Drawable fading = StateListDrawableHelper.getStateDrawable(stateListDrawable, fadingIndex); int baseIndex = StateListDrawableHelper.getStateDrawableIndex(stateListDrawable, new int[] {0}); Drawable base = StateListDrawableHelper.getStateDrawable(stateListDrawable, baseIndex); CrossFadeDrawable cd = new CrossFadeDrawable(); cd.setFading(fading); cd.setFading(fading); // tintDrawable(cd.getFading().mutate(), // mTabColorize.getSelectedTabColor(position)); tintDrawable(cd.getFading(), mTabColorize.getSelectedTabColor(position)); cd.setBase(base); // tintDrawable(cd.getBase().mutate(), // mTabColorize.getDefaultTabColor(position)); tintDrawable(cd.getBase(), mTabColorize.getDefaultTabColor(position)); textView.setCompoundDrawablesWithIntrinsicBounds(null, cd, null, null); } catch (Exception e) { textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); } } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); } textView.setCompoundDrawablePadding(mDrawablePadding); if (position == mViewPager.getCurrentItem()) { textView.setTextColor(mTabColorize.getSelectedTabColor(position)); Drawable d = textView.getCompoundDrawables()[1]; if (d instanceof CrossFadeDrawable) { crossFadeDrawable(d, 1); } else { tintDrawable(d, mTabColorize.getSelectedTabColor(position)); } textView.setSelected(true); } else { Drawable d = textView.getCompoundDrawables()[1]; if (!(d instanceof CrossFadeDrawable)) { tintDrawable(d, mTabColorize.getDefaultTabColor(position)); } } view = textView; break; } default: { throw new IllegalStateException("Invalid tab mode: " + mTabMode); } } return view; }
@Override public boolean matches(TextView textView) { return BitmapDrawableAssert.hasDrawableResourceId( resourceId, (BitmapDrawable[]) textView.getCompoundDrawables()); }