use of android.annotation.TargetApi in project mobile-center-sdk-android by Microsoft.
the class DistributeDownloadTest method notifyThenRestartAppTwice.
@Test
@PrepareForTest(Uri.class)
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void notifyThenRestartAppTwice() throws Exception {
/* Simulate async task. */
waitDownloadTask();
/* Process fake download completion, should not interfere and will be ignored. */
{
Intent completionIntent = mock(Intent.class);
when(completionIntent.getAction()).thenReturn(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
when(completionIntent.getLongExtra(eq(EXTRA_DOWNLOAD_ID), anyLong())).thenReturn(404L);
new DownloadManagerReceiver().onReceive(mContext, completionIntent);
waitCheckDownloadTask();
verify(mDownloadManager, never()).query(any(DownloadManager.Query.class));
}
/* Process download completion with the real download identifier. */
completeDownload();
Cursor cursor = mockSuccessCursor();
Intent installIntent = mockInstallIntent();
/* In background. */
Distribute.getInstance().onActivityPaused(mActivity);
/* Mock notification. */
when(mPackageManager.getApplicationInfo(mContext.getPackageName(), 0)).thenReturn(mock(ApplicationInfo.class));
TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.JELLY_BEAN);
Notification.Builder notificationBuilder = mockNotificationBuilderChain();
when(notificationBuilder.build()).thenReturn(mock(Notification.class));
/* Simulate task. */
waitCheckDownloadTask();
/* Verify notification. */
verify(mContext, never()).startActivity(installIntent);
verifyStatic();
PreferencesStorage.putInt(PREFERENCE_KEY_DOWNLOAD_STATE, DOWNLOAD_STATE_NOTIFIED);
verify(notificationBuilder).build();
verify(notificationBuilder, never()).getNotification();
verify(mNotificationManager).notify(eq(DistributeUtils.getNotificationId()), any(Notification.class));
verifyNoMoreInteractions(mNotificationManager);
verify(cursor).close();
/* Launch app should pop install U.I. and cancel notification. */
when(mActivity.getPackageManager()).thenReturn(mPackageManager);
Intent launcherIntent = mock(Intent.class);
when(mPackageManager.getLaunchIntentForPackage(anyString())).thenReturn(launcherIntent);
ComponentName launcher = mock(ComponentName.class);
when(launcherIntent.resolveActivity(mPackageManager)).thenReturn(launcher);
when(launcher.getClassName()).thenReturn(mActivity.getClass().getName());
restartActivity();
/* Wait again. */
waitCheckDownloadTask();
/* Verify U.I shown after restart and workflow completed. */
verify(mContext).startActivity(installIntent);
verify(mNotificationManager).cancel(DistributeUtils.getNotificationId());
verifyStatic();
/* Verify workflow completed. */
PreferencesStorage.remove(PREFERENCE_KEY_DOWNLOAD_STATE);
/* Verify however downloaded file was kept. */
verifyStatic(never());
PreferencesStorage.remove(PREFERENCE_KEY_DOWNLOAD_ID);
verify(mDownloadManager, never()).remove(DOWNLOAD_ID);
/* Verify second download (restart app again) cleans first one. */
when(mDownloadManager.enqueue(mDownloadRequest)).thenReturn(DOWNLOAD_ID + 1);
restartActivity();
ArgumentCaptor<DialogInterface.OnClickListener> clickListener = ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
verify(mDialogBuilder, times(2)).setPositiveButton(eq(R.string.mobile_center_distribute_update_dialog_download), clickListener.capture());
clickListener.getValue().onClick(mDialog, DialogInterface.BUTTON_POSITIVE);
waitDownloadTask();
/* Verify new download id in storage. */
verifyStatic();
PreferencesStorage.putLong(PREFERENCE_KEY_DOWNLOAD_ID, DOWNLOAD_ID + 1);
/* Verify previous download removed. */
verify(mDownloadManager).remove(DOWNLOAD_ID);
/* Notification already canceled so no more call, i.e. only once. */
verify(mNotificationManager).cancel(DistributeUtils.getNotificationId());
}
use of android.annotation.TargetApi in project NetGuard by M66B.
the class Util method getSubscriptionInfo.
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
return "Not supported";
if (!hasPhoneStatePermission(context))
return "No permission";
StringBuilder sb = new StringBuilder();
SubscriptionManager sm = SubscriptionManager.from(context);
sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/').append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n");
int dataid = -1;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
dataid = sm.getDefaultDataSubscriptionId();
int voiceid = -1;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
voiceid = sm.getDefaultVoiceSubscriptionId();
List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
if (subscriptions != null)
for (SubscriptionInfo si : subscriptions) sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId()).append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc()).append(' ').append(si.getCarrierName()).append(si.getSubscriptionId() == dataid ? " D" : "").append(si.getSubscriptionId() == voiceid ? " V" : "").append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "").append("\r\n");
if (sb.length() > 2)
sb.setLength(sb.length() - 2);
return sb.toString();
}
use of android.annotation.TargetApi in project SublimePicker by vikramkakkar.
the class SimpleMonthView method onMeasure.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int preferredHeight = mDesiredDayHeight * MAX_WEEKS_IN_MONTH + mDesiredDayOfWeekHeight + mDesiredMonthHeight + getPaddingTop() + getPaddingBottom();
final int preferredWidth = mDesiredCellWidth * DAYS_IN_WEEK + (SUtils.isApi_17_OrHigher() ? getPaddingStart() : getPaddingLeft()) + (SUtils.isApi_17_OrHigher() ? getPaddingEnd() : getPaddingRight());
final int resolvedWidth = resolveSize(preferredWidth, widthMeasureSpec);
final int resolvedHeight = resolveSize(preferredHeight, heightMeasureSpec);
setMeasuredDimension(resolvedWidth, resolvedHeight);
}
use of android.annotation.TargetApi in project wire-android by wireapp.
the class ConversationFragmentTest method assertCursorImagesGalleryButton.
@TargetApi(Build.VERSION_CODES.KITKAT)
public void assertCursorImagesGalleryButton() throws Exception {
IConversation mockConversation = mock(IConversation.class);
when(mockConversation.getType()).thenReturn(IConversation.Type.GROUP);
when(mockConversation.isMemberOfConversation()).thenReturn(true);
when(mockConversation.isActive()).thenReturn(true);
IAccentColorController mockAccentColorController = activity.getControllerFactory().getAccentColorController();
AccentColor mockAccentColor = mock(AccentColor.class);
when(mockAccentColor.getColor()).thenReturn(Color.RED);
when(mockAccentColorController.getAccentColor()).thenReturn(mockAccentColor);
String action = Intent.ACTION_OPEN_DOCUMENT;
Matcher<Intent> expectedIntent = allOf(hasAction(action), hasType("image/*"));
Intent intent = new Intent();
intent.setData(Uri.parse("file:///tmp/whatever.txt"));
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, intent);
intending(expectedIntent).respondWith(result);
MockHelper.setupConversationMocks(mockConversation, activity);
attachFragment(ConversationFragment.newInstance(), ConversationFragment.TAG);
onView(withId(R.id.cursor_menu_item_camera)).check(isVisible());
onView(withId(R.id.cursor_menu_item_camera)).perform(click());
Thread.sleep(500);
onView(withId(R.id.rv__cursor_images)).check(isVisible());
onView(withId(R.id.gtv__cursor_image__nav_open_gallery)).check(isVisible());
// onView(withId(R.id.gtv__cursor_image__nav_open_gallery)).perform(click());
}
use of android.annotation.TargetApi in project react-native-navigation by wix.
the class Screen method setNavigationBarColor.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setNavigationBarColor(StyleParams.Color navigationBarColor) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;
final Activity context = (Activity) getContext();
final Window window = context.getWindow();
if (navigationBarColor.hasColor()) {
window.setNavigationBarColor(navigationBarColor.getColor());
} else {
window.setNavigationBarColor(Color.BLACK);
}
}
Aggregations