Search in sources :

Example 26 with DisplayMetrics

use of android.util.DisplayMetrics in project android-app by eoecn.

the class Utility method getScreenParams.

public static String getScreenParams(Activity activity) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return "&screen=" + (dm.heightPixels > dm.widthPixels ? dm.widthPixels + "*" + dm.heightPixels : dm.heightPixels + "*" + dm.widthPixels);
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 27 with DisplayMetrics

use of android.util.DisplayMetrics in project MyDiary by erttyy8821.

the class ScreenHelper method getScreenHeight.

public static int getScreenHeight(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics.heightPixels;
}
Also used : Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics)

Example 28 with DisplayMetrics

use of android.util.DisplayMetrics in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method applyConfigurationToResourcesLocked.

final int applyConfigurationToResourcesLocked(Configuration config, CompatibilityInfo compat) {
    if (mResConfiguration == null) {
        mResConfiguration = new Configuration();
    }
    if (!mResConfiguration.isOtherSeqNewer(config) && compat == null) {
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Skipping new config: curSeq=" + mResConfiguration.seq + ", newSeq=" + config.seq);
        return 0;
    }
    int changes = mResConfiguration.updateFrom(config);
    flushDisplayMetricsLocked();
    DisplayMetrics defaultDisplayMetrics = getDisplayMetricsLocked(Display.DEFAULT_DISPLAY, null);
    if (compat != null && (mResCompatibilityInfo == null || !mResCompatibilityInfo.equals(compat))) {
        mResCompatibilityInfo = compat;
        changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
    }
    // set it for java, this also affects newly created Resources
    if (config.locale != null) {
        Locale.setDefault(config.locale);
    }
    Resources.updateSystemConfiguration(config, defaultDisplayMetrics, compat);
    ApplicationPackageManager.configurationChanged();
    //Slog.i(TAG, "Configuration changed in " + currentPackageName());
    Configuration tmpConfig = null;
    Iterator<Map.Entry<ResourcesKey, WeakReference<Resources>>> it = mActiveResources.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<ResourcesKey, WeakReference<Resources>> entry = it.next();
        Resources r = entry.getValue().get();
        if (r != null) {
            if (DEBUG_CONFIGURATION)
                Slog.v(TAG, "Changing resources " + r + " config to: " + config);
            int displayId = entry.getKey().mDisplayId;
            boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
            DisplayMetrics dm = defaultDisplayMetrics;
            Configuration overrideConfig = entry.getKey().mOverrideConfiguration;
            boolean themeChanged = (changes & ActivityInfo.CONFIG_THEME_RESOURCE) != 0;
            if (themeChanged) {
                AssetManager am = r.getAssets();
                if (am.hasThemeSupport()) {
                    detachThemeAssets(am);
                    if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
                        attachThemeAssets(am, config.customTheme);
                    }
                }
            }
            if (!isDefaultDisplay || overrideConfig != null) {
                if (tmpConfig == null) {
                    tmpConfig = new Configuration();
                }
                tmpConfig.setTo(config);
                if (!isDefaultDisplay) {
                    dm = getDisplayMetricsLocked(displayId, null);
                    applyNonDefaultDisplayMetricsToConfigurationLocked(dm, tmpConfig);
                }
                if (overrideConfig != null) {
                    tmpConfig.updateFrom(overrideConfig);
                }
                r.updateConfiguration(tmpConfig, dm, compat);
            } else {
                r.updateConfiguration(config, dm, compat);
            }
            if (themeChanged) {
                r.updateStringCache();
            }
        //Slog.i(TAG, "Updated app resources " + v.getKey()
        //        + " " + r + ": " + r.getConfiguration());
        } else {
            //Slog.i(TAG, "Removing old resources " + v.getKey());
            it.remove();
        }
    }
    return changes;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) WeakReference(java.lang.ref.WeakReference) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) PackageRedirectionMap(android.content.res.PackageRedirectionMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with DisplayMetrics

use of android.util.DisplayMetrics in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method getTopLevelResources.

/**
     * Creates the top level Resources for applications with the given compatibility info.
     *
     * @param resDir the resource directory.
     * @param compInfo the compability info. It will use the default compatibility info when it's
     * null.
     */
Resources getTopLevelResources(String resDir, int displayId, Configuration overrideConfiguration, CompatibilityInfo compInfo) {
    ResourcesKey key = new ResourcesKey(resDir, displayId, overrideConfiguration, compInfo.applicationScale, compInfo.isThemeable);
    Resources r;
    synchronized (mPackages) {
        // Resources is app scale dependent.
        if (false) {
            Slog.w(TAG, "getTopLevelResources: " + resDir + " / " + compInfo.applicationScale);
        }
        WeakReference<Resources> wr = mActiveResources.get(key);
        r = wr != null ? wr.get() : null;
        //if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate());
        if (r != null && r.getAssets().isUpToDate()) {
            if (false) {
                Slog.w(TAG, "Returning cached resources " + r + " " + resDir + ": appScale=" + r.getCompatibilityInfo().applicationScale);
            }
            return r;
        }
    }
    //if (r != null) {
    //    Slog.w(TAG, "Throwing away out-of-date resources!!!! "
    //            + r + " " + resDir);
    //}
    AssetManager assets = new AssetManager();
    assets.overrideHook(resDir, ExtendedPropertiesUtils.OverrideMode.FullNameExclude);
    assets.setThemeSupport(compInfo.isThemeable);
    if (assets.addAssetPath(resDir) == 0) {
        return null;
    }
    //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
    DisplayMetrics dm = getDisplayMetricsLocked(displayId, null);
    dm.overrideHook(assets, ExtendedPropertiesUtils.OverrideMode.ExtendedProperties);
    Configuration config;
    boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
    if (!isDefaultDisplay || key.mOverrideConfiguration != null) {
        config = new Configuration(getConfiguration());
        if (!isDefaultDisplay) {
            applyNonDefaultDisplayMetricsToConfigurationLocked(dm, config);
        }
        if (key.mOverrideConfiguration != null) {
            config.updateFrom(key.mOverrideConfiguration);
        }
    } else {
        config = getConfiguration();
    }
    /* Attach theme information to the resulting AssetManager when appropriate. */
    if (compInfo.isThemeable && config != null) {
        if (config.customTheme == null) {
            config.customTheme = CustomTheme.getBootTheme();
        }
        if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
            attachThemeAssets(assets, config.customTheme);
        }
    }
    r = new Resources(assets, dm, config, compInfo);
    if (false) {
        Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " + r.getConfiguration() + " appScale=" + r.getCompatibilityInfo().applicationScale);
    }
    synchronized (mPackages) {
        WeakReference<Resources> wr = mActiveResources.get(key);
        Resources existing = wr != null ? wr.get() : null;
        if (existing != null && existing.getAssets().isUpToDate()) {
            // Someone else already created the resources while we were
            // unlocked; go ahead and use theirs.
            r.getAssets().close();
            return existing;
        }
        // XXX need to remove entries when weak references go away
        mActiveResources.put(key, new WeakReference<Resources>(r));
        return r;
    }
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 30 with DisplayMetrics

use of android.util.DisplayMetrics in project android_frameworks_base by ParanoidAndroid.

the class WallpaperManager method generateBitmap.

static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
    if (bm == null) {
        return null;
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    bm.setDensity(metrics.noncompatDensityDpi);
    if (width <= 0 || height <= 0 || (bm.getWidth() == width && bm.getHeight() == height)) {
        return bm;
    }
    // This is the final bitmap we want to return.
    try {
        Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        newbm.setDensity(metrics.noncompatDensityDpi);
        Canvas c = new Canvas(newbm);
        Rect targetRect = new Rect();
        targetRect.right = bm.getWidth();
        targetRect.bottom = bm.getHeight();
        int deltaw = width - targetRect.right;
        int deltah = height - targetRect.bottom;
        if (deltaw > 0 || deltah > 0) {
            // We need to scale up so it covers the entire area.
            float scale;
            if (deltaw > deltah) {
                scale = width / (float) targetRect.right;
            } else {
                scale = height / (float) targetRect.bottom;
            }
            targetRect.right = (int) (targetRect.right * scale);
            targetRect.bottom = (int) (targetRect.bottom * scale);
            deltaw = width - targetRect.right;
            deltah = height - targetRect.bottom;
        }
        targetRect.offset(deltaw / 2, deltah / 2);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        c.drawBitmap(bm, null, targetRect, paint);
        bm.recycle();
        c.setBitmap(null);
        return newbm;
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "Can't generate default bitmap", e);
        return bm;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) WindowManager(android.view.WindowManager)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)751 WindowManager (android.view.WindowManager)103 Resources (android.content.res.Resources)95 Display (android.view.Display)75 Configuration (android.content.res.Configuration)58 Point (android.graphics.Point)56 View (android.view.View)48 SuppressLint (android.annotation.SuppressLint)44 Paint (android.graphics.Paint)42 Bitmap (android.graphics.Bitmap)41 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)26 TypedArray (android.content.res.TypedArray)25 AssetManager (android.content.res.AssetManager)24 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)22 TextView (android.widget.TextView)21 Intent (android.content.Intent)20 FrameLayout (android.widget.FrameLayout)19 RelativeLayout (android.widget.RelativeLayout)19