下面列出了android.graphics.drawable.Drawable#setTint() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void bind(BrowserMenuAdapter.MenuItem.Default menuItem) {
menuItemView.setId(menuItem.getId());
menuItemView.setText(menuItem.getLabel());
if (menuItem.getDrawableResId() != 0) {
final Drawable drawable = menuItemView.getContext().getDrawable(menuItem.getDrawableResId());
if (drawable != null) {
drawable.setTint(menuItemView.getContext().getResources().getColor(R.color.colorSettingsTint));
menuItemView.setCompoundDrawablesRelativeWithIntrinsicBounds(
drawable,
null,
null,
null
);
}
}
final boolean isLoading = browserFragment.getSession().getLoading();
if ((menuItem.getId() == R.id.add_to_homescreen || menuItem.getId() == R.id.find_in_page) && isLoading) {
menuItemView.setTextColor(browserFragment.getResources().getColor(R.color.colorTextInactive));
menuItemView.setClickable(false);
} else {
menuItemView.setOnClickListener(this);
}
}
private static Drawable getTintedDrawable(Context context, int drawableRes, int color) {
Drawable drawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable = context.getResources().getDrawable(drawableRes, null);
if (drawable != null) {
drawable.setTint(color);
}
} else {
drawable = context.getResources().getDrawable(drawableRes);
if (drawable != null) {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
return drawable;
}
/**
* Creates an overlay with a background color and a thumbnail for the cross profile apps
* animation.
*/
GraphicBuffer createCrossProfileAppsThumbnail(
@DrawableRes int thumbnailDrawableRes, Rect frame) {
final int width = frame.width();
final int height = frame.height();
final Picture picture = new Picture();
final Canvas canvas = picture.beginRecording(width, height);
canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
drawable.setBounds(
(width - thumbnailSize) / 2,
(height - thumbnailSize) / 2,
(width + thumbnailSize) / 2,
(height + thumbnailSize) / 2);
drawable.setTint(mContext.getColor(android.R.color.white));
drawable.draw(canvas);
picture.endRecording();
return Bitmap.createBitmap(picture).createGraphicBufferHandle();
}
@SuppressLint("SetTextI18n")
@Override
public void onReceive(Context context, Intent intent) {
int count = intent.getIntExtra("count", 0);
if(count > 0) {
int color = ColorUtils.setAlphaComponent(U.getBackgroundTint(context), 255);
notificationCountText.setTextColor(color);
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.tb_circle);
drawable.setTint(U.getAccentColor(context));
notificationCountCircle.setImageDrawable(drawable);
notificationCountText.setText(Integer.toString(count));
} else {
notificationCountCircle.setImageDrawable(null);
notificationCountText.setText(null);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Drawable getIcon(String chanName, int tint) {
if (C.API_LOLLIPOP) {
Drawable drawable = chanHolders.get(chanName).icon;
if (drawable == null) {
drawable = MainApplication.getInstance().getDrawable(R.drawable.ic_extension_white);
}
drawable = drawable.getConstantState().newDrawable().mutate();
drawable.setTint(tint);
return drawable;
}
return null;
}
@Override
public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Drawable badge = getManagedProfileIconForDensity(user,
com.android.internal.R.drawable.ic_corp_badge_no_background, density);
if (badge != null) {
badge.setTint(getUserBadgeColor(user));
}
return badge;
}
void updateCurrentFavorite(boolean favorite, boolean useAnim) {
Drawable select;
Drawable notSelect;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
select = activity.getDrawable(R.drawable.ic_favorite);
notSelect = activity.getDrawable(R.drawable.ic_favorite_border);
} else {
select = activity.getResources().getDrawable(R.drawable.ic_favorite);
notSelect = activity.getResources().getDrawable(R.drawable.ic_favorite_border);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (notSelect != null) {
notSelect.setTint(currentDrawableColor);
}
if (select != null) {
int color = activity.getResources().getColor(R.color.favorite);
select.setTint(color);
}
}
if (useAnim) {
if (favorite) {
startFavoriteSwitchAnim(select);
} else {
startFavoriteSwitchAnim(notSelect);
}
} else {
playFavorite.setImageDrawable(favorite ? select : notSelect);
}
}
@Override
public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Drawable badge = getManagedProfileIconForDensity(user,
com.android.internal.R.drawable.ic_corp_badge_no_background, density);
if (badge != null) {
badge.setTint(getUserBadgeColor(user));
}
return badge;
}
@Override
public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Drawable badgeColor = getManagedProfileIconForDensity(user,
com.android.internal.R.drawable.ic_corp_badge_color, density);
if (badgeColor == null) {
return null;
}
badgeColor.setTint(getUserBadgeColor(user));
Drawable badgeForeground = getDrawableForDensity(
com.android.internal.R.drawable.ic_corp_badge_case, density);
Drawable badge = new LayerDrawable(
new Drawable[] {badgeColor, badgeForeground });
return badge;
}
public static void setTint(Drawable drawable, int color){
if(Build.VERSION.SDK_INT >= 21){
drawable.setTint(color);
}else{
drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
private void updateAmPmDisplay(int amOrPm) {
int firstColor = amOrPm == HALF_DAY_1 ? mHalfDaySelectedColor : mHalfDayUnselectedColor;
int secondColor = amOrPm == HALF_DAY_2 ? mHalfDaySelectedColor : mHalfDayUnselectedColor;
if (mIs24HourMode) {
final Drawable firstHalfDayToggle = mFirstHalfDayToggle.getDrawable();
final Drawable secondHalfDayToggle = mSecondHalfDayToggle.getDrawable();
if (Utils.checkApiLevel(Build.VERSION_CODES.LOLLIPOP)) {
firstHalfDayToggle.setTint(firstColor);
secondHalfDayToggle.setTint(secondColor);
} else {
// Ignore the Lint warning that says the casting is redundant;
// it is in fact necessary.
((VectorDrawableCompat) firstHalfDayToggle).setTint(firstColor);
((VectorDrawableCompat) secondHalfDayToggle).setTint(secondColor);
}
} else {
mAmTextView.setTextColor(firstColor);
mPmTextView.setTextColor(secondColor);
}
if (amOrPm == HALF_DAY_1) {
Utils.tryAccessibilityAnnounce(mTimePicker, mAmText);
mAmPmHitspace.setContentDescription(mAmText);
} else if (amOrPm == HALF_DAY_2) {
Utils.tryAccessibilityAnnounce(mTimePicker, mPmText);
mAmPmHitspace.setContentDescription(mPmText);
} else {
mAmTextView.setText(mDoublePlaceholderText);
}
}
public Drawable getIconForBackground(Context context, int background) {
if (mIsIconLarge) {
// Only small icons should be tinted.
return mIconDrawable;
}
mIconColor = IconPalette.resolveContrastColor(context, mIconColor, background);
Drawable icon = mIconDrawable.mutate();
// DrawableContainer ignores the color filter if it's already set, so clear it first to
// get it set and invalidated properly.
icon.setTintList(null);
icon.setTint(mIconColor);
return icon;
}
@Override
public void themeChange(ThemeEnum themeEnum, int[] colors) {
int[] cs2 = ColorUtils.get2ActionStatusBarColors(this);
int actionC = cs2[0];
int statusC = cs2[1];
toolbar.setBackgroundColor(statusC);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(actionC);
}
ThemeEnum theme = appPreference.getTheme();
int[] cs = ColorUtils.get10ThemeColors(this, theme);
int vicBC = theme == ThemeEnum.WHITE ? Color.WHITE : cs[4];
int mainTC = cs[5];
int vicTC = cs[6];
guide.setTextColor(mainTC);
star.setTextColor(mainTC);
share.setTextColor(mainTC);
name.setTextColor(vicTC);
version.setTextColor(mainTC);
container.setBackgroundColor(vicBC);
Drawable d;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
d = getDrawable(R.drawable.ic_navigate_next);
d.setTint(vicTC);
} else {
d = getResources().getDrawable(R.drawable.ic_navigate_next);
}
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
d.setAlpha(150);
guide.setCompoundDrawables(null, null, d, null);
star.setCompoundDrawables(null, null, d, null);
share.setCompoundDrawables(null, null, d, null);
}
private String updatePlayMode() throws RemoteException {
Drawable drawable = null;
String mod;
int mode = control.getPlayMode();
switch (mode) {
case PlayController.MODE_SINGLE_LOOP:
drawable = activity.getResources().getDrawable(R.drawable.single_loop);
mod = activity.getString(R.string.play_mode_single_loop);
break;
case PlayController.MODE_RANDOM:
drawable = activity.getResources().getDrawable(R.drawable.random);
mod = activity.getString(R.string.play_mode_random);
break;
case PlayController.MODE_LIST_LOOP:
default:
drawable = activity.getResources().getDrawable(R.drawable.list_loop);
mod = activity.getString(R.string.play_mode_list_loop);
break;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable.setTint(adapter.getVicTextColor());
}
mPlayMode.setImageDrawable(drawable);
return mod;
}
private Drawable getTintedDrawable(Drawable icon) {
if (icon == null || !mAutoTintIcons) return icon;
TypedValue val = new TypedValue();
int[] attribute = new int[] { android.R.attr.colorAccent };
TypedArray array = mContext.obtainStyledAttributes(val.resourceId, attribute);
int color = array.getColor(0, Color.WHITE);
array.recycle();
Drawable d = icon.mutate();
d.setTint(color);
return d;
}
private void emptyViewThemeChange(int[] colors) {
int accentC;
if (colors == null) {
ThemeEnum themeEnum = new AppPreference(activity).getTheme();
int[] cs = ColorUtils.get10ThemeColors(activity, themeEnum);
accentC = cs[2];
} else {
accentC = colors[0];
}
View v = mEmptyListNoticeContainer.getChildAt(EMPTY_VIEW_INDEX);
TextView text = (TextView) v.findViewById(R.id.sheet_empty_add);
text.setTextColor(accentC);
Drawable[] drawables = text.getCompoundDrawables();
for (Drawable d : drawables) {
if (d != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
d.setTint(accentC);
}
}
}
}
@Override
public void themeChange(ThemeEnum themeEnum, int[] colors) {
ThemeEnum theme = appPreference.getTheme();
int[] cs = ColorUtils.get10ThemeColors(this, theme);
mSearchController.themeChange(theme, cs);
int statusC = cs[0];
int toolbarC = cs[1];
int accentC = cs[2];
int mainBC = cs[3];
int vicBC = cs[4];
int mainTC = cs[5];
int vicTC = cs[6];
int navC = cs[7];
int toolbarMainTC = cs[8];
int toolbarVicTC = cs[9];
mResultContainer.setBackgroundColor(mainBC);
mInput.setHintTextColor(vicTC);
mInput.setTextColor(mainTC);
Drawable icon = getResources().getDrawable(R.drawable.ic_arrow_back);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
icon.setTint(accentC);
}
mToolbar.setNavigationIcon(icon);
int[] ta = ColorUtils.get2ActionStatusBarColors(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(ta[0]);
}
}
private void buildContextMenu(int height){
ArrayList<MenuObject> menuObjects = new ArrayList<>();
MenuParams menuParams = new MenuParams();
Drawable closeDrawable = getDrawable(R.drawable.ic_close);
Drawable syncDrawable = getDrawable(R.drawable.ic_sync);
Drawable blockedDrawable = getDrawable(R.drawable.ic_blocked);
closeDrawable.setTint(getResources().getColor(R.color.colorHeader));
syncDrawable.setTint(getResources().getColor(R.color.colorHeader));
blockedDrawable.setTint(getResources().getColor(R.color.colorHeader));
MenuObject closeMenu = new MenuObject();
closeMenu.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
closeMenu.setBgDrawable(getResources().getDrawable(R.drawable.menu_button_drawable_top));
closeMenu.setMenuTextAppearanceStyle(R.style.MenuFragmentStyle_TextView);
closeMenu.setDrawable(closeDrawable);
MenuObject contactSync = new MenuObject();
contactSync.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
contactSync.setBgDrawable(getResources().getDrawable(R.drawable.menu_button_drawable_middle));
contactSync.setMenuTextAppearanceStyle(R.style.MenuFragmentStyle_TextView);
contactSync.setDrawable(syncDrawable);
contactSync.setTitle(getString(R.string.sync_contacts));
MenuObject toggleBlocked = new MenuObject();
toggleBlocked.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
toggleBlocked.setBgDrawable(getResources().getDrawable(R.drawable.menu_button_drawable_bottom));
toggleBlocked.setMenuTextAppearanceStyle(R.style.MenuFragmentStyle_TextView);
toggleBlocked.setDrawable(blockedDrawable);
toggleBlocked.setTitle(isInBlockedMode.get() ? getString(R.string.toggle_unblocked_contacts) : getString(R.string.toggle_blocked_contacts));
menuObjects.add(closeMenu);
menuObjects.add(contactSync);
menuObjects.add(toggleBlocked);
menuParams.setActionBarSize(DisplayUtils.convertDpToRoundedPixel(64, this));
menuParams.setMenuObjects(menuObjects);
menuParams.setClosableOutside(false);
menuParams.setAnimationDelay(50);
menuParams.setAnimationDuration(75);
menuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams);
menuDialogFragment.setItemClickListener(this);
}
private void dataUpdated() {
if (calendarStart != null && calendarEnd != null && walletEntryListDataSet != null) {
List<WalletEntry> entryList = new ArrayList<>(walletEntryListDataSet.getList());
long expensesSumInDateRange = 0;
long incomesSumInDateRange = 0;
HashMap<Category, Long> categoryModels = new HashMap<>();
for (WalletEntry walletEntry : entryList) {
if (walletEntry.balanceDifference > 0) {
incomesSumInDateRange += walletEntry.balanceDifference;
continue;
}
expensesSumInDateRange += walletEntry.balanceDifference;
Category category = CategoriesHelper.searchCategory(user, walletEntry.categoryID);
if (categoryModels.get(category) != null)
categoryModels.put(category, categoryModels.get(category) + walletEntry.balanceDifference);
else
categoryModels.put(category, walletEntry.balanceDifference);
}
categoryModelsHome.clear();
ArrayList<PieEntry> pieEntries = new ArrayList<>();
ArrayList<Integer> pieColors = new ArrayList<>();
for (Map.Entry<Category, Long> categoryModel : categoryModels.entrySet()) {
float percentage = categoryModel.getValue() / (float) expensesSumInDateRange;
final float minPercentageToShowLabelOnChart = 0.1f;
categoryModelsHome.add(new TopCategoryStatisticsListViewModel(categoryModel.getKey(), categoryModel.getKey().getCategoryVisibleName(getContext()),
user.currency, categoryModel.getValue(), percentage));
if (percentage > minPercentageToShowLabelOnChart) {
Drawable drawable = getContext().getDrawable(categoryModel.getKey().getIconResourceID());
drawable.setTint(Color.parseColor("#FFFFFF"));
pieEntries.add(new PieEntry(-categoryModel.getValue(), drawable));
} else {
pieEntries.add(new PieEntry(-categoryModel.getValue()));
}
pieColors.add(categoryModel.getKey().getIconColor());
}
PieDataSet pieDataSet = new PieDataSet(pieEntries, "");
pieDataSet.setDrawValues(false);
pieDataSet.setColors(pieColors);
pieDataSet.setSliceSpace(2f);
PieData data = new PieData(pieDataSet);
pieChart.setData(data);
pieChart.setTouchEnabled(false);
pieChart.getLegend().setEnabled(false);
pieChart.getDescription().setEnabled(false);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleColor(ContextCompat.getColor(getContext(), R.color.backgroundPrimary));
pieChart.setHoleRadius(55f);
pieChart.setTransparentCircleRadius(55f);
pieChart.setDrawCenterText(true);
pieChart.setRotationAngle(270);
pieChart.setRotationEnabled(false);
pieChart.setHighlightPerTapEnabled(true);
pieChart.invalidate();
Collections.sort(categoryModelsHome, new Comparator<TopCategoryStatisticsListViewModel>() {
@Override
public int compare(TopCategoryStatisticsListViewModel o1, TopCategoryStatisticsListViewModel o2) {
return Long.compare(o1.getMoney(), o2.getMoney());
}
});
adapter.notifyDataSetChanged();
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy");
dividerTextView.setText("Date range: " + dateFormat.format(calendarStart.getTime())
+ " - " + dateFormat.format(calendarEnd.getTime()));
expensesTextView.setText(CurrencyHelper.formatCurrency(user.currency, expensesSumInDateRange));
incomesTextView.setText(CurrencyHelper.formatCurrency(user.currency, incomesSumInDateRange));
float progress = 100 * incomesSumInDateRange / (float) (incomesSumInDateRange - expensesSumInDateRange);
incomesExpensesProgressBar.setProgress((int) progress);
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
S.logImportant("reminderScreen was called!");
setContentView(R.layout.reminder_screen);
attachXml();
final Intent intent = getIntent();
if (intent == null) throw new AssertionError();
int key = intent.getIntExtra(Reminder.REMINDER_KEY_VIA_INTENTS, -1);
if (key == -1) throw new AssertionError();
reminder = RemindersDatabase.getInstance(this).remindersDatabaseDao().getById(key);
if (reminder == null) {
S.logImportant("reminder == null!, returning");
return;
}
final String textual_content = reminder.getTextualContent();
if (textual_content == null) tv_textual_content.setVisibility(View.GONE);
else tv_textual_content.setText(textual_content);
if (reminder.getBinaryContentType() == Reminder.BINARY_RGB) {
final Drawable drawable = getDrawable(R.drawable.pill).mutate();
drawable.setTint(Color.rgb(reminder.getBinaryContent()[0] & 0xFF, reminder.getBinaryContent()[1] & 0xFF, reminder.getBinaryContent()[2] & 0xFF));
iv_pill.setImageDrawable(drawable);
}
took.setOnClickListener(v -> {
if (vibrator != null)
vibrator.vibrate(D.vibetime);
finish();
});
took.setOnLongClickListener(v -> {
if (vibrator != null)
vibrator.vibrate(D.vibetime);
finish();
return true;
});
snooze.setOnClickListener((v) -> snooze());
snooze.setOnLongClickListener((v) -> {
snooze();
return true;
});
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);
} catch (Exception e) {
BaldToast.error(this);
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
Animations.makeBiggerAndSmaller(this, iv_pill, null);
scheduleNextReminder();
}