use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsRedditFragment method Bind.
public void Bind() {
final SwitchCompat wantToSeeNsfwSwitch = context.findViewById(R.id.settings_reddit_wantToSeeNsfwContent);
final SwitchCompat hideAllNsfwSwitch = context.findViewById(R.id.settings_reddit_hideAllNsfw);
final TextView hideAllNsfwText = context.findViewById(R.id.settings_reddit_hideAllNsfw_text);
final SwitchCompat hideNsfwPrevCollectionsSwitch = context.findViewById(R.id.settings_reddit_hideNsfwPreviewCollections);
final TextView hideNsfwPrevCollectionsText = context.findViewById(R.id.settings_reddit_hideNsfwPreviewCollections_text);
final SwitchCompat ignoreSubMediaPrefsSwitch = context.findViewById(R.id.settings_reddit_ignoreSubMediaPrefs);
final RelativeLayout viewRedditPrefsLayout = context.findViewById(R.id.settings_reddit_viewRedditPrefs);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * NSFW Content */
wantToSeeNsfwSwitch.setChecked(SettingValues.showNSFWContent);
wantToSeeNsfwSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.showNSFWContent = isChecked;
SettingsActivity.changed = true;
if (isChecked) {
hideAllNsfwSwitch.setEnabled(true);
hideAllNsfwText.setAlpha(1f);
hideAllNsfwSwitch.setChecked(SettingValues.getIsNSFWEnabled());
hideNsfwPrevCollectionsSwitch.setEnabled(true);
hideNsfwPrevCollectionsText.setAlpha(1f);
hideNsfwPrevCollectionsSwitch.setChecked(SettingValues.hideNSFWCollection);
} else {
hideAllNsfwSwitch.setChecked(false);
hideAllNsfwSwitch.setEnabled(false);
hideAllNsfwText.setAlpha(0.25f);
hideNsfwPrevCollectionsSwitch.setChecked(false);
hideNsfwPrevCollectionsSwitch.setEnabled(false);
hideNsfwPrevCollectionsText.setAlpha(0.25f);
}
editSharedBooleanPreference(SettingValues.PREF_SHOW_NSFW_CONTENT, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (!wantToSeeNsfwSwitch.isChecked()) {
hideAllNsfwSwitch.setChecked(true);
hideAllNsfwSwitch.setEnabled(false);
hideAllNsfwText.setAlpha(0.25f);
} else {
hideAllNsfwSwitch.setChecked(SettingValues.getIsNSFWEnabled());
}
hideAllNsfwSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsActivity.changed = true;
editSharedBooleanPreference(SettingValues.PREF_HIDE_NSFW_PREVIEW + Authentication.name, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (!wantToSeeNsfwSwitch.isChecked()) {
hideNsfwPrevCollectionsSwitch.setChecked(true);
hideNsfwPrevCollectionsSwitch.setEnabled(false);
hideNsfwPrevCollectionsText.setAlpha(0.25f);
} else {
hideNsfwPrevCollectionsSwitch.setChecked(SettingValues.hideNSFWCollection);
}
hideNsfwPrevCollectionsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsActivity.changed = true;
SettingValues.hideNSFWCollection = isChecked;
editSharedBooleanPreference(SettingValues.PREF_HIDE_NSFW_COLLECTION, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ignoreSubMediaPrefsSwitch.setChecked(SettingValues.ignoreSubSetting);
ignoreSubMediaPrefsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsActivity.changed = true;
SettingValues.ignoreSubSetting = isChecked;
editSharedBooleanPreference(SettingValues.PREF_IGNORE_SUB_SETTINGS, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Open Reddit settings in browser */
viewRedditPrefsLayout.setOnClickListener(v -> LinkUtil.openUrl("https://www.reddit.com/prefs/", Palette.getDefaultColor(), context));
}
use of androidx.appcompat.widget.SwitchCompat in project Signal-Android by signalapp.
the class ChatWallpaperFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
AvatarImageView portrait = view.findViewById(R.id.chat_wallpaper_preview_top_bar_portrait);
Toolbar toolbar = view.findViewById(R.id.toolbar);
ImageView chatWallpaperPreview = view.findViewById(R.id.chat_wallpaper_preview_background);
View setWallpaper = view.findViewById(R.id.chat_wallpaper_set_wallpaper);
SwitchCompat dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
View chatWallpaperDim = view.findViewById(R.id.chat_wallpaper_dim);
TextView setChatColor = view.findViewById(R.id.chat_wallpaper_set_chat_color);
TextView resetChatColors = view.findViewById(R.id.chat_wallpaper_reset_chat_colors);
ImageView sentBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_2);
ColorizerView colorizerView = view.findViewById(R.id.colorizer);
TextView resetAllWallpaper = view.findViewById(R.id.chat_wallpaper_reset_all_wallpapers);
AppCompatImageView recvBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_1);
toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
toolbar.setNavigationOnClickListener(nav -> {
if (!Navigation.findNavController(nav).popBackStack()) {
requireActivity().finish();
}
});
forceAspectRatioToScreenByAdjustingHeight(chatWallpaperPreview);
viewModel.getWallpaperPreviewPortrait().observe(getViewLifecycleOwner(), wallpaperPreviewPortrait -> wallpaperPreviewPortrait.applyToAvatarImageView(portrait));
viewModel.getCurrentWallpaper().observe(getViewLifecycleOwner(), wallpaper -> {
if (wallpaper.isPresent()) {
wallpaper.get().loadInto(chatWallpaperPreview);
ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.conversation_item_wallpaper_bubble_color)));
} else {
chatWallpaperPreview.setImageDrawable(null);
ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary)));
}
});
viewModel.getDimInDarkTheme().observe(getViewLifecycleOwner(), shouldDimInNightMode -> {
if (shouldDimInNightMode != dimInNightMode.isChecked()) {
isSettingDimFromViewModel = true;
dimInNightMode.setChecked(shouldDimInNightMode);
isSettingDimFromViewModel = false;
}
chatWallpaperDim.setAlpha(ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME);
chatWallpaperDim.setVisibility(shouldDimInNightMode && ThemeUtil.isDarkTheme(requireContext()) ? View.VISIBLE : View.GONE);
});
viewModel.getEnableWallpaperControls().observe(getViewLifecycleOwner(), enableWallpaperControls -> {
dimInNightMode.setEnabled(enableWallpaperControls);
dimInNightMode.setAlpha(enableWallpaperControls ? 1 : 0.5f);
});
chatWallpaperPreview.setOnClickListener(unused -> setWallpaper.performClick());
setWallpaper.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), R.id.action_chatWallpaperFragment_to_chatWallpaperSelectionFragment));
setChatColor.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), ChatWallpaperFragmentDirections.actionChatWallpaperFragmentToChatColorSelectionFragment(viewModel.getRecipientId())));
if (viewModel.isGlobal()) {
resetAllWallpaper.setOnClickListener(unused -> {
new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_wallpaper).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_wallpapers).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_wallpaper, (dialog, which) -> {
viewModel.setWallpaper(null);
viewModel.setDimInDarkTheme(true);
viewModel.saveWallpaperSelection();
dialog.dismiss();
}).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_wallpapers, (dialog, which) -> {
viewModel.setWallpaper(null);
viewModel.setDimInDarkTheme(true);
viewModel.resetAllWallpaper();
dialog.dismiss();
}).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
dialog.dismiss();
}).show();
});
resetChatColors.setOnClickListener(unused -> {
new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_chat_colors).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_chat_colors).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_colors, (dialog, which) -> {
viewModel.clearChatColor();
dialog.dismiss();
}).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_colors, (dialog, which) -> {
viewModel.resetAllChatColors();
dialog.dismiss();
}).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
dialog.dismiss();
}).show();
});
} else {
resetAllWallpaper.setText(R.string.ChatWallpaperFragment__reset_wallpaper);
resetChatColors.setText(R.string.ChatWallpaperFragment__reset_chat_color);
resetAllWallpaper.setOnClickListener(unused -> {
new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_wallpaper_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> {
viewModel.setWallpaper(null);
viewModel.setDimInDarkTheme(true);
viewModel.saveWallpaperSelection();
viewModel.refreshChatColors();
}).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
});
resetChatColors.setOnClickListener(unused -> {
new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_chat_color_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> viewModel.clearChatColor()).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
});
}
dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (!isSettingDimFromViewModel) {
viewModel.setDimInDarkTheme(isChecked);
}
});
viewModel.getCurrentChatColors().observe(getViewLifecycleOwner(), chatColors -> {
sentBubble.getDrawable().setColorFilter(chatColors.getChatBubbleColorFilter());
colorizerView.setBackground(chatColors.getChatBubbleMask());
Projection projection = Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(10)));
colorizerView.setProjections(Collections.singletonList(projection));
Drawable colorCircle = chatColors.asCircle();
colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
TextViewCompat.setCompoundDrawablesRelative(setChatColor, null, null, colorCircle, null);
});
sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
}
use of androidx.appcompat.widget.SwitchCompat in project MTweaks-KernelAdiutorMOD by morogoku.
the class ApplyOnBootFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (getActivity() instanceof ProfileActivity) {
View rootView = inflater.inflate(R.layout.fragment_description, container, false);
TextView title = rootView.findViewById(R.id.title);
TextView summary = rootView.findViewById(R.id.summary);
title.setText(getString(R.string.apply_on_boot));
summary.setText(getString(R.string.apply_on_boot_not_available));
return rootView;
} else {
View rootView = inflater.inflate(R.layout.fragment_apply_on_boot, container, false);
final String category = getArguments().getString(INTENT_CATEGORY);
SwitchCompat switcher = rootView.findViewById(R.id.switcher);
switcher.setChecked(AppSettings.getBoolean(category, false, getActivity()));
switcher.setOnCheckedChangeListener((buttonView, isChecked) -> AppSettings.saveBoolean(category, isChecked, getActivity()));
return rootView;
}
}
use of androidx.appcompat.widget.SwitchCompat in project MTweaks-KernelAdiutorMOD by morogoku.
the class SwitcherFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_switcher, container, false);
String title = getArguments().getString(INTENT_TITLE);
String summary = getArguments().getString(INTENT_SUMMARY);
boolean checked = getArguments().getBoolean(INTENT_CHECKED);
((TextView) view.findViewById(R.id.title)).setText(title);
((TextView) view.findViewById(R.id.summary)).setText(summary);
SwitchCompat mSwitch = view.findViewById(R.id.switcher);
mSwitch.setChecked(checked);
mSwitch.setOnCheckedChangeListener(mOnCheckedChangeListener);
return view;
}
use of androidx.appcompat.widget.SwitchCompat in project SwipeRecyclerView by yanzhenjie.
the class DefineActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View header = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
mRecyclerView.addHeaderView(header);
SwitchCompat switchCompat = header.findViewById(R.id.switch_compat);
switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// 控制是否可以侧滑删除。
mRecyclerView.setItemViewSwipeEnabled(isChecked);
}
});
// 长按拖拽,默认关闭。
mRecyclerView.setLongPressDragEnabled(true);
// 滑动删除,默认关闭。
mRecyclerView.setItemViewSwipeEnabled(false);
// 自定义拖拽控制参数。
mRecyclerView.setOnItemMovementListener(mItemMovementListener);
}
Aggregations