當前位置: 首頁>>代碼示例>>Java>>正文


Java Drawable.getCurrent方法代碼示例

本文整理匯總了Java中android.graphics.drawable.Drawable.getCurrent方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.getCurrent方法的具體用法?Java Drawable.getCurrent怎麽用?Java Drawable.getCurrent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.Drawable的用法示例。


在下文中一共展示了Drawable.getCurrent方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Nullable
static Resource<Bitmap> convert(BitmapPool bitmapPool, Drawable drawable, int width, int height) {
  // Handle DrawableContainer or StateListDrawables that may contain one or more BitmapDrawables.
  drawable = drawable.getCurrent();
  Bitmap result = null;
  boolean isRecycleable = false;
  if (drawable instanceof BitmapDrawable) {
    result = ((BitmapDrawable) drawable).getBitmap();
  } else if (!(drawable instanceof Animatable)) {
    result = drawToBitmap(bitmapPool, drawable, width, height);
    // We created and drew to the Bitmap, so it's safe for us to recycle or re-use.
    isRecycleable = true;
  }

  BitmapPool toUse = isRecycleable ? bitmapPool : NO_RECYCLE_BITMAP_POOL;
  return BitmapResource.obtain(result, toUse);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:DrawableToBitmapConverter.java

示例2: keyPressed

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected void keyPressed() {
    if (isEnabled() && isClickable()) {
        Drawable selector = this.mSelector;
        Rect selectorRect = this.mSelectorRect;
        if (selector == null) {
            return;
        }
        if ((isFocused() || touchModeDrawsInPressedState()) && !selectorRect.isEmpty()) {
            View v = getChildAt(this.mSelectedPosition - this.mFirstPosition);
            if (v != null) {
                if (!v.hasFocusable()) {
                    v.setPressed(true);
                } else {
                    return;
                }
            }
            setPressed(true);
            boolean longClickable = isLongClickable();
            Drawable d = selector.getCurrent();
            if (d != null && (d instanceof TransitionDrawable)) {
                if (longClickable) {
                    ((TransitionDrawable) d).startTransition(ViewConfiguration.getLongPressTimeout());
                } else {
                    ((TransitionDrawable) d).resetTransition();
                }
            }
            if (longClickable && !this.mDataChanged) {
                if (this.mPendingCheckForKeyLongPress == null) {
                    this.mPendingCheckForKeyLongPress = new CheckForKeyLongPress(this, null);
                }
                this.mPendingCheckForKeyLongPress.rememberWindowAttachCount();
                postDelayed(this.mPendingCheckForKeyLongPress, (long) ViewConfiguration.getLongPressTimeout());
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:37,代碼來源:AbsHListView.java

示例3: keyPressed

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Sets the selector state to "pressed" and posts a CheckForKeyLongPress to
 * see if this is a long press.
 */
protected void keyPressed() {
	if (!isEnabled() || !isClickable()) {
		return;
	}

	Drawable selector = mSelector;
	Rect selectorRect = mSelectorRect;
	if (selector != null && (isFocused() || touchModeDrawsInPressedState())
			&& !selectorRect.isEmpty()) {

		final View v = getChildAt(mSelectedPosition - mFirstPosition);

		if (v != null) {
			if (v.hasFocusable())
				return;
			v.setPressed(true);
		}
		setPressed(true);

		final boolean longClickable = isLongClickable();
		Drawable d = selector.getCurrent();
		if (d != null && d instanceof TransitionDrawable) {
			if (longClickable) {
				((TransitionDrawable) d).startTransition(ViewConfiguration
						.getLongPressTimeout());
			} else {
				((TransitionDrawable) d).resetTransition();
			}
		}
		if (longClickable && !mDataChanged) {
			if (mPendingCheckForKeyLongPress == null) {
				mPendingCheckForKeyLongPress = new CheckForKeyLongPress();
			}
			mPendingCheckForKeyLongPress.rememberWindowAttachCount();
			postDelayed(mPendingCheckForKeyLongPress,
					ViewConfiguration.getLongPressTimeout());
		}
	}
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:44,代碼來源:AbsHListView.java

示例4: getCurrent

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 */
@Override
@SuppressLint("NewApi")
public Drawable getCurrent() {
	if (mDrawable instanceof InsetDrawable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		final Drawable innerDrawable = ((InsetDrawable) mDrawable).getDrawable();
		return innerDrawable != null ? innerDrawable.getCurrent() : null;
	}
	return mDrawable.getCurrent();
}
 
開發者ID:universum-studios,項目名稱:android_ui,代碼行數:12,代碼來源:DrawableWrapper.java

示例5: createContrastStateDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Creates a new {@link StateListDrawable} used for {@link android.widget.ImageView} icon coloring. The resulting state list's "pressed" icon color will be
 * <b>contrasted</b> to the "pressed" color of the {@link android.widget.ImageView}'s background drawable.
 * For example, since {@link android.widget.ImageButton} extends {@link android.widget.ImageView}, you can configure the ImageView's background to be black
 * when "idle" and white when "clicked", and set a fully white "idle" icon. This means that, when you click the {@link android.widget.ImageView}, its
 * background becomes white, making the white icon impossible to see. This method returns a drawable state list that will switch the icon color to black
 * when pressed, making the icon visible even on a white background; the only thing you really need to provide here is the background color you used for
 * the pressed state.
 *
 * @param context          Which context to use
 * @param normalColor      Color normal/idle icon state to this color
 * @param pressedBackColor Background color of the View that shows up when the View is pressed
 * @param shouldFade       Set to {@code true} if the state transition should have a fading effect
 * @param original         The "idle" state icon. This is the coloring base for all states
 * @return The color state list that takes care of contrasted colors
 */
@NonNull
public static StateListDrawable createContrastStateDrawable(@NonNull final Context context, @ColorInt final int normalColor, @ColorInt final int
        pressedBackColor,
                                                            final boolean shouldFade, @NonNull final Drawable original) {
    // migrate to a static drawable
    Drawable originalState = original;
    if (originalState instanceof StateListDrawable) {
        originalState = originalState.getCurrent();
    }

    // initialize state arrays (they're in arrays because you can use different colors for reverse transitions..)
    final int[] normalState = new int[] {};
    final int[] clickedState = new int[] { android.R.attr.state_pressed };
    final int[] checkedState = new int[] { android.R.attr.state_checked };
    final int[] selectedState = new int[] { android.R.attr.state_selected };
    final int[] focusedState = new int[] { android.R.attr.state_focused };
    int[] activatedState = new int[] {};
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activatedState = new int[] { android.R.attr.state_activated };
    }

    final Drawable normalDrawable = colorDrawable(context, originalState, normalColor);
    final Drawable clickedDrawable = colorDrawable(context, originalState, contrastColor(pressedBackColor));
    final Drawable checkedDrawable = colorDrawable(context, originalState, contrastColor(pressedBackColor));
    final Drawable focusedDrawable = colorDrawable(context, originalState, contrastColor(darkenColor(pressedBackColor)));

    // prepare the state list (order of the states is extremely important!)
    final StateListDrawable states = new StateListDrawable();

    if (!shouldFade) {
        // no fading, add all applicable states
        states.addState(clickedState, clickedDrawable); // !
        states.addState(selectedState, focusedDrawable); // reuse the focused drawable
        states.addState(focusedState, focusedDrawable);
        states.addState(checkedState, checkedDrawable);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            states.addState(activatedState, focusedDrawable);
        }
        states.addState(normalState, normalDrawable); // !
        return states;
    } else {
        // fade enabled, add only normal and pressed states (Honeycomb bug..)
        states.addState(clickedState, clickedDrawable); // !
        states.addState(normalState, normalDrawable); // !
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // fading only works on Honeycomb and later..
            states.setEnterFadeDuration(0);
            states.setExitFadeDuration(DEFAULT_FADE_DURATION);
        }
        return states;
    }
}
 
開發者ID:milosmns,項目名稱:silly-android,代碼行數:69,代碼來源:Coloring.java

示例6: createMultiStateDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Creates a new, multi-state {@link StateListDrawable} using the provided static drawables.
 *
 * @param normalDrawable  Used for the normal/idle and focused states
 * @param clickedDrawable Used for the clicked/pressed state
 * @param checkedDrawable Used for the checked/selected and active states
 * @param shouldFade      Set to {@code true} if the state transition should have a fading effect
 * @return A multi-state {@link StateListDrawable} consisting out of provided drawables, always a new instance
 */
@NonNull
public static StateListDrawable createMultiStateDrawable(@NonNull final Drawable normalDrawable, @NonNull final Drawable clickedDrawable,
                                                         @NonNull final Drawable checkedDrawable, final boolean shouldFade) {
    // migrate to static drawables
    Drawable normalState = normalDrawable;
    if (normalState instanceof StateListDrawable) {
        normalState = normalState.getCurrent();
    }
    Drawable clickedState = clickedDrawable;
    if (clickedState instanceof StateListDrawable) {
        clickedState = clickedState.getCurrent();
    }
    Drawable checkedState = checkedDrawable;
    if (checkedState instanceof StateListDrawable) {
        checkedState = checkedState.getCurrent();
    }

    // initialize state arrays (they're in arrays because you can use different colors for reverse transitions..)
    final int[] normalStates = new int[] {};
    final int[] clickedStates = new int[] { android.R.attr.state_pressed };
    final int[] checkedStates = new int[] { android.R.attr.state_checked };
    final int[] selectedStates = new int[] { android.R.attr.state_selected };
    final int[] focusedStates = new int[] { android.R.attr.state_focused };
    int[] activatedState = new int[] {};
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activatedState = new int[] { android.R.attr.state_activated };
    }

    // prepare the state list (order of the states is extremely important!)
    final StateListDrawable states = new StateListDrawable();

    if (!shouldFade) {
        // no fading, add all applicable states
        states.addState(clickedStates, clickedState); // !
        states.addState(selectedStates, checkedState);
        states.addState(focusedStates, normalState);
        states.addState(checkedStates, checkedState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            states.addState(activatedState, checkedState);
        }
        states.addState(normalStates, normalState); // !
        return states;
    } else {
        // fade enabled, add only normal and pressed states (Honeycomb bug..)
        states.addState(clickedStates, clickedState); // !
        states.addState(normalStates, normalState); // !
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // fading only works on Honeycomb and later..
            states.setEnterFadeDuration(0);
            states.setExitFadeDuration(DEFAULT_FADE_DURATION);
        }
        return states;
    }
}
 
開發者ID:milosmns,項目名稱:silly-android,代碼行數:64,代碼來源:Coloring.java


注:本文中的android.graphics.drawable.Drawable.getCurrent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。