Java Code Examples for android.view.MenuItem#setCheckable()

The following examples show how to use android.view.MenuItem#setCheckable() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: RemoteAdbShell   File: AdbShell.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    
    if (v == commandBox) {
    	commandHistory.populateMenu(menu);
    }
    else {
    	menu.add(Menu.NONE, MENU_ID_CTRL_C, Menu.NONE, "Send Ctrl+C");
    	
    	MenuItem autoscroll = menu.add(Menu.NONE, MENU_ID_AUTOSCROLL, Menu.NONE, "Auto-scroll terminal");
    	autoscroll.setCheckable(true);
    	autoscroll.setChecked(autoScrollEnabled);
    	
    	menu.add(Menu.NONE, MENU_ID_EXIT, Menu.NONE, "Exit Terminal");
    }
}
 
Example 2
Source Project: android   File: MessagesActivity.java    License: MIT License 6 votes vote down vote up
protected void onUpdateApps(List<Application> applications) {
    Menu menu = navigationView.getMenu();
    menu.removeGroup(R.id.apps);
    targetReferences.clear();
    updateMessagesAndStopLoading(messages.get(appId));
    for (Application app : applications) {
        MenuItem item = menu.add(R.id.apps, app.getId(), APPLICATION_ORDER, app.getName());
        item.setCheckable(true);
        Target t = Utils.toDrawable(getResources(), item::setIcon);
        targetReferences.add(t);
        picassoHandler
                .get()
                .load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage()))
                .error(R.drawable.ic_alarm)
                .placeholder(R.drawable.ic_placeholder)
                .resize(100, 100)
                .into(t);
    }
}
 
Example 3
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    item.setCheckable(true);
    item.setChecked(true);
    int id = item.getItemId();
    if (id == R.id.nav_trash) {
        startActivity(new Intent(getApplication(), RecycleActivity.class));
    } else if (id == R.id.nav_all) {
        selectedCategory = CAT_ALL;
        updateList();
    } else if (id == R.id.nav_manage_categories) {
        startActivity(new Intent(getApplication(), ManageCategoriesActivity.class));
    } else {
        selectedCategory = id;
        updateList();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 4
public void showAudioPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
    final MenuItem backgroundAudioItem = menu.findItem(0);
    backgroundAudioItem.setCheckable(true);
    backgroundAudioItem.setChecked(enableBackgroundAudio);
    OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item == backgroundAudioItem) {
                enableBackgroundAudio = !item.isChecked();
                return true;
            }
            return false;
        }
    };
    configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
    popup.show();
}
 
Example 5
Source Project: Exoplayer_VLC   File: PlayerActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void showAudioPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);
  Menu menu = popup.getMenu();
  menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
  final MenuItem backgroundAudioItem = menu.findItem(0);
  backgroundAudioItem.setCheckable(true);
  backgroundAudioItem.setChecked(enableBackgroundAudio);
  OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item == backgroundAudioItem) {
        enableBackgroundAudio = !item.isChecked();
        return true;
      }
      return false;
    }
  };
  configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
  popup.show();
}
 
Example 6
private void appendFragments(boolean setShortcuts) {
    mActualFragments.clear();
    Menu menu = mNavigationView.getMenu();
    menu.clear();

    SubMenu lastSubMenu = null;
    for (NavigationFragment navigationFragment : mFragments) {
        Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
        int id = navigationFragment.mId;

        if (fragmentClass == null) {
            lastSubMenu = menu.addSubMenu(id);
            mActualFragments.put(id, null);
        } else if (Prefs.getBoolean(fragmentClass.getSimpleName() + "_enabled",
                true, this)) {
            MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) :
                    lastSubMenu.add(0, id, 0, id);
            menuItem.setIcon(ViewUtils.getColoredIcon(Prefs.getBoolean("section_icons", true, this)
                    && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable : R.drawable.ic_blank, this));
            menuItem.setCheckable(true);
            if (mSelection != 0) {
                mNavigationView.setCheckedItem(mSelection);
            }
            mActualFragments.put(id, fragmentClass);
        }
    }
    if (setShortcuts) {
        setShortcuts();
    }
}
 
Example 7
private void appendFragments(boolean setShortcuts) {
    mActualFragments.clear();
    Menu menu = mNavigationView.getMenu();
    menu.clear();

    SubMenu lastSubMenu = null;
    for (NavigationFragment navigationFragment : mFragments) {
        Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
        int id = navigationFragment.mId;

        Drawable drawable = ContextCompat.getDrawable(this,
                    AppSettings.isSectionIcons(this)
                    && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable :
                    R.drawable.ic_blank);

        if (fragmentClass == null) {
            lastSubMenu = menu.addSubMenu(id);
            mActualFragments.put(id, null);
        } else if (AppSettings.isFragmentEnabled(fragmentClass, this)) {
            MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) :
                    lastSubMenu.add(0, id, 0, id);
            menuItem.setIcon(drawable);
            menuItem.setCheckable(true);
            if (mSelection != 0) {
                mNavigationView.setCheckedItem(mSelection);
            }
            mActualFragments.put(id, fragmentClass);
        }
    }
    if (setShortcuts) {
        setShortcuts();
    }
}
 
Example 8
private void selectFontSize() {
    final int defsize = webView.getSettings().getDefaultFontSize();
    int minsize = webView.getSettings().getMinimumFontSize();
    final float scale = getResources().getDisplayMetrics().density;


   // Log.d(TAG, "def " + defsize + " " + scale);
    final PopupMenu sizemenu = new PopupMenu(this, findViewById(R.id.zoom_button));
    for (int size=minsize; size<=36; size+=2) {
        final int s = size;

        MenuItem mi = sizemenu.getMenu().add(" "+size);
        mi.setCheckable(true);
        mi.setChecked(size==defsize);

        mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                Log.d(TAG, "def " + (defsize-s));
                int scrolloffset = (int)(-webView.getScrollY()*(defsize - s)/scale/2.7);
                Log.d(TAG, "scrollby " + scrolloffset);

                setFontSize(s);

                //attempt to adjust the scroll to keep the same text position.
                //  needs much work
                webView.scrollBy(0, scrolloffset);
                sizemenu.dismiss();
                return true;
            }
        });
    }
    sizemenu.show();


}
 
Example 9
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_ui);

    context = getApplicationContext();

    MobileAds.initialize(this);

    mAdView = findViewById(R.id.adView);
    mAdView.loadAd(new AdRequest.Builder().build());

    Toolbar toolbar = findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            mAdView.loadAd(new AdRequest.Builder().build());
        }
    });

    if(savedInstanceState == null){
        MenuItem selected = navigationView.getMenu().findItem(R.id.method1);
        selected.setCheckable(true);
        selected.setChecked(true);
        newFragment(0);
    }
}
 
Example 10
Source Project: MicroReader   File: MainActivity.java    License: MIT License 5 votes vote down vote up
private void initMenu() {
    ArrayList<Config.Channel> savedChannelList = new ArrayList<>();
    mTitles = new ArrayList<>();
    mFragments = new ArrayList<>();
    Menu menu = navView.getMenu();
    menu.clear();
    String savedChannel = mSharedPreferences.getString(SharePreferenceUtil.SAVED_CHANNEL, null);
    if (TextUtils.isEmpty(savedChannel)) {
        Collections.addAll(savedChannelList, Config.Channel.values());
    } else {
        for (String s : savedChannel.split(",")) {
            savedChannelList.add(Config.Channel.valueOf(s));
        }
    }
    for (int i = 0; i < savedChannelList.size(); i++) {
        MenuItem menuItem = menu.add(0, i, 0, savedChannelList.get(i).getTitle());
        mTitles.add(savedChannelList.get(i).getTitle());
        menuItem.setIcon(savedChannelList.get(i).getIcon());
        menuItem.setCheckable(true);
        addFragment(savedChannelList.get(i).name());
        if (i == 0) {
            menuItem.setChecked(true);
        }
    }
    navView.inflateMenu(R.menu.activity_main_drawer);
    switchFragment(mFragments.get(0), getString(mTitles.get(0)));
}
 
Example 11
Source Project: talkback   File: ContextMenu.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setGroupCheckable(int group, boolean checkable, boolean exclusive) {
  for (MenuItem item : items) {
    if (item.getGroupId() == group) {
      item.setCheckable(checkable);
    }
  }
}
 
Example 12
Source Project: GestureViews   File: SettingsMenu.java    License: Apache License 2.0 5 votes vote down vote up
private <T> void addSubMenu(Menu menu, T[] items, T selected, @StringRes int titleId) {
    SubMenu sub = menu.addSubMenu(titleId);
    sub.setGroupCheckable(Menu.NONE, true, true);

    for (int i = 0; i < items.length; i++) {
        MenuItem item = sub.add(Menu.NONE, titleId, i, items[i].toString());
        item.setCheckable(true);
        item.setChecked(items[i] == selected);
    }
}
 
Example 13
private void appendFragments(boolean setShortcuts) {
    mActualFragments.clear();
    Menu menu = mNavigationView.getMenu();
    menu.clear();

    SubMenu lastSubMenu = null;
    for (NavigationFragment navigationFragment : mFragments) {
        Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
        int id = navigationFragment.mId;

        Drawable drawable = ContextCompat.getDrawable(this,
                Utils.DONATED
                        && AppSettings.isSectionIcons(this)
                        && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable :
                        R.drawable.ic_blank);

        if (fragmentClass == null) {
            lastSubMenu = menu.addSubMenu(id);
            mActualFragments.put(id, null);
        } else if (AppSettings.isFragmentEnabled(fragmentClass, this)) {
            MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) :
                    lastSubMenu.add(0, id, 0, id);
            menuItem.setIcon(drawable);
            menuItem.setCheckable(true);
            if (mSelection != 0) {
                mNavigationView.setCheckedItem(mSelection);
            }
            mActualFragments.put(id, fragmentClass);
        }
    }
    if (setShortcuts) {
        setShortcuts();
    }
}
 
Example 14
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (mSelectedApp == null) return;

    if (mIsRemote) {
        if (!mSelectedApp.isSystem())
            menu.add(Menu.NONE, MENU_ITEM_CLONE, Menu.NONE, R.string.clone_to_main_profile);
        // Freezing / Unfreezing is only available in profiles that we can control
        if (mSelectedApp.isHidden()) {
            menu.add(Menu.NONE, MENU_ITEM_UNFREEZE, Menu.NONE, R.string.unfreeze_app);
            menu.add(Menu.NONE, MENU_ITEM_LAUNCH, Menu.NONE, R.string.unfreeze_and_launch);
        } else {
            menu.add(Menu.NONE, MENU_ITEM_FREEZE, Menu.NONE, R.string.freeze_app);
            menu.add(Menu.NONE, MENU_ITEM_LAUNCH, Menu.NONE, R.string.launch);
        }
        // Cross-profile widget settings is also limited to work profile
        MenuItem crossProfileWdiegt =
                menu.add(Menu.NONE, MENU_ITEM_ALLOW_CROSS_PROFILE_WIDGET, Menu.NONE,
                        R.string.allow_cross_profile_widgets);
        crossProfileWdiegt.setCheckable(true);
        crossProfileWdiegt.setChecked(
                mCrossProfileWidgetProviders.contains(mSelectedApp.getPackageName()));

        // TODO: If we implement God Mode (i.e. Shelter as device owner), we should
        // TODO: use two different lists to store auto freeze apps because we'll be
        // TODO: able to freeze apps in main profile.
        MenuItem autoFreeze = menu.add(Menu.NONE, MENU_ITEM_AUTO_FREEZE, Menu.NONE, R.string.auto_freeze);
        autoFreeze.setCheckable(true);
        autoFreeze.setChecked(
                LocalStorageManager.getInstance().stringListContains(
                        LocalStorageManager.PREF_AUTO_FREEZE_LIST_WORK_PROFILE, mSelectedApp.getPackageName()));
        menu.add(Menu.NONE, MENU_ITEM_CREATE_UNFREEZE_SHORTCUT, Menu.NONE, R.string.create_unfreeze_shortcut);
    } else {
        menu.add(Menu.NONE, MENU_ITEM_CLONE, Menu.NONE, R.string.clone_to_work_profile);
    }

    if (!mSelectedApp.isSystem()) {
        // We can't uninstall system apps in both cases
        // but we'll be able to "freeze" them
        menu.add(Menu.NONE, MENU_ITEM_UNINSTALL, Menu.NONE, R.string.uninstall_app);
    }

    if (menu.size() > 0) {
        // Only set title when the menu is not empty
        // this ensures that no menu will be shown
        // if no operation available
        menu.setHeaderTitle(
                getString(R.string.app_context_menu_title, mSelectedApp.getLabel()));
    }
}
 
Example 15
Source Project: AnLinux-Adfree   File: MainUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_ui);

    context = getApplicationContext();

    Toolbar toolbar = findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    relativeLayout = findViewById(R.id.fragmentHolder);

    sharedPreferences = context.getSharedPreferences("GlobalPreferences", 0);
    editor = sharedPreferences.edit();
    isOreoNotified = sharedPreferences.getBoolean("IsOreoNotified", false);
    support = sharedPreferences.getInt("Support", 0);

    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if(savedInstanceState == null){
        MenuItem selected = navigationView.getMenu().findItem(R.id.dashboard);
        selected.setCheckable(true);
        selected.setChecked(true);
        newFragment(0);
    }
    if(!donationInstalled()){
        if(isOreoNotified){
            if(support == 5){
                notifyUserForSupportOnce();
                editor.putInt("Support", 99);
                editor.apply();
            }else if(support != 99){
                editor.putInt("Support", support + 1);
                editor.apply();
            }
        }
    }
}
 
Example 16
@Override
public void populateContextMenu(ContextMenu menu, AdapterView.AdapterContextMenuInfo acmi, int num)
{
    try
    {
        if (readWriteAdapter)
        {
            menu.add(0, R.id.fman_action_refresh, 0, R.string.fman_refresh_title);
            menu.add(0, R.id.fman_action_create_folder, 0, R.string.fman_create_folder_title);
            if (num > 0)
            {
                menu.add(0, R.id.fman_action_rename, 0, R.string.fman_rename_title);
                menu.add(0, R.id.fman_action_delete, 0, R.string.fman_delete_title);
            }
        }
        MenuItem activeSort = null;
        menu.add(0, R.id.fman_action_sort_by_name, 0, R.string.fman_sort_by_name);
        if ((mode & MODE_SORTING) == SORT_NAME)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_name);
        }
        menu.add(0, R.id.fman_action_sort_by_ext, 0, R.string.fman_sort_by_ext);
        if ((mode & MODE_SORTING) == SORT_EXT)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_ext);
        }
        menu.add(0, R.id.fman_action_sort_by_size, 0, R.string.fman_sort_by_size);
        if ((mode & MODE_SORTING) == SORT_SIZE)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_size);
        }
        menu.add(0, R.id.fman_action_sort_by_date, 0, R.string.fman_sort_by_date);
        if ((mode & MODE_SORTING) == SORT_DATE)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_date);
        }
        if (activeSort != null)
        {
            activeSort.setCheckable(true);
            activeSort.setChecked(true);
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
Example 17
Source Project: GestureViews   File: SettingsMenu.java    License: Apache License 2.0 4 votes vote down vote up
private void addBoolMenu(Menu menu, boolean checked, @StringRes int titleId) {
    MenuItem item = menu.add(Menu.NONE, titleId, 0, titleId);
    item.setCheckable(true);
    item.setChecked(checked);
}