Example usage for android.os Bundle keySet

List of usage examples for android.os Bundle keySet

Introduction

In this page you can find the example usage for android.os Bundle keySet.

Prototype

public Set<String> keySet() 

Source Link

Document

Returns a Set containing the Strings used as keys in this Bundle.

Usage

From source file:org.ohmage.prompt.remoteactivity.RemoteActivityPrompt.java

/**
 * If the 'resultCode' indicates failure then we treat it as if the user
 * has skipped the prompt. If skipping is not allowed, we log it as an
 * error, but we do not make an entry in the results array to prevent
 * corrupting it nor do we set as skipped to prevent us from corrupting
 * the entire survey./*from   w  w w  .  java  2  s .c  o m*/
 * 
 * If the 'resultCode' indicates success then we check to see what was
 * returned via the parameterized 'data' object. If 'data' is null, we put
 * an empty JSONObject in the array to indicate that something went wrong.
 * If 'data' is not null, we get all the key-value pairs from the data's
 * extras and place them in a JSONObject. If the keys for these extras are
 * certain "special" return codes, some of which are required, then we
 * handle those as well which may or may not include putting them in the
 * JSONObject. Finally, we put the JSONObject in the JSONArray that is the
 * return value for this prompt type.
 */
@Override
public void handleActivityResult(Context context, int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_CANCELED) {
        if (mSkippable.equalsIgnoreCase("true")) {
            this.setSkipped(true);
        } else if (mSkippable.equalsIgnoreCase("false")) {
            // The Activity was canceled for some reason, but it shouldn't
            // have been.
            Log.e(TAG, "The Activity was canceled, but the prompt isn't set as skippable.");
        } else {
            // This should _never_ happen!
            Log.e(TAG, "Invalid 'skippable' value: " + mSkippable);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        if (data != null) {
            if (responseArray == null) {
                responseArray = new JSONArray();
            }

            boolean singleValueFound = false;
            JSONObject currResponse = new JSONObject();
            Bundle extras = data.getExtras();
            Iterator<String> keysIter = extras.keySet().iterator();
            while (keysIter.hasNext()) {
                String nextKey = keysIter.next();
                if (FEEDBACK_STRING.equals(nextKey)) {
                    feedbackText.setText(extras.getString(nextKey));
                } else {
                    try {
                        currResponse.put(nextKey, extras.get(nextKey));
                    } catch (JSONException e) {
                        Log.e(TAG, "Invalid return value from remote Activity for key: " + nextKey);
                    }

                    if (SINGLE_VALUE_STRING.equals(nextKey)) {
                        singleValueFound = true;
                    }
                }
            }

            if (singleValueFound) {
                responseArray.put(currResponse);
            } else {
                // We cannot add this to the list of responses because it
                // will be rejected for not containing the single-value
                // value.
                Log.e(TAG,
                        "The remote Activity is not returning a single value which is required for CSV export.");
            }
        } else {
            // If the data is null, we put an empty JSONObject in the
            // array to indicate that the data was null.
            responseArray.put(new JSONObject());
            Log.e(TAG, "The data returned by the remote Activity was null.");
        }
    }
    // TODO: Possibly support user-defined Activity results:
    //         resultCode > Activity.RESULT_FIRST_USER
    //
    // One obvious possibility is some sort of "SKIPPED" return code.
}

From source file:bolts.AppLinkNavigation.java

/**
 * Gets a JSONObject equivalent to the input bundle for use when falling back to a web navigation.
 *//* w  w  w. jav a 2s .co  m*/
private JSONObject getJSONForBundle(Bundle bundle) throws JSONException {
    JSONObject root = new JSONObject();
    for (String key : bundle.keySet()) {
        root.put(key, getJSONValue(bundle.get(key)));
    }
    return root;
}

From source file:com.canappi.connector.yp.yhere.SettingsView.java

public void viewDidLoad() {

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        Set<String> keys = extras.keySet();
        for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
            String key = iter.next();
            Class c = SearchView.class;
            try {
                Field f = c.getDeclaredField(key);
                Object extra = extras.get(key);
                String value = extra.toString();
                f.set(this, extras.getString(value));
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();//w  w  w.j av a 2  s. c o  m
            } catch (NoSuchFieldException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else {

    }

    settingsViewIds = new HashMap();
    settingsViewValues = new HashMap();

    isUserDefault = true;

    if (isUserDefault) {
        searchlocEditText.setText(retrieveFromUserDefaultsFor("searchloc"), TextView.BufferType.EDITABLE);
    }

    String updateZipButtonText = "Update";
    String updateZipButtonPressedText = "";

    updateZipButton = (Button) findViewById(R.id.updateZipButton);
    updateZipButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            updateDefaults(v);
        }
    });
    didSelectViewController();

}

From source file:com.kakao.helper.SharedPreferencesCache.java

public synchronized void save(final Bundle bundle) {
    Utility.notNull(bundle, "bundle");

    SharedPreferences.Editor editor = file.edit();
    for (String key : bundle.keySet()) {
        try {/*from  w w  w .ja va  2  s  . c  o m*/
            serializeKey(key, bundle, editor);
        } catch (JSONException e) {
            Logger.getInstance().w("Error processing value for key: " + key + ", e = " + e);
            return;
        }
    }

    boolean successfulCommit = editor.commit();
    if (!successfulCommit) {
        Logger.getInstance().w("SharedPreferences.Editor.commit() was not successful");
    } else {
        for (String key : bundle.keySet()) {
            try {
                deserializeKey(key);
            } catch (JSONException e) {
                Logger.getInstance().w("Error reading cached value for key: " + key + ", e = " + e);
            }
        }
    }
}

From source file:com.inbeacon.cordova.CordovaInbeaconManager.java

/**
 * Transform Android event data into JSON Object used by JavaScript
 * @param intent inBeacon SDK event data
 * @return a JSONObject with keys 'event', 'name' and 'data'
 *//*from  ww w  .java  2  s  .  c  o  m*/
private JSONObject getEventObject(Intent intent) {
    String action = intent.getAction();
    String event = action.substring(action.lastIndexOf(".") + 1); // last part of action
    String message = intent.getStringExtra("message");
    Bundle extras = intent.getExtras();

    JSONObject eventObject = new JSONObject();
    JSONObject data = new JSONObject();

    try {
        if (extras != null) {
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                data.put(key, extras.get(key)); // Android API < 19
                //                    data.put(key, JSONObject.wrap(extras.get(key)));    // Android API >= 19
            }
        }
        data.put("message", message);

        eventObject.put("name", event);
        eventObject.put("data", data);

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
    }

    return eventObject;
}

From source file:com.amansoni.tripbook.activity.LocationLookup.java

/**
 * Updates fields based on data stored in the bundle.
 *//* ww w  .jav a  2s.  c om*/
private void updateValuesFromBundle(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        // Check savedInstanceState to see if the address was previously requested.
        if (savedInstanceState.keySet().contains(ADDRESS_REQUESTED_KEY)) {
            mAddressRequested = savedInstanceState.getBoolean(ADDRESS_REQUESTED_KEY);
        }

        if (savedInstanceState.keySet().contains(IMAGE_URI)) {
            //                mImageFilePath = savedInstanceState.getString(IMAGE_URI);
            showImage();
        }
        // Check savedInstanceState to see if the location address string was previously found
        // and stored in the Bundle. If it was found, display the address string in the UI.
        if (savedInstanceState.keySet().contains(LOCATION_ADDRESS_KEY)) {
            mAddressOutput = savedInstanceState.getString(LOCATION_ADDRESS_KEY);
            displayAddressOutput();
        }
    }
}

From source file:com.example.anish.myapplication.MainActivity.java

/**
 * Updates fields based on data stored in the bundle.
 *///ww w.  j a  v  a  2 s.c o m
private void updateValuesFromBundle(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        // Check savedInstanceState to see if the address was previously requested.
        if (savedInstanceState.keySet().contains(ADDRESS_REQUESTED_KEY)) {
            mAddressRequested = savedInstanceState.getBoolean(ADDRESS_REQUESTED_KEY);
        }
        // Check savedInstanceState to see if the location address string was previously found
        // and stored in the Bundle. If it was found, display the address string in the UI.
        if (savedInstanceState.keySet().contains(LOCATION_ADDRESS_KEY)) {
            mAddressOutput = savedInstanceState.getString(LOCATION_ADDRESS_KEY);
            displayAddressOutput();
        }
    }
}

From source file:com.kakao.util.helper.SharedPreferencesCache.java

public synchronized void save(final Bundle bundle) {
    Utility.notNull(bundle, "bundle");

    SharedPreferences.Editor editor = file.edit();
    for (String key : bundle.keySet()) {
        try {//from  w  w  w  . ja  v a  2  s  .  c o m
            serializeKey(key, bundle.get(key), editor);
        } catch (JSONException e) {
            Logger.w("SharedPreferences.save", "Error serializing value for key: " + key + ", e = " + e);
            return;
        }
    }

    editor.apply();
    for (String key : bundle.keySet()) {
        try {
            deserializeKey(key);
        } catch (JSONException e) {
            Logger.w("SharedPreferences.save", "Error deserializing value for key: " + key + ", e = " + e);
        }
    }
}

From source file:com.android.mms.rcs.FavoriteDetailActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i("RCS_UI", "requestCode=" + requestCode + ",resultCode=" + resultCode + ",data=" + data);
    if (resultCode != RESULT_OK) {
        return;/*  w  w  w.j  a  v a2 s  .  c o m*/
    }
    boolean success = false;
    switch (requestCode) {
    case REQUEST_CODE_RCS_PICK:
    case REQUEST_SELECT_GROUP:
        if (data != null) {
            Bundle bundle = data.getExtras().getBundle("result");
            final Set<String> keySet = bundle.keySet();
            final int recipientCount = (keySet != null) ? keySet.size() : 0;
            final ContactList list;
            list = ContactList.blockingGetByUris(buildUris(keySet, recipientCount));
            String[] numbers = list.getNumbers(false);
            success = RcsChatMessageUtils.sendRcsForwardMessage(FavoriteDetailActivity.this,
                    Arrays.asList(list.getNumbers()), null, mMsgId);
            if (success) {
                toast(R.string.forward_message_success);
            } else {
                toast(R.string.forward_message_fail);
            }
        }
        break;
    case REQUEST_SELECT_CONV:
        success = RcsChatMessageUtils.sendRcsForwardMessage(FavoriteDetailActivity.this, null, data, mMsgId);
        if (success) {
            toast(R.string.forward_message_success);
        } else {
            toast(R.string.forward_message_fail);
        }
        break;
    default:
        break;
    }
}

From source file:com.rappsantiago.weighttracker.profile.setup.ProfileSetupActivity.java

private boolean saveAndValidatePageData(int currentPage) {

    Fragment currentFragment = mPagerAdapter.getItem(currentPage);

    if (currentFragment instanceof PageWithData) {
        PageWithData currentFragmentData = (PageWithData) currentFragment;
        Bundle pageData = currentFragmentData.getProfileData();

        if (null == pageData) {
            return false;
        }//from   w ww  .  j ava2  s.  c o m

        Set<String> errors = new HashSet<>();

        // validate entries
        for (String key : pageData.keySet()) {
            Object obj = pageData.get(key);

            if (null == obj) {
                errors.add(key);
                continue;
            }

            if (obj instanceof String) { // name
                if (((String) obj).trim().isEmpty()) {
                    errors.add(key);
                }
            } else if (obj instanceof Double) { // weight, body fat index, height

                // body fat index is optional
                if (WeightHeightFragment.KEY_BODY_FAT_INDEX == key
                        || SetGoalsFragment.KEY_TARGET_BODY_FAT_INDEX == key) {
                    continue;
                }

                // inches is allowed to be 0 if foot is not less than or equal to 0
                if (WeightHeightFragment.KEY_HEIGHT_INCHES == key) {
                    if (errors.contains(WeightHeightFragment.KEY_HEIGHT)) {
                        if (0 >= ((Double) obj).doubleValue()) {
                            errors.add(key);
                        } else {
                            errors.remove(WeightHeightFragment.KEY_HEIGHT);
                        }
                    } else {
                        continue;
                    }
                }

                if (0 >= ((Double) obj).doubleValue()) {
                    errors.add(key);
                }
            } else if (obj instanceof Long) { // birthday, due date

                // due date is optional
                if (SetGoalsFragment.KEY_DUE_DATE == key) {
                    continue;
                }

                if (0 >= ((Long) obj).longValue()) {
                    errors.add(key);
                }
            }
        }

        boolean withNoErrors = errors.isEmpty();

        if (withNoErrors) {
            Log.d(TAG, "pageData = " + pageData);
            mProfileData.putAll(pageData);
        } else {
            Log.d(TAG, errors.toString());
            currentFragmentData.showErrorMessage(errors);
        }

        return withNoErrors;
    } else {
        return true;
    }
}