Search in sources :

Example 16 with SwitchCompat

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));
}
Also used : RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 17 with SwitchCompat

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());
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DisplayMetricsUtil(org.thoughtcrime.securesms.util.DisplayMetricsUtil) ColorStateList(android.content.res.ColorStateList) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ContextCompat(androidx.core.content.ContextCompat) SwitchCompat(androidx.appcompat.widget.SwitchCompat) LayoutInflater(android.view.LayoutInflater) ImageViewCompat(androidx.core.widget.ImageViewCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) Drawable(android.graphics.drawable.Drawable) Projection(org.thoughtcrime.securesms.util.Projection) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Toolbar(androidx.appcompat.widget.Toolbar) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 18 with SwitchCompat

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;
    }
}
Also used : ProfileActivity(com.moro.mtweaks.activities.tools.profile.ProfileActivity) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) SwitchCompat(androidx.appcompat.widget.SwitchCompat) Nullable(androidx.annotation.Nullable)

Example 19 with SwitchCompat

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;
}
Also used : TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) SwitchCompat(androidx.appcompat.widget.SwitchCompat) Nullable(androidx.annotation.Nullable)

Example 20 with SwitchCompat

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);
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CompoundButton(android.widget.CompoundButton) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Aggregations

SwitchCompat (androidx.appcompat.widget.SwitchCompat)43 TextView (android.widget.TextView)23 View (android.view.View)20 CompoundButton (android.widget.CompoundButton)17 RelativeLayout (android.widget.RelativeLayout)8 LayoutInflater (android.view.LayoutInflater)7 AlertDialog (androidx.appcompat.app.AlertDialog)6 PopupMenu (androidx.appcompat.widget.PopupMenu)6 Toolbar (androidx.appcompat.widget.Toolbar)5 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)5 ArrayList (java.util.ArrayList)5 Activity (android.app.Activity)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 Uri (android.net.Uri)4 ViewGroup (android.view.ViewGroup)4 ContextCompat (androidx.core.content.ContextCompat)4 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)4 Dialog (android.app.Dialog)3 Drawable (android.graphics.drawable.Drawable)3