List of usage examples for android.graphics.drawable AnimationDrawable getNumberOfFrames
public int getNumberOfFrames()
From source file:Main.java
/** * Gets the duration of the frames of animation in an AnimationDrawable, in milliseconds. * @param drawable//from www . j av a 2s . c o m * @return The duration of the frames in the AnimationDrawable, in milliseconds. */ public static long getAnimationDuration(AnimationDrawable drawable) { long duration = 0; for (int i = 0; i < drawable.getNumberOfFrames(); ++i) { duration += drawable.getDuration(i); } return duration; }
From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java
/** * Checks whether a Drawable is a small grayscale icon. * Grayscale here means "very close to a perfect gray"; icon means "no larger than 64dp". * * @param d The drawable to test./*from www .j av a 2 s .c o m*/ * @return True if the bitmap is grayscale; false if it is color or too large to examine. */ public boolean isGrayscaleIcon(Drawable d) { if (d == null) { return false; } else if (d instanceof BitmapDrawable) { BitmapDrawable bd = (BitmapDrawable) d; return bd.getBitmap() != null && isGrayscaleIcon(bd.getBitmap()); } else if (d instanceof AnimationDrawable) { AnimationDrawable ad = (AnimationDrawable) d; int count = ad.getNumberOfFrames(); return count > 0 && isGrayscaleIcon(ad.getFrame(0)); } else if (d instanceof VectorDrawable) { // We just assume you're doing the right thing if using vectors return true; } else { return false; } }
From source file:com.landenlabs.all_devtool.IconBaseFragment.java
/** * Display icon (drawable) information/*from www.ja v a 2 s . c o m*/ * * @param iconInfo */ private void showIconDialog(IconInfo iconInfo) { Drawable iconD = iconInfo.getDrawable(); String iconType = iconD.getClass().getSimpleName(); LayoutInflater inflater = m_context.getLayoutInflater(); final View dialogLayout = inflater.inflate(R.layout.icon_dlg, null); View shareBtn = dialogLayout.findViewById(R.id.icon_dlg_share); shareBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Utils.shareScreen(dialogLayout, "iconDetail", null); } }); final TextView imageName = Ui.viewById(dialogLayout, R.id.icon_dlg_name); final TextView imageSize = Ui.viewById(dialogLayout, R.id.icon_dlg_size); final TextView imageType = Ui.viewById(dialogLayout, R.id.icon_dlg_type); final TextView imageExtra = Ui.viewById(dialogLayout, R.id.icon_dlg_extra); imageName.setText(iconInfo.fieldStr()); imageSize.setText(String.format("Size: %d x %d", iconD.getIntrinsicWidth(), iconD.getIntrinsicHeight())); imageType.setText(iconType); final ImageView imageView = Ui.viewById(dialogLayout, R.id.icon_dlg_image); // imageView.setImageDrawable(iconD); boolean hasStates = iconD.isStateful(); final View stateTitle = dialogLayout.findViewById(R.id.icon_dlg_state_title); stateTitle.setVisibility(hasStates ? View.VISIBLE : View.GONE); final TableRow row1 = Ui.viewById(dialogLayout, R.id.icon_dlg_state_row1); row1.removeAllViews(); final TableRow row2 = Ui.viewById(dialogLayout, R.id.icon_dlg_state_row2); row2.removeAllViews(); boolean showRows = false; String extraInfo = ""; if (hasStates) { extraInfo = "StateFul"; showRows = true; StateListDrawable stateListDrawable = (StateListDrawable) iconD; Set<Drawable> stateIcons = new HashSet<Drawable>(); showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_enabled, "Enabled", stateIcons); showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_pressed, "Pressed", stateIcons); showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_checked, "Checked", stateIcons); showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_selected, "Selected", stateIcons); } if (iconType.equals(LayerDrawable.class.getSimpleName())) { showRows = true; LayerDrawable layerDrawable = (LayerDrawable) iconD; int layerCnt = layerDrawable.getNumberOfLayers(); extraInfo = String.format(Locale.getDefault(), "Layers:%d", layerCnt); for (int layerIdx = 0; layerIdx < Math.min(layerCnt, 3); layerIdx++) { showLayerIcon(imageView, row1, row2, layerDrawable.getDrawable(layerIdx), layerIdx); } } else if (iconType.equals(AnimationDrawable.class.getSimpleName())) { final AnimationDrawable animationDrawable = (AnimationDrawable) iconD; extraInfo = String.format(Locale.getDefault(), "Frames:%d", animationDrawable.getNumberOfFrames()); showRows = true; showAnimationBtns(imageView, animationDrawable, row1, row2); // Can't control animation at this time, drawable not rendered yet. // animationDrawable.stop(); } row1.setVisibility(showRows ? View.VISIBLE : View.GONE); row2.setVisibility(showRows ? View.VISIBLE : View.GONE); imageExtra.setText(extraInfo); imageView.setImageDrawable(iconD); dialogLayout.findViewById(R.id.icon_dlg_whiteBtn).setOnClickListener(new View.OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { imageView.setBackgroundDrawable(v.getBackground()); } }); dialogLayout.findViewById(R.id.icon_dlg_grayBtn).setOnClickListener(new View.OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { imageView.setBackgroundDrawable(v.getBackground()); } }); dialogLayout.findViewById(R.id.icon_dlg_blackBtn).setOnClickListener(new View.OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { imageView.setBackgroundDrawable(v.getBackground()); } }); dialogLayout.findViewById(R.id.icon_dlg_squaresBtn).setOnClickListener(new View.OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { imageView.setBackgroundDrawable(v.getBackground()); } }); AlertDialog.Builder builder = new AlertDialog.Builder(m_context); builder.setView(dialogLayout); builder.setMessage("Icon").setCancelable(false).setPositiveButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close dialog.cancel(); } }); builder.show(); }
From source file:androidx.mediarouter.app.MediaRouteButton.java
/** * Sets a drawable to use as the remote route indicator. *///w w w. j a v a 2s.co m public void setRemoteIndicatorDrawable(Drawable d) { if (mRemoteIndicatorLoader != null) { mRemoteIndicatorLoader.cancel(false); } if (mRemoteIndicator != null) { mRemoteIndicator.setCallback(null); unscheduleDrawable(mRemoteIndicator); } if (d != null) { if (mButtonTint != null) { d = DrawableCompat.wrap(d.mutate()); DrawableCompat.setTintList(d, mButtonTint); } d.setCallback(this); d.setState(getDrawableState()); d.setVisible(getVisibility() == VISIBLE, false); } mRemoteIndicator = d; refreshDrawableState(); if (mAttachedToWindow && mRemoteIndicator != null && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) { AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent(); if (mIsConnecting) { if (!curDrawable.isRunning()) { curDrawable.start(); } } else if (mRemoteActive) { if (curDrawable.isRunning()) { curDrawable.stop(); } curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1); } } }
From source file:androidx.mediarouter.app.MediaRouteButton.java
void refreshRoute() { final MediaRouter.RouteInfo route = mRouter.getSelectedRoute(); final boolean isRemote = !route.isDefaultOrBluetooth() && route.matchesSelector(mSelector); final boolean isConnecting = isRemote && route.isConnecting(); boolean needsRefresh = false; if (mRemoteActive != isRemote) { mRemoteActive = isRemote;/*from w w w. j a v a 2 s .c o m*/ needsRefresh = true; } if (mIsConnecting != isConnecting) { mIsConnecting = isConnecting; needsRefresh = true; } if (needsRefresh) { updateContentDescription(); refreshDrawableState(); } if (mAttachedToWindow) { setEnabled(mRouter.isRouteAvailable(mSelector, MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE)); } if (mRemoteIndicator != null && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) { AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent(); if (mAttachedToWindow) { if ((needsRefresh || isConnecting) && !curDrawable.isRunning()) { curDrawable.start(); } } else if (isRemote && !isConnecting) { // When the route is already connected before the view is attached, show the last // frame of the connected animation immediately. if (curDrawable.isRunning()) { curDrawable.stop(); } curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1); } } }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader./* w ww.java2 s . com*/ */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }