Example usage for android.view Display getHeight

List of usage examples for android.view Display getHeight

Introduction

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

Prototype

@Deprecated
public int getHeight() 

Source Link

Usage

From source file:org.catrobat.paintroid.test.integration.BaseIntegrationTestClass.java

public void openNavigationDrawer() {

    Display display = mSolo.getCurrentActivity().getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    float xStart = 0;
    float xEnd = width / 2;
    mSolo.drag(xStart, xEnd, height / 2, height / 2, 1);
}

From source file:org.odk.collect.android.widgets.ImageWidget.java

public ImageWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent();

    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
    params.setMargins(7, 5, 7, 5);/*from   w  w  w  .  jav  a  2s.c om*/

    mErrorTextView = new TextView(context);
    mErrorTextView.setId(QuestionWidget.newUniqueId());
    mErrorTextView.setText("Selected file is not a valid image");

    // setup capture button
    mCaptureButton = new Button(getContext());
    mCaptureButton.setId(QuestionWidget.newUniqueId());
    mCaptureButton.setText(getContext().getString(R.string.capture_image));
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!prompt.isReadOnly());
    mCaptureButton.setLayoutParams(params);

    // launch capture intent on click
    mCaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "captureButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // We give the camera an absolute filename/path where to put the
            // picture because of bug:
            // http://code.google.com/p/android/issues/detail?id=1480
            // The bug appears to be fixed in Android 2.0+, but as of feb 2,
            // 2010, G1 phones only run 1.6. Without specifying the path the
            // images returned by the camera in 1.6 (and earlier) are ~1/4
            // the size. boo.

            // if this gets modified, the onActivityResult in
            // FormEntyActivity will also need to be updated.
            i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getContext(),
                    BuildConfig.APPLICATION_ID + ".provider", new File(Collect.TMPFILE_PATH)));
            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "image capture"),
                        Toast.LENGTH_SHORT).show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // setup chooser button
    mChooseButton = new Button(getContext());
    mChooseButton.setId(QuestionWidget.newUniqueId());
    mChooseButton.setText(getContext().getString(R.string.choose_image));
    mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mChooseButton.setPadding(20, 20, 20, 20);
    mChooseButton.setEnabled(!prompt.isReadOnly());
    mChooseButton.setLayoutParams(params);

    // launch capture intent on click
    mChooseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "chooseButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");

            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT)
                        .show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // finish complex layout
    LinearLayout answerLayout = new LinearLayout(getContext());
    answerLayout.setOrientation(LinearLayout.VERTICAL);
    answerLayout.addView(mCaptureButton);
    answerLayout.addView(mChooseButton);
    answerLayout.addView(mErrorTextView);

    // and hide the capture and choose button if read-only
    if (prompt.isReadOnly()) {
        mCaptureButton.setVisibility(View.GONE);
        mChooseButton.setVisibility(View.GONE);
    }
    mErrorTextView.setVisibility(View.GONE);

    // retrieve answer from data model and update ui
    mBinaryName = prompt.getAnswerText();

    // Only add the imageView if the user has taken a picture
    if (mBinaryName != null) {
        mImageView = new ImageView(getContext());
        mImageView.setId(QuestionWidget.newUniqueId());
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        int screenWidth = display.getWidth();
        int screenHeight = display.getHeight();

        File f = new File(mInstanceFolder + File.separator + mBinaryName);

        if (f.exists()) {
            Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);
            if (bmp == null) {
                mErrorTextView.setVisibility(View.VISIBLE);
            }
            mImageView.setImageBitmap(bmp);
        } else {
            mImageView.setImageBitmap(null);
        }

        mImageView.setPadding(10, 10, 10, 10);
        mImageView.setAdjustViewBounds(true);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "viewButton", "click",
                        mPrompt.getIndex());
                Intent i = new Intent("android.intent.action.VIEW");
                Uri uri = MediaUtils
                        .getImageUriFromMediaProvider(mInstanceFolder + File.separator + mBinaryName);
                if (uri != null) {
                    Log.i(t, "setting view path to: " + uri);
                    i.setDataAndType(uri, "image/*");
                    try {
                        getContext().startActivity(i);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getContext(),
                                getContext().getString(R.string.activity_not_found, "view image"),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        answerLayout.addView(mImageView);
    }
    addAnswerView(answerLayout);
}

From source file:kr.co.cashqc.MainActivity.java

private int getScreenSize() {
    Display display = MainActivity.this.getWindowManager().getDefaultDisplay();
    int screenHeight = display.getHeight();//  ? ? ?

    Window window = getWindow();// www  .j a va  2 s  . co  m
    int topBarHeight = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();// ?
                                                                               // ??
                                                                               // ?
                                                                               // ?.

    return screenHeight - topBarHeight;
}

From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java

Bitmap loadBitmapBlocking(String woeid, boolean isDay, int conditionCode) {
    File[] files = mWeatherUtils.getCityPhotos(WeatherActivity.this, woeid);
    Bitmap bitmap;//from  w  w  w.ja v a 2 s.com

    if (files != null) {
        int N = files.length;
        Random random = new Random();
        int idx = random.nextInt(N);
        File file = files[idx];
        WindowManager windowManager = mWindowManager;
        Display defaultDisplay = windowManager.getDefaultDisplay();
        int dimen = Math.max(defaultDisplay.getWidth(), defaultDisplay.getHeight());
        bitmap = mBitmapUtils.decodeSampledBitmapFromFile(file, dimen, dimen);
        return bitmap;
    }

    int resId = ImageDownloadHelper.getFallbackDrawableForConditionCode(isDay, conditionCode);
    return BitmapFactory.decodeResource(getResources(), resId);
}

From source file:io.github.dector.rkpi.views.AppViewPager.java

/**
 * Load, scale and setup background image
 *
 * @param context activity context/* w w  w  . java  2  s .c  om*/
 */
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.jwetherell.quick_response_code.EncoderActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    com.ranorex.android.RanorexAndroidAutomation.Hook(this);
    // Get text views
    textoSsid = (TextView) findViewById(R.id.ssid);
    textoPassword = (TextView) findViewById(R.id.password);
    descripcion = (TextView) findViewById(R.id.descripcion);
    icon = (ImageView) findViewById(R.id.icon);
    //textoCifrado = (TextView) findViewById(R.id.cifrado);

    settings = getSharedPreferences(MainActivity.PREFS, 0);

    // if(settings.contains("connected_wifi_5ghz") && settings.getBoolean("connected_wifi_5ghz", false))
    //      descripcion.setText("");

    final ProgressDialog dialog = new ProgressDialog(EncoderActivity.this);

    dialog.setMessage("Generando Qr...");
    dialog.show();//from  w w w .  j  a v a  2 s  . co m
    dialog.setCancelable(false);

    try {

        if (settings.contains("ssid") && settings.contains("password1")) {
            // Get ssid, psk and encrypted of settings.

            if (!getIntent().getBooleanExtra("is_5ghz", false)) // Network 2.4 GHz.
            {
                cifradoSettings = settings.getString("cifrado", "WPA");
                ssidSettings = settings.getString("ssid", "");
                pskSettings = settings.getString("password1", "");
                if (settings.contains("connected_wifi_5ghz")
                        && !settings.getBoolean("connected_wifi_5ghz", false)
                        || !settings.contains("connected_wifi_5ghz")) {
                    descripcion.setVisibility(View.VISIBLE);
                }
            } else // Network 5 GHz.
            {
                cifradoSettings = settings.getString("cifrado5ghz", "WPA");
                ssidSettings = settings.getString("ssid5ghz", "");
                pskSettings = settings.getString("password5ghz", "");
                icon.setImageResource(R.drawable.wifiplus120);
                ((TextView) findViewById(R.id.textView1)).setText("WifiPlus");
                if (settings.contains("connected_wifi_5ghz")
                        && settings.getBoolean("connected_wifi_5ghz", false)) {
                    descripcion.setVisibility(View.VISIBLE);
                }
            }

            ssidFull = ssidSettings;
            pskFull = pskSettings;

            if (cifradoSettings.contains("WPA")) {
                cifradoQR = "WPA";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;";
            } else if (cifradoSettings.contains("abierta")) {
                cifradoQR = "nopass";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";;";
            } else if (cifradoSettings.contains("WEP")) {
                cifradoQR = "WEP";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;";
            }

            // Update texts
            textoSsid.setText(ssidSettings);

            try {
                if (pskSettings.length() > 39)
                    pskSettings = ellipsis(pskSettings, 39);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (pskSettings.equalsIgnoreCase("sin password") || pskSettings.equalsIgnoreCase(""))
                pskSettings = "Sin password";

            textoPassword.setText(pskSettings);

        }

    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not encode barcode", e);
    }

    new AsyncTask<String, Integer, Bitmap>() {

        @Override
        protected Bitmap doInBackground(String... params) {
            QRCodeEncoder qrCodeEncoder = null;
            // This assumes the view is full screen, which is a good assumption
            WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
            Display display = manager.getDefaultDisplay();
            int width = display.getWidth();
            int height = display.getHeight();
            int smallerDimension = width < height ? width : height;
            smallerDimension = smallerDimension * 7 / 8;

            try {
                qrCodeEncoder = new QRCodeEncoder(string, null, Contents.Type.TEXT,
                        BarcodeFormat.QR_CODE.toString(), smallerDimension);
                Hashtable hints = new Hashtable();
                hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
                QRCodeWriter qrcw = new QRCodeWriter();
                BitMatrix matrix = qrcw.encode(string, BarcodeFormat.QR_CODE, width, height, hints);
                bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                for (int y = 0; y < matrix.getHeight(); y++) {
                    for (int x = 0; x < matrix.getWidth(); x++) {
                        if (!matrix.get(x, y))
                            bm.setPixel(x, y, Color.WHITE);
                        else
                            bm.setPixel(x, y, Color.BLACK);
                    }
                }
            } catch (WriterException we) {
                we.printStackTrace();
                Log.e(TAG, "Could not encode barcode", we);
            }

            return bm;
        }

        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap != null) {
                viewCode = (ImageView) findViewById(R.id.image_view);
                viewCode.setImageBitmap(bitmap);//bitmap);
                dialog.dismiss();
            } else {
                Toast.makeText(EncoderActivity.this, "Problema al generar Qr", Toast.LENGTH_LONG).show();
            }
        }
    }.execute();

    if (bm != null) {
        dialog.dismiss();
    }

}

From source file:org.ubicollab.nomad.home.HomeScreen.java

private void editPic(final int fileName) {
    // get the instance of the LayoutInflater
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // inflate our view from the corresponding XML file
    View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup_menu_root), false);

    Button button_ok = (Button) layout.findViewById(R.id.popup_menu_ok);
    Button button_cancel = (Button) layout.findViewById(R.id.popup_menu_cancel);
    current_picture_popup = (ImageView) findViewById(R.id.popup_currentspace_image);

    // create a 100px width and 200px height popup window
    Display display = getWindowManager().getDefaultDisplay();

    pw = new PopupWindow(layout, display.getWidth() / 4 + display.getWidth() / 2,
            display.getWidth() / 4 + display.getHeight() / 2, true);
    // set actions to buttons we have in our popup

    FileInputStream in = null;//ww  w  .j  ava2 s.  c  om
    BufferedInputStream buf = null;
    try {
        in = new FileInputStream("/sdcard/" + fileName + ".jpg");
        buf = new BufferedInputStream(in);
        Bitmap bMap = BitmapFactory.decodeStream(buf);
        current_picture_popup.setImageBitmap(bMap);
        if (in != null) {
            in.close();
        }
        if (buf != null) {
            buf.close();
        }
    } catch (Exception e) {
        Log.e("Error reading file", e.toString());
    }

    button_ok.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View vv) {
            takePicture(fileName);
        }
    });
    button_cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View vv) {
            pw.dismiss();
        }
    });
    // finally show the popup in the center of the window
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
}

From source file:cis350.blanket.IntentIntegrator.java

/**
 * Use a wide scanning rectangle./*  w ww. j a va2s .c o  m*/
 *
 * May work better for 1D barcodes.
 */
public void setWide() {
    addExtra("SCAN_WIDE", true);

    // For zxing-android-legacy, which doesn't support SCAN_WIDE
    WindowManager window = activity.getWindowManager();
    Display display = window.getDefaultDisplay();
    @SuppressWarnings("deprecation")
    int displayWidth = display.getWidth();
    @SuppressWarnings("deprecation")
    int displayHeight = display.getHeight();
    if (displayHeight > displayWidth) {
        // This is portrait dimensions, but the legacy barcode scanner is always in landscape mode.
        int temp = displayWidth;
        //noinspection SuspiciousNameCombination
        displayWidth = displayHeight;
        displayHeight = temp;
    }

    int desiredWidth = displayWidth * 9 / 10;
    int desiredHeight = Math.min(displayHeight * 3 / 4, 400); // Limit to 400px
    setScanningRectangle(desiredWidth, desiredHeight);
}

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);/*  w ww. jav  a 2s  .  c  om*/
        height = size.y;
    } else {
        height = display.getHeight(); // Deprecated
    }
    return height;
}

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

/**
 * Creates the popup and assigns cached properties.
 *
 * @return an initialized popup/*from   ww  w .ja va  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;
}