use of androidx.appcompat.widget.SwitchCompat in project ahbottomnavigation by aurelhubert.
the class DemoFragment method initDemoSettings.
/**
* Init demo settings
*/
private void initDemoSettings(View view) {
final DemoActivity demoActivity = (DemoActivity) getActivity();
final SwitchCompat switchColored = view.findViewById(R.id.fragment_demo_switch_colored);
final SwitchCompat switchFiveItems = view.findViewById(R.id.fragment_demo_switch_five_items);
final SwitchCompat showHideBottomNavigation = view.findViewById(R.id.fragment_demo_show_hide);
final SwitchCompat showSelectedBackground = view.findViewById(R.id.fragment_demo_selected_background);
final Spinner spinnerTitleState = view.findViewById(R.id.fragment_demo_title_state);
final SwitchCompat switchTranslucentNavigation = view.findViewById(R.id.fragment_demo_translucent_navigation);
switchColored.setChecked(demoActivity.isBottomNavigationColored());
switchFiveItems.setChecked(demoActivity.getBottomNavigationNbItems() == 5);
switchTranslucentNavigation.setChecked(getActivity().getSharedPreferences("shared", Context.MODE_PRIVATE).getBoolean("translucentNavigation", false));
switchTranslucentNavigation.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? View.VISIBLE : View.GONE);
switchTranslucentNavigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
getActivity().getSharedPreferences("shared", Context.MODE_PRIVATE).edit().putBoolean("translucentNavigation", isChecked).apply();
demoActivity.reload();
}
});
switchColored.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.updateBottomNavigationColor(isChecked);
}
});
switchFiveItems.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.updateBottomNavigationItems(isChecked);
}
});
showHideBottomNavigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.showOrHideBottomNavigation(isChecked);
}
});
showSelectedBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.updateSelectedBackgroundVisibility(isChecked);
}
});
final List<String> titleStates = new ArrayList<>();
for (AHBottomNavigation.TitleState titleState : AHBottomNavigation.TitleState.values()) {
titleStates.add(titleState.toString());
}
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, titleStates);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerTitleState.setAdapter(spinnerAdapter);
spinnerTitleState.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
AHBottomNavigation.TitleState titleState = AHBottomNavigation.TitleState.valueOf(titleStates.get(position));
demoActivity.setTitleState(titleState);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});
}
use of androidx.appcompat.widget.SwitchCompat in project Signal-Android by signalapp.
the class WallpaperCropActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dynamicTheme.onCreate(this);
setContentView(R.layout.chat_wallpaper_crop_activity);
RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
Uri inputImage = Objects.requireNonNull(getIntent().getParcelableExtra(EXTRA_IMAGE_URI));
Log.i(TAG, "Cropping wallpaper for " + (recipientId == null ? "default wallpaper" : recipientId));
WallpaperCropViewModel.Factory factory = new WallpaperCropViewModel.Factory(recipientId);
viewModel = ViewModelProviders.of(this, factory).get(WallpaperCropViewModel.class);
imageEditor = findViewById(R.id.image_editor);
View sentBubble = findViewById(R.id.preview_bubble_2);
TextView bubble2Text = findViewById(R.id.chat_wallpaper_bubble2_text);
View setWallPaper = findViewById(R.id.preview_set_wallpaper);
SwitchCompat blur = findViewById(R.id.preview_blur);
ColorizerView colorizerView = findViewById(R.id.colorizer);
setupImageEditor(inputImage);
setWallPaper.setOnClickListener(v -> setWallpaper());
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar supportActionBar = Objects.requireNonNull(getSupportActionBar());
supportActionBar.setHomeAsUpIndicator(ContextCompat.getDrawable(this, R.drawable.ic_arrow_left_24));
supportActionBar.setDisplayHomeAsUpEnabled(true);
blur.setOnCheckedChangeListener((v, checked) -> viewModel.setBlur(checked));
viewModel.getBlur().observe(this, blurred -> {
setBlurred(blurred);
if (blurred != blur.isChecked()) {
blur.setChecked(blurred);
}
});
viewModel.getRecipient().observe(this, r -> {
if (r.getId().isUnknown()) {
bubble2Text.setText(R.string.WallpaperCropActivity__set_wallpaper_for_all_chats);
} else {
bubble2Text.setText(getString(R.string.WallpaperCropActivity__set_wallpaper_for_s, r.getDisplayName(this)));
sentBubble.getBackground().setColorFilter(r.getChatColors().getChatBubbleColorFilter());
colorizerView.setBackground(r.getChatColors().getChatBubbleMask());
}
});
sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
colorizerView.setProjections(Collections.singletonList(Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(18)))));
});
}
use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsThemeFragment method Bind.
public void Bind() {
final RelativeLayout colorTintModeLayout = (RelativeLayout) context.findViewById(R.id.settings_theme_colorTintMode);
final TextView currentTintTextView = (TextView) context.findViewById(R.id.settings_theme_tint_current);
final SwitchCompat tintEverywhereSwitch = (SwitchCompat) context.findViewById(R.id.settings_theme_tint_everywhere);
final SwitchCompat colorNavbarSwitch = (SwitchCompat) context.findViewById(R.id.settings_theme_colorNavbar);
final SwitchCompat colorIconSwitch = (SwitchCompat) context.findViewById(R.id.settings_theme_colorAppIcon);
back = new ColorPreferences(context).getFontStyle().getThemeType();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * App Theme */
setupSettingsThemePrimary();
setupSettingsThemeAccent();
setupSettingsThemeBase();
setupSettingsThemeNight();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Tinting */
colorTintModeLayout.setOnClickListener(v -> {
final PopupMenu popup = new PopupMenu(context, v);
popup.getMenuInflater().inflate(R.menu.color_tinting_mode_settings, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.none:
setTintingMode(false, false);
break;
case R.id.background:
setTintingMode(true, false);
break;
case R.id.name:
setTintingMode(true, true);
break;
}
currentTintTextView.setText(SettingValues.colorBack ? SettingValues.colorSubName ? context.getString(R.string.subreddit_name_tint) : context.getString(R.string.card_background_tint) : context.getString(R.string.misc_none));
boolean enabled = !currentTintTextView.getText().equals(context.getString(R.string.misc_none));
tintEverywhereSwitch.setEnabled(enabled);
tintEverywhereSwitch.setChecked(SettingValues.colorEverywhere);
tintEverywhereSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.colorEverywhere = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLOR_EVERYWHERE, isChecked);
});
return true;
});
popup.show();
});
// Color tinting mode
currentTintTextView.setText(SettingValues.colorBack ? SettingValues.colorSubName ? context.getString(R.string.subreddit_name_tint) : context.getString(R.string.card_background_tint) : context.getString(R.string.misc_none));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boolean enabled = !currentTintTextView.getText().equals(context.getString(R.string.misc_none));
tintEverywhereSwitch.setEnabled(enabled);
tintEverywhereSwitch.setChecked(SettingValues.colorEverywhere);
tintEverywhereSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.colorEverywhere = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLOR_EVERYWHERE, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
colorNavbarSwitch.setChecked(SettingValues.colorNavBar);
colorNavbarSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsThemeFragment.changed = true;
SettingValues.colorNavBar = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLOR_NAV_BAR, isChecked);
context.themeSystemBars("");
if (!isChecked) {
context.getWindow().setNavigationBarColor(Color.TRANSPARENT);
}
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
colorIconSwitch.setChecked(SettingValues.colorIcon);
colorIconSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.colorIcon = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLOR_ICON, isChecked);
if (isChecked) {
setComponentState(Slide.class.getPackage().getName() + ".Slide", PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
setComponentState(ColorPreferences.getIconName(context, Reddit.colors.getInt("DEFAULTCOLOR", 0)), PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
} else {
setComponentState(ColorPreferences.getIconName(context, Reddit.colors.getInt("DEFAULTCOLOR", 0)), PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
setComponentState(Slide.class.getPackage().getName() + ".Slide", PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}
});
}
use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsSubAdapter method showSubThemeEditor.
/**
* Displays the subreddit color chooser
* It is possible to color multiple subreddits at the same time
*
* @param subreddits Subreddits as an array
* @param context Context for getting colors
* @param dialoglayout The subchooser layout (R.layout.colorsub)
*/
public static void showSubThemeEditor(final ArrayList<String> subreddits, final Activity context, View dialoglayout) {
if (subreddits.isEmpty()) {
return;
}
final boolean multipleSubs = (subreddits.size() > 1);
boolean isAlternateLayout;
int currentColor;
int currentAccentColor;
final ColorPreferences colorPrefs = new ColorPreferences(context);
final String subreddit = multipleSubs ? null : subreddits.get(0);
final SwitchCompat bigPics = dialoglayout.findViewById(R.id.bigpics);
final SwitchCompat selftext = dialoglayout.findViewById(R.id.selftext);
// Selected multiple subreddits
if (multipleSubs) {
// Check if all selected subs have the same settings
int previousSubColor = 0;
int previousSubAccent = 0;
bigPics.setChecked(SettingValues.bigPicEnabled);
selftext.setChecked(SettingValues.cardText);
boolean sameMainColor = true;
boolean sameAccentColor = true;
for (String sub : subreddits) {
int currentSubColor = Palette.getColor(sub);
int currentSubAccent = colorPrefs.getColor("");
if (previousSubColor != 0 && previousSubAccent != 0) {
if (currentSubColor != previousSubColor) {
sameMainColor = false;
} else if (currentSubAccent != previousSubAccent) {
sameAccentColor = false;
}
}
if (!sameMainColor && !sameAccentColor) {
break;
}
previousSubAccent = currentSubAccent;
previousSubColor = currentSubColor;
}
currentColor = Palette.getDefaultColor();
currentAccentColor = colorPrefs.getColor("");
isAlternateLayout = false;
// If all selected subs have the same settings, display them
if (sameMainColor) {
currentColor = previousSubColor;
}
if (sameAccentColor) {
currentAccentColor = previousSubAccent;
}
} else {
// Is only one selected sub
currentColor = Palette.getColor(subreddit);
isAlternateLayout = SettingValues.prefs.contains(Reddit.PREF_LAYOUT + subreddit);
currentAccentColor = colorPrefs.getColor(subreddit);
bigPics.setChecked(SettingValues.isPicsEnabled(subreddit));
selftext.setChecked(SettingValues.isSelftextEnabled(subreddit));
}
final TextView title = dialoglayout.findViewById(R.id.title);
title.setBackgroundColor(currentColor);
if (multipleSubs) {
StringBuilder titleStringBuilder = new StringBuilder();
for (String sub : subreddits) {
// if the subreddit is the frontpage, don't put "/r/" in front of it
if (sub.equals("frontpage")) {
titleStringBuilder.append(sub).append(", ");
} else {
if (sub.contains("/m/")) {
titleStringBuilder.append(sub).append(", ");
} else {
titleStringBuilder.append("/r/").append(sub).append(", ");
}
}
}
String titleString = titleStringBuilder.toString();
titleString = titleString.substring(0, titleString.length() - 2);
title.setMaxLines(3);
title.setText(titleString);
} else {
if (subreddit.contains("/m/")) {
title.setText(subreddit);
} else {
// if the subreddit is the frontpage, don't put "/r/" in front of it
title.setText(((subreddit.equals("frontpage")) ? "frontpage" : "/r/" + subreddit));
}
}
{
// Primary color pickers
final LineColorPicker colorPickerPrimary = dialoglayout.findViewById(R.id.picker);
// shades of primary colors
final LineColorPicker colorPickerPrimaryShades = dialoglayout.findViewById(R.id.picker2);
colorPickerPrimary.setColors(ColorPreferences.getBaseColors(context));
// Iterate through all colors and check if it matches the current color of the sub, then select it
for (int i : colorPickerPrimary.getColors()) {
for (int i2 : ColorPreferences.getColors(context, i)) {
if (i2 == currentColor) {
colorPickerPrimary.setSelectedColor(i);
colorPickerPrimaryShades.setColors(ColorPreferences.getColors(context, i));
colorPickerPrimaryShades.setSelectedColor(i2);
break;
}
}
}
// Base color changed
colorPickerPrimary.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int c) {
// Show variations of the base color
colorPickerPrimaryShades.setColors(ColorPreferences.getColors(context, c));
colorPickerPrimaryShades.setSelectedColor(c);
}
});
colorPickerPrimaryShades.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int i) {
if (context instanceof MainActivity) {
((MainActivity) context).updateColor(colorPickerPrimaryShades.getColor(), subreddit);
}
title.setBackgroundColor(colorPickerPrimaryShades.getColor());
}
});
{
/* TODO TextView dialogButton = (TextView) dialoglayout.findViewById(R.id.reset);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Palette.removeColor(subreddit);
hea.setBackgroundColor(Palette.getDefaultColor());
findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.setStatusBarColor(Palette.getDarkerColor(Palette.getDefaultColor()));
context.setTaskDescription(new ActivityManager.TaskDescription(subreddit, ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_launcher)).getBitmap(), colorPicker2.getColor()));
}
title.setBackgroundColor(Palette.getDefaultColor());
int cx = center.getWidth() / 2;
int cy = center.getHeight() / 2;
int initialRadius = body.getWidth();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Animator anim =
ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
body.setVisibility(View.GONE);
}
});
anim.start();
} else {
body.setVisibility(View.GONE);
}
}
});*/
}
// Accent color picker
final LineColorPicker colorPickerAcc = dialoglayout.findViewById(R.id.picker3);
{
// Get all possible accent colors (for day theme)
int[] arrs = new int[ColorPreferences.getNumColorsFromThemeType(0)];
int i = 0;
for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
if (type.getThemeType() == ColorPreferences.ColorThemeOptions.Dark.getValue()) {
arrs[i] = ContextCompat.getColor(context, type.getColor());
i++;
}
colorPickerAcc.setColors(arrs);
colorPickerAcc.setSelectedColor(currentAccentColor);
}
}
new AlertDialog.Builder(context).setView(dialoglayout).setCancelable(false).setNegativeButton(R.string.btn_cancel, (dialog, which) -> {
if (context instanceof MainActivity) {
((MainActivity) context).updateColor(Palette.getColor(subreddit), subreddit);
}
}).setNeutralButton(R.string.btn_reset, (dialog, which) -> {
String subTitles;
if (multipleSubs) {
StringBuilder subTitlesBuilder = new StringBuilder();
for (String sub : subreddits) {
// if the subreddit is the frontpage, don't put "/r/" in front of it
if (sub.equals("frontpage")) {
subTitlesBuilder.append(sub).append(", ");
} else {
subTitlesBuilder.append("/r/").append(sub).append(", ");
}
}
subTitles = subTitlesBuilder.toString();
subTitles = subTitles.substring(0, subTitles.length() - 2);
} else {
// if the subreddit is the frontpage, don't put "/r/" in front of it
subTitles = (subreddit.equals("frontpage") ? "frontpage" : "/r/" + subreddit);
}
String titleStart = context.getString(R.string.settings_delete_sub_settings, subTitles);
titleStart = titleStart.replace("/r//r/", "/r/");
if (titleStart.contains("/r/frontpage")) {
titleStart = titleStart.replace("/r/frontpage", "frontpage");
}
new AlertDialog.Builder(context).setTitle(titleStart).setPositiveButton(R.string.btn_yes, (dialog1, which1) -> {
for (String sub : subreddits) {
Palette.removeColor(sub);
// Remove layout settings
SettingValues.prefs.edit().remove(Reddit.PREF_LAYOUT + sub).apply();
// Remove accent / font color settings
new ColorPreferences(context).removeFontStyle(sub);
SettingValues.resetPicsEnabled(sub);
SettingValues.resetSelftextEnabled(sub);
}
if (context instanceof MainActivity) {
((MainActivity) context).reloadSubs();
} else if (context instanceof SettingsSubreddit) {
((SettingsSubreddit) context).reloadSubList();
} else if (context instanceof SubredditView) {
((SubredditView) context).restartTheme();
}
}).setNegativeButton(R.string.btn_no, null).show();
}).setPositiveButton(R.string.btn_ok, (dialog, which) -> {
final int newPrimaryColor = colorPickerPrimaryShades.getColor();
final int newAccentColor = colorPickerAcc.getColor();
for (String sub : subreddits) {
// Set main color
if (bigPics.isChecked() != SettingValues.isPicsEnabled(sub)) {
SettingValues.setPicsEnabled(sub, bigPics.isChecked());
}
if (selftext.isChecked() != SettingValues.isSelftextEnabled(sub)) {
SettingValues.setSelftextEnabled(sub, selftext.isChecked());
}
// Only do set colors if either subreddit theme color has changed
if (Palette.getColor(sub) != newPrimaryColor || Palette.getDarkerColor(sub) != newAccentColor) {
if (newPrimaryColor != Palette.getDefaultColor()) {
Palette.setColor(sub, newPrimaryColor);
} else {
Palette.removeColor(sub);
}
// Set accent color
ColorPreferences.Theme t = null;
// Do not save accent color if it matches the default accent color
if (newAccentColor != ContextCompat.getColor(context, colorPrefs.getFontStyle().getColor()) || newAccentColor != ContextCompat.getColor(context, colorPrefs.getFontStyleSubreddit(sub).getColor())) {
LogUtil.v("Accent colors not equal");
int back = new ColorPreferences(context).getFontStyle().getThemeType();
for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
if (ContextCompat.getColor(context, type.getColor()) == newAccentColor && back == type.getThemeType()) {
t = type;
LogUtil.v("Setting accent color to " + t.getTitle());
break;
}
}
} else {
new ColorPreferences(context).removeFontStyle(sub);
}
if (t != null) {
colorPrefs.setFontStyle(t, sub);
}
}
// Set layout
SettingValues.prefs.edit().putBoolean(Reddit.PREF_LAYOUT + sub, true).apply();
}
// Only refresh stuff if the user changed something
if (Palette.getColor(subreddit) != newPrimaryColor || Palette.getDarkerColor(subreddit) != newAccentColor) {
if (context instanceof MainActivity) {
((MainActivity) context).reloadSubs();
} else if (context instanceof SettingsSubreddit) {
((SettingsSubreddit) context).reloadSubList();
} else if (context instanceof SubredditView) {
((SubredditView) context).restartTheme();
}
}
}).show();
}
}
use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsFontFragment method Bind.
public void Bind() {
final SwitchCompat fontEnlargeLinksSwitch = context.findViewById(R.id.settings_font_enlarge_links);
final SwitchCompat fontLinkTypeSwitch = context.findViewById(R.id.settings_font_linktype);
final LinearLayout fontCommentFontSizeLayout = context.findViewById(R.id.settings_font_commentfontsize);
final TextView fontCommentFontView = context.findViewById(R.id.settings_font_commentFont);
final RobotoRadioButton fontCommentStyleRegularButton = context.findViewById(R.id.settings_font_creg);
final RobotoRadioButton fontCommentStyleSlabButton = context.findViewById(R.id.settings_font_cslab);
final RobotoRadioButton fontCommentStyleCondensedButton = context.findViewById(R.id.settings_font_ccond);
final RobotoRadioButton fontCommentStyleLightButton = context.findViewById(R.id.settings_font_clight);
final RobotoRadioButton fontCommentStyleSystemButton = context.findViewById(R.id.settings_font_cnone);
final LinearLayout fontPostFontSizeLayout = context.findViewById(R.id.settings_font_postfontsize);
final TextView fontPostFontView = context.findViewById(R.id.settings_font_postFont);
final RobotoRadioButton fontPostStyleRegularButton = context.findViewById(R.id.settings_font_sreg);
final RobotoRadioButton fontPostStyleBoldButton = context.findViewById(R.id.settings_font_sbold);
final RobotoRadioButton fontPostStyleMediumButton = context.findViewById(R.id.settings_font_smed);
final RobotoRadioButton fontPostStyleLightButton = context.findViewById(R.id.settings_font_slight);
final RobotoRadioButton fontPostStyleSlabButton = context.findViewById(R.id.settings_font_sslab);
final RobotoRadioButton fontPostStyleSlabLightButton = context.findViewById(R.id.settings_font_sslabl);
final RobotoRadioButton fontPostStyleCondensedButton = context.findViewById(R.id.settings_font_scond);
final RobotoRadioButton fontPostStyleCondensedLightButton = context.findViewById(R.id.settings_font_scondl);
final RobotoRadioButton fontPostStyleCondensedBoldButton = context.findViewById(R.id.settings_font_scondb);
final RobotoRadioButton fontPostStyleSystemButton = context.findViewById(R.id.settings_font_snone);
final FontPreferences newFontPrefs = new FontPreferences(context);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Links */
fontEnlargeLinksSwitch.setChecked(SettingValues.largeLinks);
fontEnlargeLinksSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.largeLinks = isChecked;
editSharedBooleanPreference(SettingValues.PREF_LARGE_LINKS, isChecked);
});
fontLinkTypeSwitch.setChecked(SettingValues.typeInText);
fontLinkTypeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.typeInText = isChecked;
editSharedBooleanPreference(SettingValues.PREF_TYPE_IN_TEXT, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Font styles */
fontCommentFontSizeLayout.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, v);
Menu getPopupMenu = popup.getMenu();
getPopupMenu.add(0, R.string.font_size_huge, 0, R.string.font_size_huge);
getPopupMenu.add(0, R.string.font_size_larger, 0, R.string.font_size_larger);
getPopupMenu.add(0, R.string.font_size_large, 0, R.string.font_size_large);
getPopupMenu.add(0, R.string.font_size_medium, 0, R.string.font_size_medium);
getPopupMenu.add(0, R.string.font_size_small, 0, R.string.font_size_small);
getPopupMenu.add(0, R.string.font_size_smaller, 0, R.string.font_size_smaller);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(item -> {
newFontPrefs.setCommentFontStyle(FontPreferences.FontStyleComment.valueOf(getFontName(item.getItemId())));
fontCommentFontView.setText(newFontPrefs.getCommentFontStyle().getTitle());
SettingsThemeFragment.changed = true;
return true;
});
popup.show();
});
fontCommentFontView.setText(newFontPrefs.getCommentFontStyle().getTitle());
switch(newFontPrefs.getFontTypeComment()) {
case Regular:
fontCommentStyleRegularButton.setChecked(true);
break;
case Slab:
fontCommentStyleSlabButton.setChecked(true);
break;
case Condensed:
fontCommentStyleCondensedButton.setChecked(true);
break;
case Light:
fontCommentStyleLightButton.setChecked(true);
break;
case System:
fontCommentStyleSystemButton.setChecked(true);
break;
}
setCommentFontTypeListener(newFontPrefs, fontCommentStyleRegularButton, FontTypeComment.Regular);
setCommentFontTypeListener(newFontPrefs, fontCommentStyleSlabButton, FontTypeComment.Slab);
setCommentFontTypeListener(newFontPrefs, fontCommentStyleCondensedButton, FontTypeComment.Condensed);
setCommentFontTypeListener(newFontPrefs, fontCommentStyleLightButton, FontTypeComment.Light);
setCommentFontTypeListener(newFontPrefs, fontCommentStyleSystemButton, FontTypeComment.System);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fontPostFontSizeLayout.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, v);
Menu getPopupMenu = popup.getMenu();
getPopupMenu.add(0, R.string.font_size_huge, 0, R.string.font_size_huge);
getPopupMenu.add(0, R.string.font_size_larger, 0, R.string.font_size_larger);
getPopupMenu.add(0, R.string.font_size_large, 0, R.string.font_size_large);
getPopupMenu.add(0, R.string.font_size_medium, 0, R.string.font_size_medium);
getPopupMenu.add(0, R.string.font_size_small, 0, R.string.font_size_small);
getPopupMenu.add(0, R.string.font_size_smaller, 0, R.string.font_size_smaller);
getPopupMenu.add(0, R.string.font_size_tiny, 0, R.string.font_size_tiny);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(item -> {
newFontPrefs.setPostFontStyle(FontPreferences.FontStyle.valueOf(getFontName(item.getItemId())));
fontPostFontView.setText(newFontPrefs.getPostFontStyle().getTitle());
SettingsThemeFragment.changed = true;
return true;
});
popup.show();
});
fontPostFontView.setText(newFontPrefs.getPostFontStyle().getTitle());
switch(newFontPrefs.getFontTypeTitle()) {
case Regular:
fontPostStyleRegularButton.setChecked(true);
break;
case Bold:
fontPostStyleBoldButton.setChecked(true);
break;
case Medium:
fontPostStyleMediumButton.setChecked(true);
break;
case Light:
fontPostStyleLightButton.setChecked(true);
break;
case SlabRegular:
fontPostStyleSlabButton.setChecked(true);
break;
case SlabLight:
fontPostStyleSlabLightButton.setChecked(true);
break;
case CondensedRegular:
fontPostStyleCondensedButton.setChecked(true);
break;
case CondensedLight:
fontPostStyleCondensedLightButton.setChecked(true);
break;
case CondensedBold:
fontPostStyleCondensedBoldButton.setChecked(true);
break;
case System:
fontPostStyleSystemButton.setChecked(true);
break;
}
setTitleFontTypeListener(newFontPrefs, fontPostStyleRegularButton, FontTypeTitle.Regular);
setTitleFontTypeListener(newFontPrefs, fontPostStyleBoldButton, FontTypeTitle.Bold);
setTitleFontTypeListener(newFontPrefs, fontPostStyleMediumButton, FontTypeTitle.Medium);
setTitleFontTypeListener(newFontPrefs, fontPostStyleLightButton, FontTypeTitle.Light);
setTitleFontTypeListener(newFontPrefs, fontPostStyleSlabButton, FontTypeTitle.SlabRegular);
setTitleFontTypeListener(newFontPrefs, fontPostStyleSlabLightButton, FontTypeTitle.SlabLight);
setTitleFontTypeListener(newFontPrefs, fontPostStyleCondensedButton, FontTypeTitle.CondensedRegular);
setTitleFontTypeListener(newFontPrefs, fontPostStyleCondensedLightButton, FontTypeTitle.CondensedLight);
setTitleFontTypeListener(newFontPrefs, fontPostStyleCondensedBoldButton, FontTypeTitle.CondensedBold);
setTitleFontTypeListener(newFontPrefs, fontPostStyleSystemButton, FontTypeTitle.System);
}
Aggregations