下面列出了android.content.res.Configuration#SCREENLAYOUT_SIZE_LARGE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static String getScreenSizeAsString(Context context) {
String size = null;
int screenLayout = context.getResources().getConfiguration().screenLayout;
if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
size = "large";
}
if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
size = "xlarge";
}
if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
size = "normal";
}
if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
size = "small";
}
if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
size = "undefined";
}
return size;
}
private static int getNavBarHeight(Context context) {
boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasNavBar = !hasMenuKey && !hasBackKey;
if (hasNavBar) {
boolean isPortrait = context.getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT;
boolean isTablet = (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
String key = isPortrait ? "navigation_bar_height"
: (isTablet ? "navigation_bar_height_landscape" : null);
return key == null ? 0 : getDimenSize(context, key);
} else {
return 0;
}
}
public void initialize(YoukuBasePlayerManager mYoukuBaseActivity) {
PackageManager pm = mYoukuBaseActivity.getBaseActivity()
.getPackageManager();
String ver = "4.1";
try {
ver = pm.getPackageInfo(mYoukuBaseActivity.getBaseActivity()
.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean isTablet = (this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
String ua = (isTablet ? "Youku HD;" : "Youku;") + ver + ";Android;"
+ android.os.Build.VERSION.RELEASE + ";"
+ android.os.Build.MODEL;
Logger.d(TAG, "initialize(): ua = " + ua);
initialize(mYoukuBaseActivity, 10001, "4e308edfc33936d7", ver, ua,
false, -7L, "631l1i1x3fv5vs2dxlj5v8x81jqfs2om");
}
static int getNavBarHeight(Context c) {
int result = 0;
boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
if (!hasMenuKey && !hasBackKey) {
// The device has a navigation bar
final Resources res = c.getResources();
final Configuration config = res.getConfiguration();
int orientation = config.orientation;
int resourceId;
// Check if the device is a tablet
if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE) {
resourceId = res.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT
? "navigation_bar_height" : "navigation_bar_height_landscape",
"dimen", "android");
} else {
resourceId = res.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT
? "navigation_bar_height" : "navigation_bar_width",
"dimen", "android");
}
if (resourceId > 0) {
return res.getDimensionPixelSize(resourceId);
}
}
return result;
}
public static boolean isLargeScreen(Context context) {
return getScreenSize(context) == Configuration.SCREENLAYOUT_SIZE_LARGE ||
getScreenSize(context) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
private static boolean isTabletInner(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >=
Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
/**
* Modify various attributes of the SuperToast before being shown.
*/
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
protected void onPrepareShow() {
final int sdkVersion = android.os.Build.VERSION.SDK_INT;
// Modify various attributes of the message TextView
this.mTextView.setText(this.mStyle.message);
this.mTextView.setTypeface(this.mTextView.getTypeface(), this.mStyle.messageTypefaceStyle);
this.mTextView.setTextColor(this.mStyle.messageTextColor);
this.mTextView.setTextSize(this.mStyle.messageTextSize);
if (this.mStyle.messageIconResource > 0) {
if (this.mStyle.messageIconPosition == Style.ICONPOSITION_LEFT) {
this.mTextView.setCompoundDrawablesWithIntrinsicBounds(
this.mStyle.messageIconResource, 0, 0, 0);
} else if (this.mStyle.messageIconPosition == Style.ICONPOSITION_TOP) {
this.mTextView.setCompoundDrawablesWithIntrinsicBounds(
0, this.mStyle.messageIconResource, 0, 0);
} else if (this.mStyle.messageIconPosition == Style.ICONPOSITION_RIGHT) {
this.mTextView.setCompoundDrawablesWithIntrinsicBounds(
0, 0, this.mStyle.messageIconResource, 0);
} else if (this.mStyle.messageIconPosition == Style.ICONPOSITION_BOTTOM) {
this.mTextView.setCompoundDrawablesWithIntrinsicBounds(
0, 0, 0, this.mStyle.messageIconResource);
}
}
// Handle depreciated API for setting the background
if (sdkVersion >= Build.VERSION_CODES.JELLY_BEAN) {
this.mView.setBackground(BackgroundUtils.getBackground(this.mStyle, this.mStyle.color));
// Give Lollipop devices a nice shadow (does not work with transparent backgrounds)
if (sdkVersion >= Build.VERSION_CODES.LOLLIPOP) mView.setElevation(3f);
} else this.mView.setBackgroundDrawable(BackgroundUtils.getBackground(this.mStyle, this.mStyle.color));
// Make adjustments that are specific to Lollipop frames
if (this.mStyle.frame == Style.FRAME_LOLLIPOP) {
this.mTextView.setGravity(Gravity.START);
// We are on a big screen device, show the SuperToast on the bottom left with padding
if ((this.mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE) {
this.mStyle.xOffset = BackgroundUtils.convertToDIP(12);
this.mStyle.yOffset = BackgroundUtils.convertToDIP(12);
this.mStyle.width = BackgroundUtils.convertToDIP(288);
this.mStyle.gravity = Gravity.BOTTOM | Gravity.START;
// Simple background shape with rounded corners
final GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setCornerRadius(BackgroundUtils.convertToDIP(2));
gradientDrawable.setColor(this.mStyle.color);
// Handle depreciated API for setting the background
if (sdkVersion >= Build.VERSION_CODES.JELLY_BEAN) this.mView.setBackground(gradientDrawable);
else this.mView.setBackgroundDrawable(gradientDrawable);
// We are NOT on a big screen device, show the SuperToast on the bottom with NO padding
} else {
this.mStyle.yOffset = 0;
this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT;
}
// Set the priority color of the Lollipop frame if any
if (this.mStyle.priorityColor != 0) {
mView.findViewById(R.id.border).setVisibility(View.VISIBLE);
mView.findViewById(R.id.border).setBackgroundColor(this.mStyle.priorityColor);
}
}
// Used for PriorityQueue comparisons
this.getStyle().timestamp = System.currentTimeMillis();
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
static public boolean isLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
@SuppressLint({"SetJavaScriptEnabled", "ShowToast", "ClickableViewAccessibility"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Don't show an action bar or title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Enable hardware acceleration
getWindow().setFlags(LayoutParams.FLAG_HARDWARE_ACCELERATED,
LayoutParams.FLAG_HARDWARE_ACCELERATED);
// Apply previous setting about showing status bar or not
applyFullScreen(isFullScreen());
// Check if screen rotation is locked in settings
boolean isOrientationEnabled = false;
try {
isOrientationEnabled = Settings.System.getInt(getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION) == 1;
} catch (SettingNotFoundException e) {
Log.d(MAIN_ACTIVITY_TAG, "Settings could not be loaded");
}
// If rotation isn't locked and it's a LARGE screen then add orientation changes based on sensor
int screenLayout = getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK;
if (((screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE)
|| (screenLayout == Configuration.SCREENLAYOUT_SIZE_XLARGE))
&& isOrientationEnabled) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
setContentView(R.layout.activity_main);
DialogChangeLog changeLog = DialogChangeLog.newInstance(this);
if (changeLog.isFirstRun()) {
changeLog.getLogDialog().show();
}
// Load webview with game
mWebView = findViewById(R.id.mainWebView);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setDatabasePath(getFilesDir().getParentFile().getPath() + "/databases");
// If there is a previous instance restore it in the webview
if (savedInstanceState != null) {
mWebView.restoreState(savedInstanceState);
} else {
// Load webview with current Locale language
mWebView.loadUrl("file:///android_asset/2048/index.html?lang=" + Locale.getDefault().getLanguage());
}
Toast.makeText(getApplication(), R.string.toggle_fullscreen, Toast.LENGTH_SHORT).show();
// Set fullscreen toggle on webview LongClick
mWebView.setOnTouchListener((v, event) -> {
// Implement a long touch action by comparing
// time between action up and action down
long currentTime = System.currentTimeMillis();
if ((event.getAction() == MotionEvent.ACTION_UP)
&& (Math.abs(currentTime - mLastTouch) > mTouchThreshold)) {
boolean toggledFullScreen = !isFullScreen();
saveFullScreen(toggledFullScreen);
applyFullScreen(toggledFullScreen);
} else if (event.getAction() == MotionEvent.ACTION_DOWN) {
mLastTouch = currentTime;
}
// return so that the event isn't consumed but used
// by the webview as well
return false;
});
pressBackToast = Toast.makeText(getApplicationContext(), R.string.press_back_again_to_exit,
Toast.LENGTH_SHORT);
}
private static boolean isTablet(@NonNull Resources resources) {
return (resources.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isPad(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
/**
* Return whether device is tablet.
*
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isTablet() {
return (Resources.getSystem().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isTablet(Context context){
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
/**
* 判断是否是平板
* 这个方法是从 Google I/O App for Android 的源码里找来的,非常准确。
* @param context
* @return
*/
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}