widgets scaling fix. Use container's compatibility info and display metrics when container and widgets disagree.
This commit is contained in:
@@ -88,8 +88,10 @@ import android.os.FileUtils.FileStatus;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.ClipboardManager;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.WindowManagerImpl;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
@@ -149,6 +151,7 @@ class ReceiverRestrictedContext extends ContextWrapper {
|
||||
*/
|
||||
class ApplicationContext extends Context {
|
||||
private final static String TAG = "ApplicationContext";
|
||||
private final static boolean DEBUG = false;
|
||||
private final static boolean DEBUG_ICONS = false;
|
||||
|
||||
private static final Object sSync = new Object();
|
||||
@@ -1238,7 +1241,7 @@ class ApplicationContext extends Context {
|
||||
@Override
|
||||
public int checkUriPermission(Uri uri, String readPermission,
|
||||
String writePermission, int pid, int uid, int modeFlags) {
|
||||
if (false) {
|
||||
if (DEBUG) {
|
||||
Log.i("foo", "checkUriPermission: uri=" + uri + "readPermission="
|
||||
+ readPermission + " writePermission=" + writePermission
|
||||
+ " pid=" + pid + " uid=" + uid + " mode" + modeFlags);
|
||||
@@ -1340,6 +1343,19 @@ class ApplicationContext extends Context {
|
||||
c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
|
||||
c.init(pi, null, mMainThread);
|
||||
if (c.mResources != null) {
|
||||
Resources newRes = c.mResources;
|
||||
if (mResources.getCompatibilityInfo().applicationScale !=
|
||||
newRes.getCompatibilityInfo().applicationScale) {
|
||||
DisplayMetrics dm = mMainThread.getDisplayMetricsLocked(false);
|
||||
c.mResources = new Resources(newRes.getAssets(), dm,
|
||||
newRes.getConfiguration(),
|
||||
mResources.getCompatibilityInfo().copy());
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "loaded context has different scaling. Using container's" +
|
||||
" compatiblity info:" + mResources.getDisplayMetrics());
|
||||
}
|
||||
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -1459,7 +1475,7 @@ class ApplicationContext extends Context {
|
||||
if ((mode&MODE_WORLD_WRITEABLE) != 0) {
|
||||
perms |= FileUtils.S_IWOTH;
|
||||
}
|
||||
if (false) {
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
|
||||
+ ", perms=0x" + Integer.toHexString(perms));
|
||||
}
|
||||
|
||||
@@ -159,14 +159,32 @@ public class CompatibilityInfo {
|
||||
}
|
||||
}
|
||||
|
||||
private CompatibilityInfo() {
|
||||
appFlags = ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
|
||||
| ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
|
||||
| ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
|
||||
applicationScale = applicationInvertedScale = 1.0f;
|
||||
mCompatibilityFlags = EXPANDABLE | CONFIGURED_EXPANDABLE;
|
||||
private CompatibilityInfo(int appFlags, int compFlags, float scale, float invertedScale) {
|
||||
this.appFlags = appFlags;
|
||||
mCompatibilityFlags = compFlags;
|
||||
applicationScale = scale;
|
||||
applicationInvertedScale = invertedScale;
|
||||
}
|
||||
|
||||
private CompatibilityInfo() {
|
||||
this(ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
|
||||
| ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
|
||||
| ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS,
|
||||
EXPANDABLE | CONFIGURED_EXPANDABLE,
|
||||
1.0f,
|
||||
1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the copy of this instance.
|
||||
*/
|
||||
public CompatibilityInfo copy() {
|
||||
CompatibilityInfo info = new CompatibilityInfo(appFlags, mCompatibilityFlags,
|
||||
applicationScale, applicationInvertedScale);
|
||||
info.setVisibleRect(mXOffset, mWidth, mHeight);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application's visible rect in compatibility mode.
|
||||
* @param xOffset the application's x offset that is added to center the content.
|
||||
@@ -470,4 +488,4 @@ public class CompatibilityInfo {
|
||||
return mVisibleInsets;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class Resources {
|
||||
*/
|
||||
public Resources(AssetManager assets, DisplayMetrics metrics,
|
||||
Configuration config) {
|
||||
this(assets, metrics, config, null);
|
||||
this(assets, metrics, config, (ApplicationInfo) null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,6 +165,26 @@ public class Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new resources that uses the given compatibility info. Used to create
|
||||
* a context for widgets using the container's compatibility info.
|
||||
* {@see ApplicationContext#createPackageCotnext}.
|
||||
* @hide
|
||||
*/
|
||||
public Resources(AssetManager assets, DisplayMetrics metrics,
|
||||
Configuration config, CompatibilityInfo info) {
|
||||
mAssets = assets;
|
||||
mMetrics.setToDefaults();
|
||||
mCompatibilityInfo = info;
|
||||
updateConfiguration(config, metrics);
|
||||
assets.ensureStringBlocks();
|
||||
if (mCompatibilityInfo.isScalingRequired()) {
|
||||
mPreloadedDrawables = emptySparseArray();
|
||||
} else {
|
||||
mPreloadedDrawables = sPreloadedDrawables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a global shared Resources object that provides access to only
|
||||
* system resources (no application resources), and is not configured for
|
||||
|
||||
Reference in New Issue
Block a user