List of usage examples for android.graphics.drawable Drawable setColorFilter
public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode)
From source file:org.totschnig.myexpenses.fragment.TransactionList.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (mAccount == null || getActivity() == null) { //mAccount seen in report 3331195c529454ca6b25a4c5d403beda //getActivity seen in report 68a501c984bdfcc95b40050af4f815bf return;/* w w w. j a va 2 s . c om*/ } MenuItem searchMenu = menu.findItem(R.id.SEARCH_COMMAND); if (searchMenu != null) { String title; Drawable searchMenuIcon = searchMenu.getIcon(); if (!mFilter.isEmpty()) { if (searchMenuIcon != null) { searchMenuIcon.setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY); } else { AcraHelper.report(new Exception("Search menu icon not found")); } searchMenu.setChecked(true); title = mAccount.label + " ( " + mFilter.prettyPrint() + " )"; } else { if (searchMenuIcon != null) { searchMenuIcon.setColorFilter(null); } else { AcraHelper.report(new Exception("Search menu icon not found")); } searchMenu.setChecked(false); title = mAccount.label; } ((MyExpenses) getActivity()).setTitle(title); SubMenu filterMenu = searchMenu.getSubMenu(); for (int i = 0; i < filterMenu.size(); i++) { MenuItem filterItem = filterMenu.getItem(i); boolean enabled = true; switch (filterItem.getItemId()) { case R.id.FILTER_CATEGORY_COMMAND: enabled = mappedCategories; break; case R.id.FILTER_STATUS_COMMAND: enabled = !mAccount.type.equals(AccountType.CASH); break; case R.id.FILTER_PAYEE_COMMAND: enabled = mappedPayees; break; case R.id.FILTER_METHOD_COMMAND: enabled = mappedMethods; break; case R.id.FILTER_TRANSFER_COMMAND: enabled = hasTransfers; break; } Criteria c = mFilter.get(filterItem.getItemId()); Utils.menuItemSetEnabledAndVisible(filterItem, enabled || c != null); if (c != null) { filterItem.setChecked(true); filterItem.setTitle(c.prettyPrint()); } } } else { AcraHelper.report(new Exception("Search menu not found")); } }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
public void resetActionBarDownload() { if (isAdded()) { if (toolbarMenu != null) { handler.post(new Runnable() { @Override/*from w w w. jav a 2 s .com*/ public void run() { Drawable drawable = getResources().getDrawable(R.drawable.ic_file_download_white_24dp); drawable.setColorFilter(AppSettings.getColorFilterInt(appContext), PorterDuff.Mode.MULTIPLY); toolbarMenu.getItem(1).setIcon(drawable); } }); } } }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
/** * Starts (or stops) download and sets download icon appropriately *//*w ww .j a va2 s . com*/ private void startDownload() { listAdapter.saveData(); if (FileHandler.isDownloading) { DialogFactory.ActionDialogListener listener = new DialogFactory.ActionDialogListener() { @Override public void onClickRight(View v) { FileHandler.cancel(appContext); resetActionBarDownload(); dismissDialog(); } }; DialogFactory.showActionDialog(appContext, "", "Cancel download?", listener, -1, R.string.cancel_button, R.string.ok_button); } else if (FileHandler.download(appContext)) { Drawable drawable = getResources().getDrawable(R.drawable.ic_cancel_white_24dp); drawable.setColorFilter(AppSettings.getColorFilterInt(appContext), PorterDuff.Mode.MULTIPLY); toolbarMenu.getItem(1).setIcon(drawable); if (AppSettings.resetOnManualDownload() && AppSettings.useTimer() && AppSettings.getTimerDuration() > 0) { Intent intent = new Intent(); intent.setAction(LiveWallpaperService.DOWNLOAD_WALLPAPER); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + AppSettings.getTimerDuration(), AppSettings.getTimerDuration(), pendingIntent); } } }
From source file:com.htc.dotdesign.ToolBoxService.java
private void setSelectedColor(ImageView button) { Drawable select = getResources().getDrawable(R.drawable.dot_design_select); select.setColorFilter(getResources().getColor(R.color.overlay_color), Mode.SRC_IN); ImageView selectedIcon = (ImageView) mPalette.findViewById(R.id.selected); selectedIcon.setBackground(select);/*w w w . ja v a 2s .c o m*/ Resources res = getResources(); int id = button.getId(); int buttonLeft = button.getLeft(); int buttonTop = button.getTop(); int m1 = res.getDimensionPixelSize(R.dimen.margin_l); int m2 = res.getDimensionPixelSize(R.dimen.margin_m); int colorSize = res.getDimensionPixelSize(R.dimen.hv01); if (id == R.id.btn_color_11 || id == R.id.btn_color_12 || id == R.id.btn_color_13 || id == R.id.btn_color_14) { buttonTop = m2; } else if (id == R.id.btn_color_21 || id == R.id.btn_color_22 || id == R.id.btn_color_23 || id == R.id.btn_color_24) { buttonTop = m2 + colorSize + m1; } else { buttonTop = m2 + 2 * colorSize + 2 * m1; } if (id == R.id.btn_color_11 || id == R.id.btn_color_21 || id == R.id.btn_color_31) { buttonLeft = m2; } else if (id == R.id.btn_color_12 || id == R.id.btn_color_22 || id == R.id.btn_color_32) { buttonLeft = 3 * m2 + colorSize; } else if (id == R.id.btn_color_13 || id == R.id.btn_color_23 || id == R.id.btn_color_33) { buttonLeft = 5 * m2 + 2 * colorSize; } else { buttonLeft = 7 * m2 + 3 * colorSize; } int widthDiff = res.getDimensionPixelSize(R.dimen.select_color_width) - colorSize; int heightDiff = res.getDimensionPixelSize(R.dimen.select_color_height) - colorSize; int marginLeft = buttonLeft - (widthDiff / 2); int marginTop = buttonTop - (heightDiff / 2); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) selectedIcon.getLayoutParams(); params.setMargins(marginLeft, marginTop, 0, 0); selectedIcon.setLayoutParams(params); selectedIcon.setVisibility(View.VISIBLE); }
From source file:emu.project64.GalleryActivity.java
private void StartGameMenu(boolean ShowSettings) { File InstantSaveDir = new File( NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); final File GameSaveDir = new File(InstantSaveDir, NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); class Item {//from w ww . java2s .com public final String text; public final int icon; public Item(String text, Integer icon) { this.text = text; this.icon = icon; } @Override public String toString() { return text; } } List<Item> menuItemLst = new ArrayList<Item>(); if (ShouldShowSupportWindow()) { menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock)); menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock)); } else { menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_controller)); menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_play)); } menuItemLst.add(new Item("Restart", R.drawable.ic_refresh)); if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue())) { menuItemLst.add(new Item("Settings", R.drawable.ic_sliders)); } Item[] itemsDynamic = new Item[menuItemLst.size()]; itemsDynamic = menuItemLst.toArray(itemsDynamic); final Item[] items = itemsDynamic; final File SaveDir = GameSaveDir; ListAdapter adapter = new ArrayAdapter<Item>(this, android.R.layout.select_dialog_item, android.R.id.text1, items) { public View getView(int position, View convertView, android.view.ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); // Get Drawable icon Drawable d = items[position].icon != 0 ? ResourcesCompat.getDrawable(getResources(), items[position].icon, null) : null; tv.setTextColor(Color.parseColor("#FFFFFF")); if (d != null) { d.setColorFilter(Color.parseColor("#FFFFFF"), android.graphics.PorterDuff.Mode.SRC_ATOP); } if (!isEnabled(position)) { tv.setTextColor(Color.parseColor("#555555")); if (d != null) { d.setColorFilter(Color.parseColor("#555555"), android.graphics.PorterDuff.Mode.SRC_ATOP); } } //Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); //Add margin between image and text (support various screen densities) int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } @Override public boolean areAllItemsEnabled() { return true; } @Override public boolean isEnabled(int position) { if (position == 1 && HasAutoSave(SaveDir) == false) { return false; } if (position == 2 && SaveDir.exists() == false) { return false; } return true; } }; final Context finalContext = this; final Activity finalActivity = this; AlertDialog.Builder GameMenu = new AlertDialog.Builder(finalContext); GameMenu.setTitle(NativeExports.SettingsLoadString(SettingsID.Game_GoodName.getValue())); GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if ((item == 0 || item == 1) && ShouldShowSupportWindow()) { ShowSupportWindow(); return; } if (item == 0) { launchGameActivity(); } else if (item == 1) { NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); launchGameActivity(); } else if (item == 2) { AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext); ResetPrompt.setTitle(getText(R.string.confirmResetGame_title)) .setMessage(getText(R.string.confirmResetGame_message)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String[] entries = SaveDir.list(); for (String s : entries) { File currentFile = new File(SaveDir.getPath(), s); currentFile.delete(); } SaveDir.delete(); NativeExports.UISettingsSaveDword(UISettingID.Game_RunCount.getValue(), 0); launchGameActivity(); } }).setNegativeButton(android.R.string.cancel, this).show(); } else if (item == 3) { Intent SettingsIntent = new Intent(finalContext, GameSettingsActivity.class); startActivityForResult(SettingsIntent, RC_SETTINGS); } } }); GameMenu.show(); }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Inflate menu and hold reference in toolbarMenu inflater.inflate(R.menu.source_list_menu, menu); super.onCreateOptionsMenu(menu, inflater); toolbarMenu = menu;//from w w w . jav a2 s . c o m // Sets correct colors of toolbar icons int colorFilterInt = AppSettings.getColorFilterInt(appContext); Drawable refreshIcon = getResources().getDrawable(R.drawable.ic_refresh_white_24dp); Drawable storageIcon = getResources().getDrawable(R.drawable.ic_sort_white_24dp); refreshIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY); storageIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY); menu.getItem(0).setIcon(refreshIcon); menu.getItem(2).setIcon(storageIcon); // Recounts images new ImageCountTask().execute(); }
From source file:com.jaredrummler.materialspinner.MaterialSpinner.java
@Override public void setBackgroundColor(int color) { backgroundColor = color;/*from ww w .jav a2 s .com*/ Drawable background = getBackground(); if (background instanceof StateListDrawable) { // pre-L try { Method getStateDrawable = StateListDrawable.class.getDeclaredMethod("getStateDrawable", int.class); if (!getStateDrawable.isAccessible()) getStateDrawable.setAccessible(true); int[] colors = { darker(color, 0.85f), color }; for (int i = 0; i < colors.length; i++) { ColorDrawable drawable = (ColorDrawable) getStateDrawable.invoke(background, i); drawable.setColor(colors[i]); } } catch (Exception e) { Log.e("MaterialSpinner", "Error setting background color", e); } } else if (background != null) { // 21+ (RippleDrawable) background.setColorFilter(color, PorterDuff.Mode.SRC_IN); } popupWindow.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN); }
From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java
private void setColors(Palette palette) { this.palette = palette; hideLoader();//from w w w . j ava 2s.com Palette.Swatch swatch = PaletteRequest.getBestSwatch(palette, palette.getDarkMutedSwatch()); if (swatch != null) { photoLayoutHolder.setBackgroundColor(swatch.getRgb()); findViewById(R.id.image_details_root).setBackgroundColor(swatch.getRgb()); Drawable floatingButtonBackground = getResources().getDrawable(R.drawable.floating_action_button); Drawable floatingButtonIcon = getResources().getDrawable(R.drawable.ic_mask_fullscreen); Palette.Swatch fabSwatch = PaletteRequest.getBestSwatch(palette, palette.getVibrantSwatch()); if (fabSwatch != null) { floatingButtonBackground.setColorFilter(fabSwatch.getRgb(), PorterDuff.Mode.MULTIPLY); floatingButtonIcon.setColorFilter(fabSwatch.getBodyTextColor(), PorterDuff.Mode.MULTIPLY); } buttonFullscreen.setBackgroundDrawable(floatingButtonBackground); buttonFullscreen.setImageDrawable(floatingButtonIcon); buttonFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleZoomImage(); } }); toolbar.setBackgroundColor(swatch.getRgb()); buttonSetAs.setTextColor(swatch.getBodyTextColor()); buttonSave.setTextColor(swatch.getBodyTextColor()); setToolbarClickListeners(); animateToolbar(View.VISIBLE); } }
From source file:org.cobaltians.cobalt.activities.CobaltActivity.java
public void setBarContent(JSONObject content) { Toolbar topBar = (Toolbar) findViewById(getTopBarId()); ActionBar actionBar = getSupportActionBar(); BottomBar bottomBar = (BottomBar) findViewById(getBottomBarId()); int colorInt = CobaltFontManager.DEFAULT_COLOR; boolean applyColor = false; try {/*from ww w . j a v a2 s . co m*/ String backgroundColor = content.optString(Cobalt.kBarsBackgroundColor, null); // TODO: apply on overflow popup if (backgroundColor != null) { int backgroundColorInt = Cobalt.parseColor(backgroundColor); if (actionBar != null) actionBar.setBackgroundDrawable(new ColorDrawable(backgroundColorInt)); bottomBar.setBackgroundColor(backgroundColorInt); } } catch (IllegalArgumentException exception) { if (Cobalt.DEBUG) { Log.w(Cobalt.TAG, TAG + " - setBarContent: backgroundColor format not supported, use (#)RGB or (#)RRGGBB(AA)."); } exception.printStackTrace(); } try { String color = content.optString(Cobalt.kBarsColor, null); if (color != null) { colorInt = Cobalt.parseColor(color); applyColor = true; topBar.setTitleTextColor(colorInt); Drawable overflowIconDrawable = topBar.getOverflowIcon(); // should never be null but sometimes.... if (overflowIconDrawable != null) { overflowIconDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP); } Drawable navigationIconDrawable = topBar.getNavigationIcon(); // should never be null but sometimes.... if (navigationIconDrawable != null) { navigationIconDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP); } } } catch (IllegalArgumentException exception) { if (Cobalt.DEBUG) { Log.w(Cobalt.TAG, TAG + " - setupBars: color format not supported, use (#)RGB or (#)RRGGBB(AA)."); } exception.printStackTrace(); } String logo = content.optString(Cobalt.kBarsIcon, null); if (logo != null && !logo.equals("")) { Drawable logoDrawable = null; int logoResId = getResourceIdentifier(logo); if (logoResId != 0) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { logoDrawable = getResources().getDrawable(logoResId, null); } else { logoDrawable = getResources().getDrawable(logoResId); } if (applyColor && logoDrawable != null) { logoDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP); } } catch (Resources.NotFoundException exception) { Log.w(Cobalt.TAG, TAG + " - setupBars: " + logo + " resource not found."); exception.printStackTrace(); } } else { logoDrawable = CobaltFontManager.getCobaltFontDrawable(getApplicationContext(), logo, colorInt); } topBar.setLogo(logoDrawable); if (actionBar != null) actionBar.setDisplayShowHomeEnabled(true); } else { if (actionBar != null) actionBar.setDisplayShowHomeEnabled(false); } if (content.has(Cobalt.kBarsNavigationIcon)) { try { JSONObject navigationIcon = content.getJSONObject(Cobalt.kBarsNavigationIcon); if (navigationIcon == null) navigationIcon = new JSONObject(); boolean enabled = navigationIcon.optBoolean(Cobalt.kNavigationIconEnabled, true); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(enabled); Drawable navigationIconDrawable = null; String icon = navigationIcon.optString(Cobalt.kNavigationIconIcon); if (icon != null) { int iconResId = getResourceIdentifier(icon); if (iconResId != 0) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { navigationIconDrawable = getResources().getDrawable(iconResId, null); } else { navigationIconDrawable = getResources().getDrawable(iconResId); } if (applyColor && navigationIconDrawable != null) { navigationIconDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP); } } catch (Resources.NotFoundException exception) { Log.w(Cobalt.TAG, TAG + " - setupBars: " + icon + " resource not found."); exception.printStackTrace(); } } else { navigationIconDrawable = CobaltFontManager.getCobaltFontDrawable(getApplicationContext(), icon, colorInt); } topBar.setNavigationIcon(navigationIconDrawable); } } catch (JSONException e) { e.printStackTrace(); } } if (content.has(Cobalt.kBarsTitle) && actionBar != null) { try { String title = content.getString(Cobalt.kBarsTitle); if (title != null) { actionBar.setTitle(title); } else { actionBar.setDisplayShowTitleEnabled(false); } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
private void setColors(Palette palette) { this.palette = palette; hideLoader();/*w w w. ja v a 2 s.c o m*/ Palette.Swatch swatch = PaletteRequest.getBestSwatch(palette, palette.getDarkMutedSwatch()); if (swatch != null) { photoLayoutHolder.setBackgroundColor(swatch.getRgb()); Drawable floatingButtonBackground = getResources().getDrawable(R.drawable.floating_action_button); Drawable floatingButtonIcon = getResources().getDrawable(R.drawable.ic_mask_fullscreen); Palette.Swatch fabSwatch = PaletteRequest.getBestSwatch(palette, palette.getVibrantSwatch()); if (fabSwatch != null) { floatingButtonBackground.setColorFilter(fabSwatch.getRgb(), PorterDuff.Mode.MULTIPLY); floatingButtonIcon.setColorFilter(fabSwatch.getBodyTextColor(), PorterDuff.Mode.MULTIPLY); } buttonFullscreen.setBackgroundDrawable(floatingButtonBackground); buttonFullscreen.setImageDrawable(floatingButtonIcon); buttonFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleZoomImage(); } }); toolbar.setBackgroundColor(swatch.getRgb()); buttonSetAs.setTextColor(swatch.getBodyTextColor()); buttonSave.setTextColor(swatch.getBodyTextColor()); setToolbarClickListeners(); animateToolbar(View.VISIBLE); } }