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:org.runnerup.export.FacebookSynchronizer.java

@Override
public Status getAuthResult(int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        try {//from   w w w .j a  v a2 s .  c om
            String authConfig = data.getStringExtra(DB.ACCOUNT.AUTH_CONFIG);
            Uri uri = Uri.parse("http://keso?" + authConfig);
            access_token = uri.getQueryParameter("access_token");
            expire_time = Long.valueOf(uri.getQueryParameter("expires"));
            token_now = System.currentTimeMillis();
            return Status.OK;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return Status.ERROR;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateScenario.java

/**
 * If scenario was created successfully, URI to scenario file will be displayed shortly.
 *
 * @param scenario created scenario if any
 *///from  ww  w.  j a va  2 s  .com
@Override
protected void onPostExecute(Scenario scenario) {
    if (scenario != null) {

        Intent resultIntent = new Intent();
        resultIntent.putExtra(Values.ADD_SCENARIO_KEY, scenario);
        activity.setResult(Activity.RESULT_OK, resultIntent);
        Toast.makeText(activity, R.string.creation_ok, Toast.LENGTH_SHORT).show();
        activity.finish();

    } else {
        Toast.makeText(activity, R.string.creation_failed, Toast.LENGTH_SHORT).show();
    }
}

From source file:fragments.NewTicket.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case COLOR_PICKER:

        if (resultCode == Activity.RESULT_OK) {
            Bundle bundle = data.getExtras();
            String color = bundle.getString("color", "");
            ticketColor.setText(color);/* w  ww.j  ava  2  s . c om*/

        } else if (resultCode == Activity.RESULT_CANCELED) {
            ticketColor.setText("");
        }
        break;
    }
}

From source file:com.phonegap.customcamera.NativeCameraLauncher.java

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // If image available
    if (resultCode == Activity.RESULT_OK) {

        resultIntent = intent;/*from   w  w  w  .  j  a  va2s . c  o m*/

        this.cordova.getThreadPool().execute(this);

    }

    // If cancelled
    else if (resultCode == Activity.RESULT_CANCELED) {
        this.failPicture("Camera cancelled.");
    }
    // back button clicked
    else if (resultCode == CAMERA_CANCELD) {
        this.cancelPicture();
    }

    // If something else
    else {
        this.failPicture("Did not complete!");
    }
}

From source file:com.foregroundcameraplugin.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits./*from ww 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) {

    // 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();
            exif.createInFile(
                    getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg");
            exif.readExifData();

            // Read in bitmap of captured image
            Bitmap bitmap;
            try {
                bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri);
            } catch (FileNotFoundException e) {
                Uri uri = intent.getData();
                android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
                bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
            }

            bitmap = scaleBitmap(bitmap);

            // Create entry in media store for image
            // (Don't use insertImage() because it uses default compression
            // setting of 50 - no way to change it)
            ContentValues values = new ContentValues();
            values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            Uri uri = null;
            try {
                uri = this.cordova.getActivity().getContentResolver()
                        .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } catch (UnsupportedOperationException e) {
                LOG.d(LOG_TAG, "Can't write to external media storage.");
                try {
                    uri = this.cordova.getActivity().getContentResolver()
                            .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                } catch (UnsupportedOperationException ex) {
                    LOG.d(LOG_TAG, "Can't write to internal media storage.");
                    this.failPicture("Error capturing image - no media storage found.");
                    return;
                }
            }

            // 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
            exif.createOutFile(getRealPathFromURI(uri, this.cordova));
            exif.writeExifData();

            // Send Uri back to JavaScript for viewing image
            this.callbackContext.success(getRealPathFromURI(uri, this.cordova));

            bitmap.recycle();
            bitmap = null;
            System.gc();

            checkForDuplicateImage();
        } 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!");
    }
}

From source file:net.mutina.uclimb.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits. /*ww  w.jav  a  2 s  . c  om*/
 * 
 * @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) {

    // 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();
            exif.createInFile(getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
            exif.readExifData();

            // Read in bitmap of captured image
            Bitmap bitmap;
            try {
                bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(),
                        imageUri);
            } catch (FileNotFoundException e) {
                Uri uri = intent.getData();
                android.content.ContentResolver resolver = this.ctx.getContentResolver();
                bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
            }

            bitmap = scaleBitmap(bitmap);

            // Create entry in media store for image
            // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
            ContentValues values = new ContentValues();
            values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            Uri uri = null;
            try {
                uri = this.ctx.getContentResolver()
                        .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } catch (UnsupportedOperationException e) {
                LOG.d(LOG_TAG, "Can't write to external media storage.");
                try {
                    uri = this.ctx.getContentResolver()
                            .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                } catch (UnsupportedOperationException ex) {
                    LOG.d(LOG_TAG, "Can't write to internal media storage.");
                    this.failPicture("Error capturing image - no media storage found.");
                    return;
                }
            }

            // Add compressed version of captured image to returned media store Uri
            OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
            os.close();

            // Restore exif data to file
            exif.createOutFile(getRealPathFromURI(uri, this.ctx));
            exif.writeExifData();

            // Send Uri back to JavaScript for viewing image
            this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);

            bitmap.recycle();
            bitmap = null;
            System.gc();

            checkForDuplicateImage();
        } 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!");
    }
}

From source file:com.ilearnrw.reader.tasks.AddToLibraryTask.java

@Override
protected void onPostExecute(Pair<String> results) {
    if (dialog.isShowing())
        dialog.dismiss();//from  ww  w.  j av  a2  s  .c o m

    wifiLock.release();
    wakeLock.release();

    if (results.second() != null) {
        Toast.makeText(context, context.getString(R.string.annotation_succeeded), Toast.LENGTH_SHORT).show();

        Gson gson = new Gson();
        String json = results.second();

        AnnotatedPack result = gson.fromJson(json, AnnotatedPack.class);

        int index = filename.lastIndexOf(".");
        String name = filename.substring(0, index);
        File dir = context.getDir(context.getString(R.string.library_location), Context.MODE_PRIVATE);

        File newFile = new File(dir, filename);
        FileHelper.saveFile(result.getHtml(), newFile);
        String wordSet = gson.toJson(result.getWordSet());
        File jsonFile = new File(dir, name + ".json");
        FileHelper.saveFile(wordSet, jsonFile);

        Intent intent = new Intent();
        intent.putExtra("file", newFile.getName());
        intent.putExtra("json", jsonFile.getName());
        activity.setResult(Activity.RESULT_OK, intent);
        activity.finish();
    } else {
        Log.e(TAG, results.first() + " " + context.getString(R.string.annotation_failed) + " : " + fault);
        Toast.makeText(context, results.first() + " " + context.getString(R.string.annotation_failed),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:com.abcvoipsip.ui.messages.MessageFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(THIS_FILE, "On activity result");
    if (requestCode == PICKUP_SIP_URI) {
        if (resultCode == Activity.RESULT_OK) {
            String from = data.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            setupFrom(from, from);/*from  w w  w. j  ava 2  s . co m*/
        }
        if (TextUtils.isEmpty(remoteFrom)) {
            if (quitListener != null) {
                quitListener.onQuit();
            }
        } else {
            loadMessageContent();
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.intel.xdk.contacts.Contacts.java

@SuppressWarnings("deprecation")
public void contactsChooserActivityResult(int requestCode, int resultCode, Intent intent) {

    if (resultCode == Activity.RESULT_OK) {
        Cursor cursor = activity.managedQuery(intent.getData(), null, null, null, null);
        cursor.moveToNext();//from ww w.  j a  va  2  s.  c  o m
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));

        getAllContacts();
        String js = String.format(
                " var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.choose',true,true);e.success=true;e.contactid='%s';document.dispatchEvent(e);",
                contactId);
        injectJS("javascript:" + js);
        busy = false;
    } else {
        String js = "var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.choose',true,true);e.success=false;e.message='User canceled';document.dispatchEvent(e);";
        injectJS("javascript:" + js);
        busy = false;
    }

}

From source file:camera.AnotherCamera.java

/**
 * The activity returns with the photo./*  w  ww .  jav a2  s .  c o  m*/
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_TAKE_PHOTO && resultCode == Activity.RESULT_OK) {
        addPhotoToGallery();
        CameraActivity activity = (CameraActivity) getActivity();

        // Show the full sized image.
        setFullImageFromFilePath(activity.getCurrentPhotoPath(), mImageView);
        setFullImageFromFilePath(activity.getCurrentPhotoPath(), mThumbnailImageView);
    } else {
        Toast.makeText(getActivity(), "Image Capture Failed", Toast.LENGTH_SHORT).show();
    }
}