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.github.chenxiaolong.dualbootpatcher.switcher.MbtoolTaskOutputFragment.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  .j  a v  a 2 s . c o  m

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

    Parcelable[] parcelables = getArguments().getParcelableArray(PARAM_ACTIONS);
    mActions = Arrays.copyOf(parcelables, parcelables.length, MbtoolAction[].class);

    int titleResId = -1;

    int countBackup = 0;
    int countRestore = 0;
    int countFlash = 0;

    for (MbtoolAction a : mActions) {
        switch (a.getType()) {
        case ROM_INSTALLER:
            countFlash++;
            break;
        case BACKUP_RESTORE:
            switch (a.getBackupRestoreParams().getAction()) {
            case BACKUP:
                countBackup++;
                break;
            case RESTORE:
                countRestore++;
                break;
            }
            break;
        }
    }

    if (countBackup + countRestore + countFlash > 1) {
        titleResId = R.string.in_app_flashing_title_flash_files;
    } else if (countBackup > 0) {
        titleResId = R.string.in_app_flashing_title_backup_rom;
    } else if (countRestore > 0) {
        titleResId = R.string.in_app_flashing_title_restore_rom;
    } else if (countFlash > 0) {
        titleResId = R.string.in_app_flashing_title_flash_file;
    }

    if (titleResId >= 0) {
        getActivity().setTitle(titleResId);
    }
}

From source file:io.selendroid.server.model.SelendroidNativeDriver.java

public Dimension getWindowSize() {
    DisplayMetrics metrics = new DisplayMetrics();
    serverInstrumentation.getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

    return new Dimension(metrics.widthPixels, metrics.heightPixels);
}

From source file:jp.seikeidenron.androidtv.common.Utils.java

public static int getDisplayWidthInPx(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics.widthPixels;
}

From source file:com.nike.plusgps.nikeplusgallery.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    dbHelper = new DBHelper(this); // Creates the database
    dbHelper.deleteAllResponse(); // Clears the JSON response cache
    dbHelper.deleteAllMedia(); // Clears the JSON images cache

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final int memClass = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/*  www .j av  a2 s . c  o m*/
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in bytes rather than number of items.
            return bitmap.getByteCount();
        }
    };

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

        setContentView(R.layout.activity_main_port);
        GridView view = (GridView) findViewById(R.id.gridView);
        flickrFeedList = new ArrayList<FlickrFeed>();
        new JSONParser()
                .execute("http://api.flickr.com/services/feeds/photos_public.gne?tags=nike&format=json");
        adapter = new FlickrFeedAdapter(getApplicationContext(), R.layout.single_elem_port, flickrFeedList,
                dbHelper, mMemoryCache);
        view.setAdapter(adapter);

    } else {

        setContentView(R.layout.activity_main_land);
        carouselElement = (LinearLayout) findViewById(R.id.carousel);
        // Compute width of a carousel item based on screen width and initial item count
        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);

        ImageView imageItem;
        String imgURL;
        for (int i = 0; i < flickrFeedList.size(); ++i) {
            imageItem = new ImageView(this);
            imgURL = flickrFeedList.get(i).getMedia();
            new DownloadImageTask(imageItem).execute(imgURL);
            imageItem.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageWidth));
            carouselElement.addView(imageItem);
        }
    }
}

From source file:jp.seikeidenron.androidtv.common.Utils.java

public static int getDisplayHeightInPx(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics.heightPixels;
}

From source file:org.openremote.android.console.Main.java

/**
 * Read display metrics.// w  ww.  ja v a  2  s  .c om
 * Include screen width and height.
 */
private void readDisplayMetrics() {
    DisplayMetrics dm = new DisplayMetrics();
    dm = getApplicationContext().getResources().getDisplayMetrics();
    Screen.SCREEN_WIDTH = dm.widthPixels;
    Screen.SCREEN_HEIGHT = dm.heightPixels;
}

From source file:net.evecom.androidecssp.base.BaseWebActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    temp = HttpUtil.getPageSize(this);
    setContentView(R.layout.message_post_web);
    // dialog = ProgressDialog.show(BaseWebActivity.this, null,
    // "..");//from  ww  w .j  a va 2  s. com
    // dialog.setCancelable(true);

    lineProgressBar = (ProgressBar) findViewById(R.id.webview_progress_id);
    imageView = (ImageView) findViewById(R.id.image_view_at_web);
    webView = (WebView) this.findViewById(R.id.wv_oauth_message);
    CookieSyncManager.createInstance(this);
    CookieSyncManager.getInstance().startSync();
    CookieManager.getInstance().removeSessionCookie();

    webView.setWebViewClient(new BaseWebViewClient((BaseWebActivity) instance));
    webView.setWebChromeClient(new BaseChromeClient((BaseWebActivity) instance));

    // 
    webView.setDownloadListener(new MyWebViewDownLoadListener());
    WebSettings webSettings = webView.getSettings();
    webSettings.setSupportZoom(true);
    // WebViewJavaScript
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);// support zoom
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    /**  */
    // //
    webSettings.setDatabaseEnabled(true);
    String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    // 
    webSettings.setGeolocationEnabled(true);
    // 
    webSettings.setGeolocationDatabasePath(dir);
    // 
    webSettings.setDomStorageEnabled(true);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    if (mDensity == 240) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == 160) {
        webSettings.setDefaultZoom(ZoomDensity.MEDIUM);
    } else if (mDensity == 120) {
        webSettings.setDefaultZoom(ZoomDensity.CLOSE);
        // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){
        // webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == DisplayMetrics.DENSITY_HIGH) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    }

    dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0")
            .setPositiveButton("", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();

    webView.addJavascriptInterface(new JsInterface(getApplicationContext()), "androidbase");
    String url = HttpUtil.getPCURL() + "jfs/mobile/androidIndex/jqmobileTest";
    // post
    // webView.postUrl(url, postData) postDatabyte[] 
    // EncodingUtils.getBytes("&pwd=888", charset)
    webView.postUrl(url, EncodingUtils.getBytes("", "BASE64"));

}

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

/**
 * This method creates a popup window when a level is unlocked
 *//*from w w  w.  jav a2  s. com*/
public void PopupWindowLevel() {

    try {

        LayoutInflater inflater = (LayoutInflater) CategoryScreenActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.popup_level, (ViewGroup) findViewById(R.id.popup_element));
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        pwindowLevel = new PopupWindow(layout, metrics.widthPixels, metrics.heightPixels, true);
        pwindowLevel.showAtLocation(layout, Gravity.CENTER, 0, 0);
        btnClosePopupLevel = (ImageView) layout.findViewById(R.id.btn_close_popup);
        btnClosePopupLevel.setOnClickListener(cancel_popup_level);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.example.camera360.ui.ImageDetailActivity.java

@SuppressWarnings("unchecked")
@TargetApi(11)//  ww w. j  a  v a  2s  .  com
@Override
public void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG) {
        Utils.enableStrictMode();
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_detail_pager);

    arrayList = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra(IMAGE_URL);

    // Fetch screen height and width, to use as our max size when loading
    // images as this
    // activity runs full screen

    baseAnimate = new BaseAnimate();

    final DisplayMetrics displayMetrics = new DisplayMetrics();
    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(this, IMAGE_CACHE_DIR);
    cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of
    // app memory

    mImageDetailLayout = (FrameLayout) findViewById(R.id.image_detail_layout);

    mImageDetailView = (LinearLayout) findViewById(R.id.image_detail);

    // The ImageFetcher takes care of loading images into our ImageView
    // children asynchronously
    mImageFetcher = new ImageFetcher(this, longest);
    mImageFetcher.addImageCache(getSupportFragmentManager(), cacheParams);
    mImageFetcher.setImageFadeIn(false);

    // Set up ViewPager and backing adapter
    mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), arrayList.size());

    mInflater = LayoutInflater.from(mImageDetailLayout.getContext());

    mPager = (ViewPager) findViewById(R.id.view_pager);
    mPager.setAdapter(mAdapter);
    mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin));
    mPager.setOffscreenPageLimit(2);

    // 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.hasHoneycomb()) {
        final ActionBar actionBar = getActionBar();

        // Hide title text and set home as up
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);

        // 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();
                }
            }
        });

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

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

    currentIndex = extraCurrentItem;

    if (extraCurrentItem != -1) {
        mPager.setCurrentItem(extraCurrentItem);
    }

    mPager.setOnPageChangeListener(new ImageOnPageChangeListener());

    initHeaderMenu();

    addFooterMenu();

    initImageDetail();

    setImageInfo();
}

From source file:com.felkertech.n.tv.fragments.VideoDetailsFragment.java

private void prepareBackgroundManager() {
    mBackgroundManager = BackgroundManager.getInstance(getActivity());
    mBackgroundManager.attach(getActivity().getWindow());
    mDefaultBackground = getResources().getDrawable(R.drawable.c_background5);
    mMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
}