List of usage examples for android.graphics.drawable Drawable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:android.support.v7.widget.DrawableUtils.java
/** * Attempt the fix any issues in the given drawable, usually caused by platform bugs in the * implementation. This method should be call after retrieval from * {@link android.content.res.Resources} or a {@link android.content.res.TypedArray}. *//* w ww.j av a 2s.c o m*/ static void fixDrawable(@NonNull final Drawable drawable) { if (Build.VERSION.SDK_INT == 21 && VECTOR_DRAWABLE_CLAZZ_NAME.equals(drawable.getClass().getName())) { fixVectorDrawableTinting(drawable); } }
From source file:android.support.v7.internal.widget.DrawableUtils.java
/** * Allows us to get the optical insets for a {@link Drawable}. Since this is hidden we need to * use reflection. Since the {@code Insets} class is hidden also, we return a Rect instead. *///from w w w . j a v a 2 s. c o m public static Rect getOpticalBounds(Drawable drawable) { if (sInsetsClazz != null) { try { // If the Drawable is wrapped, we need to manually unwrap it and process // the wrapped drawable. drawable = DrawableCompat.unwrap(drawable); final Method getOpticalInsetsMethod = drawable.getClass().getMethod("getOpticalInsets"); final Object insets = getOpticalInsetsMethod.invoke(drawable); if (insets != null) { // If the drawable has some optical insets, let's copy them into a Rect final Rect result = new Rect(); for (Field field : sInsetsClazz.getFields()) { switch (field.getName()) { case "left": result.left = field.getInt(insets); break; case "top": result.top = field.getInt(insets); break; case "right": result.right = field.getInt(insets); break; case "bottom": result.bottom = field.getInt(insets); break; } } return result; } } catch (Exception e) { // Eugh, we hit some kind of reflection issue... Log.e(TAG, "Couldn't obtain the optical insets. Ignoring."); } } // If we reach here, either we're running on a device pre-v18, the Drawable didn't have // any optical insets, or a reflection issue, so we'll just return an empty rect return INSETS_NONE; }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private static boolean isVectorDrawable(@NonNull Drawable d) { return d instanceof VectorDrawableCompat || PLATFORM_VD_CLAZZ.equals(d.getClass().getName()); }
From source file:rhcad.touchvg.view.internal.ImageCache.java
private boolean createCache() { try {/*from w w w . ja v a 2 s .c o m*/ mCache = new LruCache<String, Drawable>(CACHE_SIZE) { @Override protected int sizeOf(String key, Drawable d) { // TODO: SVG size? int size = 1; if (d.getClass().isInstance(BitmapDrawable.class)) { size = ((BitmapDrawable) d).getBitmap().getByteCount(); } return size; } }; } catch (NoClassDefFoundError e) { Log.e(TAG, "Need android-support-v4.jar in application", e); } return mCache != null; }
From source file:cz.appvision.ebookreader.image.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//from w ww . j a v a 2 s . c om * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap Drawable currentDrawable = imageView.getDrawable(); if (currentDrawable.getClass().equals(AsyncDrawable.class)) { String placeholderKey = ((AsyncDrawable) currentDrawable).getPlaceholderKey(); imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap.get(placeholderKey))); } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.landenlabs.all_devtool.IconBaseFragment.java
/** * Display icon (drawable) information/* w w w .j a v a2s.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:com.dycody.android.idealnote.DetailFragment.java
private void replacePlayingAudioBitmap(View v) { Drawable d = ((ImageView) v.findViewById(R.id.gridview_item_picture)).getDrawable(); if (BitmapDrawable.class.isAssignableFrom(d.getClass())) { recordingBitmap = ((BitmapDrawable) d).getBitmap(); } else {//from w w w . ja v a 2 s .c o m recordingBitmap = ((GlideBitmapDrawable) d.getCurrent()).getBitmap(); } ((ImageView) v.findViewById(R.id.gridview_item_picture)).setImageBitmap(ThumbnailUtils.extractThumbnail( BitmapFactory.decodeResource(mainActivity.getResources(), R.drawable.stop), Constants.THUMBNAIL_SIZE, Constants.THUMBNAIL_SIZE)); }