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:com.pictureperfect.FaceTrackerActivity.java

/**
 * Creates and starts the camera.  Note that this uses a higher resolution in comparison
 * to other detection examples to enable the barcode detector to detect small barcodes
 * at long distances./*from ww  w .j a va2s . c o m*/
 */
private void createCameraSource(int facing) {

    Context context = getApplicationContext();
    FaceDetector detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS).setMode(FaceDetector.FAST_MODE).build();

    detector.setProcessor(new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory()).build());

    if (!detector.isOperational()) {
        // Note: The first time that an app using face API is installed on a device, GMS will
        // download a native library to the device in order to do detection.  Usually this
        // completes before the app is run for the first time.  But if that download has not yet
        // completed, then the above call will not detect any faces.
        //
        // isOperational() can be used to check if the required native library is currently
        // available.  The detector will automatically become operational once the library
        // download completes on device.
        Log.w(TAG, "Face detector dependencies are not yet available.");
    }

    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth(); // deprecated
    int height = display.getHeight();

    mCameraSource = new CameraSource.Builder(context, detector).setRequestedPreviewSize(width, height)
            .setFacing(facing).setRequestedFps(32.0f).build();
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

private void resize(JSONArray data) {
    if (mBarcodePicker != null) {
        final Bundle bundle = new Bundle();
        try {/*  w w  w  .  java  2  s.c o m*/
            if (data.length() < 1) {
                Log.e("ScanditSDK",
                        "The resize call received too few arguments and has to return without starting.");
                return;
            }
            setOptionsOnBundle(data.getJSONObject(0), bundle);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
                ScanditSDKParameterParser.updatePickerUIFromBundle(mBarcodePicker, bundle, display.getWidth(),
                        display.getHeight());
                double animationDuration = 0;
                if (bundle.containsKey(ScanditSDKParameterParser.paramAnimationDuration)) {
                    animationDuration = bundle.getDouble(ScanditSDKParameterParser.paramAnimationDuration);
                }
                adjustLayout(bundle, animationDuration);
            }
        });
    }
}

From source file:org.rapidandroid.activity.chart.ChartBroker.java

protected void loadGraphFinish() {
    Display display = this.mParentActivity.getWindowManager().getDefaultDisplay();
    //Get the screen orientation

    int width = display.getWidth();
    int height = display.getHeight();

    Log.d("ChartBroker", "getWidth: " + width);
    Log.d("ChartBroker", "getHeight: " + height);

    height = height - 50;/*from w  ww.j a  v a 2  s  .c  o  m*/
    mAppView.loadUrl("javascript:SetGraph(\"" + width + "px\", \"" + height + "px\")");
    Log.d("ChartBroker", "javascript:SetGraph(\"" + width + "px\", \"" + height + "px\")");

    mAppView.loadUrl("javascript:GotGraph(" + mGraphData.toString() + "," + mGraphOptions.toString() + ")");
    Log.d("ChartBroker", "javascript:GotGraph(" + mGraphData.toString() + "," + mGraphOptions.toString() + ")");
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Constructor/*from w ww  . j  a  va2 s . c  o m*/
 * 
 * @param context
 * @param attrs
 */
public MadView(Context context, AttributeSet attrs) {
    super(context, attrs);

    MadUtil.logMessage(null, Log.DEBUG, "** Constructor for mad view called **");
    setVisibility(INVISIBLE);

    if (context.checkCallingOrSelfPermission(
            android.Manifest.permission.INTERNET) == PackageManager.PERMISSION_DENIED) {

        MadUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** ");
        MadUtil.logMessage(null, Log.DEBUG, " *** Missing internet permissions! *** ");
        MadUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** ");
        throw new IllegalArgumentException();
    }

    initParameters(attrs);

    Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    MadUtil.logMessage(null, Log.DEBUG,
            "Display values: Width = " + display.getWidth() + " ; Height = " + display.getHeight());

    setGravity(Gravity.CENTER);

    initialBackground = this.getBackground();
    Rect r = new Rect(0, 0, display.getWidth(), display.getHeight());
    textBannerBackground = generateBackgroundDrawable(r, backgroundColor, 0xffffff);

    setClickable(true);
    setFocusable(true);
    setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

private void scan(JSONArray data) {
    if (mPendingOperation) {
        return;// w w  w .j  av  a  2s.  c  o m
    }
    mPendingOperation = true;
    mHandler.start();

    final Bundle bundle = new Bundle();
    try {
        bundle.putString(ScanditSDKParameterParser.paramAppKey, data.getString(0));
    } catch (JSONException e) {
        Log.e("ScanditSDK", "Function called through Java Script contained illegal objects.");
        e.printStackTrace();
        return;
    }

    if (data.length() > 1) {
        // We extract all options and add them to the intent extra bundle.
        try {
            setOptionsOnBundle(data.getJSONObject(1), bundle);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (bundle.containsKey(ScanditSDKParameterParser.paramContinuousMode)) {
        mContinuousMode = bundle.getBoolean(ScanditSDKParameterParser.paramContinuousMode);
    }

    ScanditLicense.setAppKey(bundle.getString(ScanditSDKParameterParser.paramAppKey));
    ScanditSDKGlobals.usedFramework = "phonegap";

    if (bundle.containsKey(ScanditSDKParameterParser.paramPortraitMargins)
            || bundle.containsKey(ScanditSDKParameterParser.paramLandscapeMargins)) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                ScanSettings settings = ScanditSDKParameterParser.settingsForBundle(bundle);
                mBarcodePicker = new SearchBarBarcodePicker(cordova.getActivity(), settings);
                mBarcodePicker.setOnScanListener(ScanditSDK.this);
                mBarcodePicker.setOnSearchBarListener(ScanditSDK.this);
                mLayout = new RelativeLayout(cordova.getActivity());

                ViewGroup viewGroup = getViewGroupToAddTo();
                if (viewGroup != null) {
                    viewGroup.addView(mLayout);
                }

                Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
                ScanditSDKParameterParser.updatePickerUIFromBundle(mBarcodePicker, bundle, display.getWidth(),
                        display.getHeight());

                RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                mLayout.addView(mBarcodePicker, rLayoutParams);
                adjustLayout(bundle, 0);

                if (bundle.containsKey(ScanditSDKParameterParser.paramPaused)
                        && bundle.getBoolean(ScanditSDKParameterParser.paramPaused)) {
                    mBarcodePicker.startScanning(true);
                } else {
                    mBarcodePicker.startScanning();
                }
            }
        });

    } else {
        ScanditSDKResultRelay.setCallback(this);
        Intent intent = new Intent(cordova.getActivity(), ScanditSDKActivity.class);
        intent.putExtras(bundle);
        cordova.startActivityForResult(this, intent, 1);
    }
}

From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

private void initializeLegend(final TextView legend) {
    // From: http://stackoverflow.com/questions/6068197/utils-read-resource-text-file-to-string-java#answer-18897411
    String html = new Scanner(this.getClass().getResourceAsStream("/legend.html"), "UTF-8").useDelimiter("\\A")
            .next();/* w  w w. j av a2 s .  c om*/
    legend.setText(trimTrailingWhitespace(Html.fromHtml(html)));

    // Check MainActivity.PREF_SHOW_LEGEND and set legend visibility from that
    SharedPreferences preferences = getActivity().getPreferences(Context.MODE_PRIVATE);
    boolean showLegend = preferences.getBoolean(MainActivity.PREF_SHOW_LEGEND, true);
    legend.setVisibility(showLegend ? View.VISIBLE : View.GONE);

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        int width = (int) spToPixels(LEGEND_WIDTH_LANDSCAPE_SP);

        // Put an upper bound on the legend width at 40% landscape screen width
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        //noinspection deprecation
        int landscapeWidth = Math.max(display.getWidth(), display.getHeight());
        if (width > landscapeWidth * 0.4) {
            width = (int) (landscapeWidth * 0.4);
        }

        legend.getLayoutParams().width = width;
    }
}

From source file:de.baumann.thema.RequestActivity.java

@SuppressWarnings("deprecation")
private int getDisplaySize(String which) {
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    if (which.equals("height")) {
        return display.getHeight();
    }//  w  ww . j  a va  2 s .  co m
    if (which.equals("width")) {
        return display.getWidth();
    }
    if (DEBUG)
        Log.v(TAG, "Normally unreachable. Line. What happened??");
    return 1000;
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Starts a background thread to fetch a new ad. Method is called
 * from the refresh timer task//from w  ww. jav  a 2s. c o m
 */
private void requestNewAd() {
    MadUtil.logMessage(null, Log.DEBUG, "Trying to fetch a new ad");

    // exit if already requesting a new ad, not used yet
    if (runningRefreshAd) {
        MadUtil.logMessage(null, Log.DEBUG, "Another request is still in progress ...");
        return;
    }

    new Thread() {
        public void run() {
            // read all parameters, that we need for the request
            // get site token from manifest xml file
            String siteToken = MadUtil.getToken(getContext());
            if (siteToken == null) {
                siteToken = "";
                MadUtil.logMessage(null, Log.DEBUG, "Cannot show ads, since the appID ist null");
            } else {
                MadUtil.logMessage(null, Log.DEBUG, "appID = " + siteToken);
            }

            // get uid (does not work in emulator)
            String uid = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
            if (uid == null) {
                uid = "";
            } else {
                uid = getMD5Hash(uid);
            }
            MadUtil.logMessage(null, Log.DEBUG, "uid = " + uid);

            // get display metrics
            Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            int displayHeight = display.getHeight();
            int displayWidth = display.getWidth();
            MadUtil.logMessage(null, Log.DEBUG, "Display height = " + Integer.toString(displayHeight));
            MadUtil.logMessage(null, Log.DEBUG, "Display width = " + Integer.toString(displayWidth));

            // create post request
            HttpPost postRequest = new HttpPost(MadUtil.MAD_SERVER + "/site/" + siteToken);
            postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

            List<NameValuePair> parameterList = new ArrayList<NameValuePair>();
            parameterList.add(new BasicNameValuePair("ua", MadUtil.getUA()));
            parameterList.add(new BasicNameValuePair("app", "true"));
            parameterList.add(new BasicNameValuePair("debug", Boolean.toString(testMode)));
            parameterList.add(new BasicNameValuePair("ip", MadUtil.getLocalIpAddress()));
            parameterList.add(new BasicNameValuePair("format", "json"));
            parameterList.add(new BasicNameValuePair("requester", "android_sdk"));
            parameterList.add(new BasicNameValuePair("version", "1.1"));
            parameterList.add(new BasicNameValuePair("uid", uid));
            parameterList.add(new BasicNameValuePair("banner_type", bannerType));
            parameterList.add(new BasicNameValuePair("deliver_only_text", Boolean.toString(deliverOnlyText)));

            MadUtil.refreshCoordinates(getContext());
            if (MadUtil.getLocation() != null) {
                parameterList.add(
                        new BasicNameValuePair("lat", Double.toString(MadUtil.getLocation().getLatitude())));
                parameterList.add(
                        new BasicNameValuePair("lng", Double.toString(MadUtil.getLocation().getLongitude())));
            }

            UrlEncodedFormEntity urlEncodedEntity = null;
            try {
                urlEncodedEntity = new UrlEncodedFormEntity(parameterList);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            postRequest.setEntity(urlEncodedEntity);

            MadUtil.logMessage(null, Log.DEBUG, "Post request created");
            MadUtil.logMessage(null, Log.DEBUG, "Uri : " + postRequest.getURI().toASCIIString());
            MadUtil.logMessage(null, Log.DEBUG,
                    "All headers : " + MadUtil.getAllHeadersAsString(postRequest.getAllHeaders()));
            MadUtil.logMessage(null, Log.DEBUG,
                    "All request parameters :" + MadUtil.printRequestParameters(parameterList));

            synchronized (this) {
                // send blocking request to ad server
                HttpClient httpClient = new DefaultHttpClient();
                HttpResponse httpResponse = null;
                InputStream inputStream = null;
                boolean jsonFetched = false;
                JSONObject json = null;

                try {
                    HttpParams clientParams = httpClient.getParams();
                    HttpConnectionParams.setConnectionTimeout(clientParams,
                            MadUtil.CONNECTION_TIMEOUT.intValue());
                    HttpConnectionParams.setSoTimeout(clientParams, MadUtil.CONNECTION_TIMEOUT.intValue());

                    MadUtil.logMessage(null, Log.DEBUG, "Sending request");
                    httpResponse = httpClient.execute(postRequest);

                    MadUtil.logMessage(null, Log.DEBUG,
                            "Response Code => " + httpResponse.getStatusLine().getStatusCode());
                    if (testMode)
                        MadUtil.logMessage(null, Log.DEBUG, "Madvertise Debug Response: "
                                + httpResponse.getLastHeader("X-Madvertise-Debug"));
                    int responseCode = httpResponse.getStatusLine().getStatusCode();

                    HttpEntity entity = httpResponse.getEntity();

                    if (responseCode == 200 && entity != null) {
                        inputStream = entity.getContent();
                        String resultString = MadUtil.convertStreamToString(inputStream);
                        MadUtil.logMessage(null, Log.DEBUG, "Response => " + resultString);
                        json = new JSONObject(resultString);
                        jsonFetched = true;
                    }
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                    MadUtil.logMessage(null, Log.DEBUG, "Error in HTTP request / protocol");
                } catch (IOException e) {
                    e.printStackTrace();
                    MadUtil.logMessage(null, Log.DEBUG, "Could not receive a http response on an ad reqeust");
                } catch (JSONException e) {
                    e.printStackTrace();
                    MadUtil.logMessage(null, Log.DEBUG, "Could not parse json object");
                } finally {
                    if (inputStream != null)
                        try {
                            inputStream.close();
                        } catch (IOException e) {
                        }
                }

                // create ad, this is a blocking call
                if (jsonFetched) {
                    currentAd = new Ad(getContext(), json);
                }
            }
            mHandler.post(mUpdateResults);

        }
    }.start();
}

From source file:com.cloverstudio.spika.CameraCropActivity.java

public void scaleView() {
    // instantiate the views
    View top_view = findViewById(R.id.topView);
    View bottom_view = findViewById(R.id.bottomView);
    LinearLayout footer = (LinearLayout) findViewById(R.id.llFooter);
    LinearLayout crop_frame = (LinearLayout) findViewById(R.id.llCropFrame);
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    // 90% of width
    crop_container_size = (int) ((float) width * (1f - (10f / 100f)));

    // 10% margins
    float margin = ((float) width * (1f - (90f / 100f)));

    // Parameters for white crop border
    LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(crop_container_size, crop_container_size);
    par.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    par.setMargins((int) (margin / 2f), 0, (int) (margin / 2f), 0);
    crop_frame.setLayoutParams(par);// w  w  w .  j a  v  a2s  .  c  om

    // Margins for other transparent views
    float top_view_height = ((float) (height - crop_container_size - footer.getHeight())) / (float) 2;
    top_view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height));
    bottom_view
            .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height));

    // Image container
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(crop_container_size,
            crop_container_size);
    params.setMargins((int) (margin / 2f), (int) top_view_height, (int) (margin / 2f), 0);
    mImageView.setLayoutParams(params);
    mImageView.setImageBitmap(mBitmap);
    mImageView.setMaxZoom(4f);
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

/**
 * Adjusts the layout parameters of the barcode picker according to the margins set through java script.
 *
 * @param bundle The bundle with the java script parameters.
 * @param animationDuration Over how long the change should be animated.
 */// w  w  w .  java 2  s  .co  m
private void adjustLayout(Bundle bundle, double animationDuration) {
    if (mBarcodePicker == null) {
        return;
    }
    final RelativeLayout.LayoutParams rLayoutParams = (RelativeLayout.LayoutParams) mBarcodePicker
            .getLayoutParams();

    Display display = ((WindowManager) webView.getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    if (bundle.containsKey(ScanditSDKParameterParser.paramPortraitMargins)
            && display.getHeight() > display.getWidth()) {
        String portraitMargins = bundle.getString(ScanditSDKParameterParser.paramPortraitMargins);
        String[] split = portraitMargins.split("[/]");
        if (split.length == 4) {
            try {
                final Rect oldPortraitMargins = new Rect(mPortraitMargins);
                mPortraitMargins = new Rect(Integer.valueOf(split[0]), Integer.valueOf(split[1]),
                        Integer.valueOf(split[2]), Integer.valueOf(split[3]));
                if (animationDuration > 0) {
                    Animation anim = new Animation() {
                        @Override
                        protected void applyTransformation(float interpolatedTime, Transformation t) {
                            rLayoutParams.topMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.top
                                            + (mPortraitMargins.top - oldPortraitMargins.top)
                                                    * interpolatedTime));
                            rLayoutParams.rightMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.right
                                            + (mPortraitMargins.right - oldPortraitMargins.right)
                                                    * interpolatedTime));
                            rLayoutParams.bottomMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.bottom
                                            + (mPortraitMargins.bottom - oldPortraitMargins.bottom)
                                                    * interpolatedTime));
                            rLayoutParams.leftMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.left
                                            + (mPortraitMargins.left - oldPortraitMargins.left)
                                                    * interpolatedTime));
                            mBarcodePicker.setLayoutParams(rLayoutParams);
                        }
                    };
                    anim.setDuration((int) (animationDuration * 1000));
                    mBarcodePicker.startAnimation(anim);
                } else {

                    rLayoutParams.topMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.top);
                    rLayoutParams.rightMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.right);
                    rLayoutParams.bottomMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.bottom);
                    rLayoutParams.leftMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.left);
                    mBarcodePicker.setLayoutParams(rLayoutParams);
                }
            } catch (NumberFormatException e) {

            }
        }
    } else if (bundle.containsKey(ScanditSDKParameterParser.paramLandscapeMargins)
            && display.getWidth() > display.getHeight()) {
        String landscapeMargins = bundle.getString(ScanditSDKParameterParser.paramLandscapeMargins);
        String[] split = landscapeMargins.split("[/]");
        if (split.length == 4) {
            final Rect oldLandscapeMargins = new Rect(mLandscapeMargins);
            mLandscapeMargins = new Rect(Integer.valueOf(split[0]), Integer.valueOf(split[1]),
                    Integer.valueOf(split[2]), Integer.valueOf(split[3]));

            Animation anim = new Animation() {
                @Override
                protected void applyTransformation(float interpolatedTime, Transformation t) {
                    rLayoutParams.topMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.top
                                    + (mLandscapeMargins.top - oldLandscapeMargins.top) * interpolatedTime));
                    rLayoutParams.rightMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.right
                                    + (mLandscapeMargins.right - oldLandscapeMargins.right)
                                            * interpolatedTime));
                    rLayoutParams.bottomMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.bottom
                                    + (mLandscapeMargins.bottom - oldLandscapeMargins.bottom)
                                            * interpolatedTime));
                    rLayoutParams.leftMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.left
                                    + (mLandscapeMargins.left - oldLandscapeMargins.left) * interpolatedTime));
                    mBarcodePicker.setLayoutParams(rLayoutParams);
                }
            };
            anim.setDuration((int) (animationDuration * 1000));
            mBarcodePicker.startAnimation(anim);
        }
    }
}