Search in sources :

Example 1 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project J2ME-Loader by nikita36078.

the class ConfigActivity method showScreenPresets.

private void showScreenPresets(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    for (String preset : screenPresets) {
        menu.add(preset);
    }
    popup.setOnMenuItemClickListener(item -> {
        String string = item.getTitle().toString();
        int separator = string.indexOf(" x ");
        tfScreenWidth.setText(string.substring(0, separator));
        tfScreenHeight.setText(string.substring(separator + 3));
        return true;
    });
    popup.show();
}
Also used : Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu) SuppressLint(android.annotation.SuppressLint) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 2 with PopupMenu

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

the class MainActivity method openPopup.

public void openPopup() {
    PopupMenu popup = new PopupMenu(MainActivity.this, findViewById(R.id.anchor), Gravity.RIGHT);
    String id = ((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id;
    final Spannable[] base = SortingUtil.getSortingSpannables(id);
    for (Spannable s : base) {
        // Do not add option for "Best" in any subreddit except for the frontpage.
        if (!id.equals("frontpage") && s.toString().equals(getString(R.string.sorting_best))) {
            continue;
        }
        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:
                    SortingUtil.setSorting(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, Sorting.HOT);
                    reloadSubs();
                    break;
                case 1:
                    SortingUtil.setSorting(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, Sorting.NEW);
                    reloadSubs();
                    break;
                case 2:
                    SortingUtil.setSorting(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, Sorting.RISING);
                    reloadSubs();
                    break;
                case 3:
                    SortingUtil.setSorting(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, Sorting.TOP);
                    openPopupTime();
                    break;
                case 4:
                    SortingUtil.setSorting(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, Sorting.CONTROVERSIAL);
                    openPopupTime();
                    break;
                case 5:
                    SortingUtil.setSorting(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, Sorting.BEST);
                    reloadSubs();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 3 with PopupMenu

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

the class MainActivity method openPopupTime.

public void openPopupTime() {
    PopupMenu popup = new PopupMenu(MainActivity.this, findViewById(R.id.anchor), Gravity.RIGHT);
    String id = ((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id;
    final Spannable[] base = SortingUtil.getSortingTimesSpannables(id);
    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:
                    SortingUtil.setTime(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.HOUR);
                    reloadSubs();
                    break;
                case 1:
                    SortingUtil.setTime(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.DAY);
                    reloadSubs();
                    break;
                case 2:
                    SortingUtil.setTime(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.WEEK);
                    reloadSubs();
                    break;
                case 3:
                    SortingUtil.setTime(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.MONTH);
                    reloadSubs();
                    break;
                case 4:
                    SortingUtil.setTime(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.YEAR);
                    reloadSubs();
                    break;
                case 5:
                    SortingUtil.setTime(((SubmissionsView) (((MainPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.ALL);
                    reloadSubs();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 4 with PopupMenu

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

the class SubredditView method openPopupTime.

public void openPopupTime() {
    PopupMenu popup = new PopupMenu(SubredditView.this, findViewById(R.id.anchor), Gravity.RIGHT);
    final Spannable[] base = SortingUtil.getSortingTimesSpannables(subreddit);
    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:
                    SortingUtil.setTime(subreddit, TimePeriod.HOUR);
                    reloadSubs();
                    break;
                case 1:
                    SortingUtil.setTime(subreddit, TimePeriod.DAY);
                    reloadSubs();
                    break;
                case 2:
                    SortingUtil.setTime(subreddit, TimePeriod.WEEK);
                    reloadSubs();
                    break;
                case 3:
                    SortingUtil.setTime(subreddit, TimePeriod.MONTH);
                    reloadSubs();
                    break;
                case 4:
                    SortingUtil.setTime(subreddit, TimePeriod.YEAR);
                    reloadSubs();
                    break;
                case 5:
                    SortingUtil.setTime(subreddit, TimePeriod.ALL);
                    reloadSubs();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 5 with PopupMenu

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

the class SubredditView method openPopup.

public void openPopup() {
    PopupMenu popup = new PopupMenu(SubredditView.this, findViewById(R.id.anchor), Gravity.RIGHT);
    final Spannable[] base = SortingUtil.getSortingSpannables(subreddit);
    for (Spannable s : base) {
        // Do not add option for "Best" in any subreddit except for the frontpage.
        if (!subreddit.equalsIgnoreCase("frontpage") && s.toString().equals(getString(R.string.sorting_best))) {
            continue;
        }
        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:
                    SortingUtil.setSorting(subreddit, Sorting.HOT);
                    reloadSubs();
                    break;
                case 1:
                    SortingUtil.setSorting(subreddit, Sorting.NEW);
                    reloadSubs();
                    break;
                case 2:
                    SortingUtil.setSorting(subreddit, Sorting.RISING);
                    reloadSubs();
                    break;
                case 3:
                    SortingUtil.setSorting(subreddit, Sorting.TOP);
                    openPopupTime();
                    break;
                case 4:
                    SortingUtil.setSorting(subreddit, Sorting.CONTROVERSIAL);
                    openPopupTime();
                    break;
                case 5:
                    SortingUtil.setSorting(subreddit, Sorting.BEST);
                    reloadSubs();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) 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