Search in sources :

Example 1 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 2 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)

Example 3 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 4 with DisplayMetrics

use of android.util.DisplayMetrics in project philm by chrisbanes.

the class CollapsingTitleLayout method calculateTextBounds.

private void calculateTextBounds() {
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    // We then calculate the collapsed text size, using the same logic
    mTextPaint.setTextSize(mCollapsedTitleTextSize);
    float textHeight = mTextPaint.descent() - mTextPaint.ascent();
    float textOffset = (textHeight / 2) - mTextPaint.descent();
    mCollapsedTop = mToolbarContentBounds.centerY() + textOffset;
    // First, let's calculate the expanded text size so that it fit within the bounds
    // We make sure this value is at least our minimum text size
    mExpandedTitleTextSize = (int) Math.max(mCollapsedTitleTextSize, getSingleLineTextSize(mTitle, mTextPaint, getWidth() - mExpandedMarginLeft - mExpandedMarginRight, 0f, mRequestedExpandedTitleTextSize, 0.5f, metrics));
    mExpandedTop = getHeight() - mExpandedMarginBottom;
    // The bounds have changed so we need to clear the texture
    clearTexture();
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 5 with DisplayMetrics

use of android.util.DisplayMetrics in project loadtoast by code-mc.

the class MaterialProgressDrawable method updateSizes.

/**
     * Set the overall size for the progress spinner. This updates the radius
     * and stroke width of the ring.
     *

     */
public void updateSizes(@ProgressDrawableSize int size) {
    final DisplayMetrics metrics = mResources.getDisplayMetrics();
    final float screenDensity = metrics.density;
    if (size == LARGE) {
        setSizeParameters(CIRCLE_DIAMETER_LARGE * screenDensity, CIRCLE_DIAMETER_LARGE * screenDensity, CENTER_RADIUS_LARGE * screenDensity, STROKE_WIDTH_LARGE * screenDensity, ARROW_WIDTH_LARGE * screenDensity, ARROW_HEIGHT_LARGE * screenDensity);
    } else {
        setSizeParameters(CIRCLE_DIAMETER * screenDensity, CIRCLE_DIAMETER * screenDensity, CENTER_RADIUS * screenDensity, STROKE_WIDTH * screenDensity, ARROW_WIDTH * screenDensity, ARROW_HEIGHT * screenDensity);
    }
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

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