android.content.res.Resources#getConfiguration()源码实例Demo

下面列出了android.content.res.Resources#getConfiguration() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: iGap-Android   文件: G.java
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;
}
 
源代码2 项目: AndroidWallet   文件: LocalManageUtil.java
/**
 * 设置语言类型
 */
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);
}
 
源代码3 项目: SmartPack-Kernel-Manager   文件: BaseActivity.java
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);
}
 
源代码4 项目: UltimateAndroid   文件: BlurDialogEngine.java
/**
 * 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;
}
 
源代码5 项目: quill   文件: AppUtils.java
/**
 * 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);
}
 
源代码6 项目: AppOpsX   文件: LangHelper.java
@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);
}
 
源代码7 项目: deagle   文件: Locales.java
/**
 * 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;
}
 
源代码8 项目: smart-farmer-android   文件: LocalManageUtil.java
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;
}
 
源代码9 项目: DevUtils   文件: LanguageUtils.java
/**
 * 修改系统语言 ( 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;
}
 
源代码10 项目: NIM_Android_UIKit   文件: SystemBarTintManager.java
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;
}
 
源代码11 项目: ScreenshotsNanny   文件: LanguageSwitcher.java
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());
    }
}
 
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;
}
 
源代码13 项目: mvvm-template   文件: AppHelper.java
@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());
}
 
源代码14 项目: SuntimesWidget   文件: AppSettings.java
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);
    }
}
 
源代码15 项目: quickmark   文件: SystemBarTintManager.java
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;
}
 
源代码16 项目: Tangram-Android   文件: TangramViewMetrics.java
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;
    }
 
源代码17 项目: android_9.0.0_r45   文件: DateSorter.java
/**
 * @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);
}
 
源代码18 项目: LanguageTest   文件: LocaleManager.java
public static Locale getLocale(Resources res) {
    Configuration config = res.getConfiguration();
    return Utility.isAtLeastVersion(N) ? config.getLocales().get(0) : config.locale;
}
 
源代码19 项目: dingo   文件: FloatingView.java
/**
 * コンストラクタ
 *
 * @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);
}
 
源代码20 项目: kolabnotes-android   文件: Utils.java
public static boolean isTablet(Resources res){
        return (res.getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}