本文整理了Java中android.view.Display.getOrientation()
方法的一些代码示例,展示了Display.getOrientation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Display.getOrientation()
方法的具体详情如下:
包路径:android.view.Display
类名称:Display
方法名:getOrientation
暂无
代码示例来源:origin: stackoverflow.com
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if (display.getOrientation() == Surface.ROTATION_0) {
// landscape oriented devices
} else {
// portrait oriented device
}
代码示例来源:origin: stackoverflow.com
private int _getScreenOrientation(){
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
return display.getOrientation();
}
代码示例来源:origin: stackoverflow.com
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
switch(orientation) {
case Configuration.ORIENTATION_PORTRAIT:
if(!oAllow) {
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
break;
case Configuration.ORIENTATION_LANDSCAPE:
if(!oAllow) {
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
break;
}
}
代码示例来源:origin: stackoverflow.com
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
final int orientation = display.getOrientation();
// OR: orientation = getRequestedOrientation(); // inside an Activity
// set the screen orientation on button click
Button btn = (Button) findViewById(R.id.yourbutton);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
switch(orientation) {
case Configuration.ORIENTATION_PORTRAIT:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case Configuration.ORIENTATION_LANDSCAPE:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
}
}
});
代码示例来源:origin: stackoverflow.com
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display mDisplay = mWindowManager.getDefaultDisplay();
Log.d("ORIENTATION_TEST", "getOrientation(): " + mDisplay.getOrientation());
}
代码示例来源:origin: stackoverflow.com
if (display.getOrientation() == Surface.ROTATION_0) { // landscape oriented devices
if (orientation >= 315 || orientation < 45) {
if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) {
代码示例来源:origin: square/assertj-android
public DisplayAssert hasOrientation(@SurfaceRotation int orientation) {
isNotNull();
int actualOrientation = actual.getOrientation();
//noinspection ResourceType
assertThat(actualOrientation) //
.overridingErrorMessage("Expected orientation <%s> but was <%s>",
orientationToString(orientation), orientationToString(actualOrientation)) //
.isEqualTo(orientation);
return this;
}
代码示例来源:origin: square/assertj-android
public DisplayAssert isPortrait() {
isNotNull();
int actualOrientation = actual.getOrientation();
//noinspection ResourceType
assertThat(actualOrientation) //
.overridingErrorMessage("Expected orientation <%s> or <%s>, but was <%s>",
orientationToString(ROTATION_0), orientationToString(ROTATION_180),
orientationToString(actualOrientation)) //
.isIn(ROTATION_0, ROTATION_180);
return this;
}
代码示例来源:origin: square/assertj-android
public DisplayAssert isLandscape() {
isNotNull();
int actualOrientation = actual.getOrientation();
//noinspection ResourceType
assertThat(actualOrientation) //
.overridingErrorMessage("Expected orientation <%s> or <%s>, but was <%s>",
orientationToString(ROTATION_270), orientationToString(ROTATION_90),
orientationToString(actualOrientation)) //
.isIn(ROTATION_270, ROTATION_90);
return this;
}
代码示例来源:origin: robolectric/robolectric
/**
* The {@link android.view.Display#getOrientation()} method is deprecated, but for
* testing purposes, return the value gotten from {@link android.view.Display#getRotation()}
*/
@Test
public void deprecatedGetOrientation_returnsGetRotation() {
int testValue = 33;
shadow.setRotation(testValue);
assertEquals(testValue, display.getOrientation());
}
}
代码示例来源:origin: robolectric/robolectric
@Test @Config(minSdk = JELLY_BEAN_MR1)
public void changeDisplay_shouldAllowPartialChanges() throws Exception {
List<String> events = new ArrayList<>();
instance.registerDisplayListener(new MyDisplayListener(events), null);
int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp");
ShadowDisplayManager.changeDisplay(displayId, "+h201dp-land");
Display display = getGlobal().getRealDisplay(displayId);
assertThat(display.getWidth()).isEqualTo(201);
assertThat(display.getHeight()).isEqualTo(100);
assertThat(display.getOrientation()).isEqualTo(Surface.ROTATION_90);
assertThat(events).containsExactly(
"Added " + displayId,
"Changed " + displayId);
}
代码示例来源:origin: robolectric/robolectric
@Test @Config(minSdk = JELLY_BEAN_MR1)
public void changeAndRemoveDisplay_shouldNotifyListeners() throws Exception {
List<String> events = new ArrayList<>();
instance.registerDisplayListener(new MyDisplayListener(events), null);
int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp");
ShadowDisplayManager.changeDisplay(displayId, "w300dp-h400dp");
Display display = getGlobal().getRealDisplay(displayId);
assertThat(display.getWidth()).isEqualTo(300);
assertThat(display.getHeight()).isEqualTo(400);
assertThat(display.getOrientation()).isEqualTo(Surface.ROTATION_0);
ShadowDisplayManager.removeDisplay(displayId);
assertThat(events).containsExactly(
"Added " + displayId,
"Changed " + displayId,
"Removed " + displayId);
}
代码示例来源:origin: stackoverflow.com
System.out.println(rotation+"");
if (display.getOrientation() != Surface.ROTATION_0) { // landscape oriented devices
System.out.println("LANDSCAPE");
if (orientation >= 315 || orientation < 45) {
代码示例来源:origin: stackoverflow.com
Display myDisplay = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int rotation = myDisplay.getOrientation();
switch (rotation) {
case Surface.ROTATION_0: { doSomething(); break; }
case Surface.ROTATION_90: { doSomething(); break; }
case Surface.ROTATION_270: { doSomething(); break; }
case Surface.ROTATION_180: { doSomething(); break; }
}
代码示例来源:origin: stackoverflow.com
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
if(orientation == Configuration.ORIENTATION_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
if(orientation == Configuration.ORIENTATION_LANDSCAPE){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
代码示例来源:origin: stackoverflow.com
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
int orientation = display.getOrientation();
// use this to see on your console
System.out.println("Screen Size: " + orientation);
// use this to see on logcat
Log.v(TAG, "Screen Size:" + orientation);
代码示例来源:origin: stackoverflow.com
/* First, get the Display from the WindowManager */
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
/* Now we can retrieve all display-related infos */
int width = display.getWidth();
int height = display.getHeight();
int orientation = display.getOrientation();
代码示例来源:origin: com.squareup.assertj/assertj-android
public DisplayAssert hasOrientation(@SurfaceRotation int orientation) {
isNotNull();
int actualOrientation = actual.getOrientation();
//noinspection ResourceType
assertThat(actualOrientation) //
.overridingErrorMessage("Expected orientation <%s> but was <%s>",
orientationToString(orientation), orientationToString(actualOrientation)) //
.isEqualTo(orientation);
return this;
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public DisplayAssert isLandscape() {
isNotNull();
int actualOrientation = actual.getOrientation();
//noinspection ResourceType
assertThat(actualOrientation) //
.overridingErrorMessage("Expected orientation <%s> or <%s>, but was <%s>",
orientationToString(ROTATION_270), orientationToString(ROTATION_90),
orientationToString(actualOrientation)) //
.isIn(ROTATION_270, ROTATION_90);
return this;
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public DisplayAssert isPortrait() {
isNotNull();
int actualOrientation = actual.getOrientation();
//noinspection ResourceType
assertThat(actualOrientation) //
.overridingErrorMessage("Expected orientation <%s> or <%s>, but was <%s>",
orientationToString(ROTATION_0), orientationToString(ROTATION_180),
orientationToString(actualOrientation)) //
.isIn(ROTATION_0, ROTATION_180);
return this;
}
内容来源于网络,如有侵权,请联系作者删除!