List of usage examples for android.app Activity RESULT_OK
int RESULT_OK
To view the source code for android.app Activity RESULT_OK.
Click Source Link
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); switch (requestCode) { case Constants.ACTIVITY_PICK_SUBREDDIT: if (resultCode == Activity.RESULT_OK) { Matcher redditContextMatcher = REDDIT_PATH_PATTERN.matcher(intent.getData().getPath()); if (redditContextMatcher.matches()) { new MyDownloadThreadsTask(redditContextMatcher.group(1)).execute(); }//from w ww . j a v a2s. co m } break; default: break; } }
From source file:jen.jobs.application.UpdateJobSeeking.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int clickedItem = item.getItemId(); if (clickedItem == R.id.save) { if (isOnline) { ArrayList<String> errors = new ArrayList<>(); if (selectedJobSeekingStatusValues == null) { errors.add("Please select jobseeking status!"); }/*ww w .j ava 2 s . c o m*/ if (selectedAvailability.length() == 0 && selectedAvailabilityUnit.length() == 0) { errors.add("Please select your notice period!"); } if (selectedCountryValues == null) { errors.add("Please select the country!"); } else { if (selectedCountryValues.id == 127) { if (selectedMalaysiaStateValues == null) { errors.add("Please select the state!"); } } } if (errors.size() == 0) { JSONObject obj = new JSONObject(); // TODO - save to profile, local db ContentValues cv = new ContentValues(); cv.put("js_jobseek_status_id", selectedJobSeekingStatusValues.id); cv.put("driving_license", cbLicense.isChecked() ? 1 : 0); cv.put("transport", cbTransport.isChecked() ? 1 : 0); cv.put("availability", selectedAvailability); cv.put("availability_unit", selectedAvailabilityUnit.substring(0, 1)); tableProfile.updateProfile(cv, profileId); // TODO - save to address, add address to parameter ContentValues cv2 = new ContentValues(); if (selectedMalaysiaStateValues != null) { cv2.put("state_id", selectedMalaysiaStateValues.id); cv2.put("state_name", selectedMalaysiaStateValues.name); } else { cv2.put("state_id", 0); cv2.put("state_name", ""); } cv2.put("country_id", selectedCountryValues.id); cv2.put("updated_at", Jenjobs.date(null, "yyyy-MM-dd", null)); tableAddress.updateAddress(cv2); // update POST data try { obj.put("js_jobseek_status_id", cv.getAsString("js_jobseek_status_id")); obj.put("driving_license", cv.getAsString("driving_license")); obj.put("transport", cv.getAsString("transport")); obj.put("availability", cv.getAsString("availability")); obj.put("availability_unit", cv.getAsString("availability_unit")); obj.put("state_id", cv.getAsString("state_id")); obj.put("country_id", cv.getAsString("country_id")); } catch (JSONException e) { Log.e("err", e.getMessage()); } // TODO - change cv to ArrayList -> String, post to server String accessToken = sharedPref.getString("access_token", null); PostRequest p = new PostRequest(); p.setResultListener(new PostRequest.ResultListener() { @Override public void processResult(JSONObject success) { if (success != null) { try { success.get("status_code"); } catch (JSONException e) { Log.e("test", e.getMessage()); } } } }); String[] s = { Jenjobs.JOBSEEKING_INFO + "?access-token=" + accessToken, obj.toString() }; p.execute(s); Intent intent = new Intent(); intent.putExtra("summary", selectedJobSeekingStatusValues.name); setResult(Activity.RESULT_OK, intent); finish(); } else { Toast.makeText(getApplicationContext(), TextUtils.join(", ", errors), Toast.LENGTH_LONG).show(); } } else { Toast.makeText(getApplicationContext(), R.string.network_error, Toast.LENGTH_LONG).show(); } } return true; }
From source file:com.MustacheMonitor.MustacheMonitor.StacheCam.java
/** * Called when the camera view exits./*from w w w . ja va 2 s . c o m*/ * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; // If CAMERA if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = null; Uri uri = null; // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } // If sending filename back else if (destType == FILE_URI) { if (!this.saveToPhotoAlbum) { uri = Uri.fromFile( new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg")); } else { uri = getUriFromMediaStore(); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) { writeUncompressedImage(uri); this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { exifPath = FileUtils.getRealPathFromURI(uri, this.cordova); } else { exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); } } // Send Uri back to JavaScript for viewing image this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); bitmap = null; } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { if (resultCode == Activity.RESULT_OK) { Uri uri = intent.getData(); // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { // This is a special case to just return the path as no scaling, // rotating or compression needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && destType == FILE_URI && !this.correctOrientation) { this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { // Get the path to the image. Makes loading so much easier. String imagePath = FileUtils.getRealPathFromURI(uri, this.cordova); Log.d(LOG_TAG, "Real path = " + imagePath); // If we don't have a valid image so quit. if (imagePath == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retreive path to picture!"); return; } Bitmap bitmap = getScaledBitmap(imagePath); if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(), cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } } // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); } // If sending filename back else if (destType == FILE_URI) { // Do we need to scale the returned file if (this.targetHeight > 0 && this.targetWidth > 0) { try { // Create an ExifHelper to save the exif data that is lost during compression String resizePath = DirectoryManager .getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg"; ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(resizePath); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } OutputStream os = new FileOutputStream(resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); } // The resized image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.success( new PluginResult(PluginResult.Status.OK, ("file://" + resizePath + "?" + System.currentTimeMillis())), this.callbackId); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); } } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:org.starfishrespect.myconsumption.android.ui.AddSensorActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_sensor); Toolbar toolbar = getActionBarToolbar(); getSupportActionBar().setTitle(getString(R.string.title_add_sensor)); toolbar.setNavigationIcon(R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/* w w w .j a v a2s.c o m*/ public void onClick(View view) { Intent intent = getParentActivityIntent(); startActivity(intent); finish(); } }); spinnerSensorType = (Spinner) findViewById(R.id.spinnerSensorType); editTextSensorName = (EditText) findViewById(R.id.editTextSensorName); layoutSensorSpecificSettings = (LinearLayout) findViewById(R.id.layoutSensorSpecificSettings); buttonCreateSensor = (Button) findViewById(R.id.buttonCreateSensor); if (getIntent().getExtras() != null) { Bundle b = getIntent().getExtras(); if (b.containsKey("edit")) { try { editSensor = SingleInstance.getDatabaseHelper().getSensorDao().queryForId(b.getString("edit")); edit = true; editTextSensorName.setText(editSensor.getName()); sensorTypes = new String[1]; sensorTypes[0] = editSensor.getType(); layoutSensorSpecificSettings.removeAllViews(); selectedSensorType = sensorTypes[0].toLowerCase(); sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType); sensorView.setEditMode(true); layoutSensorSpecificSettings.addView(sensorView); buttonCreateSensor.setText(R.string.button_edit_sensor); } catch (SQLException e) { finish(); } } } spinnerSensorType.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensorTypes)); if (!edit) { spinnerSensorType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { layoutSensorSpecificSettings.removeAllViews(); selectedSensorType = sensorTypes[position].toLowerCase(); sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType); layoutSensorSpecificSettings.addView(sensorView); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); buttonCreateSensor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!MiscFunctions.isOnline(AddSensorActivity.this)) { MiscFunctions.makeOfflineDialog(AddSensorActivity.this).show(); return; } if (editTextSensorName.getText().toString().equals("") || !sensorView.areSettingsValid()) { new AlertDialog.Builder(AddSensorActivity.this).setTitle(R.string.dialog_title_error) .setMessage("You must fill all the fields in order to add a sensor !") .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); return; } new AsyncTask<Void, Boolean, Void>() { private ProgressDialog waitingDialog; @Override protected void onPreExecute() { waitingDialog = new ProgressDialog(AddSensorActivity.this); waitingDialog.setTitle(R.string.dialog_title_loading); waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); waitingDialog.setMessage( getResources().getString(R.string.dialog_message_loading_creating_sensor)); waitingDialog.show(); } @Override protected Void doInBackground(Void... params) { publishProgress(create()); return null; } @Override protected void onProgressUpdate(Boolean... values) { for (boolean b : values) { if (b) { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_information) .setMessage(R.string.dialog_message_information_sensor_added) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); setResult(RESULT_OK); Intent intent = new Intent(AddSensorActivity.this, ChartActivity.class); intent.putExtra(Config.EXTRA_FIRST_LAUNCH, true); startActivity(intent); } }) .show(); } else { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_error) .setMessage(R.string.dialog_message_error_sensor_not_added) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); } } } @Override protected void onPostExecute(Void aVoid) { waitingDialog.dismiss(); } }.execute(); } }); } else { buttonCreateSensor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AsyncTask<Void, Boolean, Void>() { private ProgressDialog waitingDialog; @Override protected void onPreExecute() { waitingDialog = new ProgressDialog(AddSensorActivity.this); waitingDialog.setTitle(R.string.dialog_title_loading); waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); waitingDialog.setMessage( getResources().getString(R.string.dialog_message_loading_editing_sensor)); waitingDialog.show(); } @Override protected Void doInBackground(Void... params) { publishProgress(edit()); return null; } @Override protected void onProgressUpdate(Boolean... values) { for (boolean b : values) { if (b) { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_information) .setMessage(R.string.dialog_message_information_sensor_edited) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); setResult(Activity.RESULT_OK); finish(); } }) .show(); } else { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_error) .setMessage(R.string.dialog_message_error_sensor_not_added) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); } } } @Override protected void onPostExecute(Void aVoid) { waitingDialog.dismiss(); } }.execute(); } }); } }
From source file:de.stadtrallye.rallyesoft.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // Android changes the upper 16 bits of a request generated from a fragment, so that // it can deliver the result back to the fragment. // We want to handle the result here, so we only look at the lower bits if ((requestCode & 0xffff) == ConnectionAssistantActivity.REQUEST_CODE) { Log.v(THIS, "ConnectionAssistant finished with " + resultCode); if (resultCode == Activity.RESULT_OK) { Log.i(THIS, "ConnectionAssistant has connected to a new Server"); // model.removeListener(this); // model = Model.getInstance(getApplicationContext()); // model.addListener(this); // updateServerState(); }/*from w ww . j a v a 2 s .c om*/ findViewById(R.id.content_frame).post(new Runnable() { @Override public void run() { tabManager.switchToTab(RallyeTabManager.TAB_OVERVIEW); } }); } else if ((requestCode & 0xffff) == SubmitNewSolutionActivity.REQUEST_CODE) { Log.i(THIS, "Task Submission"); if (resultCode == Activity.RESULT_OK) { // Log.i(THIS, "Submitted: "+ data.getExtras()); } } else { Log.i(THIS, "Received ActivityResult: Req: " + requestCode + ", res: " + resultCode + ", intent: " + data); picture = pictureManager.onActivityResult(requestCode, resultCode, data); /*if (tabManager.getCurrentTab() == RallyeTabManager.TAB_CHAT && picture != null) { IPictureTakenListener chatTab = (IPictureTakenListener) tabManager.getActiveFragment(); chatTab.pictureTaken(picture); }*/ // ImageLoader.getInstance().handleSlowNetwork(); } super.onActivityResult(requestCode, resultCode, data);//TODO: this call is redundant, it only distributes teh result to the originating fragment, (we handle this ourselves) }
From source file:org.ambientdynamix.core.HomeActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == Activity.RESULT_OK) { final Bundle extras = intent.getExtras(); switch (requestCode) { case ACTIVITY_EDIT: // Access the serialized app coming in from the Intent's Bundle // extra final DynamixApplication app = (DynamixApplication) extras.getSerializable("app"); // Update the DynamixService with the updated application DynamixService.updateApplication(app); refresh();//from ww w . j a v a 2 s. c om break; } } }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Constants.REQUEST_CODE_PLACE_PICKER) { if (resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(data, getActivity()); if (place == null) { return; }//from ww w . j a v a 2 s .c om // The place picker presents two selection options: "select this location" and // "nearby places". Only the nearby places selection returns a placeId we can // submit to the service; the location selection will return a hex-like 0xbeef // identifier for that position instead, which isn't what we want. Here we check // if the entire string is hex and clear the placeId if it is. String id = place.getId(); if (id.startsWith("0x") && id.matches("0x[0-9a-f]+")) { placeId.setText(""); beacon.placeId = ""; } else { placeId.setText(id); beacon.placeId = id; } LatLng placeLatLng = place.getLatLng(); latLng.setText(placeLatLng.toString()); beacon.latitude = placeLatLng.latitude; beacon.longitude = placeLatLng.longitude; updateBeacon(); } else { logErrorAndToast("Error loading place picker. Is the Places API enabled? " + "See https://developers.google.com/places/android-api/signup for more detail"); } } }
From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // This handles the qrcode results if (requestCode == 0) { if (resultCode == Activity.RESULT_OK) { String contents = data.getStringExtra("SCAN_RESULT"); for (String stanzas : contents.split(" ")) { String[] tmp = stanzas.split(":"); if (tmp[0].equalsIgnoreCase("KEY_BASE64")) { txt_KEY.setText(tmp[1]); chkb64key.setChecked(true); } else if (tmp[0].equalsIgnoreCase("KEY")) { txt_KEY.setText(tmp[1]); chkb64key.setChecked(false); } else if (tmp[0].equalsIgnoreCase("HMAC_KEY_BASE64")) { txt_HMAC.setText(tmp[1]); chkb64hmac.setChecked(true); } else if (tmp[0].equalsIgnoreCase("HMAC_KEY")) { txt_HMAC.setText(tmp[1]); chkb64hmac.setChecked(false); }// w w w . j a v a 2 s.c o m } // end for loop } if (resultCode == Activity.RESULT_CANCELED) { //handle cancel Context context = getActivity(); CharSequence text = " QR Code Canceled"; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastLayout = (LinearLayout) toast.getView(); TextView toastTV = (TextView) toastLayout.getChildAt(0); toastTV.setTextSize(30); toast.show(); } } }
From source file:com.example.cuisoap.agrimac.homePage.machineDetail.driverInfoFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { license_uri = data.getData();/*ww w . j a va2 s .c o m*/ Log.e("uri", license_uri.toString()); ContentResolver cr = context.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(license_uri)); if (requestCode == 1) { //String path=getRealPathFromURI(uri); //System.out.println(path); bitmap = ImageUtils.comp(bitmap); license_pic.setImageBitmap(bitmap); license_pic.setVisibility(View.VISIBLE); license.setVisibility(View.GONE); license_pic.setOnClickListener(myOnClickListener); machineDetailData.driver_license_filepath = ImageUtils.saveMyBitmap(bitmap, null); } } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(), e); } } else { Toast.makeText(context, "?", Toast.LENGTH_SHORT).show(); } super.onActivityResult(requestCode, resultCode, data); }