Example usage for android.content.res Resources getDisplayMetrics

List of usage examples for android.content.res Resources getDisplayMetrics

Introduction

In this page you can find the example usage for android.content.res Resources getDisplayMetrics.

Prototype

public DisplayMetrics getDisplayMetrics() 

Source Link

Document

Return the current display metrics that are in effect for this resource object.

Usage

From source file:android.support.v7.internal.widget.ActivityChooserView.java

/**
 * Create a new instance.//from w w w  .j av  a2s. c o  m
 *
 * @param context The application environment.
 * @param attrs A collection of attributes.
 * @param defStyle The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (LinearLayoutCompat) findViewById(R.id.activity_chooser_view_content);
    mActivityChooserContentBackground = mActivityChooserContent.getBackground();

    mDefaultActivityButton = (FrameLayout) findViewById(R.id.default_activity_button);
    mDefaultActivityButton.setOnClickListener(mCallbacks);
    mDefaultActivityButton.setOnLongClickListener(mCallbacks);
    mDefaultActivityButtonImage = (ImageView) mDefaultActivityButton.findViewById(R.id.image);

    final FrameLayout expandButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    expandButton.setOnClickListener(mCallbacks);
    expandButton.setOnTouchListener(new ListPopupWindow.ForwardingListener(expandButton) {
        @Override
        public ListPopupWindow getPopup() {
            return getListPopupWindow();
        }

        @Override
        protected boolean onForwardingStarted() {
            showPopup();
            return true;
        }

        @Override
        protected boolean onForwardingStopped() {
            dismissPopup();
            return true;
        }
    });
    mExpandActivityOverflowButton = expandButton;
    mExpandActivityOverflowButtonImage = (ImageView) expandButton.findViewById(R.id.image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

public SunriseDrawable(Context context) {

    mContext = context;/*from ww  w  .j  a v  a 2s. com*/

    Resources res = context.getResources();
    final TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.colorPrimary, R.attr.colorAccent,
            R.attr.colorPrimaryDark, R.attr.appsiHomeWidgetPrimaryColor, });

    int primaryColor = a.getColor(0, Color.BLACK);
    int accentColor = a.getColor(1, Color.BLACK);
    int primaryColorDark = a.getColor(2, Color.BLACK);
    int textColor = a.getColor(3, Color.BLACK);
    a.recycle();

    mIsRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;

    float density = res.getDisplayMetrics().density;
    int sunBounds = (int) (density * 16);
    mTopOffset = (int) (density * 12);
    mLeftOffset = (int) (density * 24);
    mRightOffset = (int) (density * 24);
    mBottomOffset = (int) (density * 24);
    mDotRadius = (int) (density * 2);

    mSunImage = mContext.getResources().getDrawable(R.drawable.ic_weather_clear);
    mSunImage.setBounds(0, 0, sunBounds, sunBounds);

    mArcPaint = new Paint();
    mArcPaint.setColor(primaryColorDark);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setAntiAlias(true);

    mArcFillPaint = new Paint();
    mArcFillPaint.setColor(primaryColor);
    mArcFillPaint.setAlpha(64);
    mArcFillPaint.setStyle(Paint.Style.FILL);
    mArcFillPaint.setAntiAlias(true);

    mLinePaint = new Paint();
    mLinePaint.setColor(textColor);
    mLinePaint.setAlpha(128);
    mLinePaint.setStyle(Paint.Style.STROKE);

    mDotPaint = new Paint();
    mDotPaint.setStyle(Paint.Style.FILL);
    mDotPaint.setColor(primaryColorDark);
    mDotPaint.setAntiAlias(true);
}

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

private void revealFrom(float x, float y, Activity a, SearchBox s) {
    FrameLayout layout = (FrameLayout) a.getWindow().getDecorView().findViewById(android.R.id.content);
    RelativeLayout root = (RelativeLayout) s.findViewById(R.id.search_root);
    Resources r = getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96, r.getDisplayMetrics());
    int cx = layout.getLeft() + layout.getRight();
    int cy = layout.getTop();

    int finalRadius = (int) Math.max(layout.getWidth(), px);

    SupportAnimator animator = ViewAnimationUtils.createCircularReveal(root, cx, cy, 0, finalRadius);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setDuration(500);/*from ww  w  .  jav  a2  s  . c o  m*/
    animator.addListener(new SupportAnimator.AnimatorListener() {

        @Override
        public void onAnimationCancel() {

        }

        @Override
        public void onAnimationEnd() {
            toggleSearch();
        }

        @Override
        public void onAnimationRepeat() {

        }

        @Override
        public void onAnimationStart() {

        }

    });
    animator.start();
}

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

/***
 * Hide the searchbox using the circle animation. Can be called regardless of result list length
 * @param activity Activity/*from  w  w w . jav a 2  s  .co m*/
 */
public void hideCircularly(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    final FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView()
            .findViewById(android.R.id.content);
    RelativeLayout root = (RelativeLayout) findViewById(R.id.search_root);
    display.getSize(size);
    Resources r = getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96, r.getDisplayMetrics());
    int cx = layout.getLeft() + layout.getRight();
    int cy = layout.getTop();
    int finalRadius = (int) Math.max(layout.getWidth() * 1.5, px);

    SupportAnimator animator = ViewAnimationUtils.createCircularReveal(root, cx, cy, 0, finalRadius);
    animator.setInterpolator(new ReverseInterpolator());
    animator.setDuration(500);
    animator.start();
    animator.addListener(new SupportAnimator.AnimatorListener() {

        @Override
        public void onAnimationStart() {

        }

        @Override
        public void onAnimationEnd() {
            setVisibility(View.GONE);
        }

        @Override
        public void onAnimationCancel() {

        }

        @Override
        public void onAnimationRepeat() {

        }

    });
}

From source file:org.mariotaku.twidere.fragment.AccountsDashboardFragment.java

protected void displayAccountBanner(@NonNull ParcelableAccount account) {
    final int bannerWidth = mAccountProfileBannerView.getWidth();
    final Resources res = getResources();
    final int defWidth = res.getDisplayMetrics().widthPixels;
    final int width = bannerWidth > 0 ? bannerWidth : defWidth;
    final ImageView bannerView = (ImageView) mAccountProfileBannerView.getNextView();
    if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(account, bannerView.getTag())) {
        mMediaLoader.displayProfileBanner(bannerView, account, width);
        bannerView.setTag(account);/* w  w  w . java  2s  .c  o  m*/
    } else {
        mMediaLoader.cancelDisplayTask(bannerView);
    }
}

From source file:de.tap.easy_xkcd.Activities.MainActivity.java

public void selectDrawerItem(final MenuItem menuItem, final boolean showOverview) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (menuItem.getItemId() == R.id.nav_whatif)
            toolbar.setElevation(0);//from  w w  w  .j a  v  a  2 s. c  o  m
        else {
            Resources r = getResources();
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, r.getDisplayMetrics());
            toolbar.setElevation(px);
        }
    }
    switch (menuItem.getItemId()) {
    case R.id.nav_browser:
        if (!prefHelper.isOnline(this) && !fullOffline) {
            showDrawerErrorToast(R.string.no_connection);
            return;
        }
        //showComicBrowserFragment
        animateToolbar(-300);
        showFragment("pref_random_comics", menuItem.getItemId(), "Comics", BROWSER_TAG, FAV_TAG, WHATIF_TAG,
                showOverview);
        break;
    case R.id.nav_favorites:
        //Check if there are any Favorites
        if (Favorites.getFavoriteList(this).length == 0) {
            showDrawerErrorToast(R.string.no_favorites);
            return;
        }
        //showFavoritesFragment
        animateToolbar(300);
        showFragment("pref_random_favorites", menuItem.getItemId(),
                getResources().getString(R.string.nv_favorites), FAV_TAG, BROWSER_TAG, WHATIF_TAG,
                showOverview);
        break;
    case R.id.nav_whatif:
        if (!prefHelper.isOnline(this) && !fullOfflineWhatIf) {
            showDrawerErrorToast(R.string.no_connection);
            return;
        }
        animateToolbar(300);
        if (getSupportFragmentManager().findFragmentByTag(WHATIF_TAG) == null) {
            mDrawer.closeDrawers();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    showFragment("", menuItem.getItemId(), "What if?", WHATIF_TAG, FAV_TAG, BROWSER_TAG,
                            showOverview);
                }
            }, 150);
        } else {
            showFragment("", menuItem.getItemId(), "What if?", WHATIF_TAG, FAV_TAG, BROWSER_TAG, showOverview);
        }
        break;

    case R.id.nav_settings:
        mDrawer.closeDrawers();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivity(i);
            }
        }, 200);
        return;

    case R.id.nav_feedback:
        mDrawer.closeDrawers();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(Intent.ACTION_SENDTO,
                        Uri.fromParts("mailto", "easyxkcd@gmail.com", null));
                startActivity(Intent.createChooser(i, getResources().getString(R.string.nav_feedback_send)));
            }
        }, 200);
        return;

    case R.id.nav_about:
        mDrawer.closeDrawers();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(i);
            }
        }, 250);
        return;
    }
    menuItem.setChecked(true);
    mDrawer.closeDrawers();
    mCurrentFragment = menuItem.getItemId();
    invalidateOptionsMenu();
}

From source file:com.woxthebox.draglistview.KanbanBoardView.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    Resources res = getResources();
    boolean isPortrait = res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    if (isPortrait) {
        mColumnWidth = (int) (res.getDisplayMetrics().widthPixels);
    } else {/*  w  w w .j a  v a  2  s .  com*/
        mColumnWidth = (int) (res.getDisplayMetrics().density * 320);
    }

    mGestureDetector = new GestureDetector(getContext(), new GestureListener());
    mColumnGestureListener = new ColumnGestureListener();
    mColumnGestureDetector = new GestureDetector(getContext(), mColumnGestureListener);
    mScroller = new Scroller(getContext(), new DecelerateInterpolator(1.1f));
    mAutoScroller = new AutoScroller(getContext(), this);
    mAutoScroller.setAutoScrollMode(snapToColumnWhenDragging() ? AutoScroller.AutoScrollMode.COLUMN
            : AutoScroller.AutoScrollMode.POSITION);
    mDragItem = new DragItem(getContext());

    mRootLayout = new FrameLayout(getContext());
    mRootLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    mColumnLayout = new LinearLayout(getContext());
    mColumnLayout.setOrientation(LinearLayout.HORIZONTAL);
    mColumnLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    mColumnLayout.setMotionEventSplittingEnabled(false);

    mRootLayout.addView(mColumnLayout);
    mRootLayout.addView(mDragItem.getDragItemView());
    addView(mRootLayout);
}

From source file:org.immopoly.android.widget.ImmoscoutPlacesOverlay.java

public ImmoscoutPlacesOverlay(Fragment fragment, MapView mapView, LayoutInflater inflator,
        boolean isPortfolio) {
    super(boundCenter(fragment.getResources().getDrawable(R.drawable.map_marker_icon)));
    mMapView = mapView;/*w w w  .  j  a  va2  s.co m*/
    this.isPortfolio = isPortfolio;
    mMapFragment = fragment;
    Resources resources = fragment.getResources();
    mapMarkerIcon = boundCenter(resources.getDrawable(R.drawable.map_marker_icon));
    mapMarkerIcon_new = boundCenter(resources.getDrawable(R.drawable.map_marker_icon_new));
    mapMarkerIcon_old = boundCenter(resources.getDrawable(R.drawable.map_marker_icon_old));
    mapMarkerIcon_owned = boundCenter(resources.getDrawable(R.drawable.map_marker_property_icon));
    mapMarkerIcon_cluster = boundCenter(resources.getDrawable(R.drawable.map_marker_icon_cluster));

    markerBounds = mapMarkerIcon.getBounds();

    MIN_INTERSECTION_AREA = (int) (markerBounds.width() * markerBounds.height() * MIN_INTERSECTION_AMOUNT);

    ClusterMarker.init(resources.getDisplayMetrics(), mapMarkerIcon.getIntrinsicHeight());
    gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        public boolean onDoubleTap(MotionEvent e) {
            if (System.currentTimeMillis() - itemTapTime > 500) // hack to prevent zoom for double tap on item
                mMapView.getController().zoomInFixing((int) e.getX(), (int) e.getY());
            return super.onDoubleTap(e);
        }
    });
}

From source file:com.github.pockethub.ui.view.DotPageIndicator.java

/**
 * Instantiates the view and it's values
 * @param context//from   ww w . ja va 2s. c  om
 * @param attrs
 */
public DotPageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (isInEditMode())
        return;

    Resources res = getResources();
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DotPageIndicator, 0, 0);

    try {
        PAINT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColorSelected,
                getColor(res, android.R.color.secondary_text_light, context.getTheme())));

        PAINT_NOT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColor,
                getColor(res, android.R.color.secondary_text_dark, context.getTheme())));

        dotSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, res.getDisplayMetrics());
        dotRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, res.getDisplayMetrics());

        dotRadius = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotRadius, (int) dotRadius);
        dotSpacing = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotSpacing, (int) dotSpacing);
    } finally {
        a.recycle();
    }
    dotAlpha = PAINT_SELECTED.getAlpha();
}

From source file:com.github.pockethub.android.ui.view.DotPageIndicator.java

/**
 * Instantiates the view and it's values
 * @param context/*from www .  ja  v a  2s. c o  m*/
 * @param attrs
 */
public DotPageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (isInEditMode()) {
        return;
    }

    Resources res = getResources();
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DotPageIndicator, 0, 0);

    try {
        PAINT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColorSelected,
                getColor(res, android.R.color.secondary_text_light, context.getTheme())));

        PAINT_NOT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColor,
                getColor(res, android.R.color.secondary_text_dark, context.getTheme())));

        dotSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, res.getDisplayMetrics());
        dotRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, res.getDisplayMetrics());

        dotRadius = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotRadius, (int) dotRadius);
        dotSpacing = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotSpacing, (int) dotSpacing);
    } finally {
        a.recycle();
    }
    dotAlpha = PAINT_SELECTED.getAlpha();
}