List of usage examples for android.os Bundle get
@Nullable
public Object get(String key)
From source file:de.ub0r.android.smsdroid.ConversationListActivity.java
/** * {@inheritDoc}/*from ww w . ja v a 2s .c o m*/ */ @Override public void onNewIntent(final Intent intent) { final Intent i = intent; if (i != null) { Log.d(TAG, "got intent: " + i.getAction()); Log.d(TAG, "got uri: " + i.getData()); final Bundle b = i.getExtras(); if (b != null) { Log.d(TAG, "user_query: " + b.get("user_query")); Log.d(TAG, "got extra: " + b); } final String query = i.getStringExtra("user_query"); Log.d(TAG, "user query: " + query); // TODO: do something with search query } }
From source file:com.phonegap.plugins.pdf417.Pdf417Scanner.java
private JSONObject parseUSDL(USDLScanResult p) throws JSONException { JSONObject fields = new JSONObject(); Bundle bundle = p.getData(); for (String key : bundle.keySet()) { // Originaly in RecognitionResultConstants.RECOGNITIONDATA_TYPE if (RECOGNITIONDATA_TYPE.equals(key)) { continue; }/* w w w . j a v a2 s.c o m*/ Object value = bundle.get(key); if (value instanceof String) { fields.put(key, (String) value); } else { Log.d(LOG_TAG, "Ignoring non string key '" + key + "'"); } } JSONObject result = new JSONObject(); result.put(RESULT_TYPE, "USDL result"); result.put(FIELDS, fields); return result; }
From source file:eu.trentorise.smartcampus.communicator.fragments.messages.AbstractMessageListFragment.java
@SuppressWarnings("unchecked") @Override//w w w . ja v a2 s . com public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { list = (ArrayList<Notification>) savedInstanceState.get(ARG_MESSAGES); position = savedInstanceState.getInt(ARG_POSITION); lastSize = savedInstanceState.getInt(ARG_LAST); } return inflater.inflate(R.layout.messages, container, false); }
From source file:com.pixelpixel.pyp.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w . j ava 2s . co m*/ //We get the ImageView, and using the intent extra information //which contains the picture taken with the camera or //the picture picked from the gallery, we set the image for the ImageView. img = (ImageView) findViewById(R.id.main_picture); Bundle extras = getIntent().getExtras(); if (extras != null) { //We have picture taken with the camera if (extras.containsKey("cPic")) { Uri picUri = (Uri) extras.get("cPic"); img.setImageURI(picUri); getIntent().removeExtra("cPic"); //We have picture picked from gallery } else if (extras.containsKey("gPic")) { Uri gPicUri = (Uri) extras.get("gPic"); img.setImageURI(gPicUri); //Next line removes the extra information from the intent (the URI) getIntent().removeExtra("gPic"); } //Storing the original picture Drawable drawing = img.getDrawable(); picture = ((BitmapDrawable) drawing).getBitmap(); } //Get the cached bitmaps if (mMemoryCache.get("current") != null) { rBitmap = (Bitmap) mMemoryCache.get("current"); img.setImageBitmap(rBitmap); } if (mMemoryCache.get("original") != null) { picture = (Bitmap) mMemoryCache.get("original"); } mMemoryCache.evictAll(); //rBitmap - current bitmap on the imageView Log.i("TAG", "Image Displayed"); Drawable drawing = img.getDrawable(); rBitmap = ((BitmapDrawable) drawing).getBitmap(); //Implementing the onClickListeners for the buttons: //First we get the ImageButtons backButton = (ImageButton) findViewById(R.id.MainImageButtonBack); effectsButton = (ImageButton) findViewById(R.id.MainImageButtonEffects); extrasButton = (ImageButton) findViewById(R.id.MainImageButtonExtras); saveButton = (ImageButton) findViewById(R.id.MainImageButtonSave); shareButton = (ImageButton) findViewById(R.id.MainImageButtonShare); Log.i("TAG", "Buttons recognized"); //Defining listener for the popup menu //POPUP MENU IS NOT WORKING ON MINSDK=8! /* PopupMenuListener = new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int menuItemId = item.getItemId(); if (menuItemId == R.id.MenuGrayScale) { Log.i("TAG", "Button GrayScale indentified"); applyGrayscaleEffect(); }else if (menuItemId == R.id.MenuSepia) { Log.i("TAG", "Button Sepia identified"); applySepiaEffect(); }else if (menuItemId == R.id.MenuOriginal) { applyOriginal(); }else if (menuItemId == R.id.MenuInverse) { applyInverseEffect(); } return true; } };*/ //Defining listener for ImageButtons View.OnClickListener ButtonListener = new View.OnClickListener() { public void onClick(View v) { ImageButton button = (ImageButton) v; //If we click on the back button if (button == backButton) { // A new alert dialog is created AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("Are you sure you want to exit?\nAll your changes will be lost.") .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { //If we click Yes, the current activity is finished, //and we return to the previous activity. public void onClick(DialogInterface dialog, int which) { mMemoryCache.evictAll(); MainActivity.this.finish(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { //If we click No, we return to the current activity public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } else if (button == effectsButton) { startActivity(new Intent(MainActivity.this, ListActivity.class)); /*PopupMenu popup = new PopupMenu(MainActivity.this, v); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.effects, popup.getMenu()); popup.setOnMenuItemClickListener(PopupMenuListener); popup.show();*/ } else if (button == extrasButton) { //TODO: implement this function } else if (button == saveButton) { // A new alert dialog is created AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("Do you want to save your picture?").setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { //If we click Yes, picture is saved to gallery/Pimped Pictures public void onClick(DialogInterface dialog, int which) { try { saveFile(); } catch (IOException e) { e.printStackTrace(); } } }).setNegativeButton("No", new DialogInterface.OnClickListener() { //If we click No, we return to the current activity public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } else if (button == shareButton) { try { saveFile(); } catch (IOException e) { e.printStackTrace(); } Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM, picUri); share.putExtra(Intent.EXTRA_TEXT, "Pyp test"); startActivity(Intent.createChooser(share, "Share image")); } } }; backButton.setOnClickListener(ButtonListener); effectsButton.setOnClickListener(ButtonListener); extrasButton.setOnClickListener(ButtonListener); saveButton.setOnClickListener(ButtonListener); shareButton.setOnClickListener(ButtonListener); }
From source file:hku.fyp14017.blencode.ui.controller.SoundController.java
public Loader<Cursor> onCreateLoader(int id, Bundle arguments, Activity activity) { Uri audioUri = null;// w w w . ja v a 2 s.c o m if (arguments != null) { audioUri = (Uri) arguments.get(BUNDLE_ARGUMENTS_SELECTED_SOUND); } String[] projection = { MediaStore.Audio.Media.DATA }; return new CursorLoader(activity, audioUri, projection, null, null, null); }
From source file:com.endiansoftware.echo.remotewatch.GcmIntentService.java
private void sendNotification(Bundle msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(msg.get("key1").toString()) .setContentText(msg.get("key2").toString()).setTicker(msg.get("key1").toString()); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); if (msg.get("collapse_key").toString().equals("Emergency")) { notification.flags |= notification.FLAG_INSISTENT | notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS; notification.vibrate = new long[] { 100L, 100L, 200L, 500L }; } else {/* w ww. j a v a 2 s .c om*/ notification.flags |= notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.vibrate = new long[] { 100L }; } mNotificationManager.notify(NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); wl.acquire(); }
From source file:edu.utexas.quietplaces.services.PlacesUpdateService.java
/** * {@inheritDoc}//from www . jav a 2 s . co m * Checks the battery and connectivity state before removing stale venues * and initiating a server poll for new venues around the specified * location within the given radius. */ @Override protected void onHandleIntent(Intent intent) { // Check if we're running in the foreground, if not, check if // we have permission to do background updates. //noinspection deprecation boolean backgroundAllowed = cm.getBackgroundDataSetting(); boolean inBackground = prefs.getBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, true); if (!backgroundAllowed && inBackground) return; // Extract the location and radius around which to conduct our search. Location location = new Location(PlacesConstants.CONSTRUCTED_LOCATION_PROVIDER); int radius = PlacesConstants.PLACES_SEARCH_RADIUS; Bundle extras = intent.getExtras(); if (intent.hasExtra(PlacesConstants.EXTRA_KEY_LOCATION)) { location = (Location) (extras.get(PlacesConstants.EXTRA_KEY_LOCATION)); radius = extras.getInt(PlacesConstants.EXTRA_KEY_RADIUS, PlacesConstants.PLACES_SEARCH_RADIUS); } // Check if we're in a low battery situation. IntentFilter batIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent battery = registerReceiver(null, batIntentFilter); lowBattery = getIsLowBattery(battery); // Check if we're connected to a data network, and if so - if it's a mobile network. NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); mobileData = activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE; // If we're not connected, enable the connectivity receiver and disable the location receiver. // There's no point trying to poll the server for updates if we're not connected, and the // connectivity receiver will turn the location-based updates back on once we have a connection. if (!isConnected) { Log.w(TAG, "Not connected!"); } else { // If we are connected check to see if this is a forced update (typically triggered // when the location has changed). boolean doUpdate = intent.getBooleanExtra(PlacesConstants.EXTRA_KEY_FORCEREFRESH, false); // If it's not a forced update (for example from the Activity being restarted) then // check to see if we've moved far enough, or there's been a long enough delay since // the last update and if so, enforce a new update. if (!doUpdate) { // Retrieve the last update time and place. long lastTime = prefs.getLong(PlacesConstants.SP_KEY_LAST_LIST_UPDATE_TIME, Long.MIN_VALUE); float lastLat; try { lastLat = prefs.getFloat(PlacesConstants.SP_KEY_LAST_LIST_UPDATE_LAT, Float.MIN_VALUE); } catch (ClassCastException e) { // handle legacy version lastLat = Float.MIN_VALUE; } float lastLng; try { lastLng = prefs.getFloat(PlacesConstants.SP_KEY_LAST_LIST_UPDATE_LNG, Float.MIN_VALUE); } catch (ClassCastException e) { lastLng = Float.MIN_VALUE; } Location lastLocation = new Location(PlacesConstants.CONSTRUCTED_LOCATION_PROVIDER); lastLocation.setLatitude(lastLat); lastLocation.setLongitude(lastLng); long currentTime = System.currentTimeMillis(); float distanceMovedSinceLast = lastLocation.distanceTo(location); long elapsedTime = currentTime - lastTime; Log.i(TAG, "Last Location in places update service: " + lastLocation + " distance to current: " + distanceMovedSinceLast + " - current: " + location); if (location == null) { Log.w(TAG, "Location is null..."); } // If update time and distance bounds have been passed, do an update. else if (lastTime < currentTime - PlacesConstants.MAX_TIME_BETWEEN_PLACES_UPDATE) { Log.i(TAG, "Time bounds passed on places update, " + elapsedTime / 1000 + "s elapsed"); doUpdate = true; } else if (distanceMovedSinceLast > PlacesConstants.MIN_DISTANCE_TRIGGER_PLACES_UPDATE) { Log.i(TAG, "Distance bounds passed on places update, moved: " + distanceMovedSinceLast + " meters, time elapsed: " + elapsedTime / 1000 + "s"); doUpdate = true; } else { Log.d(TAG, "Time/distance bounds not passed on places update. Moved: " + distanceMovedSinceLast + " meters, time elapsed: " + elapsedTime / 1000 + "s"); } } if (location == null) { Log.e(TAG, "null location in onHandleIntent"); } else if (doUpdate) { // Refresh the prefetch count for each new location. prefetchCount = 0; // Remove the old locations - TODO: we flush old locations, but if the next request // fails we are left high and dry removeOldLocations(location, radius); // Hit the server for new venues for the current location. refreshPlaces(location, radius, null); // Tell the main activity about the new results. Intent placesUpdatedIntent = new Intent(Config.ACTION_PLACES_UPDATED); LocalBroadcastManager.getInstance(this).sendBroadcast(placesUpdatedIntent); } else { Log.i(TAG, "Place List is fresh: Not refreshing"); } // Retry any queued checkins. /* Intent checkinServiceIntent = new Intent(this, PlaceCheckinService.class); startService(checkinServiceIntent); */ } Log.d(TAG, "Place List Download Service Complete"); }
From source file:com.facebook.LegacyTokenHelper.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 a 2s .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 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.app_software.chromisstock.ProductDetailFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_IMAGE_CAPTURE) { Bitmap bitmap = null;// w w w .j a v a 2 s. co m if (intent != null) { Bundle extras = intent.getExtras(); bitmap = (Bitmap) extras.get("data"); m_image.setImageBitmap(bitmap); } if (bitmap != null) { ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream1); byte[] imageInByte = stream1.toByteArray(); m_db.addChange(mItem.getChromisId(), DatabaseHandler.CHANGETYPE_CHANGEVALUEBLOB, StockProduct.IMAGE, imageInByte, getResources().getString(R.string.captured_image)); } } else { ScannerResult scanResult = ScannerIntegrator.parseActivityResult(requestCode, resultCode, intent); if (scanResult != null) { String code = scanResult.getContents(); if (!TextUtils.isEmpty(code)) { // is this an existing barcode ? DatabaseHandler db = DatabaseHandler.getInstance(getContext()); StockProduct product = db.lookupBarcode(code); if (product != null) { // Ask to load the product details activity askDuplicateBarcode(product); } else { // Use the scanned data as the barcode setBarcode(code); } } } } } }
From source file:net.abcdroid.devfest12.ui.SessionsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null) { return;//from w w w . j a v a 2s . c o m } int token = loader.getId(); if (token == SessionsQuery._TOKEN || token == SearchQuery._TOKEN) { mAdapter.changeCursor(cursor); Bundle arguments = getArguments(); if (arguments != null && arguments.containsKey("_uri")) { String uri = arguments.get("_uri").toString(); if (uri != null && uri.contains("blocks")) { String title = arguments.getString(Intent.EXTRA_TITLE); if (title == null) { title = (String) this.getActivity().getTitle(); } EasyTracker.getTracker().trackView("Session Block: " + title); LOGD("Tracker", "Session Block: " + title); } } } else { LOGD(TAG, "Query complete, Not Actionable: " + token); cursor.close(); } }