Example usage for android.graphics.drawable Drawable setCallback

List of usage examples for android.graphics.drawable Drawable setCallback

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setCallback.

Prototype

public final void setCallback(@Nullable Callback cb) 

Source Link

Document

Bind a Callback object to this Drawable.

Usage

From source file:cnedu.ustcjd.widget.MultiSlider.java

private void setThumbDrawable(Thumb thumb, Drawable thumbDrawable, int thumbColor) {
    requireNonNull(thumbDrawable);/* ww w  .ja v  a 2 s .c  o m*/
    Drawable nThumbDrawable = getTintedDrawable(thumbDrawable.getConstantState().newDrawable(), thumbColor);
    nThumbDrawable.setCallback(this);

    // Assuming the thumb drawable is symmetric, set the thumb offset
    // such that the thumb will hang halfway off either edge of the
    // progress bar.
    thumb.setThumbOffset(thumbDrawable.getIntrinsicWidth() / 2);

    // If we're updating get the new states
    if (thumb.getThumb() != null && (nThumbDrawable.getIntrinsicWidth() != thumb.getThumb().getIntrinsicWidth()
            || nThumbDrawable.getIntrinsicHeight() != thumb.getThumb().getIntrinsicHeight())) {
        requestLayout();
    }
    thumb.setThumb(nThumbDrawable);

    invalidate();
    if (nThumbDrawable != null && nThumbDrawable.isStateful()) {
        // Note that if the states are different this won't work.
        // For now, let's consider that an app bug.
        int[] state = getDrawableState();
        nThumbDrawable.setState(state);
    }
}

From source file:cnedu.ustcjd.widget.MultiSlider.java

/**
 * Manually set the track drawable/*  w w w.j av  a2s  .  c  om*/
 *
 * @param d
 */
public void setTrackDrawable(Drawable d) {
    boolean needUpdate;
    if (mTrack != null && d != mTrack) {
        mTrack.setCallback(null);
        needUpdate = true;
    } else {
        needUpdate = false;
    }

    if (d != null) {
        d.setCallback(this);
        //            if (canResolveLayoutDirection()) {
        //                d.setLayoutDirection(getLayoutDirection());
        //            }

        // Make sure the ProgressBar is always tall enough
        int drawableHeight = d.getMinimumHeight();
        if (mMaxHeight < drawableHeight) {
            mMaxHeight = drawableHeight;
            requestLayout();
        }
    }
    mTrack = d;

    if (needUpdate) {
        updateTrackBounds(getWidth(), getHeight());
        updateTrackState();
        //TODO update all thumbs with their range tracks also
    }
}

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;/*ww w  .jav a 2s  . 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:chan.android.app.bitwise.util.StaggeredGridView.java

public void setSelector(Drawable sel) {
    if (mSelector != null) {
        mSelector.setCallback(null);/*from w ww .j a  v a2  s.c o  m*/
        unscheduleDrawable(mSelector);
    }

    mSelector = sel;

    if (mSelector == null) {
        return;
    }

    Rect padding = new Rect();
    sel.getPadding(padding);
    mSelectionLeftPadding = padding.left;
    mSelectionTopPadding = padding.top;
    mSelectionRightPadding = padding.right;
    mSelectionBottomPadding = padding.bottom;
    sel.setCallback(this);
    updateSelectorState();
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Updates current indicator to the specified one. If this seek bar has discrete mode enabled
 * ({@link #isDiscrete()}), the given indicator will be updated to scaleable drawable if it is
 * not yet.//from  ww w  . j  a v  a  2  s.  c o  m
 *
 * @param indicator The new indicator to update to.
 */
private void updateDiscreteIndicator(Drawable indicator) {
    if (mDecorator.hasPrivateFlag(PFLAG_DISCRETE)) {
        indicator = mAnimations.makeDiscreteIndicatorScaleable(indicator,
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
    }
    if (mDiscreteIndicator != indicator) {
        final boolean needUpdate;
        if (mDiscreteIndicator != null) {
            mDiscreteIndicator.setCallback(null);
            unscheduleDrawable(mDiscreteIndicator);
            needUpdate = true;
        } else {
            needUpdate = false;
        }
        if (indicator != null) {
            indicator.setCallback(this);
            indicator.setVisible(getVisibility() == VISIBLE, false);

            if (indicator.getIntrinsicWidth() != mDiscreteIndicatorWidth
                    || indicator.getIntrinsicHeight() != mDiscreteIndicatorHeight) {
                this.mDiscreteIndicatorWidth = indicator.getIntrinsicWidth();
                this.mDiscreteIndicatorHeight = indicator.getIntrinsicHeight();
                requestLayout();
            }
        } else {
            this.mDiscreteIndicatorRes = 0;
            this.mDiscreteIndicatorWidth = mDiscreteIndicatorHeight = 0;
            requestLayout();
        }
        this.mDiscreteIndicator = indicator;
        this.applyDiscreteIndicatorTint();
        if (needUpdate) {
            this.updateDiscreteIndicatorPosition(getWidth(), getHeight());
            if (mDiscreteIndicator.isStateful()) {
                mDiscreteIndicator.setState(getDrawableState());
            }
            this.invalidateDiscreteIndicatorArea();
        }
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * ADW: Load the specified theme resource
 * /*from w w  w.j ava  2s  . c om*/
 * @param themeResources
 *            Resources from the theme package
 * @param themePackage
 *            the theme's package name
 * @param item_name
 *            the theme item name to load
 * @param item
 *            the View Item to apply the theme into
 * @param themeType
 *            Specify if the themed element will be a background or a
 *            foreground item
 */
public static void loadThemeResource(Resources themeResources, String themePackage, String item_name, View item,
        int themeType) {
    Drawable d = null;
    if (themeResources != null) {
        int resource_id = themeResources.getIdentifier(item_name, "drawable", themePackage);
        if (resource_id != 0) {
            try {
                d = themeResources.getDrawable(resource_id);
            } catch (Resources.NotFoundException e) {
                return;
            }
            if (themeType == THEME_ITEM_FOREGROUND && item instanceof ImageView) {
                // ADW remove the old drawable
                Drawable tmp = ((ImageView) item).getDrawable();
                if (tmp != null) {
                    tmp.setCallback(null);
                    tmp = null;
                }
                ((ImageView) item).setImageDrawable(d);
            } else {
                // ADW remove the old drawable
                Drawable tmp = item.getBackground();
                if (tmp != null) {
                    tmp.setCallback(null);
                    tmp = null;
                }
                item.setBackgroundDrawable(d);
            }
        }
    }
}

From source file:com.example.mycameragallarydemo.views.TwoWayView.java

public void setSelector(Drawable selector) {
    if (mSelector != null) {
        mSelector.setCallback(null);/* w ww . j a v a  2 s.c o m*/
        unscheduleDrawable(mSelector);
    }

    mSelector = selector;
    Rect padding = new Rect();
    selector.getPadding(padding);

    selector.setCallback(this);
    updateSelectorState();
}

From source file:com.appunite.list.AbsHorizontalListView.java

public void setSelector(Drawable sel) {
    if (mSelector != null) {
        mSelector.setCallback(null);//  ww w.  j a  v a  2s .  co  m
        unscheduleDrawable(mSelector);
    }
    mSelector = sel;
    Rect padding = new Rect();
    sel.getPadding(padding);
    mSelectionLeftPadding = padding.left;
    mSelectionTopPadding = padding.top;
    mSelectionRightPadding = padding.right;
    mSelectionBottomPadding = padding.bottom;
    sel.setCallback(this);
    updateSelectorState();
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

/**
 * Set a Drawable that should be used to highlight the currently selected item.
 *
 * @param selector A Drawable to use as the selection highlight.
 *
 * @attr ref android.R.styleable#AbsListView_listSelector
 *//*from  w  ww . ja  v a 2  s . com*/
public void setSelector(Drawable selector) {
    if (mSelector != null) {
        mSelector.setCallback(null);
        unscheduleDrawable(mSelector);
    }

    mSelector = selector;
    Rect padding = new Rect();
    selector.getPadding(padding);

    selector.setCallback(this);
    updateSelectorState();
}