Merge branch 'accents'
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package com.vk.core.drawable;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.annotation.NonNull;
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
|
||||
public class RecoloredDrawable extends Drawable implements Drawable.Callback {
|
||||
private Drawable drawable;
|
||||
private ColorStateList colorStateList;
|
||||
private int c;
|
||||
private int d;
|
||||
|
||||
public RecoloredDrawable(Drawable drawable, ColorStateList colorStateList) {
|
||||
this.c = 255;
|
||||
this.d = 255;
|
||||
try {
|
||||
this.drawable = drawable.mutate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.drawable.setCallback(this);
|
||||
this.colorStateList = RecolorUtils.themeCSL(colorStateList);
|
||||
onStateChange(new int[0]);
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
a(new ColorStateList(new int[][]{new int[0]}, new int[]{i}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
this.drawable.draw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return this.drawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return this.drawable.getIntrinsicWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return this.drawable.getOpacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateDrawable(@NonNull Drawable drawable) {
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateful() {
|
||||
return this.colorStateList.isStateful();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onStateChange(int[] iArr) {
|
||||
super.onStateChange(iArr);
|
||||
ColorStateList colorStateList = this.colorStateList;
|
||||
this.drawable.setColorFilter(colorStateList.getColorForState(iArr, colorStateList.getDefaultColor()), PorterDuff.Mode.SRC_IN);
|
||||
int length = iArr.length;
|
||||
boolean z = false;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
if (i >= length) {
|
||||
break;
|
||||
} else if (iArr[i] == 0x010100a1) {
|
||||
z = true;
|
||||
break;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
this.drawable.setState(iArr);
|
||||
this.drawable.setAlpha(z ? this.c : this.d);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable, long j) {
|
||||
scheduleSelf(runnable, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int i) {
|
||||
this.c = i;
|
||||
this.d = i;
|
||||
this.drawable.setAlpha(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBounds(int i, int i2, int i3, int i4) {
|
||||
super.setBounds(i, i2, i3, i4);
|
||||
this.drawable.setBounds(i, i2, i3, i4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unscheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable) {
|
||||
unscheduleSelf(runnable);
|
||||
}
|
||||
|
||||
public void a(ColorStateList colorStateList) {
|
||||
this.colorStateList = colorStateList;
|
||||
onStateChange(getState());
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public Drawable a() {
|
||||
return this.drawable;
|
||||
}
|
||||
|
||||
public RecoloredDrawable(Drawable drawable, int i) {
|
||||
this(drawable, new ColorStateList(new int[][]{new int[0]}, new int[]{i}));
|
||||
}
|
||||
|
||||
public RecoloredDrawable() {
|
||||
this.c = 255;
|
||||
this.d = 255;
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -71,12 +71,11 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
|
||||
this.mIcon.getLayoutParams().width = V.a(28.0F);
|
||||
this.mIcon.getLayoutParams().height = V.a(28.0F);
|
||||
|
||||
var colorStateList = getCSTDock();
|
||||
this.mSmallLabel = this.findViewById(R.id.smallLabel);
|
||||
mSmallLabel.setTextColor(colorStateList);
|
||||
mSmallLabel.setTextColor(getCSTDock());
|
||||
|
||||
this.mLargeLabel = this.findViewById(R.id.largeLabel);
|
||||
mLargeLabel.setTextColor(colorStateList);
|
||||
mLargeLabel.setTextColor(getCSTDock());
|
||||
|
||||
LayoutInflater.from(this.getContext()).inflate(R.layout.navigation_bottom_counter, this, true);
|
||||
this.mCounterContainer = this.findViewById(R.id.counter_container);
|
||||
@@ -326,6 +325,8 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
|
||||
}
|
||||
|
||||
public void setTextColor(ColorStateList colorStateList) {
|
||||
this.mSmallLabel.setTextColor(colorStateList);
|
||||
this.mLargeLabel.setTextColor(colorStateList);
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
|
||||
@@ -23,6 +23,7 @@ import ru.vtosters.lite.music.downloader.PlaylistDownloader;
|
||||
import ru.vtosters.lite.music.downloader.TrackDownloader;
|
||||
import ru.vtosters.lite.music.notification.MusicNotificationBuilder;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,7 @@ public class AudioDownloader {
|
||||
|
||||
if (CacheDatabaseDelegate.isCached(trackId)) {
|
||||
CacheDatabaseDelegate.removeTrackFromCache(LibVKXClient.asId(track));
|
||||
AndroidUtils.sendToast("Трек удален из кеша");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class OTADownloader {
|
||||
|
||||
var request = new DownloadManager.Request(uri);
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("Скачивание обновления");
|
||||
request.setTitle(AndroidUtils.getString("downloading_update"));
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite-" + commitSHA + ".apk");
|
||||
|
||||
var manager = (DownloadManager) AndroidUtils.getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
|
||||
@@ -102,6 +102,7 @@ public class DockBarInjector {
|
||||
item.setStaticMode(true);
|
||||
item.setIconsMode(false);
|
||||
item.setShiftingMode(false);
|
||||
item.setTextColor(getCSTDock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ public class GcmHook {
|
||||
}
|
||||
|
||||
public static String requestTokenV2(String orig) {
|
||||
return isValidSignature() ? "eyJhbGciOiAibm9uZSJ9eyJub25jZSI6ICJudWxsIn0=" : "e251bGx9";
|
||||
return isValidSignature() ? "eyJhbGciOiAibm9uZSJ9.eyJub25jZSI6ICJ0ZXN0PT0ifQ." : "e251bGx9";
|
||||
}
|
||||
|
||||
public static String requestToken(String orig) {
|
||||
return requestToken();
|
||||
return "yssp9o9p9pamz5t-nvmq8spgwtin3e0==";
|
||||
}
|
||||
|
||||
public static String requestToken() {
|
||||
|
||||
@@ -97,9 +97,8 @@ public class PhotoViewer {
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static void addMenuItems(AttachmentWithMedia attachment, ActionsPopup.b actionPopup, int i, boolean z) {
|
||||
actionPopup.a(R.string.search_photo_content,
|
||||
ThemesUtils.isDarkTheme()
|
||||
? AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28)
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28), ThemesUtils.getAccentColor()),
|
||||
new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28),
|
||||
ThemesUtils.isDarkTheme() ? Color.WHITE : ThemesUtils.getAccentColor()),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -119,9 +118,8 @@ public class PhotoViewer {
|
||||
}
|
||||
);
|
||||
actionPopup.a(R.string.copy_photo_url_content,
|
||||
!ThemesUtils.isDarkTheme()
|
||||
? new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28), ThemesUtils.getAccentColor())
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28), Color.WHITE),
|
||||
new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28),
|
||||
ThemesUtils.isDarkTheme() ? Color.WHITE : ThemesUtils.getAccentColor()),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -141,10 +139,8 @@ public class PhotoViewer {
|
||||
}
|
||||
);
|
||||
actionPopup.a(R.string.open_original_photo_content,
|
||||
ThemesUtils.isDarkTheme()
|
||||
? AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28)
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28),
|
||||
ThemesUtils.getAccentColor()),
|
||||
new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28),
|
||||
ThemesUtils.isDarkTheme() ? Color.WHITE : ThemesUtils.getAccentColor()),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
|
||||
@@ -110,8 +110,6 @@ public class TogglesHook {
|
||||
case FEATURE_VK_APPS_SEARCH:
|
||||
case FEATURE_VOTES_BALANCE:
|
||||
case FEATURE_WEBVIEW_TOKEN_ACTIVE:
|
||||
case FEATURE_WISHLIST_ENTRY_POINT:
|
||||
case FEATURE_WISHLIST_MY_PROFILE:
|
||||
case FEATURE_MILKSHAKE_FORCE_DISABLED:
|
||||
case FEATURE_MILKSHAKE_ACTIVATION_DISABLED:
|
||||
case EXPERIMENT_NEWS_DISABLE_CACHE:
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.ArrayList;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClientImpl;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class MusicBottomSheetHook {
|
||||
public static ArrayList<MusicAction> hook(ArrayList<MusicAction> actions, MusicTrack musicTrack) {
|
||||
@@ -36,9 +38,15 @@ public class MusicBottomSheetHook {
|
||||
if (isIntegrationEnabled()) {
|
||||
if (isVkxCached(trackid)) {
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
} else {
|
||||
if (isCached(trackid)) {
|
||||
actions.add(getRemoveCacheTrackAction());
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
}
|
||||
|
||||
if (isNetworkConnected()) {
|
||||
@@ -85,10 +93,10 @@ public class MusicBottomSheetHook {
|
||||
if (isIntegrationEnabled()) {
|
||||
if (isVkxCached(playlist.a, playlist.b)) {
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
} else {
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
|
||||
@@ -121,6 +129,15 @@ public class MusicBottomSheetHook {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == R.id.remove_from_cache) {
|
||||
CacheDatabaseDelegate.removeTrackFromCache(asId(track));
|
||||
AndroidUtils.sendToast("Трек удален из кеша");
|
||||
return true;
|
||||
} else if (actionId == R.id.add_to_cache) {
|
||||
AudioDownloader.cacheTrack(track);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == R.id.download_mp3) {
|
||||
if (isIntegrationEnabled()) {
|
||||
getInstance().runOnService(service -> {
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.vtosters.lite.R.color.*;
|
||||
|
||||
public class ColorReferences {
|
||||
public static List<Integer> accentColors = Arrays.asList(
|
||||
Color.parseColor("#3f8ae0"), // azure_300 (light accent)
|
||||
Color.parseColor("#4986cc"), // azure_a400
|
||||
Color.parseColor("#528bcc"), // another light accent
|
||||
Color.parseColor("#71aaeb"), // vk_sky_300 (dark accent)
|
||||
Color.parseColor("#5181b8"), // header_blue
|
||||
Color.parseColor("#5a9eff"),
|
||||
Color.parseColor("#5692d7"),
|
||||
Color.parseColor("#5c9ce6"),
|
||||
Color.parseColor("#518bcc"),
|
||||
Color.parseColor("#74a2d6")
|
||||
);
|
||||
|
||||
public static List<Integer> mutedAccentColors = Arrays.asList(
|
||||
Color.parseColor("#663f8ae0"),
|
||||
Color.parseColor("#19528bcc"),
|
||||
Color.parseColor("#66528bcc"),
|
||||
Color.parseColor("#1971aaeb"),
|
||||
Color.parseColor("#665181b8"),
|
||||
Color.parseColor("#1a003973"),
|
||||
Color.parseColor("#a800244d"),
|
||||
Color.parseColor("#14001c3d"),
|
||||
Color.parseColor("#3d001c3d"),
|
||||
Color.parseColor("#67a5eb"),
|
||||
Color.parseColor("#45678f"),
|
||||
Color.parseColor("#6645678f"),
|
||||
Color.parseColor("#0099cc"),
|
||||
Color.parseColor("#664986cc")
|
||||
);
|
||||
|
||||
public static List<Integer> accents = Arrays.asList(
|
||||
viewer_retry_button_text_color,
|
||||
azure_300,
|
||||
picker_camera_button,
|
||||
music_check_button_bg_pressed,
|
||||
notification_color,
|
||||
music_text_counter,
|
||||
music_follow_button_bg_pressed,
|
||||
music_blue_button_normal,
|
||||
music_check_button_bg_normal,
|
||||
vk_terms_link,
|
||||
vk_blue_200,
|
||||
accent_blue,
|
||||
azure_A400,
|
||||
vk_azure_A400,
|
||||
blue,
|
||||
blue_200,
|
||||
vk_blue_300,
|
||||
vk_blue_400,
|
||||
blue_300,
|
||||
blue_400,
|
||||
cool_blue,
|
||||
cornflower_blue,
|
||||
cornflower_blue_two,
|
||||
dot_unread,
|
||||
fave_promo_btn_pressed,
|
||||
header_blue,
|
||||
colorAccent,
|
||||
live_emoji_butt_hide,
|
||||
music_action_button_blue,
|
||||
name,
|
||||
picker_blue,
|
||||
picker_blue_pressed,
|
||||
picker_tab_bg_selected,
|
||||
picker_tab_text_selected,
|
||||
sharing_blue_btn_normal,
|
||||
sharing_blue_btn_pressed,
|
||||
vk_sky_300,
|
||||
vk_blue_A400,
|
||||
blue_A400,
|
||||
sky_300,
|
||||
text_blue,
|
||||
tip_background,
|
||||
tw__blue_default,
|
||||
tw__blue_pressed,
|
||||
vkim_msg_sending_ic,
|
||||
vkim_playing_drawable_rect,
|
||||
vk_white_blue32,
|
||||
date_picker_selector,
|
||||
post_suggest_blue,
|
||||
list_dialog_blue,
|
||||
music_tab_bg_normal,
|
||||
toolbar_blue_background,
|
||||
toolbar_blue_statusBarColorBack
|
||||
);
|
||||
|
||||
public static List<Integer> mutedAccents = Arrays.asList(
|
||||
blue_200_muted,
|
||||
vk_blue_200_muted,
|
||||
white_blue32,
|
||||
vk_white_blue32,
|
||||
header_blue_opacity16,
|
||||
black_blue45_alpha10,
|
||||
music_check_button_bg_checked,
|
||||
vk_black_blue45_alpha10,
|
||||
black_blue30_alpha66,
|
||||
vk_black_blue30_alpha66,
|
||||
attachpicker_item_background,
|
||||
black_blue24_alpha8,
|
||||
music_placeholder_artist_bg,
|
||||
black_blue24_alpha24,
|
||||
vk_black_blue24_alpha24,
|
||||
azure_100_muted,
|
||||
vk_azure_100_muted,
|
||||
muted_blue,
|
||||
blue_600,
|
||||
light_blue,
|
||||
vk_blue_600,
|
||||
muted_blue_opacity40,
|
||||
muted_blue_old,
|
||||
darker_blue,
|
||||
header_blue_opacity40
|
||||
);
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
return target != null && isAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
return accentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isMutedAccentedColor(ColorStateList target) {
|
||||
return target != null && isMutedAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isMutedAccentedColor(int target) {
|
||||
return mutedAccentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int target) {
|
||||
return accents.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefMutedAccented(int target) {
|
||||
return mutedAccents.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isCslNeedToBeThemed(ColorStateList csl) {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
boolean isUnselAccent = isAccentedColor(unsel);
|
||||
boolean isSelAccent = isAccentedColor(sel);
|
||||
return ThemesCore.isCachedAccents() && (isUnselAccent || isSelAccent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
|
||||
public class ThemesCore {
|
||||
private static final String TAG = "ThemesCore";
|
||||
|
||||
public static SparseIntArray themedColors = new SparseIntArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_DARK = new SparseBooleanArray();
|
||||
|
||||
private static boolean cachedAccents = false;
|
||||
private static int wallLightColor;
|
||||
|
||||
static {
|
||||
setExceptions();
|
||||
setThemedColors(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
public static void setExceptions() {
|
||||
ACCENT_THEME_ONLY_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK.clear();
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_MILK_DARK.clear();
|
||||
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_primary_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_secondary_foreground, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_tertiary_foreground, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_muted_foreground, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_outline_border, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.text_name, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.newsfeed_post_title_color, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.attach_picker_tab_active_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.attach_picker_tab_active_text, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.newsfeed_action_color, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.counter_primary_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.action_sheet_action_foreground, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(com.vtosters.lite.R.attr.header_background, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_tint, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.icon_name, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_tint_alternate, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.toolbarIconsColor, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_tab_active_indicator, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_alternate_tab_active_indicator, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.im_dropdown_arrow_tint, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.im_bubble_wallpaper_outgoing, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.im_bubble_outgoing, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.im_bubble_outgoing_highlighted, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK.put(com.vtosters.lite.R.attr.im_dropdown_icon_color, false);
|
||||
}
|
||||
|
||||
public static void setThemedColors(int accentColor) {
|
||||
int mutedAccentColor = ThemesUtils.getMutedColor(accentColor);
|
||||
|
||||
cachedAccents = true;
|
||||
themedColors.clear();
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.text_link, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.accent, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.newsfeed_dropdown_color, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.icon_name, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.vk_accent, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.accentColor, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.text_name, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.tabbar_active_icon, accentColor);
|
||||
//themedColors.put(com.vtosters.lite.R.attr.header_background, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.header_tint, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.header_tint_alternate, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.activity_indicator_tint, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.toolbarIconsColor, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_primary_background, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_secondary_foreground, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_tertiary_foreground, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_outline_border, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_muted_foreground, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.header_tab_active_indicator, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.header_alternate_tab_active_indicator, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_primary_background_disabled, mutedAccentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_secondary_foreground_disabled, mutedAccentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_tertiary_foreground_disabled, mutedAccentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_outline_border_disabled, mutedAccentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.button_muted_foreground_disabled, mutedAccentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_dropdown_icon_color, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_dropdown_arrow_tint, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_attach_tint, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_forward_line_tint, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.link_alternate, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.newsfeed_post_title_color, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.attach_picker_tab_active_background, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.attach_picker_tab_active_text, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.newsfeed_action_color, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.counter_primary_background, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.dynamic_blue, accentColor);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.action_sheet_action_foreground, accentColor);
|
||||
|
||||
// messages
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_reply_separator, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_text_name, accentColor);
|
||||
|
||||
wallLightColor = ThemesUtils.lighten(accentColor, 0.67f);
|
||||
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_ic_send_msg, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_bubble_wallpaper_outgoing, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_bubble_outgoing, accentColor);
|
||||
themedColors.put(com.vtosters.lite.R.attr.im_bubble_outgoing_highlighted, accentColor);
|
||||
}
|
||||
|
||||
public static int getThemedAttr(Context context, @IdRes int attr) {
|
||||
if (attr == com.vtosters.lite.R.attr.im_bubble_wallpaper_outgoing || attr == com.vtosters.lite.R.attr.im_bubble_outgoing || attr == com.vtosters.lite.R.attr.im_bubble_outgoing_highlighted) {
|
||||
return wallLightColor;
|
||||
}
|
||||
|
||||
return themedColors.get(attr);
|
||||
}
|
||||
|
||||
public static boolean hasThemedAttr(Context context, int attrID) {
|
||||
// try {
|
||||
// Log.d(TAG, "Requesting color by attr " + context.getResources().getResourceName(attrID));
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
|
||||
if (isCachedAccents()) {
|
||||
if (!ThemesUtils.isDarkTheme()) {
|
||||
return (themedColors.get(attrID) != 0
|
||||
&& ACCENT_THEME_ONLY_MILK_DARK.get(attrID, true)
|
||||
&& ACCENT_THEME_ONLY_NOMILK_LIGHT.get(attrID, true));
|
||||
} else {
|
||||
return (themedColors.get(attrID) != 0
|
||||
&& ACCENT_THEME_ONLY_MILK_LIGHT.get(attrID, true)
|
||||
&& ACCENT_THEME_ONLY_NOMILK_LIGHT.get(attrID, true));
|
||||
}
|
||||
} else return themedColors.get(attrID) != 0;
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
cachedAccents = false;
|
||||
themedColors.clear();
|
||||
}
|
||||
|
||||
public static boolean isCachedAccents() {
|
||||
return cachedAccents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.*;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ThemesHacks {
|
||||
// Фиксит селектор (все/свои/архив) в профиле
|
||||
public static void fixProfileSelector(View view) {
|
||||
if (!ThemesUtils.isMilkshake()) return;
|
||||
var id = view.getId();
|
||||
|
||||
if (id == R.id.profile_wall_owner_posts || id == R.id.profile_wall_all_posts || id == R.id.profile_wall_archived_posts) {
|
||||
StateListDrawable states = (StateListDrawable) ((LayerDrawable) view.getBackground()).getDrawable(0);
|
||||
LayerDrawable selected = (LayerDrawable) ((DrawableContainer.DrawableContainerState) states.getConstantState()).getChildren()[0];
|
||||
((ColorDrawable) selected.getDrawable(0)).setColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixThemedFeed(TextView textView, int i) {
|
||||
if (i != R.layout.themed_feed_tab_2) {
|
||||
return;
|
||||
}
|
||||
textView.setTextColor(RecolorUtils.recolorCSL(textView.getTextColors()));
|
||||
((InsetDrawable) ((DrawableContainer.DrawableContainerState) textView.getBackground().getConstantState()).getChildren()[0]).getDrawable().setTint(ThemesUtils.lighten(ThemesUtils.getAccentColor(), 0.15f));
|
||||
}
|
||||
|
||||
public static void fixDropdown(Drawable drawable) {
|
||||
if (!ThemesUtils.isDarkTheme() && ThemesUtils.isMilkshake() && ThemesCore.isCachedAccents()) {
|
||||
StateListDrawable stateListDrawable = (StateListDrawable) drawable;
|
||||
((DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState()).getChildren()[0].setTint(ThemesUtils.getAccentColor());
|
||||
((DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState()).getChildren()[1].setTint(ThemesUtils.halfAlpha(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
public static int getHackedColor(@NonNull Context context, @ColorRes int color) {
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isAccentedColor(context.getColor(color))) {
|
||||
return ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isMutedAccentedColor(context.getColor(color))) {
|
||||
return ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT > 23) {
|
||||
return context.getColor(color);
|
||||
} else return context.getResources().getColor(color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VTLResources extends Resources {
|
||||
private static final String TAG = "VTLResources";
|
||||
private final Context context;
|
||||
private static Field typedArrayField;
|
||||
|
||||
private static final List<Integer> attributesToTheme = new ArrayList<>();
|
||||
|
||||
static {
|
||||
try {
|
||||
typedArrayField = TypedArray.class.getDeclaredField("mData");
|
||||
typedArrayField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
attributesToTheme.add(16843041);
|
||||
attributesToTheme.add(android.R.attr.backgroundTint);
|
||||
attributesToTheme.add(16843173);
|
||||
}
|
||||
|
||||
public VTLResources(Context context, Resources parent) {
|
||||
super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
|
||||
this.context = context;
|
||||
// Log.d(TAG, "VTLResources: init");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
|
||||
var typedArray = super.obtainAttributes(set, attrs);
|
||||
var data = getArrayData(typedArray);
|
||||
for (int i = 0; i < attrs.length; i++) {
|
||||
try {
|
||||
int attrID = attrs[i];
|
||||
if (attributesToTheme.contains(attrID)) {
|
||||
int type = data[i*6];
|
||||
int cnt = data[(i*6)+1];
|
||||
|
||||
if (type == TypedValue.TYPE_ATTRIBUTE && isAttrThemeable(cnt)) {
|
||||
data[i*6] = TypedValue.TYPE_INT_COLOR_RGB8;
|
||||
data[(i*6)+1] = ThemesUtils.getAccentColor();
|
||||
data[(i*6)+2] = 0; // clear reference content
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "TAVzlom failed! (obtainAttributes)");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundException {
|
||||
var drawable = super.getDrawable(id, theme);
|
||||
if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16) {
|
||||
ThemesHacks.fixDropdown(drawable);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
|
||||
private static boolean isAttrThemeable(int attrID) {
|
||||
return !ThemesUtils.isDarkTheme() && attrID == com.vtosters.lite.R.attr.button_primary_background;
|
||||
}
|
||||
|
||||
private static int[] getArrayData(TypedArray arr) {
|
||||
try {
|
||||
return (int[]) typedArrayField.get(arr);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(TAG, "getArrayData: ", e);
|
||||
e.printStackTrace();
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.BaseHook;
|
||||
import ru.vtosters.lite.themes.hooks.ButtonHook;
|
||||
import ru.vtosters.lite.themes.hooks.ImageViewHook;
|
||||
import ru.vtosters.lite.themes.hooks.ProgressWheelHook;
|
||||
import ru.vtosters.lite.themes.hooks.TabLayoutHook;
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.themes.hooks.ToolbarHook;
|
||||
import ru.vtosters.lite.themes.hooks.VKImageViewHook;
|
||||
|
||||
public class ViewInjector {
|
||||
public static ArrayList<BaseHook> hooks = new ArrayList<>();
|
||||
|
||||
static {
|
||||
hooks.add(new ButtonHook());
|
||||
hooks.add(new ImageViewHook());
|
||||
hooks.add(new TabLayoutHook());
|
||||
hooks.add(new TextViewHook());
|
||||
hooks.add(new ToolbarHook());
|
||||
hooks.add(new VKImageViewHook());
|
||||
hooks.add(new ProgressWheelHook());
|
||||
}
|
||||
|
||||
public static View inject(View view, int i, boolean z) {
|
||||
for (BaseHook hook : hooks) {
|
||||
hook.inject(view, i, z);
|
||||
}
|
||||
if (view instanceof ViewGroup) {
|
||||
var viewGroup = (ViewGroup) view;
|
||||
for (int i2 = 0; i2 < viewGroup.getChildCount(); i2++) {
|
||||
inject(viewGroup.getChildAt(i2), i, false);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface BaseHook {
|
||||
void inject(View view, int i, boolean z);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ButtonHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof Button) {
|
||||
var button = (Button) view;
|
||||
if (button.getBackgroundTintList() != null && ColorReferences.isMutedAccentedColor(button.getBackgroundTintList())) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
|
||||
if (button.getBackgroundTintList() != null && ColorReferences.isAccentedColor(button.getBackgroundTintList())) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (TextViewHook.isPositiveButton(button) || TextViewHook.isVkUiButton(view)) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ImageViewHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof ImageView) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
var imageView = (ImageView) view;
|
||||
if (imageView.getImageTintList() == null) return;
|
||||
if (ColorReferences.isCslNeedToBeThemed(imageView.getImageTintList())) {
|
||||
imageView.setImageTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ProgressWheelHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof ProgressWheel) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
var progressWheel = (ProgressWheel) view;
|
||||
progressWheel.setBarColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.core.view.VKTabLayout;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
|
||||
public class TabLayoutHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKTabLayout) {
|
||||
var tabLayout = (VKTabLayout) view;
|
||||
tabLayout.setSelectedTabIndicatorColor(ThemesUtils.getAccentColor());
|
||||
tabLayout.setTabRippleColor(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatCheckedTextView;
|
||||
|
||||
import com.vk.core.extensions.EditTextExt;
|
||||
import com.vk.core.view.OverlayTextView;
|
||||
import com.vk.core.view.TintTextView;
|
||||
import com.vk.core.view.links.LinkedTextView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesHacks;
|
||||
import ru.vtosters.lite.themes.utils.VkUiThemer;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class TextViewHook implements BaseHook {
|
||||
|
||||
private static final String TAG = "TextViewHook";
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof TextView) {
|
||||
var textView = (TextView) view;
|
||||
|
||||
if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && textView.getCompoundDrawableTintList() != null) {
|
||||
if (ColorReferences.isAccentedColor(textView.getCompoundDrawableTintList())) {
|
||||
textView.setCompoundDrawableTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(textView.getCompoundDrawableTintList())) {
|
||||
textView.setCompoundDrawableTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if (textView.getLinkTextColors() != null && ColorReferences.isAccentedColor(textView.getLinkTextColors())) {
|
||||
textView.setLinkTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (textView.getLinkTextColors() != null && ColorReferences.isMutedAccentedColor(textView.getLinkTextColors())) {
|
||||
textView.setLinkTextColor(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (isPositiveButton(textView) || isVkUiButton(textView)) {
|
||||
view.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (view instanceof OverlayTextView) {
|
||||
if (view.getId() == android.R.id.button1) {
|
||||
view.setBackground(ThemesUtils.recolorDrawable(view.getBackground()));
|
||||
}
|
||||
if (ColorReferences.isAccentedColor(((OverlayTextView) view).getTextColors().getDefaultColor())) {
|
||||
((OverlayTextView) view).setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof TintTextView) {
|
||||
if (eligibleForStartTinting((TintTextView) view)) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForStartTintingMuted((TintTextView) view)) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForTinting(view.getId())) {
|
||||
((TintTextView) view).setDrawableTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForTinting(view.getId())) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof LinkedTextView) {
|
||||
((LinkedTextView) view).setLinkTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (view instanceof AppCompatCheckedTextView) {
|
||||
var check = (AppCompatCheckedTextView) view;
|
||||
if (ColorReferences.isAccentedColor(check.getCheckMarkTintList())) {
|
||||
check.setCheckMarkTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(check.getCheckMarkTintList())) {
|
||||
check.setCheckMarkTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof EditText) {
|
||||
ThemesUtils.setCursorColor((EditText) view);
|
||||
}
|
||||
|
||||
ThemesUtils.colorHandles(textView);
|
||||
VkUiThemer.autoThemeVkuiButtons(textView);
|
||||
ThemesHacks.fixProfileSelector(textView);
|
||||
ThemesHacks.fixThemedFeed(textView, i);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean eligibleForStartTinting(TintTextView view) {
|
||||
return ColorReferences.isAccentedColor(view.getTextColors()) || view.getTextColors().getDefaultColor() == ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
public static boolean eligibleForStartTintingMuted(TintTextView view) {
|
||||
return ColorReferences.isMutedAccentedColor(view.getTextColors()) || view.getTextColors().getDefaultColor() == ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
public static boolean eligibleForTinting(int id) {
|
||||
return !ThemesUtils.isDarkTheme() && (id == R.id.attach_title || id == R.id.post_retweet_name);
|
||||
}
|
||||
|
||||
public static boolean isPositiveButton(View view) {
|
||||
return !ThemesUtils.isDarkTheme() && (view.getId() == R.id.positive || view.getId() == R.id.positive_button);
|
||||
}
|
||||
|
||||
public static boolean isVkUiButton(View view) {
|
||||
return !ThemesUtils.isDarkTheme() && (view.getId() == R.id.empty_button || view.getId() == R.id.button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ToolbarHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof Toolbar) {
|
||||
var color = (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText();
|
||||
var menu = ((Toolbar) view).getMenu();
|
||||
for (int j = 0; j < menu.size(); ++j) {
|
||||
var item = menu.getItem(j);
|
||||
var icon = item.getIcon();
|
||||
if (icon != null) {
|
||||
if (icon instanceof RecoloredDrawable)
|
||||
((RecoloredDrawable) icon).a(color);
|
||||
else
|
||||
icon = new RecoloredDrawable(icon, color);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.imageloader.view.VKImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VKImageViewHook implements BaseHook {
|
||||
private static Paint paint = new Paint();
|
||||
static {
|
||||
paint.setColorFilter(new PorterDuffColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKImageView) {
|
||||
var imageView = (VKImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(RecolorUtils.recolorCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package ru.vtosters.lite.themes.items;
|
||||
|
||||
public class VTLColor {
|
||||
|
||||
public String resName;
|
||||
public int id;
|
||||
public int color;
|
||||
|
||||
public VTLColor(int id, int color) {
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
}
|
||||
public VTLColor(String resName, int id, int color) {
|
||||
this.resName = resName;
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static VTLColor create(int id, int color) {
|
||||
return new VTLColor(id, color);
|
||||
}
|
||||
|
||||
public static VTLColor create(String resName, int id, int color) {
|
||||
return new VTLColor(resName, id, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.themes.items;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VTLPalette {
|
||||
public String id;
|
||||
public String name;
|
||||
public String author;
|
||||
public List<VTLColor> colors = new ArrayList<>();
|
||||
|
||||
public VTLPalette() {
|
||||
|
||||
}
|
||||
|
||||
public VTLPalette(String id, String name, String author, List<VTLColor> colors) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.author = author;
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public VTLPalette setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setAuthor(String author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setColors(List<VTLColor> colors) {
|
||||
this.colors = colors;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setColor(String name, int color) {
|
||||
this.colors.add(new VTLColor(name, 0, color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getColor(String name) {
|
||||
for (var item : colors)
|
||||
if (name.equals(item.resName))
|
||||
return item.color;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static VTLPalette fromJson(JSONObject json) throws JSONException {
|
||||
var palette = new VTLPalette()
|
||||
.setId(json.optString("palette_id"))
|
||||
.setName(json.optString("name"))
|
||||
.setAuthor(json.optString("author"));
|
||||
var paletteNode = json.getJSONArray("palette");
|
||||
for (int i = 0; i < paletteNode.length(); i++) {
|
||||
var colorNode = paletteNode.getJSONObject(i);
|
||||
var name = colorNode.getString("name");
|
||||
if (colorNode.has("colors")) {
|
||||
var colorsNode = colorNode.getJSONArray("colors");
|
||||
for (int j = 0; j < colorsNode.length(); j++) {
|
||||
var subColorNode = colorsNode.getJSONObject(j);
|
||||
var index = subColorNode.getString("index");
|
||||
var subColor = subColorNode.getString("color");
|
||||
if (!subColor.startsWith("#")) subColor = "#" + subColor;
|
||||
palette.setColor(name + " " + index, Color.parseColor(subColor));
|
||||
}
|
||||
} else {
|
||||
var color = colorNode.getString("color");
|
||||
if (!color.startsWith("#")) color = "#" + color;
|
||||
palette.setColor(name, Color.parseColor(color));
|
||||
}
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
public static VTLPalette valuesOf(String id, String name, String author, List<VTLColor> colors) {
|
||||
return new VTLPalette()
|
||||
.setId(id)
|
||||
.setName(name)
|
||||
.setAuthor(author)
|
||||
.setColors(colors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package ru.vtosters.lite.themes.palettes;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLPalette;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class PalettesManager {
|
||||
|
||||
private final static File PALETTES_DIR = new File(Environment.getExternalStorageDirectory(), "VTL/palettes");
|
||||
private final static String ASSETS_DIR = "vtl_themes/palettes/";
|
||||
|
||||
private static PalettesManager sInstance;
|
||||
|
||||
private final List<VTLPalette> mPalettes = new ArrayList<>();
|
||||
|
||||
public static PalettesManager getInstance() {
|
||||
if (sInstance == null)
|
||||
sInstance = new PalettesManager();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public PalettesManager() {
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
mPalettes.clear();
|
||||
if (!PALETTES_DIR.exists())
|
||||
PALETTES_DIR.mkdirs();
|
||||
final var palettes = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"));
|
||||
if (palettes == null || palettes.length == 0)
|
||||
copyPaletteFromAssets();
|
||||
parsePalettes();
|
||||
}
|
||||
|
||||
private boolean copyPaletteFromAssets() {
|
||||
try {
|
||||
final var manager = AndroidUtils.getGlobalContext().getAssets();
|
||||
final var assets = manager.list(ASSETS_DIR);
|
||||
if (assets == null || assets.length == 0) return false;
|
||||
for (var asset : assets) {
|
||||
try {
|
||||
IOUtils.copyFile(manager.open(ASSETS_DIR + asset), new File(PALETTES_DIR, asset));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void parsePalettes() {
|
||||
var arr = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"));
|
||||
if (arr == null || arr.length == 0)
|
||||
throw new RuntimeException("Can't load palettes");
|
||||
for (var file : arr) {
|
||||
try {
|
||||
var json = new JSONObject(IOUtils.readAllLines(file));
|
||||
mPalettes.add(VTLPalette.fromJson(json));
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VTLPalette getPalette(String id) {
|
||||
for (var palette : mPalettes)
|
||||
if (id.equals(palette.id))
|
||||
return palette;
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public VTLPalette getPalette(int i) {
|
||||
return mPalettes.get(i);
|
||||
}
|
||||
|
||||
public int getPalettesCount() {
|
||||
return mPalettes.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class RecolorUtils {
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
return new RecoloredDrawable(drawable, ThemesUtils.getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = AndroidUtils.getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, ThemesUtils.getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static int recolorHexColor(int i){
|
||||
var accented = ColorReferences.isAccentedColor(i);
|
||||
var mutedaccented = ColorReferences.isMutedAccentedColor(i);
|
||||
return (accented || mutedaccented) ? (accented ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : i;
|
||||
}
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (ColorReferences.isColorRefAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} else if (ColorReferences.isColorRefMutedAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
return themeCSL(csl);
|
||||
} // Recolor ColorStateList
|
||||
|
||||
public static ColorStateList themeCSL(ColorStateList csl){
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
int enabled = csl.getColorForState(new int[]{android.R.attr.state_enabled}, Color.BLACK);
|
||||
int disabled = csl.getColorForState(new int[]{-android.R.attr.state_enabled}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = ColorReferences.isAccentedColor(unsel);
|
||||
boolean isSelAccent = ColorReferences.isAccentedColor(sel);
|
||||
boolean isEnabledAccent = ColorReferences.isAccentedColor(enabled);
|
||||
boolean isDisabledAccent = ColorReferences.isAccentedColor(disabled);
|
||||
|
||||
boolean isUnselMutedAccent = ColorReferences.isMutedAccentedColor(unsel);
|
||||
boolean isSelMutedAccent = ColorReferences.isMutedAccentedColor(sel);
|
||||
boolean isEnabledMutedAccent = ColorReferences.isMutedAccentedColor(enabled);
|
||||
boolean isDisabledMutedAccent = ColorReferences.isMutedAccentedColor(disabled);
|
||||
|
||||
if (isUnselAccent || isSelAccent || isUnselMutedAccent || isSelMutedAccent) {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{(isSelAccent || isSelMutedAccent) ? (isSelAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : sel, (isUnselAccent || isUnselMutedAccent) ? (isUnselAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : unsel});
|
||||
}
|
||||
|
||||
if (isDisabledAccent || isEnabledAccent || isEnabledMutedAccent || isDisabledMutedAccent) {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_enabled}, new int[]{-android.R.attr.state_enabled}
|
||||
}, new int[]{(isEnabledAccent || isEnabledMutedAccent) ? (isEnabledAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : enabled, (isDisabledAccent || isDisabledMutedAccent) ? (isDisabledAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : disabled});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.DrawableContainer;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.Build;
|
||||
import android.widget.TextView;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VkUiThemer {
|
||||
public static void autoThemeVkuiButtons(TextView view) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
|
||||
if (ThemesUtils.isDarkTheme())
|
||||
return; // no need to theme b/w buttons, well it should skip, but I do it for extra performance
|
||||
|
||||
try {
|
||||
if (!(view.getBackground() instanceof StateListDrawable)) return;
|
||||
|
||||
StateListDrawable states = ((StateListDrawable) view.getBackground());
|
||||
if (states.getConstantState() == null) return;
|
||||
DrawableContainer.DrawableContainerState dStates = (DrawableContainer.DrawableContainerState) states.getConstantState();
|
||||
|
||||
if (dStates.getChildCount() == 2) {
|
||||
Drawable target = dStates.getChildren()[0];
|
||||
if (!(target instanceof RippleDrawable)) return;
|
||||
|
||||
RippleDrawable ripple = (RippleDrawable) target;
|
||||
for (int i = 0; i < ripple.getNumberOfLayers(); i++) {
|
||||
if (ripple.getId(i) == android.R.id.mask) continue;
|
||||
|
||||
Drawable currentTarget = ripple.getDrawable(i);
|
||||
|
||||
if (!(currentTarget instanceof GradientDrawable)) continue;
|
||||
|
||||
//if (TSColorRefs.TS_DEBUG_MODE) Log.d("TSCore", "[tsh] finally, obamium = ["+currentTarget.toString()+"]");
|
||||
|
||||
GradientDrawable spd = (GradientDrawable) currentTarget;
|
||||
if (spd.getShape() != GradientDrawable.RECTANGLE) continue;
|
||||
|
||||
// Log.d("TSCore", "[tsh] got a color!");
|
||||
|
||||
ColorStateList csl = spd.getColor();
|
||||
// if (csl != null) {
|
||||
// Log.d("TSCore", "[tsh] csl2 <def: " + csl.getDefaultColor() + " = " + ThemesUtils.hex(csl.getDefaultColor()) + "> | " + csl);
|
||||
// }
|
||||
|
||||
if (ColorReferences.isAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh] theming CSL");
|
||||
spd.setTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
Drawable draw2 = dStates.getChildren()[0];
|
||||
if (!(draw2 instanceof GradientDrawable)) return;
|
||||
GradientDrawable spd = (GradientDrawable) draw2;
|
||||
if (spd.getShape() != GradientDrawable.RECTANGLE) return;
|
||||
|
||||
// Log.d("TSCore", "[tsh:disabled] got a color!");
|
||||
|
||||
ColorStateList csl = spd.getColor();
|
||||
// if (csl != null) {
|
||||
// Log.d("TSCore", "[tsh:disabled] csl2 <def: " + csl.getDefaultColor() + " = " + ThemesUtils.hex(csl.getDefaultColor()) + "> | " + csl);
|
||||
// }
|
||||
|
||||
if (ColorReferences.isAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh:disabled] theming CSL");
|
||||
spd.setTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh:disabled] theming CSL");
|
||||
spd.setTint(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// This must go wrong, so we ignore any exceptions that may occur
|
||||
e.printStackTrace(); // REMOVE THIS!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,23 @@
|
||||
package ru.vtosters.lite.ui;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.ImageUtils.setTint;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import com.vtosters.lite.ui.MaterialSwitchPreference;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ImageUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class PreferencesUtil {
|
||||
|
||||
@@ -36,7 +29,7 @@ public class PreferencesUtil {
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
ListPreference preference = new ListPreference(fragment.requireContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setTitle(title); // setTitle
|
||||
@@ -57,7 +50,7 @@ public class PreferencesUtil {
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
ListPreference preference = new ListPreference(fragment.requireContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setSummary(summary); // setSummary
|
||||
@@ -69,7 +62,7 @@ public class PreferencesUtil {
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
@@ -80,7 +73,7 @@ public class PreferencesUtil {
|
||||
CharSequence summary,
|
||||
boolean defValue
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(materialPreferenceToolbarFragment.requireContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -98,7 +91,7 @@ public class PreferencesUtil {
|
||||
// boolean defValue,
|
||||
// Preference.OnPreferenceChangeListener listener
|
||||
// ) {
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(fragment.requireContext());
|
||||
// materialSwitchPreference.setTitle(title); // setTitle
|
||||
// materialSwitchPreference.setSummary(summary); // setSummary
|
||||
// materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -106,7 +99,7 @@ public class PreferencesUtil {
|
||||
// materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener
|
||||
//
|
||||
// if (iconRes != 0)
|
||||
// materialSwitchPreference.setIcon(setTint(getGlobalContext(), Objects.requireNonNull(ContextCompat.getDrawable(getGlobalContext(), iconRes)))); // preference.setIcon
|
||||
// materialSwitchPreference.setIcon(setTint(fragment.requireContext(), Objects.requireNonNull(ContextCompat.getDrawable(fragment.requireContext(), iconRes)))); // preference.setIcon
|
||||
//
|
||||
// fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
// }
|
||||
@@ -120,7 +113,7 @@ public class PreferencesUtil {
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(fragment.requireContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -128,7 +121,7 @@ public class PreferencesUtil {
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
|
||||
if (iconRes != 0)
|
||||
materialSwitchPreference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -140,7 +133,7 @@ public class PreferencesUtil {
|
||||
CharSequence title,
|
||||
CharSequence summary
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
@@ -155,12 +148,12 @@ public class PreferencesUtil {
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -173,13 +166,13 @@ public class PreferencesUtil {
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -193,7 +186,7 @@ public class PreferencesUtil {
|
||||
@Nullable Drawable icon,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
@@ -206,37 +199,37 @@ public class PreferencesUtil {
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), null);
|
||||
PreferenceCategory preference = new PreferenceCategory(fragment.requireContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title, int collapsedSize) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), null);
|
||||
PreferenceCategory preference = new PreferenceCategory(fragment.requireContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addEditTextPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, EditTextPrefChangeListener editTextPrefChangeListener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setOnPreferenceClickListener(preference1 -> {
|
||||
LinearLayout linearLayout = new LinearLayout(getGlobalContext());
|
||||
LinearLayout linearLayout = new LinearLayout(fragment.requireContext());
|
||||
|
||||
final EditText editText = new EditText(getGlobalContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(getGlobalContext()).getString(key, ""));
|
||||
final EditText editText = new EditText(fragment.requireContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(fragment.requireContext()).getString(key, ""));
|
||||
editText.setHint(title);
|
||||
editText.setTextColor(getTextAttr());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setTextColor(ThemesUtils.getTextAttr());
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(dp2px(20f), 0, dp2px(20f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(20f), 0, AndroidUtils.dp2px(20f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(fragment.getContext())
|
||||
@@ -247,7 +240,7 @@ public class PreferencesUtil {
|
||||
if (!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getGlobalContext())
|
||||
PreferenceManager.getDefaultSharedPreferences(fragment.requireContext())
|
||||
.edit()
|
||||
.putString(key, editText.getText().toString())
|
||||
.apply();
|
||||
@@ -261,13 +254,13 @@ public class PreferencesUtil {
|
||||
|
||||
public static int getTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getTextAttr(), typedValue, true);
|
||||
ctx.getTheme().resolveAttribute(ThemesUtils.getTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getSTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getSTextAttr(), typedValue, true);
|
||||
ctx.getTheme().resolveAttribute(ThemesUtils.getSTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.core.drawable.BorderDrawable;
|
||||
import com.vk.core.util.Screen;
|
||||
import com.vk.stories.view.StoryCircleImageView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLColor;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.ColorPickerViewHolder> {
|
||||
|
||||
private List<VTLColor> mColors;
|
||||
private OnColorSelectListener mSelectListener;
|
||||
|
||||
public ColorPickerAdapter(List<VTLColor> colors, OnColorSelectListener selectListener) {
|
||||
this.mColors = colors;
|
||||
this.mSelectListener = selectListener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ColorPickerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
var container = LayoutInflater.from(parent.getContext())
|
||||
.inflate(AndroidUtils.getIdentifier("color_picker_item", "layout"), parent, false);
|
||||
return new ColorPickerViewHolder(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ColorPickerViewHolder holder, int pos) {
|
||||
holder.bind(mColors.get(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mColors.size();
|
||||
}
|
||||
|
||||
public class ColorPickerViewHolder extends RecyclerView.ViewHolder {
|
||||
private View mContainer;
|
||||
private FrameLayout mColorPreviewBorder;
|
||||
private StoryCircleImageView mColorPreview;
|
||||
private TextView mColorName;
|
||||
private TextView mColorValue;
|
||||
|
||||
public ColorPickerViewHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
mContainer = view;
|
||||
mColorPreviewBorder = view.findViewById(AndroidUtils.getIdentifier("color_preview_border", "id"));
|
||||
mColorPreview = view.findViewById(AndroidUtils.getIdentifier("color_preview", "id"));
|
||||
mColorName = view.findViewById(AndroidUtils.getIdentifier("color_name", "id"));
|
||||
mColorValue = view.findViewById(AndroidUtils.getIdentifier("color_value", "id"));
|
||||
}
|
||||
|
||||
public void bind(VTLColor item) {
|
||||
mContainer.setOnClickListener(v -> mSelectListener.onColorSelected(ColorPickerAdapter.this, item));
|
||||
mColorPreviewBorder.setBackground(new BorderDrawable(ThemesUtils.isDarkTheme() ? Color.WHITE : Color.BLACK, Screen.c(24.0f), Screen.c(1.0f)));
|
||||
mColorPreview.setPlaceholderColor(item.color);
|
||||
mColorName.setText(item.resName);
|
||||
mColorValue.setText("#" + Integer.toHexString(item.color).toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnColorSelectListener {
|
||||
|
||||
void onColorSelected(ColorPickerAdapter adapter, VTLColor vtlcolor);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,41 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.core.widget.BubbleFluidLayout;
|
||||
import com.vk.im.ui.components.viewcontrollers.msg_list.entry.MsgTextBuilder;
|
||||
import com.vk.im.ui.views.msg.MsgPartTextView;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleDrawable;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubblePart;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleStyle;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleView;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.m0.ToolbarHelper;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreviewAdapter.MessagePreviewViewHolder> {
|
||||
private static final int ME = 0x0;
|
||||
private static final int ANONYMOUS = -0x1;
|
||||
|
||||
private final String[] mMessages = AndroidUtils.getArray(R.array.wallpaper_change_dialog);
|
||||
private final String[] mMessages;
|
||||
|
||||
private static int getColorFromAttribute(Context context, int attrId) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(attrId, typedValue, true);
|
||||
return typedValue.data;
|
||||
public MessagesPreviewAdapter(String... messages) {
|
||||
mMessages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
return i % 2 == 0 ? ANONYMOUS : ME;
|
||||
return i % 2 == 0 ? Gravity.START : Gravity.END;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -41,7 +43,12 @@ public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreview
|
||||
public MessagePreviewViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
Context context = viewGroup.getContext();
|
||||
|
||||
var bubbleFluidLayout = (BubbleFluidLayout) LayoutInflater.from(context).inflate(R.layout.vkim_msg_list_item_msg_from_user, viewGroup, false);
|
||||
final var inflater = LayoutInflater.from(context);
|
||||
|
||||
final var bubbleFluidLayout = (BubbleFluidLayout) inflater
|
||||
.inflate(R.layout.vkim_msg_list_item_msg_from_user, viewGroup, false);
|
||||
bubbleFluidLayout.setPadding(0, AndroidUtils.dp2px(4), 0, 0);
|
||||
bubbleFluidLayout.setGravity(viewType);
|
||||
|
||||
bubbleFluidLayout.findViewById(R.id.avatar).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.avatar_space).setVisibility(View.GONE);
|
||||
@@ -49,19 +56,20 @@ public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreview
|
||||
bubbleFluidLayout.findViewById(R.id.status).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.status_space).setVisibility(View.GONE);
|
||||
|
||||
var messageBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
messageBubbleView.setContentPaddingLeft(AndroidUtils.dp2px(5));
|
||||
messageBubbleView.setContentPaddingTop(AndroidUtils.dp2px(5));
|
||||
messageBubbleView.setContentPaddingRight(AndroidUtils.dp2px(5));
|
||||
messageBubbleView.setContentPaddingBottom(AndroidUtils.dp2px(5));
|
||||
bubbleFluidLayout.setGravity(viewType == ME ? Gravity.RIGHT : Gravity.LEFT);
|
||||
final var messageBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
messageBubbleView.setContentPaddingLeft(AndroidUtils.dp2px(10));
|
||||
messageBubbleView.setContentPaddingTop(AndroidUtils.dp2px(4));
|
||||
messageBubbleView.setContentPaddingRight(AndroidUtils.dp2px(4));
|
||||
messageBubbleView.setContentPaddingBottom(AndroidUtils.dp2px(0));
|
||||
if (viewType == Gravity.END)
|
||||
messageBubbleView.a(MsgBubbleStyle.b(false, false), MsgBubblePart.FULL, ThemesUtils.getAccentColor());
|
||||
bubbleFluidLayout.setLayoutDirection(viewType);
|
||||
|
||||
var message = new TextView(context);
|
||||
message.setTag("message");
|
||||
message.setGravity(Gravity.LEFT);
|
||||
message.setTextColor(getTextAttr());
|
||||
final var msgTextView = inflater.inflate(R.layout.vkim_msg_part_text, viewGroup, false);
|
||||
msgTextView.setId(R.id.msg_text);
|
||||
|
||||
messageBubbleView.setContentView(message);
|
||||
final var msgBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
msgBubbleView.setContentView(msgTextView);
|
||||
|
||||
return new MessagePreviewViewHolder(bubbleFluidLayout);
|
||||
}
|
||||
@@ -77,17 +85,17 @@ public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreview
|
||||
}
|
||||
|
||||
protected static class MessagePreviewViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final TextView mMessage;
|
||||
private final MsgPartTextView mMsgTextView;
|
||||
|
||||
public MessagePreviewViewHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
mMessage = view.findViewWithTag("message");
|
||||
mMsgTextView = view.findViewById(R.id.msg_text);
|
||||
}
|
||||
|
||||
public void bind(String text) {
|
||||
mMessage.setText(text);
|
||||
mMsgTextView.setText(new MsgTextBuilder().a(text));
|
||||
mMsgTextView.setTimeText("12:00");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class NewsfeedListManager {
|
||||
sendToast(activity.getString(R.string.newsfeed_list_update_feed_to_work));
|
||||
}
|
||||
)
|
||||
));
|
||||
), "newsfeed_items_editor");
|
||||
}
|
||||
|
||||
public static void resetHideItems() {
|
||||
|
||||
@@ -26,22 +26,22 @@ public class OTADialog implements OTAUtils.OTAListener {
|
||||
|
||||
@Override
|
||||
public void onUpdateApplied() {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновления найдены", Toast.LENGTH_SHORT).show();
|
||||
new ModalBottomSheetWrapper(mActivity)
|
||||
.setTitle(mActivity.getString(R.string.newversion) + " " + mHelper.getNewVersionName())
|
||||
.setUpdateInfoView(mHelper.getUpdateDescription())
|
||||
.setPositiveButton(mActivity.getString(R.string.updateanddownload), () -> {
|
||||
OTADownloader.downloadBuild(mHelper.getDownloadUrl(), mHelper.getCommitSHA());
|
||||
})
|
||||
.show();
|
||||
});
|
||||
// mActivity.runOnUiThread(() -> {
|
||||
// // Toast.makeText(mActivity, "Обновления найдены", Toast.LENGTH_SHORT).show();
|
||||
// new ModalBottomSheetWrapper(mActivity)
|
||||
// .setTitle(mActivity.getString(R.string.newversion) + " " + mHelper.getNewVersionName())
|
||||
// .setUpdateInfoView(mHelper.getUpdateDescription())
|
||||
// .setPositiveButton(mActivity.getString(R.string.updateanddownload), () -> {
|
||||
// OTADownloader.downloadBuild(mHelper.getDownloadUrl(), mHelper.getCommitSHA());
|
||||
// })
|
||||
// .show();
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCanceled() {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновлений не найдено", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
// mActivity.runOnUiThread(() -> {
|
||||
// // Toast.makeText(mActivity, "Обновлений не найдено", Toast.LENGTH_SHORT).show();
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLPalette;
|
||||
import ru.vtosters.lite.ui.adapters.ColorPickerAdapter;
|
||||
|
||||
public class PalettesBottomSheetDialog {
|
||||
|
||||
private static final String TAG = "palettes_copy_color";
|
||||
|
||||
public static void create(Activity activity, VTLPalette palette, ColorPickerAdapter.OnColorSelectListener action) {
|
||||
var instance = new VTColorPickerBottomSheetDialog(activity);
|
||||
var colorPickerAdapter = new ColorPickerAdapter(palette.colors, (adapter, vtlcolor) -> {
|
||||
action.onColorSelected(adapter, vtlcolor);
|
||||
instance.dismiss();
|
||||
});
|
||||
instance.setTitle(palette.name)
|
||||
.setAdapter(colorPickerAdapter, true)
|
||||
.show(TAG, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.ColorPickerAdapter;
|
||||
import ru.vtosters.lite.ui.vkui.ModalBottomSheetWrapper;
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
|
||||
public class VTColorPickerBottomSheetDialog extends ModalBottomSheetWrapper<VTColorPickerBottomSheetDialog> {
|
||||
|
||||
private Activity mActivity;
|
||||
private LinearLayout mContainer;
|
||||
|
||||
public VTColorPickerBottomSheetDialog(Activity activity) {
|
||||
super(activity);
|
||||
this.mActivity = activity;
|
||||
mContainer = new LinearLayout(mActivity);
|
||||
mContainer.setLayoutParams(LayoutUtils.createLinear(-1, -1));
|
||||
mContainer.setOrientation(LinearLayout.VERTICAL);
|
||||
}
|
||||
|
||||
public VTColorPickerBottomSheetDialog setAdapter(ColorPickerAdapter adapter, boolean searchMode) {
|
||||
var recyclerView = new RecyclerView(mActivity);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
|
||||
var recyclerViewParams = LayoutUtils.createLinear(-1, -1);
|
||||
mContainer.addView(recyclerView, recyclerViewParams);
|
||||
|
||||
mBuilder.a(mContainer);
|
||||
return setView(mContainer);
|
||||
}
|
||||
|
||||
public LinearLayout getContainer() {
|
||||
return mContainer;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public abstract class BaseToolbarFragment extends FragmentImpl {
|
||||
private Toolbar mToolbar;
|
||||
private FrameLayout mContentLayout;
|
||||
|
||||
@CallSuper
|
||||
|
||||
protected void onCreateMenu(Menu menu) {
|
||||
if (menu.size() > 0)
|
||||
for (int i = 0; i < menu.size(); i++)
|
||||
@@ -63,6 +63,10 @@ public abstract class BaseToolbarFragment extends FragmentImpl {
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
public Toolbar getToolbar() {
|
||||
return mToolbar;
|
||||
}
|
||||
|
||||
public abstract View onCreateContent(@NonNull LayoutInflater inflater, @Nullable Bundle bundle);
|
||||
|
||||
private void initToolbar() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
|
||||
import ru.vtosters.lite.ui.components.DockBarEditorManager;
|
||||
import ru.vtosters.lite.ui.components.ItemMovingCallback;
|
||||
@@ -54,6 +55,8 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(save, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams saveParams = new LinearLayout.LayoutParams(0, -2);
|
||||
saveParams.weight = 1.0f;
|
||||
buttonsContainer.addView(save, saveParams);
|
||||
@@ -68,6 +71,8 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(reset, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams resetParams = new LinearLayout.LayoutParams(0, -2);
|
||||
resetParams.weight = 1.0f;
|
||||
buttonsContainer.addView(reset, resetParams);
|
||||
|
||||
@@ -50,6 +50,7 @@ import ru.vtosters.lite.music.LastFMScrobbler;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.ui.adapters.ImagineArrayAdapter;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
@@ -57,7 +58,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
public static void download(Context ctx) {
|
||||
final EditText input = new EditText(ctx);
|
||||
input.setTextColor(getTextAttr());
|
||||
input.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
input.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
var lp = new FrameLayout.LayoutParams(-1, -2);
|
||||
lp.leftMargin = AndroidUtils.dp2px(16);
|
||||
@@ -175,7 +176,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
fn.setHint(R.string.lastfm_login);
|
||||
fn.setTextColor(getTextAttr());
|
||||
fn.setHintTextColor(getSTextAttr());
|
||||
fn.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
fn.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(fn);
|
||||
fn.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) fn.getLayoutParams());
|
||||
@@ -186,7 +187,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
ln.setHint(R.string.lastfm_password);
|
||||
ln.setTextColor(getTextAttr());
|
||||
ln.setHintTextColor(getSTextAttr());
|
||||
ln.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
ln.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(ln);
|
||||
ln.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ln.setLayoutParams(margin);
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
|
||||
import ru.vtosters.lite.ui.components.ItemMovingCallback;
|
||||
import ru.vtosters.lite.ui.components.SuperAppEditorManager;
|
||||
@@ -70,6 +71,8 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(save, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams saveParams = new LinearLayout.LayoutParams(0, -2);
|
||||
saveParams.weight = 1.0f;
|
||||
buttonsContainer.addView(save, saveParams);
|
||||
@@ -84,6 +87,8 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(reset, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams resetParams = new LinearLayout.LayoutParams(0, -2);
|
||||
resetParams.weight = 1.0f;
|
||||
buttonsContainer.addView(reset, resetParams);
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.fragments.FragmentImpl;
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.themes.palettes.PalettesManager;
|
||||
import ru.vtosters.lite.ui.dialogs.PalettesBottomSheetDialog;
|
||||
import ru.vtosters.lite.ui.views.rarepebble.ColorPickerView;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@@ -22,23 +29,75 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(R.xml.preferences_themes);
|
||||
prefs();
|
||||
initPreferences();
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
findPreference("navbar").setOnPreferenceClickListener(new restart());
|
||||
findPreference("milkshake").setOnPreferenceClickListener(new restart());
|
||||
findPreference("darktheme").setOnPreferenceChangeListener(new restartdark());
|
||||
findPreference("lighttheme").setOnPreferenceChangeListener(new restartlight());
|
||||
findPreference("iconmanager").setOnPreferenceClickListener(new openicons());
|
||||
findPreference("dockbar_tab_titles").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dockbar_accent").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dockcounter").setOnPreferenceClickListener(new restart());
|
||||
findPreference("newsfeed_notif").setOnPreferenceClickListener(new restart());
|
||||
findPreference("newsfeed_notif").setVisible(milkshake());
|
||||
private void initPreferences() {
|
||||
var accentColorPreference = findPreference("accent_color");
|
||||
accentColorPreference.setIcon(ThemesUtils.recolorDrawable(requireContext().getDrawable(R.drawable.bg_accent_circle)));
|
||||
accentColorPreference.setOnPreferenceClickListener(preference -> {
|
||||
changeAccent();
|
||||
return false;
|
||||
});
|
||||
|
||||
if (isTablet()) {
|
||||
findPreference("dockbarsett").setVisible(false);
|
||||
var navBarPreference = findPreference("navbar");
|
||||
navBarPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return false;
|
||||
});
|
||||
|
||||
var milkshakePreference = findPreference("milkshake");
|
||||
milkshakePreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return false;
|
||||
});
|
||||
|
||||
var darkThemePreference = findPreference("darktheme");
|
||||
darkThemePreference.setOnPreferenceChangeListener((preference, o) -> {
|
||||
restartDark(o.toString());
|
||||
return false;
|
||||
});
|
||||
|
||||
var lightThemePreference = findPreference("lighttheme");
|
||||
lightThemePreference.setOnPreferenceChangeListener(((preference, o) -> {
|
||||
restartLight(o.toString());
|
||||
return false;
|
||||
}));
|
||||
|
||||
var iconManagerPreference = findPreference("iconmanager");
|
||||
iconManagerPreference.setOnPreferenceClickListener(preference -> {
|
||||
switchFragment(IconsFragment.class);
|
||||
return false;
|
||||
});
|
||||
|
||||
var dockbarTabTitlesPreference = findPreference("dockbar_tab_titles");
|
||||
dockbarTabTitlesPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return false;
|
||||
});
|
||||
|
||||
var dockbarAccentPreference = findPreference("dockbar_accent");
|
||||
dockbarAccentPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return false;
|
||||
});
|
||||
|
||||
var dockCounterPreference = findPreference("dockcounter");
|
||||
dockCounterPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return false;
|
||||
});
|
||||
|
||||
var newsfeedNotificationsPreference = findPreference("newsfeed_notif");
|
||||
newsfeedNotificationsPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return false;
|
||||
});
|
||||
newsfeedNotificationsPreference.setVisible(Preferences.milkshake());
|
||||
|
||||
if (AndroidUtils.isTablet()) {
|
||||
PreferenceCategory dockbarSettingsPreferenceCategory = (PreferenceCategory) findPreference("dockbarsett");
|
||||
dockbarSettingsPreferenceCategory.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,40 +106,78 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return R.string.vtlthemes;
|
||||
}
|
||||
|
||||
public static class restart implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
restartApplicationWithTimer();
|
||||
return true;
|
||||
}
|
||||
void changeAccent() {
|
||||
final var titles = AndroidUtils.getArray("accent_select_type");
|
||||
new VkAlertDialog.Builder(requireContext())
|
||||
.setTitle(AndroidUtils.getString("change_accent_color"))
|
||||
.setItems(titles, (dialog, which) -> {
|
||||
switch (which) {
|
||||
case 0:
|
||||
showColorPicker();
|
||||
break;
|
||||
case 1:
|
||||
showPalettesDialog();
|
||||
break;
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.reset, (dialog, which) -> {
|
||||
ThemesUtils.setCustomAccentColor(0, false);
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
})
|
||||
.setPositiveButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static class restartlight implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
edit().putString("lighttheme", o.toString()).commit();
|
||||
restartApplicationWithTimer();
|
||||
return false;
|
||||
}
|
||||
void showColorPicker() {
|
||||
final var colorPickerView = new ColorPickerView(requireContext());
|
||||
colorPickerView.setColor(ThemesUtils.getAccentColor());
|
||||
new VkAlertDialog.Builder(requireContext())
|
||||
.setTitle(AndroidUtils.getString("select_color"))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.select, (dialog, which) -> setAccentColor(colorPickerView.getColor()))
|
||||
.setView(colorPickerView)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static class restartdark implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
edit().putString("darktheme", o.toString()).commit();
|
||||
restartApplicationWithTimer();
|
||||
return false;
|
||||
}
|
||||
void showPalettesDialog() {
|
||||
final var manager = PalettesManager.getInstance();
|
||||
final var titles = new String[manager.getPalettesCount()];
|
||||
for (int i = 0; i < titles.length; ++i)
|
||||
titles[i] = manager.getPalette(i).name;
|
||||
new VkAlertDialog.Builder(requireContext())
|
||||
.setTitle(AndroidUtils.getString("select_palette"))
|
||||
.setItems(titles, (dialog, which) ->
|
||||
PalettesBottomSheetDialog.create(requireActivity(), manager.getPalette(which),
|
||||
(adapter, vtlcolor) -> setAccentColor(vtlcolor.color))
|
||||
)
|
||||
.setPositiveButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public class openicons implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(IconsFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
return true;
|
||||
}
|
||||
void setAccentColor(int color) {
|
||||
ThemesUtils.setCustomAccentColor(color, false);
|
||||
ThemesCore.setThemedColors(color);
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
}
|
||||
|
||||
void restart() {
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
}
|
||||
|
||||
void restartLight(String value) {
|
||||
AndroidUtils.edit().putString("lighttheme", value).commit();
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
}
|
||||
|
||||
void restartDark(String value) {
|
||||
AndroidUtils.edit().putString("darktheme", value).commit();
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
}
|
||||
|
||||
private void switchFragment(Class<? extends FragmentImpl> fragmentClz) {
|
||||
var intent = new Navigator(fragmentClz)
|
||||
.b(requireContext())
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
requireContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,36 @@
|
||||
package ru.vtosters.lite.ui.fragments.tgstickers;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static android.widget.Toast.makeText;
|
||||
import static ru.vtosters.lite.tgs.TGPref.setTGBotKey;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.*;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersGrabber;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import ru.vtosters.lite.tgs.TGPref;
|
||||
import ru.vtosters.lite.ui.adapters.StickerPackAdapter;
|
||||
import ru.vtosters.lite.ui.components.StickerTouchHelperCallback;
|
||||
import ru.vtosters.lite.ui.fragments.BaseToolbarFragment;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StickersFragment extends BaseToolbarFragment {
|
||||
public final static String ACTION_RELOAD = "com.vtosters.lite.action.RELOAD_TGS_LIST";
|
||||
@@ -83,8 +68,8 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
@Override
|
||||
protected void onCreateMenu(Menu menu) {
|
||||
var item = menu.add(0, 0, 0, "");
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
item.setIcon(R.drawable.ic_settings_24);
|
||||
item.setIcon(ThemesUtils.recolorDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_settings_24)))
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
super.onCreateMenu(menu);
|
||||
}
|
||||
@@ -97,7 +82,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
|
||||
private void openMenu(String toast) {
|
||||
if (toast != null) {
|
||||
makeText(getContext(), toast, LENGTH_SHORT).show();
|
||||
Toast.makeText(getContext(), toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
var intent = new Navigator(StickersPreferencesFragment.class, new Bundle()).b(getContext());
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -132,12 +117,12 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
|
||||
FloatingActionButton mAddStickerPack = new FloatingActionButton(getContext());
|
||||
mAddStickerPack.setImageResource(R.drawable.ic_add_24);
|
||||
mAddStickerPack.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
mAddStickerPack.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
mAddStickerPack.setOnClickListener(v2 -> fabClick());
|
||||
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2, -2);
|
||||
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
||||
params.setMargins(0, 0, 0, dp2px(12f));
|
||||
params.setMargins(0, 0, 0, AndroidUtils.dp2px(12f));
|
||||
layout.addView(mAddStickerPack, params);
|
||||
|
||||
return layout;
|
||||
@@ -172,13 +157,13 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
|
||||
final EditText editText = new EditText(getContext());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(dp2px(24f), 0, dp2px(24f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(24f), 0, AndroidUtils.dp2px(24f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(getContext())
|
||||
@@ -190,7 +175,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
if (!pack.startsWith("https://")) {
|
||||
pack = "https://" + pack;
|
||||
} else if (!pack.contains("addstickers")) {
|
||||
sendToast(AndroidUtils.getString("invalid_pack_link"));
|
||||
AndroidUtils.sendToast(AndroidUtils.getString("invalid_pack_link"));
|
||||
}
|
||||
pack = parsePack(pack);
|
||||
mService.requestPackDownload(pack, new File(getContext().getFilesDir(), new File("VT-Stickers", pack).getAbsolutePath()));
|
||||
@@ -230,13 +215,13 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
|
||||
final EditText editText = new EditText(getContext());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(dp2px(24f), 0, dp2px(24f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(24f), 0, AndroidUtils.dp2px(24f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(getContext())
|
||||
@@ -244,7 +229,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
.setMessage(requireContext().getString(R.string.stickersapi6))
|
||||
.setView(linearLayout)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
setTGBotKey(editText.getText().toString());
|
||||
TGPref.setTGBotKey(editText.getText().toString());
|
||||
if (r != null) r.run();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
@@ -276,8 +261,8 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
public void onKeyChecked(boolean ok) {
|
||||
progressDialog.dismiss();
|
||||
if (!ok) {
|
||||
makeText(context, requireContext().getString(R.string.stickersapi2), LENGTH_SHORT).show();
|
||||
setTGBotKey(null);
|
||||
Toast.makeText(context, requireContext().getString(R.string.stickersapi2), Toast.LENGTH_SHORT).show();
|
||||
TGPref.setTGBotKey(null);
|
||||
return;
|
||||
}
|
||||
mService.setBotKey(TGPref.getTGBotKey());
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class AlphaView extends SliderViewBase implements ColorObserver {
|
||||
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
|
||||
public AlphaView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void observeColor(ObservableColor observableColor) {
|
||||
this.observableColor = observableColor;
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
setPos((float)observableColor.getAlpha()/0xff);
|
||||
updateBitmap();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyListener(float currentPos) {
|
||||
observableColor.updateAlpha((int)(currentPos * 0xff), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPointerColor(float currentPos) {
|
||||
float solidColorLightness = observableColor.getLightness();
|
||||
float posLightness = 1 + currentPos * (solidColorLightness - 1);
|
||||
return posLightness > 0.5f ? 0xff000000 : 0xffffffff;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap makeBitmap(int w, int h) {
|
||||
final boolean isWide = w > h;
|
||||
final int n = Math.max(w, h);
|
||||
int color = observableColor.getColor();
|
||||
int[] colors = new int[n];
|
||||
for (int i = 0; i < n; ++i) {
|
||||
float alpha = isWide ? (float)i / n : 1 - (float)i / n;
|
||||
colors[i] = color & 0xffffff | (int)(alpha * 0xff) << 24;
|
||||
}
|
||||
final int bmpWidth = isWide ? w : 1;
|
||||
final int bmpHeight = isWide ? 1 : h;
|
||||
return Bitmap.createBitmap(colors, bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
public interface ColorObserver {
|
||||
|
||||
void updateColor(ObservableColor observableColor);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.method.DigitsKeyListener;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
|
||||
public class ColorPickerView extends FrameLayout {
|
||||
|
||||
private AlphaView alphaView;
|
||||
private EditText hexEdit;
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
private SwatchView swatchView;
|
||||
|
||||
public ColorPickerView(Context context) {
|
||||
super(context);
|
||||
|
||||
var container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setPadding(dp2px(16), dp2px(16), dp2px(16), dp2px(16));
|
||||
container.setGravity(Gravity.CENTER);
|
||||
this.addView(container, LayoutUtils.createFrame(-2, -2));
|
||||
|
||||
var colorPickerFrame = new FrameLayout(context);
|
||||
var colorPickerFrameParams = LayoutUtils.createLinear(-2, -2);
|
||||
colorPickerFrameParams.weight = 1.0f;
|
||||
container.addView(colorPickerFrame, colorPickerFrameParams);
|
||||
|
||||
swatchView = new SwatchView(context);
|
||||
colorPickerFrame.addView(swatchView, LayoutUtils.createFrame(-2, -2));
|
||||
|
||||
HueSatView hueSatView = new HueSatView(context);
|
||||
colorPickerFrame.addView(hueSatView, LayoutUtils.createFrame(-2, -2));
|
||||
|
||||
ValueView valueView = new ValueView(context);
|
||||
var valueViewParams = LayoutUtils.createLinear(-1, dp2px(36));
|
||||
valueViewParams.topMargin = dp2px(16);
|
||||
container.addView(valueView, valueViewParams);
|
||||
|
||||
alphaView = new AlphaView(context);
|
||||
var alphaViewParams = LayoutUtils.createLinear(-1, dp2px(36));
|
||||
valueViewParams.topMargin = dp2px(16);
|
||||
container.addView(alphaView, alphaViewParams);
|
||||
|
||||
hexEdit = new EditText(context);
|
||||
hexEdit.setText("00000000");
|
||||
hexEdit.setKeyListener(DigitsKeyListener.getInstance("0123456789ABCDEFabcdef"));
|
||||
hexEdit.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
hexEdit.setFilters(new InputFilter[]{ new InputFilter.LengthFilter(4) });
|
||||
hexEdit.setBackground(null);
|
||||
hexEdit.setTypeface(Typeface.MONOSPACE);
|
||||
hexEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
hexEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
container.addView(hexEdit, LayoutUtils.createLinear(-1, -2));
|
||||
|
||||
swatchView.observeColor(observableColor);
|
||||
hueSatView.observeColor(observableColor);
|
||||
valueView.observeColor(observableColor);
|
||||
alphaView.observeColor(observableColor);
|
||||
HexEdit.setUpListeners(hexEdit, observableColor);
|
||||
|
||||
showAlpha(true);
|
||||
showHex(true);
|
||||
showPreview(true);
|
||||
|
||||
// We get all our state saved and restored for free,
|
||||
// thanks to the EditText and its listeners!
|
||||
}
|
||||
|
||||
/** Returns the color selected by the user */
|
||||
public int getColor() {
|
||||
return observableColor.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the original color swatch and the current color to the specified value.<br>
|
||||
* Using dark colors may lead to a loss of color information caused by the ARGB color space.
|
||||
* Use {@link #setColor(int, float, float, float)} instead to avoid this.
|
||||
*/
|
||||
public void setColor(int color) {
|
||||
setOriginalColor(color);
|
||||
setCurrentColor(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the original color swatch and the current color to the specified value.
|
||||
*
|
||||
* <ul>
|
||||
* <li>Alpha [0...255]</li>
|
||||
* <li>Hue [0...360)</li>
|
||||
* <li>Saturation [0...1]</li>
|
||||
* <li>Brightness [0...1]</li>
|
||||
* </ul>
|
||||
*/ public void setColor(int alpha, float hue, float sat, float bri) {
|
||||
setOriginalColor(alpha, hue, sat, bri);
|
||||
setCurrentColor(alpha, hue, sat, bri);
|
||||
}
|
||||
|
||||
/** Sets the original color swatch without changing the current color. */
|
||||
public void setOriginalColor(int color) {
|
||||
swatchView.setOriginalColor(color);
|
||||
}
|
||||
|
||||
/** Sets the original color swatch without changing the current color. */
|
||||
public void setOriginalColor(int alpha, float hue, float sat, float bri) {
|
||||
int color = Color.HSVToColor(alpha, new float[]{hue, sat, bri});
|
||||
swatchView.setOriginalColor(color);
|
||||
}
|
||||
|
||||
/** Updates the current color without changing the original color swatch. */
|
||||
public void setCurrentColor(int color) {
|
||||
observableColor.updateColor(color, null);
|
||||
}
|
||||
|
||||
/** Updates the current color without changing the original color swatch. */
|
||||
public void setCurrentColor(int alpha, float hue, float sat, float bri) {
|
||||
observableColor.updateColor(alpha, hue, sat, bri, null);
|
||||
}
|
||||
|
||||
public void showAlpha(boolean showAlpha) {
|
||||
alphaView.setVisibility(showAlpha ? View.VISIBLE : View.GONE);
|
||||
HexEdit.setShowAlphaDigits(hexEdit, showAlpha);
|
||||
}
|
||||
|
||||
public void addColorObserver(ColorObserver observer) {
|
||||
observableColor.addObserver(observer);
|
||||
}
|
||||
|
||||
public void showHex(boolean showHex) {
|
||||
hexEdit.setVisibility(showHex ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public void showPreview(boolean showPreview) {
|
||||
swatchView.setVisibility(showPreview ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextWatcher;
|
||||
import android.widget.EditText;
|
||||
|
||||
class HexEdit {
|
||||
|
||||
private static InputFilter[] withoutAlphaDigits = {new ColorPasteLengthFilter()};
|
||||
private static InputFilter[] withAlphaDigits = {new InputFilter.LengthFilter(8)};
|
||||
|
||||
public static void setUpListeners(final EditText hexEdit, final ObservableColor observableColor) {
|
||||
|
||||
class MultiObserver implements ColorObserver, TextWatcher {
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
final String colorString = formatColor(observableColor.getColor());
|
||||
// Prevent onTextChanged getting called when we update text programmatically
|
||||
hexEdit.removeTextChangedListener(this);
|
||||
hexEdit.setText(colorString);
|
||||
hexEdit.addTextChangedListener(this);
|
||||
}
|
||||
|
||||
private String formatColor(int color) {
|
||||
return shouldTrimAlphaDigits()
|
||||
? String.format("%06x", color & 0x00ffffff)
|
||||
: String.format("%08x", color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
int color = parseHexColor(s);
|
||||
if (shouldTrimAlphaDigits()) color = color | 0xff000000;
|
||||
observableColor.updateColor(color, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
private boolean shouldTrimAlphaDigits() {
|
||||
return hexEdit.getFilters() == withoutAlphaDigits;
|
||||
}
|
||||
}
|
||||
|
||||
final MultiObserver multiObserver = new MultiObserver();
|
||||
hexEdit.addTextChangedListener(multiObserver);
|
||||
observableColor.addObserver(multiObserver);
|
||||
setShowAlphaDigits(hexEdit, true);
|
||||
}
|
||||
|
||||
private static int parseHexColor(CharSequence s) {
|
||||
try {
|
||||
return (int)(Long.parseLong(s.toString(), 16) & 0xffffffffL);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return Color.GRAY;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setShowAlphaDigits(final EditText hexEdit, boolean showAlphaDigits) {
|
||||
hexEdit.setFilters(showAlphaDigits ? withAlphaDigits : withoutAlphaDigits);
|
||||
hexEdit.setText(hexEdit.getText()); // trigger a reformat of text
|
||||
}
|
||||
|
||||
|
||||
private static class ColorPasteLengthFilter implements InputFilter {
|
||||
|
||||
private static final int MAX_LENGTH = 6;
|
||||
private static final int PASTED_LEN = 8;
|
||||
private final InputFilter sixDigitFilter = new InputFilter.LengthFilter(MAX_LENGTH);
|
||||
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
// If 8 digits have been pasted, replacing all source, trim alpha digits.
|
||||
// Otherwise standard LengthFilter behavior.
|
||||
final int srcLength = end - start;
|
||||
final int dstSelLength = dend - dstart;
|
||||
if (srcLength == PASTED_LEN && dstSelLength == dest.length()) {
|
||||
// Discard alpha digits:
|
||||
return source.subSequence(PASTED_LEN - MAX_LENGTH, PASTED_LEN);
|
||||
}
|
||||
else {
|
||||
return sixDigitFilter.filter(source, start, end, dest, dstart, dend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class HueSatView extends SquareView implements ColorObserver {
|
||||
|
||||
private Paint borderPaint;
|
||||
private Paint pointerPaint;
|
||||
private Path pointerPath;
|
||||
private Path borderPath;
|
||||
private Rect viewRect = new Rect();
|
||||
private int w;
|
||||
private int h;
|
||||
|
||||
// Bitmap is generated once and shared across instances.
|
||||
private static Bitmap bitmap;
|
||||
|
||||
private final PointF pointer = new PointF();
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
|
||||
public HueSatView(Context context) {
|
||||
super(context);
|
||||
|
||||
borderPaint = Resources.makeLinePaint();
|
||||
pointerPaint = Resources.makeLinePaint();
|
||||
pointerPaint.setColor(0xff000000);
|
||||
pointerPath = Resources.makePointerPath();
|
||||
borderPath = new Path();
|
||||
if (bitmap == null) {
|
||||
bitmap = makeBitmap(optimalBitmapSize());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
// Need clipPath() and setLayerType()...
|
||||
throw new UnsupportedOperationException("Android API 10 and below is not supported.");
|
||||
}
|
||||
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
// clipPath() is only supported on a software layer.
|
||||
setLayerType(LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
}
|
||||
|
||||
private int optimalBitmapSize() {
|
||||
final int scale = 2;
|
||||
final int maxBitmapSize = 128;
|
||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
return Math.min(maxBitmapSize, Math.min(dm.widthPixels, dm.heightPixels) / scale);
|
||||
}
|
||||
|
||||
public void observeColor(ObservableColor observableColor) {
|
||||
this.observableColor = observableColor;
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
setPointer(pointer, observableColor.getHue(), observableColor.getSat(), w);
|
||||
optimisePointerColor();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
viewRect.set(0, 0, w, h);
|
||||
|
||||
float inset = borderPaint.getStrokeWidth() / 2;
|
||||
makeBorderPath(borderPath, w, h, inset);
|
||||
|
||||
// Sets pointer position
|
||||
updateColor(observableColor);
|
||||
}
|
||||
|
||||
private static void makeBorderPath(Path borderPath, int w, int h, float inset) {
|
||||
w -= inset;
|
||||
h -= inset;
|
||||
borderPath.reset();
|
||||
borderPath.moveTo(w, inset);
|
||||
borderPath.lineTo(w, h);
|
||||
borderPath.lineTo(inset, h);
|
||||
borderPath.addArc(new RectF(inset, inset, 2 * w, 2 * h), 180, 270);
|
||||
borderPath.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
boolean withinPicker = clamp(pointer, event.getX(), event.getY(), true);
|
||||
if (withinPicker) update();
|
||||
return withinPicker;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
clamp(pointer, event.getX(), event.getY(), false);
|
||||
update();
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
observableColor.updateHueSat(
|
||||
hueForPos(pointer.x, pointer.y, w),
|
||||
satForPos(pointer.x, pointer.y, w),
|
||||
this);
|
||||
optimisePointerColor();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private boolean clamp(PointF pointer, float x, float y, boolean rejectOutside) {
|
||||
x = Math.min(x, w);
|
||||
y = Math.min(y, h);
|
||||
final float dx = w - x;
|
||||
final float dy = h - y;
|
||||
final float r = (float)Math.sqrt(dx * dx + dy * dy);
|
||||
boolean outside = r > w;
|
||||
if (!outside || !rejectOutside) {
|
||||
if (outside) {
|
||||
x = w - dx * w / r;
|
||||
y = w - dy * w / r;
|
||||
}
|
||||
pointer.set(x, y);
|
||||
}
|
||||
return !outside;
|
||||
}
|
||||
|
||||
private void optimisePointerColor() {
|
||||
pointerPaint.setColor(
|
||||
observableColor.getLightnessWithValue(1) > 0.5
|
||||
? 0xff000000 : 0xffffffff);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
canvas.save();
|
||||
|
||||
canvas.clipPath(borderPath);
|
||||
canvas.drawBitmap(bitmap, null, viewRect, null);
|
||||
canvas.translate(pointer.x, pointer.y);
|
||||
canvas.drawPath(pointerPath, pointerPaint);
|
||||
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawPath(borderPath, borderPaint);
|
||||
}
|
||||
|
||||
private static Bitmap makeBitmap(int radiusPx) {
|
||||
int[] colors = new int[radiusPx * radiusPx];
|
||||
float[] hsv = new float[]{0f, 0f, 1f};
|
||||
for (int y = 0; y < radiusPx; ++y) {
|
||||
for (int x = 0; x < radiusPx; ++x) {
|
||||
final int i = x + y * radiusPx;
|
||||
final float sat = satForPos(x, y, radiusPx);
|
||||
final float arcBleed = 2f / radiusPx; // extend curved edge pixels just outside clip area.
|
||||
if (sat <= 1 + arcBleed) {
|
||||
hsv[0] = hueForPos(x, y, radiusPx);
|
||||
hsv[1] = sat;
|
||||
colors[i] = Color.HSVToColor(0xff, hsv);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(colors, radiusPx, radiusPx, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
private static float hueForPos(float x, float y, float radiusPx) {
|
||||
final double r = radiusPx - 1; // gives values 0...1 inclusive
|
||||
final double dx = (r - x) / r;
|
||||
final double dy = (r - y) / r;
|
||||
final double angle = Math.atan2(dy, dx);
|
||||
final double hue = 360 * angle / (Math.PI / 2);
|
||||
return (float)hue;
|
||||
}
|
||||
|
||||
private static float satForPos(float x, float y, float radiusPx) {
|
||||
final double r = radiusPx - 1; // gives values 0...1 inclusive
|
||||
final double dx = (r - x) / r;
|
||||
final double dy = (r - y) / r;
|
||||
final double sat = dx * dx + dy * dy; // leave it squared -- exaggerates pale colors
|
||||
return (float)sat;
|
||||
}
|
||||
|
||||
private static void setPointer(PointF pointer, float hue, float sat, float radiusPx) {
|
||||
final float r = radiusPx - 1; // for values 0...1 inclusive
|
||||
final double distance = r * Math.sqrt(sat);
|
||||
final double angle = hue / 360 * Math.PI / 2;
|
||||
final double dx = distance * Math.cos(angle);
|
||||
final double dy = distance * Math.sin(angle);
|
||||
pointer.set(r - (float)dx, r - (float)dy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ObservableColor {
|
||||
|
||||
// Store as HSV & A, otherwise round-trip to int causes color drift.
|
||||
private final float[] hsv = {0, 0, 0};
|
||||
private int alpha;
|
||||
private final List<ColorObserver> observers = new ArrayList<ColorObserver>();
|
||||
|
||||
public ObservableColor(int color) {
|
||||
Color.colorToHSV(color, hsv);
|
||||
alpha = Color.alpha(color);
|
||||
}
|
||||
|
||||
public void getHsv(float hsvOut[]) {
|
||||
hsvOut[0] = hsv[0];
|
||||
hsvOut[1] = hsv[1];
|
||||
hsvOut[2] = hsv[2];
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return Color.HSVToColor(alpha, hsv);
|
||||
}
|
||||
|
||||
public float getHue() {
|
||||
return hsv[0];
|
||||
}
|
||||
|
||||
public float getSat() {
|
||||
return hsv[1];
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return hsv[2];
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public float getLightness() {
|
||||
return getLightnessWithValue(hsv[2]);
|
||||
}
|
||||
|
||||
public float getLightnessWithValue(float value) {
|
||||
float[] hsV = {hsv[0], hsv[1], value};
|
||||
final int color = Color.HSVToColor(hsV);
|
||||
return (Color.red(color) * 0.2126f + Color.green(color) * 0.7152f + Color.blue(color) * 0.0722f)/0xff;
|
||||
}
|
||||
|
||||
public void addObserver(ColorObserver observer) {
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void updateHueSat(float hue, float sat, ColorObserver sender) {
|
||||
hsv[0] = hue;
|
||||
hsv[1] = sat;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateValue(float value, ColorObserver sender) {
|
||||
hsv[2] = value;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateAlpha(int alpha, ColorObserver sender) {
|
||||
this.alpha = alpha;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateColor(int color, ColorObserver sender) {
|
||||
Color.colorToHSV(color, hsv);
|
||||
alpha = Color.alpha(color);
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateColor(int alpha, float hue, float sat, float bri, ColorObserver sender) {
|
||||
this.alpha = alpha;
|
||||
hsv[0] = hue;
|
||||
hsv[1] = sat;
|
||||
hsv[2] = bri;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
private void notifyOtherObservers(ColorObserver sender) {
|
||||
for (ColorObserver observer : observers) {
|
||||
if (observer != sender) {
|
||||
observer.updateColor(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Shader;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
class Resources {
|
||||
|
||||
private static final float LINE_WIDTH_DIP = 1.5f;
|
||||
private static final float POINTER_RADIUS_DIP = 7;
|
||||
private static final int VIEW_OUTLINE_COLOR = 0xff808080;
|
||||
|
||||
public static Paint makeLinePaint() {
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(VIEW_OUTLINE_COLOR);
|
||||
paint.setStrokeWidth(dp2px(LINE_WIDTH_DIP));
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setAntiAlias(true);
|
||||
return paint;
|
||||
}
|
||||
|
||||
public static Paint makeCheckerPaint(Context context) {
|
||||
Paint paint = new Paint();
|
||||
final Bitmap checkerBmp = BitmapFactory.decodeResource(context.getResources(), AndroidUtils.getIdentifier("checker_background", "drawable"));
|
||||
paint.setShader(new BitmapShader(checkerBmp, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
|
||||
paint.setStrokeWidth(dp2px(LINE_WIDTH_DIP));
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setAntiAlias(true);
|
||||
return paint;
|
||||
}
|
||||
|
||||
public static Path makePointerPath() {
|
||||
Path pointerPath = new Path();
|
||||
final float radiusPx = dp2px(POINTER_RADIUS_DIP);
|
||||
pointerPath.addCircle(0, 0, radiusPx, Path.Direction.CW);
|
||||
return pointerPath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public abstract class SliderViewBase extends View {
|
||||
|
||||
private final Paint borderPaint;
|
||||
private final Paint checkerPaint;
|
||||
private final Rect viewRect = new Rect();
|
||||
private int w;
|
||||
private int h;
|
||||
private final Path borderPath;
|
||||
private Bitmap bitmap;
|
||||
private final Path pointerPath;
|
||||
private final Paint pointerPaint;
|
||||
|
||||
private float currentPos;
|
||||
|
||||
public SliderViewBase(Context context) {
|
||||
super(context);
|
||||
checkerPaint = Resources.makeCheckerPaint(context);
|
||||
borderPaint = Resources.makeLinePaint();
|
||||
pointerPaint = Resources.makeLinePaint();
|
||||
pointerPath = Resources.makePointerPath();
|
||||
borderPath = new Path();
|
||||
}
|
||||
|
||||
protected abstract void notifyListener(float currentPos);
|
||||
|
||||
protected abstract Bitmap makeBitmap(int w, int h);
|
||||
|
||||
protected abstract int getPointerColor(float currentPos);
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
viewRect.set(0, 0, w, h);
|
||||
float inset = borderPaint.getStrokeWidth() / 2;
|
||||
borderPath.reset();
|
||||
borderPath.addRect(new RectF(inset, inset, w - inset, h - inset), Path.Direction.CW);
|
||||
updateBitmap();
|
||||
}
|
||||
|
||||
protected void setPos(float pos) {
|
||||
currentPos = pos;
|
||||
optimisePointerColor();
|
||||
}
|
||||
|
||||
protected void updateBitmap() {
|
||||
if (w > 0 && h > 0) {
|
||||
bitmap = makeBitmap(w, h);
|
||||
optimisePointerColor();
|
||||
}
|
||||
// else not ready yet
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
currentPos = valueForTouchPos(event.getX(), event.getY());
|
||||
optimisePointerColor();
|
||||
notifyListener(currentPos);
|
||||
invalidate();
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawPath(borderPath, checkerPaint);
|
||||
canvas.drawBitmap(bitmap, null, viewRect, null);
|
||||
canvas.drawPath(borderPath, borderPaint);
|
||||
|
||||
canvas.save();
|
||||
if (isWide()) {
|
||||
canvas.translate(w * currentPos, h / 2);
|
||||
}
|
||||
else {
|
||||
canvas.translate(w / 2, h * (1 - currentPos));
|
||||
}
|
||||
canvas.drawPath(pointerPath, pointerPaint);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
private boolean isWide() {
|
||||
return w > h;
|
||||
}
|
||||
|
||||
private float valueForTouchPos(float x, float y) {
|
||||
final float val = isWide() ? x / w : 1 - y / h;
|
||||
return Math.max(0, Math.min(1, val));
|
||||
}
|
||||
|
||||
private void optimisePointerColor() {
|
||||
pointerPaint.setColor(getPointerColor(currentPos));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
class SquareView extends View {
|
||||
private static final int MIN_SIZE_DIP = 200;
|
||||
|
||||
private final int minSizePx;
|
||||
|
||||
public SquareView(Context context) {
|
||||
super(context);
|
||||
minSizePx = dp2px(MIN_SIZE_DIP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
// Constrain to square
|
||||
final int w = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int h = MeasureSpec.getSize(heightMeasureSpec);
|
||||
final int modeW = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int modeH = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int size = minSizePx;
|
||||
if (modeW == MeasureSpec.UNSPECIFIED) {
|
||||
size = h;
|
||||
}
|
||||
else if (modeH == MeasureSpec.UNSPECIFIED) {
|
||||
size = w;
|
||||
}
|
||||
else {
|
||||
size = Math.min(w, h);
|
||||
}
|
||||
size = Math.max(size, minSizePx);
|
||||
setMeasuredDimension(size, size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class SwatchView extends SquareView implements ColorObserver {
|
||||
|
||||
private final Paint borderPaint;
|
||||
private final Path borderPath;
|
||||
private final Paint checkerPaint;
|
||||
private final Path oldFillPath;
|
||||
private final Path newFillPath;
|
||||
private final Paint oldFillPaint;
|
||||
private final Paint newFillPaint;
|
||||
private final float radialMarginPx;
|
||||
|
||||
public SwatchView(Context context) {
|
||||
super(context);
|
||||
|
||||
radialMarginPx = AndroidUtils.dp2px(16);
|
||||
|
||||
borderPaint = Resources.makeLinePaint();
|
||||
checkerPaint = Resources.makeCheckerPaint(context);
|
||||
oldFillPaint = new Paint();
|
||||
newFillPaint = new Paint();
|
||||
|
||||
borderPath = new Path();
|
||||
oldFillPath = new Path();
|
||||
newFillPath = new Path();
|
||||
}
|
||||
|
||||
void setOriginalColor(int color) {
|
||||
oldFillPaint.setColor(color);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void observeColor(ObservableColor observableColor) {
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
newFillPaint.setColor(observableColor.getColor());
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
// We expect to be stacked behind a square HueSatView and fill the top left corner.
|
||||
|
||||
final float inset = borderPaint.getStrokeWidth() / 2;
|
||||
final float r = Math.min(w, h);
|
||||
|
||||
// Trim the corners of the swatch is where it is radialMarginPx thick.
|
||||
// find how long the outeredges are:
|
||||
final float margin = radialMarginPx;
|
||||
final float diagonal = r + 2 * margin;
|
||||
final float opp = (float)Math.sqrt(diagonal * diagonal - r * r);
|
||||
final float edgeLen = r - opp;
|
||||
|
||||
// Arc angles for drawing CCW
|
||||
final float outerAngle = (float)Math.toDegrees(Math.atan2(opp, r));
|
||||
final float startAngle = 270 - outerAngle;
|
||||
// Sweep angle for each half of the swatch:
|
||||
final float sweepAngle = outerAngle - 45;
|
||||
// Sweep angle for the smooth corners:
|
||||
final float cornerSweepAngle = 90 - outerAngle;
|
||||
|
||||
// Outer border:
|
||||
beginBorder(borderPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
mainArc(borderPath, r, margin, startAngle, 2 * sweepAngle);
|
||||
endBorder(borderPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
|
||||
// Old fill shape:
|
||||
oldFillPath.reset();
|
||||
oldFillPath.moveTo(inset, inset);
|
||||
mainArc(oldFillPath, r, margin, 225, sweepAngle);
|
||||
endBorder(oldFillPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
|
||||
// New fill shape:
|
||||
beginBorder(newFillPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
mainArc(newFillPath, r, margin, startAngle, sweepAngle);
|
||||
newFillPath.lineTo(inset, inset);
|
||||
newFillPath.close();
|
||||
}
|
||||
|
||||
private static void beginBorder(Path path, float inset, float edgeLen, float cornerRadius, float cornerSweepAngle) {
|
||||
path.reset();
|
||||
path.moveTo(inset, inset);
|
||||
cornerArc(path, edgeLen, inset, cornerRadius-inset, 0, cornerSweepAngle);
|
||||
}
|
||||
|
||||
private static void endBorder(Path path, float inset, float edgeLen, float cornerRadius, float cornerSweepAngle) {
|
||||
cornerArc(path, inset, edgeLen, cornerRadius - inset, 90 - cornerSweepAngle, cornerSweepAngle);
|
||||
path.lineTo(inset, inset);
|
||||
path.close();
|
||||
}
|
||||
|
||||
private static void cornerArc(Path path, float cx, float cy, float r, float startAngle, float sweepAngle) {
|
||||
final RectF ovalRect = new RectF(-r, -r, r, r);
|
||||
ovalRect.offset(cx, cy);
|
||||
path.arcTo(ovalRect, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
private static void mainArc(Path path, float viewSize, float margin, float startAngle, float sweepAngle) {
|
||||
float r = viewSize + margin;
|
||||
final RectF ovalRect = new RectF(-r, -r, r, r);
|
||||
ovalRect.offset(viewSize, viewSize);
|
||||
path.arcTo(ovalRect, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawPath(borderPath, checkerPaint);
|
||||
canvas.drawPath(oldFillPath, oldFillPaint);
|
||||
canvas.drawPath(newFillPath, newFillPaint);
|
||||
canvas.drawPath(borderPath, borderPaint);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
public class ValueView extends SliderViewBase implements ColorObserver {
|
||||
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
|
||||
public ValueView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void observeColor(ObservableColor observableColor) {
|
||||
this.observableColor = observableColor;
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
setPos(this.observableColor.getValue());
|
||||
updateBitmap();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyListener(float currentPos) {
|
||||
observableColor.updateValue(currentPos, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPointerColor(float currentPos) {
|
||||
float brightColorLightness = observableColor.getLightness();
|
||||
float posLightness = currentPos * brightColorLightness;
|
||||
return posLightness > 0.5f ? 0xff000000 : 0xffffffff;
|
||||
}
|
||||
|
||||
protected Bitmap makeBitmap(int w, int h) {
|
||||
final boolean isWide = w > h;
|
||||
final int n = Math.max(w, h);
|
||||
int[] colors = new int[n];
|
||||
|
||||
float[] hsv = new float[]{0, 0, 0};
|
||||
observableColor.getHsv(hsv);
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
hsv[2] = isWide ? (float)i / n : 1 - (float)i / n;
|
||||
colors[i] = Color.HSVToColor(hsv);
|
||||
}
|
||||
final int bmpWidth = isWide ? w : 1;
|
||||
final int bmpHeight = isWide ? 1 : h;
|
||||
return Bitmap.createBitmap(colors, bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +1,55 @@
|
||||
package ru.vtosters.lite.ui.vkui;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.vk.core.dialogs.bottomsheet.ModalBottomSheet;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
public class ModalBottomSheetWrapper {
|
||||
public final ModalBottomSheet.a builder;
|
||||
public class ModalBottomSheetWrapper<T> {
|
||||
public final ModalBottomSheet.a mBuilder;
|
||||
public ModalBottomSheet mBottomSheet;
|
||||
|
||||
public ModalBottomSheetWrapper(Activity activity) {
|
||||
builder = new ModalBottomSheet.a(activity);
|
||||
mBuilder = new ModalBottomSheet.a(activity);
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setTitle(String title) {
|
||||
builder.d(title);
|
||||
return this;
|
||||
public T setTitle(String title) {
|
||||
mBuilder.d(title);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
public ModalBottomSheetWrapper setUpdateInfoView(String changelog) {
|
||||
var context = getGlobalContext();
|
||||
var container = new LinearLayout(context);
|
||||
var changelogView = new TextView(context);
|
||||
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
changelogView.setPadding(0, dp2px(8), 0, 0);
|
||||
changelogView.setText(context.getString(R.string.changelog) + ": \n" + changelog);
|
||||
changelogView.setTextColor(getTextAttr());
|
||||
container.addView(changelogView, new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
builder.a(container);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setClickableMessage(
|
||||
public T setClickableMessage(
|
||||
String text,
|
||||
Runnable callback
|
||||
) {
|
||||
builder.a(text, listener -> callback.run());
|
||||
return this;
|
||||
mBuilder.a(text, listener -> callback.run());
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setPositiveButton(
|
||||
public T setPositiveButton(
|
||||
String text,
|
||||
Runnable callback
|
||||
) {
|
||||
builder.a(text, kostil -> callback.run());
|
||||
return this;
|
||||
mBuilder.a(text, kostil -> callback.run());
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setView(View view) {
|
||||
builder.a(view);
|
||||
return this;
|
||||
public T setView(View view) {
|
||||
mBuilder.a(view);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public ModalBottomSheet show() {
|
||||
return builder.a("");
|
||||
public ModalBottomSheet show(String tag) {
|
||||
return mBuilder.a(tag);
|
||||
}
|
||||
|
||||
public ModalBottomSheet show(boolean isCancellable) {
|
||||
var sheet = builder.a("");
|
||||
sheet.setCancelable(isCancellable);
|
||||
return sheet;
|
||||
public ModalBottomSheet show(String tag, boolean isCancellable) {
|
||||
mBottomSheet = mBuilder.a(tag);
|
||||
mBottomSheet.setCancelable(isCancellable);
|
||||
return mBottomSheet;
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mBottomSheet.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class VBottomSheetBuilder {
|
||||
public static void show(Activity activity, VBSContent content) {
|
||||
public static void show(Activity activity, VBSContent content, String tag) {
|
||||
ModalBottomSheetWrapper builder = new ModalBottomSheetWrapper(activity);
|
||||
|
||||
builder.setView(content.view);
|
||||
@@ -20,9 +20,10 @@ public class VBottomSheetBuilder {
|
||||
new Handler(Looper.getMainLooper()).post(content.button.action);
|
||||
}); // Positive
|
||||
|
||||
builder.show(); // Build+Show
|
||||
builder.show(tag); // Build+Show
|
||||
}
|
||||
|
||||
|
||||
public static class VBSContent {
|
||||
public String title;
|
||||
@Nullable
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.MessagesPreviewAdapter;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class WallpaperPreferences extends Preference {
|
||||
|
||||
@@ -49,7 +50,7 @@ public class WallpaperPreferences extends Preference {
|
||||
mRecyclerView = (RecyclerView) preferenceViewHolder.findViewById(R.id.install_btn_container);
|
||||
mRecyclerView.setPadding(0, dp2px(8), 0, 0);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecyclerView.setAdapter((mAdapter = new MessagesPreviewAdapter()));
|
||||
mRecyclerView.setAdapter((mAdapter = new MessagesPreviewAdapter(AndroidUtils.getArray(R.array.wallpaper_change_dialog))));
|
||||
mRecyclerView.setClickable(false);
|
||||
mRecyclerView.setFocusable(false);
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ package ru.vtosters.lite.utils;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/*
|
||||
*Extension of Base64 class for decoding/encoding with flag NO_PADDING
|
||||
*/
|
||||
@@ -14,4 +18,12 @@ public class Base64Utils {
|
||||
public static String encode(String base) {
|
||||
return Base64.encodeToString(base.getBytes(), Base64.NO_PADDING);
|
||||
}
|
||||
|
||||
public static String encodeValue(String value) {
|
||||
try {
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,7 @@ public class IOUtils {
|
||||
|
||||
public static byte[] decodeStream(InputStream encIs, String keyURL) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IOException {
|
||||
CipherInputStream cip = new CipherInputStream(encIs, getCipher(keyURL));
|
||||
var bytes = readAllBytes(cip);
|
||||
cip.close();
|
||||
|
||||
return bytes;
|
||||
return readAllBytes(cip);
|
||||
}
|
||||
|
||||
public static Cipher getCipher(String key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
@@ -49,23 +46,15 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static String readAllLines(File file) throws IOException {
|
||||
var is = new FileInputStream(file);
|
||||
var bytes = readAllBytes(is);
|
||||
is.close();
|
||||
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
return readAllLines(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public static String readAllLines(InputStream is) throws IOException {
|
||||
return new String(readAllBytes(is), StandardCharsets.UTF_8);
|
||||
return new String(readAllBytes(is), "utf-8");
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(File file) throws IOException {
|
||||
var is = new FileInputStream(file);
|
||||
var bytes = readAllBytes(is);
|
||||
is.close();
|
||||
|
||||
return bytes;
|
||||
return readAllBytes(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(InputStream is) throws IOException {
|
||||
@@ -74,11 +63,9 @@ public class IOUtils {
|
||||
int len;
|
||||
while ((len = is.read(buffer)) > 0)
|
||||
bos.write(buffer, 0, len);
|
||||
|
||||
var bytes = bos.toByteArray();
|
||||
is.close();
|
||||
bos.close();
|
||||
|
||||
return bytes;
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
public static void writeToFile(File file, String content) throws IOException {
|
||||
@@ -86,11 +73,35 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static void writeToFile(File file, byte[] content) throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
var fos = new FileOutputStream(file);
|
||||
fos.write(content);
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void copyFileToDirectory(File dest, File targetDir) throws IOException {
|
||||
if (!targetDir.exists())
|
||||
targetDir.mkdirs();
|
||||
var path = dest.getAbsolutePath();
|
||||
var target = new File(targetDir, path.substring(path.lastIndexOf("/")));
|
||||
copyFile(dest, target);
|
||||
}
|
||||
|
||||
public static void copyFile(File dest, File target) throws IOException {
|
||||
var parent = target.getParentFile();
|
||||
if (!parent.exists())
|
||||
parent.getParentFile().mkdirs();
|
||||
writeToFile(target, readAllBytes(dest));
|
||||
}
|
||||
|
||||
public static void copyFile(InputStream is, File target) throws IOException {
|
||||
var parent = target.getParentFile();
|
||||
if (!parent.exists())
|
||||
parent.getParentFile().mkdirs();
|
||||
writeToFile(target, readAllBytes(is));
|
||||
}
|
||||
|
||||
public static void deleteRecursive(File f) {
|
||||
deleteRecursive(f, true);
|
||||
}
|
||||
@@ -98,8 +109,8 @@ public class IOUtils {
|
||||
public static void deleteRecursive(File f, boolean selfDeletion) {
|
||||
if (f.isDirectory()) {
|
||||
var fs = f.listFiles();
|
||||
if (fs != null)
|
||||
for (File child : fs)
|
||||
if (fs != null && fs.length > 0)
|
||||
for (var child : fs)
|
||||
deleteRecursive(child, true);
|
||||
}
|
||||
if (selfDeletion)
|
||||
@@ -107,7 +118,7 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static long getDirSize(File dir) {
|
||||
var arr = dir.listFiles();
|
||||
final var arr = dir.listFiles();
|
||||
if (arr == null || arr.length == 0)
|
||||
return 0;
|
||||
|
||||
@@ -121,4 +132,4 @@ public class IOUtils {
|
||||
public static String getValidFileName(String fileName) {
|
||||
return fileName.replaceAll("[\\\\/:*?\"<>|]", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class RenameTool {
|
||||
fn.setHint(R.string.vk_auth_sign_up_first_name);
|
||||
fn.setTextColor(getTextAttr());
|
||||
fn.setHintTextColor(getSTextAttr());
|
||||
fn.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
fn.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(fn);
|
||||
fn.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) fn.getLayoutParams());
|
||||
@@ -164,7 +164,7 @@ public class RenameTool {
|
||||
ln.setHint(R.string.vk_auth_sign_up_last_name);
|
||||
ln.setTextColor(getTextAttr());
|
||||
ln.setHintTextColor(getSTextAttr());
|
||||
ln.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
ln.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(ln);
|
||||
ln.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ln.setLayoutParams(margin);
|
||||
@@ -235,7 +235,7 @@ public class RenameTool {
|
||||
fn.setHint(R.string.vk_auth_sign_up_first_name);
|
||||
fn.setHintTextColor(getSTextAttr());
|
||||
fn.setTextColor(getTextAttr());
|
||||
fn.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
fn.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(fn);
|
||||
fn.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) fn.getLayoutParams());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isAnyProxyEnabled;
|
||||
import static ru.vtosters.lite.utils.About.getBuildNumber;
|
||||
@@ -17,8 +19,8 @@ public class SSFSUtils {
|
||||
"&secret=" + AccountManagerUtils.getUserSecret() +
|
||||
"&proxy=" + getUserProxy() +
|
||||
"&lang=" + getLocale() +
|
||||
"&vt=1&vksans=" + isVKSansEnabled() +
|
||||
"&vt_version=" + getBuildNumber() +
|
||||
"&vt=1" +
|
||||
"&useragent=" + Base64Utils.encodeValue(Base64Utils.encode(Network.l.c().a())) +
|
||||
"&vt_debug=" + isDEVModEnabled();
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ public class SSFSUtils {
|
||||
|
||||
if (!string.isEmpty()) return string;
|
||||
|
||||
return "https://vtsf.vknext.net";
|
||||
return "https://ssfs.vtosters.app";
|
||||
}
|
||||
|
||||
public static String getDarkVKUI() {
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
import static ru.vtosters.lite.hooks.VKUIHook.isLoaded;
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaper;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getCenterScreenCoords;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getResources;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.getCurrentActivity;
|
||||
import static ru.vtosters.lite.utils.Preferences.color_grishka;
|
||||
import static ru.vtosters.lite.utils.Preferences.dockbar_accent;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.navbar;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import com.vk.articles.preload.WebCachePreloader;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import com.vk.core.preference.Preference;
|
||||
@@ -39,15 +28,16 @@ import com.vk.core.ui.themes.VKTheme;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
import ru.vtosters.lite.hooks.VKUIHook;
|
||||
import ru.vtosters.lite.themes.ThemesHacks;
|
||||
import ru.vtosters.lite.ui.wallpapers.WallpapersHooks;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
import static ru.vtosters.lite.utils.Preferences.*;
|
||||
|
||||
public class ThemesUtils {
|
||||
public static List<String> accentColors = Arrays.asList(
|
||||
"5692d7", "528bcc", "7aa0cc", "518bcc", "6296d0", "2f68aa", "638ebf", "5181b8", "71aaeb", "4774a8", "5baaf4", "4186c8", "add3ff", "4774a8", "718198", "5a9eff", "99a2ad", "74a2d6", "e9eef3", "dfe3e7", "eff1f3", "5c9ce6", "4986cc", "4680c2"
|
||||
);
|
||||
|
||||
public static void applyTheme(VKTheme theme) {
|
||||
var currentActivity = LifecycleUtils.getCurrentActivity();
|
||||
if (currentActivity != null) {
|
||||
@@ -61,6 +51,10 @@ public class ThemesUtils {
|
||||
}
|
||||
} // Apply VKTheme and ImTheme (hard applying without dynamic theme changing)
|
||||
|
||||
public static ColorStateList getAccenedColorStateList() {
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
}
|
||||
|
||||
public static int getSystemModeTheme() {
|
||||
return AppCompatDelegate.getDefaultNightMode();
|
||||
}
|
||||
@@ -71,26 +65,26 @@ public class ThemesUtils {
|
||||
|
||||
public static void setTheme(VKTheme theme, Activity activity) {
|
||||
if (activity == null) {
|
||||
activity = getCurrentActivity();
|
||||
activity = LifecycleUtils.getCurrentActivity();
|
||||
|
||||
if (activity == null) return;
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, getCenterScreenCoords());
|
||||
ThemeTracker.a();
|
||||
isLoaded = false;
|
||||
VKUIHook.isLoaded = false;
|
||||
new WebView(activity).clearCache(true);
|
||||
WebCachePreloader.e();
|
||||
} // apply changed theme
|
||||
|
||||
public static void setThemeFL(VKTheme theme, Activity activity, float[] fl) {
|
||||
if (activity == null) {
|
||||
activity = getCurrentActivity();
|
||||
activity = LifecycleUtils.getCurrentActivity();
|
||||
|
||||
if (activity == null) return;
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, fl);
|
||||
ThemeTracker.a();
|
||||
isLoaded = false;
|
||||
VKUIHook.isLoaded = false;
|
||||
new WebView(activity).clearCache(true);
|
||||
WebCachePreloader.e();
|
||||
}
|
||||
@@ -100,9 +94,108 @@ public class ThemesUtils {
|
||||
}
|
||||
|
||||
public static int getAccentColor() {
|
||||
return getColorFromAttr(R.attr.accent);
|
||||
var accent = AndroidUtils.getPreferences().getInt("accent_color", getColorFromAttr(R.attr.accent));
|
||||
return accent == 0 ? getColorFromAttr(R.attr.accent) : accent;
|
||||
} // Color accent
|
||||
|
||||
public static int getMutedAccentColor() {
|
||||
return getMutedColor(getAccentColor());
|
||||
}
|
||||
|
||||
@SuppressLint("DiscouragedPrivateApi")
|
||||
public static void setCursorColor(EditText view) {
|
||||
try {
|
||||
view.setHighlightColor(ThemesUtils.getMutedAccentColor());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
view.getTextCursorDrawable().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
Field field = TextView.class.getDeclaredField("mCursorDrawableRes");
|
||||
field.setAccessible(true);
|
||||
int drawableResId = field.getInt(view);
|
||||
|
||||
field = TextView.class.getDeclaredField("mEditor");
|
||||
field.setAccessible(true);
|
||||
Object editor = field.get(view);
|
||||
|
||||
if (editor != null) {
|
||||
Drawable drawable = ContextCompat.getDrawable(view.getContext(), drawableResId);
|
||||
drawable.setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
Drawable[] drawables = {drawable, drawable};
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
field = editor.getClass().getDeclaredField("mCursorDrawable");
|
||||
} else {
|
||||
field = editor.getClass().getDeclaredField("mDrawableForCursor");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
field.set(editor, drawables);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
@SuppressLint("DiscouragedPrivateApi")
|
||||
public static void colorHandles(TextView view) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
view.getTextSelectHandle().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
view.getTextSelectHandleRight().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
view.getTextSelectHandleLeft().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
Field editorField = TextView.class.getDeclaredField("mEditor");
|
||||
|
||||
if (!editorField.isAccessible()) editorField.setAccessible(true);
|
||||
|
||||
Object editor = editorField.get(view);
|
||||
|
||||
if (editor != null) {
|
||||
Class<?> editorClass;
|
||||
|
||||
editorClass = editor.getClass();
|
||||
|
||||
String[] handleNames = {"mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter"};
|
||||
String[] resNames = {"mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes"};
|
||||
|
||||
for (int i = 0; i < handleNames.length; i++) {
|
||||
Field handleField = editorClass.getDeclaredField(handleNames[i]);
|
||||
if (!handleField.isAccessible()) {
|
||||
handleField.setAccessible(true);
|
||||
}
|
||||
|
||||
Drawable handleDrawable = (Drawable) handleField.get(editor);
|
||||
|
||||
if (handleDrawable == null) {
|
||||
Field resField = TextView.class.getDeclaredField(resNames[i]);
|
||||
if (!resField.isAccessible()) {
|
||||
resField.setAccessible(true);
|
||||
}
|
||||
int resId = resField.getInt(view);
|
||||
handleDrawable = view.getResources().getDrawable(resId);
|
||||
}
|
||||
|
||||
if (handleDrawable != null) {
|
||||
Drawable drawable = handleDrawable.mutate();
|
||||
drawable.setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
handleField.set(editor, drawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getMutedColor(int color) {
|
||||
return ColorUtils.blendARGB(color, (isDarkTheme() ? Color.BLACK : Color.WHITE), 0.5f);
|
||||
}
|
||||
|
||||
public static void setCustomAccentColor(int newColor, boolean async) {
|
||||
var editor = AndroidUtils.edit().putInt("accent_color", newColor);
|
||||
if (async) editor.apply();
|
||||
else editor.commit();
|
||||
}
|
||||
|
||||
public static int getTextAttr() {
|
||||
return getColorFromAttr(R.attr.text_primary);
|
||||
} // Text Primary color
|
||||
@@ -131,38 +224,12 @@ public class ThemesUtils {
|
||||
return getColorFromAttr(R.attr.header_text);
|
||||
} // Header/Toolbar color text
|
||||
|
||||
public static int getAmoledTheme() {
|
||||
return getIdentifier("BaseAmoledStyle", "style");
|
||||
} // Get Amoled theme id
|
||||
|
||||
public static int picFix() {
|
||||
return getIdentifier("ActionBarThemeFix", "style");
|
||||
} // Fix tabbar color in photo viewer
|
||||
|
||||
public static int getAmoledImTheme() {
|
||||
return getIdentifier("VkIm.Theme.VkApp.Amoled", "style");
|
||||
} // Get Amoled theme id for messages
|
||||
|
||||
public static int getAmoledMeTheme() {
|
||||
return getIdentifier("VkIm.Theme.VkMe.Amoled", "style");
|
||||
} // Get Amoled theme id for messages with rounded msg
|
||||
|
||||
public static int getAttrId(String attr) {
|
||||
return getIdentifier(attr, "attr");
|
||||
}
|
||||
|
||||
public static void setBarTheme(View getview) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
getview.setSystemUiVisibility(getNeededColorNavbar() | getNeededColorStatusbar());
|
||||
}
|
||||
} // Set white/dark statusbar/navbar icons
|
||||
|
||||
public static int getNeededColorStatusbar() {
|
||||
return !isDarkTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 8192 : 0;
|
||||
}
|
||||
|
||||
public static int getNeededColorNavbar() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? isDarkTheme() ? SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0 : 0;
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? isDarkTheme() ? View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0 : 0;
|
||||
}
|
||||
|
||||
public static int getDarkThemeRes() {
|
||||
@@ -197,16 +264,35 @@ public class ThemesUtils {
|
||||
return MilkshakeHelper.e();
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int color) {
|
||||
for (int accent : new int[]{R.color.accent_blue, R.color.azure_A400, R.color.blue, R.color.blue_200, R.color.blue_200_muted, R.color.blue_300, R.color.blue_400, R.color.cool_blue, R.color.cornflower_blue, R.color.cornflower_blue_two, R.color.dot_unread, R.color.fave_promo_btn_pressed, R.color.header_blue, R.color.vkim_ripple_dark, R.color.colorAccent, R.color.light_blue, R.color.light_blue_gray, R.color.live_emoji_butt_hide, R.color.music_action_button_blue, R.color.name, R.color.picker_blue, R.color.picker_blue_pressed, R.color.picker_tab_bg_selected, R.color.picker_tab_text_selected, R.color.sharing_blue_btn_normal, R.color.sharing_blue_btn_pressed, R.color.sky_300, R.color.text_blue, R.color.tip_background, R.color.tw__blue_default, R.color.tw__blue_pressed, R.color.vkim_msg_sending_ic, R.color.vkim_playing_drawable_rect, R.color.white_blue32}) {
|
||||
if (color == accent) return true;
|
||||
}
|
||||
return false;
|
||||
} // Accent colors
|
||||
private static int[] p() {
|
||||
int[] iArr = new int[4];
|
||||
iArr[0] = getColor(isDarkTheme() ? R.color.gray_800 : R.color.white);
|
||||
iArr[1] = getColor(isDarkTheme() ? R.color.switch_disabled_on_dark : R.color.switch_disabled_on_light);
|
||||
iArr[2] = getColor(R.color.gray_20);
|
||||
iArr[3] = getAccentColor();
|
||||
return iArr;
|
||||
}
|
||||
|
||||
public static void themeMonetToolbar(ImageButton imageButton, Toolbar toolbar) {
|
||||
imageButton.setImageTintList(ColorStateList.valueOf(getHeaderText()));
|
||||
toolbar.setElevation(0.0f);
|
||||
private static int[][] f() {
|
||||
return new int[][]{new int[]{-16842910, -16842912}, new int[]{-16842910, 16842912}, new int[]{-16842912}, new int[]{16842912}};
|
||||
}
|
||||
|
||||
private static int[] q() {
|
||||
return new int[]{VKThemeHelper.d(R.attr.loader_track_fill), getMutedAccentColor(), VKThemeHelper.d(R.attr.loader_track_fill), getMutedAccentColor()};
|
||||
}
|
||||
|
||||
public static void setSwitch(SwitchCompat switchCompat) {
|
||||
DrawableCompat.setTintList(DrawableCompat.wrap(switchCompat.getThumbDrawable()), new ColorStateList(f(), p()));
|
||||
DrawableCompat.setTintList(DrawableCompat.wrap(switchCompat.getTrackDrawable()), new ColorStateList(f(), q()));
|
||||
}
|
||||
|
||||
public static void setSwitch(Switch aSwitch) {
|
||||
DrawableCompat.setTintList(DrawableCompat.wrap(aSwitch.getThumbDrawable()), new ColorStateList(f(), p()));
|
||||
DrawableCompat.setTintList(DrawableCompat.wrap(aSwitch.getTrackDrawable()), new ColorStateList(f(), q()));
|
||||
}
|
||||
|
||||
public static void setImageViewColored(ImageView view){
|
||||
view.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
|
||||
public static Drawable recolorDrawable(Drawable drawable) {
|
||||
@@ -214,76 +300,18 @@ public class ThemesUtils {
|
||||
return new RecoloredDrawable(drawable, getAccentColor());
|
||||
} // Recolor drawable to accent color
|
||||
|
||||
public static Drawable recolorVKIconMenu(Drawable drawable) {
|
||||
int accent = getHeaderText();
|
||||
|
||||
public static Drawable recolorToolbarDrawable(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
return new RecoloredDrawable(drawable, (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText());
|
||||
}
|
||||
|
||||
if (isAndroidMonet() || isDarkTheme()) accent = getAccentColor();
|
||||
public static void recolorTextView(TextView tw) {
|
||||
tw.getBackground().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
return new RecoloredDrawable(drawable, accent);
|
||||
} // Recolor vk icon to accent color
|
||||
|
||||
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
if (!isAndroidMonet()) return drawable;
|
||||
|
||||
return new RecoloredDrawable(drawable, getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
if (!isAndroidMonet()) return getResources().getDrawable(drawable);
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
if (!isAndroidMonet()) return colorStateList;
|
||||
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (isColorRefAccented(color) && isAndroidMonet()) {
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = isAccentedColor(unsel);
|
||||
boolean isSelAccent = isAccentedColor(sel);
|
||||
|
||||
if (isUnselAccent || isSelAccent) {
|
||||
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{isSelAccent ? getAccentColor() : sel, isUnselAccent ? getAccentColor() : unsel});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} // Recolor ColorStateList
|
||||
public static void recolorBGView(View view) {
|
||||
view.getBackground().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
public static int darken(int color, float by) {
|
||||
float[] hsl = new float[3];
|
||||
@@ -311,30 +339,8 @@ public class ThemesUtils {
|
||||
return ColorUtils.setAlphaComponent(src, 169);
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
return target != null && isAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
return accentColors.contains(hex(target).toLowerCase());
|
||||
}
|
||||
|
||||
public static int getColor(Context context, int i) {
|
||||
if (isColorRefAccented(i) && isAndroidMonet()) {
|
||||
return getAccentColor();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return context.getColor(i);
|
||||
} else {
|
||||
return context.getResources().getColor(i);
|
||||
}
|
||||
} // Android Support color injector + accent color checker
|
||||
|
||||
public static int getColor2(int i) {
|
||||
if (isColorRefAccented(i) && isAndroidMonet()) {
|
||||
return getAccentColor();
|
||||
}
|
||||
return getResources().getColor(i);
|
||||
public static int getColor(int i) {
|
||||
return ThemesHacks.getHackedColor(getGlobalContext(), i);
|
||||
} // Android Support color injector + accent color checker
|
||||
|
||||
public static int getAlertStyle() {
|
||||
@@ -342,7 +348,7 @@ public class ThemesUtils {
|
||||
}
|
||||
|
||||
public static String getBackgroundStickers() {
|
||||
if (getWallpaper() != null) {
|
||||
if (WallpapersHooks.getWallpaper() != null) {
|
||||
return "images_with_background";
|
||||
}
|
||||
return "images";
|
||||
@@ -384,6 +390,11 @@ public class ThemesUtils {
|
||||
return String.format("#%06X", i & 16777215);
|
||||
} // Get color as hex string
|
||||
|
||||
// hex, but without # at the beginning
|
||||
public static String hexx(int i) {
|
||||
return String.format("%06X", i & 16777215);
|
||||
}
|
||||
|
||||
public static int getNavigationHeight(int Default) {
|
||||
int VKME = R.dimen.design_bottom_sheet_peek_height_min;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user