List of usage examples for android.graphics.drawable Drawable setAlpha
public abstract void setAlpha(@IntRange(from = 0, to = 255) int alpha);
From source file:website.openeng.anki.StudyOptionsFragment.java
/** * Special method to show the context menu for the custom study options * TODO: Turn this into a DialogFragment *///from w w w.j ava 2s . c o m private void showCustomStudyContextMenu() { Resources res = getResources(); Drawable icon = res.getDrawable(R.drawable.ic_sort_black_36dp); icon.setAlpha(Themes.ALPHA_ICON_ENABLED_DARK); MaterialDialog dialog = new MaterialDialog.Builder(this.getActivity()) .title(res.getString(R.string.custom_study)).icon(icon).cancelable(true) .items(res.getStringArray(R.array.custom_study_options_labels)) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog materialDialog, View view, int which, CharSequence charSequence) { DialogFragment dialogFragment; if (which == CustomStudyDialog.CUSTOM_STUDY_TAGS) { /* * This is a special Dialog for CUSTOM STUDY, where instead of only collecting a * number, it is necessary to collect a list of tags. This case handles the creation * of that Dialog. */ dialogFragment = website.openeng.anki.dialogs.TagsDialog.newInstance( TagsDialog.TYPE_CUSTOM_STUDY_TAGS, new ArrayList<String>(), new ArrayList<String>(getCol().getTags().all())); ((TagsDialog) dialogFragment).setTagsDialogListener(new TagsDialogListener() { @Override public void onPositive(List<String> selectedTags, int option) { /* * Here's the method that gathers the final selection of tags, type of cards and generates the search * screen for the custom study deck. */ StringBuilder sb = new StringBuilder(); switch (option) { case 1: sb.append("is:new "); break; case 2: sb.append("is:due "); break; default: // Logging here might be appropriate : ) break; } List<String> arr = new ArrayList<>(); if (selectedTags.size() > 0) { for (String tag : selectedTags) { arr.add(String.format("tag:'%s'", tag)); } sb.append("(" + TextUtils.join(" or ", arr) + ")"); } mSearchTerms = sb.toString(); createFilteredDeck(new JSONArray(), new Object[] { mSearchTerms, Consts.DYN_MAX_SIZE, Consts.DYN_RANDOM }, false); } }); } else { // Show CustomStudyDialog for all options other than the tags dialog dialogFragment = CustomStudyDialog.newInstance(which); // If we increase limits, refresh the interface to reflect the new counts ((CustomStudyDialog) dialogFragment).setCustomStudyDialogListener( new CustomStudyDialog.CustomStudyDialogListener() { @Override public void onPositive(int option) { if (option == CustomStudyDialog.CUSTOM_STUDY_NEW || option == CustomStudyDialog.CUSTOM_STUDY_REV) { refreshInterfaceAndDecklist(true); } } }); } // Show the DialogFragment via Activity ((AnkiActivity) getActivity()).showDialogFragment(dialogFragment); } }).build(); dialog.setOwnerActivity(getActivity()); dialog.show(); }
From source file:co.taqat.call.AccountPreferencesFragment.java
private void initAccountPreferencesFields(PreferenceScreen parent) { boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n; accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl()); accountCreator.setListener(this); PreferenceCategory account = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_sipaccount_key)); EditTextPreference username = (EditTextPreference) account.getPreference(0); username.setOnPreferenceChangeListener(usernameChangedListener); if (!isNewAccount) { username.setText(mPrefs.getAccountUsername(n)); username.setSummary(username.getText()); }/*from w w w .ja v a2s . com*/ EditTextPreference userid = (EditTextPreference) account.getPreference(1); userid.setOnPreferenceChangeListener(useridChangedListener); if (!isNewAccount) { userid.setText(mPrefs.getAccountUserId(n)); userid.setSummary(userid.getText()); } EditTextPreference password = (EditTextPreference) account.getPreference(2); password.setOnPreferenceChangeListener(passwordChangedListener); if (!isNewAccount) { password.setText(mPrefs.getAccountPassword(n)); } EditTextPreference domain = (EditTextPreference) account.getPreference(3); domain.setOnPreferenceChangeListener(domainChangedListener); if (!isNewAccount) { domain.setText(mPrefs.getAccountDomain(n)); domain.setSummary(domain.getText()); } EditTextPreference displayName = (EditTextPreference) account.getPreference(4); displayName.setOnPreferenceChangeListener(displayNameChangedListener); if (!isNewAccount) { displayName.setText(mPrefs.getAccountDisplayName(n)); displayName.setSummary(displayName.getText()); } PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_advanced_key)); mTransportPreference = (ListPreference) advanced.getPreference(0); initializeTransportPreference(mTransportPreference); mTransportPreference.setOnPreferenceChangeListener(transportChangedListener); if (!isNewAccount) { mTransportPreference.setSummary(mPrefs.getAccountTransportString(n)); } mProxyPreference = (EditTextPreference) advanced.getPreference(1); mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener); if (!isNewAccount) { mProxyPreference.setText(mPrefs.getAccountProxy(n)); mProxyPreference .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null) ? getString(R.string.pref_help_proxy) : mProxyPreference.getText()); } CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2); outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener); if (!isNewAccount) { outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n)); } EditTextPreference expires = (EditTextPreference) advanced.getPreference(3); expires.setOnPreferenceChangeListener(expiresChangedListener); if (!isNewAccount) { expires.setText(mPrefs.getExpires(n)); expires.setSummary(mPrefs.getExpires(n)); } EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4); prefix.setOnPreferenceChangeListener(prefixChangedListener); if (!isNewAccount) { String prefixValue = mPrefs.getPrefix(n); prefix.setText(prefixValue); prefix.setSummary(prefixValue); } CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5); avpf.setOnPreferenceChangeListener(avpfChangedListener); if (!isNewAccount) { avpf.setChecked(mPrefs.avpfEnabled(n)); } EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6); avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener); if (!isNewAccount) { avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n)); avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n)); } CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7); escape.setOnPreferenceChangeListener(escapeChangedListener); if (!isNewAccount) { escape.setChecked(mPrefs.getReplacePlusByZeroZero(n)); } CheckBoxPreference friendlistSubscribe = (CheckBoxPreference) advanced.getPreference(8); friendlistSubscribe.setOnPreferenceChangeListener(friendlistSubscribeListener); if (!isNewAccount) { friendlistSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled()); } Preference linkAccount = advanced.getPreference(9); linkAccount.setOnPreferenceClickListener(linkAccountListener); PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_manage_key)); final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0); disable.setEnabled(true); disable.setOnPreferenceChangeListener(disableChangedListener); if (!isNewAccount) { disable.setChecked(!mPrefs.isAccountEnabled(n)); } CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1); mainAccount.setChecked(isDefaultAccount); mainAccount.setEnabled(!mainAccount.isChecked()); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.setDefaultAccount(n); disable.setEnabled(false); disable.setChecked(false); preference.setEnabled(false); return true; } }); if (!isNewAccount) { mainAccount.setEnabled(!mainAccount.isChecked()); } final Preference changePassword = manage.getPreference(2); if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) { changePassword.setEnabled(!isNewAccount); changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance()); LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater(); View layout = inflater.inflate(R.layout.new_password, null); final EditText pass1 = (EditText) layout.findViewById(R.id.password1); final EditText pass2 = (EditText) layout.findViewById(R.id.password2); alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinphoneAccountCreator.Status status = accountCreator .setPassword(pass1.getText().toString()); if (status.equals(LinphoneAccountCreator.Status.Ok)) { if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) { accountCreator.setUsername(mPrefs.getAccountUsername(n)); accountCreator.setHa1(mPrefs.getAccountHa1(n)); status = accountCreator.updatePassword(pass1.getText().toString()); if (!status.equals(LinphoneAccountCreator.Status.Ok)) { LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance()); } else { progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); Drawable d = new ColorDrawable(ContextCompat .getColor(LinphoneActivity.instance(), R.color.colorE)); d.setAlpha(200); progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); progress.getWindow().setBackgroundDrawable(d); progress.setContentView(R.layout.progress_dialog); progress.show(); } } else { LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched), LinphoneActivity.instance()); } return; } LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance()); } }); alert.setView(layout); alert.show(); return true; } }); } else { changePassword.setEnabled(false); } final Preference delete = manage.getPreference(3); delete.setEnabled(!isNewAccount); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.deleteAccount(n); LinphoneActivity.instance().refreshAccounts(); LinphoneActivity.instance().displaySettings(); return true; } }); }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes final int resId, @NonNull Drawable drawable) { PorterDuff.Mode tintMode = DEFAULT_MODE; boolean colorAttrSet = false; int colorAttr = 0; int alpha = -1; if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) { colorAttr = R.attr.colorControlNormal_ox; colorAttrSet = true;//from w w w .j av a 2 s.com } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) { colorAttr = R.attr.colorControlActivated_ox; colorAttrSet = true; } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; tintMode = PorterDuff.Mode.MULTIPLY; } else { colorAttr = android.R.attr.colorForeground; colorAttrSet = true; alpha = Math.round(0.16f * 255); } if (colorAttrSet) { if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } final int color = ThemeUtils.getThemeAttrColor(context, colorAttr); drawable.setColorFilter(getPorterDuffColorFilter(color, tintMode)); if (alpha != -1) { drawable.setAlpha(alpha); } if (DEBUG) { Log.d(TAG, "[tintDrawableUsingColorFilter] Tinted " + context.getResources().getResourceName(resId) + " with color: #" + Integer.toHexString(color)); } return true; } return false; }
From source file:com.appeaser.sublimenavigationviewlibrary.SublimeSwitchItemView.java
public void setCheckableItemTintList(ColorStateList checkableItemTintList) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Covers android M (23) Drawable dTrack = getResources().getDrawable(R.drawable.snv_switch_track_material, getContext().getTheme()); Drawable dThumb = getResources().getDrawable(R.drawable.snv_switch_thumb_material_anim, getContext().getTheme()); if (dTrack != null && dThumb != null) { DrawableCompat.setTintList(dTrack, checkableItemTintList); DrawableCompat.setTintList(dThumb, checkableItemTintList); mSwitch.setTrackDrawable(dTrack); mSwitch.setThumbDrawable(dThumb); }//from w w w . java 2s . c o m } else { Drawable dTrack = ContextCompat.getDrawable(getContext(), R.drawable.snv_switch_track); Drawable dThumb = ContextCompat.getDrawable(getContext(), R.drawable.switch_thumb_pre_lollipop); if (dTrack != null && dThumb != null) { dTrack = DrawableCompat.wrap(dTrack); DrawableCompat.setTintList(dTrack, checkableItemTintList); dTrack.setAlpha(85 /* 0.3f */); dThumb = DrawableCompat.wrap(dThumb); DrawableCompat.setTintList(dThumb, checkableItemTintList); mSwitch.setTrackDrawable(dTrack); mSwitch.setThumbDrawable(dThumb); } } }
From source file:org.mythdroid.remote.TVRemote.java
private void setBackground(final int id, final Program prog, final View v) { final Drawable metal = getResources().getDrawable(R.drawable.metal); if (!Globals.haveServices()) { v.setBackgroundDrawable(metal);// w ww.j a v a 2s . com return; } final DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); final int height = (int) (dm.heightPixels / 1.5); final int width = (int) (dm.widthPixels / 1.5); final ArtworkType type = (width > height) ? ArtworkType.fanart : ArtworkType.coverart; Globals.runOnThreadPool(new Runnable() { @Override public void run() { Bitmap bm = null; if (videoId != -1) bm = Video.getArtwork(id, type, width, 0, null); else if (prog != null) bm = prog.getArtwork(type, width, 0); final Drawable d = (bm == null) ? metal : new BitmapDrawable(getResources(), bm); if (bm != null) d.setAlpha(65); handler.post(new Runnable() { @Override public void run() { if (v == null) return; v.setBackgroundDrawable(d); } }); } }); }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes final int resId, @NonNull Drawable drawable) { PorterDuff.Mode tintMode = DEFAULT_MODE; boolean colorAttrSet = false; int colorAttr = 0; int alpha = -1; if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) { colorAttr = R.attr.colorControlNormal; colorAttrSet = true;/* w w w . java2 s .c o m*/ } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) { colorAttr = R.attr.colorControlActivated; colorAttrSet = true; } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; tintMode = PorterDuff.Mode.MULTIPLY; } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) { colorAttr = android.R.attr.colorForeground; colorAttrSet = true; alpha = Math.round(0.16f * 255); } else if (resId == R.drawable.abc_dialog_material_background) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; } if (colorAttrSet) { if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } final int color = getThemeAttrColor(context, colorAttr); drawable.setColorFilter(getPorterDuffColorFilter(color, tintMode)); if (alpha != -1) { drawable.setAlpha(alpha); } if (DEBUG) { Log.d(TAG, "[tintDrawableUsingColorFilter] Tinted " + context.getResources().getResourceName(resId) + " with color: #" + Integer.toHexString(color)); } return true; } return false; }
From source file:com.tr4android.support.extension.widget.FlexibleToolbarLayout.java
/** * Set the drawable to use for the content scrim from resources. Providing null will disable * the scrim functionality./*w w w.j a v a 2 s .co m*/ * * @param drawable the drawable to display * @attr ref R.styleable#FlexibleToolbarLayout_contentScrimColor * @see #getContentScrim() */ public void setContentScrim(@Nullable Drawable drawable) { if (mContentScrim != drawable) { if (mContentScrim != null) { mContentScrim.setCallback(null); } if (drawable != null) { mContentScrim = drawable.mutate(); drawable.setBounds(0, 0, getWidth(), getHeight()); drawable.setCallback(this); drawable.setAlpha(mScrimAlpha); } else { mContentScrim = null; } ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.custom.music.MusicBrowserActivity.java
/** * update play back tab info/* ww w. ja va 2s . com*/ */ private void updatePlaybackTab() { final int drawalbeTopPostion = 1; final int opaqueFull = 255; // 100% final int opaqueHalf = 128; // 50% TabWidget tabWidgetTemp = mTabHost.getTabWidget(); TextView tabView = (TextView) tabWidgetTemp.getChildTabViewAt(PLAYBACK_INDEX); boolean enable = true; long id = -1; Drawable[] drawables; Drawable drawableTop = null; int drawableTopAlpha = opaqueFull; if (tabView == null) { return; } try { if (mService != null) { id = mService.getAudioId(); } } catch (RemoteException ex) { Log.e(TAG, "updatePlaybackTab getAudioId remote excption:" + ex, Log.APP); } if (id == -1) { enable = false; drawableTopAlpha = opaqueHalf; } tabView.setEnabled(enable); drawables = tabView.getCompoundDrawables(); drawableTop = drawables[drawalbeTopPostion]; if (drawableTop != null) { drawableTop.setAlpha(drawableTopAlpha); } Log.i(TAG, "updatePlaybackTab:" + enable, Log.APP); }
From source file:com.android.music.MusicBrowserActivity.java
/** * update play back tab info//from w w w.ja v a 2 s.co m */ private void updatePlaybackTab() { final int drawalbeTopPostion = 1; final int opaqueFull = 255; // 100% final int opaqueHalf = 128; // 50% TabWidget tabWidgetTemp = mTabHost.getTabWidget(); TextView tabView = (TextView) tabWidgetTemp.getChildTabViewAt(PLAYBACK_INDEX); boolean enable = true; long id = -1; Drawable[] drawables; Drawable drawableTop = null; int drawableTopAlpha = opaqueFull; if (tabView == null) { return; } try { if (mService != null) { id = mService.getAudioId(); } } catch (RemoteException ex) { MusicLogUtils.e(TAG, "updatePlaybackTab getAudioId remote excption:" + ex); } if (id == -1) { enable = false; drawableTopAlpha = opaqueHalf; } tabView.setEnabled(enable); drawables = tabView.getCompoundDrawables(); drawableTop = drawables[drawalbeTopPostion]; if (drawableTop != null) { drawableTop.setAlpha(drawableTopAlpha); } MusicLogUtils.d(TAG, "updatePlaybackTab:" + enable); }
From source file:android.support.v7.internal.widget.TintManager.java
void tintDrawable(final int resId, final Drawable drawable) { PorterDuff.Mode tintMode = null;/* w w w. j a v a 2 s . c om*/ boolean colorAttrSet = false; int colorAttr = 0; int alpha = -1; if (arrayContains(TINT_COLOR_CONTROL_NORMAL, resId)) { colorAttr = R.attr.colorControlNormal; colorAttrSet = true; } else if (arrayContains(TINT_COLOR_CONTROL_ACTIVATED, resId)) { colorAttr = R.attr.colorControlActivated; colorAttrSet = true; } else if (arrayContains(TINT_COLOR_BACKGROUND_MULTIPLY, resId)) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; tintMode = PorterDuff.Mode.MULTIPLY; } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) { colorAttr = android.R.attr.colorForeground; colorAttrSet = true; alpha = Math.round(0.16f * 255); } if (colorAttrSet) { if (tintMode == null) { tintMode = DEFAULT_MODE; } final int color = getThemeAttrColor(mContext, colorAttr); tintDrawableUsingColorFilter(drawable, color, tintMode); if (alpha != -1) { drawable.setAlpha(alpha); } if (DEBUG) { Log.d(TAG, "Tinted Drawable ID: " + mResources.getResourceName(resId) + " with color: #" + Integer.toHexString(color)); } } }