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.github.tdudziak.gps_lock_lock.ControlActivity.java

@Override
protected void onResume() {
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this);
    IntentFilter filter = new IntentFilter(LockService.ACTION_UI_UPDATE);
    bm.registerReceiver(mUiUpdateBroadcastReceiver, filter);

    // request UI update broadcast from the service
    Intent intent = new Intent(LockService.ACTION_UI_UPDATE);
    intent.setClass(this, LockService.class);
    startService(intent);/*from www. ja  va  2s  .  c  o m*/
    setStatus(0);

    // if service is already running we can update status text immediately
    LockService service = ((LockApplication) getApplication()).getLockService();
    if (service != null) {
        setStatus(service.getRemainingTime());
    }

    // update text on "Restart" list item
    String format = getResources().getString(R.string.menu_restart);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    int lock_time = prefs.getInt("lockTime", 5);
    mMenuAdapter.getItemById(R.id.menuItemRestart).title = String.format(format, lock_time);
    mMenuAdapter.notifyDataSetChanged();

    super.onResume();
}

From source file:com.lepin.activity.AddNewCarActivity.java

@Override
public void onClick(View v) {
    if (v == addBack) {
        AddNewCarActivity.this.finish();
    } else if (v == typeLayout) {
        Intent intent = new Intent();
        intent.setClass(AddNewCarActivity.this, SelectCarBrandActivity.class);
        startActivityForResult(intent, 5);
    } else if (v == numLayout) {
        choicePeoPleNumber();/*from   w  ww  .j  a v  a  2 s  .  co m*/
    } else if (v == addSave) {
        if (checkData()) {
            addNewCarInfo();
        }
    }
}

From source file:com.springsource.greenhouse.authorization.SignInActivity.java

private void displayGreenhouseOptions() {
    Intent intent = new Intent();
    intent.setClass(this, MainActivity.class);
    startActivity(intent);/*from  w  w w  .j a  v  a  2 s  . c  o m*/
    setResult(RESULT_OK);
    finish();
}

From source file:com.bhb27.isu.services.BootBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // only run if the app has run before and main has extracted asserts
    String action = intent.getAction();
    boolean run_boot = Tools.getBoolean("run_boot", false, context);
    boolean rootAccess = Tools.rootAccess(context);
    if (Intent.ACTION_BOOT_COMPLETED.equals(action) && rootAccess && run_boot) {
        Log.d(TAG, " Started action " + action + " run_boot " + run_boot);

        if (Tools.getBoolean("prop_run", false, context) && Tools.getBoolean("apply_props", false, context))
            ContextCompat.startForegroundService(context, new Intent(context, PropsService.class));

        ContextCompat.startForegroundService(context, new Intent(context, BootService.class));

        if (Tools.getBoolean("apply_su", false, context) && Tools.SuVersionBool(Tools.SuVersion(context))) {

            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            Intent serviceIntent = new Intent("com.bhb27.isu.services.SuServiceReceiver.RUN");
            serviceIntent.putExtra("RUN", 100);
            serviceIntent.setClass(context, SuServiceReceiver.class);
            serviceIntent.setAction("RUN");

            PendingIntent pi = PendingIntent.getBroadcast(context, 100, serviceIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                    + Integer.valueOf(Tools.readString("apply_su_delay", "0", context)), pi);
        }/*from ww  w  . j a  v  a 2s. com*/

    } else
        Log.d(TAG, "Not Started action " + action + " rootAccess " + rootAccess + " run_boot " + run_boot);
}

From source file:li.klass.fhem.fragments.SendCommandFragment.java

private void sendCommandIntent(String command) {
    final Context context = getActivity();
    Intent intent = new Intent(Actions.EXECUTE_COMMAND);
    intent.setClass(getActivity(), SendCommandIntentService.class);
    intent.putExtra(BundleExtraKeys.COMMAND, command);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override//w  w  w.  j  a  v  a 2 s. c o m
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultData != null && resultCode == ResultCodes.SUCCESS
                    && resultData.containsKey(BundleExtraKeys.COMMAND_RESULT)) {
                String result = resultData.getString(BundleExtraKeys.COMMAND_RESULT);
                if (result == null || result.equals("")) {
                    update(false);
                    return;
                }

                if (isEmpty(result.replaceAll("[\\r\\n]", "")))
                    return;
                new AlertDialog.Builder(context).setTitle(R.string.command_execution_result).setMessage(result)
                        .setPositiveButton(R.string.okButton, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.cancel();
                                update(false);
                            }
                        }).show();
            }
        }
    });
    getActivity().startService(intent);
}

From source file:com.example.parking.MobilePaymentActivity.java

private void changeSelect(int resId) {
    mTwoDimensionsCodeTitleTV.setSelected(false);
    mTwoDimensionsCodeTitleTV.setBackgroundResource(R.color.gray);
    mScanTitleTV.setSelected(false);//from   ww  w  .  j  a  va2  s  .  com
    mScanTitleTV.setBackgroundResource(R.color.gray);
    switch (resId) {
    case R.id.tv_mobile_payment_two_dimensions_code:
        mTwoDimensionsCodeTitleTV.setSelected(true);
        mTwoDimensionsCodeTitleTV.setBackgroundResource(R.color.orange);
        break;
    case R.id.tv_mobile_payment_scan:
        mScanTitleTV.setSelected(true);
        mScanTitleTV.setBackgroundResource(R.color.orange);
        //Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent();
        intent.setClass(MobilePaymentActivity.this, CaptureActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
        break;
    }
}

From source file:ca.ualberta.cs.shoven_habittracker.AllHabitsActivity.java

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    Intent intent = new Intent();
    intent.setClass(this, HabitHomepageActivity.class);
    Bundle bundle = new Bundle();
    bundle.putInt("position", position);
    bundle.putString("activity", "AllHabitsActivity");
    intent.putExtras(bundle);/*from w w w  . j  a v a  2s. com*/
    startActivity(intent);
}

From source file:com.innoc.secureline.ui.UpgradeCallDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
        builder = new AlertDialog.Builder(
                new ContextThemeWrapper(getActivity(), R.style.RedPhone_Light_Dialog));
    } else {/*from   w w w.ja v  a 2  s. c o  m*/
        builder = new AlertDialog.Builder(getActivity(), R.style.RedPhone_Light_Dialog);
    }

    builder.setIcon(R.drawable.red_call);

    final String upgradeString = getActivity().getResources()
            .getString(R.string.RedPhoneChooser_upgrade_to_redphone);
    SpannableStringBuilder titleBuilder = new SpannableStringBuilder(upgradeString);
    titleBuilder.setSpan(new AbsoluteSizeSpan(20, true), 0, upgradeString.length(),
            Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    builder.setTitle(titleBuilder);

    //builder.setMessage(R.string.RedPhoneChooser_this_contact_also_uses_redphone_would_you_like_to_upgrade_to_a_secure_call);

    builder.setPositiveButton(R.string.RedPhoneChooser_secure_call, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(getActivity(), SecureLineService.class);
            intent.setAction(SecureLineService.ACTION_OUTGOING_CALL);
            intent.putExtra(Constants.REMOTE_NUMBER, number);
            getActivity().startService(intent);

            Intent activityIntent = new Intent();
            activityIntent.setClass(getActivity(), SecureLine.class);
            activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(activityIntent);

            getActivity().finish();
        }
    });

    builder.setNegativeButton(R.string.RedPhoneChooser_insecure_call, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            CallChooserCache.getInstance().addInsecureChoice(number);

            Intent intent = new Intent("android.intent.action.CALL",
                    Uri.fromParts("tel", number + CallListener.IGNORE_SUFFIX, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            getActivity().finish();
        }
    });

    AlertDialog alert = builder.create();

    alert.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ((AlertDialog) dialog).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    getActivity().finish();
                }
            });

            ((AlertDialog) dialog).setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    getActivity().finish();
                }
            });
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);

            Button negativeButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
        }
    });

    return alert;
}

From source file:com.mindprotectionkit.freephone.ui.UpgradeCallDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
        builder = new AlertDialog.Builder(
                new ContextThemeWrapper(getActivity(), R.style.RedPhone_Light_Dialog));
    } else {//from   w w w  .  j a v a 2 s.  com
        builder = new AlertDialog.Builder(getActivity(), R.style.RedPhone_Light_Dialog);
    }

    builder.setIcon(R.drawable.red_call);

    final String upgradeString = getActivity().getResources()
            .getString(R.string.RedPhoneChooser_upgrade_to_redphone);
    SpannableStringBuilder titleBuilder = new SpannableStringBuilder(upgradeString);
    titleBuilder.setSpan(new AbsoluteSizeSpan(20, true), 0, upgradeString.length(),
            Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    builder.setTitle(titleBuilder);

    //builder.setMessage(R.string.RedPhoneChooser_this_contact_also_uses_redphone_would_you_like_to_upgrade_to_a_secure_call);

    builder.setPositiveButton(R.string.RedPhoneChooser_secure_call, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(getActivity(), RedPhoneService.class);
            intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
            intent.putExtra(Constants.REMOTE_NUMBER, number);
            getActivity().startService(intent);

            Intent activityIntent = new Intent();
            activityIntent.setClass(getActivity(), RedPhone.class);
            activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(activityIntent);

            getActivity().finish();
        }
    });

    builder.setNegativeButton(R.string.RedPhoneChooser_insecure_call, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            CallChooserCache.getInstance().addInsecureChoice(number);

            Intent intent = new Intent("android.intent.action.CALL",
                    Uri.fromParts("tel", number + CallListener.IGNORE_SUFFIX, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            getActivity().finish();
        }
    });

    AlertDialog alert = builder.create();

    alert.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ((AlertDialog) dialog).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    getActivity().finish();
                }
            });

            ((AlertDialog) dialog).setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    getActivity().finish();
                }
            });
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);

            Button negativeButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
        }
    });

    return alert;
}

From source file:li.klass.fhem.fragments.SendCommandFragment.java

@Override
public void update(boolean doUpdate) {
    Intent intent = new Intent(Actions.RECENT_COMMAND_LIST);
    intent.setClass(getActivity(), SendCommandIntentService.class);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override/*from w  w  w . j  a v a2s .  c o m*/
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode != ResultCodes.SUCCESS || resultData == null
                    || !resultData.containsKey(BundleExtraKeys.RECENT_COMMANDS)) {
                return;
            }

            View view = getView();
            if (view == null)
                return;

            recentCommands = resultData.getStringArrayList(BundleExtraKeys.RECENT_COMMANDS);
            recentCommandsAdapter.clear();

            // careful: addAll method is only available since API level 11 (Android 3.0)
            for (String recentCommand : recentCommands) {
                recentCommandsAdapter.add(recentCommand);
            }
            recentCommandsAdapter.notifyDataSetChanged();

            ListViewUtil.setHeightBasedOnChildren((ListView) view.findViewById(R.id.command_history));

            getActivity().sendBroadcast(new Intent(Actions.DISMISS_EXECUTING_DIALOG));
        }
    });
    getActivity().startService(intent);
}