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:jp.co.ipublishing.esnavi.views.MarqueeView.java

/**
 * ??X/*from   w  ww  .  ja  va  2 s  .c  o m*/
 *
 * @return
 */
private int getLastX() {
    final WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);

    final int measureText = (int) mTextPaint.measureText(mText);

    if (measureText >= size.x) {
        // ????
        return -measureText;
    } else {
        return -measureText;
    }
}

From source file:com.normalexception.app.rx8club.activities.MainActivity.java

/**
 * On create method that will initialize our main layout and construct
 * our navigation menu.  We then call our Login fragment to get the 
 * application started//from  w ww . j  a v  a2s .  c  o  m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_basiclist);

    mTitle = mDrawerTitle = getTitle();

    constructNavMenu();

    // Get our screen size
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    windowSizeW_H = new int[] { width, height };

    if (savedInstanceState == null) {
        // Initial display
        displayView(7, false);
    }
}

From source file:de.radiohacks.frinmean.emojicon.EmojiconsPopup.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public int calculateScreenHeightForLollipop() {
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.y;
}

From source file:jp.co.ipublishing.esnavi.views.MarqueeView.java

/**
 * ???X?//  w  w w  . j  a v  a 2s.  co m
 *
 * @return
 */
private int getMarqueeStartX() {
    final WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);

    final int measureText = (int) mTextPaint.measureText(mText);
    final int measureWidth = getMeasuredWidth();

    if (size.x == measureWidth) {
        return measureWidth;
    } else if (measureText > size.x) {
        // ????
        return size.x;
    } else if (measureWidth > measureText) {
        return measureWidth;
    } else {
        return measureText;
    }
}

From source file:com.oakesville.mythling.app.AppData.java

public Point getScreenSize() {
    if (screenSize == null) {
        WindowManager wm = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenSize = new Point();
        display.getSize(screenSize);
    }// w w  w. j  a v a2 s.c o  m
    return screenSize;
}

From source file:co.edu.uniajc.vtf.content.NavigationActivity.java

private void getSreenDimanstions() {
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    ciWidth = size.x;/*  ww  w .  j  a  va 2s  . co m*/
    ciHeight = size.y;

}

From source file:com.smartsoftasia.sligingtab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from   ww  w  .  j  a va2  s  . c  om
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (navigationMode == NAVIGATION_MODE_TABS) {
            Display display = ((FragmentActivity) getContext()).getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            tabView.setMinimumWidth(size.x / adapter.getCount());
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:edu.stanford.cs.sing.helena.DeviceControlActivity.java

public void onShowPopup(View view, final int position) {

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // inflate the custom popup layout
    final View inflatedView = layoutInflater.inflate(R.layout.observer_view, null, false);

    // find the ListView in the popup layout
    mFireLitDisplay = false;/*w ww  .  j a  v a  2  s  . c  o  m*/
    Firestorm mFire = mFirestormArray.get(position);

    Log.d(TAG, "FIRE ID " + mFire.id);

    // get device size
    Display display = getWindowManager().getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);

    // set height depends on the device size
    popWindow = new PopupWindow(inflatedView, size.x - 50, size.y - 200, true);
    // set a background drawable with rounders corners
    popWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.dialog_background));
    // make it focusable to show the keyboard to enter in `EditText`
    popWindow.setFocusable(true);
    // make it outside touchable to dismiss the popup window
    popWindow.setOutsideTouchable(true);

    // show the popup at bottom of the screen and set some margin at bottom ie,
    // popWindow.showAtLocation(getCurrentFocus(), Gravity.TOP, 0, 100); //showAtLocation(v, Gravity.BOTTOM, 0,100);
    findViewById(R.id.fire_list).post(new Runnable() {
        public void run() {
            popWindow.showAtLocation(findViewById(R.id.fire_list), Gravity.CENTER, 0, 0);
            addDetailList(inflatedView, position);
        }
    });
}

From source file:com.androchill.call411.MainActivity.java

private Phone getHardwareSpecs() {
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    PhoneBuilder pb = new PhoneBuilder();
    pb.setModelNumber(Build.MODEL);//  ww  w.  j a v  a 2 s .  c o m
    pb.setManufacturer(Build.MANUFACTURER);

    Process p = null;
    String board_platform = "No data available";
    try {
        p = new ProcessBuilder("/system/bin/getprop", "ro.chipname").redirectErrorStream(true).start();
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = "";
        while ((line = br.readLine()) != null) {
            board_platform = line;
        }
        p.destroy();
    } catch (IOException e) {
        e.printStackTrace();
        board_platform = "No data available";
    }

    pb.setProcessor(board_platform);
    ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(mInfo);
    pb.setRam((int) (mInfo.totalMem / 1048576L));
    pb.setBatteryCapacity(getBatteryCapacity());
    pb.setTalkTime(-1);
    pb.setDimensions("No data available");

    WindowManager mWindowManager = getWindowManager();
    Display mDisplay = mWindowManager.getDefaultDisplay();
    Point mPoint = new Point();
    mDisplay.getSize(mPoint);
    pb.setScreenResolution(mPoint.x + " x " + mPoint.y + " pixels");

    DisplayMetrics mDisplayMetrics = new DisplayMetrics();
    mDisplay.getMetrics(mDisplayMetrics);
    int mDensity = mDisplayMetrics.densityDpi;
    pb.setScreenSize(
            Math.sqrt(Math.pow(mPoint.x / (double) mDensity, 2) + Math.pow(mPoint.y / (double) mDensity, 2)));

    Camera camera = Camera.open(0);
    android.hardware.Camera.Parameters params = camera.getParameters();
    List sizes = params.getSupportedPictureSizes();
    Camera.Size result = null;

    ArrayList<Integer> arrayListForWidth = new ArrayList<Integer>();
    ArrayList<Integer> arrayListForHeight = new ArrayList<Integer>();

    for (int i = 0; i < sizes.size(); i++) {
        result = (Camera.Size) sizes.get(i);
        arrayListForWidth.add(result.width);
        arrayListForHeight.add(result.height);
    }
    if (arrayListForWidth.size() != 0 && arrayListForHeight.size() != 0) {
        pb.setCameraMegapixels(
                Collections.max(arrayListForHeight) * Collections.max(arrayListForWidth) / (double) 1000000);
    } else {
        pb.setCameraMegapixels(-1);
    }
    camera.release();

    pb.setPrice(-1);
    pb.setWeight(-1);
    pb.setSystem("Android " + Build.VERSION.RELEASE);

    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    StatFs statInternal = new StatFs(Environment.getRootDirectory().getAbsolutePath());
    double storageSize = ((stat.getBlockSizeLong() * stat.getBlockCountLong())
            + (statInternal.getBlockSizeLong() * statInternal.getBlockCountLong())) / 1073741824L;
    pb.setStorageOptions(storageSize + " GB");
    TelephonyManager telephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE));
    String operatorName = telephonyManager.getNetworkOperatorName();
    if (operatorName.length() == 0)
        operatorName = "No data available";
    pb.setCarrier(operatorName);
    pb.setNetworkFrequencies("No data available");
    pb.setImage(null);
    return pb.createPhone();
}

From source file:java_lang_programming.com.android_media_demo.article94.java.ImageDecoderActivity.java

/**
 * Bitmap??//w  ww  . j av  a  2  s. c  om
 *
 * @param context 
 * @param uri     ?Uri
 * @return Bitmap
 */
private @Nullable Bitmap getBitmap(@NonNull Context context, @NonNull Uri uri) {
    final ParcelFileDescriptor parcelFileDescriptor;
    try {
        parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r");
    } catch (FileNotFoundException e) {
        e.getStackTrace();
        return null;
    }

    final FileDescriptor fileDescriptor;
    if (parcelFileDescriptor != null) {
        fileDescriptor = parcelFileDescriptor.getFileDescriptor();
    } else {
        // ParcelFileDescriptor was null for given Uri: [" + mInputUri + "]"
        return null;
    }

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    if (options.outWidth == -1 || options.outHeight == -1) {
        // "Bounds for bitmap could not be retrieved from the Uri: [" + mInputUri + "]"
        return null;
    }

    int orientation = getOrientation(uri);
    int rotation = getRotation(orientation);

    Matrix transformMatrix = new Matrix();
    transformMatrix.setRotate(rotation);

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

    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    int reqWidth = Math.min(width, options.outWidth);
    int reqHeight = Math.min(height, options.outHeight);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;

    Bitmap decodeSampledBitmap = null;

    boolean decodeAttemptSuccess = false;
    while (!decodeAttemptSuccess) {
        try {
            decodeSampledBitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
            decodeAttemptSuccess = true;
        } catch (OutOfMemoryError error) {
            Log.e("", "doInBackground: BitmapFactory.decodeFileDescriptor: ", error);
            options.inSampleSize *= 2;
        }
    }

    // ??
    decodeSampledBitmap = transformBitmap(decodeSampledBitmap, transformMatrix);

    return decodeSampledBitmap;
}