本文整理匯總了Java中android.content.res.Resources.getConfiguration方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getConfiguration方法的具體用法?Java Resources.getConfiguration怎麽用?Java Resources.getConfiguration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getConfiguration方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyLocale
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void applyLocale() {
Context context = getContext();
final LocaleManager localeManager = LocaleManager.getInstance();
if (!localeManager.isMirroringSystemLocale(context)) {
final Locale currentLocale = localeManager.getCurrentLocale(context);
Locale.setDefault(currentLocale);
final Resources resources = context.getResources();
final Configuration config = resources.getConfiguration();
config.setLocale(currentLocale);
context.getResources().updateConfiguration(config, null);
}
// We create and destroy a new WebView here to force the internal state of WebView to know
// about the new language. See issue #666.
final WebView unneeded = new WebView(getContext());
unneeded.destroy();
}
示例2: updateConfigurationForNightMode
import android.content.res.Resources; //導入方法依賴的package包/類
private boolean updateConfigurationForNightMode(int mode) {
Resources res = this.mContext.getResources();
Configuration conf = res.getConfiguration();
int currentNightMode = conf.uiMode & 48;
int newNightMode = 0;
switch (mode) {
case 1:
newNightMode = 16;
break;
case 2:
newNightMode = 32;
break;
}
if (currentNightMode == newNightMode) {
return false;
}
conf.uiMode = (conf.uiMode & -49) | newNightMode;
res.updateConfiguration(conf, null);
return true;
}
示例3: say
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* get String out of a string-value file
*
* @param resourceId id of string
* @param useTTSLanguage set to true if the string should be said in the current language of the tts engine
*
* */
public Future say(Integer resourceId, Boolean useTTSLanguage) {
if(useTTSLanguage) {
Resources standardResources = session.getContext().getResources();
AssetManager assets = standardResources.getAssets();
DisplayMetrics metrics = standardResources.getDisplayMetrics();
Configuration config = new Configuration(standardResources.getConfiguration());
try {
config.locale = LANGUAGE_TO_LOCALE.get((String) this.getLanguage().get());
Resources defaultResources = new Resources(assets, metrics, config);
String text = defaultResources.getString(resourceId);
return this.say(text);
} catch (ExecutionException e) {
Log.d("PepperAndroid.Say", e.getMessage());
}
}
// Fallback to default language
return this.say(this.session.getContext().getResources().getString(resourceId));
}
示例4: updateResourcesLegacy
import android.content.res.Resources; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private static Context updateResourcesLegacy(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLayoutDirection(locale);
}
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return context;
}
示例5: getNavigationBarHeight
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* 獲取虛擬導航欄高度
*
* @param context Context
* @return 虛擬導航欄高度
*/
@TargetApi(14)
public static int getNavigationBarHeight(Context context) {
Resources res = context.getResources();
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (hasNavBar(context)) {
String key;
if (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
key = NAV_BAR_HEIGHT_RES_NAME;
} else {
key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;
}
return getInternalDimensionSize(res, key);
}
}
return result;
}
示例6: updateRamBarLayout
import android.content.res.Resources; //導入方法依賴的package包/類
@SuppressLint("RtlHardcoded")
private static void updateRamBarLayout() {
if (mRamUsageBar == null || mRamBarGravity == 0) return;
final Context context = mRamUsageBar.getContext();
final Resources res = mRamUsageBar.getResources();
final int orientation = res.getConfiguration().orientation;
final boolean caOnTop = (mButtonGravity & Gravity.TOP) == Gravity.TOP;
final boolean caOnLeft = (mButtonGravity & Gravity.LEFT) == Gravity.LEFT;
final boolean rbOnTop = (mRamBarGravity == Gravity.TOP);
final int marginTop = rbOnTop ? mMarginTopPx : 0;
final int marginBottom = (!rbOnTop && (orientation == Configuration.ORIENTATION_PORTRAIT ||
!Utils.isPhoneUI(context))) ? mMarginBottomPx : 0;
final int marginLeft = orientation == Configuration.ORIENTATION_LANDSCAPE &&
Utils.isPhoneUI(context) & mNavbarLeftHanded ? mMarginBottomPx : 0;
final int marginRight = orientation == Configuration.ORIENTATION_LANDSCAPE &&
Utils.isPhoneUI(context) & !mNavbarLeftHanded ? mMarginBottomPx : 0;
FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams) mRamUsageBar.getLayoutParams();
flp.gravity = mRamBarGravity;
flp.setMargins(mRamUsageBarHorizontalMargin + marginLeft,
rbOnTop ? (mRamUsageBarVerticalMargin + marginTop) : 0,
mRamUsageBarHorizontalMargin + marginRight,
rbOnTop ? 0 : (mRamUsageBarVerticalMargin + marginBottom)
);
mRamUsageBar.setLayoutParams(flp);
if (DEBUG) log("RAM bar layout updated");
}
示例7: getResources
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public Resources getResources(Context context, ApplicationInfo appInfo) throws Exception {
AppSetting appSetting = VAppManagerService.get().findAppInfo(appInfo.packageName);
if (appSetting != null) {
AssetManager assets = mirror.android.content.res.AssetManager.ctor.newInstance();
mirror.android.content.res.AssetManager.addAssetPath.call(assets, appSetting.apkPath);
Resources hostRes = context.getResources();
return new Resources(assets, hostRes.getDisplayMetrics(), hostRes.getConfiguration());
}
return null;
}
示例8: getAllowRotationDefaultValue
import android.content.res.Resources; //導入方法依賴的package包/類
public static boolean getAllowRotationDefaultValue(Context context) {
if (isNycOrAbove()) {
// If the device was scaled, used the original dimensions to determine if rotation
// is allowed of not.
Resources res = context.getResources();
int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
* res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEVICE_STABLE;
return originalSmallestWidth >= 600;
}
return false;
}
示例9: getResources
import android.content.res.Resources; //導入方法依賴的package包/類
@CheckResult
public static Resources getResources(Context context, String apkPath) {
try {
AssetManager assetManager = getAssetManager(apkPath);
Resources resources = context.getResources();
return new Resources(assetManager, resources.getDisplayMetrics(), resources.getConfiguration());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例10: updateResources
import android.content.res.Resources; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private static void updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.setLocale(locale);
resources.updateConfiguration(configuration,null);
}
示例11: updateConfiguration
import android.content.res.Resources; //導入方法依賴的package包/類
private void updateConfiguration(Resources resources) {
LogInfo.log(TAG, "updateConfiguration resources=" + resources);
if (JarApplication.getInstance() != null && JarApplication.getInstance().getResources() != null) {
Resources superRes = JarApplication.getInstance().getResources();
Configuration configuration = superRes.getConfiguration();
LogInfo.log(TAG, "updateConfiguration configuration=" + configuration);
DisplayMetrics displayMetrics = superRes.getDisplayMetrics();
if (resources != null && configuration != null && displayMetrics != null) {
resources.updateConfiguration(configuration, displayMetrics);
}
}
}
示例12: SystemBarConfig
import android.content.res.Resources; //導入方法依賴的package包/類
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: updateResources
import android.content.res.Resources; //導入方法依賴的package包/類
private static Context updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources res = context.getResources();
Configuration config = new Configuration(res.getConfiguration());
if (Build.VERSION.SDK_INT >= 17) {
config.setLocale(locale);
context = context.createConfigurationContext(config);
} else {
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
}
return context;
}
示例14: setLocale
import android.content.res.Resources; //導入方法依賴的package包/類
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(getContext(), MainActivity.class);
startActivity(refresh);
getActivity().finish();
}
示例15: setResourcesLocale
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Set the current locale for the resources (strings, ...).
*/
public static void setResourcesLocale(Locale locale, Context context) {
Resources resources = context.getResources();
resources.getConfiguration().locale = locale;
resources.updateConfiguration(resources.getConfiguration(), null);
}