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

The following examples show how to use android.view.MenuItem#isCheckable() . 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: tup.dota2recipe   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param menu
 * @param isRecipe
 *            物品页面,当前物品是否是合成卷轴
 */
public static void configureStarredMenuItem(MenuItem menu, boolean isRecipe) {
    if (menu == null || !menu.isCheckable()) {
        return;
    }
    if (isRecipe) {
        menu.setVisible(false);
        return;
    }

    if (menu.isChecked()) {
        menu.setIcon(R.drawable.ic_action_favorite);
        menu.setTitle(R.string.menu_removefavorite);
    } else {
        menu.setIcon(R.drawable.ic_action_favorite2);
        menu.setTitle(R.string.menu_addfavorite);
    }
}
 
Example 2
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()){
        item.setChecked(!item.isChecked());
    }

    switch (item.getItemId()) {
        case R.id.menu_lock_screen:
            Preferences.setUseLockScreen(item.isChecked());
            break;
        case R.id.menu_back_key_behavior:
            Preferences.setAdjustBackKeyBehavior(item.isChecked());
            mWebView.setAdjustBackKeyBehavior(Preferences.getAdjustBackKeyBehavior());
            break;
        case R.id.menu_hide_admin_menu_items:
            Preferences.setHideAdminMenuItems(item.isChecked());
            mWebView.setHideAdminMenuItems(Preferences.getHideAdminMenuItems());
            break;
        case R.id.menu_hide_top_bar:
            askHidingTopBar();
            break;
    }

    Preferences.save(this);

    return true;
}
 
Example 3
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	if (item.isCheckable() && item.isEnabled()) {
		item.setChecked(!item.isChecked());
	}
	
	int id = item.getItemId();
	if (id == android.R.id.home) {
		finish();
		return true;
	} else if (id == R.id.post_send) {
		try {
			if (Utility.lengthOfString(mText.getText().toString()) <= 140) {
				if (!TextUtils.isEmpty(mText.getText().toString())) {
					new Uploader().execute();
				} else {
					Toast.makeText(this, R.string.empty_weibo, Toast.LENGTH_SHORT).show();
				}
			}
		} catch (Exception e) {
				
		}
		return true;
	} else if (id == R.id.post_pic) {
		if (mBitmap == null){
               showPicturePicker();
           } else {
               // Delete picture
               setPicture(null);
           }
		return true;
	} else if (id == R.id.post_emoticon) {
		if (mDrawer.isDrawerOpen(Gravity.END)) {
			mDrawer.closeDrawer(Gravity.END);
		} else {
			mDrawer.openDrawer(Gravity.END);
		}
		return true;
	} else if (id == R.id.post_at) {
		AtUserSuggestDialog diag = new AtUserSuggestDialog(this);
		diag.setListener(new AtUserSuggestDialog.AtUserListener() {
			@Override
			public void onChooseUser(String name) {
				mText.getText().insert(mText.getSelectionStart(), " @" + name +" ");
			}
		});
		diag.show();
		return true;		
	} else {
		return super.onOptionsItemSelected(item);
	}
}