Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

In this page you can find the example usage for android.view Display getWidth.

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

public static void showAboutDialog(final Context mContext) {
    LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = li.inflate(R.layout.about, null);

    String sVersionInfo = "";
    try {//  w w w.  j  a v  a 2  s .c  om
        PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
        sVersionInfo += pi.versionName;
        if (!pi.versionName.contains("" + pi.versionCode))
            sVersionInfo += " (" + pi.versionCode + ")";
        if (OpenExplorer.IS_DEBUG_BUILD)
            sVersionInfo += " *debug*";
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String sBuildTime = "";
    try {
        sBuildTime = SimpleDateFormat.getInstance()
                .format(new Date(new ZipFile(
                        mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0).sourceDir)
                                .getEntry("classes.dex").getTime()));
    } catch (Exception e) {
        Logger.LogError("Couldn't get Build Time.", e);
    }

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    Display d = wm.getDefaultDisplay();
    String sHardwareInfo = "Display:\n";
    sHardwareInfo += "Size: " + d.getWidth() + "x" + d.getHeight() + "\n";
    if (dm != null)
        sHardwareInfo += "Density: " + dm.density + "\n";
    sHardwareInfo += "Rotation: " + d.getRotation() + "\n\n";
    sHardwareInfo += getNetworkInfo(mContext);
    sHardwareInfo += getDeviceInfo();
    ((TextView) view.findViewById(R.id.about_hardware)).setText(sHardwareInfo);

    final String sSubject = "Feedback for OpenExplorer " + sVersionInfo;
    OnClickListener email = new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            //intent.addCategory(Intent.CATEGORY_APP_EMAIL);
            intent.putExtra(android.content.Intent.EXTRA_TEXT, "\n" + getDeviceInfo());
            intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "brandroid64@gmail.com" });
            intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sSubject);
            mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.s_chooser_email)));
        }
    };
    OnClickListener viewsite = new OnClickListener() {
        public void onClick(View v) {
            mContext.startActivity(
                    new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://brandroid.org/open/")));
        }
    };
    view.findViewById(R.id.about_email).setOnClickListener(email);
    view.findViewById(R.id.about_email_btn).setOnClickListener(email);
    view.findViewById(R.id.about_site).setOnClickListener(viewsite);
    view.findViewById(R.id.about_site_btn).setOnClickListener(viewsite);
    final View mRecentLabel = view.findViewById(R.id.about_recent_status_label);
    final WebView mRecent = (WebView) view.findViewById(R.id.about_recent);
    final OpenChromeClient occ = new OpenChromeClient();
    occ.mStatus = (TextView) view.findViewById(R.id.about_recent_status);
    mRecent.setWebChromeClient(occ);
    mRecent.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            occ.mStatus.setVisibility(View.GONE);
            mRecent.setVisibility(View.GONE);
            mRecentLabel.setVisibility(View.GONE);
        }
    });
    mRecent.setBackgroundColor(Color.TRANSPARENT);
    mRecent.loadUrl("http://brandroid.org/open/?show=recent");

    ((TextView) view.findViewById(R.id.about_version)).setText(sVersionInfo);
    if (sBuildTime != "")
        ((TextView) view.findViewById(R.id.about_buildtime)).setText(sBuildTime);
    else
        ((TableRow) view.findViewById(R.id.row_buildtime)).setVisibility(View.GONE);

    fillShortcutsTable((TableLayout) view.findViewById(R.id.shortcuts_table));

    final View tab1 = view.findViewById(R.id.tab1);
    final View tab2 = view.findViewById(R.id.tab2);
    final View tab3 = view.findViewById(R.id.tab3);
    ((Button) view.findViewById(R.id.btn_recent)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setVisibility(View.VISIBLE);
            tab2.setVisibility(View.GONE);
            tab3.setVisibility(View.GONE);
        }
    });
    ((Button) view.findViewById(R.id.btn_hardware)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setVisibility(View.GONE);
            tab2.setVisibility(View.VISIBLE);
            tab3.setVisibility(View.GONE);
        }
    });
    ((Button) view.findViewById(R.id.btn_shortcuts)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tab1.setVisibility(View.GONE);
            tab2.setVisibility(View.GONE);
            tab3.setVisibility(View.VISIBLE);
        }
    });

    AlertDialog mDlgAbout = new AlertDialog.Builder(mContext).setTitle(R.string.app_name).setView(view)
            .create();

    mDlgAbout.getWindow().getAttributes().windowAnimations = R.style.SlideDialogAnimation;
    mDlgAbout.getWindow().getAttributes().alpha = 0.9f;

    mDlgAbout.show();
}

From source file:Main.java

public static int getFullScreenSizeHeight(Context context) {
    int realWidth;
    int realHeight;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point point = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        //new pleasant way to get real metrics
        DisplayMetrics realMetrics = new DisplayMetrics();
        display.getRealMetrics(realMetrics);
        realWidth = realMetrics.widthPixels;
        realHeight = realMetrics.heightPixels;

    } else if (Build.VERSION.SDK_INT >= 14) {
        //reflection for this weird in-between time
        try {/* www.  j  av a 2  s .  c o m*/
            Method mGetRawH = Display.class.getMethod("getRawHeight");
            Method mGetRawW = Display.class.getMethod("getRawWidth");
            realWidth = (Integer) mGetRawW.invoke(display);
            realHeight = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            //this may not be 100% accurate, but it's all we've got
            realWidth = display.getWidth();
            realHeight = display.getHeight();
            Log.e("Display Info", "Couldn't use reflection to get the real display metrics.");
        }

    } else {
        //This should be close, as lower API devices should not have window navigation bars
        realWidth = display.getWidth();
        realHeight = display.getHeight();
    }
    return realHeight;
}

From source file:Main.java

public static int getFullScreenSizeWidth(Context context) {
    int realWidth;
    int realHeight;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point point = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        //new pleasant way to get real metrics
        DisplayMetrics realMetrics = new DisplayMetrics();
        display.getRealMetrics(realMetrics);
        realWidth = realMetrics.widthPixels;
        realHeight = realMetrics.heightPixels;

    } else if (Build.VERSION.SDK_INT >= 14) {
        //reflection for this weird in-between time
        try {//  w  w w.j a v  a  2 s  .  c o  m
            Method mGetRawH = Display.class.getMethod("getRawHeight");
            Method mGetRawW = Display.class.getMethod("getRawWidth");
            realWidth = (Integer) mGetRawW.invoke(display);
            realHeight = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            //this may not be 100% accurate, but it's all we've got
            realWidth = display.getWidth();
            realHeight = display.getHeight();
            Log.e("Display Info", "Couldn't use reflection to get the real display metrics.");
        }

    } else {
        //This should be close, as lower API devices should not have window navigation bars
        realWidth = display.getWidth();
        realHeight = display.getHeight();
    }
    return realWidth;
}

From source file:com.apptentive.android.sdk.util.Util.java

public static Point getScreenSize(Context context) {
    Point ret = new Point();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    // TODO: getWidth(), getHeight(), and getOrientation() are deprecated in API 13 in favor of getSize() and getRotation().
    ret.set(display.getWidth(), display.getHeight());
    return ret;/*w w w  .ja v a2 s.  c o  m*/
}

From source file:com.pdftron.pdf.utils.Utils.java

/**
 * Gets the size of the display, in pixels.
 *
 * @param context the Context//  w w w  . j a va2s .  c  o m
 * @param outSize A Point object to receive the size information
 */
public static void getDisplaySize(Context context, Point outSize) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (outSize == null) {
        outSize = new Point();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(outSize);
    } else {
        outSize.set(display.getWidth(), display.getHeight());
    }
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static int getDisplayWidth(Context ctx) {
    final Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    return display.getWidth();
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Get Display Width//from w ww  . j a  v a 2  s.  c  o m
 *
 * @param context Application context
 * @return
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static int getDisplayWidth(Context context) {
    Activity activity = (Activity) context;
    if (Integer.valueOf(Build.VERSION.SDK_INT) < 13) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        return display.getWidth();
    } else {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size.x;
    }
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static Point getDisplaySize(Context ctx) {
    Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    size.x = display.getWidth();
    size.y = display.getHeight();/*  www  .  ja v a2s.  c om*/
    return size;
}

From source file:com.pickr.tasks.PhotoLoader.java

@Override
protected Bitmap doInBackground() {
    try {/*ww w.ja  va  2 s  . com*/
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        int resolution = display.getWidth() * display.getHeight();

        Flickr flickr = FlickrHandler.getFlickr();
        List<PhotoSize> sizes = flickr.getPhotosService().getSizes(mPhoto);

        return loadBitmap(PhotoSizeWeight.getOptimalPhotoSize(sizes, resolution), display);

    } catch (Throwable ex) {
        ex.printStackTrace();
        LOGGER.e("Error loading photo", ex);
    }
    return null;
}

From source file:org.kaaproject.kaa.demo.smarthousedemo.device.QrcodeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_qrcode, container, false);

    Bundle args = this.getArguments();
    String contents = args.getString(QR_CONTENTS);
    String contentsDesc = args.getString(QR_CONTENTS_DESCRIPTION);

    WindowManager manager = (WindowManager) getActivity().getSystemService(Activity.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int smallerDimension = width < height ? width : height;
    smallerDimension = smallerDimension * 7 / 8;

    qrCodeEncoder = new QRCodeEncoder(contents, smallerDimension);
    try {/*  w  w w  . j  a v a2 s  .com*/
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        if (bitmap == null) {
            Log.w(TAG, "Could not encode barcode");
            showErrorMessage(R.string.msg_encode_contents_failed);
            qrCodeEncoder = null;
            return rootView;
        }
        ImageView view = (ImageView) rootView.findViewById(R.id.image_view);
        view.setImageBitmap(bitmap);
        TextView contentsView = (TextView) rootView.findViewById(R.id.contents_text_view);
        contentsView.setText(contentsDesc);
    } catch (WriterException e) {
        Log.w(TAG, "Could not encode barcode", e);
        showErrorMessage(R.string.msg_encode_contents_failed);
        qrCodeEncoder = null;
    }
    return rootView;
}