List of usage examples for android.view Display getRotation
@Surface.Rotation public int getRotation()
From source file:Main.java
/** * Calls {@link Display#getRotation()}/*from w w w . j a v a2 s. c o m*/ * * @return one of {@link android.view.Surface#ROTATION_0}, * {@link android.view.Surface#ROTATION_90}, * {@link android.view.Surface#ROTATION_180}, * or {@link android.view.Surface#ROTATION_180}. */ public static int getRotation(Display display) { return display.getRotation(); }
From source file:Main.java
public static int getRotation(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); return display.getRotation(); }
From source file:Main.java
/** * Calculates the default orientation of the device.<br> * The default orientation of most phones is portrait, and the default orientation of most tablets is landscape. * /*from w ww .j a va 2s . c o m*/ * @param activity Activity. * @return {@link Configuration#ORIENTATION_PORTRAIT} or {@link Configuration#ORIENTATION_LANDSCAPE} */ public static int getDefaultOrientationOfDevice(Activity activity) { Configuration configuration = activity.getResources().getConfiguration(); boolean orientationLandscape = (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE); Display display = activity.getWindowManager().getDefaultDisplay(); int rotation = display.getRotation(); boolean parallelToDefaultVerticalAxis = (rotation == Surface.ROTATION_0) || (rotation == Surface.ROTATION_180); boolean defaultOrientationLandscape = (parallelToDefaultVerticalAxis && orientationLandscape) || (!parallelToDefaultVerticalAxis && !orientationLandscape); if (defaultOrientationLandscape) { return Configuration.ORIENTATION_LANDSCAPE; } return Configuration.ORIENTATION_PORTRAIT; }
From source file:Main.java
public static void lockOrientation(Activity activity) { Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); int tempOrientation = activity.getResources().getConfiguration().orientation; int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; switch (tempOrientation) { case Configuration.ORIENTATION_LANDSCAPE: if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; else// ww w .ja v a 2 s .c o m orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Configuration.ORIENTATION_PORTRAIT: if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; else orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } activity.setRequestedOrientation(orientation); }
From source file:Main.java
/** * @Thach Feb 21, 2014/*w w w . j ava 2 s. co m*/ * @Desc lock Orientation * @param b */ @SuppressWarnings("deprecation") public static void lockOrientation(Activity act, boolean isLock) { if (act == null) { return; } if (isLock) { Display display = act.getWindowManager().getDefaultDisplay(); int rotation = display.getRotation(); int height; int width; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) { height = display.getHeight(); width = display.getWidth(); } else { Point size = new Point(); display.getSize(size); height = size.y; width = size.x; } switch (rotation) { case Surface.ROTATION_90: if (width > height) act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else act.setRequestedOrientation(9/* reversePortait */); break; case Surface.ROTATION_180: if (height > width) act.setRequestedOrientation(9/* reversePortait */); else act.setRequestedOrientation(8/* reverseLandscape */); break; case Surface.ROTATION_270: if (width > height) act.setRequestedOrientation(8/* reverseLandscape */); else act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; default: if (height > width) act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); else act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else { act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }
From source file:org.acra.collector.DisplayManagerCollector.java
@NonNull private static String collectRotation(@NonNull Display display) { return display.getDisplayId() + ".rotation=" + rotationToString(display.getRotation()) + '\n'; }
From source file:Main.java
public static int getSurfaceOrientation(Activity activity) { // Sanity check: if (activity == null) { return -1; // invalid value }/*from ww w . j av a 2s . co m*/ Configuration config = activity.getResources().getConfiguration(); Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int displayRotation; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { displayRotation = display.getRotation(); // only available from Froyo } else { displayRotation = display.getOrientation(); } int activityOrientation = SCREEN_ORIENTATION_UNKNOWN; switch (config.orientation) { case Configuration.ORIENTATION_PORTRAIT: case Configuration.ORIENTATION_SQUARE: activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_270) ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_PORTRAITUPSIDEDOWN); break; case Configuration.ORIENTATION_LANDSCAPE: activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90) ? SCREEN_ORIENTATION_LANDSCAPELEFT : SCREEN_ORIENTATION_LANDSCAPERIGHT); break; case Configuration.ORIENTATION_UNDEFINED: default: break; } return activityOrientation; }
From source file:me.wimanacra.collector.DisplayManagerCollector.java
private static void collectRotation(@NonNull Display display, JSONObject container) throws JSONException { container.put("rotation", rotationToString(display.getRotation())); }
From source file:com.poloure.simplerss.FeedsActivity.java
/** * Checks to see if the default Display in the WindowManager is rotated horizontally. * * @return true if the display is currently rotated horizontally, false otherwise. */// w w w . j a v a 2 s. c o m private static boolean isDisplayHorizontal() { Display display = s_windowManager.getDefaultDisplay(); int rotation = display.getRotation(); return Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation; }
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
public static void showAboutDialog(final Context mContext) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = li.inflate(R.layout.about, null); String sVersionInfo = ""; try {//from w ww. j a va 2 s . c o m PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); sVersionInfo += pi.versionName; if (!pi.versionName.contains("" + pi.versionCode)) sVersionInfo += " (" + pi.versionCode + ")"; if (OpenExplorer.IS_DEBUG_BUILD) sVersionInfo += " *debug*"; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String sBuildTime = ""; try { sBuildTime = SimpleDateFormat.getInstance() .format(new Date(new ZipFile( mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0).sourceDir) .getEntry("classes.dex").getTime())); } catch (Exception e) { Logger.LogError("Couldn't get Build Time.", e); } WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); Display d = wm.getDefaultDisplay(); String sHardwareInfo = "Display:\n"; sHardwareInfo += "Size: " + d.getWidth() + "x" + d.getHeight() + "\n"; if (dm != null) sHardwareInfo += "Density: " + dm.density + "\n"; sHardwareInfo += "Rotation: " + d.getRotation() + "\n\n"; sHardwareInfo += getNetworkInfo(mContext); sHardwareInfo += getDeviceInfo(); ((TextView) view.findViewById(R.id.about_hardware)).setText(sHardwareInfo); final String sSubject = "Feedback for OpenExplorer " + sVersionInfo; OnClickListener email = new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //intent.addCategory(Intent.CATEGORY_APP_EMAIL); intent.putExtra(android.content.Intent.EXTRA_TEXT, "\n" + getDeviceInfo()); intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "brandroid64@gmail.com" }); intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sSubject); mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.s_chooser_email))); } }; OnClickListener viewsite = new OnClickListener() { public void onClick(View v) { mContext.startActivity( new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://brandroid.org/open/"))); } }; view.findViewById(R.id.about_email).setOnClickListener(email); view.findViewById(R.id.about_email_btn).setOnClickListener(email); view.findViewById(R.id.about_site).setOnClickListener(viewsite); view.findViewById(R.id.about_site_btn).setOnClickListener(viewsite); final View mRecentLabel = view.findViewById(R.id.about_recent_status_label); final WebView mRecent = (WebView) view.findViewById(R.id.about_recent); final OpenChromeClient occ = new OpenChromeClient(); occ.mStatus = (TextView) view.findViewById(R.id.about_recent_status); mRecent.setWebChromeClient(occ); mRecent.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { occ.mStatus.setVisibility(View.GONE); mRecent.setVisibility(View.GONE); mRecentLabel.setVisibility(View.GONE); } }); mRecent.setBackgroundColor(Color.TRANSPARENT); mRecent.loadUrl("http://brandroid.org/open/?show=recent"); ((TextView) view.findViewById(R.id.about_version)).setText(sVersionInfo); if (sBuildTime != "") ((TextView) view.findViewById(R.id.about_buildtime)).setText(sBuildTime); else ((TableRow) view.findViewById(R.id.row_buildtime)).setVisibility(View.GONE); fillShortcutsTable((TableLayout) view.findViewById(R.id.shortcuts_table)); final View tab1 = view.findViewById(R.id.tab1); final View tab2 = view.findViewById(R.id.tab2); final View tab3 = view.findViewById(R.id.tab3); ((Button) view.findViewById(R.id.btn_recent)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.VISIBLE); tab2.setVisibility(View.GONE); tab3.setVisibility(View.GONE); } }); ((Button) view.findViewById(R.id.btn_hardware)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.GONE); tab2.setVisibility(View.VISIBLE); tab3.setVisibility(View.GONE); } }); ((Button) view.findViewById(R.id.btn_shortcuts)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.GONE); tab2.setVisibility(View.GONE); tab3.setVisibility(View.VISIBLE); } }); AlertDialog mDlgAbout = new AlertDialog.Builder(mContext).setTitle(R.string.app_name).setView(view) .create(); mDlgAbout.getWindow().getAttributes().windowAnimations = R.style.SlideDialogAnimation; mDlgAbout.getWindow().getAttributes().alpha = 0.9f; mDlgAbout.show(); }