Search in sources :

Example 81 with DisplayMetrics

use of android.util.DisplayMetrics in project UltimateRecyclerView by cymcsg.

the class GridLayoutRVTest method dimension_columns.

private void dimension_columns() {
    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);
    float density = getResources().getDisplayMetrics().density;
    float dpWidth = outMetrics.widthPixels / density;
    columns = Math.round(dpWidth / 300);
}
Also used : DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display)

Example 82 with DisplayMetrics

use of android.util.DisplayMetrics in project Launcher3 by chislon.

the class TiledImageRenderer method isHighResolution.

private static boolean isHighResolution(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    return metrics.heightPixels > 2048 || metrics.widthPixels > 2048;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Example 83 with DisplayMetrics

use of android.util.DisplayMetrics in project Launcher3 by chislon.

the class LauncherTransitionable method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }
    super.onCreate(savedInstanceState);
    LauncherAppState.setApplicationContext(getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    // Determine the dynamic grid properties
    Point smallestSize = new Point();
    Point largestSize = new Point();
    Point realSize = new Point();
    Display display = getWindowManager().getDefaultDisplay();
    display.getCurrentSizeRange(smallestSize, largestSize);
    display.getRealSize(realSize);
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);
    // Lazy-initialize the dynamic grid
    DeviceProfile grid = app.initDynamicGrid(this, Math.min(smallestSize.x, smallestSize.y), Math.min(largestSize.x, largestSize.y), realSize.x, realSize.y, dm.widthPixels, dm.heightPixels);
    // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
    mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mIconCache.flushInvalidIcons(grid);
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();
    mStats = new Stats(this);
    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();
    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;
    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }
    checkForLocaleChange();
    setContentView(R.layout.launcher);
    setupViews();
    grid.layout(this);
    registerContentObservers();
    lockAllApps();
    mSavedState = savedInstanceState;
    restoreState(mSavedState);
    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(this));
    }
    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }
    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }
    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);
    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);
    updateGlobalIcons();
    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
    showFirstRunCling();
}
Also used : StrictMode(android.os.StrictMode) IntentFilter(android.content.IntentFilter) SpannableStringBuilder(android.text.SpannableStringBuilder) Point(android.graphics.Point) DisplayMetrics(android.util.DisplayMetrics) SpannableStringBuilder(android.text.SpannableStringBuilder) Display(android.view.Display)

Example 84 with DisplayMetrics

use of android.util.DisplayMetrics in project Launcher3 by chislon.

the class PagedView method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (!mIsDataReady || getChildCount() == 0) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }
    // We measure the dimensions of the PagedView to be larger than the pages so that when we
    // zoom out (and scale down), the view is still contained in the parent
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    // NOTE: We multiply by 1.5f to account for the fact that depending on the offset of the
    // viewport, we can be at most one and a half screens offset once we scale down
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int maxSize = Math.max(dm.widthPixels, dm.heightPixels + mInsets.top + mInsets.bottom);
    int parentWidthSize, parentHeightSize;
    int scaledWidthSize, scaledHeightSize;
    if (mUseMinScale) {
        parentWidthSize = (int) (1.5f * maxSize);
        parentHeightSize = maxSize;
        scaledWidthSize = (int) (parentWidthSize / mMinScale);
        scaledHeightSize = (int) (parentHeightSize / mMinScale);
    } else {
        scaledWidthSize = widthSize;
        scaledHeightSize = heightSize;
    }
    mViewport.set(0, 0, widthSize, heightSize);
    if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }
    // Return early if we aren't given a proper dimension
    if (widthSize <= 0 || heightSize <= 0) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }
    /* Allow the height to be set as WRAP_CONTENT. This allows the particular case
         * of the All apps view on XLarge displays to not take up more space then it needs. Width
         * is still not allowed to be set as WRAP_CONTENT since many parts of the code expect
         * each page to have the same width.
         */
    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    final int horizontalPadding = getPaddingLeft() + getPaddingRight();
    // unless they were set to WRAP_CONTENT
    if (DEBUG)
        Log.d(TAG, "PagedView.onMeasure(): " + widthSize + ", " + heightSize);
    if (DEBUG)
        Log.d(TAG, "PagedView.scaledSize: " + scaledWidthSize + ", " + scaledHeightSize);
    if (DEBUG)
        Log.d(TAG, "PagedView.parentSize: " + parentWidthSize + ", " + parentHeightSize);
    if (DEBUG)
        Log.d(TAG, "PagedView.horizontalPadding: " + horizontalPadding);
    if (DEBUG)
        Log.d(TAG, "PagedView.verticalPadding: " + verticalPadding);
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        // disallowing padding in paged view (just pass 0)
        final View child = getPageAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childWidthMode;
            int childHeightMode;
            int childWidth;
            int childHeight;
            if (!lp.isFullScreenPage) {
                if (lp.width == LayoutParams.WRAP_CONTENT) {
                    childWidthMode = MeasureSpec.AT_MOST;
                } else {
                    childWidthMode = MeasureSpec.EXACTLY;
                }
                if (lp.height == LayoutParams.WRAP_CONTENT) {
                    childHeightMode = MeasureSpec.AT_MOST;
                } else {
                    childHeightMode = MeasureSpec.EXACTLY;
                }
                childWidth = widthSize - horizontalPadding;
                childHeight = heightSize - verticalPadding - mInsets.top - mInsets.bottom;
                mNormalChildHeight = childHeight;
            } else {
                childWidthMode = MeasureSpec.EXACTLY;
                childHeightMode = MeasureSpec.EXACTLY;
                if (mUseMinScale) {
                    childWidth = getViewportWidth();
                    childHeight = getViewportHeight();
                } else {
                    childWidth = widthSize - getPaddingLeft() - getPaddingRight();
                    childHeight = heightSize - getPaddingTop() - getPaddingBottom();
                }
            }
            final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth, childWidthMode);
            final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight, childHeightMode);
            child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        }
    }
    setMeasuredDimension(scaledWidthSize, scaledHeightSize);
    if (childCount > 0) {
        // Calculate the variable page spacing if necessary
        if (mAutoComputePageSpacing && mRecomputePageSpacing) {
            // The gap between pages in the PagedView should be equal to the gap from the page
            // to the edge of the screen (so it is not visible in the current screen).  To
            // account for unequal padding on each side of the paged view, we take the maximum
            // of the left/right gap and use that as the gap between each page.
            int offset = (getViewportWidth() - getChildWidth(0)) / 2;
            int spacing = Math.max(offset, widthSize - offset - getChildAt(0).getMeasuredWidth());
            setPageSpacing(spacing);
            mRecomputePageSpacing = false;
        }
    }
}
Also used : DisplayMetrics(android.util.DisplayMetrics) View(android.view.View)

Example 85 with DisplayMetrics

use of android.util.DisplayMetrics in project Launcher3 by chislon.

the class Utilities method initStatics.

private static void initStatics(Context context) {
    final Resources resources = context.getResources();
    final DisplayMetrics metrics = resources.getDisplayMetrics();
    final float density = metrics.density;
    sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size);
    sIconTextureWidth = sIconTextureHeight = sIconWidth;
    sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
    sGlowColorPressedPaint.setColor(0xffffc300);
    sGlowColorFocusedPaint.setColor(0xffff8e00);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0.2f);
    sDisabledPaint.setColorFilter(new ColorMatrixColorFilter(cm));
    sDisabledPaint.setAlpha(0x88);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix) BlurMaskFilter(android.graphics.BlurMaskFilter) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)772 WindowManager (android.view.WindowManager)107 Resources (android.content.res.Resources)99 Display (android.view.Display)78 Configuration (android.content.res.Configuration)61 Point (android.graphics.Point)57 View (android.view.View)52 SuppressLint (android.annotation.SuppressLint)47 Bitmap (android.graphics.Bitmap)42 Paint (android.graphics.Paint)42 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)27 AssetManager (android.content.res.AssetManager)25 TypedArray (android.content.res.TypedArray)25 Context (android.content.Context)23 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)21 RelativeLayout (android.widget.RelativeLayout)20