Example usage for android.app Activity RESULT_OK

List of usage examples for android.app Activity RESULT_OK

Introduction

In this page you can find the example usage for android.app Activity RESULT_OK.

Prototype

int RESULT_OK

To view the source code for android.app Activity RESULT_OK.

Click Source Link

Document

Standard activity result: operation succeeded.

Usage

From source file:com.mobicage.rogerthat.registration.OauthRegistrationActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    T.UI();//from w ww.j a  v  a  2 s .c  o  m
    if (requestCode == START_OAUTH_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            if (!TextUtils.isEmptyOrWhitespace(data.getStringExtra(OauthActivity.RESULT_CODE))) {
                registerWithOauthCode(data.getStringExtra(OauthActivity.RESULT_CODE),
                        data.getStringExtra(OauthActivity.RESULT_STATE));
            } else {
                String errorMessage = data.getStringExtra(OauthActivity.RESULT_ERROR_MESSAGE);
                mErrorTextView.setText(errorMessage);
                UIUtils.showDialog(OauthRegistrationActivity.this, null, errorMessage);
            }
        }
    }
}

From source file:ca.taglab.PictureFrame.ScreenSlidePageFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case CAPTURE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            // Image captured and saved
            try {
                String photo_location = getLastImageId();

                /**//w  ww  .ja  va  2s .c  om
                 * Code for adding audio caption
                mAttachments = new String[2];
                mAttachments[0] = photo_location;
                Intent intent = new Intent(getActivity(), AudioRecorderActivity.class);
                startActivityForResult(intent, CAPTURE_AUDIO_CAPTION);
                 */

                String[] attachments = { photo_location };
                new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I have a photo for you", "",
                        attachments).execute();
                messageSent(mPhoto);
            } catch (Exception e) {
                // Photo to mEmail failed
                Log.e("SendEmailAsyncTask", e.getMessage(), e);
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User cancelled photo capture
        } else {
            // Photo capture failed
        }
        break;

    case CAPTURE_VIDEO:
        if (resultCode == Activity.RESULT_OK) {
            // Video captured and saved
            try {
                String video_location = getLastVideoId();
                String[] attachments = { video_location };
                new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I have a video message for you",
                        "", attachments).execute();
                messageSent(mVideo);
            } catch (Exception e) {
                // Video to mEmail failed
                Log.e("SendEmailAsyncTask", e.getMessage(), e);
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User cancelled video capture
        } else {
            // Video capture failed
        }
        break;

    case CAPTURE_AUDIO:
        if (resultCode == Activity.RESULT_OK) {
            // Audio captured and saved
            try {
                String audio_location = data.getStringExtra("audio_location");
                String[] attachments = { audio_location };
                new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I have an audio message for you",
                        "", attachments).execute();
                messageSent(mAudio);
            } catch (Exception e) {
                // Audio to mEmail failed
                Log.e("SendEmailAsyncTask", e.getMessage(), e);
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User cancelled audio capture
        } else {
            // Audio capture failed
        }
        break;

    case CAPTURE_AUDIO_CAPTION:
        if (resultCode == Activity.RESULT_OK) {
            try {
                String audio_location = data.getStringExtra("audio_location");
                mAttachments[1] = audio_location;
                new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I have a photo for you", "",
                        mAttachments).execute();
                messageSent(mPhoto);
            } catch (Exception e) {
                // Photo and audio caption to mEmail failed
                Log.e("SendEmailAsyncTask", e.getMessage(), e);
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User cancelled audio capture
        } else {
            // Audio capture failed
        }
        break;

    default:
        Log.e(TAG, "Intent to start an activity failed");
        break;
    }
}

From source file:com.google.sample.beaconservice.MainActivityFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.REQUEST_CODE_PICK_ACCOUNT) {
        // Receiving a result from the AccountPicker
        if (resultCode == Activity.RESULT_OK) {
            String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            accountNameView.setText(name);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString("accountName", name);
            editor.apply();//  w ww  .j  a  v a2s  .  c  o  m
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // The account picker dialog closed without selecting an account.
            // Notify users that they must pick an account to proceed.
            Toast.makeText(getActivity(), "Please pick an account", Toast.LENGTH_SHORT).show();
        }
    } else if (requestCode == Constants.REQUEST_CODE_ENABLE_BLE) {
        if (resultCode == Activity.RESULT_OK) {
            createScanner();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Toast.makeText(getActivity(), "Please enable Bluetooth", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:at.fhooe.mc.ba2.wimmer.wikitude.WikitudeMainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case CONNECTION_FAILURE_RESOLUTION_REQUEST: {
        // If the result code is Activity.RESULT_OK, try to connect again
        switch (resultCode) {
        case Activity.RESULT_OK: {
            Log.d("Location Updates", "RESULT_OK; Connection is tried again");
            mLocationClient.connect();/*from w  w w. j av a 2s.co  m*/
            break;
        }
        default: {
            Log.d("Location Updates", "Resultcode: " + resultCode);
        }
        }
    }
    default: {
        Log.d("Location Updates", "Requestcode: " + requestCode);
    }
    }
}

From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java

@SuppressWarnings("unchecked")
@Override//from ww  w  . ja  v  a  2  s  .  c  o  m
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == Statics.REQUEST_PICK_SERVICE) {
        if (resultCode == Activity.RESULT_OK) {
            ExtendedHashMap map = new ExtendedHashMap();
            map.putAll((HashMap<String, Object>) data.getSerializableExtra(sData));

            mTimer.put(Timer.KEY_SERVICE_NAME, map.getString(Service.KEY_NAME));
            mTimer.put(Timer.KEY_REFERENCE, map.getString(Service.KEY_REFERENCE));
            mService.setText(mTimer.getString(Timer.KEY_SERVICE_NAME));
        }
    }
}

From source file:li.barter.fragments.EditProfileFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {

    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK) {
        return;//from  w  ww  .j  a v a 2s  . co m
    }

    switch (requestCode) {
    case PICK_FROM_CAMERA:
        // doCrop(PICK_FROM_CAMERA);
        setAndSaveImage(mCameraImageCaptureUri, PICK_FROM_CAMERA);
        break;

    case PICK_FROM_FILE:
        mGalleryImageCaptureUri = data.getData();
        setAndSaveImage(mGalleryImageCaptureUri, PICK_FROM_FILE);
        // doCrop(PICK_FROM_FILE);
        break;

    case CROP_FROM_CAMERA:
        final Bundle extras = data.getExtras();
        if (extras != null) {
            mCompressedPhoto = extras.getParcelable("data");
            mProfileImageView.setImageBitmap(mCompressedPhoto);
        }
        PhotoUtils.saveImage(mCompressedPhoto, "barterli_avatar_small.png");
        break;

    case AppConstants.RequestCodes.EDIT_PREFERRED_LOCATION: {
        loadPreferredLocation();
        break;
    }

    }
}

From source file:com.crowflying.buildwatch.ConfigurationActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(LOG_TAG, String.format("Got result: %s, %s, %s", requestCode, resultCode, data));
    // We won't check for XZing originating intent here - lets just hope
    // this will not bite later.
    if (resultCode == Activity.RESULT_OK) {
        new ConfigureAppFromQRCode().execute(data);
    }//w  w  w.  java  2  s . c  o  m
}

From source file:com.support.android.designlibdemo.activities.CampaignDetailActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == TAKE_PHOTO_CODE) {

            photoBitmap = BitmapFactory.decodeFile(photoUri.getPath());
            Bitmap resizedImage = BitmapScaler.scaleToFitWidth(photoBitmap, 300);
            ivCampaignImage.getAdjustViewBounds();
            ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY);
            //********** Update parse with image

            // Convert bitmap to a byte array
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            resizedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] image = stream.toByteArray();

            // Create the ParseFile with an image
            final ParseFile file = new ParseFile(
                    "posted_by_user_" + ParseUser.getCurrentUser().getUsername() + ".jpg", image);

            //posting an image file with campaign id to Parse to Images object
            ParseObject photoPost = new ParseObject("Images");
            photoPost.put("imagePost", file);
            photoPost.put("campaignId", campaign.getObjectId());
            photoPost.saveInBackground(new SaveCallback() {
                @Override//  ww w  . ja  v  a2 s . c om
                public void done(ParseException e) {
                    getImagesUploadedByUserForCampaign(campaign.getObjectId());
                }
            });

        } else if (requestCode == PICK_PHOTO_CODE) {

            photoUri = data.getData();
            try {
                photoBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);
            } catch (IOException e) {
                e.printStackTrace();
            }

            Bitmap resizedImage = BitmapScaler.scaleToFitWidth(photoBitmap, 300);
            ivCampaignImage.getAdjustViewBounds();
            ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY);
            //********** Update parse with image
            //ivCampaignImage.setImageBitmap(resizedImage);

            // Convert bitmap to a byte array
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            resizedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] image = stream.toByteArray();

            // Create the ParseFile with an image
            final ParseFile file = new ParseFile(
                    "posted_by_user_" + ParseUser.getCurrentUser().getUsername() + ".jpg", image);

            //posting an image file with campaign id to Parse to Images object
            ParseObject photoPost = new ParseObject("Images");
            photoPost.put("imagePost", file);
            photoPost.put("campaignId", campaign.getObjectId());
            photoPost.saveInBackground();
            photoPost.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    getImagesUploadedByUserForCampaign(campaign.getObjectId());
                }
            });

        } else if (requestCode == CROP_PHOTO_CODE) {
            photoBitmap = data.getParcelableExtra("data");

            ivCampaignImage.getAdjustViewBounds();
            ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY);
            ivCampaignImage.setImageBitmap(photoBitmap);
            Toast.makeText(this, "I just took a picture", Toast.LENGTH_LONG).show();

        }
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ui.scenario.ScenarioAddActivity.java

/**
 * Validates if scenario data are correct and starts service for creating scenario if no error found.
 *
 * @param scenario scenario to be created
 *///from  w w  w.ja  v a2 s  .c o m
private void validateAndRun(Scenario scenario) {

    //        if (!ConnectionUtils.isOnline(this)) {
    //            showAlert(getString(R.string.error_offline));
    //            return;
    //        }

    StringBuilder error = new StringBuilder();

    //validations
    if (scenario.getResearchGroupId() == null) {
        error.append(getString(R.string.error_no_group_selected)).append('\n');
    }
    if (ValidationUtils.isEmpty(scenario.getScenarioName())) {
        error.append(getString(R.string.error_empty_field)).append(" (")
                .append(getString(R.string.scenario_name)).append(")").append('\n');
    }
    if (scenario.getFilePath() == null) {
        error.append(getString(R.string.error_no_file_selected)).append('\n');
    }

    //if no error occurs, service starts
    if (error.toString().isEmpty()) {
        //            new CreateScenario(this).execute(scenario);

        //===================================================================Database Code==================================================//
        db = new CBDatabase(Keys.DB_NAME, ScenarioAddActivity.this);
        // create an object that contains data for a document
        Map<String, Object> docContent = new HashMap<String, Object>();
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_type),
                ScenarioAddActivity.this.getResources().getString(R.string.doc_type_scenario));
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_scenario_name),
                scenario.getScenarioName().toString());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_res_grp_id),
                scenario.getResearchGroupId());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_description),
                scenario.getDescription().toString());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_mime),
                scenario.getMimeType().toString());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_file_name),
                scenario.getFileName().toString());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_isprivate),
                scenario.isPrivate());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_file_path),
                scenario.getFilePath());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_file_length),
                scenario.getFileLength());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_owner_id),
                scenario.getOwnerId());
        docContent.put(ScenarioAddActivity.this.getResources().getString(R.string.attribute_owner_user_name),
                scenario.getOwnerUserName());

        String docId = null;
        try {
            // Create a new scenario document
            docId = db.create(docContent);
            assert (docId != null);
            Intent resultIntent = new Intent();
            scenario.setScenarioId(docId);
            resultIntent.putExtra(Values.ADD_SCENARIO_KEY, scenario);
            ScenarioAddActivity.this.setResult(Activity.RESULT_OK, resultIntent);
            Toast.makeText(ScenarioAddActivity.this, R.string.creation_ok, Toast.LENGTH_SHORT).show();
            ScenarioAddActivity.this.finish();
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(ScenarioAddActivity.this, R.string.creation_failed, Toast.LENGTH_SHORT).show();
        }
        //==================================================================================================================================//

    } else {
        showAlert(error.toString());
    }
}