Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

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

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

From source file:com.farmerbb.taskbar.activity.DashboardActivity.java

@SuppressWarnings("deprecation")
@Override//w w  w . j a va2  s .co  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    contextMenuFix = getIntent().hasExtra("context_menu_fix");

    // Detect outside touches, and finish the activity when one is detected
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);

    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);

    setContentView(R.layout.incognito);

    LinearLayout layout = (LinearLayout) findViewById(R.id.incognitoLayout);
    layout.setLayoutParams(new FrameLayout.LayoutParams(display.getWidth(), display.getHeight()));

    LocalBroadcastManager.getInstance(this).registerReceiver(addWidgetReceiver,
            new IntentFilter("com.farmerbb.taskbar.ADD_WIDGET_REQUESTED"));
    LocalBroadcastManager.getInstance(this).registerReceiver(removeWidgetReceiver,
            new IntentFilter("com.farmerbb.taskbar.REMOVE_WIDGET_REQUESTED"));
    LocalBroadcastManager.getInstance(this).registerReceiver(finishReceiver,
            new IntentFilter("com.farmerbb.taskbar.DASHBOARD_DISAPPEARING"));

    if (!DashboardHelper.getInstance().isDashboardOpen())
        finish();
}

From source file:com.nikola.despotoski.drawerlayoutedgetoggle.DrawerLayoutEdgeToggle.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private int getScreenWidth() {

    Point size = new Point();
    WindowManager w = mActivity.getWindowManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        w.getDefaultDisplay().getSize(size);
        return size.x;
    } else {/*from  w w w. j  av a 2 s.c  o  m*/
        Display d = w.getDefaultDisplay();
        return d.getWidth();
    }
}

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

private void setupScreen() {
    setOrientation(LinearLayout.VERTICAL);

    // Retrieve answer from data model and update ui
    mBinaryName = mPrompt.getAnswerText();

    // Set location of folder containing answer
    mInstanceFolder = FormEntryActivity.mInstancePath.substring(0,
            FormEntryActivity.mInstancePath.lastIndexOf("/") + 1);

    // Error text, if needed
    mErrorTextView = new TextView(getContext());
    mErrorTextView.setText("Selected file is not a valid image");

    LayoutParams layoutParams = new TableLayout.LayoutParams();
    layoutParams.setMargins(7, 5, 7, 5);

    mCaptureButton = new Button(getContext());
    mCaptureButton.setText(getCapturePrompt());
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!mPrompt.isReadOnly());
    mCaptureButton.setLayoutParams(layoutParams);

    // Launch capture intent on click
    mCaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w  w .  jav a 2  s  .co  m*/
        public void onClick(View v) {
            mWaitingForData = true;
            mErrorTextView.setVisibility(View.GONE);

            File tmp = new File(
                    FileUtilsExtended.EXTERNAL_CACHE + File.separator + FileUtilsExtended.CAPTURED_IMAGE_FILE);

            // Copy existing image into temporary slot (edit existing image)
            if (mBinaryName == null) {
                // Remove this file if it's still sitting around
                tmp.delete();
            } else {
                try {
                    org.apache.commons.io.FileUtils.copyFile(new File(mInstanceFolder, mBinaryName), tmp);
                } catch (IOException e) {
                    Log.e(Collect.LOGTAG,
                            t + "unable to copy existing binary image to temporary location: " + e.toString());
                    e.printStackTrace();
                }
            }

            Intent i = new Intent(getContext(), DrawActivity.class);
            i.putExtra(DrawActivity.KEY_DRAW_MODE, mDrawMode);
            i.putExtra(DrawActivity.KEY_OUTPUT_URI, Uri.fromFile(tmp));
            ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
        }
    });

    addView(mCaptureButton);

    // Proceed to add the imageView only if the user has taken a picture
    if (mBinaryName == null)
        return;

    // Below taken from ImageWidget (w/o onClick for loading a larger image)
    mImageView = new ImageView(getContext());

    Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    int screenWidth = display.getWidth();
    int screenHeight = display.getHeight();

    File f = new File(mInstanceFolder + "/" + 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);

    addView(mImageView);
}

From source file:io.github.importre.android.chromeadb.ChromeAdbService.java

@SuppressLint("NewApi")
private void setCursorPosToCenter() {
    if (mWindowManager == null || mCursorImage == null) {
        return;//from   w  ww .  ja  v  a 2  s . c  o  m
    }

    Display display = mWindowManager.getDefaultDisplay();
    int x, y;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);
        x = size.x;
        y = size.y;
    } else {
        x = display.getWidth();
        y = display.getHeight();
    }

    move(x >> 1, y >> 1);
}

From source file:net.openwatch.acluaz.FormFragmentActivity.java

/**
 * Measure display width so the view pager can implement its 
 * custom behavior re: paging on the map view
 */// w w w  .  ja va2 s.c  om
private void getDisplayWidth() {
    Display display = getWindowManager().getDefaultDisplay();
    display_width = display.getWidth();
}

From source file:com.ubuntuone.android.files.fragment.GalleryFragment.java

@Override
public void onDownloadCached(String key, String path) {
    final GalleryViewHolder holder = holders.get(key);
    if (holder != null) {
        WindowManager wm = getActivity().getWindowManager();
        Display display = wm.getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        int maxDimention = Math.max(width, height);

        final Bitmap bitmap = BitmapUtilities.decodeFile(new File(path), maxDimention);
        mHandler.post(new Runnable() {
            @Override// ww w.  j av  a 2s . co  m
            public void run() {
                if (holder.previewImage != null) {
                    holder.previewImage.setImageDrawable(new BitmapDrawable(bitmap));
                    holder.progressWrapper.setVisibility(View.GONE);
                }
            }
        });
    }
}

From source file:se.leap.bitmaskclient.ConfigurationWizard.java

private int listItemHeight() {
    View listItem = adapter.getView(0, null, provider_list_view);
    listItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT));
    WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int screenWidth = display.getWidth(); // deprecated

    int listViewWidth = screenWidth - 10 - 10;
    int widthSpec = View.MeasureSpec.makeMeasureSpec(listViewWidth, View.MeasureSpec.AT_MOST);
    listItem.measure(widthSpec, 0);//  w  ww.j  a v  a 2s  .c om

    return listItem.getMeasuredHeight();
}

From source file:com.github.mobile.util.HttpImageGetter.java

@SuppressWarnings("deprecation")
private Point fetchDisplaySizePreHoneycomb(WindowManager wm) {
    Display display = wm.getDefaultDisplay();
    return new Point(display.getWidth(), display.getHeight());
}

From source file:com.bitants.wally.fragments.ImageZoomFragment.java

private void animateIn(final Dialog dialog) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomableImageView.getLayoutParams();
    params.width = rect.right;//ww  w  .  j a v a  2 s.  c om
    params.height = rect.bottom;
    zoomableImageView.setLayoutParams(params);

    zoomableImageView.setX(rect.left);
    zoomableImageView.setY(rect.top - statusBarHeightCorrection);
    zoomableImageView.setAlpha(0.0f);
    zoomableImageView.setImageBitmap(bitmap);

    WindowManager win = getActivity().getWindowManager();
    Display d = win.getDefaultDisplay();
    int displayWidth = d.getWidth(); // Width of the actual device
    int displayHeight = d.getHeight() + statusBarHeightCorrection;

    ValueAnimator animWidth = ValueAnimator.ofInt(rect.right, displayWidth);
    animWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.width = val;
            zoomableImageView.setLayoutParams(layoutParams);
        }
    });
    animWidth.setDuration(500);
    animWidth.setInterpolator(new LinearOutSlowInInterpolator());
    animWidth.start();

    ValueAnimator animHeight = ValueAnimator.ofInt(rect.bottom, displayHeight);
    animHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.height = val;
            zoomableImageView.setLayoutParams(layoutParams);
        }
    });
    animHeight.setDuration(500);
    animHeight.setInterpolator(new LinearOutSlowInInterpolator());

    animHeight.start();

    if (statusBarHeightCorrection > 0) {
        zoomableImageView.animate().y(0.0f).setDuration(300).start();
    }

    ValueAnimator animDim = ValueAnimator.ofFloat(0.0f, 0.5f);
    animDim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            layoutParams.copyFrom(dialog.getWindow().getAttributes());
            layoutParams.dimAmount = (Float) valueAnimator.getAnimatedValue();
            dialog.getWindow().setAttributes(layoutParams);
        }
    });
    animDim.setDuration(300);
    animDim.setStartDelay(300);
    animDim.start();
    zoomableImageView.animate().alpha(1.0f).setDuration(300).start();
}

From source file:io.selendroid.server.model.internal.execute_native.IsElementDisplayedInViewport.java

@SuppressWarnings("deprecation")
public boolean isDisplayedOnViewport(View view) {
    int coordinates[] = { -1, -1 };
    int width = 0, height = 0;

    view.getLocationOnScreen(coordinates);
    if (coordinates[0] + view.getWidth() < 0)
        return false;
    if (coordinates[1] + view.getHeight() < 0)
        return false;

    if (width == 0 || height == 0) {
        if (instrumentation.getContext() == null)
            return false;
        Display display = ((WindowManager) instrumentation.getContext()
                .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        try {//from   w w w .  j a  va 2 s  .  co  m
            android.graphics.Point screenSize = new android.graphics.Point();
            display.getSize(screenSize);
            width = screenSize.x;
            height = screenSize.y;
        } catch (NoSuchMethodError e) {
            width = display.getWidth();
            height = display.getHeight();
        }
    }

    if (coordinates[0] > width)
        return false;
    if (coordinates[1] > height)
        return false;

    return true;
}