Java Code Examples for android.content.res.Resources#getConfiguration()
The following examples show how to use
android.content.res.Resources#getConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: G.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
public static Context updateResources(Context baseContext) { if (G.selectedLanguage == null) { G.selectedLanguage = Locale.getDefault().getLanguage(); } Locale locale = new Locale(G.selectedLanguage); Locale.setDefault(locale); Resources res = baseContext.getResources(); Configuration configuration = res.getConfiguration(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { configuration.setLocale(locale); } else { configuration.locale = locale; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { baseContext = baseContext.createConfigurationContext(configuration); } else { res.updateConfiguration(configuration, res.getDisplayMetrics()); } G.context = baseContext; return baseContext; }
Example 2
Source File: LocalManageUtil.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
/** * 设置语言类型 */ public static void setApplicationLanguage(Context context) { Resources resources = context.getApplicationContext().getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); Configuration config = resources.getConfiguration(); Locale locale = getSetLanguageLocale(context); config.locale = locale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { LocaleList localeList = new LocaleList(locale); LocaleList.setDefault(localeList); config.setLocales(localeList); context.getApplicationContext().createConfigurationContext(config); Locale.setDefault(locale); } resources.updateConfiguration(config, dm); }
Example 3
Source File: DateSorter.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @param context Application context */ public DateSorter(Context context) { Resources resources = context.getResources(); Calendar c = Calendar.getInstance(); beginningOfDay(c); // Create the bins mBins[0] = c.getTimeInMillis(); // Today c.add(Calendar.DAY_OF_YEAR, -1); mBins[1] = c.getTimeInMillis(); // Yesterday c.add(Calendar.DAY_OF_YEAR, -(NUM_DAYS_AGO - 1)); mBins[2] = c.getTimeInMillis(); // Five days ago c.add(Calendar.DAY_OF_YEAR, NUM_DAYS_AGO); // move back to today c.add(Calendar.MONTH, -1); mBins[3] = c.getTimeInMillis(); // One month ago // build labels Locale locale = resources.getConfiguration().locale; if (locale == null) { locale = Locale.getDefault(); } LocaleData localeData = LocaleData.get(locale); mLabels[0] = localeData.today; mLabels[1] = localeData.yesterday; int resId = com.android.internal.R.plurals.last_num_days; String format = resources.getQuantityString(resId, NUM_DAYS_AGO); mLabels[2] = String.format(format, NUM_DAYS_AGO); mLabels[3] = context.getString(com.android.internal.R.string.last_month); mLabels[4] = context.getString(com.android.internal.R.string.older); }
Example 4
Source File: BaseActivity.java From SmartPack-Kernel-Manager with GNU General Public License v3.0 | 5 votes |
public static ContextWrapper wrap(Context context, Locale newLocale) { Resources res = context.getResources(); Configuration configuration = res.getConfiguration(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { configuration.setLocale(newLocale); LocaleList localeList = new LocaleList(newLocale); LocaleList.setDefault(localeList); configuration.setLocales(localeList); context = context.createConfigurationContext(configuration); } else { configuration.setLocale(newLocale); context = context.createConfigurationContext(configuration); } return new ContextWrapper(context); }
Example 5
Source File: TangramViewMetrics.java From Tangram-Android with MIT License | 5 votes |
public static void initWith(@NonNull final Context context) { final Resources resources = context.getResources(); final DisplayMetrics dm = resources.getDisplayMetrics(); mDensity = dm.density; final Configuration configuration = resources.getConfiguration(); mScreenWidth = configuration.orientation == Configuration.ORIENTATION_PORTRAIT ? dm.widthPixels : dm.heightPixels; mScreenHeight = configuration.orientation == Configuration.ORIENTATION_PORTRAIT ? dm.heightPixels : dm.widthPixels; }
Example 6
Source File: SystemBarTintManager.java From quickmark with MIT License | 5 votes |
private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { Resources res = activity.getResources(); mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); mSmallestWidthDp = getSmallestWidthDp(activity); mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); mActionBarHeight = getActionBarHeight(activity); mNavigationBarHeight = getNavigationBarHeight(activity); mNavigationBarWidth = getNavigationBarWidth(activity); mHasNavigationBar = (mNavigationBarHeight > 0); mTranslucentStatusBar = translucentStatusBar; mTranslucentNavBar = traslucentNavBar; }
Example 7
Source File: AppSettings.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
public static Context loadLocale( Context context, String languageTag ) { if (systemLocale == null) { systemLocale = Locale.getDefault().getLanguage(); } Locale customLocale = localeForLanguageTag(languageTag); Locale.setDefault(customLocale); Log.i("loadLocale", languageTag); Resources resources = context.getApplicationContext().getResources(); Configuration config = resources.getConfiguration(); if (Build.VERSION.SDK_INT >= 17) config.setLocale(customLocale); else config.locale = customLocale; if (Build.VERSION.SDK_INT >= 25) { return new ContextWrapper(context.createConfigurationContext(config)); } else { DisplayMetrics metrics = resources.getDisplayMetrics(); //noinspection deprecation resources.updateConfiguration(config, metrics); return new ContextWrapper(context); } }
Example 8
Source File: AppHelper.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private static void updateResourcesLegacy(Context context, String language) { Locale locale = getLocale(language); Locale.setDefault(locale); Resources resources = context.getResources(); Configuration configuration = resources.getConfiguration(); configuration.locale = locale; resources.updateConfiguration(configuration, resources.getDisplayMetrics()); }
Example 9
Source File: SystemBarTintManager.java From AyoActivityNoManifest with Apache License 2.0 | 5 votes |
private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { Resources res = activity.getResources(); mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); mSmallestWidthDp = getSmallestWidthDp(activity); mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); mActionBarHeight = getActionBarHeight(activity); mNavigationBarHeight = getNavigationBarHeight(activity); mNavigationBarWidth = getNavigationBarWidth(activity); mHasNavigationBar = (mNavigationBarHeight > 0); mTranslucentStatusBar = translucentStatusBar; mTranslucentNavBar = traslucentNavBar; }
Example 10
Source File: LanguageSwitcher.java From ScreenshotsNanny with MIT License | 5 votes |
public static void change(Context context, String language) { if (context != null) { Resources resources = context.getResources(); DisplayMetrics displayMetrics = resources.getDisplayMetrics(); Configuration configuration = resources.getConfiguration(); configuration.locale = new Locale(language.toLowerCase()); resources.updateConfiguration(configuration, displayMetrics); Log.i(LOG_TAG, "⚙ Language is set to: " + language.toUpperCase()); } }
Example 11
Source File: SystemBarTintManager.java From NIM_Android_UIKit with MIT License | 5 votes |
private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { Resources res = activity.getResources(); mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); mSmallestWidthDp = getSmallestWidthDp(activity); mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); mActionBarHeight = getActionBarHeight(activity); mNavigationBarHeight = getNavigationBarHeight(activity); mNavigationBarWidth = getNavigationBarWidth(activity); mHasNavigationBar = (mNavigationBarHeight > 0); mTranslucentStatusBar = translucentStatusBar; mTranslucentNavBar = traslucentNavBar; }
Example 12
Source File: LanguageUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 修改系统语言 ( APP 多语言, 单独改变 APP 语言 ) * @param context {@link Context} - Activity * @param locale {@link Locale} * @return {@code true} success, {@code false} fail */ public static boolean applyLanguage(final Context context, final Locale locale) { if (context != null && locale != null) { try { // 获取 res 资源对象 Resources resources = context.getResources(); // 获取设置对象 Configuration config = resources.getConfiguration(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // apply locale config.setLocale(locale); context.createConfigurationContext(config); } else { // updateConfiguration // 获取屏幕参数: 主要是分辨率, 像素等 DisplayMetrics displayMetrics = resources.getDisplayMetrics(); config.locale = locale; // 更新语言 resources.updateConfiguration(config, displayMetrics); } return true; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "applyLanguage"); } } return false; }
Example 13
Source File: LocalManageUtil.java From smart-farmer-android with Apache License 2.0 | 5 votes |
private static Context updateResources(Context context, Locale locale) { Locale.setDefault(locale); Resources res = context.getResources(); Configuration config = new Configuration(res.getConfiguration()); config.setLocale(locale); context = context.createConfigurationContext(config); return context; }
Example 14
Source File: Locales.java From deagle with Apache License 2.0 | 5 votes |
/** * Switch the locale of current app to explicitly specified or default one * * @param locale null for default */ public static boolean switchTo(final Context context, final Locale locale) { final Resources resources = context.getResources(); final Configuration configuration = resources.getConfiguration(); if (match(locale, configuration.locale)) return false; setConfigurationLocale(configuration, locale); resources.updateConfiguration(configuration, null); return true; }
Example 15
Source File: LangHelper.java From AppOpsX with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.N) private static Context updateResources(Context context) { Resources resources = context.getResources(); Locale locale = getLocaleByLanguage(context); Configuration configuration = resources.getConfiguration(); configuration.setLocale(locale); configuration.setLocales(new LocaleList(locale)); return context.createConfigurationContext(configuration); }
Example 16
Source File: AppUtils.java From quill with MIT License | 5 votes |
/** * Set the app to use the given locale. Useful for testing translations. This is normally * not needed because the device locale is applied automatically. * @param context - context from which to get resources * @param locale - the locale to use */ public static void setLocale(@NonNull Context context, @NonNull Locale locale) { Locale.setDefault(locale); Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = Locale.getDefault(); res.updateConfiguration(conf, dm); }
Example 17
Source File: BlurDialogEngine.java From UltimateAndroid with Apache License 2.0 | 5 votes |
/** * Retrieve offset introduce by the navigation bar. * * @return bottom offset due to navigation bar. */ private int getNavigationBarOffset() { int result = 0; Resources resources = mHoldingActivity.getResources(); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP && resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { result = resources.getDimensionPixelSize(resourceId); } } return result; }
Example 18
Source File: Utils.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean isTablet(Resources res){ return (res.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; }
Example 19
Source File: FloatingView.java From dingo with GNU General Public License v3.0 | 4 votes |
/** * コンストラクタ * * @param context {@link Context} */ FloatingView(final Context context) { super(context); mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mParams = new WindowManager.LayoutParams(); mMetrics = new DisplayMetrics(); mWindowManager.getDefaultDisplay().getMetrics(mMetrics); //mParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; mParams.width = (int)(mMetrics.widthPixels * (2/3.f)); mParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; mParams.type = OVERLAY_TYPE; mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; mParams.format = PixelFormat.TRANSLUCENT; // 左下の座標を0とする mParams.gravity = Gravity.LEFT | Gravity.BOTTOM; if (Build.VERSION.SDK_INT >= 26) { mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; } else { mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; } mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; mAnimationHandler = new FloatingAnimationHandler(this); mLongPressHandler = new LongPressHandler(this); mMoveEdgeInterpolator = new OvershootInterpolator(MOVE_TO_EDGE_OVERSHOOT_TENSION); mMoveDirection = FloatingViewManager.MOVE_DIRECTION_DEFAULT; mUsePhysics = false; final Resources resources = context.getResources(); mIsTablet = (resources.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; mRotation = mWindowManager.getDefaultDisplay().getRotation(); mMoveLimitRect = new Rect(); mPositionLimitRect = new Rect(); mSafeInsetRect = new Rect(); // ステータスバーの高さを取得 mBaseStatusBarHeight = getSystemUiDimensionPixelSize(resources, "status_bar_height"); // Check landscape resource id final int statusBarLandscapeResId = resources.getIdentifier("status_bar_height_landscape", "dimen", "android"); if (statusBarLandscapeResId > 0) { mBaseStatusBarRotatedHeight = getSystemUiDimensionPixelSize(resources, "status_bar_height_landscape"); } else { mBaseStatusBarRotatedHeight = mBaseStatusBarHeight; } // Init physics-based animation properties updateViewConfiguration(); // Detect NavigationBar if (hasSoftNavigationBar()) { mBaseNavigationBarHeight = getSystemUiDimensionPixelSize(resources, "navigation_bar_height"); final String resName = mIsTablet ? "navigation_bar_height_landscape" : "navigation_bar_width"; mBaseNavigationBarRotatedHeight = getSystemUiDimensionPixelSize(resources, resName); } else { mBaseNavigationBarHeight = 0; mBaseNavigationBarRotatedHeight = 0; } mInitialViewWidth = mParams.width; // Create an instance of OnPinchListner custom class. OnPinchListener onPinchListener = new OnPinchListener(getContext(), this); // Create the new scale gesture detector object use above pinch zoom gesture listener. scaleGestureDetector = new ScaleGestureDetector(getContext(), onPinchListener); // 初回描画処理用 getViewTreeObserver().addOnPreDrawListener(this); }
Example 20
Source File: LocaleManager.java From LanguageTest with MIT License | 4 votes |
public static Locale getLocale(Resources res) { Configuration config = res.getConfiguration(); return Utility.isAtLeastVersion(N) ? config.getLocales().get(0) : config.locale; }