List of usage examples for android.graphics.drawable LayerDrawable getDrawable
public Drawable getDrawable(int index)
From source file:com.landenlabs.all_devtool.IconBaseFragment.java
/** * Display icon (drawable) information//w w w . j av 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:it.ndorigatti.android.view.MulticolorProgressBar.java
/** * Converts a drawable to a tiled version of itself. It will recursively * traverse layer and state list drawables. *//* w ww . j ava2s .c om*/ private Drawable tileify(Drawable drawable, boolean clip) { if (drawable instanceof LayerDrawable) { LayerDrawable background = (LayerDrawable) drawable; final int N = background.getNumberOfLayers(); Drawable[] outDrawables = new Drawable[N]; for (int i = 0; i < N; i++) { int id = background.getId(i); outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress)); } LayerDrawable newBg = new LayerDrawable(outDrawables); for (int i = 0; i < N; i++) { newBg.setId(i, background.getId(i)); } return newBg; } return drawable; }
From source file:de.grobox.liberario.activities.MapActivity.java
private Drawable getMarkerDrawable(MarkerType type, Line line) { // Get colors int bg = getBackgroundColor(type, line); int fg = getForegroundColor(type, line); // Get Drawable int res;//from w ww. j a v a2 s . c o m if (type == MarkerType.BEGIN) { res = R.drawable.ic_marker_trip_begin; } else if (type == MarkerType.CHANGE) { res = R.drawable.ic_marker_trip_change; } else if (type == MarkerType.END) { res = R.drawable.ic_marker_trip_end; } else if (type == MarkerType.WALK) { res = R.drawable.ic_marker_trip_walk; } else { res = R.drawable.ic_marker_intermediate_stop; } LayerDrawable drawable = (LayerDrawable) ContextCompat.getDrawable(this, res); if (drawable != null) { drawable.getDrawable(0).mutate().setColorFilter(bg, PorterDuff.Mode.MULTIPLY); drawable.getDrawable(1).mutate().setColorFilter(fg, PorterDuff.Mode.SRC_IN); } return drawable; }
From source file:android.support.v17.leanback.app.BackgroundManager.java
private TranslucentLayerDrawable createOptimizedTranslucentLayerDrawable(LayerDrawable layerDrawable) { int numChildren = layerDrawable.getNumberOfLayers(); Drawable[] drawables = new Drawable[numChildren]; for (int i = 0; i < numChildren; i++) { drawables[i] = layerDrawable.getDrawable(i); }//www. j a v a2 s. c om TranslucentLayerDrawable result = new OptimizedTranslucentLayerDrawable(drawables); for (int i = 0; i < numChildren; i++) { result.setId(i, layerDrawable.getId(i)); } return result; }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
/** * Converts a drawable to a tiled version of itself. It will recursively * traverse layer and state list drawables. *///from w w w. ja v a2s .c o m private Drawable tileify(Drawable drawable, boolean clip) { if (drawable instanceof LayerDrawable) { LayerDrawable background = (LayerDrawable) drawable; final int N = background.getNumberOfLayers(); Drawable[] outDrawables = new Drawable[N]; for (int i = 0; i < N; i++) { int id = background.getId(i); outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress)); } LayerDrawable newBg = new LayerDrawable(outDrawables); for (int i = 0; i < N; i++) { newBg.setId(i, background.getId(i)); } return newBg; } /* else if (drawable instanceof StateListDrawable) { StateListDrawable in = (StateListDrawable) drawable; StateListDrawable out = new StateListDrawable(); int numStates = in.getStateCount(); for (int i = 0; i < numStates; i++) { out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip)); } return out; }*/ else if (drawable instanceof BitmapDrawable) { final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap(); if (mSampleTile == null) { mSampleTile = tileBitmap; } final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape()); final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); shapeDrawable.getPaint().setShader(bitmapShader); return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable; } return drawable; }
From source file:org.kde.necessitas.ministro.ExtractStyle.java
private JSONObject getLayerDrawable(Object drawable, String filename) { JSONObject json = new JSONObject(); LayerDrawable layers = (LayerDrawable) drawable; final int nr = layers.getNumberOfLayers(); try {/*from ww w .j av a2 s . c o m*/ JSONArray array = new JSONArray(); for (int i = 0; i < nr; i++) { JSONObject layerJsonObject = getDrawable(layers.getDrawable(i), filename + "__" + layers.getId(i)); layerJsonObject.put("id", layers.getId(i)); array.put(layerJsonObject); } json.put("type", "layer"); Rect padding = new Rect(); if (layers.getPadding(padding)) json.put("padding", getJsonRect(padding)); json.put("layers", array); } catch (JSONException e) { e.printStackTrace(); } return json; }
From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java
private void updateButtonNextDrawable() { float realPosition = position + positionOffset; float offset = 0; if (buttonNextFunction == BUTTON_NEXT_FUNCTION_NEXT_FINISH) { if (realPosition >= adapter.getCount() - 1) { offset = 1;/*ww w.java 2 s. com*/ } else if (realPosition >= adapter.getCount() - 2) { offset = positionOffset; } } if (offset <= 0) { miButtonNext.setImageResource(R.drawable.mi_ic_next); miButtonNext.getDrawable().setAlpha(0xFF); } else { miButtonNext.setImageResource(R.drawable.mi_ic_next_finish); if (miButtonNext.getDrawable() != null && miButtonNext.getDrawable() instanceof LayerDrawable) { LayerDrawable drawable = (LayerDrawable) miButtonNext.getDrawable(); drawable.getDrawable(0).setAlpha((int) (0xFF * (1 - offset))); drawable.getDrawable(1).setAlpha((int) (0xFF * offset)); } else { miButtonNext.setImageResource(offset > 0 ? R.drawable.mi_ic_finish : R.drawable.mi_ic_next); } } }
From source file:org.musicmod.android.app.MusicPlaybackActivity.java
private void setUIColor(int color) { LayerDrawable mProgressLayer = (LayerDrawable) mProgress.getProgressDrawable(); mProgressLayer.getDrawable(mProgressLayer.getNumberOfLayers() - 1).setColorFilter(mUIColor, Mode.MULTIPLY); mProgress.invalidate();/*w w w. j av a2 s .c o m*/ mVisualizerViewFftSpectrum.setColor(color); mVisualizerViewWaveForm.setColor(color); mTouchPaintView.setColor(color); }
From source file:org.brandroid.openmanager.fragments.ContentFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { Logger.LogVerbose("ContentFragment.onPrepareOptionsMenu"); if (getActivity() == null) return;/* w ww . j a v a2s .c om*/ if (menu == null) return; if (isDetached() || !isVisible()) return; super.onPrepareOptionsMenu(menu); if (OpenExplorer.BEFORE_HONEYCOMB) MenuUtils.setMenuVisible(menu, false, R.id.menu_view_carousel); MenuUtils.setMenuVisible(menu, mPath instanceof OpenNetworkPath, R.id.menu_context_download); MenuUtils.setMenuVisible(menu, !(mPath instanceof OpenNetworkPath), R.id.menu_context_edit, R.id.menu_context_view); MenuUtils.setMenuChecked(menu, getSorting().foldersFirst(), R.id.menu_sort_folders_first); if (mPath != null) MenuUtils.setMenuEnabled(menu, !mPath.requiresThread() && mPath.canWrite(), R.id.menu_multi_all_copy, R.id.menu_multi_all_move); SortType.Type st = getSorting().getType(); int sti = Utils.getArrayIndex(sortTypes, st); if (sti > -1) MenuUtils.setMenuChecked(menu, true, sortMenuOpts[sti], sortMenuOpts); if (getClipboard() == null || getClipboard().size() == 0) { MenuUtils.setMenuVisible(menu, false, R.id.content_paste); } else { MenuItem mPaste = menu.findItem(R.id.content_paste); if (mPaste != null && getClipboard() != null && !isDetached()) mPaste.setTitle(getString(R.string.s_menu_paste) + " (" + getClipboard().size() + ")"); if (getClipboard().isMultiselect()) { LayerDrawable d = (LayerDrawable) getResources().getDrawable(R.drawable.ic_menu_paste_multi); d.getDrawable(1).setAlpha(127); if (menu.findItem(R.id.content_paste) != null) menu.findItem(R.id.content_paste).setIcon(d); } if (mPaste != null) mPaste.setVisible(true); } MenuUtils.setMenuEnabled(menu, true, R.id.menu_view, R.id.menu_sort, R.id.menu_content_ops); int mViewMode = getViewMode(); MenuUtils.setMenuChecked(menu, true, 0, R.id.menu_view_grid, R.id.menu_view_list, R.id.menu_view_carousel); if (mViewMode == OpenExplorer.VIEW_GRID) MenuUtils.setMenuChecked(menu, true, R.id.menu_view_grid, R.id.menu_view_list, R.id.menu_view_carousel); else if (mViewMode == OpenExplorer.VIEW_LIST) MenuUtils.setMenuChecked(menu, true, R.id.menu_view_list, R.id.menu_view_grid, R.id.menu_view_carousel); else if (mViewMode == OpenExplorer.VIEW_CAROUSEL) MenuUtils.setMenuChecked(menu, true, R.id.menu_view_carousel, R.id.menu_view_grid, R.id.menu_view_list); MenuUtils.setMenuChecked(menu, getShowHiddenFiles(), R.id.menu_view_hidden); MenuUtils.setMenuChecked(menu, getShowThumbnails(), R.id.menu_view_thumbs); MenuUtils.setMenuVisible(menu, OpenExplorer.CAN_DO_CAROUSEL, R.id.menu_view_carousel); }