@Test public void clickingOnImportQRCode_whenPickerActivityNotAvailable_showsToast() { when(activityAvailability.isActivityAvailable(any())).thenReturn(false); menuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_item_scan_sd_card)); assertThat(shadowOf(activity).getNextStartedActivityForResult(), is(nullValue())); assertThat(ShadowToast.getLatestToast(), notNullValue()); }
@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; }