use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemePreviewActivity method selectColorType.
private void selectColorType(int id, boolean ask) {
if (getParentActivity() == null || colorType == id || patternViewAnimation != null) {
return;
}
if (ask && id == 2 && (Theme.hasCustomWallpaper() || accent.backgroundOverrideColor == 0x100000000L)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ChangeChatBackground", R.string.ChangeChatBackground));
if (!Theme.hasCustomWallpaper() || Theme.isCustomWallpaperColor()) {
builder.setMessage(LocaleController.getString("ChangeColorToColor", R.string.ChangeColorToColor));
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialog, which) -> {
if (accent.backgroundOverrideColor == 0x100000000L) {
accent.backgroundOverrideColor = 0;
accent.backgroundGradientOverrideColor1 = 0;
accent.backgroundGradientOverrideColor2 = 0;
accent.backgroundGradientOverrideColor3 = 0;
updatePlayAnimationView(false);
Theme.refreshThemeColors();
}
removeBackgroundOverride = true;
Theme.resetCustomWallpaper(true);
selectColorType(2, false);
});
builder.setNegativeButton(LocaleController.getString("Continue", R.string.Continue), (dialog, which) -> {
if (Theme.isCustomWallpaperColor()) {
accent.backgroundOverrideColor = accent.overrideWallpaper.color;
accent.backgroundGradientOverrideColor1 = accent.overrideWallpaper.gradientColor1;
accent.backgroundGradientOverrideColor2 = accent.overrideWallpaper.gradientColor2;
accent.backgroundGradientOverrideColor3 = accent.overrideWallpaper.gradientColor3;
accent.backgroundRotation = accent.overrideWallpaper.rotation;
accent.patternSlug = accent.overrideWallpaper.slug;
currentIntensity = accent.patternIntensity = accent.overrideWallpaper.intensity;
if (accent.patternSlug != null && !Theme.COLOR_BACKGROUND_SLUG.equals(accent.patternSlug)) {
for (int a = 0, N = patterns.size(); a < N; a++) {
TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) patterns.get(a);
if (wallPaper.pattern) {
if (accent.patternSlug.equals(wallPaper.slug)) {
selectedPattern = wallPaper;
break;
}
}
}
} else {
selectedPattern = null;
}
removeBackgroundOverride = true;
backgroundCheckBoxView[1].setChecked(selectedPattern != null, true);
updatePlayAnimationView(false);
Theme.refreshThemeColors();
}
Drawable background = backgroundImage.getBackground();
if (background instanceof MotionBackgroundDrawable) {
MotionBackgroundDrawable drawable = (MotionBackgroundDrawable) background;
drawable.setPatternBitmap(100, null);
if (Theme.getActiveTheme().isDark()) {
if (currentIntensity < 0) {
backgroundImage.getImageReceiver().setGradientBitmap(drawable.getBitmap());
}
if (intensitySeekBar != null) {
intensitySeekBar.setTwoSided(true);
}
} else if (currentIntensity < 0) {
currentIntensity = -currentIntensity;
}
}
if (intensitySeekBar != null) {
intensitySeekBar.setProgress(currentIntensity);
}
Theme.resetCustomWallpaper(true);
selectColorType(2, false);
});
} else {
builder.setMessage(LocaleController.getString("ChangeWallpaperToColor", R.string.ChangeWallpaperToColor));
builder.setPositiveButton(LocaleController.getString("Change", R.string.Change), (dialog, which) -> {
if (accent.backgroundOverrideColor == 0x100000000L) {
accent.backgroundOverrideColor = 0;
accent.backgroundGradientOverrideColor1 = 0;
accent.backgroundGradientOverrideColor2 = 0;
accent.backgroundGradientOverrideColor3 = 0;
updatePlayAnimationView(false);
Theme.refreshThemeColors();
}
removeBackgroundOverride = true;
Theme.resetCustomWallpaper(true);
selectColorType(2, false);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
}
showDialog(builder.create());
return;
}
int prevType = colorType;
colorType = id;
switch(id) {
case 1:
dropDown.setText(LocaleController.getString("ColorPickerMainColor", R.string.ColorPickerMainColor));
int colorsCount = accent.accentColor2 != 0 ? 2 : 1;
colorPicker.setType(1, hasChanges(1), 2, colorsCount, false, 0, false);
colorPicker.setColor(accent.accentColor, 0);
if (accent.accentColor2 != 0) {
colorPicker.setColor(accent.accentColor2, 1);
}
if (prevType == 2 || prevType == 3 && accent.myMessagesGradientAccentColor2 != 0) {
messagesAdapter.notifyItemRemoved(0);
}
break;
case 2:
{
dropDown.setText(LocaleController.getString("ColorPickerBackground", R.string.ColorPickerBackground));
int defaultBackground = Theme.getColor(Theme.key_chat_wallpaper);
int defaultGradient1 = Theme.hasThemeKey(Theme.key_chat_wallpaper_gradient_to1) ? Theme.getColor(Theme.key_chat_wallpaper_gradient_to1) : 0;
int defaultGradient2 = Theme.hasThemeKey(Theme.key_chat_wallpaper_gradient_to2) ? Theme.getColor(Theme.key_chat_wallpaper_gradient_to2) : 0;
int defaultGradient3 = Theme.hasThemeKey(Theme.key_chat_wallpaper_gradient_to3) ? Theme.getColor(Theme.key_chat_wallpaper_gradient_to3) : 0;
int backgroundGradientOverrideColor1 = (int) accent.backgroundGradientOverrideColor1;
if (backgroundGradientOverrideColor1 == 0 && accent.backgroundGradientOverrideColor1 != 0) {
defaultGradient1 = 0;
}
int backgroundGradientOverrideColor2 = (int) accent.backgroundGradientOverrideColor2;
if (backgroundGradientOverrideColor2 == 0 && accent.backgroundGradientOverrideColor2 != 0) {
defaultGradient2 = 0;
}
int backgroundGradientOverrideColor3 = (int) accent.backgroundGradientOverrideColor3;
if (backgroundGradientOverrideColor3 == 0 && accent.backgroundGradientOverrideColor3 != 0) {
defaultGradient3 = 0;
}
int backgroundOverrideColor = (int) accent.backgroundOverrideColor;
int count;
if (backgroundGradientOverrideColor1 != 0 || defaultGradient1 != 0) {
if (backgroundGradientOverrideColor3 != 0 || defaultGradient3 != 0) {
count = 4;
} else if (backgroundGradientOverrideColor2 != 0 || defaultGradient2 != 0) {
count = 3;
} else {
count = 2;
}
} else {
count = 1;
}
colorPicker.setType(2, hasChanges(2), 4, count, false, accent.backgroundRotation, false);
colorPicker.setColor(backgroundGradientOverrideColor3 != 0 ? backgroundGradientOverrideColor3 : defaultGradient3, 3);
colorPicker.setColor(backgroundGradientOverrideColor2 != 0 ? backgroundGradientOverrideColor2 : defaultGradient2, 2);
colorPicker.setColor(backgroundGradientOverrideColor1 != 0 ? backgroundGradientOverrideColor1 : defaultGradient1, 1);
colorPicker.setColor(backgroundOverrideColor != 0 ? backgroundOverrideColor : defaultBackground, 0);
if (prevType == 1 || accent.myMessagesGradientAccentColor2 == 0) {
messagesAdapter.notifyItemInserted(0);
} else {
messagesAdapter.notifyItemChanged(0);
}
listView2.smoothScrollBy(0, AndroidUtilities.dp(60));
break;
}
case 3:
{
dropDown.setText(LocaleController.getString("ColorPickerMyMessages", R.string.ColorPickerMyMessages));
int count;
if (accent.myMessagesGradientAccentColor1 != 0) {
if (accent.myMessagesGradientAccentColor3 != 0) {
count = 4;
} else if (accent.myMessagesGradientAccentColor2 != 0) {
count = 3;
} else {
count = 2;
}
} else {
count = 1;
}
colorPicker.setType(2, hasChanges(3), 4, count, true, 0, false);
colorPicker.setColor(accent.myMessagesGradientAccentColor3, 3);
colorPicker.setColor(accent.myMessagesGradientAccentColor2, 2);
colorPicker.setColor(accent.myMessagesGradientAccentColor1, 1);
colorPicker.setColor(accent.myMessagesAccentColor != 0 ? accent.myMessagesAccentColor : accent.accentColor, 0);
messagesCheckBoxView[1].setColor(0, accent.myMessagesAccentColor);
messagesCheckBoxView[1].setColor(1, accent.myMessagesGradientAccentColor1);
messagesCheckBoxView[1].setColor(2, accent.myMessagesGradientAccentColor2);
messagesCheckBoxView[1].setColor(3, accent.myMessagesGradientAccentColor3);
if (accent.myMessagesGradientAccentColor2 != 0) {
if (prevType == 1) {
messagesAdapter.notifyItemInserted(0);
} else {
messagesAdapter.notifyItemChanged(0);
}
} else if (prevType == 2) {
messagesAdapter.notifyItemRemoved(0);
}
listView2.smoothScrollBy(0, AndroidUtilities.dp(60));
showAnimationHint();
break;
}
}
if (id == 1 || id == 3) {
if (prevType == 2) {
if (patternLayout[1].getVisibility() == View.VISIBLE) {
showPatternsView(0, true, true);
}
}
if (id == 1) {
if (applyingTheme.isDark()) {
colorPicker.setMinBrightness(0.2f);
} else {
colorPicker.setMinBrightness(0.05f);
colorPicker.setMaxBrightness(0.8f);
}
} else {
colorPicker.setMinBrightness(0f);
colorPicker.setMaxBrightness(1f);
}
} else {
colorPicker.setMinBrightness(0f);
colorPicker.setMaxBrightness(1f);
}
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class QrActivity method getEmojiThemeIcon.
private Bitmap getEmojiThemeIcon(EmojiThemes theme, boolean isDark) {
if (isDark) {
Bitmap bitmap = emojiThemeDarkIcons.get(theme.emoji);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(emojiThemeIcon.getWidth(), emojiThemeIcon.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
int[] colors = qrColorsMap.get(theme.emoji + "n");
if (colors != null) {
if (tempMotionDrawable == null) {
tempMotionDrawable = new MotionBackgroundDrawable(0, 0, 0, 0, true);
}
tempMotionDrawable.setColors(colors[0], colors[1], colors[2], colors[3]);
tempMotionDrawable.setBounds(AndroidUtilities.dp(6), AndroidUtilities.dp(6), canvas.getWidth() - AndroidUtilities.dp(6), canvas.getHeight() - AndroidUtilities.dp(6));
tempMotionDrawable.draw(canvas);
}
canvas.drawBitmap(emojiThemeIcon, 0, 0, null);
canvas.setBitmap(null);
emojiThemeDarkIcons.put(theme.emoji, bitmap);
}
return bitmap;
} else {
return emojiThemeIcon;
}
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createDefaultWallpaper.
public static Drawable createDefaultWallpaper(int w, int h) {
MotionBackgroundDrawable motionBackgroundDrawable = new MotionBackgroundDrawable(0xffdbddbb, 0xff6ba587, 0xffd5d88d, 0xff88b884, w != 0);
if (w <= 0 || h <= 0) {
w = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
h = Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
}
motionBackgroundDrawable.setPatternBitmap(34, SvgHelper.getBitmap(R.raw.default_pattern, w, h, Color.BLACK));
motionBackgroundDrawable.setPatternColorFilter(motionBackgroundDrawable.getPatternColor());
return motionBackgroundDrawable;
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method getThemedWallpaper.
public static Drawable getThemedWallpaper(boolean thumb, View ownerView) {
Integer backgroundColor = currentColors.get(key_chat_wallpaper);
File file = null;
MotionBackgroundDrawable motionBackgroundDrawable = null;
int offset = 0;
if (backgroundColor != null) {
Integer gradientToColor1 = currentColors.get(key_chat_wallpaper_gradient_to1);
Integer gradientToColor2 = currentColors.get(key_chat_wallpaper_gradient_to2);
Integer gradientToColor3 = currentColors.get(key_chat_wallpaper_gradient_to3);
Integer rotation = currentColors.get(key_chat_wallpaper_gradient_rotation);
if (rotation == null) {
rotation = 45;
}
if (gradientToColor1 == null) {
return new ColorDrawable(backgroundColor);
} else {
ThemeAccent accent = currentTheme.getAccent(false);
if (accent != null && !TextUtils.isEmpty(accent.patternSlug) && previousTheme == null) {
File wallpaperFile = accent.getPathToWallpaper();
if (wallpaperFile != null && wallpaperFile.exists()) {
file = wallpaperFile;
}
}
if (gradientToColor2 != null) {
motionBackgroundDrawable = new MotionBackgroundDrawable(backgroundColor, gradientToColor1, gradientToColor2, gradientToColor3 != null ? gradientToColor3 : 0, true);
if (file == null) {
return motionBackgroundDrawable;
}
} else if (file == null) {
final int[] colors = { backgroundColor, gradientToColor1 };
final GradientDrawable.Orientation orientation = BackgroundGradientDrawable.getGradientOrientation(rotation);
final BackgroundGradientDrawable backgroundGradientDrawable = new BackgroundGradientDrawable(orientation, colors);
final BackgroundGradientDrawable.Sizes sizes;
if (!thumb) {
sizes = BackgroundGradientDrawable.Sizes.ofDeviceScreen();
} else {
sizes = BackgroundGradientDrawable.Sizes.ofDeviceScreen(BackgroundGradientDrawable.DEFAULT_COMPRESS_RATIO / 4f, BackgroundGradientDrawable.Sizes.Orientation.PORTRAIT);
}
final BackgroundGradientDrawable.Listener listener;
if (ownerView != null) {
listener = new BackgroundGradientDrawable.ListenerAdapter() {
@Override
public void onSizeReady(int width, int height) {
if (!thumb) {
final boolean isOrientationPortrait = AndroidUtilities.displaySize.x <= AndroidUtilities.displaySize.y;
final boolean isGradientPortrait = width <= height;
if (isOrientationPortrait == isGradientPortrait) {
ownerView.invalidate();
}
} else {
ownerView.invalidate();
}
}
};
} else {
listener = null;
}
backgroundGradientDrawable.startDithering(sizes, listener);
return backgroundGradientDrawable;
}
}
} else if (themedWallpaperFileOffset > 0 && (currentTheme.pathToFile != null || currentTheme.assetName != null)) {
if (currentTheme.assetName != null) {
file = getAssetFile(currentTheme.assetName);
} else {
file = new File(currentTheme.pathToFile);
}
offset = themedWallpaperFileOffset;
}
if (file != null) {
FileInputStream stream = null;
try {
int currentPosition = 0;
stream = new FileInputStream(file);
stream.getChannel().position(offset);
BitmapFactory.Options opts = new BitmapFactory.Options();
int scaleFactor = 1;
if (thumb) {
opts.inJustDecodeBounds = true;
float photoW = opts.outWidth;
float photoH = opts.outHeight;
int maxWidth = AndroidUtilities.dp(100);
while (photoW > maxWidth || photoH > maxWidth) {
scaleFactor *= 2;
photoW /= 2;
photoH /= 2;
}
}
opts.inJustDecodeBounds = false;
opts.inSampleSize = scaleFactor;
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, opts);
if (motionBackgroundDrawable != null) {
int intensity;
ThemeAccent accent = currentTheme.getAccent(false);
if (accent != null) {
intensity = (int) (accent.patternIntensity * 100);
} else {
intensity = 100;
}
motionBackgroundDrawable.setPatternBitmap(intensity, bitmap);
motionBackgroundDrawable.setPatternColorFilter(motionBackgroundDrawable.getPatternColor());
return motionBackgroundDrawable;
}
if (bitmap != null) {
return new BitmapDrawable(bitmap);
}
} catch (Throwable e) {
FileLog.e(e);
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
return null;
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createBackgroundDrawable.
public static BackgroundDrawableSettings createBackgroundDrawable(ThemeInfo currentTheme, OverrideWallpaperInfo overrideWallpaper, HashMap<String, Integer> currentColors, File wallpaperFile, String themedWallpaperLink, int themedWallpaperFileOffset, int intensity, int previousPhase, boolean defaultTheme, boolean hasPreviousTheme, boolean isApplyingAccent, boolean wallpaperMotion, TLRPC.Document wallpaperDocument) {
BackgroundDrawableSettings settings = new BackgroundDrawableSettings();
settings.wallpaper = wallpaper;
boolean overrideTheme = (!hasPreviousTheme || isApplyingAccent) && overrideWallpaper != null;
if (overrideWallpaper != null) {
settings.isWallpaperMotion = overrideWallpaper.isMotion;
settings.isPatternWallpaper = overrideWallpaper.color != 0 && !overrideWallpaper.isDefault() && !overrideWallpaper.isColor();
} else {
settings.isWallpaperMotion = currentTheme.isMotion;
settings.isPatternWallpaper = currentTheme.patternBgColor != 0;
}
if (!overrideTheme) {
Integer backgroundColor = defaultTheme ? null : currentColors.get(key_chat_wallpaper);
Integer gradientToColor3 = currentColors.get(key_chat_wallpaper_gradient_to3);
if (gradientToColor3 == null) {
gradientToColor3 = 0;
}
Integer gradientToColor2 = currentColors.get(key_chat_wallpaper_gradient_to2);
gradientToColor2 = currentColors.get(key_chat_wallpaper_gradient_to2);
Integer gradientToColor1 = currentColors.get(key_chat_wallpaper_gradient_to1);
if (wallpaperFile != null && wallpaperFile.exists()) {
try {
if (backgroundColor != null && gradientToColor1 != null && gradientToColor2 != null) {
MotionBackgroundDrawable motionBackgroundDrawable = new MotionBackgroundDrawable(backgroundColor, gradientToColor1, gradientToColor2, gradientToColor3, false);
motionBackgroundDrawable.setPatternBitmap(intensity, BitmapFactory.decodeFile(wallpaperFile.getAbsolutePath()));
motionBackgroundDrawable.setPatternColorFilter(motionBackgroundDrawable.getPatternColor());
settings.wallpaper = motionBackgroundDrawable;
} else {
settings.wallpaper = Drawable.createFromPath(wallpaperFile.getAbsolutePath());
}
settings.isWallpaperMotion = wallpaperMotion;
settings.isPatternWallpaper = true;
settings.isCustomTheme = true;
} catch (Throwable e) {
FileLog.e(e);
}
} else if (backgroundColor != null) {
Integer rotation = currentColors.get(key_chat_wallpaper_gradient_rotation);
if (rotation == null) {
rotation = 45;
}
if (gradientToColor1 != null && gradientToColor2 != null) {
MotionBackgroundDrawable motionBackgroundDrawable = new MotionBackgroundDrawable(backgroundColor, gradientToColor1, gradientToColor2, gradientToColor3, false);
Bitmap pattensBitmap = null;
if (wallpaperFile != null && wallpaperDocument != null) {
File f = FileLoader.getPathToAttach(wallpaperDocument, true);
pattensBitmap = SvgHelper.getBitmap(f, AndroidUtilities.dp(360), AndroidUtilities.dp(640), false);
if (pattensBitmap != null) {
FileOutputStream stream = null;
try {
stream = new FileOutputStream(wallpaperFile);
pattensBitmap.compress(Bitmap.CompressFormat.PNG, 87, stream);
stream.close();
} catch (Exception e) {
FileLog.e(e);
e.printStackTrace();
}
}
}
motionBackgroundDrawable.setPatternBitmap(intensity, pattensBitmap);
motionBackgroundDrawable.setPhase(previousPhase);
settings.wallpaper = motionBackgroundDrawable;
} else if (gradientToColor1 == null || gradientToColor1.equals(backgroundColor)) {
settings.wallpaper = new ColorDrawable(backgroundColor);
} else {
final int[] colors = { backgroundColor, gradientToColor1 };
final BackgroundGradientDrawable.Orientation orientation = BackgroundGradientDrawable.getGradientOrientation(rotation);
final BackgroundGradientDrawable backgroundGradientDrawable = new BackgroundGradientDrawable(orientation, colors);
final BackgroundGradientDrawable.Listener listener = new BackgroundGradientDrawable.ListenerAdapter() {
@Override
public void onSizeReady(int width, int height) {
final boolean isOrientationPortrait = AndroidUtilities.displaySize.x <= AndroidUtilities.displaySize.y;
final boolean isGradientPortrait = width <= height;
if (isOrientationPortrait == isGradientPortrait) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didSetNewWallpapper);
}
}
};
backgroundGradientDisposable = backgroundGradientDrawable.startDithering(BackgroundGradientDrawable.Sizes.ofDeviceScreen(), listener, 100);
settings.wallpaper = backgroundGradientDrawable;
}
settings.isCustomTheme = true;
} else if (themedWallpaperLink != null) {
try {
File pathToWallpaper = new File(ApplicationLoader.getFilesDirFixed(), Utilities.MD5(themedWallpaperLink) + ".wp");
Bitmap bitmap = loadScreenSizedBitmap(new FileInputStream(pathToWallpaper), 0);
if (bitmap != null) {
settings.wallpaper = new BitmapDrawable(bitmap);
settings.themedWallpaper = settings.wallpaper;
settings.isCustomTheme = true;
}
} catch (Exception e) {
FileLog.e(e);
}
} else if (themedWallpaperFileOffset > 0 && (currentTheme.pathToFile != null || currentTheme.assetName != null)) {
try {
File file;
if (currentTheme.assetName != null) {
file = getAssetFile(currentTheme.assetName);
} else {
file = new File(currentTheme.pathToFile);
}
Bitmap bitmap = loadScreenSizedBitmap(new FileInputStream(file), themedWallpaperFileOffset);
if (bitmap != null) {
settings.wallpaper = settings.themedWallpaper = wallpaper = new BitmapDrawable(bitmap);
settings.isCustomTheme = true;
}
} catch (Throwable e) {
FileLog.e(e);
}
}
}
if (settings.wallpaper == null) {
int selectedColor = overrideWallpaper != null ? overrideWallpaper.color : 0;
try {
if (overrideWallpaper == null || overrideWallpaper.isDefault()) {
settings.wallpaper = createDefaultWallpaper();
settings.isCustomTheme = false;
} else if (!overrideWallpaper.isColor() || overrideWallpaper.gradientColor1 != 0) {
if (selectedColor != 0 && (!isPatternWallpaper || overrideWallpaper.gradientColor2 != 0)) {
if (overrideWallpaper.gradientColor1 != 0 && overrideWallpaper.gradientColor2 != 0) {
MotionBackgroundDrawable motionBackgroundDrawable = new MotionBackgroundDrawable(overrideWallpaper.color, overrideWallpaper.gradientColor1, overrideWallpaper.gradientColor2, overrideWallpaper.gradientColor3, false);
motionBackgroundDrawable.setPhase(previousPhase);
if (settings.isPatternWallpaper) {
File toFile = new File(ApplicationLoader.getFilesDirFixed(), overrideWallpaper.fileName);
if (toFile.exists()) {
motionBackgroundDrawable.setPatternBitmap((int) (overrideWallpaper.intensity * 100), loadScreenSizedBitmap(new FileInputStream(toFile), 0));
settings.isCustomTheme = true;
}
}
settings.wallpaper = motionBackgroundDrawable;
} else if (overrideWallpaper.gradientColor1 != 0) {
final int[] colors = { selectedColor, overrideWallpaper.gradientColor1 };
final BackgroundGradientDrawable.Orientation orientation = BackgroundGradientDrawable.getGradientOrientation(overrideWallpaper.rotation);
final BackgroundGradientDrawable backgroundGradientDrawable = new BackgroundGradientDrawable(orientation, colors);
final BackgroundGradientDrawable.Listener listener = new BackgroundGradientDrawable.ListenerAdapter() {
@Override
public void onSizeReady(int width, int height) {
final boolean isOrientationPortrait = AndroidUtilities.displaySize.x <= AndroidUtilities.displaySize.y;
final boolean isGradientPortrait = width <= height;
if (isOrientationPortrait == isGradientPortrait) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didSetNewWallpapper);
}
}
};
backgroundGradientDisposable = backgroundGradientDrawable.startDithering(BackgroundGradientDrawable.Sizes.ofDeviceScreen(), listener, 100);
settings.wallpaper = backgroundGradientDrawable;
} else {
settings.wallpaper = new ColorDrawable(selectedColor);
}
} else {
File toFile = new File(ApplicationLoader.getFilesDirFixed(), overrideWallpaper.fileName);
if (toFile.exists()) {
Bitmap bitmap = loadScreenSizedBitmap(new FileInputStream(toFile), 0);
if (bitmap != null) {
settings.wallpaper = new BitmapDrawable(bitmap);
settings.isCustomTheme = true;
}
}
if (settings.wallpaper == null) {
settings.wallpaper = createDefaultWallpaper();
settings.isCustomTheme = false;
}
}
}
} catch (Throwable throwable) {
// ignore
}
if (settings.wallpaper == null) {
if (selectedColor == 0) {
selectedColor = -2693905;
}
settings.wallpaper = new ColorDrawable(selectedColor);
}
}
return settings;
}
Aggregations