Java Code Examples for com.actionbarsherlock.view.MenuItem

The following are top voted examples for showing how to use com.actionbarsherlock.view.MenuItem. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CSipSimple   File: MenuBuilder.java   View source code 7 votes vote down vote up
public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
            }
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }

    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}
 
Example 2
Project: CSipSimple   File: DialerFragment.java   View source code 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    int action = getResources().getBoolean(R.bool.menu_in_bar) ? MenuItem.SHOW_AS_ACTION_IF_ROOM : MenuItem.SHOW_AS_ACTION_NEVER;
    MenuItem delMenu = menu.add(isDigit ? R.string.switch_to_text : R.string.switch_to_digit);
    delMenu.setIcon(
            isDigit ? R.drawable.ic_menu_switch_txt
                    : R.drawable.ic_menu_switch_digit).setShowAsAction( action );
    delMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            setTextDialing(isDigit);
            return true;
        }
    });
}
 
Example 3
Project: CSipSimple   File: MenuItemImpl.java   View source code 6 votes vote down vote up
public MenuItem setActionView(View view) {
    mActionView = view;
    mActionProvider = null;
    if (view != null && view.getId() == View.NO_ID && mId > 0) {
        view.setId(mId);
    }
    mMenu.onItemActionRequestChanged(this);
    return this;
}
 
Example 4
Project: CSipSimple   File: ActionMenuPresenter.java   View source code 6 votes vote down vote up
public ActionButtonSubmenu(Context context, SubMenuBuilder subMenu) {
    super(context, subMenu);
    //UNUSED mSubMenu = subMenu;

    MenuItemImpl item = (MenuItemImpl) subMenu.getItem();
    if (!item.isActionButton()) {
        // Give a reasonable anchor to nested submenus.
        setAnchorView(mOverflowButton == null ? (View) mMenuView : mOverflowButton);
    }

    setCallback(mPopupPresenterCallback);

    boolean preserveIconSpacing = false;
    final int count = subMenu.size();
    for (int i = 0; i < count; i++) {
        MenuItem childItem = subMenu.getItem(i);
        if (childItem.isVisible() && childItem.getIcon() != null) {
            preserveIconSpacing = true;
            break;
        }
    }
    setForceShowIcon(preserveIconSpacing);
}
 
Example 5
Project: CSipSimple   File: ActionBarView.java   View source code 6 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable p) {
    SavedState state = (SavedState) p;

    super.onRestoreInstanceState(state.getSuperState());

    if (state.expandedMenuItemId != 0 &&
            mExpandedMenuPresenter != null && mOptionsMenu != null) {
        final MenuItem item = mOptionsMenu.findItem(state.expandedMenuItemId);
        if (item != null) {
            item.expandActionView();
        }
    }

    if (state.isOverflowOpen) {
        postShowOverflowMenu();
    }
}
 
Example 6
Project: CSipSimple   File: MenuBuilder.java   View source code 6 votes vote down vote up
public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;
    }

    SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(
            getActionViewStatesKey());

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && viewStates == null) {
        //Fixes Issue #652 with sdk <= 2.3.6
        return;
    }

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            v.restoreHierarchyState(viewStates);
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.restoreActionViewStates(states);
        }
    }

    final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
    if (expandedId > 0) {
        MenuItem itemToExpand = findItem(expandedId);
        if (itemToExpand != null) {
            itemToExpand.expandActionView();
        }
    }
}
 
Example 7
Project: CSipSimple   File: MenuPopupHelper.java   View source code 6 votes vote down vote up
@Override
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (subMenu.hasVisibleItems()) {
        MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mAnchorView, false);
        subPopup.setCallback(mPresenterCallback);

        boolean preserveIconSpacing = false;
        final int count = subMenu.size();
        for (int i = 0; i < count; i++) {
            MenuItem childItem = subMenu.getItem(i);
            if (childItem.isVisible() && childItem.getIcon() != null) {
                preserveIconSpacing = true;
                break;
            }
        }
        subPopup.setForceShowIcon(preserveIconSpacing);

        if (subPopup.tryShow()) {
            if (mPresenterCallback != null) {
                mPresenterCallback.onOpenSubMenu(subMenu);
            }
            return true;
        }
    }
    return false;
}
 
Example 8
Project: CSipSimple   File: Watson.java   View source code 6 votes vote down vote up
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item);

    if (featureId == Window.FEATURE_OPTIONS_PANEL) {
        if (onOptionsItemSelected(item)) {
            return true;
        }

        if (mFragments.mAdded != null) {
            for (int i = 0; i < mFragments.mAdded.size(); i++) {
                Fragment f = mFragments.mAdded.get(i);
                if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible && f instanceof OnOptionsItemSelectedListener) {
                    if (((OnOptionsItemSelectedListener)f).onOptionsItemSelected(item)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 9
Project: CSipSimple   File: PrefsFilters.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == Compatibility.getHomeMenuId()) {
        finish();
        return true;
    }
    return false;
}
 
Example 10
Project: CSipSimple   File: MainPrefs.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(PrefsLogic.onMainActivityOptionsItemSelected(item, this, prefsWrapper)) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 11
Project: CSipSimple   File: MainPrefs.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(PrefsLogic.onMainActivityOptionsItemSelected(item, this, prefsWrapper)) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 12
Project: CSipSimple   File: ActionMenuPresenter.java   View source code 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState saved = (SavedState) state;
    if (saved.openSubMenuId > 0) {
        MenuItem item = mMenu.findItem(saved.openSubMenuId);
        if (item != null) {
            SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            onSubMenuSelected(subMenu);
        }
    }
}
 
Example 13
Project: Huochexing12306   File: ResetPwdAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch(item.getItemId()){
	case android.R.id.home:
		startActivity(new Intent(this, LoginAty.class));
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 14
Project: CSipSimple   File: MenuItemImpl.java   View source code 5 votes vote down vote up
public MenuItem setCheckable(boolean checkable) {
    final int oldFlags = mFlags;
    mFlags = (mFlags & ~CHECKABLE) | (checkable ? CHECKABLE : 0);
    if (oldFlags != mFlags) {
        mMenu.onItemsChanged(false);
    }

    return this;
}
 
Example 15
Project: Huochexing12306   File: MoreAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		startActivity(new Intent(this, MainActivity.class));
		finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 16
Project: CSipSimple   File: MenuItemImpl.java   View source code 5 votes vote down vote up
public MenuItem setIcon(Drawable icon) {
    mIconResId = NO_ICON;
    mIconDrawable = icon;
    mMenu.onItemsChanged(false);

    return this;
}
 
Example 17
Project: CSipSimple   File: MessageActivity.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == Compatibility.getHomeMenuId()) {
        finish();
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 18
Project: CSipSimple   File: ActionMenuPresenter.java   View source code 5 votes vote down vote up
private View findViewForItem(MenuItem item) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null) return null;

    final int count = parent.getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = parent.getChildAt(i);
        if (child instanceof MenuView.ItemView &&
                ((MenuView.ItemView) child).getItemData() == item) {
            return child;
        }
    }
    return null;
}
 
Example 19
Project: CSipSimple   File: ShareActionProvider.java   View source code 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext,
            mShareHistoryFileName);
    final int itemId = item.getItemId();
    Intent launchIntent = dataModel.chooseActivity(itemId);
    if (launchIntent != null) {
        mContext.startActivity(launchIntent);
    }
    return true;
}
 
Example 20
Project: CSipSimple   File: AccountsEditListFragment.java   View source code 5 votes vote down vote up
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    final SipProfile account = profileFromContextMenuInfo(item.getMenuInfo());
       if (account == null) {
           // For some reason the requested item isn't available, do nothing
           return super.onContextItemSelected(item);
       }
       
       switch (item.getItemId()) {
           case MENU_ITEM_DELETE: {
               getActivity().getContentResolver().delete(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), null, null);
               return true;
           }
           case MENU_ITEM_MODIFY : {
               showDetails(account.id, account.wizard);
               return true;
           }
           case MENU_ITEM_ACTIVATE: {
               ContentValues cv = new ContentValues();
               cv.put(SipProfile.FIELD_ACTIVE, ! account.active);
               getActivity().getContentResolver().update(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), cv, null, null);
               return true;
           }
           case MENU_ITEM_WIZARD:{
               Intent it = new Intent(getActivity(), WizardChooser.class);
               it.putExtra(Intent.EXTRA_UID, account.id);
               startActivityForResult(it, CHANGE_WIZARD);
               return true;
           }
       }
       return super.onContextItemSelected(item);

}
 
Example 21
Project: Huochexing12306   File: HuoCheXingAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch(item.getItemId()){
	case android.R.id.home:
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 22
Project: CSipSimple   File: CallLogDetailsActivity.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId() == Compatibility.getHomeMenuId()) {
         finish();
         return true;
    }

       return super.onOptionsItemSelected(item);
}
 
Example 23
Project: Huochexing12306   File: EditPassengerAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		startActivity(new Intent(this, PassengerMangAty.class));
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 24
Project: CSipSimple   File: BasePrefsWizard.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case SAVE_MENU:
		saveAndFinish();
		return true;
	case TRANSFORM_MENU:
		startActivityForResult(new Intent(this, WizardChooser.class), CHOOSE_WIZARD);
		return true;
	case DELETE_MENU:
		if (account.id != SipProfile.INVALID_ID) {
			getContentResolver().delete(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), null, null);
			setResult(RESULT_OK, getIntent());
			finish();
		}
		return true;
	case FILTERS_MENU:
		if (account.id != SipProfile.INVALID_ID) {
			Intent it = new Intent(this, AccountFilters.class);
			it.putExtra(SipProfile.FIELD_ID, account.id);
			it.putExtra(SipProfile.FIELD_DISPLAY_NAME, account.display_name);
			it.putExtra(SipProfile.FIELD_WIZARD, account.wizard);
			startActivityForResult(it, MODIFY_FILTERS);
			return true;
		}
		break;
	default:
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 25
Project: Huochexing12306   File: EditMonitorAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 26
Project: CSipSimple   File: SherlockPreferenceActivity.java   View source code 5 votes vote down vote up
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    if (featureId == Window.FEATURE_OPTIONS_PANEL) {
        return onOptionsItemSelected(item);
    }
    return false;
}
 
Example 27
Project: CSipSimple   File: SherlockListActivity.java   View source code 5 votes vote down vote up
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    if (featureId == Window.FEATURE_OPTIONS_PANEL) {
        return onOptionsItemSelected(item);
    }
    return false;
}
 
Example 28
Project: CSipSimple   File: MenuItemImpl.java   View source code 5 votes vote down vote up
public MenuItem setTitleCondensed(CharSequence title) {
    mTitleCondensed = title;

    // Could use getTitle() in the loop below, but just cache what it would do here
    if (title == null) {
        title = mTitle;
    }

    mMenu.onItemsChanged(false);

    return this;
}
 
Example 29
Project: CSipSimple   File: SherlockFragmentActivity.java   View source code 5 votes vote down vote up
@Override
public final boolean onMenuItemSelected(int featureId, android.view.MenuItem item) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item.getTitle());

    if (featureId == Window.FEATURE_OPTIONS_PANEL && !mIgnoreNativeSelected) {
        mIgnoreNativeSelected = true;
        boolean result = getSherlock().dispatchOptionsItemSelected(item);
        mIgnoreNativeSelected = false;

        if (ActionBarSherlock.DEBUG) Log.d(TAG, "[onMenuItemSelected] returning " + result);
        return result;
    }
    return super.onMenuItemSelected(featureId, item);
}
 
Example 30
Project: CSipSimple   File: SherlockActivity.java   View source code 5 votes vote down vote up
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    if (featureId == Window.FEATURE_OPTIONS_PANEL) {
        return onOptionsItemSelected(item);
    }
    return false;
}
 
Example 31
Project: Huochexing12306   File: AboutAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 32
Project: Huochexing12306   File: EditTextAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch(item.getItemId()){
	case android.R.id.home:
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 33
Project: Huochexing12306   File: A6UserInfoAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 34
Project: Huochexing12306   File: TrainInfoAty.java   View source code 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		startActivity(new Intent(this, MainActivity.class));
		this.finish();
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 35
Project: Huochexing12306   File: TrainSchListAty.java   View source code 5 votes vote down vote up
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
	QueryLeftNewDTOInfo qlndInfo = mLstInfos.get(intCurrDataPos).getQueryLeftNewDTO();
	switch (item.getItemId()) {
	case 0:
		 Intent intent = new Intent(TrainSchListAty.this, AddInfoAty.class);
		 intent.putExtra(AddInfoAty.TRAIN_NUM, qlndInfo.getStation_train_code());
		 intent.putExtra(AddInfoAty.START_STATION, qlndInfo.getFrom_station_name());
		 intent.putExtra(AddInfoAty.END_STATION, qlndInfo.getTo_station_name());
		 intent.putExtra(AddInfoAty.DATA_SOURCE, AddInfoAty.DATA_FROM_NEWWORK);
		 startActivity(intent);
		break;
	case 1:
		mBInfo.setTrain_no(qlndInfo.getTrain_no());
		mBInfo.setFrom_station_no(qlndInfo.getFrom_station_no());
		mBInfo.setTo_station_no(qlndInfo.getTo_station_no());
		mBInfo.setSeat_types(qlndInfo.getSeat_types());
		Intent intent1 = new Intent(TrainSchListAty.this,
				TrainDetailAty.class);
		Train train = new Train();
		train.setTrain_no(qlndInfo.getTrain_no());
		train.setTrainNum(qlndInfo.getStation_train_code());
		train.setStartStation(qlndInfo.getFrom_station_name());
		train.setEndStation(qlndInfo.getTo_station_name());
		train.setD_Time(qlndInfo.getStart_time());
		train.setA_Time(qlndInfo.getArrive_time());
		train.setD_LateTime(String.valueOf(qlndInfo.getD_LateTime()));
		train.setA_LateTime(String.valueOf(qlndInfo.getA_LateTime()));
		train.setR_Date(qlndInfo.getLishi());
		intent1.putExtra(TrainDetailAty.TRAIN, train);
		startActivity(intent1);
		break;
	}
	return super.onContextItemSelected(item);
}
 
Example 36
Project: CSipSimple   File: MenuItemImpl.java   View source code 5 votes vote down vote up
public MenuItem setEnabled(boolean enabled) {
    if (enabled) {
        mFlags |= ENABLED;
    } else {
        mFlags &= ~ENABLED;
    }

    mMenu.onItemsChanged(false);

    return this;
}
 
Example 37
Project: CSipSimple   File: MenuBuilder.java   View source code 5 votes vote down vote up
public int addIntentOptions(int group, int id, int categoryOrder, ComponentName caller,
        Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) {
    PackageManager pm = mContext.getPackageManager();
    final List<ResolveInfo> lri =
            pm.queryIntentActivityOptions(caller, specifics, intent, 0);
    final int N = lri != null ? lri.size() : 0;

    if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
        removeGroup(group);
    }

    for (int i=0; i<N; i++) {
        final ResolveInfo ri = lri.get(i);
        Intent rintent = new Intent(
            ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
        rintent.setComponent(new ComponentName(
                ri.activityInfo.applicationInfo.packageName,
                ri.activityInfo.name));
        final MenuItem item = add(group, id, categoryOrder, ri.loadLabel(pm))
                .setIcon(ri.loadIcon(pm))
                .setIntent(rintent);
        if (outSpecificItems != null && ri.specificIndex >= 0) {
            outSpecificItems[ri.specificIndex] = item;
        }
    }

    return N;
}
 
Example 38
Project: CSipSimple   File: MenuBuilder.java   View source code 5 votes vote down vote up
void setExclusiveItemChecked(MenuItem item) {
    final int group = item.getGroupId();

    final int N = mItems.size();
    for (int i = 0; i < N; i++) {
        MenuItemImpl curItem = mItems.get(i);
        if (curItem.getGroupId() == group) {
            if (!curItem.isExclusiveCheckable()) continue;
            if (!curItem.isCheckable()) continue;

            // Check the item meant to be checked, uncheck the others (that are in the group)
            curItem.setCheckedInt(curItem == item);
        }
    }
}
 
Example 39
Project: CSipSimple   File: MenuItemImpl.java   View source code 5 votes vote down vote up
public MenuItem setTitle(CharSequence title) {
    mTitle = title;

    mMenu.onItemsChanged(false);

    if (mSubMenu != null) {
        mSubMenu.setHeaderTitle(title);
    }

    return this;
}
 
Example 40
Project: CSipSimple   File: ActionBarImpl.java   View source code 5 votes vote down vote up
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
    if (mCallback != null) {
        return mCallback.onActionItemClicked(this, item);
    } else {
        return false;
    }
}