Example usage for android.util DisplayMetrics DENSITY_DEFAULT

List of usage examples for android.util DisplayMetrics DENSITY_DEFAULT

Introduction

In this page you can find the example usage for android.util DisplayMetrics DENSITY_DEFAULT.

Prototype

int DENSITY_DEFAULT

To view the source code for android.util DisplayMetrics DENSITY_DEFAULT.

Click Source Link

Document

The reference density used throughout the system.

Usage

From source file:com.zns.comicdroid.activity.Comics.java

private int dpToPx(int dp) {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*from   ww w  .  j  av a2 s. c o m*/
}

From source file:com.fastbootmobile.encore.utils.Utils.java

public static int dpToPx(Resources res, int dp) {
    final DisplayMetrics displayMetrics = res.getDisplayMetrics();
    return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}

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/*from   w ww.  j ava 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.nextgis.maplibui.util.ControlHelper.java

public static int dpToPx(int dp, Resources resources) {
    DisplayMetrics dm = resources.getDisplayMetrics();
    return Math.round(dp * (dm.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}

From source file:watch.oms.omswatch.application.OMSApplication.java

/**
 * Checks if the device is a tablet or a phone
 * //from   ww w. j a  va2  s. c o  m
 * @param
 *
 * @return Returns true if the device is a Tablet
 */
public boolean isTabletDevice() {
    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge = ((activity.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);

    // If XLarge, checks if the Generalized Density is at least MDPI
    // (160dpi)
    if (xlarge) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
        // DENSITY_TV=213, DENSITY_XHIGH=320
        if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {

            // Yes, this is a tablet!
            return true;
        }
    }
    return false;
}

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

@SuppressLint("NewApi")
private float dp2px(float dp) {
    DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
    return Math.round(dp * (displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}

From source file:com.qingsongchou.library.widget.tab.PagerSlidingTabStrip.java

public static float getScreenDensity(Context context) {
    try {//from   w w w  . j  ava2s .c  o m
        DisplayMetrics dm = new DisplayMetrics();
        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
        return dm.density;
    } catch (Exception e) {
        return DisplayMetrics.DENSITY_DEFAULT;
    }
}

From source file:com.xee.auth.SignInButton.java

/**
 * Convert do to px/*from w ww  .j a v a 2  s  . co m*/
 *
 * @param dp the dp to convert
 * @return
 */
private int dpToPx(int dp) {
    DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
    return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}

From source file:com.amaze.filemanager.fragments.Main.java

public int dpToPx(int dp) {
    if (displayMetrics == null)
        displayMetrics = getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;//from  ww  w .  ja v  a2  s. co m
}

From source file:com.filemanager.free.fragments.Main.java

public int dpToPx(int dp) {
    if (displayMetrics == null)
        displayMetrics = getResources().getDisplayMetrics();
    return round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}