List of usage examples for android.os Bundle getBoolean
public boolean getBoolean(String key)
From source file:com.facebook.internal.BundleJSONConverterTest.java
@Test public void testSimpleValues() throws JSONException { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1st"); arrayList.add("2nd"); arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] { "7", "8" }); innerBundle1.putBundle("nested bundle", innerBundle2); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] { "first", "second" }); b.putStringArrayList("stringArrayListValue", arrayList); b.putBundle("nested", innerBundle1); JSONObject json = BundleJSONConverter.convertToJSON(b); assertNotNull(json);//w w w .j a va 2s .co m assertEquals(true, json.getBoolean("boolValue")); assertEquals(7, json.getInt("intValue")); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", json.getString("stringValue")); JSONArray jsonArray = json.getJSONArray("stringArrayValue"); assertEquals(2, jsonArray.length()); assertEquals("first", jsonArray.getString(0)); assertEquals("second", jsonArray.getString(1)); jsonArray = json.getJSONArray("stringArrayListValue"); assertEquals(3, jsonArray.length()); assertEquals("1st", jsonArray.getString(0)); assertEquals("2nd", jsonArray.getString(1)); assertEquals("third", jsonArray.getString(2)); JSONObject innerJson = json.getJSONObject("nested"); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner")); jsonArray = innerJson.getJSONArray("deep list"); assertEquals(2, jsonArray.length()); assertEquals("7", jsonArray.getString(0)); assertEquals("8", jsonArray.getString(1)); Bundle finalBundle = BundleJSONConverter.convertToBundle(json); assertNotNull(finalBundle); assertEquals(true, finalBundle.getBoolean("boolValue")); assertEquals(7, finalBundle.getInt("intValue")); assertEquals(5000000000l, finalBundle.getLong("longValue")); assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", finalBundle.getString("stringValue")); List<String> stringList = finalBundle.getStringArrayList("stringArrayValue"); assertEquals(2, stringList.size()); assertEquals("first", stringList.get(0)); assertEquals("second", stringList.get(1)); stringList = finalBundle.getStringArrayList("stringArrayListValue"); assertEquals(3, stringList.size()); assertEquals("1st", stringList.get(0)); assertEquals("2nd", stringList.get(1)); assertEquals("third", stringList.get(2)); Bundle finalInnerBundle = finalBundle.getBundle("nested"); assertEquals(1, finalInnerBundle.getInt("inner")); finalBundle = finalInnerBundle.getBundle("nested bundle"); assertEquals("2", finalBundle.getString("inner")); stringList = finalBundle.getStringArrayList("deep list"); assertEquals(2, stringList.size()); assertEquals("7", stringList.get(0)); assertEquals("8", stringList.get(1)); }
From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java
private void stopServer(Context context, ServerControl serverControl) { final CyclicBarrier barrier = new CyclicBarrier(2); final BroadcastReceiver receiver = new BroadcastReceiver() { @Override//from w w w .j a v a2 s. co m public void onReceive(Context context, Intent intent) { if (intent.getAction() == null || !intent.getAction().equals(MainActivity.getIntentActionServerStatus(context))) { return; } final Bundle extras = intent.getExtras(); if (extras == null || extras.containsKey("errorLine") || extras.getBoolean("running")) { return; } try { barrier.await(); } catch (InterruptedException | BrokenBarrierException ignored) { } } }; context.registerReceiver(receiver, new IntentFilter(MainActivity.getIntentActionServerStatus(context))); preferences.set(context, Preferences.SERVER_STARTED, false); serverControl.requestStop(null); try { barrier.await(); } catch (InterruptedException | BrokenBarrierException ignored) { } context.unregisterReceiver(receiver); }
From source file:fr.cph.chicago.activity.BaseActivity.java
@Override protected final void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loading);/*from w w w. jav a 2 s .c o m*/ Bundle extras = getIntent().getExtras(); if (extras != null && mError == null) { mError = extras.getBoolean("error"); } else { mError = false; } if (mError) { new LoadData().execute(); } else if (mTrainArrivals == null || mBusArrivals == null) { new LoadData().execute(); } else { startMainActivity(mTrainArrivals, mBusArrivals); } }
From source file:com.anxpp.blog.fragment.SandboxFragment.java
private boolean restoreBooleanPrefState(Bundle savedInstanceState, int prefValue) { final boolean value = savedInstanceState.getBoolean(String.valueOf(prefValue)); final CompoundButton viewValue = (CompoundButton) viewRoot.findViewById(prefValue); viewValue.setChecked(value);//w ww.j av a 2s. c om return value; }
From source file:co.malm.heusum.mobile.activities.HomeActivity.java
private void reconnectChannels(Bundle hint) { if ((hint != null) && hint.getBoolean(Cast.EXTRA_APP_NO_LONGER_RUNNING)) { //Log.e( TAG, "App is no longer running" ); teardown();//from w w w. j a va 2s .c o m } else { try { Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer); } catch (Exception e) { Log.e(this.getClass().getSimpleName(), "Exception while creating media channel ", e); } } }
From source file:com.onesignal.example.OneSignalBackgroundDataReceiver.java
public void onReceive(Context context, Intent intent) { Bundle dataBundle = intent.getBundleExtra("data"); try {//from ww w. j a v a2 s . com //Log.i("OneSignalExample", "NotificationTable content: " + dataBundle.getString("alert")); Log.i("OneSignalExample", "NotificationTable title: " + dataBundle.getString("title")); Log.i("OneSignalExample", "Is Your App Active: " + dataBundle.getBoolean("isActive")); Log.i("OneSignalExample", "data addt: " + dataBundle.getString("custom")); JSONObject customJSON = new JSONObject(dataBundle.getString("custom")); if (customJSON.has("a")) Log.i("OneSignalExample", "additionalData:key_a: " + customJSON.getJSONObject("a").getString("a")); } catch (Throwable t) { t.printStackTrace(); } }
From source file:edu.ucla.cs.nopainnogame.WatchActivity.java
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); viewing = savedInstanceState.getBoolean("viewingBoolean"); if (viewing) { counter = new MyCount((getTvTime(user) * 1000), 1000); counter.start();// w w w .j av a 2s . c o m } }
From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java
protected void Prepare(GetFiresService c) { this.c = c;//w ww . j a v a 2 s . c o m nID = -1; bHasNews = false; mFillDataHandler = new Handler() { public void handleMessage(Message msg) { Bundle resultData = msg.getData(); boolean bHaveErr = resultData.getBoolean(GetFiresService.ERROR); if (bHaveErr) { SendError(resultData.getString(GetFiresService.ERR_MSG)); } else { int nType = resultData.getInt(GetFiresService.SOURCE); String sData = resultData.getString(GetFiresService.JSON); switch (nType) { case 5: FillData(nType, sData); break; default: break; } } }; }; mmoItems = new HashMap<Long, ScanexNotificationItem>(); }
From source file:com.onesignal.example.BackgroundDataBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle dataBundle = intent.getBundleExtra("data"); try {/*w ww. j a va2 s .c o m*/ Log.i("OneSignalExample", "Notification content: " + dataBundle.getString("alert")); Log.i("OneSignalExample", "Notification title: " + dataBundle.getString("title")); Log.i("OneSignalExample", "Is Your App Active: " + dataBundle.getBoolean("isActive")); JSONObject customJSON = new JSONObject(dataBundle.getString("custom")); if (customJSON.has("a")) Log.i("OneSignalExample", "additionalData: " + customJSON.getJSONObject("a").toString()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java
@Override protected void onHandleIntent(Intent intent) { Context context = getApplicationContext(); Bundle bundle = intent.getExtras(); String query = bundle.getString(QUERY); int instances_id = bundle.getInt(INSTANCES_ID); int accounts_id = bundle.getInt(ACCOUNTS_ID, -1); boolean forceReload = bundle.getBoolean(FORCE_RELOAD); ArrayList<Product> products = null; if (!forceReload) { String selection = Products.Columns.INSTANCES_ID.getName() + "=" + instances_id + " AND " + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id; String sortOrder = Products.Columns.NAME.getName(); Cursor cursor = context.getContentResolver().query(Products.CONTENT_URI, Products.PROJECTION, selection, null, sortOrder);//from w w w . j av a 2 s . c om if (cursor.getCount() > 0) { products = new ArrayList<Product>(); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); Product product = Product.toProduct(cursor); products.add(product); } sendResult(intent, products); return; } cursor.close(); } String jsonString = NetworkUtils.readJson(query).result; products = parse(jsonString); sendResult(intent, products); // Delete old products for instance String selection = Products.Columns.INSTANCES_ID + "=" + instances_id + " AND " + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id; context.getContentResolver().delete(Products.CONTENT_URI, selection, null); context.getContentResolver().bulkInsert(Products.CONTENT_URI, Product.toContentValues(products, instances_id, accounts_id)); }