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:org.openremote.android.console.model.PollingHelper.java

/**
 * Handle server error with status code.
 * If request timeout, return and start a new request.
 * //  ww w  .jav  a 2s. c om
 * @param statusCode the status code
 */
private void handleServerErrorWithStatusCode(int statusCode) {
    if (statusCode != Constants.HTTP_SUCCESS) {
        httpGet = null;
        if (statusCode == ControllerException.GATEWAY_TIMEOUT) { // polling timeout, need to refresh
            return;
        }
        if (statusCode == ControllerException.REFRESH_CONTROLLER) {
            Main.prepareToastForRefreshingController();
            Intent refreshControllerIntent = new Intent();
            refreshControllerIntent.setClass(context, Main.class);
            context.startActivity(refreshControllerIntent);
            // Notify the groupactiviy to finish.
            ORListenerManager.getInstance().notifyOREventListener(ListenerConstant.FINISH_GROUP_ACTIVITY, null);
            return;
        } else {
            isPolling = false;
            handler.sendEmptyMessage(statusCode);
        }
    }
}

From source file:com.cloudbees.gasp.activity.PlacesActivity.java

private void showDetails(PlaceDetails placeDetails) {
    try {//ww w . jav a  2  s .  c  o  m
        Intent intent = new Intent();
        intent.setClass(PlacesActivity.this, PlacesDetailActivity.class);
        intent.putExtra(PlacesDetailActivity.PLACES_DETAIL_SERIALIZED, placeDetails.getResult());
        intent.putExtra(PlacesDetailActivity.PLACES_DETAIL_REFERENCE, mReference);
        startActivityForResult(intent, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.csipsimple.plugins.betamax.CallHandlerWeb.java

@Override
public void onReceive(Context context, Intent intent) {
    if (Utils.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // We must handle that clean way cause when call just to
        // get the row in account list expect this to reply correctly
        if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr)
                && !TextUtils.isEmpty(pwd) && !TextUtils.isEmpty(provider)) {
            // Build pending intent
            Intent i = new Intent(ACTION_DO_WEB_CALL);
            i.setClass(context, getClass());
            i.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
            pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

        }//from  w  w w. j  a  v a  2 s  .  c  o m

        // Build icon
        Bitmap bmp = Utils.getBitmapFromResource(context, R.drawable.icon_web);

        // Build the result for the row (label, icon, pending intent, and
        // excluded phone number)
        Bundle results = getResultExtras(true);
        if (pendingIntent != null) {
            results.putParcelable(Utils.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }

        // Text for the row
        String providerName = "";
        Resources r = context.getResources();
        if (!TextUtils.isEmpty(provider)) {
            String[] arr = r.getStringArray(R.array.provider_values);
            String[] arrEntries = r.getStringArray(R.array.provider_entries);
            int i = 0;
            for (String prov : arr) {
                if (prov.equalsIgnoreCase(provider)) {
                    providerName = arrEntries[i];
                    break;
                }
                i++;
            }
        }
        results.putString(Intent.EXTRA_TITLE, providerName + " " + r.getString(R.string.web_callback));
        Log.d(THIS_FILE, "icon is " + bmp);
        if (bmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp);
        }

        // DO *NOT* exclude from next tel: intent cause we use a http method
        // results.putString(Intent.EXTRA_PHONE_NUMBER, number);

    } else if (ACTION_DO_WEB_CALL.equals(intent.getAction())) {

        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // params
        List<NameValuePair> params = new LinkedList<NameValuePair>();
        params.add(new BasicNameValuePair("username", user));
        params.add(new BasicNameValuePair("password", pwd));
        params.add(new BasicNameValuePair("from", nbr));
        params.add(new BasicNameValuePair("to", number));
        String paramString = URLEncodedUtils.format(params, "utf-8");

        String requestURL = "https://www." + provider + "/myaccount/makecall.php?" + paramString;

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(requestURL);

        // Create a response handler
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpGet);
            Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent());
                BufferedReader br = new BufferedReader(isr);

                String line;
                String fullReply = "";
                boolean foundSuccess = false;
                while ((line = br.readLine()) != null) {
                    if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) {
                        showToaster(context, "Success... wait a while you'll called back");
                        foundSuccess = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(line)) {
                        fullReply = fullReply.concat(line);
                    }
                }
                if (!foundSuccess) {
                    showToaster(context, "Error : server error : " + fullReply);
                }
            } else {
                showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode());
            }
        } catch (ClientProtocolException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        } catch (IOException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        }

    }
}

From source file:com.redhorse.quickstart.AppAll.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    case ITEM_ID_SETTING:
        break;//from  ww w  .  j  ava  2s  .c o m
    case ITEM_ID_ABOUT:
        Intent setting = new Intent();
        setting.setClass(AppAll.this, Feedback.class);
        startActivity(setting);
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.idt.ontomedia.geoconsum.NearPlacesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.places_near);

    //Initialize some values
    mNearPlaceList = new ArrayList<NearPlace>();
    mDistances = getResources().getStringArray(R.array.distances_to_places);

    mSpinnerTypeOfLocation = (Spinner) findViewById(R.id.spinner1);
    mSpinnerTypeOfLocation.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override//from   w w  w.  j  av a  2  s. co m
        public void onItemSelected(AdapterView<?> _containerView, View _itemView, int _position, long _id) {
            getSupportLoaderManager().getLoader(NEAR_PLACES_LOADER_ID).onContentChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> _containerView) {

        }
    });

    mSpinnerDistances = (Spinner) findViewById(R.id.spinner2);
    mSpinnerDistances.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> _containerView, View _itemView, int _position, long _id) {
            getSupportLoaderManager().getLoader(NEAR_PLACES_LOADER_ID).onContentChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> _containerView) {

        }
    });

    ImageButton buttonUpdate = (ImageButton) findViewById(R.id.buttonUpdate);
    buttonUpdate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View _view) {
            getSupportLoaderManager().getLoader(NEAR_PLACES_LOADER_ID).onContentChanged();
        }
    });

    // Configure the adapter and set the spinner of distances
    // This is a programatically operation because we can't modify the text color 
    // with the use of "entries" in the xml file. We define an ArrayAdapter and specify the layout of this to avoid
    // the default layout with the normal text style (black and normal)
    ArrayAdapter<String> arrayAdapterDistances = new ArrayAdapter<String>(this, R.layout.my_spinner_layout,
            mDistances);
    arrayAdapterDistances.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerDistances.setAdapter(arrayAdapterDistances);

    // Configure the adapter and set the spinner of types of Places
    // This is a programatically operation because we can't modify the text color 
    // with the use of "entries" in the xml file. We define an ArrayAdapter and specify the layout of this to avoid
    // the default layout with the normal text style (black and normal)
    mAdapterTypeOfLocation = new SimpleCursorAdapter(this, R.layout.my_spinner_layout, null, COLUMNS_FROM,
            VIEWS_TO, 0);
    mAdapterTypeOfLocation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerTypeOfLocation.setAdapter(mAdapterTypeOfLocation);
    mSpinnerTypeOfLocation.setSelection(mTypeOfLocationPosition, true);

    //Create the adapter and fill the place list with the real distances
    mNearPlacesAdapter = new NearPlacesAdapter(this, mNearPlaceList);

    mListViewNearPlaces = (ListView) findViewById(R.id.listViewNearPlaces);
    mListViewNearPlaces.setAdapter(mNearPlacesAdapter);
    mListViewNearPlaces.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> _containerView, View _itemView, int _position, long _id) {
            Intent intent = new Intent();
            intent.setClass(getBaseContext(), PlaceDetailActivity.class);
            intent.putExtra(ListPlacesFragment.EXTRA_ID_KEY, mNearPlaceList.get(_position).getId());
            startActivity(intent);
        }
    });

    getSupportLoaderManager().initLoader(TYPE_OF_LOCATION_LOADER_ID, null,
            new TypeOfLocationCursorLoaderCallback());
    getSupportLoaderManager().initLoader(NEAR_PLACES_LOADER_ID, null, new NearPlacesCursorLoaderCallback());
}

From source file:com.cssweb.android.quote.QHHQActivity.java

private void loadAllStock(final int position) {
    Intent localIntent = new Intent();
    if (position == 0) {
        localIntent.setClass(QHHQActivity.this, ZJS.class);
        Bundle extras = new Bundle();
        extras.putInt("stocktype", 201);
        extras.putString("market", "cffex");
        extras.putString("exchange", "cf");
        extras.putString("title", "");
        localIntent.putExtras(extras);/* w w  w.  jav  a2s.  co  m*/

    } else if (position == 1) {
        localIntent.setClass(QHHQActivity.this, SQS.class);

        Bundle extras = new Bundle();
        extras.putInt("stocktype", 201);
        extras.putString("market", "sfe");
        extras.putString("exchange", "sf");
        extras.putString("title", "");
        extras.putInt("type", R.array.sqs_type_menu);
        localIntent.putExtras(extras);
    } else if (position == 2) {
        localIntent.setClass(QHHQActivity.this, DSS.class);

        Bundle extras = new Bundle();
        extras.putInt("stocktype", 201);
        extras.putString("market", "dce");
        extras.putString("exchange", "dc");
        extras.putString("title", "");
        extras.putInt("type", R.array.dss_type_menu);
        localIntent.putExtras(extras);
    } else if (position == 3) {
        localIntent.setClass(QHHQActivity.this, ZSS.class);

        Bundle extras = new Bundle();
        extras.putInt("stocktype", 201);
        extras.putString("market", "czce");
        extras.putString("exchange", "cz");
        extras.putString("title", "");
        extras.putInt("type", R.array.zss_type_menu);
        localIntent.putExtras(extras);
    } else if (position == 4) {
        localIntent.setClass(QHHQActivity.this, QQSP.class);
    }
    startActivity(localIntent);
}

From source file:com.bangz.smartmute.RulelistActivity.java

@Override
public void onRuleItemSelected(long id, int ruletype) {
    Uri uri = ContentUris.withAppendedId(RulesColumns.CONTENT_URI, id);
    Intent intent = new Intent();
    intent.setData(uri);//from  w w  w. j a  va 2 s.  com
    switch (ruletype) {
    case RulesColumns.RT_LOCATION:
        intent.setClass(this, LocationRuleEditActivity.class);
        intent.putExtra(Constants.INTENT_EDITORNEW, Constants.INTENT_EDIT);
        break;
    case RulesColumns.RT_WIFI:
        intent.setClass(this, WifiEditActivity.class);
        intent.putExtra(Constants.INTENT_EDITORNEW, Constants.INTENT_EDIT);
        break;
    case RulesColumns.RT_TIME:
        intent.setClass(this, TimeRuleEditActivity.class);
        intent.putExtra(Constants.INTENT_EDITORNEW, Constants.INTENT_EDIT);
        break;
    }
    startActivity(intent);
}

From source file:com.cloudbees.gasp.activity.GaspRESTLoaderActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Single menu item only - need to handle multiple items if added
    Intent intent = new Intent();
    intent.setClass(GaspRESTLoaderActivity.this, SetPreferencesActivity.class);
    startActivityForResult(intent, 0);//from   w  w  w. j  av  a  2  s.co m

    return true;
}

From source file:com.loadsensing.app.LoginActivity.java

public void onClick(View v) {

    // this gets the resources in the xml file
    // and assigns it to a local variable of type EditText
    EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
    EditText passwordEditText = (EditText) findViewById(R.id.txt_password);

    // the getText() gets the current value of the text box
    // the toString() converts the value to String data type
    // then assigns it to a variable of type String
    String sUserName = usernameEditText.getText().toString();
    String sPassword = passwordEditText.getText().toString();

    // Definimos constructor de alerta para los avisos posteriores
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog = new AlertDialog.Builder(this).create();

    // call the backend using Get parameters
    String address = SERVER_HOST + "?user=" + sUserName + "&pass=" + sPassword + "";

    if (sUserName.equals("") || sPassword.equals("")) {
        // error alert
        alertDialog.setTitle(getResources().getString(R.string.error));
        alertDialog.setMessage(getResources().getString(R.string.empty_fields));
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }//from ww w  . ja  v a2  s  .c  om
        });
        alertDialog.show();
    } else if (!checkConnection(this.getApplicationContext())) {
        alertDialog.setTitle(getResources().getString(R.string.error));
        alertDialog.setMessage(getResources().getString(R.string.error_no_internet));
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        alertDialog.show();
    } else {
        try {
            showBusyCursor(true);
            progress = ProgressDialog.show(this, getResources().getString(R.string.pantalla_espera_title),
                    getResources().getString(R.string.iniciando_sesion), true);

            Log.d(DEB_TAG, "Requesting to " + address);

            JSONObject json = JsonClient.connectJSONObject(address);

            CheckBox rememberUserPassword = (CheckBox) findViewById(R.id.remember_user_password);
            if (rememberUserPassword.isChecked()) {
                setSharedPreference("login", sUserName);
                setSharedPreference("password", sPassword);
            } else {
                setSharedPreference("login", "");
                setSharedPreference("password", "");
            }

            if (json.getString("session") != "0") {
                progress.dismiss();
                // Guardamos la session en SharedPreferences para utilizarla
                // posteriormente
                setSharedPreference("session", json.getString("session"));
                // Sessin correcta. StartActivity de la home
                Intent intent = new Intent();
                intent.setClass(this.getApplicationContext(), HomeActivity.class);
                startActivity(intent);

            } else {
                progress.dismiss();
                alertDialog.setTitle(getResources().getString(R.string.error));
                alertDialog.setMessage(getResources().getString(R.string.error_login));
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alertDialog.show();
            }

        } catch (JSONException e) {
            progress.dismiss();
            Log.d(DEB_TAG, "Error parsing data " + e.toString());
        }

        showBusyCursor(false);
    }
}

From source file:com.cloudbees.gasp.activity.PlacesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case R.id.gasp_settings:
        Intent intent = new Intent();
        intent.setClass(this, SetPreferencesActivity.class);
        startActivityForResult(intent, 0);
        return true;

    case R.id.options_exit:
        finish();/*from ww  w .ja va  2s. c o  m*/
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}