本文整理汇总了Java中android.content.res.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于android.content.res包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkScreenSize
import android.content.res.Configuration; //导入依赖的package包/类
public void checkScreenSize() {
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch (screenSize) {
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
column_no = 4;
break;
case Configuration.SCREENLAYOUT_SIZE_UNDEFINED:
column_no = 3;
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
column_no = 3;
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
column_no = 2;
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
column_no = 2;
break;
default:
column_no = 2;
}
}
示例2: onConfigurationChanged
import android.content.res.Configuration; //导入依赖的package包/类
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//当屏幕变为横屏时
if (isLandscape()) {
//设置为全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
mControlLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
mRoomInfoLayout.setVisibility(View.GONE);
mFullScreen.setVisibility(View.GONE);
mDanmakuView.show();
isShowDanmu = true;
} else {
//退出全屏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
mRoomInfoLayout.setVisibility(View.VISIBLE);
mFullScreen.setVisibility(View.VISIBLE);
mDanmakuView.hide();
isShowDanmu = false;
}
updateVideoLayoutParams();
}
示例3: adjustFullScreen
import android.content.res.Configuration; //导入依赖的package包/类
/**
* Adjusts immersive full-screen flags depending on the screen orientation.
*
* @param config The current {@link Configuration}.
*/
private void adjustFullScreen(Configuration config) {
final View decorView = getWindow().getDecorView();
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
mScrollView.setVisibility(View.GONE);
mMovieView.setAdjustViewBounds(false);
} else {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
mScrollView.setVisibility(View.VISIBLE);
mMovieView.setAdjustViewBounds(true);
}
}
示例4: resetRecyclerViewPadding
import android.content.res.Configuration; //导入依赖的package包/类
private void resetRecyclerViewPadding(int orientation) {
if (mRecyclerView == null) return;
int padding = 0;
int navBar = 0;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
padding = getActivity().getResources().getDimensionPixelSize(R.dimen.content_padding);
navBar = padding;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
boolean tabletMode = getResources().getBoolean(R.bool.android_helpers_tablet_mode);
if (tabletMode || orientation == Configuration.ORIENTATION_PORTRAIT) {
navBar = WindowHelper.getNavigationBarHeight(getActivity());
}
}
mRecyclerView.setPadding(padding, padding, 0, navBar);
}
示例5: detectLanguage
import android.content.res.Configuration; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static void detectLanguage(Context context) {
SharedPreferences setting = PreferenceManager
.getDefaultSharedPreferences(context);
String language = setting.getString(Util.PREF_LANGUAGE, "auto");
Resources res = context.getResources();
Configuration conf = res.getConfiguration();
switch (language) {
case "en":
case "zh":
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
conf.setLocale(new Locale(language));
} else {
conf.locale = new Locale(language);
}
break;
default:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
conf.setLocale(Resources.getSystem().getConfiguration().getLocales().get(0));
} else {
conf.locale = Resources.getSystem().getConfiguration().locale;
}
}
DisplayMetrics dm = res.getDisplayMetrics();
res.updateConfiguration(conf, dm);
}
示例6: simulateDayNight
import android.content.res.Configuration; //导入依赖的package包/类
void simulateDayNight(int currentSetting) {
final int DAY = 0;
final int NIGHT = 1;
final int FOLLOW_SYSTEM = 3;
int currentNightMode = getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK;
if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO);
} else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
} else if (currentSetting == FOLLOW_SYSTEM) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
}
示例7: onCreate
import android.content.res.Configuration; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Resources resources = getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
Configuration config = resources.getConfiguration();
// 应用用户选择语言
String language = SPUtil.getInstance(this).getLanguage();
if ("".equals(language)){
language =Locale.getDefault().getLanguage();
}
if (language.equals(SPUtil.LANGUAGE_CHINESE)) {
config.setLocale(Locale.getDefault());
} else {
config.setLocale(Locale.ENGLISH);
}
resources.updateConfiguration(config, dm);
mContext=getApplicationContext();
}
示例8: PopulateDetailsPoster
import android.content.res.Configuration; //导入依赖的package包/类
/**
* Populates poster in screen.
* @param container TVShowData
* @param callback callback
*/
private void PopulateDetailsPoster(final TVShowData container, Callback callback) {
ActivityUtils.loadImage(this, TMDB_IMAGE_URL + SIZE_W342 + container.getPosterPath(), true,
R.drawable.disk_reel, tvShowPoster, null);
String backgroundPosterPath = container.getBackgroundPath();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
ActivityUtils.loadImage(this, BACKGROUND_BASE_URI + backgroundPosterPath, true,
R.drawable.no_background_poster, backgroundPoster, callback);
} else {
ActivityUtils.loadImage(this, BACKGROUND_BASE_URI + backgroundPosterPath, false,
R.drawable.no_background_poster, backgroundPoster, callback);
}
// Save background movie image poster to use in PersonProfile page.
ActivityUtils.saveStringToPreferences(this, KNOWN_FOR_BACKGROUND_POSTER,
container.getBackgroundPath());
}
示例9: applyGravity
import android.content.res.Configuration; //导入依赖的package包/类
/**
* apply the gravity for window params.
*
* @param expectGravity the expect gravity
* @param applyWlp the window layout params.
*/
private static void applyGravity(Context context,int expectGravity, WindowManager.LayoutParams applyWlp) {
if (Build.VERSION.SDK_INT >= 17) {
final Configuration configuration = context.getResources().getConfiguration();
final int gravity = Gravity.getAbsoluteGravity(expectGravity, configuration.getLayoutDirection());
applyWlp.gravity = gravity;
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
applyWlp.horizontalWeight = 1.0f;
}
if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
applyWlp.verticalWeight = 1.0f;
}
} else {
applyWlp.gravity = expectGravity;
}
}
示例10: onConfigurationChanged
import android.content.res.Configuration; //导入依赖的package包/类
/**
* We need to do locale work here, because we need to intercept
* each hit to onConfigurationChanged.
*/
@Override
public void onConfigurationChanged(Configuration config) {
// Do nothing if we're in the background. It'll simply cause a loop
// (Bug 936756 Comment 11), and it's not necessary.
if (mInBackground) {
super.onConfigurationChanged(config);
return;
}
// Otherwise, correct the locale. This catches some cases that the current Activity
// doesn't get a chance to.
try {
LocaleManager.getInstance().correctLocale(this, getResources(), config);
} catch (IllegalStateException ex) {
// Activity hasn't started yey, so we have no ContextGetter in LocaleManager.
}
super.onConfigurationChanged(config);
}
示例11: getNavBarHeight
import android.content.res.Configuration; //导入依赖的package包/类
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
Resources res = c.getResources();
int orientation = res.getConfiguration().orientation;
int resourceId;
if (isTablet(c)) {
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;
}
示例12: setFullScreenForSmallLandscape
import android.content.res.Configuration; //导入依赖的package包/类
protected void setFullScreenForSmallLandscape() {
int nScreenSizeCategory = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
int nScreenOrientation = getResources().getConfiguration().orientation;
if (nScreenOrientation != Configuration.ORIENTATION_LANDSCAPE) {
if (nScreenSizeCategory == Configuration.SCREENLAYOUT_SIZE_SMALL) { // making it full screen in portrait mode if small screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
} else {
if (nScreenSizeCategory == Configuration.SCREENLAYOUT_SIZE_SMALL
|| nScreenSizeCategory == Configuration.SCREENLAYOUT_SIZE_NORMAL) { // making it full screen in landscape mode if small or normal screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
}
示例13: onUpdate
import android.content.res.Configuration; //导入依赖的package包/类
/**
* Function fire on system update widget
*
* @param context Context of application
* @param appWidgetManager App widget manger
* @param appWidgetIds Widget system ids
*/
@Override
public void onUpdate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int count = appWidgetIds.length;
//set widget language with the system language
Locale locale = new Locale(Resources.getSystem().getConfiguration().locale.getLanguage());
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
this.context = context;
//loop in all widgets
for (int i = 0; i < count; i++) {
svcIntent = new Intent(context, CalenderRemoteViewsService.class);
final int widgetId = appWidgetIds[i];
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_calender);
remoteViews.setRemoteAdapter(R.id.calendar_pager, svcIntent);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.calendar_pager);
HGDate hgDate = new HGDate();
hgDate.toHigri();
remoteViews.setTextViewText(R.id.textView8, Dates.getCurrentWeekDay());
remoteViews.setTextViewText(R.id.textView7, NumbersLocal.convertToNumberTypeSystem(context, hgDate.getDay() + ""));
remoteViews.setTextViewText(R.id.textView24, NumbersLocal.convertToNumberTypeSystem(context, hgDate.getYear() + ""));
remoteViews.setTextViewText(R.id.curr_month_txt, Dates.islamicMonthName(context, hgDate.getMonth() - 1));
remoteViews.setTextViewText(R.id.curr_month_txt_other, showOtherMonth(hgDate));
PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
remoteViews.setOnClickPendingIntent(R.id.relativeLayout, configPendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}
示例14: resetViewBottomPadding
import android.content.res.Configuration; //导入依赖的package包/类
public static void resetViewBottomPadding(@Nullable View view, boolean scroll) {
if (view == null) return;
Context context = ContextHelper.getBaseContext(view);
int orientation = context.getResources().getConfiguration().orientation;
int left = view.getPaddingLeft();
int right = view.getPaddingRight();
int bottom = view.getPaddingTop();
int top = view.getPaddingTop();
int navBar = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
boolean tabletMode = context.getResources().getBoolean(R.bool.android_helpers_tablet_mode);
if (tabletMode || orientation == Configuration.ORIENTATION_PORTRAIT) {
navBar = getNavigationBarHeight(context);
}
if (!scroll) {
navBar += getStatusBarHeight(context);
}
}
if (!scroll) {
navBar += getToolbarHeight(context);
}
view.setPadding(left, top, right, (bottom + navBar));
}
示例15: drawResizedBitmap
import android.content.res.Configuration; //导入依赖的package包/类
private void drawResizedBitmap(final Bitmap src, final Bitmap dst) {
Display getOrient = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
Point point = new Point();
getOrient.getSize(point);
int screen_width = point.x;
int screen_height = point.y;
Log.d(TAG, String.format("screen size (%d,%d)", screen_width, screen_height));
if (screen_width < screen_height) {
orientation = Configuration.ORIENTATION_PORTRAIT;
mScreenRotation = -90;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
mScreenRotation = 0;
}
Assert.assertEquals(dst.getWidth(), dst.getHeight());
final float minDim = Math.min(src.getWidth(), src.getHeight());
final Matrix matrix = new Matrix();
// We only want the center square out of the original rectangle.
final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
matrix.preTranslate(translateX, translateY);
final float scaleFactor = dst.getHeight() / minDim;
matrix.postScale(scaleFactor, scaleFactor);
// Rotate around the center if necessary.
if (mScreenRotation != 0) {
matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
matrix.postRotate(mScreenRotation);
matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
}
final Canvas canvas = new Canvas(dst);
canvas.drawBitmap(src, matrix, null);
}