@Test public void clickingOnImportQRCode_startsExternalImagePickerIntent() { when(activityAvailability.isActivityAvailable(any())).thenReturn(true); menuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_item_scan_sd_card)); ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertThat(intentForResult, notNullValue()); assertThat(intentForResult.requestCode, is(SELECT_PHOTO)); assertThat(intentForResult.intent.getAction(), is(Intent.ACTION_PICK)); assertThat(intentForResult.intent.getType(), is("image/*")); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_scan_sd_card: Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); if (activityAvailability.isActivityAvailable(photoPickerIntent)) { activity.startActivityForResult(photoPickerIntent, SELECT_PHOTO); } else { ToastUtils.showShortToast(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); Timber.w(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); } return true; case R.id.menu_item_share: if (qrFilePath != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_STREAM, fileProvider.getURIForFile(qrFilePath)); activity.startActivity(intent); } return true; } return false; }
QRCodeMenuDelegate implements MenuDelegate { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_scan_sd_card: Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); if (activityAvailability.isActivityAvailable(photoPickerIntent)) { activity.startActivityForResult(photoPickerIntent, SELECT_PHOTO); } else { ToastUtils.showShortToast(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); Timber.w(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); } return true; case R.id.menu_item_share: if (qrFilePath != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_STREAM, fileProvider.getURIForFile(qrFilePath)); activity.startActivity(intent); } return true; } return false; } }
QRCodeMenuDelegate implements MenuDelegate { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_scan_sd_card: Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); if (activityAvailability.isActivityAvailable(photoPickerIntent)) { activity.startActivityForResult(photoPickerIntent, SELECT_PHOTO); } else { ToastUtils.showShortToast(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); Timber.w(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); } return true; case R.id.menu_item_share: if (qrFilePath != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_STREAM, fileProvider.getURIForFile(qrFilePath)); activity.startActivity(intent); } return true; } return false; } QRCodeMenuDelegate(FragmentActivity activity, ActivityAvailability activityAvailability, QRCodeGenerator qrCodeGenerator, FileProvider fileProvider, PreferencesProvider preferencesProvider, Scheduler scheduler); }
QRCodeMenuDelegate implements MenuDelegate { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_scan_sd_card: Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); if (activityAvailability.isActivityAvailable(photoPickerIntent)) { activity.startActivityForResult(photoPickerIntent, SELECT_PHOTO); } else { ToastUtils.showShortToast(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); Timber.w(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); } return true; case R.id.menu_item_share: if (qrFilePath != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_STREAM, fileProvider.getURIForFile(qrFilePath)); activity.startActivity(intent); } return true; } return false; } QRCodeMenuDelegate(FragmentActivity activity, ActivityAvailability activityAvailability, QRCodeGenerator qrCodeGenerator, FileProvider fileProvider, PreferencesProvider preferencesProvider, Scheduler scheduler); @Override void onCreateOptionsMenu(MenuInflater menuInflater, Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onPrepareOptionsMenu(Menu menu); }
QRCodeMenuDelegate implements MenuDelegate { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_scan_sd_card: Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); if (activityAvailability.isActivityAvailable(photoPickerIntent)) { activity.startActivityForResult(photoPickerIntent, SELECT_PHOTO); } else { ToastUtils.showShortToast(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); Timber.w(activity.getString(R.string.activity_not_found, activity.getString(R.string.choose_image))); } return true; case R.id.menu_item_share: if (qrFilePath != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_STREAM, fileProvider.getURIForFile(qrFilePath)); activity.startActivity(intent); } return true; } return false; } QRCodeMenuDelegate(FragmentActivity activity, ActivityAvailability activityAvailability, QRCodeGenerator qrCodeGenerator, FileProvider fileProvider, PreferencesProvider preferencesProvider, Scheduler scheduler); @Override void onCreateOptionsMenu(MenuInflater menuInflater, Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onPrepareOptionsMenu(Menu menu); static final int SELECT_PHOTO; }