Search in sources :

Example 26 with PopupMenu

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

the class EditCardsLayout method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideRedditSwipeAnywhere();
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme();
    setContentView(R.layout.activity_settings_theme_card);
    setupAppBar(R.id.toolbar, R.string.settings_layout_default, true, true);
    final LinearLayout layout = (LinearLayout) findViewById(R.id.card);
    layout.removeAllViews();
    layout.addView(CreateCardView.CreateView(layout));
    // View type//
    // Cards or List//
    ((TextView) findViewById(R.id.view_current)).setText(CreateCardView.isCard() ? (CreateCardView.isMiddle() ? getString(R.string.mode_centered) : getString(R.string.mode_card)) : CreateCardView.isDesktop() ? getString(R.string.mode_desktop_compact) : getString(R.string.mode_list));
    findViewById(R.id.view).setOnClickListener(new View.OnClickListener() {

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

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.center:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setMiddleCard(true, layout));
                            break;
                        case R.id.card:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setCardViewType(CreateCardView.CardEnum.LARGE, layout));
                            break;
                        case R.id.list:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setCardViewType(CreateCardView.CardEnum.LIST, layout));
                            break;
                        case R.id.desktop:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setCardViewType(CreateCardView.CardEnum.DESKTOP, layout));
                            break;
                    }
                    ((TextView) findViewById(R.id.view_current)).setText(CreateCardView.isCard() ? (CreateCardView.isMiddle() ? getString(R.string.mode_centered) : getString(R.string.mode_card)) : CreateCardView.isDesktop() ? getString(R.string.mode_desktop_compact) : getString(R.string.mode_list));
                    return true;
                }
            });
            popup.show();
        }
    });
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.commentlast);
        single.setChecked(SettingValues.commentLastVisit);
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.commentLastVisit = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COMMENT_LAST_VISIT, isChecked).apply();
            }
        });
    }
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.domain);
        single.setChecked(SettingValues.showDomain);
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.showDomain = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SHOW_DOMAIN, isChecked).apply();
            }
        });
    }
    {
        SwitchCompat single2 = (SwitchCompat) findViewById(R.id.selftextcomment);
        single2.setChecked(SettingValues.hideSelftextLeadImage);
        single2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.hideSelftextLeadImage = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SELFTEXT_IMAGE_COMMENT, isChecked).apply();
            }
        });
    }
    {
        SwitchCompat single2 = (SwitchCompat) findViewById(R.id.abbreviateScores);
        single2.setChecked(SettingValues.abbreviateScores);
        single2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.abbreviateScores = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_ABBREVIATE_SCORES, isChecked).apply();
            }
        });
    }
    {
        SwitchCompat single2 = (SwitchCompat) findViewById(R.id.hidePostAwards);
        single2.setChecked(SettingValues.hidePostAwards);
        single2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.hidePostAwards = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_HIDE_POST_AWARDS, isChecked).apply();
            }
        });
    }
    {
        SwitchCompat single2 = (SwitchCompat) findViewById(R.id.titleTop);
        single2.setChecked(SettingValues.titleTop);
        single2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.titleTop = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_TITLE_TOP, isChecked).apply();
            }
        });
    }
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.votes);
        single.setChecked(SettingValues.votesInfoLine);
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.votesInfoLine = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_VOTES_INFO_LINE, isChecked).apply();
                SubmissionCache.evictAll();
            }
        });
    }
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.contenttype);
        single.setChecked(SettingValues.typeInfoLine);
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.typeInfoLine = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_TYPE_INFO_LINE, isChecked).apply();
                SubmissionCache.evictAll();
            }
        });
    }
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.selftext);
        single.setChecked(SettingValues.cardText);
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.cardText = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_CARD_TEXT, isChecked).apply();
            }
        });
    }
    // Pic modes//
    final TextView CURRENT_PICTURE = (TextView) findViewById(R.id.picture_current);
    // it won't be
    assert CURRENT_PICTURE != null;
    if (SettingValues.bigPicCropped) {
        CURRENT_PICTURE.setText(R.string.mode_cropped);
    } else if (SettingValues.bigPicEnabled) {
        CURRENT_PICTURE.setText(R.string.mode_bigpic);
    } else if (SettingValues.noThumbnails) {
        CURRENT_PICTURE.setText(R.string.mode_no_thumbnails);
    } else {
        CURRENT_PICTURE.setText(R.string.mode_thumbnail);
    }
    findViewById(R.id.picture).setOnClickListener(new View.OnClickListener() {

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

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.bigpic:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setBigPicEnabled(true, layout));
                            {
                                SharedPreferences.Editor e = SettingValues.prefs.edit();
                                for (Map.Entry<String, ?> map : SettingValues.prefs.getAll().entrySet()) {
                                    if (map.getKey().startsWith("picsenabled")) {
                                        // reset all overridden values
                                        e.remove(map.getKey());
                                    }
                                }
                                e.apply();
                            }
                            break;
                        case R.id.cropped:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setBigPicCropped(true, layout));
                            break;
                        case R.id.thumbnail:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setBigPicEnabled(false, layout));
                            {
                                SharedPreferences.Editor e = SettingValues.prefs.edit();
                                for (Map.Entry<String, ?> map : SettingValues.prefs.getAll().entrySet()) {
                                    if (map.getKey().startsWith("picsenabled")) {
                                        // reset all overridden values
                                        e.remove(map.getKey());
                                    }
                                }
                                e.apply();
                            }
                            break;
                        case R.id.noThumbnails:
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setNoThumbnails(true, layout));
                            {
                                SharedPreferences.Editor e = SettingValues.prefs.edit();
                                for (Map.Entry<String, ?> map : SettingValues.prefs.getAll().entrySet()) {
                                    if (map.getKey().startsWith("picsenabled")) {
                                        // reset all overridden values
                                        e.remove(map.getKey());
                                    }
                                }
                                e.apply();
                            }
                            break;
                    }
                    if (SettingValues.bigPicCropped) {
                        CURRENT_PICTURE.setText(R.string.mode_cropped);
                    } else if (SettingValues.bigPicEnabled) {
                        CURRENT_PICTURE.setText(R.string.mode_bigpic);
                    } else if (SettingValues.noThumbnails) {
                        CURRENT_PICTURE.setText(R.string.mode_no_thumbnails);
                    } else {
                        CURRENT_PICTURE.setText(R.string.mode_thumbnail);
                    }
                    return true;
                }
            });
            popup.show();
        }
    });
    if (!SettingValues.noThumbnails) {
        final SwitchCompat bigThumbnails = (SwitchCompat) findViewById(R.id.bigThumbnails);
        // def won't be null
        assert bigThumbnails != null;
        bigThumbnails.setChecked(SettingValues.bigThumbnails);
        bigThumbnails.setOnCheckedChangeListener(new SwitchCompat.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.prefs.edit().putBoolean("bigThumbnails", isChecked).apply();
                SettingValues.bigThumbnails = isChecked;
                if (!SettingValues.bigPicCropped) {
                    layout.removeAllViews();
                    layout.addView(CreateCardView.setBigPicEnabled(false, layout));
                    {
                        SharedPreferences.Editor e = SettingValues.prefs.edit();
                        for (Map.Entry<String, ?> map : SettingValues.prefs.getAll().entrySet()) {
                            if (map.getKey().startsWith("picsenabled")) {
                                // reset all overridden values
                                e.remove(map.getKey());
                            }
                        }
                        e.apply();
                    }
                }
            }
        });
    }
    // Actionbar//
    ((TextView) findViewById(R.id.actionbar_current)).setText(!SettingValues.actionbarVisible ? (SettingValues.actionbarTap ? getString(R.string.tap_actionbar) : getString(R.string.press_actionbar)) : getString(R.string.always_actionbar));
    findViewById(R.id.actionbar).setOnClickListener(new View.OnClickListener() {

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

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.always:
                            SettingValues.actionbarTap = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_ACTIONBAR_TAP, false).apply();
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setActionbarVisible(true, layout));
                            break;
                        case R.id.tap:
                            SettingValues.actionbarTap = true;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_ACTIONBAR_TAP, true).apply();
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setActionbarVisible(false, layout));
                            break;
                        case R.id.button:
                            SettingValues.actionbarTap = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_ACTIONBAR_TAP, false).apply();
                            layout.removeAllViews();
                            layout.addView(CreateCardView.setActionbarVisible(false, layout));
                            break;
                    }
                    ((TextView) findViewById(R.id.actionbar_current)).setText(!SettingValues.actionbarVisible ? (SettingValues.actionbarTap ? getString(R.string.tap_actionbar) : getString(R.string.press_actionbar)) : getString(R.string.always_actionbar));
                    return true;
                }
            });
            popup.show();
        }
    });
    // Other buttons//
    final AppCompatCheckBox hidebutton = (AppCompatCheckBox) findViewById(R.id.hidebutton);
    layout.findViewById(R.id.hide).setVisibility(SettingValues.hideButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
    layout.findViewById(R.id.save).setVisibility(SettingValues.saveButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
    hidebutton.setChecked(SettingValues.hideButton);
    hidebutton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.hideButton = isChecked;
            layout.findViewById(R.id.hide).setVisibility(SettingValues.hideButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
            layout.findViewById(R.id.save).setVisibility(SettingValues.saveButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_HIDEBUTTON, isChecked).apply();
        }
    });
    final AppCompatCheckBox savebutton = (AppCompatCheckBox) findViewById(R.id.savebutton);
    layout.findViewById(R.id.save).setVisibility(SettingValues.saveButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
    savebutton.setChecked(SettingValues.saveButton);
    savebutton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.saveButton = isChecked;
            layout.findViewById(R.id.hide).setVisibility(SettingValues.hideButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
            layout.findViewById(R.id.save).setVisibility(SettingValues.saveButton && SettingValues.actionbarVisible ? View.VISIBLE : View.GONE);
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SAVE_BUTTON, isChecked).apply();
        }
    });
    // Smaller tags//
    final SwitchCompat smallTag = (SwitchCompat) findViewById(R.id.tagsetting);
    smallTag.setChecked(SettingValues.smallTag);
    smallTag.setOnCheckedChangeListener(new SwitchCompat.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            layout.removeAllViews();
            layout.addView(CreateCardView.setSmallTag(isChecked, layout));
        }
    });
    // Actionbar//
    // Enable, collapse//
    final SwitchCompat switchThumb = (SwitchCompat) findViewById(R.id.action);
    switchThumb.setChecked(SettingValues.switchThumb);
    switchThumb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            layout.removeAllViews();
            layout.addView(CreateCardView.setSwitchThumb(isChecked, layout));
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) MenuItem(android.view.MenuItem) TextView(android.widget.TextView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) TextView(android.widget.TextView) Map(java.util.Map) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton) PopupMenu(androidx.appcompat.widget.PopupMenu) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 27 with PopupMenu

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

the class SettingsDataFragment method Bind.

public void Bind() {
    final RelativeLayout datasavingDataSaveTypeLayout = context.findViewById(R.id.settings_datasaving_datasavetype);
    final TextView datasavingLowQualityView = context.findViewById(R.id.settings_datasaving_lowquality);
    final RelativeLayout datasavingDataSaveQualityLayout = context.findViewById(R.id.settings_datasaving_datasavequality);
    final TextView datasavingCurrentModeView = context.findViewById(R.id.settings_datasaving_currentmode);
    final SwitchCompat datasavingVideoQualitySwitch = context.findViewById(R.id.settings_datasaving_videoquality);
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // * Data saving mode */
    datasavingDataSaveTypeLayout.setOnClickListener(v -> {
        PopupMenu popup = new PopupMenu(context, v);
        popup.getMenuInflater().inflate(R.menu.imagequality_settings, popup.getMenu());
        popup.setOnMenuItemClickListener(item -> {
            switch(item.getItemId()) {
                case R.id.never:
                    setImageQualitySettings(false, false);
                    break;
                case R.id.mobile:
                    setImageQualitySettings(true, false);
                    break;
                case R.id.always:
                    setImageQualitySettings(true, true);
                    break;
            }
            datasavingLowQualityView.setText(SettingValues.lowResMobile ? SettingValues.lowResAlways ? context.getString(R.string.datasave_always) : context.getString(R.string.datasave_mobile) : context.getString(R.string.never));
            if (datasavingLowQualityView.getText().equals(context.getString(R.string.never))) {
                datasavingDataSaveQualityLayout.setAlpha(0.25f);
                datasavingCurrentModeView.setText("Enable datasaving mode");
                datasavingVideoQualitySwitch.setEnabled(false);
            } else {
                datasavingDataSaveQualityLayout.setAlpha(1f);
                datasavingCurrentModeView.setText(SettingValues.noImages ? context.getString(R.string.never_load_images) : SettingValues.lqLow ? context.getString(R.string.load_low_quality) : SettingValues.lqMid ? context.getString(R.string.load_medium_quality) : context.getString(R.string.load_high_quality));
                datasavingVideoQualitySwitch.setEnabled(true);
            }
            return true;
        });
        popup.show();
    });
    if (datasavingLowQualityView.getText().equals(context.getString(R.string.never))) {
        datasavingDataSaveQualityLayout.setAlpha(0.25f);
        datasavingCurrentModeView.setText("Enable datasaving mode");
    }
    // Datasaving type multi choice
    datasavingLowQualityView.setText(SettingValues.lowResMobile ? SettingValues.lowResAlways ? context.getString(R.string.datasave_always) : context.getString(R.string.datasave_mobile) : context.getString(R.string.never));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // * Data saving quality */
    datasavingDataSaveQualityLayout.setOnClickListener(v -> {
        if (!datasavingLowQualityView.getText().equals(context.getString(R.string.never))) {
            PopupMenu popup = new PopupMenu(context, v);
            popup.getMenuInflater().inflate(R.menu.imagequality_mode, popup.getMenu());
            popup.setOnMenuItemClickListener(item -> {
                switch(item.getItemId()) {
                    case R.id.never:
                        setImageQualityMode(true, true, false, false, false);
                        break;
                    case R.id.low:
                        setImageQualityMode(false, true, true, false, false);
                        break;
                    case R.id.medium:
                        setImageQualityMode(false, true, false, true, false);
                        break;
                    case R.id.high:
                        setImageQualityMode(false, true, false, false, true);
                        break;
                }
                datasavingCurrentModeView.setText(SettingValues.noImages ? context.getString(R.string.never_load_images) : SettingValues.lqLow ? context.getString(R.string.load_low_quality) : SettingValues.lqMid ? context.getString(R.string.load_medium_quality) : context.getString(R.string.load_high_quality));
                return true;
            });
            popup.show();
        }
    });
    // Image mode multi choice
    datasavingCurrentModeView.setText(SettingValues.noImages ? context.getString(R.string.never_load_images) : SettingValues.lqLow ? context.getString(R.string.load_low_quality) : SettingValues.lqMid ? context.getString(R.string.load_medium_quality) : context.getString(R.string.load_high_quality));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    datasavingVideoQualitySwitch.setChecked(SettingValues.lqVideos);
    datasavingVideoQualitySwitch.setEnabled(SettingValues.lowResMobile || SettingValues.lowResAlways);
    datasavingVideoQualitySwitch.setOnCheckedChangeListener((v, checked) -> {
        SettingValues.lqVideos = checked;
        editSharedBooleanPreference(SettingValues.PREF_LQ_VIDEOS, checked);
    });
}
Also used : RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) SwitchCompat(androidx.appcompat.widget.SwitchCompat) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 28 with PopupMenu

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

the class Profile method openPopup.

public void openPopup() {
    PopupMenu popup = new PopupMenu(Profile.this, findViewById(R.id.anchor), Gravity.RIGHT);
    final Spannable[] base = SortingUtil.getSortingSpannables(profSort);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            LogUtil.v("Chosen is " + item.getOrder());
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            switch(i) {
                case 0:
                    profSort = (Sorting.HOT);
                    break;
                case 1:
                    profSort = (Sorting.NEW);
                    break;
                case 2:
                    profSort = (Sorting.RISING);
                    break;
                case 3:
                    profSort = (Sorting.TOP);
                    openPopupTime();
                    return true;
                case 4:
                    profSort = (Sorting.CONTROVERSIAL);
                    openPopupTime();
                    return true;
            }
            SortingUtil.sorting.put(name.toLowerCase(Locale.ENGLISH), profSort);
            int current = pager.getCurrentItem();
            ProfilePagerAdapter adapter = new ProfilePagerAdapter(getSupportFragmentManager());
            pager.setAdapter(adapter);
            pager.setOffscreenPageLimit(1);
            tabs.setupWithViewPager(pager);
            pager.setCurrentItem(current);
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 29 with PopupMenu

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

the class Profile method openPopupTime.

public void openPopupTime() {
    PopupMenu popup = new PopupMenu(Profile.this, findViewById(R.id.anchor), Gravity.RIGHT);
    final Spannable[] base = SortingUtil.getSortingTimesSpannables(profTime);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            LogUtil.v("Chosen is " + item.getOrder());
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            switch(i) {
                case 0:
                    profTime = (TimePeriod.HOUR);
                    break;
                case 1:
                    profTime = (TimePeriod.DAY);
                    break;
                case 2:
                    profTime = (TimePeriod.WEEK);
                    break;
                case 3:
                    profTime = (TimePeriod.MONTH);
                    break;
                case 4:
                    profTime = (TimePeriod.YEAR);
                    break;
                case 5:
                    profTime = (TimePeriod.ALL);
                    break;
            }
            SortingUtil.sorting.put(name.toLowerCase(Locale.ENGLISH), profSort);
            SortingUtil.times.put(name.toLowerCase(Locale.ENGLISH), profTime);
            int current = pager.getCurrentItem();
            ProfilePagerAdapter adapter = new ProfilePagerAdapter(getSupportFragmentManager());
            pager.setAdapter(adapter);
            pager.setOffscreenPageLimit(1);
            tabs.setupWithViewPager(pager);
            pager.setCurrentItem(current);
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 30 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project mongol-library by suragch.

the class MongolMenuActivity method onStandardMenuButtonClick.

public void onStandardMenuButtonClick(View view) {
    Button standardMenuButton = findViewById(R.id.standard_menu_button);
    PopupMenu popup = new PopupMenu(this, standardMenuButton);
    popup.getMenuInflater().inflate(R.menu.mongol_menu_activity, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(MongolMenuActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    popup.show();
}
Also used : Button(android.widget.Button) MongolMenuItem(net.studymongolian.mongollibrary.MongolMenuItem) MenuItem(android.view.MenuItem) 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