List of usage examples for android.os Bundle getParcelable
@Nullable public <T extends Parcelable> T getParcelable(@Nullable String key)
From source file:br.com.GUI.avaliacoes.AvaliarPerimetria.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == 200 || requestCode == 202) { if (requestCode == 200) { selectedImageUri = data.getData(); cortar(requestCode);/*from w w w.j a v a 2 s .co m*/ } else if (requestCode == 202) { //get the returned data Bundle extras = data.getExtras(); //get the cropped bitmap Bitmap foto = extras.getParcelable("data"); bmp = ImageUtils.compactImages(foto); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); } } else if (requestCode == 100 || requestCode == 102) { if (requestCode == 100) { selectedImageUri = data.getData(); cortar(requestCode); } else if (requestCode == 102) { Bundle extras = data.getExtras(); Bitmap foto = extras.getParcelable("data"); bmp = ImageUtils.compactImages(foto); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); } } } else { selectedImageUri = null; } /* if(requestCode == 100){ selectedImageUri = Uri.fromFile(photo); ContentResolver cr = getActivity().getContentResolver(); Bitmap foto; try{ foto = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImageUri); bmp = ImageUtils.compactImages(foto); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); }catch(FileNotFoundException e){ Log.i("Exception", e.toString()); e.printStackTrace(); } catch (IOException e){ Log.i("Exception", e.toString()); e.printStackTrace(); } }else if( requestCode == 200){ if (resultCode == Activity.RESULT_OK) { try { Uri selectedImage = data.getData(); String[] nomeCaminho = {MediaStore.Images.Media.DATA}; Cursor cursor = getActivity().getContentResolver().query(selectedImage, nomeCaminho, null, null, null); cursor.moveToFirst(); int indexColuna = cursor.getColumnIndex(nomeCaminho[0]); String caminho = cursor.getString(indexColuna); bmp = ImageUtils.compactImages(BitmapFactory.decodeFile(caminho)); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); } catch (Exception e) { Toast.makeText(getActivity(), "Failed to load", Toast.LENGTH_SHORT).show(); Log.e("Camera", e.toString()); } } else { selectedImageUri = null; //bmp.setImageBitmap(null); } } */ }
From source file:com.android.mms.quickmessage.QuickMessage.java
private void parseIntent(Intent intent, boolean newMessage) { if (intent == null) { return;/*from w ww.j av a 2s . c o m*/ } Bundle extras = intent.getExtras(); if (extras == null) { return; } // Parse the intent and ensure we have a notification object to work with NotificationInfo nm = (NotificationInfo) extras.getParcelable(SMS_NOTIFICATION_OBJECT_EXTRA); if (nm != null) { QuickMessageContent qm = new QuickMessageContent(extras.getString(SMS_FROM_NAME_EXTRA), extras.getString(SMS_FROM_NUMBER_EXTRA), nm, extras.getInt(SMS_NOTIFICATION_ID_EXTRA)); mMessageList.add(qm); if (newMessage && mCurrentQmIndex != -1) { // There is already a message showing // Stay on the current message mMessagePager.setCurrentItem(mCurrentQmIndex); } else { // Set the current message to the last message received mCurrentQmIndex = mMessageList.size() - 1; mMessagePager.setCurrentItem(mCurrentQmIndex); } // Make sure the counter is accurate updateMessageCounter(); } }
From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java
@Override public void restoreState(Parcelable state, ClassLoader cl) { if (state instanceof Bundle) { Log.d("RMBT RESTORE STATE", "Restoring state in ResultPagerAdapter"); Bundle bundle = (Bundle) state; super.restoreState(bundle.getParcelable("instanceState"), cl); try {//from ww w . j a v a 2s . c om String testResultJson = bundle.getString("test_result"); if (testResultJson != null) { testResult = new JSONArray(testResultJson); } String testDetailsJson = bundle.getString("test_result_details"); if (testDetailsJson != null) { testResultDetails = new JSONArray(testDetailsJson); } String testGraphJson = bundle.getString("test_result_graph"); if (testGraphJson != null) { testGraphResult = new JSONArray(testGraphJson); //graphViewEndTaskListener.taskEnded(testGraphResult); } String testDetailsQos = bundle.getString("test_result_qos"); if (testDetailsQos != null) { setTestResultQoSDetails(new QoSServerResultCollection(new JSONArray(testDetailsQos))); } } catch (JSONException e) { // TODO Auto-generated catch block //e.printStackTrace(); } return; } }
From source file:com.buddi.client.dfu.DfuActivity.java
@Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { final Uri uri = args.getParcelable(EXTRA_URI); /*/*ww w. ja v a 2 s .c o m*/ * Some apps, f.e. Google Drive allow to select file that is not on the device. There is no "_data" column handled by that provider. Let's try to obtain all columns and than check * which columns are present. */ //final String[] projection = new String[] { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DATA }; return new CursorLoader(this, uri, null /* all columns, instead of projection */, null, null, null); }
From source file:com.nokia.example.paymentoneapk.PaymentOneAPKActivity.java
public void launchPurchase(final String sku, final String itemType, final int requestCode, final String extraData) { Log.d(TAG, "PaymentOneAPKActivity.launchPurchase"); try {//from www . j a v a2 s . c om final Bundle buyIntentBundle = mService.getBuyIntent(API_VERSION, getPackageName(), sku, itemType, extraData); final int response = buyIntentBundle.getInt("RESPONSE_CODE"); if (response != PaymentOneAPKUtils.RESULT_OK) { Log.e(TAG, String.format("error while buying. response=%s", getErrorMessage(response))); toastMessage(String.format("Got an error while buying: %s", getErrorMessage(response))); return; } final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); Log.d(TAG, String.format("pendingIntent = %s", pendingIntent)); startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), 0, 0, 0); } catch (final RemoteException e) { Log.e(TAG, "error while buying", e); toastMessage("Got an exception while buying"); } catch (final IntentSender.SendIntentException e) { Log.e(TAG, "error while buying", e); toastMessage("Got an exception while buying"); } }
From source file:com.antew.redditinpictures.library.service.RESTService.java
@Override protected void onHandleIntent(Intent intent) { Uri action = intent.getData();// w w w.j a v a2 s . c o m Bundle extras = intent.getExtras(); if (extras == null || action == null) { Ln.e("You did not pass extras or data with the Intent."); return; } // We default to GET if no verb was specified. int verb = extras.getInt(EXTRA_HTTP_VERB, GET); RequestCode requestCode = (RequestCode) extras.getSerializable(EXTRA_REQUEST_CODE); Bundle params = extras.getParcelable(EXTRA_PARAMS); String cookie = extras.getString(EXTRA_COOKIE); String userAgent = extras.getString(EXTRA_USER_AGENT); // Items in this bundle are simply passed on in onRequestComplete Bundle passThrough = extras.getBundle(EXTRA_PASS_THROUGH); HttpEntity responseEntity = null; Intent result = new Intent(Constants.Broadcast.BROADCAST_HTTP_FINISHED); result.putExtra(EXTRA_PASS_THROUGH, passThrough); Bundle resultData = new Bundle(); try { // Here we define our base request object which we will // send to our REST service via HttpClient. HttpRequestBase request = null; // Let's build our request based on the HTTP verb we were // given. switch (verb) { case GET: { request = new HttpGet(); attachUriWithQuery(request, action, params); } break; case DELETE: { request = new HttpDelete(); attachUriWithQuery(request, action, params); } break; case POST: { request = new HttpPost(); request.setURI(new URI(action.toString())); // Attach form entity if necessary. Note: some REST APIs // require you to POST JSON. This is easy to do, simply use // postRequest.setHeader('Content-Type', 'application/json') // and StringEntity instead. Same thing for the PUT case // below. HttpPost postRequest = (HttpPost) request; if (params != null) { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params)); postRequest.setEntity(formEntity); } } break; case PUT: { request = new HttpPut(); request.setURI(new URI(action.toString())); // Attach form entity if necessary. HttpPut putRequest = (HttpPut) request; if (params != null) { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params)); putRequest.setEntity(formEntity); } } break; } if (request != null) { DefaultHttpClient client = new DefaultHttpClient(); // GZip requests // antew on 3/12/2014 - Disabling GZIP for now, need to figure this CloseGuard error: // 03-12 21:02:09.248 9674-9683/com.antew.redditinpictures.pro E/StrictMode A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. // java.lang.Throwable: Explicit termination method 'end' not called // at dalvik.system.CloseGuard.open(CloseGuard.java:184) // at java.util.zip.Inflater.<init>(Inflater.java:82) // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96) // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81) // at com.antew.redditinpictures.library.service.RESTService$GzipDecompressingEntity.getContent(RESTService.java:346) client.addRequestInterceptor(getGzipRequestInterceptor()); client.addResponseInterceptor(getGzipResponseInterceptor()); if (cookie != null) { request.addHeader("Cookie", cookie); } if (userAgent != null) { request.addHeader("User-Agent", Constants.Reddit.USER_AGENT); } // Let's send some useful debug information so we can monitor things // in LogCat. Ln.d("Executing request: %s %s ", verbToString(verb), action.toString()); // Finally, we send our request using HTTP. This is the synchronous // long operation that we need to run on this thread. HttpResponse response = client.execute(request); responseEntity = response.getEntity(); StatusLine responseStatus = response.getStatusLine(); int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0; if (responseEntity != null) { resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity)); resultData.putSerializable(EXTRA_REQUEST_CODE, requestCode); resultData.putInt(EXTRA_STATUS_CODE, statusCode); result.putExtra(EXTRA_BUNDLE, resultData); onRequestComplete(result); } else { onRequestFailed(result, statusCode); } } } catch (URISyntaxException e) { Ln.e(e, "URI syntax was incorrect. %s %s ", verbToString(verb), action.toString()); onRequestFailed(result, 0); } catch (UnsupportedEncodingException e) { Ln.e(e, "A UrlEncodedFormEntity was created with an unsupported encoding."); onRequestFailed(result, 0); } catch (ClientProtocolException e) { Ln.e(e, "There was a problem when sending the request."); onRequestFailed(result, 0); } catch (IOException e) { Ln.e(e, "There was a problem when sending the request."); onRequestFailed(result, 0); } finally { if (responseEntity != null) { try { responseEntity.consumeContent(); } catch (IOException ignored) { } } } }
From source file:com.demo.firebase.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance();/*from w w w .j av a 2 s . c om*/ // Click listeners findViewById(R.id.button_camera).setOnClickListener(this); findViewById(R.id.button_sign_in).setOnClickListener(this); findViewById(R.id.button_download).setOnClickListener(this); // Restore instance state if (savedInstanceState != null) { mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI); mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL); } onNewIntent(getIntent()); // Local broadcast receiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive:" + intent); hideProgressDialog(); switch (intent.getAction()) { case MyDownloadService.DOWNLOAD_COMPLETED: // Get number of bytes downloaded long numBytes = intent.getLongExtra(MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0); // Alert success showMessageDialog(getString(R.string.success), String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes, intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH))); break; case MyDownloadService.DOWNLOAD_ERROR: // Alert failure showMessageDialog("Error", String.format(Locale.getDefault(), "Failed to download from %s", intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH))); break; case MyUploadService.UPLOAD_COMPLETED: case MyUploadService.UPLOAD_ERROR: onUploadResultIntent(intent); break; } } }; }
From source file:com.ayuget.redface.ui.activity.TopicsActivity.java
@Override protected void onRestoreUiState(Bundle savedInstanceState) { Log.d(LOG_TAG, "Restoring UI state for TopicsActivity"); // This will prevent categories loading eventfrom the navigation drawer to // mess-up with the UI (unnecessary reload) when the activity is re-created from // a previous state (like rotating the phone...) restoredInstanceState = true;//from w w w . java 2 s. c om currentCategory = savedInstanceState.getParcelable(ARG_CURRENT_CATEGORY); TopicListFragment topicListFragment = (TopicListFragment) getSupportFragmentManager() .findFragmentByTag(TOPICS_FRAGMENT_TAG); TopicFragment topicFragment = (TopicFragment) getSupportFragmentManager() .findFragmentByTag(TOPIC_FRAGMENT_TAG); if (topicListFragment != null) { // Register the callbacks again topicListFragment.addOnTopicClickedListener(this); } // Restore topic list fragment to the correct pane if we come from portrait mode if (isTwoPaneMode() && (topicListFragment != null && !topicListFragment.isVisible())) { getSupportFragmentManager().beginTransaction() .replace(R.id.container, topicListFragment, TOPICS_FRAGMENT_TAG).commit(); } }
From source file:com.abc.driver.PersonalActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CellSiteConstants.TAKE_USER_PORTRAIT || requestCode == CellSiteConstants.PICK_USER_PORTRAIT) { Uri uri = null;//from w w w . j a v a 2 s. c o m if (requestCode == CellSiteConstants.TAKE_USER_PORTRAIT) { uri = imageUri; } else if (requestCode == CellSiteConstants.PICK_USER_PORTRAIT) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); imageUri = Uri.fromFile(new File(filePath)); } else // This is a bug, in some cases, some images like { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().setProfileImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } doCrop(); Log.d(TAG, "onActivityResult PICK_PICTURE"); } else if (requestCode == CellSiteConstants.CROP_PICTURE) { Log.d(TAG, "crop picture"); // processFile(); if (data != null) { Bundle extras = data.getExtras(); Bitmap photo = extras.getParcelable("data"); app.setPortaritBitmap(photo); mUserPortraitIv.setImageBitmap(photo); mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(photo), CellSiteConstants.UPDATE_USER_PORTRAIT_URL); isPortraitChanged = true; } } else if (requestCode == CellSiteConstants.TAKE_IDENTITY || requestCode == CellSiteConstants.PICK_IDENTITY) { Uri uri = null; if (requestCode == CellSiteConstants.TAKE_IDENTITY) { uri = imageUri; } else if (requestCode == CellSiteConstants.PICK_IDENTITY) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG, "filePath =" + filePath); Log.d(TAG, "uri=" + uri.toString()); imageUri = Uri.fromFile(new File(filePath)); } else // { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().setIdentityImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IDENTITY_IMAGE_WIDTH, CellSiteConstants.IDENTITY_IMAGE_HEIGHT, false); mUserIdentityIv.setImageBitmap(scaledBmp); // s isChanged = true; mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_USER_IDENTITY_URL); } else if (requestCode == CellSiteConstants.TAKE_DRIVER_LICENSE || requestCode == CellSiteConstants.PICK_DRIVER_LICENSE) { Uri uri = null; if (requestCode == CellSiteConstants.TAKE_DRIVER_LICENSE) { uri = imageUri; } else if (requestCode == CellSiteConstants.PICK_DRIVER_LICENSE) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG, "filePath =" + filePath); Log.d(TAG, "uri=" + uri.toString()); imageUri = Uri.fromFile(new File(filePath)); } else // { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().setDriverLicenseImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IDENTITY_IMAGE_WIDTH, CellSiteConstants.IDENTITY_IMAGE_HEIGHT, false); mUserDriverLicenseIv.setImageBitmap(scaledBmp); // s isChanged = true; mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_DRIVER_LICENSE_URL); } }