下面列出了android.content.res.Configuration#ORIENTATION_SQUARE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int getScreenOrientation(Context context)
{
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if(display.getWidth()==display.getHeight()){
orientation = Configuration.ORIENTATION_SQUARE;
} else{
if(display.getWidth() < display.getHeight()){
orientation = Configuration.ORIENTATION_PORTRAIT;
}else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}
public static int getScreenOrientation(Context context)
{
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if(display.getWidth()==display.getHeight()){
orientation = Configuration.ORIENTATION_SQUARE;
} else{
if(display.getWidth() < display.getHeight()){
orientation = Configuration.ORIENTATION_PORTRAIT;
}else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}
public void prepareRecog(){
strokeMgr = StrokeMgr.instance();
Configuration config = mContext.getResources().getConfiguration();
if(config.orientation == Configuration.ORIENTATION_PORTRAIT
|| config.orientation == Configuration.ORIENTATION_SQUARE){
currSplitMode = com.sinovoice.hcicloudsdk.api.hwr.HciCloudHwr.HCI_HWR_SPLIT_MODE_OVERLAP;
}else if(config.orientation == Configuration.ORIENTATION_LANDSCAPE){
currSplitMode = com.sinovoice.hcicloudsdk.api.hwr.HciCloudHwr.HCI_HWR_SPLIT_MODE_LINE;
}else{
currSplitMode = com.sinovoice.hcicloudsdk.api.hwr.HciCloudHwr.HCI_HWR_SPLIT_MODE_OVERLAP;
}
lastSpliteMode = currSplitMode;
recogThread = new HwrRecogThread();
recogThread.start();
mIsInited = true;
}
/**
* Get the device's current screen orientation.
*
* @return the device's current screen orientation, or null if unknown
*/
@SuppressWarnings("deprecation")
public static @Nullable Device.DeviceOrientation getOrientation(int orientation) {
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
return Device.DeviceOrientation.LANDSCAPE;
case Configuration.ORIENTATION_PORTRAIT:
return Device.DeviceOrientation.PORTRAIT;
case Configuration.ORIENTATION_SQUARE:
case Configuration.ORIENTATION_UNDEFINED:
default:
return null;
}
}
public int getScreenOrientation() {
int width = getScreenWidthPixels();
int height = getScreenHeightPixels();
if (width > height) {
Log.v(MyUtil.PACKAGE_NAME, "ORIENTATION_LANDSCAPE");
return Configuration.ORIENTATION_LANDSCAPE;
}
if (width < height) {
Log.v(MyUtil.PACKAGE_NAME, "ORIENTATION_PORTRAIT");
return Configuration.ORIENTATION_PORTRAIT;
}
Log.v(MyUtil.PACKAGE_NAME, "ORIENTATION_SQUARE");
return Configuration.ORIENTATION_SQUARE;
}
/**
* Reliably get orientation. Return values are one of
* Configuration.ORIENTATION_XXXXX
*
* @return
*/
public int getScreenOrientation(Activity context) {
Display getOrient = context.getWindowManager().getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if (getOrient.getWidth() == getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_SQUARE;
} else {
if (getOrient.getWidth() < getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_PORTRAIT;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}