Example usage for android.view MenuItem getIntent

List of usage examples for android.view MenuItem getIntent

Introduction

In this page you can find the example usage for android.view MenuItem getIntent.

Prototype

public Intent getIntent();

Source Link

Document

Return the Intent associated with this item.

Usage

From source file:syncthing.android.ui.LauncherActivity.java

void setupNavigation(Bundle savedInstanceState) {
    mNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//  w w w  .jav  a2  s. co  m
        public boolean onNavigationItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.manage_devices:
                closeDrawers();
                startDeviceManageActivity();
                return true;
            case R.id.app_settings:
                closeDrawers();
                startSettingsActivity();
                return true;
            default:
                break;
            }
            Intent intent = item.getIntent();
            if (intent != null && intent.hasExtra(ManageActivity.EXTRA_CREDENTIALS)) {
                clearCheckedMenuItems();
                item.setChecked(true);
                closeDrawers();

                intent.setExtrasClassLoader(LauncherActivity.class.getClassLoader());
                Credentials credentials = intent.getParcelableExtra(ManageActivity.EXTRA_CREDENTIALS);
                openSession(credentials);
                return true;
            }
            return false;
        }
    });
    Credentials current = mSettings.getDefaultCredentials();
    populateNavigationMenu(current, savedInstanceState == null);
}

From source file:app.umitems.greenclock.DeskClock.java

private boolean processMenuClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_settings:
        startActivity(new Intent(DeskClock.this, SettingsActivity.class));
        return true;
    case R.id.menu_item_help:
        Intent i = item.getIntent();
        if (i != null) {
            try {
                startActivity(i);//w  w  w. jav a 2 s .co m
            } catch (ActivityNotFoundException e) {
                // No activity found to match the intent - ignore
            }
        }
        return true;
    case R.id.menu_item_night_mode:
        startActivity(new Intent(DeskClock.this, ScreensaverActivity.class));
    default:
        break;
    }
    return true;
}

From source file:com.android.deskclock.Back_DeskClock.java

private boolean processMenuClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_settings:
        startActivity(new Intent(Back_DeskClock.this, SettingsActivity.class));
        return true;
    case R.id.menu_item_help:
        Intent i = item.getIntent();
        if (i != null) {
            try {
                startActivity(i);/*from  ww  w  .j  av  a2 s.  co m*/
            } catch (ActivityNotFoundException e) {
                // No activity found to match the intent - ignore
            }
        }
        return true;
    case R.id.menu_item_night_mode:
        startActivity(new Intent(Back_DeskClock.this, ScreensaverActivity.class));
    default:
        break;
    }
    return true;
}

From source file:com.android.deskclock.worldclock.CitiesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();//from w  w w  .j  av a2 s .  c o m
        return true;
    case R.id.menu_item_settings:
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    case R.id.menu_item_help:
        Intent i = item.getIntent();
        if (i != null) {
            try {
                startActivity(i);
            } catch (ActivityNotFoundException e) {
                // No activity found to match the intent - ignore
            }
        }
        return true;
    case R.id.menu_item_sort:
        if (mAdapter != null) {
            mAdapter.toggleSort();
            setFastScroll(TextUtils.isEmpty(mQueryTextBuffer.toString().trim()));
        }
        return true;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.embeddedlog.LightUpDroid.DeskClock.java

private boolean processMenuClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_settings:
        startActivity(new Intent(DeskClock.this, SettingsActivity.class));
        return true;
    case R.id.menu_item_help:
        Intent i = item.getIntent();
        if (i != null) {
            try {
                startActivity(i);/*from w  w w.  j a va  2  s.c  o  m*/
            } catch (ActivityNotFoundException e) {
                // No activity found to match the intent - ignore
            }
        }
        return true;
    case R.id.menu_item_night_mode:
        startActivity(new Intent(DeskClock.this, ScreensaverActivity.class));
    case R.id.menu_item_sync_lightuppi:
        // TODO: update LightUpPiSync to actually sync alarms and then update this bit
        return true;
    case R.id.menu_item_push_to_lightuppi:
        // TODO: update LightUpPiSync to actually push alarms and then update this bit
        return true;
    case R.id.menu_item_push_to_phone:
        // TODO: update LightUpPiSync to actually push alarms and then update this bit
        String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX;
        new LightUpPiSync(this, correctString).syncPushToPhone();
        return true;
    case R.id.menu_item_reset_db:
        // Delete the database
        ContentResolver cr = this.getContentResolver();
        cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null);

        // Restart the app to repopulate db with default and recreate activities.
        Intent mStartActivity = new Intent(this, DeskClock.class);
        int mPendingIntentId = 123456;
        PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
        System.exit(0);
        return true;
    default:
        break;
    }
    return true;
}

From source file:com.numberx.kkmctimer.DeskClock.java

private boolean processMenuClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_settings:
        startActivity(new Intent(DeskClock.this, SettingsActivity.class));
        return true;
    case R.id.menu_item_help:
        Intent i = item.getIntent();
        if (i != null) {
            try {
                startActivity(i);/*from  ww w  .j  av a  2 s .c  o  m*/
            } catch (ActivityNotFoundException e) {
                // No activity found to match the intent - ignore
            }
        }
        return true;
    case R.id.menu_item_night_mode:
        startActivity(new Intent(DeskClock.this, ScreensaverActivity.class));
    case R.id.menu_item_sync_kkmctimer:
        // TODO: update KKMCTimerSync to actually sync alarms and then update this bit
        return true;
    case R.id.menu_item_push_to_kkmctimer:
        // TODO: update KKMCTimerSync to actually push alarms and then update this bit
        return true;
    case R.id.menu_item_push_to_phone:
        // TODO: update KKMCTimerSync to actually push alarms and then update this bit
        String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX;
        new KKMCTimerSync(this, correctString).syncPushToPhone();
        return true;
    case R.id.menu_item_reset_db:
        // Delete the database
        ContentResolver cr = this.getContentResolver();
        cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null);

        // Restart the app to repopulate db with default and recreate activities.
        Intent mStartActivity = new Intent(this, DeskClock.class);
        int mPendingIntentId = 123456;
        PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
        System.exit(0);
        return true;
    default:
        break;
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.BaseUsersListFragment.java

@Override
public boolean onMenuItemClick(final MenuItem item) {
    if (mSelectedUser == null)
        return false;
    switch (item.getItemId()) {
    case MENU_VIEW_PROFILE: {
        openUserProfile(getActivity(), mSelectedUser);
        break;/*from  w w w .j a  v  a2s  .c  o m*/
    }
    case MENU_MULTI_SELECT: {
        if (!mApplication.isMultiSelectActive()) {
            mApplication.startMultiSelect();
        }
        final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems();
        if (!list.contains(mSelectedUser)) {
            list.add(mSelectedUser);
        }
        break;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:com.guayaba.tapir.ui.fragments.profile.ArtistAlbumFragment.java

/**
 * {@inheritDoc}/*from   w  w w .j a  v  a 2s  .c o  m*/
 */
@Override
public boolean onContextItemSelected(final MenuItem item) {
    // Avoid leaking context menu selections
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), mAlbumList, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), mAlbumList);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(mAlbumList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long id = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), mAlbumList, id);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mAlbum.mAlbumName, mAlbumList, null).show(getFragmentManager(),
                    "DeleteDialog");
            refresh();
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.boko.vimusic.ui.fragments.profile.ArtistAlbumFragment.java

/**
 * {@inheritDoc}// w w w .  j a  va 2 s.  c  o  m
 */
@Override
public boolean onContextItemSelected(final MenuItem item) {
    // Avoid leaking context menu selections
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), mAlbumList, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), mAlbumList);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(mAlbumList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final String id = item.getIntent().getStringExtra("playlist");
            MusicUtils.addToPlaylist(getActivity(), mAlbumList, id);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mAlbum.getName(), mAlbumList, null).show(getFragmentManager(),
                    "DeleteDialog");
            refresh();
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.andrew.apollo.ui.fragments.profile.ArtistAlbumFragment.java

/**
 * {@inheritDoc}/*w  ww . j  a v  a  2s  .co m*/
 */
@Override
public boolean onContextItemSelected(final MenuItem item) {
    // Avoid leaking context menu selections
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getSherlockActivity(), mAlbumList, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getSherlockActivity(), mAlbumList);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(mAlbumList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long id = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getSherlockActivity(), mAlbumList, id);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mAlbum.mAlbumName, mAlbumList, null).show(getFragmentManager(),
                    "DeleteDialog");
            refresh();
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}