List of usage examples for android.widget TextView setCompoundDrawablesRelative
@android.view.RemotableViewMethod public void setCompoundDrawablesRelative(@Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom)
From source file:Main.java
/** * @see android.widget.TextView#setCompoundDrawablesRelative(Drawable, Drawable, Drawable, * Drawable)/*from www. ja v a2 s. com*/ */ public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top, Drawable end, Drawable bottom) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(start, top, bottom, end); } else { textView.setCompoundDrawables(start, top, bottom, end); } }
From source file:com.stepstone.stepper.internal.util.TintUtil.java
/** * Tints TextView's text color and it's compound drawables * @param textview text view to tint//from w ww. j a v a 2 s . co m * @param tintColor color state list to use for tinting */ public static void tintTextView(@NonNull TextView textview, ColorStateList tintColor) { textview.setTextColor(tintColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Drawable[] drawables = textview.getCompoundDrawablesRelative(); textview.setCompoundDrawablesRelative(tintDrawable(drawables[0], tintColor), tintDrawable(drawables[1], tintColor), tintDrawable(drawables[2], tintColor), tintDrawable(drawables[3], tintColor)); } else { Drawable[] drawables = textview.getCompoundDrawables(); textview.setCompoundDrawables(tintDrawable(drawables[0], tintColor), tintDrawable(drawables[1], tintColor), tintDrawable(drawables[2], tintColor), tintDrawable(drawables[3], tintColor)); } }
From source file:Main.java
/** * @see android.widget.TextView#setCompoundDrawablesRelative(Drawable, Drawable, Drawable, * Drawable)/*from w w w . java 2s.c o m*/ */ public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top, Drawable end, Drawable bottom) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { // On JB MR1, due to a platform bug, setCompoundDrawablesRelative() is a no-op if the // view has ever been measured. As a workaround, use setCompoundDrawables() directly. // See: http://crbug.com/368196 and http://crbug.com/361709 boolean isRtl = isLayoutRtl(textView); textView.setCompoundDrawables(isRtl ? end : start, top, isRtl ? start : end, bottom); } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } }
From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java
@SuppressLint("ObsoleteSdkInt") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void unBindView(View view) { if (view == null) return;//from w w w.jav a 2 s . c o m Drawable drawable; int i; //1. try { view.setOnClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //2. try { view.setOnCreateContextMenuListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //3. try { view.setOnFocusChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //4. try { view.setOnKeyListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //5. try { view.setOnLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //6. try { view.setOnTouchListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //7. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { view.setOnApplyWindowInsetsListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //8. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnContextClickListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //9. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnScrollChangeListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //10. try { view.setOnDragListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //11. try { view.setOnGenericMotionListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //12. try { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13 view.setOnHoverListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //13. try { view.setOnSystemUiVisibilityChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } /** * @see SwipeRefreshLayout#onDetachedFromWindow() */ if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) { try { view.getBackground().setCallback(null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16 view.setBackgroundDrawable(null); } else { view.setBackground(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageView if (view instanceof ImageView) { try { ImageView imageView = (ImageView) view; drawable = imageView.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageView.setImageDrawable(null); imageView.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //TextView if (view instanceof TextView) { try { TextView textView = (TextView) view; textView.setCompoundDrawables(null, null, null, null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(null, null, null, null); } textView.setCursorVisible(false); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageButton if (view instanceof ImageButton) { try { ImageButton imageButton = (ImageButton) view; drawable = imageButton.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageButton.setImageDrawable(null); imageButton.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ListView if (view instanceof ListView) { ListView listView = (ListView) view; try { listView.setAdapter(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnScrollListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemSelectedListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //RecyclerView if (view instanceof RecyclerView) { try { RecyclerView recyclerView = (RecyclerView) view; recyclerView.setAdapter(null); recyclerView.setChildDrawingOrderCallback(null); recyclerView.setOnScrollListener(null); recyclerView.addOnScrollListener(null); recyclerView.removeOnScrollListener(null); recyclerView.setRecyclerListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //WebView if (view instanceof WebView) { WebView webView = (WebView) view; try { webView.stopLoading(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.removeAllViews(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebChromeClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebViewClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.destroy(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { if (null != view.getParent() && view.getParent() instanceof ViewGroup) { ((ViewGroup) view.getParent()).removeView(view); } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } //SurfaceView if (view instanceof SurfaceView) { try { SurfaceView surfaceView = (SurfaceView) view; SurfaceHolder holder = surfaceView.getHolder(); if (holder != null) { Surface surface = holder.getSurface(); if (surface != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { surface.release(); } } } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } view.destroyDrawingCache(); view.clearAnimation(); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; int childCount = (viewGroup).getChildCount(); for (i = 0; i < childCount; i++) { unBindView((viewGroup).getChildAt(i)); } } }
From source file:com.achep.acdisplay.ui.widgets.notification.NotificationActions.java
/** * Sets new actions.//from w ww .ja v a 2s . c o m * * @param notification the host notification * @param actions the actions to set */ public void setActions(@Nullable OpenNotification notification, @Nullable Action[] actions) { Check.getInstance().isInMainThread(); mRemoteInputsMap.clear(); mActionsMap.clear(); hideRii(); if (actions == null) { // Free actions' container. removeAllViews(); return; } else { assert notification != null; } int count = actions.length; View[] views = new View[count]; // Find available views. int childCount = getChildCount(); int a = Math.min(childCount, count); for (int i = 0; i < a; i++) { views[i] = getChildAt(i); } // Remove redundant views. for (int i = childCount - 1; i >= count; i--) { removeViewAt(i); } LayoutInflater inflater = null; for (int i = 0; i < count; i++) { final Action action = actions[i]; View root = views[i]; if (root == null) { // Initialize layout inflater only when we really need it. if (inflater == null) { inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); assert inflater != null; } root = inflater.inflate(getActionLayoutResource(), this, false); root = onCreateActionView(root); // We need to keep all IDs unique to make // TransitionManager.beginDelayedTransition(viewGroup, null) // work correctly! root.setId(getChildCount() + 1); addView(root); } mActionsMap.put(root, action); int style = Typeface.NORMAL; root.setOnLongClickListener(null); if (action.intent != null) { root.setEnabled(true); root.setOnClickListener(mActionsOnClick); RemoteInput remoteInput = getRemoteInput(action); if (remoteInput != null) { mRemoteInputsMap.put(action, remoteInput); root.setOnLongClickListener(mActionsOnLongClick); // Highlight the action style = Typeface.ITALIC; } } else { root.setEnabled(false); root.setOnClickListener(null); } // Get message view and apply the content. TextView textView = root instanceof TextView ? (TextView) root : (TextView) root.findViewById(android.R.id.title); textView.setText(action.title); if (mTypeface == null) mTypeface = textView.getTypeface(); textView.setTypeface(mTypeface, style); Drawable icon = NotificationUtils.getDrawable(getContext(), notification, action.icon); if (icon != null) icon = onCreateActionIcon(icon); if (Device.hasJellyBeanMR1Api()) { textView.setCompoundDrawablesRelative(icon, null, null, null); } else { textView.setCompoundDrawables(icon, null, null, null); } } }