java 位运算 优点_在写代码的过程中使用位运算的好处?

/*** Return a bit mask of the differences between this Configuration* object and the given one. Does not change the values of either. Any* undefined fields in delta are ignored.* @return Returns a bit mask indicating which configuration* values has changed, containing any combination of* {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE* PackageManager.ActivityInfo.CONFIG_FONT_SCALE},* {@link android.content.pm.ActivityInfo#CONFIG_MCC* PackageManager.ActivityInfo.CONFIG_MCC},* {@link android.content.pm.ActivityInfo#CONFIG_MNC* PackageManager.ActivityInfo.CONFIG_MNC},* {@link android.content.pm.ActivityInfo#CONFIG_LOCALE* PackageManager.ActivityInfo.CONFIG_LOCALE},* {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN* PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},* {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD* PackageManager.ActivityInfo.CONFIG_KEYBOARD},* {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION* PackageManager.ActivityInfo.CONFIG_NAVIGATION},* {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION* PackageManager.ActivityInfo.CONFIG_ORIENTATION},* {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT* PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or* {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE* PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or* {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE* PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}.* {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION* PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}.*/

public int diff(Configuration delta) {

int changed = 0;

if (delta.fontScale > 0 && fontScale != delta.fontScale) {

changed |= ActivityInfo.CONFIG_FONT_SCALE;

}

if (delta.mcc != 0 && mcc != delta.mcc) {

changed |= ActivityInfo.CONFIG_MCC;

}

if (delta.mnc != 0 && mnc != delta.mnc) {

changed |= ActivityInfo.CONFIG_MNC;

}

if (delta.locale != null

&& (locale == null || !locale.equals(delta.locale))) {

changed |= ActivityInfo.CONFIG_LOCALE;

changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;

}

final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;

if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED &&

deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {

changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;

}

if (delta.touchscreen != TOUCHSCREEN_UNDEFINED

&& touchscreen != delta.touchscreen) {

changed |= ActivityInfo.CONFIG_TOUCHSCREEN;

}

if (delta.keyboard != KEYBOARD_UNDEFINED

&& keyboard != delta.keyboard) {

changed |= ActivityInfo.CONFIG_KEYBOARD;

}

if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED

&& keyboardHidden != delta.keyboardHidden) {

changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;

}

if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED

&& hardKeyboardHidden != delta.hardKeyboardHidden) {

changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;

}

if (delta.navigation != NAVIGATION_UNDEFINED

&& navigation != delta.navigation) {

changed |= ActivityInfo.CONFIG_NAVIGATION;

}

if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED

&& navigationHidden != delta.navigationHidden) {

changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;

}

if (delta.orientation != ORIENTATION_UNDEFINED

&& orientation != delta.orientation) {

changed |= ActivityInfo.CONFIG_ORIENTATION;

}

if (getScreenLayoutNoDirection(delta.screenLayout) !=

(SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED)

&& getScreenLayoutNoDirection(screenLayout) !=

getScreenLayoutNoDirection(delta.screenLayout)) {

changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;

}

if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)

&& uiMode != delta.uiMode) {

changed |= ActivityInfo.CONFIG_UI_MODE;

}

if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED

&& screenWidthDp != delta.screenWidthDp) {

changed |= ActivityInfo.CONFIG_SCREEN_SIZE;

}

if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED

&& screenHeightDp != delta.screenHeightDp) {

changed |= ActivityInfo.CONFIG_SCREEN_SIZE;

}

if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED

&& smallestScreenWidthDp != delta.smallestScreenWidthDp) {

changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;

}

if (delta.densityDpi != DENSITY_DPI_UNDEFINED

&& densityDpi != delta.densityDpi) {

changed |= ActivityInfo.CONFIG_DENSITY;

}

return changed;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值