/** * For in-app messages that have a preferred orientation, locks the screen orientation and returns * true if the screen is currently in the preferred orientation. If the screen is not currently in * the preferred orientation, returns false. * * <p>Always returns true for tablets, regardless of current orientation. * * <p>Always returns true if the in-app message doesn't have a preferred orientation. * * @param inAppMessage * @return */ boolean verifyOrientationStatus(IInAppMessage inAppMessage) { if (ViewUtils.isRunningOnTablet(mActivity)) { AppboyLogger.d(TAG, "Running on tablet. In-app message can be displayed in any orientation."); return true; } Orientation preferredOrientation = inAppMessage.getOrientation(); if (preferredOrientation == null) { AppboyLogger.d( TAG, "No orientation specified. In-app message can be displayed in any orientation."); return true; } if (preferredOrientation == Orientation.ANY) { AppboyLogger.d( TAG, "Any orientation specified. In-app message can be displayed in any orientation."); return true; } int currentScreenOrientation = mActivity.getResources().getConfiguration().orientation; if (currentOrientationIsValid(currentScreenOrientation, preferredOrientation)) { if (mOriginalOrientation == null) { AppboyLogger.d(TAG, "Requesting orientation lock."); mOriginalOrientation = mActivity.getRequestedOrientation(); mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); } return true; } return false; }
@Override public void setPreferredOrientations( int deviceOrientationMask, SetPreferredOrientationsResponse callback) { Activity activity = ActivityImpl.getCurrentActivity(); if (activity == null) { callback.call(false); return; } // Currently the Android implementation only supports masks with zero or one // selected device orientations. int androidOrientation; if (deviceOrientationMask == 0) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; } else if (deviceOrientationMask == DeviceOrientation.PORTRAIT_UP) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else if (deviceOrientationMask == DeviceOrientation.LANDSCAPE_LEFT) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if (deviceOrientationMask == DeviceOrientation.PORTRAIT_DOWN) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } else if (deviceOrientationMask == DeviceOrientation.LANDSCAPE_RIGHT) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else { callback.call(false); return; } activity.setRequestedOrientation(androidOrientation); callback.call(true); }
// @TargetApi(5) // TODO find out why the above is not working and I need to use SupressLint to get rid of the // error @SuppressLint("newApi") public void disableRotation() { switch (activity.getResources().getConfiguration().orientation) { case Configuration.ORIENTATION_PORTRAIT: if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == android.view.Surface.ROTATION_90 || rotation == android.view.Surface.ROTATION_180) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } break; case Configuration.ORIENTATION_LANDSCAPE: if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } break; } // switch }
public static void setActivityOrientation(Activity activity, int orientationFromConfiguration) { if (orientationFromConfiguration == Configuration.ORIENTATION_LANDSCAPE) { if (Build.VERSION.SDK_INT < 9) { if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { // You need to check if your desired orientation isn't // already set because setting orientation restarts your // Activity which takes long activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else { if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { // You need to check if your desired orientation isn't // already set because setting orientation restarts your // Activity which takes long activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } } } else if (orientationFromConfiguration == Configuration.ORIENTATION_PORTRAIT) { if (Build.VERSION.SDK_INT < 9) { if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } else { if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } } else { if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_USER) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); } } }
public static void lockOrientation(Activity context) { int currentOrientation = context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } }
public static void setPortrait(Context context) { mIsNeedSensor = true; if (context != null) { if (android.os.Build.VERSION.SDK_INT >= 9 && !VDVideoFullModeController.getInstance().getIsScreenLock()) { ((Activity) context) .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } }
@Override public void onToggleFullScreen() { if (!mInFS) { if (!mIsLargeScreen) mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); openFullscreen(); } else { if (!mIsLargeScreen) mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); closeFullscreen(); } }
@Test public void getAndSetRequestedOrientation_shouldDelegateToParentIfPresent() throws Exception { Activity parentActivity = new Activity() {}; Activity activity = new Activity() {}; shadowOf(activity).setParent(parentActivity); parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, activity.getRequestedOrientation()); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); assertEquals( ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, parentActivity.getRequestedOrientation()); }
public static void setNoSensor(Context context) { mIsNeedSensor = false; if (context != null) { DisplayMetrics metrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics); int w = metrics.widthPixels; int h = metrics.heightPixels; if (w > h) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } }
@Test public void shouldSetOrientation() { activity = create(DialogLifeCycleActivity.class); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); assertThat(activity.getRequestedOrientation()) .isEqualTo(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
public static void setOnlyLandscape(Context context) { mIsNeedSensor = false; if (context != null) { if (android.os.Build.VERSION.SDK_INT >= 9) { ((Activity) context) .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } } }
public void resetAfterInAppMessageClose() { mInAppMessageViewWrapper = null; mDisplayingInAppMessage.set(false); if (mActivity != null && mOriginalOrientation != null) { mActivity.setRequestedOrientation(mOriginalOrientation); AppboyLogger.d( TAG, "Setting requested orientation to original orientation " + mOriginalOrientation); mOriginalOrientation = null; } }
public void onCreate() { activity.setRequestedOrientation( orientationStrategyProvider.getOrientationStrategy().getAppropriateOrientation()); if (androidDevice.isDebuggable()) { ViewServer.get(activity).addWindow(activity); } wasInAccessibilityMode = accessibilityUtil.isAccessibilityEnabled(); getTalkDelegate(); speechDelegate = new SpeechDelegate(activity); talkDelegate.ignoreAnnounceTitleOnce(); }
// 静态方法 锁定屏幕 public static int lockScreenOrientation(Activity mActivity) { Configuration config = mActivity.getResources().getConfiguration(); int mHardwareRotation = SystemProperties.getInt("ro.sf.hwrotation", 0); Log.v( "", ">>>>>>>>>>>> config orientation : " + config.orientation + " , mHardwareRotation : " + mHardwareRotation); switch (mHardwareRotation) { case 0: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case 90: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; // case 180: // mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); // break; // case 270: // mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); // break; default: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; } /* if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { Log.d(TAG, ">>>>>>>>>> lock orientation to landscape"); mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { Log.d(TAG, ">>>>>>>>>> lock orientation to portrait"); mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }*/ return mHardwareRotation; }
public void toggleOrientation() { if (getContext() instanceof Activity && mOrientation != ORIENTATION_LOCKED) { Activity mActivity = (Activity) getContext(); if (isLandscape()) { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } if (mOrientation == ORIENTATION_SENSOR) { getHandler() .postDelayed( new Runnable() { @Override public void run() { setOrientation(mOrientation); } }, 2000); } } }
@Override public void onHideCustomView() { if (mCustomView == null) return; setFullscreen(false); FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); decor.removeView(mFullscreenContainer); mFullscreenContainer = null; mCustomView = null; mCustomViewCallback.onCustomViewHidden(); // Show the content view. mActivity.setRequestedOrientation(mOriginalOrientation); }
public void setOrientation(int orientation) { if (getContext() instanceof Activity) { Activity mActivity = (Activity) getContext(); switch (orientation) { case ORIENTATION_PORTRAIT: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case ORIENTATION_LANDSCAPE: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case ORIENTATION_SENSOR_LANDSCAPE: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); break; case ORIENTATION_SENSOR_PORTRAIT: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); break; case ORIENTATION_SENSOR: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); break; case ORIENTATION_LOCKED: mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); break; } mOrientation = orientation; invalidate(); } }
protected static void a(Activity activity, b b1) { int i = activity.getResources().getConfiguration().orientation; static final class _cls1 { static final int a[]; static { a = new int[b.values().length]; try { a[b.c.ordinal()] = 1; } catch (NoSuchFieldError nosuchfielderror2) { } try { a[com.appnexus.opensdk.b.b.ordinal()] = 2; } catch (NoSuchFieldError nosuchfielderror1) { } try { a[b.a.ordinal()] = 3; } catch (NoSuchFieldError nosuchfielderror) { return; } } } _cls1.a[b1.ordinal()]; JVM INSTR tableswitch 1 3: default 44 // 1 50 // 2 56 // 3 61; goto _L1 _L2 _L3 _L4 _L1: b(activity, i); return; _L2: activity.setRequestedOrientation(-1); return; _L3: i = 2; continue; /* Loop/switch isn't completed */ _L4: i = 1; if (true) goto _L1; else goto _L5
public void show() { PackageInfo versionInfo = getPackageInfo(); final String eulaKey = EULA_PREFIX + versionInfo.versionCode; final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); boolean bAlreadyAccepted = prefs.getBoolean(eulaKey, false); if (bAlreadyAccepted == false) { String title = mContext.getString(R.string.app_name) + " " + versionInfo.versionName; String message = mContext.getString(R.string.eula_string); mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); AlertDialog.Builder builder = new AlertDialog.Builder(mContext) .setTitle(title) .setMessage(message) .setCancelable(false) .setPositiveButton( R.string.accept, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // Mark this version as read. SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(eulaKey, true); editor.commit(); // Close dialog dialogInterface.dismiss(); // Enable orientation changes based on // device's sensor mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } }) .setNegativeButton( android.R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Close the activity as they have declined // the EULA mContext.finish(); mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } }); builder.create().show(); } }
/* returns true when the calling app is responsible for monitoring */ public static boolean setOrientation(Activity activity) { SharedPreferences options = PreferenceManager.getDefaultSharedPreferences(activity); int orientation = Integer.parseInt(options.getString(PREF_ORIENTATION, "0")); switch (orientation) { case 0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); break; case 1: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case 2: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case 3: activity.setRequestedOrientation( options.getInt( Options.PREF_PREV_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)); return true; default: break; } return false; }
@Override public void showCustomView( View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback) { // if a view already exists then immediately terminate the new one if (mCustomView != null) { callback.onCustomViewHidden(); return; } mOriginalOrientation = mActivity.getRequestedOrientation(); FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); mFullscreenContainer = new FullscreenHolder(mActivity); mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS); decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS); mCustomView = view; setFullscreen(true); mCustomViewCallback = callback; mActivity.setRequestedOrientation(requestedOrientation); }
@Before public void setUp() { ShadowApplication.setDisplayMetricsDensity(1.0f); activity = spy(Robolectric.buildActivity(Activity.class).create().get()); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); rootView = new FrameLayout(activity); when(mockBridge.isVisible()).thenReturn(true); // By default, immediately fulfill a screen metrics wait request. Individual tests can // reset this, if desired. when(mockScreenMetricsWaiter.waitFor(Mockito.<View>anyVararg())).thenReturn(mockWaitRequest); doAnswer( new Answer<Void>() { @Override public Void answer(final InvocationOnMock invocation) throws Throwable { Runnable runnable = (Runnable) invocation.getArguments()[0]; runnable.run(); return null; } }) .when(mockWaitRequest) .start(any(Runnable.class)); subject = new MraidController( activity, mockAdReport, PlacementType.INLINE, mockBridge, mockTwoPartBridge, mockScreenMetricsWaiter); subject.setMraidListener(mockMraidListener); subject.setOrientationBroadcastReceiver(mockOrientationBroadcastReceiver); subject.setRootView(rootView); subject.loadContent("fake_html_data"); verify(mockBridge).setMraidBridgeListener(bridgeListenerCaptor.capture()); verify(mockTwoPartBridge).setMraidBridgeListener(twoPartBridgeListenerCaptor.capture()); }
public static void lockOrientationLandscape(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }
public static void setActivityOrientation(Activity activity) { if (shouldSetOrientation()) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Log.d(LOG_TAG, "setOrientationPortait Activity:" + activity); } }
/** * dynamically enable rotation counterpart to enableRotation slightly modified from * http://stackoverflow.com/a/8765901/322642 */ public void enableRotation() { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置无标题窗口 super.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 全屏模式 super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // 强制为横屏 this.setContentView(R.layout.yooxicafe_goodslist); Intent intent = this.getIntent(); String goodsid = intent.getStringExtra("goodsid"); Cursor c = dbhelper.queryByParamgoodsid(dbhelper.GOODS_TM_NAME, goodsid); try { goodslists = jmGoodsListAction.getGoodsListSQLiteNoZip(c); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } c.close(); if (!goodslists.isEmpty()) { holder.setGoodsimage((ImageView) this.findViewById(R.id.goodsimage)); holder.setGoodsname((TextView) this.findViewById(R.id.goodsname)); holder.setWeight((TextView) this.findViewById(R.id.valueweight)); holder.setUnitname((TextView) this.findViewById(R.id.unitname)); holder.setMemberprice((TextView) this.findViewById(R.id.memberprice)); holder.setDetail((TextView) this.findViewById(R.id.goodsdetail)); holder.getGoodsimage().setImageBitmap((Bitmap) goodslists.get(0).get("pictureurl")); holder.getGoodsname().setText(goodslists.get(0).get("goodsname").toString()); holder.getMemberprice().setText(goodslists.get(0).get("memberprice").toString()); holder.getUnitname().setText(goodslists.get(0).get("unitname").toString()); holder.getWeight().setText(goodslists.get(0).get("weight").toString()); } // 处理返回事件响应 getback = (TextView) this.findViewById(R.id.getback); getback.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { finish(); } }); // 处理加入餐车事件 countplus = (TextView) this.findViewById(R.id.countplus); countplus.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { addtoCart(goodslists, 0); } }); // 查看已选 checkselected = (TextView) this.findViewById(R.id.checkselected); checkselected.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { setElecartListView(); } }); }
@Test public void getAndSetRequestedOrientation_shouldRemember() throws Exception { Activity activity = new Activity() {}; activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, activity.getRequestedOrientation()); }
public static void setSensor(Context context) { mIsNeedSensor = true; if (context != null) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }
public static void unlockOrientation(Activity context) { context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); }
/** * 设置activity屏幕为垂直方向。 * * @param activity Activity对象。 */ public static void setScreenPortrait(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }