List of usage examples for android.app Activity RESULT_OK
int RESULT_OK
To view the source code for android.app Activity RESULT_OK.
Click Source Link
From source file:com.plugin.camera.ForegroundCameraLauncher.java
/** * Called when the camera view exits.// w w w.j av a 2 s. c om * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost // during compression ExifHelper exif = new ExifHelper(); exif.createInFile( getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // Create entry in media store for image // (Don't use insertImage() because it uses default compression // setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = null; try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } //This if block is added to the plugin to solve the issue which was saving portrait images in landscape with -90 degree rotetion if (intent.getBooleanExtra("portrait", false)) { Matrix matrix = new Matrix(); matrix.preRotate(90); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (Exception e) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2, matrix, true); e.printStackTrace(); } } // Add compressed version of captured image to returned media // store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext.success(getRealPathFromURI(uri, this.cordova)); bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } }
From source file:at.alladin.rmbt.android.terms.RMBTCheckFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { if (!(getActivity() instanceof RMBTMainActivity)) firstTime = false;/*from w w w. ja v a 2 s. co m*/ final View v = inflater.inflate(R.layout.ndt_check, container, false); if (!firstTime) v.findViewById(R.id.termsNdtButtonBack).setVisibility(View.GONE); final TextView textTitle = (TextView) v.findViewById(R.id.check_fragment_title); textTitle.setText(checkType.getTitleId()); checkBox = (CheckBox) v.findViewById(R.id.ndtCheckBox); checkBox.setText(checkType.getTextId()); if (savedInstanceState != null) { checkBox.setChecked(savedInstanceState.getBoolean("isChecked")); } else { checkBox.setChecked(checkType.isDefaultIsChecked()); } final Button buttonAccept = (Button) v.findViewById(R.id.termsNdtAcceptButton); if (!firstTime) { checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { buttonAccept.setEnabled(isChecked); } }); } final WebView wv = (WebView) v.findViewById(R.id.ndtInfoWebView); wv.loadUrl(checkType.getTemplateFile()); buttonAccept.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { final FragmentActivity activity = getActivity(); switch (checkType) { case NDT: ConfigHelper.setNDT(activity, checkBox.isChecked()); ConfigHelper.setNDTDecisionMade(activity, true); break; case LOOP_MODE: ConfigHelper.setLoopMode(activity, checkBox.isChecked()); break; } activity.getSupportFragmentManager().popBackStack(checkType.getFragmentTag(), FragmentManager.POP_BACK_STACK_INCLUSIVE); if (firstTime && CheckType.NDT.equals(checkType)) { ((RMBTMainActivity) activity).initApp(false); } else { getActivity().setResult(checkBox.isChecked() ? Activity.RESULT_OK : Activity.RESULT_CANCELED); getActivity().finish(); } } }); new Handler().postDelayed(new Runnable() { @Override public void run() { buttonAccept.setEnabled(firstTime || checkBox.isChecked()); } }, 500); final Button buttonBack = (Button) v.findViewById(R.id.termsNdtBackButton); buttonBack.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { getActivity().getSupportFragmentManager().popBackStack(); } }); return v; }
From source file:com.samuelcastro.cordova.InstagramSharePlugin.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Log.v("Instagram", "shared ok"); this.cbContext.success(); } else if (resultCode == Activity.RESULT_CANCELED) { Log.v("Instagram", "share cancelled"); this.cbContext.error("Share Cancelled"); }//ww w . j ava2s. c o m }
From source file:com.facebook.reflection.SelectionFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK && requestCode >= 0 && requestCode < listElements.size()) { listElements.get(requestCode).onActivityResult(data); } else {//from ww w . j a v a2 s . c o m uiHelper.onActivityResult(requestCode, resultCode, data, nativeDialogCallback); } }
From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java
/** * Called when the camera view exits./*from w ww . j ava 2 s . c om*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost // during compression ExifHelper exif = new ExifHelper(); exif.createInFile( getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // Create entry in media store for image // (Don't use insertImage() because it uses default compression // setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = null; try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } // Add compressed version of captured image to returned media // store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri.toString())); // getRealPathFromURI(uri, this.cordova))); WRONG. Needs URI bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } }
From source file:com.ecml.ChooseSongActivity.java
/** Open the chosen file in the right activity */ public void doOpenFile(FileUri file) { byte[] data = file.getData(this); if (data == null || data.length <= 6 || !MidiFile.hasMidiHeader(data)) { ChooseSongActivity.showErrorDialog("Error: Unable to open song: " + file.toString(), this); return;/*from w w w . jav a 2 s. co m*/ } ECML.song = file; updateRecentFile(file); String mode = ""; // Get the mode for which we are opening a file if (ECML.intent != null) { mode = ECML.intent.getStringExtra(ChooseSongActivity.mode); } Log.d("MODE", "" + mode); // Get the number of the current activity int number = this.getIntent().getIntExtra("number", 0); // Get the level of the mode (speed/reading of notes) if there is one int lvl = this.getIntent().getIntExtra("level", level); if (mode.equals("speed")) { if (lvl == 1) { intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SpeedGamelvl1.class); intent.putExtra(SpeedGamelvl1.MidiTitleID, file.toString()); intent.putExtra("number", number); startActivity(intent); finish(); } else { intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SpeedGamelvln.class); intent.putExtra(SpeedGamelvln.MidiTitleID, file.toString()); intent.putExtra("level", lvl); intent.putExtra("number", number); startActivity(intent); finish(); } } else if (mode.equals("reading")) { if (lvl == 1) { intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, ReadingGameBeginner.class); intent.putExtra(ReadingGameBeginner.MidiTitleID, file.toString()); intent.putExtra("number", number); startActivity(intent); finish(); } else { intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, ReadingGameNormal.class); intent.putExtra(ReadingGameNormal.MidiTitleID, file.toString()); intent.putExtra("number", number); startActivity(intent); finish(); } } else if (mode.equals("chooseSong")) { intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SheetMusicActivity.class); intent.putExtra("number", number); startActivity(intent); finish(); } else if (mode.equals("studentActivities")) { intent = new Intent(); intent.putExtra("song", file.toString()); setResult(Activity.RESULT_OK, intent); finish(); } }
From source file:es.ugr.swad.swadroid.modules.Module.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case Constants.LOGIN_REQUEST_CODE: // Toast.makeText(getApplicationContext(), // R.string.loginSuccessfulMsg, // Toast.LENGTH_SHORT).show(); /*/* w w w .ja va 2 s .co m*/ * if(isDebuggable) Log.d(TAG, * getString(R.string.loginSuccessfulMsg)); */ if (!(this instanceof Login)) { connect(); } break; } } else { setResult(RESULT_CANCELED); finish(); } }
From source file:co.uk.aging.mabel.places.placepicker.PlacePickerFragment.java
/** * Extracts data from PlacePicker result. * This method is called when an Intent has been started by calling * {@link #startActivityForResult(android.content.Intent, int)}. The Intent for the * {@link com.google.android.gms.location.places.ui.PlacePicker} is started with * {@link #REQUEST_PLACE_PICKER} request code. When a result with this request code is received * in this method, its data is extracted by converting the Intent data to a {@link Place} * through the//from w w w.ja va2 s.c o m * {@link com.google.android.gms.location.places.ui.PlacePicker#getPlace(android.content.Intent, * android.content.Context)} call. * * @param requestCode * @param resultCode * @param data */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // BEGIN_INCLUDE(activity_result) if (requestCode == REQUEST_PLACE_PICKER) { // This result is from the PlacePicker dialog. // Enable the picker option showPickAction(true); if (resultCode == Activity.RESULT_OK) { /* User has picked a place, extract data. Data is extracted from the returned intent by retrieving a Place object from the PlacePicker. */ final Place place = PlacePicker.getPlace(data, getActivity()); /* A Place object contains details about that place, such as its name, address and phone number. Extract the name, address, phone number, place ID and place types. */ final CharSequence name = place.getName(); final CharSequence address = place.getAddress(); final CharSequence phone = place.getPhoneNumber(); final String placeId = place.getId(); String attribution = PlacePicker.getAttributions(data); if (attribution == null) { attribution = ""; } // Update data on card. getCardStream().getCard(CARD_DETAIL).setTitle(name.toString()) .setDescription(getString(R.string.detail_text, placeId, address, phone, attribution)); // Print data to debug log Log.d(TAG, "Place selected: " + placeId + " (" + name.toString() + ")"); // Show the card. getCardStream().showCard(CARD_DETAIL); } else { // User has not selected a place, hide the card. getCardStream().hideCard(CARD_DETAIL); } } else { super.onActivityResult(requestCode, resultCode, data); } // END_INCLUDE(activity_result) }
From source file:br.com.imovelhunter.imovelhunterwebmobile.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); if (SessionUtilJson.getInstance(context).containsName(ParametrosSessaoJson.USUARIO_LOGADO)) { usuarioLogado = (Usuario) SessionUtilJson.getInstance(context) .getJsonObject(ParametrosSessaoJson.USUARIO_LOGADO, Usuario.class); }//from w w w .java 2 s . c o m if (mensagemDAO == null) { mensagemDAO = new MensagemDAO(context); } if (notificacaoDAO == null) { notificacaoDAO = new NotificacaoDAO(context); } if (escutadorDeMensagem != null) { Bundle bundle = intent.getExtras(); String mensagemS = bundle.getString("mensagem"); if (!mensagemS.contains("idImovel")) { // uma mensagem do chat Mensagem m = new Mensagem(); m.parse(mensagemS); m.setLida(false); if (usuarioLogado != null && m.getUsuariosDestino().get(0).getIdUsuario() == usuarioLogado.getIdUsuario()) { escutadorDeMensagem.recebeuAlgo(bundle); } else { mensagemDAO.inserirMensagem(m); } } else { // um perfil de imvel Notificacao not = new Notificacao(); Imovel imovel = new Imovel(); imovel.parse(mensagemS); this.parseNotificacao(not, imovel); not.setDataNotificacao(new Date()); notificacaoDAO.inserir(not); if (usuarioLogado != null && usuarioLogado.getIdUsuario() == imovel.getIdUsuarioNotificacao()) { if (onRecebeuNotificacao != null) { onRecebeuNotificacao.recebeuNotificacao(); } else { // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); } } } } else { String mensagem = intent.getExtras().getString("mensagem"); boolean notificar = true; if (!mensagem.contains("idImovel")) { // mensagem de chat Mensagem mensagemO = new Mensagem(); mensagemO.parse(mensagem); mensagemO.setLida(false); mensagemDAO.inserirMensagem(mensagemO); if (onMessageListener != null && usuarioLogado != null && usuarioLogado.getIdUsuario() == mensagemO.getUsuariosDestino().get(0).getIdUsuario()) { onMessageListener.atualizar(); } if (usuarioLogado == null || mensagemO.getUsuariosDestino().get(0).getIdUsuario() != usuarioLogado.getIdUsuario()) { notificar = false; } } else { // imvel Notificacao not = new Notificacao(); Imovel imovel = new Imovel(); imovel.parse(mensagem); this.parseNotificacao(not, imovel); not.setDataNotificacao(new Date()); notificacaoDAO.inserir(not); if (usuarioLogado != null && usuarioLogado.getIdUsuario() == imovel.getIdUsuarioNotificacao()) { if (onRecebeuNotificacao != null) { notificar = false; onRecebeuNotificacao.recebeuNotificacao(); } } else { notificar = false; } } if (notificar) { // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); } } setResultCode(Activity.RESULT_OK); }
From source file:io.github.acashjos.anarch.Session.java
/** * To be called inside onActivityResult method of activity from which login is triggered * @param requestCode requestCode/*from www . j a v a 2s . co m*/ * @param resultCode resultCode * @param data data */ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == LOGIN_UI && resultCode == Activity.RESULT_OK) { cookies = pref.getString("session", ""); callback.call(this); } }