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:org.solovyev.android.calculator.widget.CalculatorWidget.java

@TargetApi(JELLY_BEAN)
private int getLayoutJellyBean(@Nonnull AppWidgetManager manager, int widgetId, Resources resources,
        @Nonnull SimpleTheme theme) {/*w  ww .ja  va  2 s  . c om*/
    final Bundle options = manager.getAppWidgetOptions(widgetId);
    if (options == null) {
        return getDefaultLayout(theme);
    }

    final int category = options.getInt(OPTION_APPWIDGET_HOST_CATEGORY, -1);
    if (category == -1) {
        return getDefaultLayout(theme);
    }

    final boolean keyguard = category == WIDGET_CATEGORY_KEYGUARD;
    if (!keyguard) {
        return getDefaultLayout(theme);
    }

    final int widgetMinHeight = App.toPixels(resources.getDisplayMetrics(),
            options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0));
    final int lockScreenMinHeight = resources.getDimensionPixelSize(R.dimen.min_expanded_height_lock_screen);
    final boolean expanded = widgetMinHeight >= lockScreenMinHeight;
    if (expanded) {
        return R.layout.widget_layout_lockscreen;
    } else {
        return R.layout.widget_layout_lockscreen_collapsed;
    }
}

From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java

private void setupCommonViews() {
    if (!isSinglePane) {
        getSupportFragmentManager().addOnBackStackChangedListener(this);

        navContainer = findViewById(R.id.nav_container);
        leftContainer = findViewById(R.id.left_container);
        rightContainer = findViewById(R.id.right_container);

        Resources r = getResources();
        leftWidth = r.getDimensionPixelSize(R.dimen.left_width);
        fullNavWidth = r.getDisplayMetrics().widthPixels;
    }/*  ww  w  .j  a v a 2  s  .  com*/

    measureThingBodyWidth();
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

/** @hide */
@RestrictTo(LIBRARY_GROUP)/*from  w  ww .j  a  v  a2s  . c om*/
void setTextSizeInternal(int unit, float size) {
    Resources res = mContext == null ? Resources.getSystem() : mContext.getResources();

    setRawTextSize(TypedValue.applyDimension(unit, size, res.getDisplayMetrics()));
}

From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java

private void updateAccountOptionsSeparatorLabel(Drawable profileImageSnapshot) {
    final ParcelableAccount account = mAccountsAdapter.getSelectedAccount();
    if (account == null) {
        return;/*from  w w  w  .  j  ava 2 s  .  c  o  m*/
    }
    mAccountProfileNameView.setText(account.name);
    mAccountProfileScreenNameView.setText("@" + account.screen_name);
    mImageLoader.displayDashboardProfileImage(mAccountProfileImageView, account.profile_image_url,
            profileImageSnapshot);
    mAccountProfileImageView.setBorderColors(account.color);
    final int bannerWidth = mAccountProfileBannerView.getWidth();
    final Resources res = getResources();
    final int defWidth = res.getDisplayMetrics().widthPixels;
    final int width = bannerWidth > 0 ? bannerWidth : defWidth;
    final String bannerUrl = Utils.getBestBannerUrl(account.profile_banner_url, width);
    final ImageView bannerView = mAccountProfileBannerView;
    if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(bannerUrl, bannerView.getTag())) {
        mImageLoader.displayProfileBanner(mAccountProfileBannerView, bannerUrl, this);
    }
}

From source file:fr.rolandl.smartshareactionprovider.SmartActivityChooserView.java

/**
 * Create a new instance./*from  w  w  w  .j a  v  a2  s.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 SmartActivityChooserView(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);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.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.dat.towerofhanoi.draggablerecyclerview.BoardView.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 * 0.87);
    } else {//from w  w w.  ja v  a  2  s.  c  o m
        mColumnWidth = (int) (res.getDisplayMetrics().density * 320);
    }

    mGestureDetector = new GestureDetector(getContext(), new GestureListener());
    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:com.example.FilteredActivityChooserView.java

/**
 * Create a new instance./*www . j  a  v a  2s  . 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 FilteredActivityChooserView(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 = (LinearLayout) 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);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.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:chaitanya.im.searchforreddit.LauncherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get and set theme from shared preferences
    sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    theme = sharedPref.getInt(getString(R.string.style_pref_key), 0);
    donate = sharedPref.getInt(getString(R.string.donate_check), 0);
    UtilMethods.onActivityCreateSetTheme(this, theme, SOURCE);

    mServiceConn = new ServiceConnection() {
        @Override/*  w  ww .  j a  va 2 s  . c o m*/
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
            Log.d(TAG, "Service Connected");
            getPrices();
        }
    };

    //ComponentName myService = startService(new Intent(this, LauncherActivity.class));
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

    // IAP stuff
    skuList = new ArrayList<>();
    skuList.add("donate");
    skuList.add("donate2");
    skuList.add("donate3");
    querySkus = new Bundle();
    querySkus.putStringArrayList("ITEM_ID_LIST", skuList);

    setContentView(R.layout.activity_launcher);

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    fontAwesome = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
    dialog = new GenericAlertDialog();
    dialog.setFontAwesome(fontAwesome);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    LinearLayout searchBox = (LinearLayout) findViewById(R.id.search_box);
    searchOptions = (LinearLayout) findViewById(R.id.search_options);
    launcherRefresh = (SwipeRefreshLayout) findViewById(R.id.launcher_refresh);
    searchEditText = (EditText) findViewById(R.id.search_edit_text);
    clearSearchBoxButton = (ImageButton) findViewById(R.id.clearSearchBox);
    //filterButton = (Button) findViewById(R.id.filter_button);
    sortButton = (Button) findViewById(R.id.sort_button);
    timeButton = (Button) findViewById(R.id.time_button);
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.launcher_coordinatorlayout);
    searchOptions.post(new Runnable() {
        @Override
        public void run() {
            searchOptionsCenter = searchOptions.getWidth() / 2;
            if (searchOptions.getVisibility() != View.VISIBLE) {
                UtilMethods.revealView(searchOptions, searchOptionsCenter, 0);
            }
        }
    });
    setSupportActionBar(toolbar);

    searchEditText.setOnKeyListener(onKeyListener);
    searchEditText.setOnTouchListener(searchEditTextTouchListener);

    sortButton.setOnLongClickListener(buttonLongClick);
    timeButton.setOnLongClickListener(buttonLongClick);
    //filterButton.setOnLongClickListener(buttonLongClick);

    rvResults = (RecyclerView) findViewById(R.id.result_view_launcher);
    ResultsAdapter adapter = new ResultsAdapter(resultList, this);
    rvResults.setAdapter(adapter);
    rvResults.setLayoutManager(new LinearLayoutManager(this));
    rvResults.addItemDecoration(new SimpleDividerItemDecoration(this, theme));

    //rvResults.setRecyclerListener(recyclerListener);
    urlSearch = new UrlSearch(BASE_URL, this, 1, adapter);

    // dp -> px : http://stackoverflow.com/a/9563438/1055475
    Resources resources = getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(px * 4);
        searchBox.setElevation(px * 3);
    } else {
        findViewById(R.id.shadow).setVisibility(View.VISIBLE);
        findViewById(R.id.shadow2).setVisibility(View.VISIBLE);
    }
    Log.d(TAG, "OnCreate");
    Log.d(TAG, "searchEditText - " + searchEditText.getText().toString());

    launcherRefresh.setOnRefreshListener(refreshListener);
    launcherRefresh.setColorSchemeResources(R.color.blue_tint, R.color.reddit_orange,
            R.color.material_light_black);

    UtilMethods.getLocation();

    Intent intent = getIntent();
    receiveIntent(intent);
}

From source file:com.coinomi.wallet.ui.widget.ActivityChooserView.java

/**
 * Create a new instance./*  ww  w.  j  av a  2 s.c  om*/
 *
 * @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 = (LinearLayout) 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);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.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.chauthai.overscroll.BouncyAdapter.java

private double dpToPx(double dp) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * ((double) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}