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.github.dector.rkpi.views.AppViewPager.java

/**
 * Load, scale and setup background image
 *
 * @param context activity context//from  w ww  .  ja v  a  2  s.c o m
 */
private void initBackground(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    Point displaySize = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(displaySize);
    } else {
        displaySize.set(display.getWidth(), display.getHeight());
    }

    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    decodeOptions.inJustDecodeBounds = true;

    BitmapFactory.decodeResource(context.getResources(), R.drawable.background);
    decodeOptions.inJustDecodeBounds = false;
    decodeOptions.inSampleSize = DeviceTools.getSampleSize(decodeOptions, displaySize);

    Bitmap sourceBackground = BitmapFactory.decodeResource(context.getResources(), R.drawable.background,
            decodeOptions);
    Bitmap background = Bitmap.createScaledBitmap(sourceBackground, displaySize.x, displaySize.y, true);
    Drawable bitmapDrawable = new BitmapDrawable(context.getResources(), background);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(bitmapDrawable);
    } else {
        setBackgroundDrawable(bitmapDrawable);
    }

    sourceBackground.recycle();
}

From source file:com.example.android.navigationdrawer.QRCode.java

public void onQR(View v) {
    switch (v.getId()) {
    case R.id.button1:
        String qrInputText = MidiFile.readString;

        //Find screen size
        WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        int width = point.x;
        int height = point.y;
        int smallerDimension = width < height ? width : height;
        smallerDimension = smallerDimension * 3 / 4;
        //Encode with a QR Code image
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText, null, Contents.Type.TEXT,
                BarcodeFormat.QR_CODE.toString(), smallerDimension);
        try {//from   w w w.  j ava  2  s .  com
            Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
            ImageView myImage = (ImageView) findViewById(R.id.imageView1);
            myImage.setImageBitmap(bitmap);

            // Get screen size
            Display display1 = this.getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display1.getSize(size);
            int screenWidth = size.x;
            int screenHeight = size.y;

            // Get target image size
            Bitmap bitmap1 = qrCodeEncoder.encodeAsBitmap();
            int bitmapHeight = bitmap1.getHeight();
            int bitmapWidth = bitmap1.getWidth();

            // Scale the image down to fit perfectly into the screen
            // The value (250 in this case) must be adjusted for phone/tables displays
            while (bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) {
                bitmapHeight = bitmapHeight / 2;
                bitmapWidth = bitmapWidth / 2;
            }

            // Create resized bitmap image
            BitmapDrawable resizedBitmap = new BitmapDrawable(this.getResources(),
                    Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));

            // Create dialog
            Dialog dialog = new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.thumbnail);

            ImageView image = (ImageView) dialog.findViewById(R.id.imageview);

            // !!! Do here setBackground() instead of setImageDrawable() !!! //
            image.setBackground(resizedBitmap);

            // Without this line there is a very small border around the image (1px)
            // In my opinion it looks much better without it, so the choice is up to you.
            dialog.getWindow().setBackgroundDrawable(null);
            dialog.show();

        } catch (WriterException e) {
            e.printStackTrace();
        }
        break;
    }
}

From source file:com.echlabsw.android.drawertab.MainActivity.java

@TargetApi(13)
@SuppressWarnings("deprecation")
private int getDisplayPxWidth() {
    Display display = getWindowManager().getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point size = new Point();
        display.getSize(size);
        return size.x;
    } else {//from   w  w w. j a va  2s  .  c om
        return display.getWidth();
    }
}

From source file:com.google.mist.plot.MainActivity.java

private void dumpSensorData() throws JSONException { //TODO(cjr): do we want JSONException here?
    File dataDir = getOrCreateSessionDir();
    File target = new File(dataDir, String.format("%s.json", mRecordingType));

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("version", "1.0.0");

    boolean isCalibrated = mPullDetector.getCalibrationStatus();
    jsonObject.put("calibrated", isCalibrated);

    // Write system information
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    JSONObject deviceData = new JSONObject();
    deviceData.put("Build.DEVICE", Build.DEVICE);
    deviceData.put("Build.MODEL", Build.MODEL);
    deviceData.put("Build.PRODUCT", Build.PRODUCT);
    deviceData.put("Build.VERSION.SDK_INT", Build.VERSION.SDK_INT);
    deviceData.put("screenResolution.X", size.x);
    deviceData.put("screenResolution.Y", size.y);
    jsonObject.put("systemInfo", deviceData);

    // Write magnetometer data
    JSONArray magnetData = new JSONArray();
    for (int i = 0; i < mSensorData.size(); i++) {
        JSONArray dataPoint = new JSONArray();
        long time = mSensorTime.get(i);
        dataPoint.put(time);/*from   w w w.  j a  v  a  2  s. co  m*/
        dataPoint.put(mSensorAccuracy.get(i));
        float[] data = mSensorData.get(i);
        for (float d : data) {
            dataPoint.put(d);
        }
        magnetData.put(dataPoint);
    }
    jsonObject.put("magnetometer", magnetData);

    // Write onAccuracyChanged data
    JSONArray accuracyChangedData = new JSONArray();
    for (int i = 0; i < mAccuracyData.size(); i++) {
        JSONArray dataPoint = new JSONArray();
        long time = mAccuracyTime.get(i);
        dataPoint.put(time);
        dataPoint.put(mAccuracyData.get(i));
        accuracyChangedData.put(dataPoint);
    }
    jsonObject.put("onAccuracyChangedData", accuracyChangedData);

    // Write rotation data
    if (mRecordRotation) {
        JSONArray rotationData = new JSONArray();
        for (int i = 0; i < mSensorData.size(); i++) {
            JSONArray dataPoint = new JSONArray();
            long time = mRotationTime.get(i);
            dataPoint.put(time);
            float[] data = mRotationData.get(i);
            for (float d : data) {
                dataPoint.put(d);
            }
            rotationData.put(dataPoint);
        }
        jsonObject.put("rotation", rotationData);
    }

    // Write event labels
    JSONArray trueLabels = new JSONArray();
    for (int i = 0; i < mPositivesData.size(); i++) {
        JSONArray dataPoint = new JSONArray();
        long time = mPositivesTime.get(i);
        dataPoint.put(time);
        dataPoint.put(mPositivesData.get(i));
        trueLabels.put(dataPoint);
    }
    jsonObject.put("labels", trueLabels);

    try {
        FileWriter fw = new FileWriter(target, true);
        fw.write(jsonObject.toString());
        fw.flush();
        fw.close();
        mDumpPath = target.toString();
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    }
}

From source file:android.support.v7.view.menu.MenuPopupHelper.java

/**
 * Creates the popup and assigns cached properties.
 *
 * @return an initialized popup// w ww .j  a  v a  2  s.  co m
 */
@NonNull
private MenuPopup createPopup() {
    final WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    final Display display = windowManager.getDefaultDisplay();
    final Point displaySize = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        display.getRealSize(displaySize);
    } else if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(displaySize);
    } else {
        displaySize.set(display.getWidth(), display.getHeight());
    }

    final int smallestWidth = Math.min(displaySize.x, displaySize.y);
    final int minSmallestWidthCascading = mContext.getResources()
            .getDimensionPixelSize(R.dimen.abc_cascading_menus_min_smallest_width);
    final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading;

    final MenuPopup popup;
    if (enableCascadingSubmenus) {
        popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly);
    } else {
        popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr, mPopupStyleRes,
                mOverflowOnly);
    }

    // Assign immutable properties.
    popup.addMenu(mMenu);
    popup.setOnDismissListener(mInternalOnDismissListener);

    // Assign mutable properties. These may be reassigned later.
    popup.setAnchorView(mAnchorView);
    popup.setCallback(mPresenterCallback);
    popup.setForceShowIcon(mForceShowIcon);
    popup.setGravity(mDropDownGravity);

    return popup;
}

From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java

@SuppressLint("NewApi")
public static int getWidth(Context mContext) {
    int width = 0;
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT > 12) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;//from w  ww.j  ava2  s.  co m
    } else {
        width = display.getWidth(); // Deprecated
    }
    return width;
}

From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java

@SuppressLint("NewApi")
public static int getHeight(Context mContext) {
    int height = 0;
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT > 12) {
        Point size = new Point();
        display.getSize(size);
        height = size.y;//w w w.  java 2  s  . co m
    } else {
        height = display.getHeight(); // Deprecated
    }
    return height;
}

From source file:nl.vincentketelaars.mexen.activities.RollDice.java

protected Point getSize() {
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size;/*ww  w. j a v  a 2s.  c  o  m*/
}

From source file:org.cyanogenmod.theme.chooser.ChooserBrowseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_chooser_browse, container, false);
    ArrayList<String> filters = getArguments().getStringArrayList(ChooserActivity.EXTRA_COMPONENT_FILTER);
    mComponentFilters = (filters != null) ? filters : new ArrayList<String>(0);
    // If we are filtering by "styles" add status bar and navigation bar to the list
    if (mComponentFilters.contains(ThemesColumns.MODIFIES_OVERLAYS)) {
        mComponentFilters.add(ThemesColumns.MODIFIES_STATUS_BAR);
        mComponentFilters.add(ThemesColumns.MODIFIES_NAVIGATION_BAR);
    }//from   w w w  .j av a 2  s . com
    mListView = (ListView) v.findViewById(R.id.list);
    mAdapter = new LocalPagerAdapter(getActivity(), null, mComponentFilters);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String pkgName = (String) mAdapter.getItem(position);
            ChooserDetailFragment fragment = ChooserDetailFragment.newInstance(pkgName, mComponentFilters);
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.content, fragment, ChooserDetailFragment.class.toString());
            transaction.addToBackStack(null);
            transaction.commit();
        }
    });
    getLoaderManager().initLoader(0, null, this);

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    display.getSize(mMaxImageSize);
    mMaxImageSize.y = (int) getActivity().getResources().getDimension(R.dimen.item_browse_height);

    return v;
}

From source file:ir.rasen.charsoo.view.widgets.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextViewFont tab = new TextViewFont(getContext());
    tab.setText(title);/*from ww w .  j ava2  s . c  o m*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    if (fitToScreen) {
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        tab.setWidth(size.x / tabCount);
    }

    addTab(position, tab);
}