Example usage for android.app Activity RESULT_FIRST_USER

List of usage examples for android.app Activity RESULT_FIRST_USER

Introduction

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

Prototype

int RESULT_FIRST_USER

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

Click Source Link

Document

Start of user-defined activity results.

Usage

From source file:com.freecast.LudoCast.MainActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult() was called1");
    if (requestCode == FIRST_REQUEST_CODE && resultCode == Activity.RESULT_FIRST_USER) {
        if (data != null) {
            Log.d(TAG, "onActivityResult was call");
        }//  ww w  .  ja  v  a  2 s.  com
    }
}

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

private void populateScoreboard() {
    // Ensure all components are firstly removed from scoreboardContainer
    scoreboardContainer.removeAllViews();

    // Ensure the progress spinner is hidden
    progressContainer.setVisibility(View.INVISIBLE);

    // Ensure scoreboardEntriesList is not null and not empty first
    if (application.getScoreboardEntriesList() == null || application.getScoreboardEntriesList().size() <= 0) {
        closeAndShowError(getResources().getString(R.string.error_no_scores));
    } else {// w  ww .ja  v  a 2s.  co  m
        // Iterate through scoreboardEntriesList, creating new UI elements for each entry
        int index = 0;
        Iterator<ScoreboardEntry> scoreboardEntriesIterator = application.getScoreboardEntriesList().iterator();
        while (scoreboardEntriesIterator.hasNext()) {
            // Get the current scoreboard entry
            final ScoreboardEntry currentScoreboardEntry = scoreboardEntriesIterator.next();

            // FrameLayout Container for the currentScoreboardEntry ...

            // Create and add a new FrameLayout to display the details of this entry
            FrameLayout frameLayout = new FrameLayout(getActivity());
            scoreboardContainer.addView(frameLayout);

            // Set the attributes for this frameLayout
            int topPadding = getResources().getDimensionPixelSize(R.dimen.scoreboard_entry_top_margin);
            frameLayout.setPadding(0, topPadding, 0, 0);

            // ImageView background image ...
            {
                // Create and add an ImageView for the background image to this entry
                ImageView backgroundImageView = new ImageView(getActivity());
                frameLayout.addView(backgroundImageView);

                // Set the image of the backgroundImageView
                String uri = "drawable/scores_stub_even";
                if (index % 2 != 0) {
                    // Odd entry
                    uri = "drawable/scores_stub_odd";
                }
                int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName());
                Drawable image = getResources().getDrawable(imageResource);
                backgroundImageView.setImageDrawable(image);

                // Other attributes of backgroundImageView to modify
                FrameLayout.LayoutParams backgroundImageViewLayoutParams = new FrameLayout.LayoutParams(
                        FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
                int backgroundImageViewMarginTop = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_background_imageview_margin_top);
                backgroundImageViewLayoutParams.setMargins(0, backgroundImageViewMarginTop, 0, 0);
                backgroundImageViewLayoutParams.gravity = Gravity.LEFT;
                if (index % 2 != 0) {
                    // Odd entry
                    backgroundImageViewLayoutParams.gravity = Gravity.RIGHT;
                }
                backgroundImageView.setLayoutParams(backgroundImageViewLayoutParams);
            }

            // ProfilePictureView of the current user ...
            {
                // Create and add a ProfilePictureView for the current user entry's profile picture
                ProfilePictureView profilePictureView = new ProfilePictureView(getActivity());
                frameLayout.addView(profilePictureView);

                // Set the attributes of the profilePictureView
                int profilePictureViewWidth = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_width);
                FrameLayout.LayoutParams profilePictureViewLayoutParams = new FrameLayout.LayoutParams(
                        profilePictureViewWidth, profilePictureViewWidth);
                int profilePictureViewMarginLeft = 0;
                int profilePictureViewMarginTop = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_top);
                int profilePictureViewMarginRight = 0;
                int profilePictureViewMarginBottom = 0;
                if (index % 2 == 0) {
                    profilePictureViewMarginLeft = getResources()
                            .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_left);
                } else {
                    profilePictureViewMarginRight = getResources()
                            .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_right);
                }
                profilePictureViewLayoutParams.setMargins(profilePictureViewMarginLeft,
                        profilePictureViewMarginTop, profilePictureViewMarginRight,
                        profilePictureViewMarginBottom);
                profilePictureViewLayoutParams.gravity = Gravity.LEFT;
                if (index % 2 != 0) {
                    // Odd entry
                    profilePictureViewLayoutParams.gravity = Gravity.RIGHT;
                }
                profilePictureView.setLayoutParams(profilePictureViewLayoutParams);

                // Finally set the id of the user to show their profile pic
                profilePictureView.setProfileId(currentScoreboardEntry.getId());
            }

            // LinearLayout to hold the text in this entry

            // Create and add a LinearLayout to hold the TextViews
            LinearLayout textViewsLinearLayout = new LinearLayout(getActivity());
            frameLayout.addView(textViewsLinearLayout);

            // Set the attributes for this textViewsLinearLayout
            FrameLayout.LayoutParams textViewsLinearLayoutLayoutParams = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            int textViewsLinearLayoutMarginLeft = 0;
            int textViewsLinearLayoutMarginTop = getResources()
                    .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_top);
            int textViewsLinearLayoutMarginRight = 0;
            int textViewsLinearLayoutMarginBottom = 0;
            if (index % 2 == 0) {
                textViewsLinearLayoutMarginLeft = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_left);
            } else {
                textViewsLinearLayoutMarginRight = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_right);
            }
            textViewsLinearLayoutLayoutParams.setMargins(textViewsLinearLayoutMarginLeft,
                    textViewsLinearLayoutMarginTop, textViewsLinearLayoutMarginRight,
                    textViewsLinearLayoutMarginBottom);
            textViewsLinearLayoutLayoutParams.gravity = Gravity.LEFT;
            if (index % 2 != 0) {
                // Odd entry
                textViewsLinearLayoutLayoutParams.gravity = Gravity.RIGHT;
            }
            textViewsLinearLayout.setLayoutParams(textViewsLinearLayoutLayoutParams);
            textViewsLinearLayout.setOrientation(LinearLayout.VERTICAL);

            // TextView with the position and name of the current user
            {
                // Set the text that should go in this TextView first
                int position = index + 1;
                String currentScoreboardEntryTitle = position + ". " + currentScoreboardEntry.getName();

                // Create and add a TextView for the current user position and first name
                TextView titleTextView = new TextView(getActivity());
                textViewsLinearLayout.addView(titleTextView);

                // Set the text and other attributes for this TextView
                titleTextView.setText(currentScoreboardEntryTitle);
                titleTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerNameFont);
            }

            // TextView with the score of the current user
            {
                // Create and add a TextView for the current user score
                TextView scoreTextView = new TextView(getActivity());
                textViewsLinearLayout.addView(scoreTextView);

                // Set the text and other attributes for this TextView
                scoreTextView.setText("Score: " + currentScoreboardEntry.getScore());
                scoreTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerScoreFont);
            }

            // Finally make this frameLayout clickable so that a game starts with the user smashing
            // the user represented by this frameLayout in the scoreContainer
            frameLayout.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        Bundle bundle = new Bundle();
                        bundle.putString("user_id", currentScoreboardEntry.getId());

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

                        getActivity().setResult(Activity.RESULT_FIRST_USER, i);
                        getActivity().finish();
                        return false;
                    } else {
                        return true;
                    }
                }

            });

            // Increment the index before looping back
            index++;
        }
    }
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

private Intent handleMessageIntent(Intent intent, Bundle extras) {
    String action = extras.getString(ACTION);
    if (action != null && action.equals(DISMISS_NOTIFICATION)) {
        logger.debug("MFPPushIntentService:handleMessageIntent() - Dismissal message from GCM Server");
        dismissNotification(extras.getString(NID));
    } else {/*from  w  ww  .j  ava2  s .c o m*/
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                logger.debug("MFPPushIntentService:handleMessageIntent() - Received a message from GCM Server."
                        + intent.getExtras());
                MFPInternalPushMessage message = new MFPInternalPushMessage(intent);
                intent = new Intent(MFPPushUtils.getIntentPrefix(getApplicationContext()) + GCM_MESSAGE);
                intent.putExtra(GCM_EXTRA_MESSAGE, message);

                if (!isAppForeground()) {
                    logger.debug(
                            "MFPPushIntentService:handleMessageIntent() - App is not on foreground. Queue the intent for later re-sending when app is on foreground");
                    intentsQueue.add(intent);
                }
                getApplicationContext().sendOrderedBroadcast(intent, null, resultReceiver, null,
                        Activity.RESULT_FIRST_USER, null, null);
            }
        }
    }
    return intent;
}

From source file:it.feio.android.omninotes.ListFragment.java

@Override
public// Used to show a Crouton dialog after saved (or tried to) a note
void onActivityResult(int requestCode, final int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    switch (requestCode) {
    case REQUEST_CODE_CATEGORY:
        // Dialog retarded to give time to activity's views of being completely initialized
        // The dialog style is choosen depending on result code
        switch (resultCode) {
        case Activity.RESULT_OK:
            mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM);
            EventBus.getDefault().post(new CategoriesUpdatedEvent());
            break;
        case Activity.RESULT_FIRST_USER:
            mainActivity.showMessage(R.string.category_deleted, ONStyle.ALERT);
            break;
        default://  w  ww  .  ja va  2  s.  c om
            break;
        }

        break;

    case REQUEST_CODE_CATEGORY_NOTES:
        if (intent != null) {
            Category tag = intent.getParcelableExtra(Constants.INTENT_CATEGORY);
            categorizeNotesExecute(tag);
        }
        break;

    case REQUEST_CODE_ADD_ALARMS:
        list.clearChoices();
        selectedNotes.clear();
        finishActionMode();
        list.invalidateViews();
        break;

    default:
        break;
    }

}

From source file:com.dycody.android.idealnote.ListFragment.java

@Override
public// Used to show a Crouton dialog after saved (or tried to) a note
void onActivityResult(int requestCode, final int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    switch (requestCode) {
    case REQUEST_CODE_CATEGORY:
        // Dialog retarded to give time to activity's views of being completely initialized
        // The dialog style is choosen depending on result code
        switch (resultCode) {
        case Activity.RESULT_OK:
            Toast.makeText(getActivity(), R.string.category_saved, Toast.LENGTH_SHORT).show();
            //mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM);
            EventBus.getDefault().post(new CategoriesUpdatedEvent());
            break;
        case Activity.RESULT_FIRST_USER:
            Toast.makeText(getActivity(), R.string.category_deleted, Toast.LENGTH_SHORT).show();
            //mainActivity.showMessage(R.string.category_deleted, ONStyle.ALERT);
            break;
        default:/*w w w . j  a va2 s.c o m*/
            break;
        }

        break;

    case REQUEST_CODE_CATEGORY_NOTES:
        if (intent != null) {
            Category tag = intent.getParcelableExtra(Constants.INTENT_CATEGORY);
            categorizeNotesExecute(tag);
        }
        break;

    case REQUEST_CODE_ADD_ALARMS:
        list.clearChoices();
        selectedNotes.clear();
        finishActionMode();
        list.invalidateViews();
        break;

    default:
        break;
    }

}

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

public void goBackToDialer() {
    Intent intent = new Intent();
    intent.putExtra("Transfer", false);
    setResult(Activity.RESULT_FIRST_USER, intent);
    finish();/*from  ww w. j  a v  a2  s  . co  m*/
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Connects to file provider service, then loads root directory. If can not,
 * then finishes this activity with result code =
 * {@link Activity#RESULT_CANCELED}//  w  w  w  .  j  a  v  a 2  s.c o  m
 * 
 * @param savedInstanceState
 */
private void loadInitialPath(final Bundle savedInstanceState) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, String.format("loadInitialPath() >> authority=[%s] | mRoot=[%s]",
                mFileProviderAuthority, mRoot));

    /*
     * Priorities for starting path:
     * 
     * 1. Current location (in case the activity has been killed after
     * configurations changed).
     * 
     * 2. Selected file from key EXTRA_SELECT_FILE.
     * 
     * 3. Root path from key EXTRA_ROOTPATH.
     * 
     * 4. Last location.
     */

    new LoadingDialog<Void, Uri, Bundle>(getActivity(), false) {

        /**
         * In onPostExecute(), if result is null then check this value. If
         * this is not null, show a toast and finish. If this is null, call
         * showCannotConnectToServiceAndWaitForTheUserToFinish().
         */
        String errMsg = null;
        boolean errorMessageInDialog = false;

        String log = "";

        @Override
        protected Bundle doInBackground(Void... params) {
            /*
             * Current location
             */
            Uri path = (Uri) (savedInstanceState != null ? savedInstanceState.getParcelable(CURRENT_LOCATION)
                    : null);

            log += "savedInstanceState != null ? " + (savedInstanceState != null);
            log += "\npath != null ? " + (path != null);
            if (path != null)
                log += path;
            log += "\nmRoot != null ? " + (mRoot != null);
            if (mRoot != null)
                log += mRoot;

            if (mRoot != null) {
                Uri queryUri = BaseFile.genContentUriApi(mRoot.getAuthority()).buildUpon()
                        .appendPath(BaseFile.CMD_CHECK_CONNECTION)
                        .appendQueryParameter(BaseFile.PARAM_SOURCE, mRoot.getLastPathSegment()).build();
                Cursor cursor = getActivity().getContentResolver().query(queryUri, null, null, null, null);
                log += "\ncursor != null ? " + (cursor != null);
                if (cursor != null) {
                    cursor.moveToFirst();

                    errMsg = getString(R.string.afc_msg_cannot_connect_to_file_provider_service) + " " + " "
                            + cursor.getString(0);
                    errorMessageInDialog = true;
                    return null;
                }

            }

            try {
                /*
                 * Selected file
                 */
                log += "try selected file ";
                if (path == null) {
                    path = (Uri) getArguments().getParcelable(FileChooserActivity.EXTRA_SELECT_FILE);

                    if (path != null && BaseFileProviderUtils.fileExists(getActivity(), path))
                        path = BaseFileProviderUtils.getParentFile(getActivity(), path);
                }
                log += "success ? " + (path != null);

                /*
                 * Rootpath
                 */
                log += "rootpath";
                if ((path == null) || (!BaseFileProviderUtils.isDirectory(getActivity(), path))) {
                    log += " assign";
                    path = mRoot;
                }
                if (path != null) {
                    log += " path=" + path;
                    log += " isdir?" + BaseFileProviderUtils.isDirectory(getActivity(), path);
                }

                /*
                 * Last location
                 */
                if (path == null && DisplayPrefs.isRememberLastLocation(getActivity())) {
                    String lastLocation = DisplayPrefs.getLastLocation(getActivity());
                    if (lastLocation != null) {
                        path = Uri.parse(lastLocation);
                        log += " from last loc";
                    }
                }

                if (path == null || !BaseFileProviderUtils.isDirectory(getActivity(), path)) {
                    path = BaseFileProviderUtils.getDefaultPath(getActivity(),
                            path == null ? mFileProviderAuthority : path.getAuthority());
                    log += " getDefault. path==null?" + (path == null);
                }
            } catch (Exception ex) {
                errMsg = getString(R.string.afc_msg_cannot_connect_to_file_provider_service) + " "
                        + ex.toString();
                errorMessageInDialog = true;
                return null;
            }

            if (path == null) {
                errMsg = "Did not find initial path.";
                errorMessageInDialog = true;
                return null;
            }
            if (BuildConfig.DEBUG)
                Log.d(CLASSNAME, "loadInitialPath() >> " + path);

            publishProgress(path);

            if (BaseFileProviderUtils.fileCanRead(getActivity(), path)) {
                Bundle result = new Bundle();
                result.putParcelable(PATH, path);
                return result;
            } else {
                errorMessageInDialog = true;
                errMsg = getString(R.string.afc_pmsg_cannot_access_dir,
                        BaseFileProviderUtils.getFileName(getActivity(), path));
            }

            return null;
        }// doInBackground()

        @Override
        protected void onProgressUpdate(Uri... progress) {
            setCurrentLocation(progress[0]);
        }// onProgressUpdate()

        @Override
        protected void onPostExecute(Bundle result) {
            super.onPostExecute(result);

            if (result != null) {
                /*
                 * Prepare the loader. Either re-connect with an existing
                 * one, or start a new one.
                 */
                getLoaderManager().initLoader(mIdLoaderData, result, FragmentFiles.this);
            } else if (errMsg != null) {
                if (errorMessageInDialog) {
                    Dlg.showError(getActivity(), errMsg, new DialogInterface.OnCancelListener() {

                        @Override
                        public void onCancel(DialogInterface dialog) {
                            getActivity().setResult(Activity.RESULT_FIRST_USER);
                            getActivity().finish();
                        }// onCancel()
                    });
                } else {
                    Dlg.toast(getActivity(), errMsg, Dlg.LENGTH_SHORT);
                    getActivity().finish();
                }

            } else
                showCannotConnectToServiceAndWaitForTheUserToFinish("loadInitialPath");
        }// onPostExecute()

    }.execute();
}

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

private void goBackToDialerAndDisplayTransferButton() {
    Intent intent = new Intent();
    intent.putExtra("Transfer", true);
    setResult(Activity.RESULT_FIRST_USER, intent);
    finish();/*from  ww w .  j  a  va 2  s. co  m*/
}

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

private void goToChatList() {
    Intent intent = new Intent();
    intent.putExtra("chat", true);
    setResult(Activity.RESULT_FIRST_USER, intent);
    finish();
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * As the name means...//from w w  w .j av  a  2  s  .c  o m
 */
private void showCannotConnectToServiceAndWaitForTheUserToFinish(String info) {
    Dlg.showError(getActivity(),
            getActivity().getString(R.string.afc_msg_cannot_connect_to_file_provider_service) + " " + info,
            new DialogInterface.OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    getActivity().setResult(Activity.RESULT_FIRST_USER);
                    getActivity().finish();
                }// onCancel()
            });
}