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

The following examples show how to use org.telegram.ui.ActionBar.Theme#ThemeAccent . 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: ThemeActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void updateMenuItem() {
    if (menuItem == null) {
        return;
    }
    Theme.ThemeInfo themeInfo = Theme.getCurrentTheme();
    Theme.ThemeAccent accent = themeInfo.getAccent(false);
    if (themeInfo.themeAccents != null && !themeInfo.themeAccents.isEmpty() && accent != null && accent.id >= 100) {
        menuItem.showSubItem(share_theme);
        menuItem.showSubItem(edit_theme);
    } else {
        menuItem.hideSubItem(share_theme);
        menuItem.hideSubItem(edit_theme);
    }
    int fontSize = AndroidUtilities.isTablet() ? 18 : 16;
    Theme.ThemeInfo currentTheme = Theme.getCurrentTheme();
    if (SharedConfig.fontSize != fontSize || SharedConfig.bubbleRadius != 10 || !currentTheme.firstAccentIsDefault || currentTheme.currentAccentId != Theme.DEFALT_THEME_ACCENT_ID) {
        menuItem.showSubItem(reset_settings);
    } else {
        menuItem.hideSubItem(reset_settings);
    }
}
 
Example 2
Source File: ThemeActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void updateMenuItem() {
    if (menuItem == null) {
        return;
    }
    Theme.ThemeInfo themeInfo = Theme.getCurrentTheme();
    Theme.ThemeAccent accent = themeInfo.getAccent(false);
    if (themeInfo.themeAccents != null && !themeInfo.themeAccents.isEmpty() && accent != null && accent.id >= 100) {
        menuItem.showSubItem(share_theme);
        menuItem.showSubItem(edit_theme);
    } else {
        menuItem.hideSubItem(share_theme);
        menuItem.hideSubItem(edit_theme);
    }
    int fontSize = AndroidUtilities.isTablet() ? 18 : 16;
    Theme.ThemeInfo currentTheme = Theme.getCurrentTheme();
    if (SharedConfig.fontSize != fontSize || SharedConfig.bubbleRadius != 10 || !currentTheme.firstAccentIsDefault || currentTheme.currentAccentId != Theme.DEFALT_THEME_ACCENT_ID) {
        menuItem.showSubItem(reset_settings);
    } else {
        menuItem.hideSubItem(reset_settings);
    }
}
 
Example 3
Source File: ThemeSetUrlActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public ThemeSetUrlActivity(Theme.ThemeInfo theme, Theme.ThemeAccent accent, boolean newTheme) {
    super();
    themeInfo = theme;
    themeAccent = accent;
    info = accent != null ? accent.info : theme.info;
    currentAccount = accent != null ? accent.account : theme.account;
    creatingNewTheme = newTheme;
}
 
Example 4
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
void updateColors(boolean animate) {
    oldInColor = inColor;
    oldOutColor = outColor;
    oldBackColor = backColor;
    oldCheckColor = checkColor;

    Theme.ThemeAccent accent = themeInfo.getAccent(false);

    int accentColor;
    int myAccentColor;
    int backAccent;
    if (accent != null) {
        accentColor = accent.accentColor;
        myAccentColor = accent.myMessagesAccentColor != 0 ? accent.myMessagesAccentColor : accentColor;
        int backgroundOverrideColor = (int) accent.backgroundOverrideColor;
        backAccent = backgroundOverrideColor != 0 ? backgroundOverrideColor : accentColor;
    } else {
        accentColor = 0;
        myAccentColor = 0;
        backAccent = 0;
    }
    inColor = Theme.changeColorAccent(themeInfo, accentColor, themeInfo.getPreviewInColor());
    outColor = Theme.changeColorAccent(themeInfo, myAccentColor, themeInfo.getPreviewOutColor());
    backColor = Theme.changeColorAccent(themeInfo, backAccent, themeInfo.getPreviewBackgroundColor());
    checkColor = outColor;
    accentId = themeInfo.currentAccentId;

    if (accentAnimator != null) {
        accentAnimator.cancel();
    }

    if (animate) {
        accentAnimator = ObjectAnimator.ofFloat(this, "accentState", 0f, 1f);
        accentAnimator.setDuration(200);
        accentAnimator.start();
    } else {
        setAccentState(1f);
    }
}
 
Example 5
Source File: ThemeSetUrlActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public ThemeSetUrlActivity(Theme.ThemeInfo theme, Theme.ThemeAccent accent, boolean newTheme) {
    super();
    themeInfo = theme;
    themeAccent = accent;
    info = accent != null ? accent.info : theme.info;
    currentAccount = accent != null ? accent.account : theme.account;
    creatingNewTheme = newTheme;
}
 
Example 6
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
void updateColors(boolean animate) {
    oldInColor = inColor;
    oldOutColor = outColor;
    oldBackColor = backColor;
    oldCheckColor = checkColor;

    Theme.ThemeAccent accent = themeInfo.getAccent(false);

    int accentColor;
    int myAccentColor;
    int backAccent;
    if (accent != null) {
        accentColor = accent.accentColor;
        myAccentColor = accent.myMessagesAccentColor != 0 ? accent.myMessagesAccentColor : accentColor;
        int backgroundOverrideColor = (int) accent.backgroundOverrideColor;
        backAccent = backgroundOverrideColor != 0 ? backgroundOverrideColor : accentColor;
    } else {
        accentColor = 0;
        myAccentColor = 0;
        backAccent = 0;
    }
    inColor = Theme.changeColorAccent(themeInfo, accentColor, themeInfo.getPreviewInColor());
    outColor = Theme.changeColorAccent(themeInfo, myAccentColor, themeInfo.getPreviewOutColor());
    backColor = Theme.changeColorAccent(themeInfo, backAccent, themeInfo.getPreviewBackgroundColor());
    checkColor = outColor;
    accentId = themeInfo.currentAccentId;

    if (accentAnimator != null) {
        accentAnimator.cancel();
    }

    if (animate) {
        accentAnimator = ObjectAnimator.ofFloat(this, "accentState", 0f, 1f);
        accentAnimator.setDuration(200);
        accentAnimator.start();
    } else {
        setAccentState(1f);
    }
}
 
Example 7
Source File: ThemeActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
void setThemeAndColor(Theme.ThemeInfo themeInfo, Theme.ThemeAccent accent) {
    currentTheme = themeInfo;
    currentAccent = accent;
    updateCheckedState(false);
}
 
Example 8
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 9
Source File: ThemeActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
void setThemeAndColor(Theme.ThemeInfo themeInfo, Theme.ThemeAccent accent) {
    currentTheme = themeInfo;
    currentAccent = accent;
    updateCheckedState(false);
}
 
Example 10
Source File: AlertsCreator.java    From Telegram 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);
    });
}