Example usage for android.util DisplayMetrics DisplayMetrics

List of usage examples for android.util DisplayMetrics DisplayMetrics

Introduction

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

Prototype

public DisplayMetrics() 

Source Link

Usage

From source file:com.morphoss.jumble.frontend.CategoryScreenActivity.java

@Override
protected void onResume() {
    super.onResume();
    myApp.resumeMusic();/*from   w ww.  j ava2 s  .c o m*/
    if (!Category.unlockedCategories.isEmpty()) {
        DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int height = displaymetrics.heightPixels;
        int width = displaymetrics.widthPixels;
        pga = new CategoryGridAdapter(this, width, height);
        new LoadCategoryTask().execute();
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                // Show the popup window of an unlocked level after 0.5s =
                // 500ms
                if (!Category.unlockedCategories.isEmpty()) {
                    PopupWindowLevel();
                }

            }
        }, 500);
    }
}

From source file:com.google.zxing.client.android.history.HistoryActivity.java

@Override
public void pegaScreenResolution() {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int height = metrics.heightPixels;
    int width = metrics.widthPixels;
    Log.i("Script", " Tela do dispositivo - " + height + "x" + width);
    // pegar - largura por altura
    if (width <= 780 && height <= 1080) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    } else {/*from www .j  a va  2  s.co m*/
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }

}

From source file:com.manning.androidhacks.hack040.ImageDetailActivity.java

@SuppressLint("NewApi")
@Override/* w w w.j a  v  a 2s  . c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_detail_pager);

    // 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();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    final int height = displaymetrics.heightPixels;
    final int width = displaymetrics.widthPixels;
    final int longest = height > width ? height : width;

    // The ImageWorker takes care of loading images into our ImageView children
    // asynchronously
    mImageWorker = new ImageFetcher(this, longest);
    mImageWorker.setAdapter(Images.imageWorkerUrlsAdapter);
    mImageWorker.setImageCache(ImageCache.findOrCreateCache(this, IMAGE_CACHE_DIR));
    mImageWorker.setImageFadeIn(false);

    // Set up ViewPager and backing adapter
    mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), mImageWorker.getAdapter().getSize());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);
    mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin));

    // Set up activity to go full screen
    getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);

    // Enable some additional newer visibility and ActionBar features to create
    // a more immersive
    // photo viewing experience
    if (Utils.hasActionBar()) {
        final ActionBar actionBar = getActionBar();

        // Enable "up" navigation on ActionBar icon and hide title text
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);

        // Start low profile mode and hide ActionBar
        mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        actionBar.hide();

        // Hide and show the ActionBar as the visibility changes
        mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int vis) {
                if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
                    actionBar.hide();
                } else {
                    actionBar.show();
                }
            }
        });
    }

    // Set the current item based on the extra passed in to this activity
    final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1);
    if (extraCurrentItem != -1) {
        mPager.setCurrentItem(extraCurrentItem);
    }
}

From source file:com.yi4all.rupics.ImageDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_detail_pager);

    util = new DownloadUtil();

    default_image = BitmapFactory.decodeResource(getResources(), R.drawable.download_32);
    no_image = BitmapFactory.decodeResource(getResources(), R.drawable.no_image);

    // 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();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;

    // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

    SCREEN_WIDTH = width;//from   ww  w.  ja  v a2  s.  co m
    SCREEN_HEIGHT = height;

    issue = (IssueModel) getIntent().getSerializableExtra("issue");

    // Set up activity to go full screen
    getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);

    initBtn();

    refreshData();

}

From source file:com.free.underground.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.i("mycode", "MainActivity onCreate");
    //loadCategories();

    mTitle = mDrawerTitle = getTitle();//from   www . j  a v  a 2  s . c o  m
    mMenuTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        Log.i("mycode", "MainActivity selectItem");
        selectItem(0);
    }

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int width = metrics.widthPixels;
    Log.i("mycode", "width " + width);
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.ZipFlashingOutputFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mEmulatorView = (EmulatorView) getActivity().findViewById(R.id.terminal);
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mEmulatorView.setDensity(metrics);//from w ww  .  ja  v a2 s.  c om

    if (savedInstanceState != null) {
        mIsRunning = savedInstanceState.getBoolean(EXTRA_IS_RUNNING);
    }
}

From source file:app.hanks.com.conquer.activity.LoginActivity.java

private void showAnim() {
    int DURATION = 400;

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    ////www.j  ava  2 s.  c o m
    bg.animate().translationY(-metrics.heightPixels + PixelUtil.dp2px(220)).setDuration(DURATION).start();

    line.animate().scaleX(1).setDuration(DURATION).setStartDelay(DURATION).start();

    welcome.animate().alpha(1).setDuration(DURATION).setStartDelay(DURATION).start();

    bottom.animate().alpha(1).setDuration(DURATION).setStartDelay(DURATION).start();

}

From source file:com.abiansoftware.lib.reader.AbianReaderApplication.java

@Override
public void onCreate() {
    s_singleton = this;

    ImageLoader theImageLoader = ImageLoader.getInstance();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 1).memoryCacheSize(2 * 1024 * 1024)
            .denyCacheImageMultipleSizesInMemory()
            //.enableLogging()
            .build();//from ww  w .  j a  v a  2 s  .c  o  m

    theImageLoader.init(config);

    s_asyncHttpClient = new AsyncHttpClient();
    s_asyncHttpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

    m_data = new AbianReaderData();
    m_dataFetcher = new AbianReaderDataFetcher();

    WindowManager theWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display theDefaultDisplay = theWindowManager.getDefaultDisplay();

    DisplayMetrics theDisplayMetrics = new DisplayMetrics();
    theDefaultDisplay.getMetrics(theDisplayMetrics);
    s_width = theDisplayMetrics.widthPixels;
    s_height = theDisplayMetrics.heightPixels;

    m_handlerVector = new Vector<Handler>();
    m_adapterVector = new Vector<BaseAdapter>();

    m_bSplashScreenHasBeenShown = false;

    m_readUrlArrayList = null;

    loadReadUrlList();

    super.onCreate();
}

From source file:fr.cph.stock.android.activity.ChartActivity.java

/**
 * //from w  w  w . j a  va2 s  .  c o m
 * @return
 */
private String getData() {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    String data = null;
    try {
        InputStream is = null;
        StringWriter writer = new StringWriter();
        switch (chartType) {
        case CAPITALIZATION:
            is = getApplicationContext().getAssets().open("www/pie.html");
            IOUtils.copy(is, writer, "UTF8");
            data = writer.toString();
            data = data.replace("#DATA#", portfolio.getChartCapData());
            data = data.replace("#TITLE#", portfolio.getChartCapTitle());
            data = data.replace("#DRAW#", portfolio.getChartCapDraw());
            data = data.replace("#COMPANIES#", portfolio.getChartCapCompanies());
            data = data.replaceAll("#WIDTH#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            data = data.replaceAll("#HEIGHT#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            actionBar.setTitle("Capitalization Chart");
            webView.setHorizontalScrollBarEnabled(false);
            break;
        case SECTOR:
            is = getApplicationContext().getAssets().open("www/pie.html");
            IOUtils.copy(is, writer, "UTF8");
            data = writer.toString();
            data = data.replace("#DATA#", portfolio.getChartSectorData());
            data = data.replace("#TITLE#", portfolio.getChartSectorTitle());
            data = data.replace("#DRAW#", portfolio.getChartSectorDraw());
            data = data.replace("#COMPANIES#", portfolio.getChartSectorCompanies());
            data = data.replaceAll("#WIDTH#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            data = data.replaceAll("#HEIGHT#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            actionBar.setTitle("Sector Chart");
            webView.setHorizontalScrollBarEnabled(false);
            break;
        case SHARE_VALUE:
            is = getApplicationContext().getAssets().open("www/share_value.html");
            IOUtils.copy(is, writer, "UTF8");
            data = writer.toString();
            data = data.replace("#DATA#", portfolio.getChartData());
            data = data.replace("#DRAW#", portfolio.getChartDraw());
            data = data.replace("#COLOR#", portfolio.getChartColors());
            data = data.replace("#DATE#", portfolio.getChartDate());
            data = data.replaceAll("#WIDTH#", ((int) (metrics.widthPixels / metrics.density)) - 30 + "");
            data = data.replaceAll("#HEIGHT#", (int) (metrics.heightPixels / metrics.density / 1.35) + "");
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            actionBar.setTitle("Share Value Chart");
            break;
        }
    } catch (IOException e) {
        Log.e(TAG, "", e);
    }
    return data;
}

From source file:com.intel.xdk.base.Base.java

public void showSplashScreen() {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            //treat displays larger than 6" as tablets
            DisplayMetrics dm = new DisplayMetrics();
            cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
            double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
            double screenInches = Math.sqrt(x + y);
            if (screenInches > 6) {
                isTablet = true;/*from   w w w.  j a va2s .  com*/
            }

            //used for calculating status bar height
            int deviceWidth = dm.widthPixels;
            int deviceHeight = dm.heightPixels;
            if (deviceWidth > deviceHeight) {
                deviceWidth = dm.heightPixels;
                deviceHeight = dm.widthPixels;
            }

            //get the splash screen image from asssets
            Bitmap bm = null;
            try {
                if (isTablet) {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen_tablet.jpg");
                } else {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen.jpg");
                }
            } catch (IOException ioe) {
            }

            //if the splash screen assets are missing, don't try to show the splash screen
            if (bm == null) {
                return;
            }

            if (Debug.isDebuggerConnected())
                Log.i("[intel.xdk]", "splash");

            ActivityInfo ai = null;
            int splashViewId = 0;
            try {
                ai = cordova.getActivity().getPackageManager().getActivityInfo(
                        cordova.getActivity().getComponentName(),
                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);

                if (isTablet) {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet_ls",
                                "layout", cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet",
                                "layout", cordova.getActivity().getPackageName());
                    }
                } else {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_ls", "layout",
                                cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash", "layout",
                                cordova.getActivity().getPackageName());
                    }
                }
                LayoutInflater inflater = LayoutInflater.from(cordova.getActivity());
                splashView = inflater.inflate(splashViewId, null);

                //set the splash screen image
                //http://stackoverflow.com/questions/7776445/in-android-can-i-use-image-from-assets-in-layout-xml
                ImageView backgroundImage = (ImageView) splashView
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                backgroundImage.setImageBitmap(bm);
                ((ViewGroup) root.getParent()).addView(splashView);
                splashView.bringToFront();

                //hack to fix splash screen size when it is smaller than screen            
                ImageView splashImage = (ImageView) cordova.getActivity()
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                LayoutParams params = splashImage.getLayoutParams();
                Rect imgBounds = splashImage.getDrawable().getBounds();
                int splashHeight = params.height;
                int splashWidth = params.width;

                //make copies in case we have to switch for landscape - not sure if needed, this is a last minute hack
                int deviceWidthCopy, deviceHeightCopy;
                deviceWidthCopy = deviceWidth;
                deviceHeightCopy = deviceHeight;
                if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                    int temp = deviceWidthCopy;
                    deviceWidthCopy = deviceHeightCopy;
                    deviceHeightCopy = temp;
                }
                if (splashHeight < deviceHeightCopy || splashWidth < deviceWidthCopy) {
                    float scaleH = (float) deviceHeightCopy / splashHeight;
                    float scaleW = (float) deviceWidthCopy / splashWidth;
                    float scale = Math.max(scaleH, scaleW);
                    params.height *= scale;
                    params.width *= scale;
                    splashImage.setLayoutParams(params);
                }

                cordova.getActivity().setProgressBarIndeterminateVisibility(true);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}