Java Code Examples for org.telegram.ui.ActionBar.Theme#ThemeInfo

The following examples show how to use org.telegram.ui.ActionBar.Theme#ThemeInfo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setTheme(Theme.ThemeInfo theme, boolean last, boolean first) {
    themeInfo = theme;
    isFirst = first;
    isLast = last;
    accentId = theme.currentAccentId;
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) button.getLayoutParams();
    layoutParams.leftMargin = AndroidUtilities.dp(isFirst ? 22 + 27 : 27);
    button.setLayoutParams(layoutParams);
    placeholderAlpha = 0.0f;

    if (themeInfo.pathToFile != null && !themeInfo.previewParsed) {
        themeInfo.setPreviewInColor(Theme.getDefaultColor(Theme.key_chat_inBubble));
        themeInfo.setPreviewOutColor(Theme.getDefaultColor(Theme.key_chat_outBubble));
        File file = new File(themeInfo.pathToFile);
        boolean fileExists = file.exists();
        boolean parsed = fileExists && parseTheme();
        if ((!parsed || !fileExists) && themeInfo.info != null) {
            if (themeInfo.info.document != null) {
                themeInfo.themeLoaded = false;
                placeholderAlpha = 1.0f;
                loadingDrawable = getResources().getDrawable(R.drawable.msg_theme).mutate();
                Theme.setDrawableColor(loadingDrawable, loadingColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText7));
                if (!fileExists) {
                    String name = FileLoader.getAttachFileName(themeInfo.info.document);
                    if (!loadingThemes.containsKey(name)) {
                        loadingThemes.put(name, themeInfo);
                        FileLoader.getInstance(themeInfo.account).loadFile(themeInfo.info.document, themeInfo.info, 1, 1);
                    }
                }
            } else {
                loadingDrawable = getResources().getDrawable(R.drawable.preview_custom).mutate();
                Theme.setDrawableColor(loadingDrawable, loadingColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText7));
            }
        }
    }
    applyTheme();
}
 
Example 2
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void checkVisibleTheme(Theme.ThemeInfo info) {
    int count = getChildCount();
    for (int a = 0; a < count; a++) {
        View child = getChildAt(a);
        if (child instanceof InnerThemeView) {
            InnerThemeView view = (InnerThemeView) child;
            if (view.themeInfo == info) {
                if (view.parseTheme()) {
                    view.themeInfo.themeLoaded = true;
                    view.applyTheme();
                }
            }
        }
    }
}
 
Example 3
Source File: ChatAttachAlertLocationLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private boolean isActiveThemeDark() {
    Theme.ThemeInfo info = Theme.getActiveTheme();
    if (info.isDark()) {
        return true;
    }
    int color = Theme.getColor(Theme.key_windowBackgroundWhite);
    return AndroidUtilities.computePerceivedBrightness(color) < 0.721f;
}
 
Example 4
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void checkVisibleTheme(Theme.ThemeInfo info) {
    int count = getChildCount();
    for (int a = 0; a < count; a++) {
        View child = getChildAt(a);
        if (child instanceof InnerThemeView) {
            InnerThemeView view = (InnerThemeView) child;
            if (view.themeInfo == info) {
                if (view.parseTheme()) {
                    view.themeInfo.themeLoaded = true;
                    view.applyTheme();
                }
            }
        }
    }
}
 
Example 5
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void selectTheme(Theme.ThemeInfo themeInfo) {
    if (themeInfo.info != null) {
        if (!themeInfo.themeLoaded) {
            return;
        }
        if (themeInfo.info.document == null) {
            presentFragment(new ThemeSetUrlActivity(themeInfo, null, true));
            return;
        }
    }
    if (!TextUtils.isEmpty(themeInfo.assetName)) {
        Theme.PatternsLoader.createLoader(false);
    }
    if (currentType != ThemeActivity.THEME_TYPE_OTHER) {
        SharedPreferences.Editor editor = ApplicationLoader.applicationContext.getSharedPreferences("themeconfig", Activity.MODE_PRIVATE).edit();
        editor.putString(currentType == ThemeActivity.THEME_TYPE_NIGHT || themeInfo.isDark() ? "lastDarkTheme" : "lastDayTheme", themeInfo.getKey());
        editor.commit();
    }
    if (currentType == ThemeActivity.THEME_TYPE_NIGHT) {
        if (themeInfo == Theme.getCurrentNightTheme()) {
            return;
        }
        Theme.setCurrentNightTheme(themeInfo);
    } else {
        if (themeInfo == Theme.getCurrentTheme()) {
            return;
        }
        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needSetDayNightTheme, themeInfo, false, null, -1);
    }
    updateRows();

    int count = getChildCount();
    for (int a = 0; a < count; a++) {
        View child = getChildAt(a);
        if (child instanceof InnerThemeView) {
            ((InnerThemeView) child).updateCurrentThemeCheck();
        }
    }
}
 
Example 6
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    Theme.ThemeInfo t = currentType == ThemeActivity.THEME_TYPE_NIGHT ? Theme.getCurrentNightTheme() : Theme.getCurrentTheme();
    button.setChecked(themeInfo == t, false);
    if (themeInfo != null && themeInfo.info != null && !themeInfo.themeLoaded) {
        String name = FileLoader.getAttachFileName(themeInfo.info.document);
        if (!loadingThemes.containsKey(name) && !loadingWallpapers.containsKey(themeInfo)) {
            themeInfo.themeLoaded = true;
            placeholderAlpha = 0.0f;
            parseTheme();
            applyTheme();
        }
    }
}
 
Example 7
Source File: ThemePreviewActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public ThemePreviewActivity(Theme.ThemeInfo themeInfo, boolean deleteFile, int screenType, boolean edit, boolean night) {
    super();
    this.screenType = screenType;
    nightTheme = night;
    applyingTheme = themeInfo;
    deleteOnCancel = deleteFile;
    editingTheme = edit;

    if (screenType == SCREEN_TYPE_ACCENT_COLOR) {
        accent = applyingTheme.getAccent(!edit);
        useDefaultThemeForButtons = false;
        backupAccentColor = accent.accentColor;
        backupMyMessagesAccentColor = accent.myMessagesAccentColor;
        backupMyMessagesGradientAccentColor = accent.myMessagesGradientAccentColor;
        backupBackgroundOverrideColor = accent.backgroundOverrideColor;
        backupBackgroundGradientOverrideColor = accent.backgroundGradientOverrideColor;
        backupBackgroundRotation = accent.backgroundRotation;
    } else {
        accent = applyingTheme.getAccent(false);
        if (accent != null) {
            selectedPattern = accent.pattern;
        }
    }
    if (accent != null) {
        isMotion = accent.patternMotion;
        if (!TextUtils.isEmpty(accent.patternSlug)) {
            currentIntensity = accent.patternIntensity;
        }
        Theme.applyThemeTemporary(applyingTheme, true);
    }
    NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.goingToPreviewTheme);
}
 
Example 8
Source File: ThemeActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void setTheme(Theme.ThemeInfo themeInfo) {
    if (themeInfo.defaultAccentCount >= 8) {
        colors = new int[]{themeInfo.getAccentColor(6), themeInfo.getAccentColor(4), themeInfo.getAccentColor(7), themeInfo.getAccentColor(2), themeInfo.getAccentColor(0), themeInfo.getAccentColor(5), themeInfo.getAccentColor(3)};
    } else {
        colors = new int[7];
    }
}
 
Example 9
Source File: ThemePreviewActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public ThemePreviewActivity(Theme.ThemeInfo themeInfo, boolean deleteFile, int screenType, boolean edit, boolean night) {
    super();
    this.screenType = screenType;
    nightTheme = night;
    applyingTheme = themeInfo;
    deleteOnCancel = deleteFile;
    editingTheme = edit;

    if (screenType == SCREEN_TYPE_ACCENT_COLOR) {
        accent = applyingTheme.getAccent(!edit);
        useDefaultThemeForButtons = false;
        backupAccentColor = accent.accentColor;
        backupMyMessagesAccentColor = accent.myMessagesAccentColor;
        backupMyMessagesGradientAccentColor = accent.myMessagesGradientAccentColor;
        backupBackgroundOverrideColor = accent.backgroundOverrideColor;
        backupBackgroundGradientOverrideColor = accent.backgroundGradientOverrideColor;
        backupBackgroundRotation = accent.backgroundRotation;
    } else {
        accent = applyingTheme.getAccent(false);
        if (accent != null) {
            selectedPattern = accent.pattern;
        }
    }
    if (accent != null) {
        isMotion = accent.patternMotion;
        if (!TextUtils.isEmpty(accent.patternSlug)) {
            currentIntensity = accent.patternIntensity;
        }
        Theme.applyThemeTemporary(applyingTheme, true);
    }
    NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.goingToPreviewTheme);
}
 
Example 10
Source File: ThemeCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void updateCurrentThemeCheck() {
    Theme.ThemeInfo currentTheme;
    if (isNightTheme) {
        currentTheme = Theme.getCurrentNightTheme();
    } else {
        currentTheme = Theme.getCurrentTheme();
    }
    int newVisibility = currentThemeInfo == currentTheme ? VISIBLE : INVISIBLE;
    if (checkImage.getVisibility() != newVisibility) {
        checkImage.setVisibility(newVisibility);
    }
}
 
Example 11
Source File: ThemePreviewActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public ThemePreviewActivity(Theme.ThemeInfo themeInfo) {
    this(themeInfo, false, SCREEN_TYPE_PREVIEW, false, false);
}
 
Example 12
Source File: ThemePreviewActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public ThemePreviewActivity(Theme.ThemeInfo themeInfo) {
    this(themeInfo, false, SCREEN_TYPE_PREVIEW, false, false);
}
 
Example 13
Source File: ThemePreviewActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public ThemePreviewActivity(File file, Theme.ThemeInfo themeInfo) {
    super();
    swipeBackEnabled = false;
    applyingTheme = themeInfo;
    themeFile = file;
}
 
Example 14
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void updateCurrentThemeCheck() {
    Theme.ThemeInfo t = currentType == ThemeActivity.THEME_TYPE_NIGHT ? Theme.getCurrentNightTheme() : Theme.getCurrentTheme();
    button.setChecked(themeInfo == t, true);
}
 
Example 15
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void updateCurrentThemeCheck() {
    Theme.ThemeInfo t = currentType == ThemeActivity.THEME_TYPE_NIGHT ? Theme.getCurrentNightTheme() : Theme.getCurrentTheme();
    button.setChecked(themeInfo == t, true);
}
 
Example 16
Source File: ThemeCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public Theme.ThemeInfo getCurrentThemeInfo() {
    return currentThemeInfo;
}
 
Example 17
Source File: ThemePreviewActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public ThemePreviewActivity(File file, Theme.ThemeInfo themeInfo) {
    super();
    swipeBackEnabled = false;
    applyingTheme = themeInfo;
    themeFile = file;
}
 
Example 18
Source File: ThemeCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public Theme.ThemeInfo getCurrentThemeInfo() {
    return currentThemeInfo;
}
 
Example 19
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void createThemeCreateDialog(BaseFragment fragment, int type, Theme.ThemeInfo switchToTheme, Theme.ThemeAccent switchToAccent) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    final EditTextBoldCursor editText = new EditTextBoldCursor(context);
    editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("Create", R.string.Create), (dialog, which) -> {

    });

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    final TextView message = new TextView(context);
    if (type != 0) {
        message.setText(AndroidUtilities.replaceTags(LocaleController.getString("EnterThemeNameEdit", R.string.EnterThemeNameEdit)));
    } else {
        message.setText(LocaleController.getString("EnterThemeName", R.string.EnterThemeName));
    }
    message.setTextSize(16);
    message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6));
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    editText.setGravity(Gravity.LEFT | Gravity.TOP);
    editText.setSingleLine(true);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorSize(AndroidUtilities.dp(20));
    editText.setCursorWidth(1.5f);
    editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
    linearLayout.addView(editText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
    editText.setOnEditorActionListener((textView, i, keyEvent) -> {
        AndroidUtilities.hideKeyboard(textView);
        return false;
    });
    editText.setText(generateThemeName(switchToAccent));
    editText.setSelection(editText.length());

    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    }));
    fragment.showDialog(alertDialog);
    editText.requestFocus();
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (fragment.getParentActivity() == null) {
            return;
        }
        if (editText.length() == 0) {
            Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        if (fragment instanceof ThemePreviewActivity) {
            Theme.applyPreviousTheme();
            fragment.finishFragment();
        }
        if (switchToAccent != null) {
            switchToTheme.setCurrentAccentId(switchToAccent.id);
            Theme.refreshThemeColors();
            Utilities.searchQueue.postRunnable(() -> AndroidUtilities.runOnUIThread(() -> processCreate(editText, alertDialog, fragment)));
            return;
        }
        processCreate(editText, alertDialog, fragment);
    });
}
 
Example 20
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
protected void showOptionsForTheme(Theme.ThemeInfo themeInfo) {

    }