List of usage examples for android.os Bundle get
@Nullable
public Object get(String key)
From source file:com.facebook.SharedPreferencesTokenCache.java
private void serializeKey(String key, Bundle bundle, SharedPreferences.Editor editor) throws JSONException { Object value = bundle.get(key); if (value == null) { // Cannot serialize null values. return;/* w w w . ja v a2s. co m*/ } String supportedType = null; JSONArray jsonArray = null; JSONObject json = new JSONObject(); if (value instanceof Byte) { supportedType = TYPE_BYTE; json.put(JSON_VALUE, ((Byte) value).intValue()); } else if (value instanceof Short) { supportedType = TYPE_SHORT; json.put(JSON_VALUE, ((Short) value).intValue()); } else if (value instanceof Integer) { supportedType = TYPE_INTEGER; json.put(JSON_VALUE, ((Integer) value).intValue()); } else if (value instanceof Long) { supportedType = TYPE_LONG; json.put(JSON_VALUE, ((Long) value).longValue()); } else if (value instanceof Float) { supportedType = TYPE_FLOAT; json.put(JSON_VALUE, ((Float) value).doubleValue()); } else if (value instanceof Double) { supportedType = TYPE_DOUBLE; json.put(JSON_VALUE, ((Double) value).doubleValue()); } else if (value instanceof Boolean) { supportedType = TYPE_BOOLEAN; json.put(JSON_VALUE, ((Boolean) value).booleanValue()); } else if (value instanceof Character) { supportedType = TYPE_CHAR; json.put(JSON_VALUE, value.toString()); } else if (value instanceof String) { supportedType = TYPE_STRING; json.put(JSON_VALUE, (String) value); } else { // Optimistically create a JSONArray. If not an array type, we can null // it out later jsonArray = new JSONArray(); if (value instanceof byte[]) { supportedType = TYPE_BYTE_ARRAY; for (byte v : (byte[]) value) { jsonArray.put((int) v); } } else if (value instanceof short[]) { supportedType = TYPE_SHORT_ARRAY; for (short v : (short[]) value) { jsonArray.put((int) v); } } else if (value instanceof int[]) { supportedType = TYPE_INTEGER_ARRAY; for (int v : (int[]) value) { jsonArray.put(v); } } else if (value instanceof long[]) { supportedType = TYPE_LONG_ARRAY; for (long v : (long[]) value) { jsonArray.put(v); } } else if (value instanceof float[]) { supportedType = TYPE_FLOAT_ARRAY; for (float v : (float[]) value) { jsonArray.put((double) v); } } else if (value instanceof double[]) { supportedType = TYPE_DOUBLE_ARRAY; for (double v : (double[]) value) { jsonArray.put(v); } } else if (value instanceof boolean[]) { supportedType = TYPE_BOOLEAN_ARRAY; for (boolean v : (boolean[]) value) { jsonArray.put(v); } } else if (value instanceof char[]) { supportedType = TYPE_CHAR_ARRAY; for (char v : (char[]) value) { jsonArray.put(String.valueOf(v)); } } else if (value instanceof List<?>) { supportedType = TYPE_STRING_LIST; @SuppressWarnings("unchecked") List<String> stringList = (List<String>) value; for (String v : stringList) { jsonArray.put((v == null) ? JSONObject.NULL : v); } } else { // Unsupported type. Clear out the array as a precaution even though // it is redundant with the null supportedType. jsonArray = null; } } if (supportedType != null) { json.put(JSON_VALUE_TYPE, supportedType); if (jsonArray != null) { // If we have an array, it has already been converted to JSON. So use // that instead. json.putOpt(JSON_VALUE, jsonArray); } String jsonString = json.toString(); editor.putString(key, jsonString); } }
From source file:com.myandroidremote.AccountsActivity.java
/** * Registers for C2DM messaging with the given account name. * //from ww w .j a v a2 s. c o m * @param accountName * a String containing a Google account name */ private void register(final String accountName) { // Store the account name in shared preferences final SharedPreferences prefs = Util.getSharedPreferences(mContext); SharedPreferences.Editor editor = prefs.edit(); editor.putString(Util.ACCOUNT_NAME, accountName); editor.putString(Util.AUTH_COOKIE, null); editor.commit(); // Obtain an auth token and register final AccountManager mgr = AccountManager.get(mContext); Account[] accts = mgr.getAccountsByType("com.google"); for (Account acct : accts) { if (acct.name.equals(accountName)) { if (Util.isDebug(mContext)) { // Use a fake cookie for the dev mode app engine server // The cookie has the form email:isAdmin:userId // We set the userId to be the same as the account name String authCookie = "dev_appserver_login=" + accountName + ":false:" + accountName; boolean result = prefs.edit().putString(Util.AUTH_COOKIE, authCookie).commit(); C2DMessaging.register(mContext, Setup.SENDER_ID); } else { // Get the auth token from the AccountManager and convert // it into a cookie for the appengine server mgr.getAuthToken(acct, "ah", null, this, new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture<Bundle> future) { try { Bundle authTokenBundle = future.getResult(); String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString(); String authCookie = getAuthCookie(authToken); if (authCookie == null) { mgr.invalidateAuthToken("com.google", authToken); } prefs.edit().putString(Util.AUTH_COOKIE, authCookie).commit(); C2DMessaging.register(mContext, Setup.SENDER_ID); } catch (AuthenticatorException e) { Log.w(TAG, "Got AuthenticatorException " + e); Log.w(TAG, Log.getStackTraceString(e)); } catch (IOException e) { Log.w(TAG, "Got IOException " + Log.getStackTraceString(e)); Log.w(TAG, Log.getStackTraceString(e)); } catch (OperationCanceledException e) { Log.w(TAG, "Got OperationCanceledException " + e); Log.w(TAG, Log.getStackTraceString(e)); } } }, null); } break; } } }
From source file:com.groksolutions.grok.mobile.instance.InstanceListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); if (args != null) { _aggregation = (AggregationType) args.get(AggregationType.class.getCanonicalName()); if (_listAdapter != null) { _listAdapter.setAggregation(_aggregation); updateInstanceList();/*from w ww. j a v a2 s .c o m*/ } } }
From source file:com.example.wojtekswiderski.woahpaper.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); word = extras.get("word").toString(); sender = extras.get("sender").toString(); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*// w ww . j a va2 s .c o m * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { int results = numberResults(); if (results > MAXRESULTS) { int start; int i = 0; do { start = (int) (Math.random() * MAXRESULTS); i++; } while (setWallPaper(start) && i <= 10); } else { int i = 0; do { i++; } while (setWallPaper(i) && i <= 10); } sendNotification("Received " + word.substring(0, 1).toUpperCase() + word.substring(1) + " from " + sender.substring(0, 1).toUpperCase() + sender.substring(1)); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.facebook.SharedPreferencesTokenCachingStrategy.java
private void serializeKey(String key, Bundle bundle, SharedPreferences.Editor editor) throws JSONException { Object value = bundle.get(key); if (value == null) { // Cannot serialize null values. return;/* www . j ava 2 s . co m*/ } String supportedType = null; JSONArray jsonArray = null; JSONObject json = new JSONObject(); if (value instanceof Byte) { supportedType = TYPE_BYTE; json.put(JSON_VALUE, ((Byte) value).intValue()); } else if (value instanceof Short) { supportedType = TYPE_SHORT; json.put(JSON_VALUE, ((Short) value).intValue()); } else if (value instanceof Integer) { supportedType = TYPE_INTEGER; json.put(JSON_VALUE, ((Integer) value).intValue()); } else if (value instanceof Long) { supportedType = TYPE_LONG; json.put(JSON_VALUE, ((Long) value).longValue()); } else if (value instanceof Float) { supportedType = TYPE_FLOAT; json.put(JSON_VALUE, ((Float) value).doubleValue()); } else if (value instanceof Double) { supportedType = TYPE_DOUBLE; json.put(JSON_VALUE, ((Double) value).doubleValue()); } else if (value instanceof Boolean) { supportedType = TYPE_BOOLEAN; json.put(JSON_VALUE, ((Boolean) value).booleanValue()); } else if (value instanceof Character) { supportedType = TYPE_CHAR; json.put(JSON_VALUE, value.toString()); } else if (value instanceof String) { supportedType = TYPE_STRING; json.put(JSON_VALUE, value); } else if (value instanceof Enum<?>) { supportedType = TYPE_ENUM; json.put(JSON_VALUE, value.toString()); json.put(JSON_VALUE_ENUM_TYPE, value.getClass().getName()); } else { // Optimistically create a JSONArray. If not an array type, we can null // it out later jsonArray = new JSONArray(); if (value instanceof byte[]) { supportedType = TYPE_BYTE_ARRAY; for (byte v : (byte[]) value) { jsonArray.put((int) v); } } else if (value instanceof short[]) { supportedType = TYPE_SHORT_ARRAY; for (short v : (short[]) value) { jsonArray.put((int) v); } } else if (value instanceof int[]) { supportedType = TYPE_INTEGER_ARRAY; for (int v : (int[]) value) { jsonArray.put(v); } } else if (value instanceof long[]) { supportedType = TYPE_LONG_ARRAY; for (long v : (long[]) value) { jsonArray.put(v); } } else if (value instanceof float[]) { supportedType = TYPE_FLOAT_ARRAY; for (float v : (float[]) value) { jsonArray.put((double) v); } } else if (value instanceof double[]) { supportedType = TYPE_DOUBLE_ARRAY; for (double v : (double[]) value) { jsonArray.put(v); } } else if (value instanceof boolean[]) { supportedType = TYPE_BOOLEAN_ARRAY; for (boolean v : (boolean[]) value) { jsonArray.put(v); } } else if (value instanceof char[]) { supportedType = TYPE_CHAR_ARRAY; for (char v : (char[]) value) { jsonArray.put(String.valueOf(v)); } } else if (value instanceof List<?>) { supportedType = TYPE_STRING_LIST; @SuppressWarnings("unchecked") List<String> stringList = (List<String>) value; for (String v : stringList) { jsonArray.put((v == null) ? JSONObject.NULL : v); } } else { // Unsupported type. Clear out the array as a precaution even though // it is redundant with the null supportedType. jsonArray = null; } } if (supportedType != null) { json.put(JSON_VALUE_TYPE, supportedType); if (jsonArray != null) { // If we have an array, it has already been converted to JSON. So use // that instead. json.putOpt(JSON_VALUE, jsonArray); } String jsonString = json.toString(); editor.putString(key, jsonString); } }
From source file:com.example.drugsformarinemammals.Listview_DrugResults.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listview_drugresults); helper = new Handler_Sqlite(this); Bundle extra = this.getIntent().getExtras(); if (extra.containsKey("drugList")) { //option Combined Search drugList = (ArrayList<String>) extra.get("drugList"); } else {/* ww w . ja v a 2s . c o m*/ fiveLastScreen = (Boolean) extra.get("fiveLastScreen"); //option Five Last Searched orderDrugsByPriority(); } ListAdapter adapter = new ItemAdapterDrugResults(this, drugList); ListView listview = (ListView) findViewById(R.id.drugsresult); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String drugName = drugList.get(position); if (!helper.existDrug(drugName)) { String[] urls = { "http://formmulary.tk/Android/getGeneralInfoDrug.php?drug_name=", "http://formmulary.tk/Android/getInfoCodes.php?drug_name=" }; boolean sync = false; new GetGeneralInfoDrug(drugName, sync).execute(urls); } else { Intent intent = new Intent(getApplicationContext(), General_Info_Drug.class); intent.putExtra("drugName", drugName); intent.putExtra("fiveLastScreen", fiveLastScreen); startActivity(intent); if (fiveLastScreen) finish(); } } }); listview.setAdapter(adapter); }
From source file:hku.fyp14017.blencode.ui.controller.LookController.java
public Loader<Cursor> onCreateLoader(int id, Bundle arguments, FragmentActivity activity) { Uri imageUri = null;//from w w w .j a v a 2 s . c o m if (arguments != null) { imageUri = (Uri) arguments.get(LOADER_ARGUMENTS_IMAGE_URI); } String[] projection = { MediaStore.MediaColumns.DATA }; return new CursorLoader(activity, imageUri, projection, null, null, null); }
From source file:edu.mit.media.funf.probe.Probe.java
public static String normalizedStringRepresentation(Bundle dataRequest, Parameter[] availableParameters) { // We use JSONObject to ensure special characters are properly and consistently escaped during serialization // But key order is not guaranteed, so we make many of them List<String> representations = new ArrayList<String>(); for (Parameter parameter : availableParameters) { String name = parameter.getName(); Object value = dataRequest.get(name); if (value != null) { JSONObject jsonObject = new JSONObject(); try { jsonObject.put(name, value); representations.add(jsonObject.toString()); } catch (JSONException e) { Log.e(Utils.TAG,//w w w. j a v a2s. co m "Unable to serialize parameter name '" + name + "' with value '" + value + "'"); } } } Collections.sort(representations); return "[" + Utils.join(representations, ",") + "]"; }
From source file:com.ibm.pi.beacon.PIBeaconSensorService.java
private void handleCommands(Intent intent) { Bundle extras = intent.getExtras(); // check passed in intent for commands sent from Beacon Sensor wrapper class if (extras != null) { if (extras.containsKey(PIBeaconSensor.ADAPTER_KEY)) { mPiApiAdapter = (PIAPIAdapter) extras.get(PIBeaconSensor.ADAPTER_KEY); }/*from w w w. j a va2 s .c om*/ if (extras.containsKey(PIBeaconSensor.SEND_INTERVAL_KEY)) { PILogger.d(TAG, "updating send interval to: " + mSendInterval); mSendInterval = extras.getLong(PIBeaconSensor.SEND_INTERVAL_KEY); } if (extras.containsKey(PIBeaconSensor.BEACON_LAYOUT_KEY)) { String beaconLayout = intent.getStringExtra(PIBeaconSensor.BEACON_LAYOUT_KEY); PILogger.d(TAG, "adding beacon layout: " + beaconLayout); mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(beaconLayout)); } if (extras.containsKey(PIBeaconSensor.BACKGROUND_SCAN_PERIOD_KEY)) { PILogger.d(TAG, "updating background scan period to: " + mBackgroundScanPeriod); mBackgroundScanPeriod = extras.getLong(PIBeaconSensor.BACKGROUND_SCAN_PERIOD_KEY); mBeaconManager.setBackgroundScanPeriod(mBackgroundScanPeriod); } if (extras.containsKey(PIBeaconSensor.BACKGROUND_BETWEEN_SCAN_PERIOD_KEY)) { PILogger.d(TAG, "updating background between scan period to: " + mBackgroundBetweenScanPeriod); mBackgroundBetweenScanPeriod = extras.getLong(PIBeaconSensor.BACKGROUND_BETWEEN_SCAN_PERIOD_KEY); mBeaconManager.setBackgroundBetweenScanPeriod(mBackgroundBetweenScanPeriod); } if (extras.containsKey(PIBeaconSensor.START_IN_BACKGROUND_KEY)) { PILogger.d(TAG, "service started up in the background, starting sensor in background mode"); mBeaconManager.setBackgroundMode(true); } } if (intent.getAction() != null) { String action = intent.getAction(); if (action.equals(PIBeaconSensor.INTENT_ACTION_START)) { PILogger.d(TAG, "Service has started scanning for beacons"); mBeaconManager.bind(this); } else if (action.equals(PIBeaconSensor.INTENT_ACTION_STOP)) { PILogger.d(TAG, "Service has stopped scanning for beacons"); mBeaconManager.unbind(this); stopSelf(); } } }
From source file:com.example.kharlamov.cheesetask.CheeseListFragment.java
@Nullable @Override/*from w ww. ja v a 2 s .c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true); loaderId = getArguments().getInt(KEY_FRAGMENT_NUMBER); View view = inflater.inflate(R.layout.fragment_cheese_list, container, false); mRvCheeses = (RecyclerView) view.findViewById(R.id.recyclerview); if (savedInstanceState != null) { try { mCheeseList = (ArrayList<Cheese>) savedInstanceState.get(KEY_CHEESES); } catch (ClassCastException e) { e.printStackTrace(); } } setupRecyclerView(mRvCheeses); return view; }