Java Code Examples for android.view.MenuItem

The following examples show how to use android.view.MenuItem. 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: SmartProxy   Author: oldman1977   File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_activity_actions, menu);

    MenuItem menuItem = menu.findItem(R.id.menu_item_switch);
    if (menuItem == null) {
        return false;
    }

    switchProxy = (Switch) menuItem.getActionView();
    if (switchProxy == null) {
        return false;
    }

    switchProxy.setChecked(LocalVpnService.IsRunning);
    switchProxy.setOnCheckedChangeListener(this);

    return true;
}
 
Example #2
Source Project: codeexamples-android   Author: vogellacompany   File: CardFlipActivity.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
            return true;

        case R.id.action_flip:
            flipCard();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #3
Source Project: PagerTabIndicator   Author: Crysis21   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.text:
            changeTabAdapter(TabAdapterType.TEXT);
            break;
        case R.id.image:
            changeTabAdapter(TabAdapterType.IMAGE);
            break;
        case R.id.web:
            changeTabAdapter(TabAdapterType.WEB);
            break;
        case R.id.custom:
            changeTabAdapter(TabAdapterType.CUSTOM);
            break;
        case R.id.custom_anim:
            changeTabAdapter(TabAdapterType.CUSTOM_ANIM);
            break;
    }
    return true;
}
 
Example #4
Source Project: MyBookshelf   Author: gedoor   File: SearchBookActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.action_book_source_manage:
            BookSourceActivity.startThis(this, requestSource);
            break;
        case android.R.id.home:
            SoftInputUtil.hideIMM(getCurrentFocus());
            finish();
            break;
        default:
            if (item.getGroupId() == R.id.source_group) {
                item.setChecked(true);
                if (Objects.equals(getString(R.string.all_source), item.getTitle().toString())) {
                    MApplication.SEARCH_GROUP = null;
                } else {
                    MApplication.SEARCH_GROUP = item.getTitle().toString();
                }
                mPresenter.initSearchEngineS(MApplication.SEARCH_GROUP);
            }
    }
    return super.onOptionsItemSelected(item);
}
 
Example #5
Source Project: odyssey   Author: gateship-one   File: AllTracksFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 */
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
        case R.id.fragment_all_tracks_action_enqueue:
            enqueueTrack(info.position, false);
            return true;
        case R.id.fragment_all_tracks_action_enqueueasnext:
            enqueueTrack(info.position, true);
            return true;
        case R.id.fragment_all_tracks_action_play:
            playTrack(info.position, false);
            return true;
        case R.id.fragment_all_tracks_showartist:
            showArtist(info.position);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example #6
Source Project: BrokenView   Author: zhanyongsheng   File: MainActivity.java    License: MIT License 6 votes vote down vote up
private void initToolbar(){
    toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_refresh:
                    mBrokenView.reset();
                    refreshDate();
                    setOnTouchListener();
                    setViewVisible();
                    break;
            }
            return true;
        }
    });
}
 
Example #7
Source Project: MultiStateView   Author: XuDaojie   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        // Handle the camera action
    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #8
Source Project: CoolChat   Author: CooLoongWu   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.nav_menu_setting:
            startActivity(new Intent(MainActivity.this, SettingActivity.class));
            break;
        default:
            showToast("暂未开发");
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawer(GravityCompat.START);

            startActivity(new Intent(MainActivity.this, TestActivity.class));
            break;
    }
    return true;
}
 
Example #9
Source Project: Ruisi   Author: xidian-rs   File: UserDetailActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_add) {
        if (!App.isLogin(this)) {
            Snackbar.make(coordinatorLayout, "你还没有登录,无法进行操作", Snackbar.LENGTH_LONG)
                    .setAction("点我登录", view -> startActivity(new Intent(getApplicationContext(), LoginActivity.class))).show();
        } else {
            AddFriendDialog dialogFragment = AddFriendDialog.newInstance(
                    this, username, imageUrl);
            dialogFragment.show(getSupportFragmentManager(), "add");
        }

    }
    return super.onOptionsItemSelected(item);
}
 
Example #10
Source Project: android-SwipeRefreshLayoutBasic   Author: googlearchive   File: SwipeRefreshLayoutBasicFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Respond to the user's selection of the Refresh action item. Start the SwipeRefreshLayout
 * progress bar, then initiate the background task that refreshes the content.
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_refresh:
            Log.i(LOG_TAG, "Refresh menu item selected");

            // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
            if (!mSwipeRefreshLayout.isRefreshing()) {
                mSwipeRefreshLayout.setRefreshing(true);
            }

            // Start our refresh background task
            initiateRefresh();

            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #11
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: PicSelectActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();
        if (itemId == android.R.id.home) {
            this.finish();
            return true;
        } else if (itemId == R.id.action_complete) {

            complete();
            return true;
        }

//            case R.id.action_more:
//                // Get the ActionProvider for later usage
//                provider = (MoreActionProvider) menu.findItem(R.id.menu_share)
//                        .getActionProvider();
//                return true;

        return super.onOptionsItemSelected(item);
    }
 
Example #12
Source Project: Abelana-Android   Author: googlearchive   File: FriendsFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    //Uses a built-in Android intent to display email addresses from your contacts
    if (id == R.id.action_find_friends) {
        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_TYPE);
        startActivityForResult(intent, PICK_CONTACT_REQUEST);
    }
    /* Alternatively, the user can manually input an email address of a friend they'd like to follow.
     * Note, currently the user must already have the app for the follow to work.
     */
    if (id == R.id.manual_friend_search) {
        showDialog();
    }

    return super.onOptionsItemSelected(item);

}
 
Example #13
Source Project: UberClone   Author: IramML   File: Home.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    switch (id){
        case R.id.nav_trip_history:
            showTripHistory();
            break;
        case R.id.nav_updateInformation:
            showDialogUpdateInfo();
            break;
        case R.id.nav_signOut:
            signOut();
            break;
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #14
Source Project: coursera-android   Author: aporter   File: QuotesFragment.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        // Show Toast Messages. Toast Messages are discussed in the lesson on user interface classes
        // return value true indicates that the menu click has been handled

        case R.id.detail_menu_item_main:
            Toast.makeText(getActivity().getApplicationContext(),
                    "This action provided by the QuoteFragment",
                    Toast.LENGTH_SHORT).show();
            return true;

        case R.id.detail_menu_item_secondary:
            Toast.makeText(getActivity().getApplicationContext(),
                    "This action is also provided by the QuoteFragment",
                    Toast.LENGTH_SHORT).show();
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #15
Source Project: material-navigation-drawer   Author: consp1racy   File: MainActivity.java    License: 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.
    // AUTOMATICALLY ONLY ON 4.1+ !!!

    int id = item.getItemId();

    if (id == android.R.id.home) {
        if (mDrawerToggle != null) return mDrawerToggle.onOptionsItemSelected(item);
        if (mSlidingLayout != null) {
            if (mSlidingLayout.isOpen()) mSlidingLayout.closePane();
            else mSlidingLayout.openPane();
            return true;
        }
    }

    return super.onOptionsItemSelected(item);
}
 
Example #16
Source Project: talk-android   Author: jianliaoim   File: TagEditActivity.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;

        case R.id.action_done:
            final String text = mEditText.getText().toString().trim();
            if (!TextUtils.isEmpty(text)) {
                mPresenter.updateTag(mTagId, text);
            }
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #17
Source Project: APDE   Author: Calsign   File: PermissionsActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
        	if (isPreviewSetttings) {
        		promptSaveDataPreviewSettings();
} else {
	finish();
}
            return true;
        case R.id.menu_new_permission:
        	newPermission();
        	return true;
        case R.id.action_settings:
        	launchSettings();
        	return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #18
Source Project: batteryhub   Author: greenhub-project   File: TaskListActivity.java    License: 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) {
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    } else if (id == R.id.action_sort_memory) {
        sortTasksBy(Config.SORT_BY_MEMORY, mSortOrderMemory);
        mSortOrderMemory = -mSortOrderMemory;
        return true;
    } else if (id == R.id.action_sort_name) {
        sortTasksBy(Config.SORT_BY_NAME, mSortOrderName);
        mSortOrderName = -mSortOrderName;
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #19
Source Project: RetroMusicPlayer   Author: deepshooter   File: AlbumsFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) {
    String sortOrder = null;
    switch (item.getItemId()) {
        case R.id.action_sort_order_album:
            sortOrder = AlbumSortOrder.ALBUM_A_Z;
            break;
        case R.id.action_sort_order_album_desc:
            sortOrder = AlbumSortOrder.ALBUM_Z_A;
            break;
        case R.id.action_sort_order_artist:
            sortOrder = AlbumSortOrder.ALBUM_ARTIST;
            break;
    }
    if (sortOrder != null) {
        item.setChecked(true);
        setSaveSortOrder(sortOrder);
    }
    return true;
}
 
Example #20
Source Project: Loop   Author: lawloretienne   File: VideoDetailsFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public boolean onOptionsItemSelected(final MenuItem item) {
        switch (item.getItemId()) {
            case R.id.share:
                if (video != null) {
//                    EventLogger.fire(ProductShareEvent.start(mProduct.getId()));

                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    sendIntent.setType("text/plain");
                    sendIntent.putExtra(Intent.EXTRA_TEXT,
                            String.format("I found this on Loop. Check it out.\n\n%s\n\n%s", video.getName(), video.getLink()));

                    String title = getResources().getString(R.string.share_this_video);
                    Intent chooser = Intent.createChooser(sendIntent, title);

                    if (sendIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                        startActivityForResult(chooser, VIDEO_SHARE_REQUEST_CODE);
                    }
                }
                return true;
            default:
                break;
        }

        return super.onOptionsItemSelected(item);
    }
 
Example #21
Source Project: tapchat-android   Author: tapchat   File: MemberListActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override public boolean onOptionsItemSelected(MenuItem item) {
    long connectionId = getIntent().getLongExtra(BufferFragment.ARG_CONNECTION_ID, -1);
    long bufferId     = getIntent().getLongExtra(BufferFragment.ARG_BUFFER_ID, -1);

    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(this, BuffersActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setData(Uri.parse(String.format("tapchat://%s/%s", connectionId, bufferId)));
        startActivity(intent);
        return true;
    }
    return false;
}
 
Example #22
Source Project: BooheeScrollView   Author: zhaozhentao   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id){
        case R.id.normal:
            booheeScrollView.setAnimType(BooheeScrollView.NORMAL_ANIM);
            break;
        case R.id.rebound:
            booheeScrollView.setAnimType(BooheeScrollView.REBOUND_ANIM);
            break;
    }
    return true;
}
 
Example #23
Source Project: my-first-realm-app   Author: realm   File: ChatRoomActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_logout) {
        SyncUser syncUser = SyncUser.current();
        if (syncUser != null) {
            syncUser.logOut();
            Intent intent = new Intent(this, WelcomeActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #24
Source Project: TemplateAppProject   Author: xuexiangjys   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 处理侧边栏点击事件
 *
 * @param menuItem
 * @return
 */
private boolean handleNavigationItemSelected(@NonNull MenuItem menuItem) {
    int index = CollectionUtils.arrayIndexOf(mTitles, menuItem.getTitle());
    if (index != -1) {
        toolbar.setTitle(menuItem.getTitle());
        viewPager.setCurrentItem(index, false);
        return true;
    }
    return false;
}
 
Example #25
Source Project: animation-samples   Author: android   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example #26
Source Project: android-map-sdk   Author: navermaps   File: MapClickEventActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #27
Source Project: Game-of-Thrones   Author: tonilopezmr   File: DetailActivity.java    License: 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 true;
}
 
Example #28
Source Project: intra42   Author: pvarry   File: BasicActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Called when an item in the navigation menu is selected.
 *
 * @param item The selected item
 * @return true to display the item as the selected item
 */
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Navigation.onNavigationItemSelected(this, item);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #29
Source Project: MessagingAndroidChat   Author: realtime-framework   File: ChatRoomActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #30
Source Project: twittererer   Author: zfoltin   File: TimelineActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_tweet) {
        showNewTweetDialog();
        return true;
    }
    return super.onOptionsItemSelected(item);
}