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

The following examples show how to use android.view.MenuItem#getItemId() . 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 File: BleProfileServiceReadyActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
	final int id = item.getItemId();
	switch (id) {
		case android.R.id.home:
			onBackPressed();
			break;
		case R.id.action_about:
			final AppHelpFragment fragment = AppHelpFragment.getInstance(getAboutTextId());
			fragment.show(getSupportFragmentManager(), "help_fragment");
			break;
		default:
			return onOptionsItemSelected(id);
	}
	return true;
}
 
Example 2
Source File: PlaceViewActivity.java    From android_coursera_1 with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case R.id.print_badges:
		ArrayList<PlaceRecord> currData = mAdapter.getList();
		for (int i = 0; i < currData.size(); i++) {
			log(currData.get(i).toString());
		}
		return true;
	case R.id.delete_badges:
		mAdapter.removeAllViews();
		return true;
	case R.id.place_one:
		mMockLocationProvider.pushLocation(37.422, -122.084);
		return true;
	case R.id.place_invalid:
		mMockLocationProvider.pushLocation(0, 0);
		return true;
	case R.id.place_two:
		mMockLocationProvider.pushLocation(38.996667, -76.9275);
		return true;
	default:
		return super.onOptionsItemSelected(item);
	}
}
 
Example 3
Source File: SettingsActivity.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    /*
     * Normally, calling setDisplayHomeAsUpEnabled(true) (we do so in onCreate here) as well as
     * declaring the parent activity in the AndroidManifest is all that is required to get the
     * up button working properly. However, in this case, we want to navigate to the previous
     * screen the user came from when the up button was clicked, rather than a single
     * designated Activity in the Manifest.
     *
     * We use the up button's ID (android.R.id.home) to listen for when the up button is
     * clicked and then call onBackPressed to navigate to the previous Activity when this
     * happens.
     */
    int id = item.getItemId();
    if (id == android.R.id.home) {
        onBackPressed();
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 4
Source File: MainActivity.java    From CrepeCake with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 5
Source File: FormRecordListActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case DOWNLOAD_FORMS_FROM_SERVER:
            String source = DeveloperPreferences.getRemoteFormPayloadUrl();
            ArchivedFormRemoteRestore.pullArchivedFormsFromServer(source, this, platform);
            return true;
        case DOWNLOAD_FORMS_FROM_FILE:
            String sourceFile = DeveloperPreferences.getLocalFormPayloadFilePath();
            ArchivedFormRemoteRestore.pullArchivedFormsFromFile(sourceFile, this, platform);
        case MENU_SUBMIT_QUARANTINE_REPORT:
            generateQuarantineReport();
            return true;
        case R.id.barcode_scan_action_bar:
            barcodeScanOnClickListener.onClick(null);
            return true;
        case R.id.menu_settings:
            HomeScreenBaseActivity.createPreferencesMenu(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 6
Source File: HeaderAndFooterViewActivity.java    From RecyclerViewHelper with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.liner_layout:
            mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
            break;

        case R.id.grid_layout:
            mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
            break;
    }
    mDataList.clear();
    getData();
    mRecyclerView.setAdapter(mHeaderAndFooterWrapper);
    return super.onOptionsItemSelected(item);
}
 
Example 7
Source File: GosConfigFailedActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem menu) {
	switch (menu.getItemId()) {
	case android.R.id.home:
		quitAlert(this);
		break;

	default:
		break;
	}

	return true;
}
 
Example 8
Source File: DeveloperPreferences.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId() ) {
        case android.R.id.home:
            onBackPressed();
            overridePendingTransition(R.anim.ease_in_from_left, R.anim.slide_out_to_right);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 9
Source File: AndroidDevelopActivity.java    From gank.io-unofficial-android-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

  if (item.getItemId() == android.R.id.home) {
    onBackPressed();
  }
  return super.onOptionsItemSelected(item);
}
 
Example 10
Source File: MainActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 11
Source File: CourseActionsActivity.java    From PKUCourses with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
    }

    return (super.onOptionsItemSelected(item));
}
 
Example 12
Source File: SearchedSessionsActivity.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
    }
    return super.onOptionsItemSelected(item);
}
 
Example 13
Source File: HistoryActivity.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
  int position = item.getItemId();
  historyManager.deleteHistoryItem(position);
  reloadHistoryItems();
  return true;
}
 
Example 14
Source File: MainActivity.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected (final MenuItem item) {
	switch (item.getItemId()) {
		case android.R.id.home:
			new GotoMenu(this).onClick(this.columnTitleStrip); // TODO FIXME position it correctly under icon.
			return true;
		case R.id.mnuPost:
			showPost();
			return true;
		case R.id.mnuOutbox:
			showOutbox();
			return true;
		case R.id.mnuRefreshColumnNow:
			scheduleRefreshInteractive(getVisibleColumnIds());
			return true;
		case R.id.mnuRefreshAllNow:
			scheduleRefreshInteractive();
			return true;
		case R.id.mnuPreferences:
			startActivity(new Intent(this, OsPreferenceActivity.class));
			return true;
		case R.id.mnuLocalSearch:
			showLocalSearch();
			return true;
		default:
			return super.onOptionsItemSelected(item);
	}
}
 
Example 15
Source File: MainActivity.java    From explorer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case R.id.action_delete:
            actionDelete();
            return true;

        case R.id.action_rename:
            actionRename();
            return true;

        case R.id.action_search:
            actionSearch();
            return true;

        case R.id.action_copy:
            actionCopy();
            return true;

        case R.id.action_move:
            actionMove();
            return true;

        case R.id.action_send:
            actionSend();
            return true;

        case R.id.action_sort:
            actionSort();
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 16
Source File: ActionBarActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 17
Source File: PlayingQueueAdapter.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean onSongMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_remove_from_playing_queue:
            MusicPlayerRemote.removeFromQueue(getAdapterPosition());
            return true;
    }
    return super.onSongMenuItemClick(item);
}
 
Example 18
Source File: MenuGridViewPagerAdapter.java    From flopsydroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isViewFromObject(View view, Object o) {
    MenuItem item = (MenuItem) o;

    int tag = (Integer)view.getTag();
    return item.getItemId() == tag;
}
 
Example 19
Source File: VideoFragment.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.action_refresh) {
        mSwipeRefreshLayout.setRefreshing(true);
        mAdapter.loadFirst();
        return true;
    }
    return false;
}
 
Example 20
Source File: SubsonicFragment.java    From Audinaut with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_global_shuffle:
            onShuffleRequested();
            return true;
        case R.id.menu_refresh:
            refresh(true);
            return true;
        case R.id.menu_play_now:
            playNow(false, false, false);
            return true;
        case R.id.menu_play_last:
            playNow(false, true, false);
            return true;
        case R.id.menu_play_next:
            playNow(false, true, true);
            return true;
        case R.id.menu_shuffle:
            playNow(true, false, false);
            return true;
        case R.id.menu_download:
            downloadBackground(false);
            clearSelected();
            return true;
        case R.id.menu_cache:
            downloadBackground(true);
            clearSelected();
            return true;
        case R.id.menu_delete:
            delete();
            clearSelected();
            return true;
        case R.id.menu_add_playlist:
            List<Entry> songs = getSelectedEntries();
            addToPlaylist(songs);
            clearSelected();
            return true;
    }

    return false;
}