Search in sources :

Example 21 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project android by nextcloud.

the class ManageAccountsActivity method onOptionItemClicked.

@Override
public void onOptionItemClicked(User user, View view) {
    if (view.getId() == R.id.account_menu) {
        PopupMenu popup = new PopupMenu(this, view);
        popup.getMenuInflater().inflate(R.menu.item_account, popup.getMenu());
        if (accountManager.getUser().equals(user)) {
            popup.getMenu().findItem(R.id.action_open_account).setVisible(false);
        }
        popup.setOnMenuItemClickListener(item -> {
            int itemId = item.getItemId();
            if (itemId == R.id.action_open_account) {
                accountClicked(user.hashCode());
            } else if (itemId == R.id.action_delete_account) {
                openAccountRemovalConfirmationDialog(user, getSupportFragmentManager());
            } else {
                openAccount(user);
            }
            return true;
        });
        popup.show();
    } else {
        openAccount(user);
    }
}
Also used : PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 22 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project android by nextcloud.

the class NotificationListAdapter method setButtons.

public void setButtons(NotificationViewHolder holder, Notification notification) {
    // add action buttons
    holder.binding.buttons.removeAllViews();
    MaterialButton button;
    Resources resources = notificationsActivity.getResources();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(resources.getDimensionPixelOffset(R.dimen.standard_half_margin), 0, resources.getDimensionPixelOffset(R.dimen.standard_half_margin), 0);
    int primaryColor = ThemeColorUtils.primaryColor(notificationsActivity);
    List<Action> overflowActions = new ArrayList<>();
    if (notification.getActions().size() > 2) {
        for (Action action : notification.getActions()) {
            if (action.primary) {
                button = new MaterialButton(notificationsActivity);
                button.setAllCaps(false);
                button.setText(action.label);
                button.setCornerRadiusResource(R.dimen.button_corner_radius);
                button.setLayoutParams(params);
                button.setGravity(Gravity.CENTER);
                button.setOnClickListener(v -> {
                    setButtonEnabled(holder, false);
                    if (ACTION_TYPE_WEB.equals(action.type)) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(action.link));
                        notificationsActivity.startActivity(intent);
                    } else {
                        new NotificationExecuteActionTask(client, holder, notification, notificationsActivity).execute(action);
                    }
                });
                ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity);
                holder.binding.buttons.addView(button);
            } else {
                overflowActions.add(action);
            }
        }
        // further actions
        button = new MaterialButton(notificationsActivity);
        button.setBackgroundColor(resources.getColor(R.color.grey_200));
        button.setTextColor(primaryColor);
        button.setAllCaps(false);
        button.setText(R.string.more);
        button.setCornerRadiusResource(R.dimen.button_corner_radius);
        button.setLayoutParams(params);
        button.setGravity(Gravity.CENTER);
        MaterialButton finalButton = button;
        button.setOnClickListener(v -> {
            PopupMenu popup = new PopupMenu(notificationsActivity, finalButton);
            for (Action action : overflowActions) {
                popup.getMenu().add(action.label).setOnMenuItemClickListener(item -> {
                    setButtonEnabled(holder, false);
                    if (ACTION_TYPE_WEB.equals(action.type)) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(action.link));
                        notificationsActivity.startActivity(intent);
                    } else {
                        new NotificationExecuteActionTask(client, holder, notification, notificationsActivity).execute(action);
                    }
                    return true;
                });
            }
            popup.show();
        });
        holder.binding.buttons.addView(button);
    } else {
        for (Action action : notification.getActions()) {
            button = new MaterialButton(notificationsActivity);
            if (action.primary) {
                ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity);
            } else {
                button.setBackgroundColor(resources.getColor(R.color.grey_200));
                button.setTextColor(primaryColor);
            }
            button.setAllCaps(false);
            button.setText(action.label);
            button.setCornerRadiusResource(R.dimen.button_corner_radius);
            button.setLayoutParams(params);
            button.setGravity(Gravity.CENTER);
            button.setOnClickListener(v -> {
                setButtonEnabled(holder, false);
                if (ACTION_TYPE_WEB.equals(action.type)) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(action.link));
                    notificationsActivity.startActivity(intent);
                } else {
                    new NotificationExecuteActionTask(client, holder, notification, notificationsActivity).execute(action);
                }
            });
            holder.binding.buttons.addView(button);
        }
    }
}
Also used : Action(com.owncloud.android.lib.resources.notifications.models.Action) NotificationExecuteActionTask(com.owncloud.android.ui.asynctasks.NotificationExecuteActionTask) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Resources(android.content.res.Resources) MaterialButton(com.google.android.material.button.MaterialButton) LinearLayout(android.widget.LinearLayout) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 23 with PopupMenu

use of androidx.appcompat.widget.PopupMenu 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);
        }
    });
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Slide(me.ccrama.redditslide.Activities.Slide) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) SwitchCompat(androidx.appcompat.widget.SwitchCompat) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 24 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project Slide by ccrama.

the class SettingsViewType method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_viewtype);
    setupAppBar(R.id.toolbar, R.string.settings_view_type, true, true);
    // View type multi choice
    ((TextView) findViewById(R.id.currentViewType)).setText(SettingValues.single ? (SettingValues.commentPager ? getString(R.string.view_type_comments) : getString(R.string.view_type_none)) : getString(R.string.view_type_tabs));
    findViewById(R.id.viewtype).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SettingsViewType.this, v);
            popup.getMenuInflater().inflate(R.menu.view_type_settings, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.tabs:
                            SettingValues.single = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE, false).apply();
                            break;
                        case R.id.notabs:
                            SettingValues.single = true;
                            SettingValues.commentPager = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COMMENT_PAGER, false).apply();
                            break;
                        case R.id.comments:
                            SettingValues.single = true;
                            SettingValues.commentPager = true;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COMMENT_PAGER, true).apply();
                            break;
                    }
                    ((TextView) findViewById(R.id.currentViewType)).setText(SettingValues.single ? (SettingValues.commentPager ? getString(R.string.view_type_comments) : getString(R.string.view_type_none)) : getString(R.string.view_type_tabs));
                    SettingsThemeFragment.changed = true;
                    return true;
                }
            });
            popup.show();
        }
    });
}
Also used : TextView(android.widget.TextView) MenuItem(android.view.MenuItem) TextView(android.widget.TextView) View(android.view.View) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 25 with PopupMenu

use of androidx.appcompat.widget.PopupMenu 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);
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) RobotoRadioButton(com.devspark.robototextview.widget.RobotoRadioButton) TextView(android.widget.TextView) PopupMenu(androidx.appcompat.widget.PopupMenu) Menu(android.view.Menu) LinearLayout(android.widget.LinearLayout) SwitchCompat(androidx.appcompat.widget.SwitchCompat) PopupMenu(androidx.appcompat.widget.PopupMenu)

Aggregations

PopupMenu (androidx.appcompat.widget.PopupMenu)34 MenuItem (android.view.MenuItem)20 TextView (android.widget.TextView)12 Spannable (android.text.Spannable)8 View (android.view.View)8 Menu (android.view.Menu)7 SwitchCompat (androidx.appcompat.widget.SwitchCompat)5 MenuInflater (android.view.MenuInflater)4 LinearLayout (android.widget.LinearLayout)4 RelativeLayout (android.widget.RelativeLayout)4 Intent (android.content.Intent)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 CompoundButton (android.widget.CompoundButton)2 SearchView (androidx.appcompat.widget.SearchView)2