Example usage for android.view Display getSize

List of usage examples for android.view Display getSize

Introduction

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

Prototype

public void getSize(Point outSize) 

Source Link

Document

Gets the size of the display, in pixels.

Usage

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

@Override
@SuppressWarnings("deprecation")
public byte[] takeScreenshot() {
    ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance();

    // TODO ddary review later, but with getRecentDecorView() it seems to work better
    // long drawingTime = 0;
    // View container = null;
    // for (View view : viewAnalyzer.getTopLevelViews()) {
    // if (view != null && view.isShown() && view.hasWindowFocus()
    // && view.getDrawingTime() > drawingTime) {
    // container = view;
    // drawingTime = view.getDrawingTime();
    // }// w  ww .  j a va 2 s  . c  o m
    // }
    // final View mainView = container;
    final View mainView = viewAnalyzer.getRecentDecorView();
    if (mainView == null) {
        throw new SelendroidException("No open windows.");
    }
    done = false;
    long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis();
    final byte[][] rawPng = new byte[1][1];
    ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() {
        public void run() {
            synchronized (syncObject) {
                Display display = serverInstrumentation.getCurrentActivity().getWindowManager()
                        .getDefaultDisplay();
                Point size = new Point();
                try {
                    display.getSize(size);
                } catch (NoSuchMethodError ignore) { // Older than api level 13
                    size.x = display.getWidth();
                    size.y = display.getHeight();
                }

                // Get root view
                View view = mainView.getRootView();

                // Create the bitmap to use to draw the screenshot
                final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);
                final Canvas canvas = new Canvas(bitmap);

                // Get current theme to know which background to use
                final Activity activity = serverInstrumentation.getCurrentActivity();
                final Theme theme = activity.getTheme();
                final TypedArray ta = theme
                        .obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
                final int res = ta.getResourceId(0, 0);
                final Drawable background = activity.getResources().getDrawable(res);

                // Draw background
                background.draw(canvas);

                // Draw views
                view.draw(canvas);

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                if (!bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream)) {
                    throw new RuntimeException("Error while compressing screenshot image.");
                }
                try {
                    stream.flush();
                    stream.close();
                } catch (IOException e) {
                    throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage());
                } finally {
                    Closeable closeable = (Closeable) stream;
                    try {
                        if (closeable != null) {
                            closeable.close();
                        }
                    } catch (IOException ioe) {
                        // ignore
                    }
                }
                rawPng[0] = stream.toByteArray();
                mainView.destroyDrawingCache();
                done = true;
                syncObject.notify();
            }
        }
    });

    waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot.");
    return rawPng[0];
}

From source file:lu.fisch.canze.activities.MainActivity.java

@Override
public void onResume() {
    debug("MainActivity: onResume");

    instance = this;

    visible = true;/*ww  w  .  j  a v  a  2  s. c  o  m*/
    super.onResume();

    // if returning from a single widget activity, we have to leave here!
    if (returnFromWidget) {
        returnFromWidget = false;
        return;
    }

    if (!leaveBluetoothOn) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                setBluetoothState(BLUETOOTH_DISCONNECTED);
            }
        });
        (new Thread(new Runnable() {
            @Override
            public void run() {
                reloadBluetooth();
            }
        })).start();
    }

    final SharedPreferences settings = getSharedPreferences(PREFERENCES_FILE, 0);
    if (!settings.getBoolean("disclaimer", false)) {

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

        // set title
        alertDialogBuilder.setTitle(R.string.prompt_Disclaimer);

        // set dialog message
        String yes = getStringSingle(R.string.prompt_Accept);
        String no = getStringSingle(R.string.prompt_Decline);

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        float width = size.x;
        // int height = size.y;
        width = width / getResources().getDisplayMetrics().scaledDensity;
        if (width <= 480) {
            yes = getStringSingle(R.string.default_Yes);
            no = getStringSingle(R.string.default_No);
        }

        alertDialogBuilder.setMessage(Html.fromHtml(getStringSingle(R.string.prompt_DisclaimerText)))
                .setCancelable(true).setPositiveButton(yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putBoolean("disclaimer", true);
                        // editor.commit();
                        editor.apply();
                        // current activity
                        dialog.cancel();
                    }
                }).setNegativeButton(no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                        //MainActivity.this.finishAffinity(); requires API16
                        MainActivity.this.finish();
                        android.os.Process.killProcess(android.os.Process.myPid());
                        System.exit(0);
                    }
                });

        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();
    }
}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Handles showing the Calendar pop up, fetching the selected date, calling to fetch
 * submissions again// w w w .  j a v  a2 s .  c  o m
 */
private void showCalendarPicker() {
    // Inflate the popup_layout.xml
    ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root);
    LayoutInflater layoutInflater = (LayoutInflater) getMainActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup);
    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    //or if popup is on edge display it to the left of the circle
    Display display = getMainActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point(0, 0);
    display.getSize(size);

    int OFFSET_X = 25;
    int OFFSET_Y = 25;

    final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(getMainActivity());
    popup.setAnimationStyle(android.R.style.Animation_Dialog);
    popup.setContentView(layout);

    popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    popup.setFocusable(true);
    //gets rid of default background
    popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null));
    //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu));

    // Displaying the popup at the specified location, + offsets.
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y);
    Calendar minDate;
    minDate = Calendar.getInstance();
    this.tempY = minDate.get(Calendar.YEAR);
    this.tempM = minDate.get(Calendar.MONTH);
    this.tempD = minDate.get(Calendar.DAY_OF_MONTH);
    dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                // Months start from 0, so January is month 0
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    tempY = year;
                    tempM = monthOfYear;
                    tempD = dayOfMonth;
                    Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY);
                }
            });
    ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept);
    ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(tempY, tempM, tempD, 1, 0);
            Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis());
            // clear items from clustermanager and submissionMarkerList, as all new submissions
            // need to be fetched based on the selected date
            clusterManager.clearItems();
            submissionMarkerIdList.clear();
            addAdminMarkersToMap();
            setMinDateInMs(calendar.getTimeInMillis());
            popup.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setMinDateInMs(0);
            popup.dismiss();

        }
    });
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

public static Point getPreviewDimension() {

    //        Taken from: http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels
    View v = ((Activity) mContext).findViewById(R.id.camera_controls_layout);

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    Point dim = null;//  w ww.  jav  a 2s . c om

    if (v != null) {
        if (getOrientation() == Surface.ROTATION_0 || getOrientation() == Surface.ROTATION_180)
            dim = new Point(size.x, size.y - v.getHeight());
        //                return size.y - v.getHeight();
        else if (getOrientation() == Surface.ROTATION_90 || getOrientation() == Surface.ROTATION_270)
            dim = new Point(size.x - v.getWidth(), size.y);
        //                return size.x - v.getWidth();
    }

    return dim;

}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void lockOrientation() {
    Display display = POIMapActivity.this.getWindowManager().getDefaultDisplay();
    int rotation = display.getRotation();
    int height;/*w ww  . j a  v  a 2s.c o m*/
    int width;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        height = display.getHeight();
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        height = size.y;
        width = size.x;
    }
    switch (rotation) {
    case Surface.ROTATION_90:
        if (width > height)
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        else
            POIMapActivity.this.setRequestedOrientation(9/* reversePortait */);
        break;
    case Surface.ROTATION_180:
        if (height > width)
            POIMapActivity.this.setRequestedOrientation(9/* reversePortait */);
        else
            POIMapActivity.this.setRequestedOrientation(8/* reverseLandscape */);
        break;
    case Surface.ROTATION_270:
        if (width > height)
            POIMapActivity.this.setRequestedOrientation(8/* reverseLandscape */);
        else
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
    default:
        if (height > width)
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        else
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

/***
 * Hide the searchbox using the circle animation. Can be called regardless of result list length
 * @param activity Activity/*from  w  w  w .  ja  v  a 2s .c  om*/
 */
public void hideCircularly(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    final FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView()
            .findViewById(android.R.id.content);
    RelativeLayout root = (RelativeLayout) findViewById(R.id.search_root);
    display.getSize(size);
    Resources r = getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96, r.getDisplayMetrics());
    int cx = layout.getLeft() + layout.getRight();
    int cy = layout.getTop();
    int finalRadius = (int) Math.max(layout.getWidth() * 1.5, px);

    SupportAnimator animator = ViewAnimationUtils.createCircularReveal(root, cx, cy, 0, finalRadius);
    animator.setInterpolator(new ReverseInterpolator());
    animator.setDuration(500);
    animator.start();
    animator.addListener(new SupportAnimator.AnimatorListener() {

        @Override
        public void onAnimationStart() {

        }

        @Override
        public void onAnimationEnd() {
            setVisibility(View.GONE);
        }

        @Override
        public void onAnimationCancel() {

        }

        @Override
        public void onAnimationRepeat() {

        }

    });
}

From source file:com.thingsee.tracker.MainActivity.java

@SuppressLint("InflateParams")
@Override/*from w  ww  . ja va  2 s.  c o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = this;
    mResources = getResources();
    mSettings = getSharedPreferences(MainActivity.PREFS_NAME, 0);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    mapBoundsPadding = size.x / CommonConstants.SCREEN_PADDING_WITH_MAP_BOUNDS;

    progress = new ProgressDialog(this);

    splashScreen = (RelativeLayout) findViewById(R.id.splash_screen);
    splashScreen.setVisibility(View.VISIBLE);

    loginScreen = (LinearLayout) findViewById(R.id.login_view);

    mSplashHandler.postDelayed(splashScreenOffFromDisplay, CommonConstants.SPLASH_SCREEN_TIMEOUT);
    Log.d("Tracker", "waiting for GoogleMaps");

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_area);
    mapFragment.getMapAsync(this);
}

From source file:org.puder.trs80.EmulatorActivity.java

private void lockOrientation() {
    Display display = getWindowManager().getDefaultDisplay();
    rotation = display.getRotation();//from   www. j  a v a  2s.  c o  m
    int height;
    int width;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        height = display.getHeight();
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        height = size.y;
        width = size.x;
    }
    switch (rotation) {
    case Surface.ROTATION_90:
        if (width > height) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        }
        break;
    case Surface.ROTATION_180:
        if (height > width) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
        break;
    case Surface.ROTATION_270:
        if (width > height) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        break;
    default:
        if (height > width) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

private void setPic() {
    // Get the dimensions of the View
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    // Get the dimensions of the bitmap
    ImageView imv = (ImageView) findViewById(R.id.image_intro);
    int targetW = imv.getMaxWidth();
    int targetH = imv.getMaxHeight();
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    Bitmap bitmap = loadBitmap(image_uri.getPath());
    int photoW = bitmap.getWidth();
    int photoH = bitmap.getHeight();
    imv.setImageBitmap(bitmap);// www.j a  v  a  2s.com
    galleryAddPic();
}

From source file:com.hippo.ehviewer.ui.scene.FavoritesScene.java

private void guideCollections() {
    Activity activity = getActivity2();/* w  ww  .j  av a 2  s  .c o  m*/
    if (null == activity || !Settings.getGuideCollections()) {
        return;
    }

    Display display = activity.getWindowManager().getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);

    mShowcaseView = new ShowcaseView.Builder(activity).withMaterialShowcase().setStyle(R.style.Guide)
            .setTarget(new PointTarget(point.x, point.y / 3)).blockAllTouches()
            .setContentTitle(R.string.guide_collections_title).setContentText(R.string.guide_collections_text)
            .replaceEndButton(R.layout.button_guide)
            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                @Override
                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                    mShowcaseView = null;
                    ViewUtils.removeFromParent(showcaseView);
                    Settings.putGuideCollections(false);
                    openDrawer(Gravity.RIGHT);
                }
            }).build();
}