Example usage for android.content Intent setClass

List of usage examples for android.content Intent setClass

Introduction

In this page you can find the example usage for android.content Intent setClass.

Prototype

public @NonNull Intent setClass(@NonNull Context packageContext, @NonNull Class<?> cls) 

Source Link

Document

Convenience for calling #setComponent(ComponentName) with the name returned by a Class object.

Usage

From source file:com.miz.mizuu.fragments.TvShowLibraryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
    case R.id.update:
        Intent intent = new Intent();
        intent.setClass(mContext, Update.class);
        intent.putExtra("isMovie", false);
        startActivityForResult(intent, 0);
        break;//from   w  ww.  j  a va 2s  . co  m
    case R.id.menuSortNewestEpisode:
        mTvShowLoader.setSortType(TvShowSortType.NEWEST_EPISODE);
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortRating:
        mTvShowLoader.setSortType(TvShowSortType.RATING);
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortWeightedRating:
        mTvShowLoader.setSortType(TvShowSortType.WEIGHTED_RATING);
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortRelease:
        mTvShowLoader.setSortType(TvShowSortType.FIRST_AIR_DATE);
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortTitle:
        mTvShowLoader.setSortType(TvShowSortType.TITLE);
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortDuration:
        mTvShowLoader.setSortType(TvShowSortType.DURATION);
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.genres:
        mTvShowLoader.showGenresFilterDialog(getActivity());
        break;
    case R.id.certifications:
        mTvShowLoader.showCertificationsFilterDialog(getActivity());
        break;
    case R.id.folders:
        mTvShowLoader.showFoldersFilterDialog(getActivity());
        break;
    case R.id.fileSources:
        mTvShowLoader.showFileSourcesFilterDialog(getActivity());
        break;
    case R.id.release_year:
        mTvShowLoader.showReleaseYearFilterDialog(getActivity());
        break;
    case R.id.offline_files:
        mTvShowLoader.addFilter(new TvShowFilter(TvShowFilter.OFFLINE_FILES));
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.available_files:
        mTvShowLoader.addFilter(new TvShowFilter(TvShowFilter.AVAILABLE_FILES));
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.clear_filters:
        mTvShowLoader.clearFilters();
        mTvShowLoader.load();
        showProgressBar();
        break;
    case R.id.random:
        if (mAdapter.getCount() > 0) {
            int random = new Random().nextInt(mAdapter.getCount());
            viewTvShowDetails(random, null);
        }
        break;
    case R.id.unidentifiedFiles:
        startActivity(new Intent(mContext, UnidentifiedTvShows.class));
        break;
    }

    return true;
}

From source file:com.npi.muzeiflickr.ui.activities.SettingsActivity.java

@Override
protected void onPause() {
    super.onPause();
    managePhotoFromSourceDeletion();/*from   w w w .j  av  a 2  s .c o  m*/

    //Launch an update if a source has been added
    if (mSourceAdded) {
        Intent intent = new Intent(FlickrSource.ACTION_RELOAD_SOME_PHOTOS);
        intent.setClass(this, FlickrSource.class);
        startService(intent);
    }
}

From source file:com.android.deskclock.timer.TimerReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (Timers.LOGGING) {
        Log.v(TAG, "Received intent " + intent.toString());
    }//w ww . j av a2  s  .  c  o  m
    String actionType = intent.getAction();
    // This action does not need the timers data
    if (Timers.NOTIF_IN_USE_CANCEL.equals(actionType)) {
        cancelInUseNotification(context);
        return;
    }

    // Get the updated timers data.
    if (mTimers == null) {
        mTimers = new ArrayList<>();
    }
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    TimerObj.getTimersFromSharedPrefs(prefs, mTimers);

    if (AlarmService.PRE_SHUTDOWN_ACTION.equals(actionType)) {
        // Stop Ringtone if all timers are not in times-up status
        TimerObj timerRing = Timers.findExpiredTimer(mTimers);
        if (timerRing != null) {
            timerRing.mState = TimerObj.STATE_STOPPED;
            stopRingtoneIfNoTimesup(context);
        }
        return;
    }

    // These actions do not provide a timer ID, but do use the timers data
    if (Timers.NOTIF_IN_USE_SHOW.equals(actionType)) {
        showInUseNotification(context);
        return;
    } else if (Timers.NOTIF_TIMES_UP_SHOW.equals(actionType)) {
        showTimesUpNotification(context);
        return;
    } else if (Timers.NOTIF_TIMES_UP_CANCEL.equals(actionType)) {
        cancelTimesUpNotification(context);
        return;
    }

    // Remaining actions provide a timer Id
    if (!intent.hasExtra(Timers.TIMER_INTENT_EXTRA)) {
        // No data to work with, do nothing
        Log.e(TAG, "got intent without Timer data");
        return;
    }

    // Get the timer out of the Intent
    int timerId = intent.getIntExtra(Timers.TIMER_INTENT_EXTRA, -1);
    if (timerId == -1) {
        Log.d(TAG, "OnReceive:intent without Timer data for " + actionType);
    }

    TimerObj t = Timers.findTimer(mTimers, timerId);

    if (Timers.TIMES_UP.equals(actionType)) {
        // Find the timer (if it doesn't exists, it was probably deleted).
        if (t == null) {
            Log.d(TAG, " timer not found in list - do nothing");
            return;
        }

        t.setState(TimerObj.STATE_TIMESUP);
        t.writeToSharedPref(prefs);
        Events.sendEvent(R.string.category_timer, R.string.action_fire, 0);
        /// M: We acquire the lock here because in some rare scenario, the wake lock is release
        /// by alarm before it could be acquired by Timer activity causing state to be suspended
        AlarmAlertWakeLock.acquireScreenCpuWakeLock(context);

        // Play ringtone by using TimerRingService service with a default alarm.
        Log.d(TAG, "playing ringtone");
        Intent si = new Intent();
        si.setClass(context, TimerRingService.class);
        context.startService(si);

        // Update the in-use notification
        if (getNextRunningTimer(mTimers, false, Utils.getTimeNow()) == null) {
            // Found no running timers.
            cancelInUseNotification(context);
        } else {
            showInUseNotification(context);
        }

        /**
         * M: To show time up notification to avoid the case: pausing the
         * current activity(eg: touch home key) when time is up, it cause
         * the TimerAlertFullScreen can not be started, and this cause no
         * notification in status bar but the timer has sound. @{
         */
        Utils.showTimesUpNotifications(context);
        /** @} */
        // Start the TimerAlertFullScreen activity.
        Intent timersAlert = new Intent(context, TimerAlertFullScreen.class);
        timersAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
        context.startActivity(timersAlert);
    } else if (Timers.RESET_TIMER.equals(actionType) || Timers.DELETE_TIMER.equals(actionType)
            || Timers.TIMER_DONE.equals(actionType)) {
        // Stop Ringtone if all timers are not in times-up status
        stopRingtoneIfNoTimesup(context);

        if (t != null) {
            cancelTimesUpNotification(context, t);
        }
    } else if (Timers.NOTIF_TIMES_UP_STOP.equals(actionType)) {
        // Find the timer (if it doesn't exists, it was probably deleted).
        if (t == null) {
            Log.d(TAG, "timer to stop not found in list - do nothing");
            return;
        } else if (t.mState != TimerObj.STATE_TIMESUP) {
            Log.d(TAG, "action to stop but timer not in times-up state - do nothing");
            return;
        }

        // Update timer state
        t.setState(t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_RESTART);
        t.mTimeLeft = t.mOriginalLength = t.mSetupLength;
        t.writeToSharedPref(prefs);

        // Flag to tell DeskClock to re-sync with the database
        prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply();

        cancelTimesUpNotification(context, t);

        // Done with timer - delete from data base
        if (t.getDeleteAfterUse()) {
            t.deleteFromSharedPref(prefs);
        }

        // Stop Ringtone if no timers are in times-up status
        stopRingtoneIfNoTimesup(context);
    } else if (Timers.NOTIF_TIMES_UP_PLUS_ONE.equals(actionType)) {
        // Find the timer (if it doesn't exists, it was probably deleted).
        if (t == null) {
            Log.d(TAG, "timer to +1m not found in list - do nothing");
            return;
        } else if (t.mState != TimerObj.STATE_TIMESUP) {
            Log.d(TAG, "action to +1m but timer not in times up state - do nothing");
            return;
        }

        // Restarting the timer with 1 minute left.
        t.setState(TimerObj.STATE_RUNNING);
        t.mStartTime = Utils.getTimeNow();
        t.mTimeLeft = t.mOriginalLength = TimerObj.MINUTE_IN_MILLIS;
        t.writeToSharedPref(prefs);

        // Flag to tell DeskClock to re-sync with the database
        prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply();

        cancelTimesUpNotification(context, t);

        // If the app is not open, refresh the in-use notification
        if (!prefs.getBoolean(Timers.NOTIF_APP_OPEN, false)) {
            showInUseNotification(context);
        }

        // Stop Ringtone if no timers are in times-up status
        stopRingtoneIfNoTimesup(context);
    } else if (Timers.TIMER_UPDATE.equals(actionType)) {
        // Find the timer (if it doesn't exists, it was probably deleted).
        if (t == null) {
            Log.d(TAG, " timer to update not found in list - do nothing");
            return;
        }

        // Refresh buzzing notification
        if (t.mState == TimerObj.STATE_TIMESUP) {
            // Must cancel the previous notification to get all updates displayed correctly
            cancelTimesUpNotification(context, t);
            showTimesUpNotification(context, t);
        }
    }
    if (intent.getBooleanExtra(Timers.UPDATE_NEXT_TIMESUP, true)) {
        // Update the next "Times up" alarm unless explicitly told not to.
        updateNextTimesup(context);
    }
}

From source file:li.klass.fhem.appwidget.view.widget.medium.TargetStateWidgetView.java

@Override
protected void fillWidgetView(Context context, RemoteViews view, FhemDevice<?> device,
        WidgetConfiguration widgetConfiguration) {
    String payload = widgetConfiguration.payload.get(1);
    String state = device.getEventMapStateFor(payload);

    view.setTextViewText(R.id.button, state);

    PendingIntent pendingIntent;//from  www .j  a  v a  2  s.c  o m
    if (requiresAdditionalInformation(state)) {
        Intent actionIntent = new Intent(context, TargetStateAdditionalInformationActivity.class);
        actionIntent.putExtra(BundleExtraKeys.DEVICE_NAME, device.getName());
        actionIntent.putExtra(BundleExtraKeys.DEVICE_TARGET_STATE, payload);
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        pendingIntent = PendingIntent.getActivity(context, widgetConfiguration.widgetId, actionIntent,
                FLAG_UPDATE_CURRENT);
    } else {
        Intent actionIntent = new Intent(Actions.DEVICE_SET_STATE);
        actionIntent.setClass(context, DeviceIntentService.class);
        actionIntent.putExtra(BundleExtraKeys.DEVICE_NAME, device.getName());
        actionIntent.putExtra(BundleExtraKeys.DEVICE_TARGET_STATE, payload);

        pendingIntent = PendingIntent.getService(context, widgetConfiguration.widgetId, actionIntent,
                FLAG_UPDATE_CURRENT);
    }

    view.setOnClickPendingIntent(R.id.button, pendingIntent);

    openDeviceDetailPageWhenClicking(R.id.main, view, device, widgetConfiguration, context);
}

From source file:com.android.music.AlbumBrowserFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case PLAY_SELECTION: {
        // play the selected album
        long[] list = MusicUtils.getSongListForAlbum(getActivity(), Long.parseLong(mCurrentAlbumId));
        MusicUtils.playAll(getActivity(), list, 0);
        return true;
    }/* w w w  .  j a  va  2s .co m*/

    case QUEUE: {
        long[] list = MusicUtils.getSongListForAlbum(getActivity(), Long.parseLong(mCurrentAlbumId));
        MusicUtils.addToCurrentPlaylist(getActivity(), list);
        return true;
    }

    case NEW_PLAYLIST: {
        Intent intent = new Intent();
        intent.setClass(getActivity(), CreatePlaylist.class);
        startActivityForResult(intent, NEW_PLAYLIST);
        return true;
    }

    case PLAYLIST_SELECTED: {
        long[] list = MusicUtils.getSongListForAlbum(getActivity(), Long.parseLong(mCurrentAlbumId));
        long playlist = item.getIntent().getLongExtra("playlist", 0);
        MusicUtils.addToPlaylist(getActivity(), list, playlist);
        return true;
    }
    case DELETE_ITEM: {
        long[] list = MusicUtils.getSongListForAlbum(getActivity(), Long.parseLong(mCurrentAlbumId));
        String f;
        if (android.os.Environment.isExternalStorageRemovable()) {
            f = getString(R.string.delete_album_desc);
        } else {
            f = getString(R.string.delete_album_desc_nosdcard);
        }
        String desc = String.format(f, mCurrentAlbumName);
        Bundle b = new Bundle();
        b.putString("description", desc);
        b.putLongArray("items", list);
        Intent intent = new Intent();
        intent.setClass(getActivity(), DeleteItems.class);
        intent.putExtras(b);
        startActivityForResult(intent, -1);
        return true;
    }
    case SEARCH:
        doSearch();
        return true;

    }
    return super.onContextItemSelected(item);
}

From source file:bmcx.aiton.com.passenger.view.activity.SmsLoginActivity.java

@Override
public void onClick(View v) {
    Intent intent = new Intent();
    switch (v.getId()) {
    case R.id.textView_frogetPassword:
        intent.setClass(SmsLoginActivity.this, UpdatePasswordActivity.class);
        startActivity(intent);/*w  w w.jav  a  2 s .c o  m*/
        break;
    case R.id.textView_register:
        intent.setClass(SmsLoginActivity.this, RegisterActivity.class);
        startActivity(intent);
        break;
    case R.id.textView_quickLogin:
        isQuickLogin = true;
        mTextView_quickLogin.setTextColor(basicColor);
        mTextView_accountLogin.setTextColor(mSystem_gray);
        Animation animation = new TranslateAnimation(offset, 0, 0, 0);
        animation.setFillAfter(true);// True:???
        animation.setDuration(300);
        mImageView_tiao01.startAnimation(animation);
        mLogin.setVisibility(View.GONE);
        mLinear_quickLogin.setVisibility(View.VISIBLE);
        mLinear_accountLogin.setVisibility(View.INVISIBLE);
        break;
    case R.id.textView_accountLogin:
        isQuickLogin = false;
        mTextView_accountLogin.setTextColor(basicColor);
        mTextView_quickLogin.setTextColor(mSystem_gray);
        Animation animation02 = new TranslateAnimation(0, offset, 0, 0);
        animation02.setFillAfter(true);// True:???
        animation02.setDuration(300);
        mImageView_tiao01.startAnimation(animation02);
        mLogin.setVisibility(View.VISIBLE);
        mLinear_quickLogin.setVisibility(View.INVISIBLE);
        mLinear_accountLogin.setVisibility(View.VISIBLE);
        break;
    case R.id.login:
        if (isQuickLogin) {
            if (mSuijiMath.equals(mSms.getText().toString().trim())) {
                //?
                final String DeviceId = Installation.id(SmsLoginActivity.this);
                //??????????----start----//
                Map<String, String> params = new HashMap<>();
                params.put("phone", mPhoneNum);
                params.put("login_id", DeviceId);
                ApiClient.smsLogingSuccess(SmsLoginActivity.this, params, new VolleyListener() {
                    public void onErrorResponse(VolleyError volleyError) {
                    }

                    public void onResponse(String s) {
                        Log.e("SmsLoginActivity", "onResponse: --??????->>" + s);

                        mUser = GsonUtils.parseJSON(s, User.class);
                        if (mUser.isSuccess()) {
                            Log.e("SmsLoginActivity",
                                    "onResponse: --????->>"
                                            + mLoginState.isLogin());
                            toast("??");
                            //????????
                            mLoginState.login(SmsLoginActivity.this);
                            Log.e("SmsLoginActivity",
                                    "onResponse: --?????->>"
                                            + mLoginState.isLogin());
                            //???id??
                            UserLoginInfo userLoginInfo = new UserLoginInfo(mPhoneNum,
                                    "" + mUser.getContains().getId(), DeviceId, mUser.getContains().getImage(),
                                    mUser.getContains().getIdCardImage(),
                                    mUser.getContains().getIdCardImage_back(),
                                    mUser.getContains().getDrivingLicenseImage(),
                                    mUser.getContains().getDrivingLicenseImage_back());
                            mLoginState.setLoginInfo(userLoginInfo);
                            Log.e("SmsLoginActivity",
                                    "onResponse: --?->>" + mLoginState.getLoginInfo().toString());
                            //?
                            MobclickAgent.onProfileSignIn(mPhoneNum);
                            finish();
                        } else {
                            toast(mUser.getMessage());
                        }
                    }
                });
                //??????????----end----//
            } else {
                toast("?");
            }
        } else {
            mPhoneNum = mEditText_phoneNum.getText().toString().trim();
            String password = mEditText_password.getText().toString().trim();
            //?
            final String DeviceId = Installation.id(SmsLoginActivity.this);
            Map<String, String> map = new HashMap<>();
            map.put("phone", mPhoneNum);
            map.put("login_id", DeviceId);
            map.put("password", password);
            ApiClient.passWordLoginSuccess(SmsLoginActivity.this, map, new VolleyListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {

                }

                @Override
                public void onResponse(String s) {
                    mUser = GsonUtils.parseJSON(s, User.class);
                    if (mUser.isSuccess()) {
                        Log.e("SmsLoginActivity", "onResponse: --????->>"
                                + mLoginState.isLogin());
                        //????????
                        mLoginState.login(SmsLoginActivity.this);
                        Log.e("SmsLoginActivity",
                                "onResponse: --?????->>"
                                        + mLoginState.isLogin());
                        //???id??
                        UserLoginInfo userLoginInfo = new UserLoginInfo(mPhoneNum,
                                "" + mUser.getContains().getId(), DeviceId, mUser.getContains().getImage(),
                                mUser.getContains().getIdCardImage(), mUser.getContains().getIdCardImage_back(),
                                mUser.getContains().getDrivingLicenseImage(),
                                mUser.getContains().getDrivingLicenseImage_back());
                        mLoginState.setLoginInfo(userLoginInfo);
                        toast("?");
                        //?
                        MobclickAgent.onProfileSignIn(mPhoneNum);
                        finish();
                        //                                Intent intent = new Intent();
                        //                                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        //                                intent.setClass(SmsLoginActivity.this, MainActivity.class);
                        //                                startActivity(intent);
                    } else {
                        toast("???");
                    }

                }
            });
        }
        break;
    case R.id.iv_org_detailback:
        finish();
        AnimFromRightToLeft();
        break;
    case R.id.phone_num_cancle:
        mPhone_num.setText("");
        break;
    case R.id.sms_cancle:
        mSms.setText("");
        break;
    case R.id.sendSms:
        if (ContextCompat.checkSelfPermission(SmsLoginActivity.this,
                Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
            //WRITE_EXTERNAL_STORAGE??
            ActivityCompat.requestPermissions(SmsLoginActivity.this,
                    new String[] { Manifest.permission.READ_SMS },
                    Constant.PermissionRequestAndResultCode.PERMISSION_READ_SMS);
        } else {
            sendSMS();
        }

        break;
    }
}

From source file:com.miz.mizuu.fragments.MovieLibraryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
    case R.id.update:
        Intent intent = new Intent();
        intent.setClass(mContext, Update.class);
        intent.putExtra("isMovie", true);
        startActivityForResult(intent, 0);
        break;//from   ww w. ja va2  s. c o  m
    case R.id.menuSortAdded:
        mMovieLoader.setSortType(MovieSortType.DATE_ADDED);
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortRating:
        mMovieLoader.setSortType(MovieSortType.RATING);
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortWeightedRating:
        mMovieLoader.setSortType(MovieSortType.WEIGHTED_RATING);
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortRelease:
        mMovieLoader.setSortType(MovieSortType.RELEASE);
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortTitle:
        mMovieLoader.setSortType(MovieSortType.TITLE);
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.menuSortDuration:
        mMovieLoader.setSortType(MovieSortType.DURATION);
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.genres:
        mMovieLoader.showGenresFilterDialog(getActivity());
        break;
    case R.id.certifications:
        mMovieLoader.showCertificationsFilterDialog(getActivity());
        break;
    case R.id.folders:
        mMovieLoader.showFoldersFilterDialog(getActivity());
        break;
    case R.id.fileSources:
        mMovieLoader.showFileSourcesFilterDialog(getActivity());
        break;
    case R.id.release_year:
        mMovieLoader.showReleaseYearFilterDialog(getActivity());
        break;
    case R.id.offline_files:
        mMovieLoader.addFilter(new MovieFilter(MovieFilter.OFFLINE_FILES));
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.available_files:
        mMovieLoader.addFilter(new MovieFilter(MovieFilter.AVAILABLE_FILES));
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.clear_filters:
        mMovieLoader.clearFilters();
        mMovieLoader.load();
        showProgressBar();
        break;
    case R.id.random:
        if (mAdapter.getCount() > 0) {
            int random = new Random().nextInt(mAdapter.getCount());
            viewMovieDetails(random, null);
        }
        break;
    case R.id.unidentifiedFiles:
        startActivity(new Intent(mContext, UnidentifiedMovies.class));
        break;
    }

    return true;
}

From source file:ca.zadrox.dota2esportticker.ui.MatchActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intentx;
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        setRefreshingState(true);/*  w  w  w  .  jav  a2 s.  co m*/
        onRefresh();
        break;
    case R.id.menu_debug_notify:
        intentx = new Intent(ReminderAlarmService.ACTION_NOTIFY_DEBUG);
        intentx.setClass(this, ReminderAlarmService.class);
        this.startService(intentx);
        return true;
    case R.id.menu_debug_view_live_match:
        final Intent intent = new Intent(this, LiveGameStatsActivity.class);
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLL, (String) null);
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLR, (String) null);
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_BO, "best of 1");
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNL, "Invasion");
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNR, "Koopa");
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TN, "awesome");

        final Context mContext = this;

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Enter Match Id:");

        // Set an EditText view to get user input
        final EditText input = new EditText(this);
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                intent.putExtra(LiveGameStatsActivity.ARGS_GAME_MID,
                        Long.parseLong(input.getText().toString()));
                mContext.startActivity(intent);
            }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });

        alert.show();

        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.fbbackup.MyFriendFragmentActivity.java

@SuppressLint("NewApi")
public void setLisetner() {

    // Tag//from   w  ww.jav a  2s. co  m
    btn_tag_me.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Fragment newFragment = new TagMeImageGridFragment();

            Bundle args = new Bundle();
            args.putString("token", token);
            args.putStringArray("tagMePicture", tagMePicture);
            args.putString("userName", friendsName[0]);

            newFragment.setArguments(args);

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.rl_user_photo, newFragment, "first");
            ft.addToBackStack(null);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            ft.commit();

            controlPanelHandler.sendEmptyMessage(HIDE_CONTROL_PANEL);
        }

    });

    btn_cancel_download.setOnClickListener(new ImageButton.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            downloadTask.cancel(true);
            downloadTaskNoUI.cancel(true);
            rl_prb_download.setVisibility(View.GONE);
            hasCancel = true;
        }

    });

    // Photo
    btn_photo.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Fragment newFragment = new MyFriendFragment();

            Bundle args = new Bundle();
            args.putStringArray("friendPic", friendsPicture);
            args.putStringArray("friendName", friendsName);
            args.putStringArray("friendID", friendsID);
            args.putString("token", token);

            newFragment.setArguments(args);

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.rl_user_photo, newFragment, "first");

            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            ft.commit();

        }
    });

    btn_logout.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads()
                        .detectDiskWrites().detectNetwork() // or
                        // .detectAll()
                        // for
                        // all
                        // detectable
                        // problems
                        .penaltyLog().build());
                StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                        .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

            }

            try {
                facebook.logout(MyFriendFragmentActivity.this);

                Toast.makeText(MyFriendFragmentActivity.this, "FB logout", Toast.LENGTH_LONG).show();

            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            SharedPreferences mPrefs = getSharedPreferences(MainActivity.FIRST_LOGIN_PREFERENCE, MODE_PRIVATE);

            Log.w("Ryan", "S:" + mPrefs.getBoolean(MainActivity.FIRST_LOGIN, true));

            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putBoolean(MainActivity.FIRST_LOGIN, true);
            editor.commit();

            Log.w("Ryan", "F:" + mPrefs.getBoolean(MainActivity.FIRST_LOGIN, true));

            Intent it = new Intent();
            it.setClass(MyFriendFragmentActivity.this, MainActivity.class);
            startActivity(it);
            finish();

        }

    });
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*from   ww w  .j  av  a2s .  c  o  m*/
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.add_new_safe_my) {
        try {
            DD.load_listing_directories();
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this.getApplicationContext(), "Error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG)
                    .show();
            // return;
        }

        if ((Identity.getListing_directories_addr().size() <= 0)) {
            Toast.makeText(this,
                    "To add your safe, first add a directory from the Manage Directories top-right menu!",
                    Toast.LENGTH_LONG).show();
            return super.onOptionsItemSelected(item);
        }
        Toast.makeText(this, "add a new safe my", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent();
        intent.setClass(this, AddSafe.class);
        startActivityForResult(intent, Main.RESULT_ADD_PEER);
    }

    if (item.getItemId() == R.id.add_new_safe_other) {
        if ((Identity.getListing_directories_addr().size() <= 0)) {
            Toast.makeText(this,
                    "To add a safe, first add a directory from the Manage Directories top-right menu!",
                    Toast.LENGTH_LONG).show();
            return super.onOptionsItemSelected(item);
        }
        Toast.makeText(this, "add a new safe other", Toast.LENGTH_SHORT).show();

        if (Build.VERSION.SDK_INT < 19) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(intent, SELECT_PHOTO);
        } else {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.setType("image/*");
            startActivityForResult(intent, SELECT_PHOTO_KITKAT);
        }
    }

    if (item.getItemId() == R.id.add_new_org) {
        Toast.makeText(this, "add a new organization", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent();
        intent.setClass(this, AddOrg.class);
        startActivity(intent);
    }

    if (item.getItemId() == R.id.action_directories) {
        Toast.makeText(this, "adding a directory", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent();
        intent.setClass(this, SelectDirectoryServer.class);
        startActivity(intent);
    }

    if (item.getItemId() == R.id.action_loadAddresss) {

        FragmentManager fm = getSupportFragmentManager();
        LoadPK loadPKDialog = new LoadPK();
        loadPKDialog.show(fm, "fragment_send_public_key");

    }

    // not yet implemented!
    if (item.getItemId() == R.id.action_start_directory) {

        Intent i = new Intent();
        i.setClass(this, StartDirectoryServer.class);
        startActivity(i);
    }

    if (item.getItemId() == R.id.action_settings) {
        Intent intent = new Intent();
        intent.setClass(this, Setting.class);
        startActivity(intent);
    }

    return super.onOptionsItemSelected(item);
}