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.dycody.android.idealnote.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case SPRINGPAD_IMPORT:
            Uri filesUri = intent.getData();
            String path = FileHelper.getPath(getActivity(), filesUri);
            // An IntentService will be launched to accomplish the import task
            Intent service = new Intent(getActivity(), DataBackupIntentService.class);
            service.setAction(DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD);
            service.putExtra(DataBackupIntentService.EXTRA_SPRINGPAD_BACKUP, path);
            getActivity().startService(service);
            break;

        case RINGTONE_REQUEST_CODE:
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            String notificationSound = uri == null ? null : uri.toString();
            prefs.edit().putString("settings_notification_ringtone", notificationSound).apply();
            break;

        default://from w  ww. ja v  a 2s .com
            Log.e(Constants.TAG, "Wrong element choosen: " + requestCode);
        }
    }
}

From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java

/**
 * <p>Returns the transcription results (matches) to the caller,
 * or sends them to the pending intent, or performs a web search.</p>
 *
 * <p>If a pending intent was specified then use it. This is the case with
 * applications that use the standard search bar (e.g. Google Maps and YouTube).</p>
 *
 * <p>Otherwise. If there was no caller (i.e. we cannot return the results), or
 * the caller asked us explicitly to perform "web search", then do that, possibly
 * disambiguating the results or redoing the recognition.
 * This is the case when K6nele was launched from its launcher icon (i.e. no caller),
 * or from a browser app.//from  www.j  ava  2  s.  com
 * (Note that trying to return the results to Google Chrome does not seem to work.)</p>
 *
 * <p>Otherwise. Just return the results to the caller.</p>
 *
 * <p>Note that we assume that the given list of matches contains at least one
 * element.</p>
 *
 * @param handler message handler
 * @param matches transcription results (one or more hypotheses)
 */
private void returnOrForwardMatches(final Handler handler, ArrayList<String> matches) {
    // Throw away matches that the user is not interested in
    int maxResults = mExtras.getInt(RecognizerIntent.EXTRA_MAX_RESULTS);
    if (maxResults > 0 && matches.size() > maxResults) {
        matches.subList(maxResults, matches.size()).clear();
    }

    if (mExtraResultsPendingIntent == null) {
        if (getCallingActivity() == null || RecognizerIntent.ACTION_WEB_SEARCH.equals(getIntent().getAction())
                || mExtras.getBoolean(RecognizerIntent.EXTRA_WEB_SEARCH_ONLY)) {
            handleResultsByWebSearch(this, handler, matches);
            return;
        } else {
            setResultIntent(handler, matches);
        }
    } else {
        Bundle bundle = mExtras.getBundle(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE);
        if (bundle == null) {
            bundle = new Bundle();
        }
        String match = matches.get(0);
        //mExtraResultsPendingIntentBundle.putString(SearchManager.QUERY, match);
        Intent intent = new Intent();
        intent.putExtras(bundle);
        // This is for Google Maps, YouTube, ...
        intent.putExtra(SearchManager.QUERY, match);
        // This is for SwiftKey X, ...
        intent.putStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS, matches);
        String message = "";
        if (matches.size() == 1) {
            message = match;
        } else {
            message = matches.toString();
        }
        // Display a toast with the transcription.
        handler.sendMessage(
                createMessage(MSG_TOAST, String.format(getString(R.string.toastForwardedMatches), message)));
        try {
            mExtraResultsPendingIntent.send(this, Activity.RESULT_OK, intent);
        } catch (CanceledException e) {
            handler.sendMessage(createMessage(MSG_TOAST, e.getMessage()));
        }
    }
    finish();
}

From source file:com.github.gorbin.asne.googleplus.GooglePlusSocialNetwork.java

/**
 * Overrided for Google plus/*from   www .java  2 s  . c  om*/
 * @param requestCode The integer 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 data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    int sanitizedRequestCode = requestCode % 0x10000;
    if (sanitizedRequestCode == REQUEST_AUTH) {
        if (resultCode == Activity.RESULT_OK && !googleApiClient.isConnected()
                && !googleApiClient.isConnecting()) {
            // This time, connect should succeed.
            googleApiClient.connect();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            if (mLocalListeners.get(REQUEST_LOGIN) != null) {
                mLocalListeners.get(REQUEST_LOGIN).onError(getID(), REQUEST_LOGIN, "canceled", null);
            }
        }
    }
}

From source file:com.facebook.android.friendsmash.GameFragment.java

void setLives(int lives) {
    this.lives = lives;

    if (getActivity() != null) {
        // Update the livesContainer
        livesContainer.removeAllViews();
        for (int i = 0; i < lives; i++) {
            ImageView heartImageView = new ImageView(getActivity());
            heartImageView.setImageResource(R.drawable.heart_red);
            livesContainer.addView(heartImageView);
        }//from   ww  w  .j a  v a 2s.  c o  m

        if (lives <= 0) {
            // User has no lives left, so end the game, passing back the score
            Bundle bundle = new Bundle();
            bundle.putInt("score", getScore());

            Intent i = new Intent();
            i.putExtras(bundle);

            getActivity().setResult(Activity.RESULT_OK, i);
            getActivity().finish();
        }
    }
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

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

    Log.d(TAG, String.format("onActivityResult(%d, %d, %s)", requestCode, resultCode, data));

    if (data == null) {
        return;//from   w  ww  .  j  a  v a  2 s .  c  o  m
    }

    if (data.getBooleanExtra(EXTRA_REFRESH_FEED_LIST, false)
            || data.getBooleanExtra(PODCAST_ADD_REFRESH_FEED_LIST, false)) {

        if (resultCode == Activity.RESULT_OK) {
            Bundle bundle = new Bundle();
            if (data.getBooleanExtra(PODCAST_ADD_REFRESH_FEED_LIST, false)) {
                bundle.putBoolean(PODCAST_ADD_REFRESH_FEED_LIST, true);
            } else {
                bundle.putBoolean(EXTRA_REFRESH_FEED_LIST, true);
            }
            onRefreshPressed(bundle);
        } else {
            if (data.getBooleanExtra(EXTRA_REFRESH_FEED_LIST, false)) {
                Toast.makeText(this, getString(R.string.you_can_refresh_your_podcasts_later), Toast.LENGTH_LONG)
                        .show();
            }
        }
    }

}

From source file:com.lewa.crazychapter11.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    switch (requestCode) {
    case PICK_CONTACT:
        if (resultCode == Activity.RESULT_OK) {
            Uri contactData = intent.getData();
            CursorLoader cursorLoader = new CursorLoader(this, contactData, null, null, null, null);

            Cursor cursor = cursorLoader.loadInBackground();
            if (cursor != null && cursor.moveToFirst()) {
                Log.i("algerheContact", " comhere 111");
                String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cursor
                        .getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                String phoneNumber = "????";

                Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null);
                if (phones == null) {
                    return;
                }/*  w  ww  .  j  a  va  2 s .  c  om*/
                // Log.i("algerheContact"," comhere 222 phones.moveToFirst()="+phones.moveToFirst());
                if (phones.moveToFirst()) {
                    phoneNumber = phones
                            .getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                }

                phones.close();
                EditText show = (EditText) findViewById(R.id.show);

                show.setText(name);
                EditText phone = (EditText) findViewById(R.id.phone);
                phone.setText(phoneNumber);

                show.setVisibility(View.GONE);
                phone.setVisibility(View.GONE);
            }
            cursor.close();
        }
        break;
    }

    if (requestCode == 0 && resultCode == 0 && intent != null) {
        Bundle data = intent.getExtras();
        if (data == null) {
            return;
        }
        String resultArms = data.getString("armType");
        String showArms = "?" + resultArms;
        show_txt = (EditText) findViewById(R.id.show_txt);
        if (resultArms != null && show_txt != null) {
            show_txt.setText(showArms);
        }
    }
}

From source file:cliq.com.cliqgram.fragments.CameraFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    Activity activity = getActivity();/*from   w ww. j  a  v a2  s .c o m*/

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK && data != null
            && data.getData() != null) {

        /**
         * @param imageDate byte[]
         * @param currentUser User
         * @param description String
         * @return post Post
         * Note: Any data in post object may not be able to
         * get before post.saveInBackground() in finished.
         * So, check the database (table "Post") on Parse to see if post is
         * created successfully.
         * If post is created successfully, it will be shown on home page.
         */
        Uri uri = data.getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), uri);
            // Log.d(TAG, String.valueOf(bitmap));

            startImageDisplayActivity(bitmap);

        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        activity.finish();
    }
}

From source file:co.taqat.call.ChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
        String fileToUploadPath = null;

        if (data != null && data.getData() != null) {
            fileToUploadPath = getRealPathFromURI(data.getData());
        } else if (imageToUploadUri != null) {
            fileToUploadPath = imageToUploadUri.getPath();
        }/*from  w  w w  .  j a  v a 2  s  .  c o m*/

        if (fileToUploadPath != null) {
            //showPopupMenuAskingImageSize(fileToUploadPath);
            sendImageMessage(fileToUploadPath, 0);
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.sim2dial.dialer.ChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
        if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) {
            Bitmap bm = (Bitmap) data.getExtras().get("data");
            showPopupMenuAskingImageSize(null, bm);
        } else if (data != null && data.getData() != null) {
            String filePath = getRealPathFromURI(data.getData());
            showPopupMenuAskingImageSize(filePath, null);
        } else if (imageToUploadUri != null) {
            String filePath = imageToUploadUri.getPath();
            showPopupMenuAskingImageSize(filePath, null);
        } else {/*  w  ww  . ja  va2s.  c  o m*/
            File file = new File(Environment.getExternalStorageDirectory(),
                    getString(R.string.temp_photo_name));
            if (file.exists()) {
                imageToUploadUri = Uri.fromFile(file);
                String filePath = imageToUploadUri.getPath();
                showPopupMenuAskingImageSize(filePath, null);
            }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.appybite.customer.AllowedHotels.java

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

    if (requestCode == 101 && resultCode == Activity.RESULT_OK) {

        Bundle extras = data.getExtras();
        String qrcode = extras.getString("SCAN_RESULT");
        Log.i("Scanner", "QRcode: " + qrcode);

        String order_type = PrefValue.getString(this, R.string.pref_order_type);

        if (NetworkUtils.haveInternet(this)) {
            checkQRCode(order_type, qrcode);
        } else {/*from   ww w  .  j ava2  s .  c  o  m*/

        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}