Search in sources :

Example 96 with DisplayMetrics

use of android.util.DisplayMetrics in project zxingfragmentlib by mitoyarzun.

the class CameraConfigurationManager method getScreenOrientation.

// Taken from http://stackoverflow.com/a/10383164/902599
private int getScreenOrientation() {
    int rotation;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getRotation();
    } else {
        rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getOrientation();
    }
    DisplayMetrics dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    int orientation;
    // if the device's natural orientation is portrait:
    if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) {
        switch(rotation) {
            case Surface.ROTATION_0:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
            case Surface.ROTATION_90:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.ROTATION_180:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                break;
            case Surface.ROTATION_270:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                break;
            default:
                Log.e(TAG, "Unknown screen orientation. Defaulting to " + "portrait.");
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
        }
    } else // if the device's natural orientation is landscape or if the device
    // is square:
    {
        switch(rotation) {
            case Surface.ROTATION_0:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.ROTATION_90:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
            case Surface.ROTATION_180:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                break;
            case Surface.ROTATION_270:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                break;
            default:
                Log.e(TAG, "Unknown screen orientation. Defaulting to " + "landscape.");
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }
    Log.v(TAG, "Orientation: " + orientation);
    return orientation;
}
Also used : PreferencesActivity(com.google.zxing.client.android.PreferencesActivity) Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics) Point(android.graphics.Point)

Example 97 with DisplayMetrics

use of android.util.DisplayMetrics in project AboutLibraries by mikepenz.

the class UIUtils method convertPixelsToDp.

/**
     * This method converts device specific pixels to density independent pixels.
     *
     * @param px      A value in px (pixels) unit. Which we need to convert into db
     * @param context Context to get resources and device specific display metrics
     * @return A float value to represent dp equivalent to px value
     */
public static float convertPixelsToDp(float px, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float dp = px / (metrics.densityDpi / 160f);
    return dp;
}
Also used : Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 98 with DisplayMetrics

use of android.util.DisplayMetrics in project LollipopShowcase by mikepenz.

the class AppInfo method getEnglishRessources.

public Resources getEnglishRessources(Resources standardResources) {
    AssetManager assets = standardResources.getAssets();
    DisplayMetrics metrics = standardResources.getDisplayMetrics();
    Configuration config = new Configuration(standardResources.getConfiguration());
    config.locale = Locale.US;
    return new Resources(assets, metrics, config);
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 99 with DisplayMetrics

use of android.util.DisplayMetrics in project AndroidDynamicLoader by mmin18.

the class ImageDetailFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mImageUrl = getActivity().getIntent().getStringExtra("imageUrl");
    // Fetch screen height and width, to use as our max size when loading images as this
    // activity runs full screen
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;
    // For this sample we'll use half of the longest width to resize our images. As the
    // image scaling ensures the image is larger than this, we should be left with a
    // resolution that is appropriate for both portrait and landscape. For best image quality
    // we shouldn't divide by 2, but this will use more memory and require a larger memory
    // cache.
    final int longest = (height > width ? height : width) / 2;
    ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(getActivity(), IMAGE_CACHE_DIR);
    // Set memory cache to 25% of app memory
    cacheParams.setMemCacheSizePercent(0.25f);
    // The ImageFetcher takes care of loading images into our ImageView children asynchronously
    mImageFetcher = new ImageFetcher(getActivity(), longest);
    mImageFetcher.addImageCache(getFragmentManager(), cacheParams);
    mImageFetcher.setImageFadeIn(false);
    if (!TextUtils.isEmpty(mImageUrl)) {
        mImageFetcher.loadImage(mImageUrl, mImageView);
    }
    // Set up activity to go full screen
    getActivity().getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
    // Enable some additional newer visibility and ActionBar features to create a more
    // immersive photo viewing experience
    final ActionBar actionBar = getActivity().getActionBar();
    // Hide title text and set home as up
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    // Start low profile mode and hide ActionBar
    mImageView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    actionBar.hide();
    mImageView.setOnClickListener(this);
}
Also used : ImageFetcher(com.example.android.bitmapfun.util.ImageFetcher) ImageCache(com.example.android.bitmapfun.util.ImageCache) DisplayMetrics(android.util.DisplayMetrics) ActionBar(android.app.ActionBar)

Example 100 with DisplayMetrics

use of android.util.DisplayMetrics in project qksms by moezbhatti.

the class Units method pxToDp.

/**
     * Converts pixels to dp.
     */
public static int pxToDp(Context context, int px) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return dp;
}
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