android.content.pm.ActivityInfo Java Examples

The following examples show how to use android.content.pm.ActivityInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SuggestionsAdapter.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example #2
Source File: Theme.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
public static HashMap<String, String> getAvailableThemes(Context ctxt){
	HashMap<String, String> result = new HashMap<String, String>();
	result.put("", ctxt.getResources().getString(R.string.app_name));
	
	PackageManager packageManager = ctxt.getPackageManager();
	Intent it = new Intent(SipManager.ACTION_GET_DRAWABLES);
	
	List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
	Log.d(THIS_FILE, "We found " + availables.size() + "themes");
	for(ResolveInfo resInfo : availables) {
		Log.d(THIS_FILE, "We have -- "+resInfo);
		ActivityInfo actInfos = resInfo.activityInfo;
		ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
		String label = (String) actInfos.loadLabel(packageManager);
		if(TextUtils.isEmpty(label)) {
		    label = (String) resInfo.loadLabel(packageManager);
		}
		result.put(cmp.flattenToString(), label);
	}
	
	return result;
}
 
Example #3
Source File: MainActivityTest.java    From media-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void fullscreen_disabledOnPortrait() throws Throwable {
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            rule.getActivity()
                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final View decorView = rule.getActivity().getWindow().getDecorView();
            assertThat(decorView.getSystemUiVisibility(),
                    not(hasFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)));
        }
    });
}
 
Example #4
Source File: RecyclerViewAdapter.java    From ExoPlayer-Wrapper with Apache License 2.0 6 votes vote down vote up
public void changeToNormalScreen() {
    ((Activity) mTextView.getContext()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mLayouManager.enableScroll();

    RecyclerView.LayoutParams layoutParamsItem = (RecyclerView.LayoutParams) mView.getLayoutParams();
    layoutParamsItem.height = mItemHeight;
    layoutParamsItem.width = mItemWidth;
    layoutParamsItem.topMargin = mItemTopMargin;
    layoutParamsItem.bottomMargin = mItemBottomMargin;
    layoutParamsItem.leftMargin = mItemLeftMargin;
    layoutParamsItem.rightMargin = mItemRightMargin;
    mView.setLayoutParams(layoutParamsItem);

    ConstraintLayout.LayoutParams videoParams = (ConstraintLayout.LayoutParams) mExoPlayerView.getLayoutParams();
    videoParams.height = mVideoHeight;
    videoParams.width = mVideoWidth;
    //videoParams.bottomToBottom = 0;
    mExoPlayerView.setLayoutParams(videoParams);

    mTextView.setVisibility(View.VISIBLE);
}
 
Example #5
Source File: ManifestValidator.java    From braintree_android with MIT License 6 votes vote down vote up
@Nullable
public static ActivityInfo getActivityInfo(Context context, Class klass) {
    try {
        PackageInfo packageInfo =
                context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
        ActivityInfo[] activities = packageInfo.activities;
        if (activities != null) {
            for (ActivityInfo activityInfo : activities) {
                if (activityInfo.name.equals(klass.getName())) {
                    return activityInfo;
                }
            }
        }
    } catch (NameNotFoundException ignored) {}

    return null;
}
 
Example #6
Source File: GalleryPreviewDetail.java    From moviedb-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (activity.getSupportActionBar() != null && activity.getSupportActionBar().isShowing())
        activity.getSupportActionBar().hide();

    if (Build.VERSION.SDK_INT >= 19) {
        mUIFlag ^= View.SYSTEM_UI_FLAG_IMMERSIVE;
    }

    if (this.isVisible()) {
        // Check orientation and lock to portrait if we are on phone
        if (getResources().getBoolean(R.bool.portrait_only)) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        }
    }
    imageLoader.displayImage(currImg, mImageView, options, imageLoadingListener);
}
 
Example #7
Source File: BaseActivity.java    From FlowGeek with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 主题选择
    SharedPreferences preferences = SharePreferenceManager.getApplicationSetting(this);

    int theme = preferences.getInt(ApplicationSetting.KEY_THEME, ApplicationTheme.LIGHT.getKey());

    if (theme == ApplicationTheme.LIGHT.getKey()){
        setTheme(ApplicationTheme.LIGHT.getResId());
    }else if(theme == ApplicationTheme.DARK.getKey()){
        setTheme(ApplicationTheme.DARK.getResId());
    }

    // 方向锁定
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
 
Example #8
Source File: InstrActivityProxy1.java    From Neptune with Apache License 2.0 6 votes vote down vote up
@Override
public void setTheme(int resId) {
    if (VersionUtils.hasNougat()) {
        String[] temp = parsePkgAndClsFromIntent();
        if (mNeedUpdateConfiguration && (temp != null || mLoadedApk != null)) {
            if (null != temp && temp.length == 2) {
                tryToInitPluginLoadApk(temp[0]);
            }
            if (mLoadedApk != null && temp != null) {
                ActivityInfo actInfo = mLoadedApk.getActivityInfoByClassName(temp[1]);
                if (actInfo != null) {
                    int resTheme = actInfo.getThemeResource();
                    if (mNeedUpdateConfiguration) {
                        changeActivityInfo(InstrActivityProxy1.this, temp[0], actInfo);
                        super.setTheme(resTheme);
                        mNeedUpdateConfiguration = false;
                        return;
                    }
                }
            }
        }
        super.setTheme(resId);
    } else {
        getTheme().applyStyle(resId, true);
    }
}
 
Example #9
Source File: PlayerActivity.java    From GiraffePlayer2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.giraffe_player_activity);
    Intent intent = getIntent();
    if (intent == null) {
        finish();
        return;
    }
    VideoInfo videoInfo = intent.getParcelableExtra("__video_info__");
    if (videoInfo == null) {
        finish();
        return;
    }
    if(videoInfo.isFullScreenOnly()){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }
    PlayerManager.getInstance().releaseByFingerprint(videoInfo.getFingerprint());
    VideoView videoView = findViewById(R.id.video_view);
    videoView.videoInfo(videoInfo);
    PlayerManager.getInstance().getPlayer(videoView).start();
}
 
Example #10
Source File: NoteTakingActivity.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  permissions = new RxPermissions(this);
  setContentView(R.layout.activity_experiment_layout);

  Resources resources = getResources();
  boolean isTablet = resources.getBoolean(R.bool.is_tablet);
  if (!isTablet) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }
  boolean isLandscape =
      resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
  isTwoPane = isTablet && isLandscape;

  appAccount = WhistlePunkApplication.getAccount(this, getIntent(), EXTRA_ACCOUNT_KEY);
  experimentId = getIntent().getStringExtra(EXTRA_EXPERIMENT_ID);
  exp = whenSelectedExperiment(experimentId, getDataController());

  AppSingleton.getInstance(this)
      .whenLabelsAdded(appAccount)
      .takeUntil(destroyed.happens())
      .subscribe(event -> onLabelAdded(event.getTrialId(), event.getLabel()));
}
 
Example #11
Source File: SuggestionsAdapter.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example #12
Source File: RunningProcessList.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
boolean isStubInfoUsed(ActivityInfo stubInfo, ActivityInfo targetInfo, String stubProcessName) {
    for (Integer pid : items.keySet()) {
        ProcessItem item = items.get(pid);
        if (TextUtils.equals(item.stubProcessName, stubProcessName)) {
            Set<ActivityInfo> infos = item.activityInfosMap.get(stubInfo.name);
            if (infos != null && infos.size() > 0) {
                for (ActivityInfo info : infos) {
                    if (TextUtils.equals(info.name, targetInfo.name) && TextUtils.equals(info.packageName, targetInfo.packageName)) {
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
    }
    return false;
}
 
Example #13
Source File: PreferredComponent.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** Returns components from mSetPackages that are present in query. */
public ComponentName[] discardObsoleteComponents(List<ResolveInfo> query) {
    if (mSetPackages == null || query == null) {
        return new ComponentName[0];
    }
    final int NQ = query.size();
    final int NS = mSetPackages.length;
    ArrayList<ComponentName> aliveComponents = new ArrayList<>();
    for (int i = 0; i < NQ; i++) {
        ResolveInfo ri = query.get(i);
        ActivityInfo ai = ri.activityInfo;
        for (int j = 0; j < NS; j++) {
            if (mSetPackages[j].equals(ai.packageName) && mSetClasses[j].equals(ai.name)) {
                aliveComponents.add(new ComponentName(mSetPackages[j], mSetClasses[j]));
                break;
            }
        }
    }
    return aliveComponents.toArray(new ComponentName[aliveComponents.size()]);
}
 
Example #14
Source File: EyepetizerDetailActivity.java    From Ency with Apache License 2.0 6 votes vote down vote up
private void initVideoPlayer() {
    LinkedHashMap map = new LinkedHashMap();
    if (videoBean.getContent().getData().getPlayInfo().size() == 3) {
        map.put("流畅", videoBean.getContent().getData().getPlayInfo().get(0).getUrl());
        map.put("标清", videoBean.getContent().getData().getPlayInfo().get(1).getUrl());
        map.put("高清", videoBean.getContent().getData().getPlayInfo().get(2).getUrl());
    } else if (videoBean.getContent().getData().getPlayInfo().size() == 2) {
        map.put("标清", videoBean.getContent().getData().getPlayInfo().get(0).getUrl());
        map.put("高清", videoBean.getContent().getData().getPlayInfo().get(1).getUrl());
    } else if (videoBean.getContent().getData().getPlayInfo().size() == 1) {
        map.put("高清", videoBean.getContent().getData().getPlayInfo().get(0).getUrl());
    }
    Object[] objects = new Object[3];
    objects[0] = map;
    objects[1] = false;//looping
    objects[2] = new HashMap<>();
    videoPlayerStandard.backButton.setVisibility(View.VISIBLE);
    videoPlayerStandard.titleTextView.setTextSize(16);
    videoPlayerStandard.setUp(objects, 0,
            JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL, videoBean.getContent().getData().getTitle());
    ImageLoader.loadAllNoPlaceHolder(mContext, videoBean.getContent().getData().getCover().getFeed()
            ,videoPlayerStandard.thumbImageView);
    JZVideoPlayer.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    JZVideoPlayer.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
 
Example #15
Source File: MxVideoPlayer.java    From MxVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void autoFullscreen(float x) {
    Log.i(TAG, "autoFullscreen: [" + this.hashCode() + "] ");
    if (isCurrentMediaListener()
            && mCurrentState == CURRENT_STATE_PLAYING
            && mCurrentScreen != SCREEN_WINDOW_FULLSCREEN
            && mCurrentScreen != SCREEN_WINDOW_TINY) {
        if (x > 0) {
            MxUtils.getAppComptActivity(getContext()).setRequestedOrientation(
                    ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            MxUtils.getAppComptActivity(getContext()).setRequestedOrientation(
                    ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
        startWindowFullscreen();
    }
}
 
Example #16
Source File: RunningProcessList.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addActivityInfo(String stubActivityName, ActivityInfo info) {
    if (!targetActivityInfos.containsKey(info.name)) {
        targetActivityInfos.put(info.name, info);
    }

    //pkgs
    if (!pkgs.contains(info.packageName)) {
        pkgs.add(info.packageName);
    }

    //stub map to activity info
    Set<ActivityInfo> list = activityInfosMap.get(stubActivityName);
    if (list == null) {
        list = new TreeSet<ActivityInfo>(sComponentInfoComparator);
        list.add(info);
        activityInfosMap.put(stubActivityName, list);
    } else {
        list.add(info);
    }
}
 
Example #17
Source File: MediaPlayer.java    From HeroVideo-master with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    if (v.getId() == R.id.app_video_fullscreen) {
        toggleFullScreen();
    } else if (v.getId() == R.id.app_video_play) {
        doPauseResume();
        show(defaultTimeout);
    }else if (v.getId() == R.id.app_video_replay_icon) {
        videoView.seekTo(0);
        videoView.start();
        doPauseResume();
    } else if (v.getId() == R.id.app_video_finish) {
        if (!fullScreenOnly && !portrait) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
            activity.finish();
        }
    }
}
 
Example #18
Source File: VActivityManager.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public ActivityClientRecord onActivityCreate(ComponentName component, ComponentName caller, IBinder token, ActivityInfo info, Intent intent, String affinity, int taskId, int launchMode, int flags) {
    ActivityClientRecord r = new ActivityClientRecord();
    r.info = info;
    mActivities.put(token, r);
    try {
        getService().onActivityCreated(component, caller, token, intent, affinity, taskId, launchMode, flags);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return r;
}
 
Example #19
Source File: ScreenUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置屏幕为竖屏
 * @param activity {@link Activity}
 * @return {@code true} success, {@code false} fail
 */
public static boolean setPortrait(final Activity activity) {
    try {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        return true;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "setPortrait");
    }
    return false;
}
 
Example #20
Source File: PackageManagerUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static ComponentName getComponentName(Context context, Intent intent) {
	PackageManager packageManager = context.getPackageManager();
	ComponentName resolvedComponentName = intent.resolveActivity(packageManager);
	try {
		ActivityInfo activityInfo = packageManager.getActivityInfo(resolvedComponentName, 0);
		if (activityInfo.targetActivity != null) {
			return new ComponentName(resolvedComponentName.getPackageName(), activityInfo.targetActivity);
		}
	} catch (PackageManager.NameNotFoundException e) {
		// TODO nothing
	}
	return resolvedComponentName;
}
 
Example #21
Source File: ApplicationUtils.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
public static int getActivityTitleResId(final Context context,
        final Class<? extends Activity> cls) {
    final ComponentName cn = new ComponentName(context, cls);
    try {
        final ActivityInfo ai = context.getPackageManager().getActivityInfo(cn, 0);
        if (ai != null) {
            return ai.labelRes;
        }
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Failed to get settings activity title res id.", e);
    }
    return 0;
}
 
Example #22
Source File: XFlutterActivityDelegate.java    From hybrid_stack_manager with MIT License 5 votes vote down vote up
/**
 * Let the user specify whether the activity's {@code windowBackground} is a launch screen
 * and should be shown until the first frame via a <meta-data> tag in the activity.
 */
private Boolean showSplashScreenUntilFirstFrame() {
    try {
        ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(
                activity.getComponentName(),
                PackageManager.GET_META_DATA|PackageManager.GET_ACTIVITIES);
        Bundle metadata = activityInfo.metaData;
        return metadata != null && metadata.getBoolean(SPLASH_SCREEN_META_DATA_KEY);
    } catch (NameNotFoundException e) {
        return false;
    }
}
 
Example #23
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public ActivityInfo getReceiverInfo(ComponentName className, int flags)
        throws NameNotFoundException {
    try {
        ActivityInfo ai = mPM.getReceiverInfo(className, flags);
        if (ai != null) {
            return ai;
        }
    } catch (RemoteException e) {
        throw new RuntimeException("Package manager has died", e);
    }

    throw new NameNotFoundException(className.toString());
}
 
Example #24
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
        ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo,
        Bundle state, List<ResultInfo> pendingResults,
        List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
        String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler) {
    ActivityClientRecord r = new ActivityClientRecord();

    r.token = token;
    r.ident = ident;
    r.intent = intent;
    r.activityInfo = info;
    r.compatInfo = compatInfo;
    r.state = state;

    r.pendingResults = pendingResults;
    r.pendingIntents = pendingNewIntents;

    r.startsNotResumed = notResumed;
    r.isForward = isForward;

    r.profileFile = profileName;
    r.profileFd = profileFd;
    r.autoStopProfiler = autoStopProfiler;

    updatePendingConfiguration(curConfig);

    queueOrSendMessage(H.LAUNCH_ACTIVITY, r);
}
 
Example #25
Source File: LandscapeUITests.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Switch screen orientation to landscape. Perform some action. Switch back again. Perform some
 * action
 */
@Test public void landscapeHomeTab() {
  Activity activity = mActivityRule.getActivity();
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  onView(withId(R.id.toolbar)).perform(swipeUp());
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  onView(withId(R.id.toolbar)).perform(swipeUp());
}
 
Example #26
Source File: VerFullLiveUI.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_verfulllive);
    mActivityComponent.inject(this);
    livePlayerPresenterImpl.attachView(this);
    initPlayer();
    initControll();
    initData();
}
 
Example #27
Source File: ViewUtil.java    From android-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Set orientation change lock
 *
 * @param activity the activity
 * @param status   the status
 */
public static void setOrientation(Activity activity, boolean status) {
    if (status) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
        }
    } else {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
    }
}
 
Example #28
Source File: Hook_StartActivity.java    From DeepInVirtualApp with MIT License 5 votes vote down vote up
private void replaceIntent(IBinder resultTo, Object[] args, int intentIndex) {
    //由于我们没有在Manifest里注册这个类,所以我们获取不到这个ActivityInfo,so我们直接从一个桩里去信息赋值到启动的Activity中
    final Intent targetIntent = (Intent) args[intentIndex];

    ActivityInfo stubInfo = DodoApplication.info;
    Intent stubIntent = new Intent();
    stubIntent.setClassName(stubInfo.packageName, stubInfo.name);//此处其实new了一个ComponentName
    stubIntent.putExtra(ExtraConstants.EXTRA_TARGET_INTENT, targetIntent);//将我们要跳转的东东保存起来
    args[intentIndex] = stubIntent;
}
 
Example #29
Source File: MediaPlayer.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
public boolean onBackPressed() {
    if (!fullScreenOnly && getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        return true;
    }
    return false;
}
 
Example #30
Source File: PackageManagerUtils.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
public static PackageManager mockPackageManagerSupportsThreeDSecure()
        throws PackageManager.NameNotFoundException {
    ActivityInfo activityInfo = new ActivityInfo();
    PackageInfo packageInfo = new PackageInfo();
    Application app = RuntimeEnvironment.application;

    activityInfo.name = "com.braintreepayments.api.BraintreeBrowserSwitchActivity";
    activityInfo.launchMode = LAUNCH_SINGLE_TASK;

    packageInfo.activities = new ActivityInfo[] { activityInfo };

    PackageManager packageManager = spy(RuntimeEnvironment.application.getPackageManager());
    doReturn(packageInfo).when(packageManager)
            .getPackageInfo("com.braintreepayments.api.dropin", PackageManager.GET_ACTIVITIES);
    doAnswer(new Answer() {
        @Override
        public List<ResolveInfo> answer(InvocationOnMock invocation) throws Throwable {
            String browserSwitchUri = "com.braintreepayments.api.dropin.braintree";
            String data = ((Intent) invocation.getArguments()[0]).getDataString();
            if (data == null) {
                data = "";
            }

            if (data.contains(browserSwitchUri)) {
                return Arrays.asList(new ResolveInfo());
            } else {
                return (List<ResolveInfo>) invocation.callRealMethod();
            }
        }
    }).when(packageManager).queryIntentActivities(any(Intent.class), eq(0));

    return packageManager;
}