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.noriginmedia.exoplayer.VideoPlayerFragment.java

private void resizeVideo(Configuration config, boolean fullscreen) {
    Display display = mActivity.getWindowManager().getDefaultDisplay();
    int screenWidth = display.getWidth();
    int screenHeight = display.getHeight();
    boolean softkeys = false;
    resizeVideo(config, fullscreen, screenWidth, screenHeight, true, softkeys);
}

From source file:com.farmerbb.taskbar.adapter.StartMenuAdapter.java

@SuppressWarnings("deprecation")
private void openContextMenu(final AppEntry entry, final int[] location) {
    LocalBroadcastManager.getInstance(getContext())
            .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

    new Handler().postDelayed(() -> {
        SharedPreferences pref = U.getSharedPreferences(getContext());
        Intent intent = null;/*from   w w  w  .j  a v a2 s  .co  m*/

        switch (pref.getString("theme", "light")) {
        case "light":
            intent = new Intent(getContext(), ContextMenuActivity.class);
            break;
        case "dark":
            intent = new Intent(getContext(), ContextMenuActivityDark.class);
            break;
        }

        if (intent != null) {
            intent.putExtra("package_name", entry.getPackageName());
            intent.putExtra("app_name", entry.getLabel());
            intent.putExtra("component_name", entry.getComponentName());
            intent.putExtra("user_id", entry.getUserId(getContext()));
            intent.putExtra("launched_from_start_menu", true);
            intent.putExtra("x", location[0]);
            intent.putExtra("y", location[1]);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
            DisplayManager dm = (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
            Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);

            if (intent != null && U.isOPreview())
                intent.putExtra("context_menu_fix", true);

            getContext().startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU)
                    .setLaunchBounds(new Rect(0, 0, display.getWidth(), display.getHeight())).toBundle());
        } else
            getContext().startActivity(intent);
    }, shouldDelay() ? 100 : 0);
}

From source file:org.secuso.privacyfriendlydicegame.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w  w  w  .  ja va  2 s  .  c  o m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    hints(0);

    Display display = getWindowManager().getDefaultDisplay();
    setSizes(display.getWidth() / 40, Math.round(display.getWidth() / 4));

    final TextView finalResult = (TextView) findViewById(R.id.resultTextView);

    Button rollDiceButtonNotFinal = (Button) findViewById(R.id.button);
    rollDiceButtonNotFinal.setText(getString(R.string.roll_button));

    dice = new Button[5];
    dice[0] = (Button) findViewById(R.id.button_dice_one);
    dice[1] = (Button) findViewById(R.id.button_dice_two);
    dice[2] = (Button) findViewById(R.id.button_dice_three);
    dice[3] = (Button) findViewById(R.id.button_dice_four);
    dice[4] = (Button) findViewById(R.id.button_dice_five);

    for (int i = 0; i < dice.length; i++) {
        dice[i].setWidth(Math.round(diceSize));
        dice[i].setHeight(Math.round(diceSize));
    }

    isLocked = new boolean[5];
    for (int k = 0; k < isLocked.length; k++) {
        isLocked[k] = false;
    }

    for (int i = 0; i < dice.length; i++) {
        dice[i].setBackground(getResources().getDrawable(R.drawable.invisible_button));
    }

    oldResults = new int[] { 1, 2, 3, 4, 5 };
    backResults = new int[] { 1, 2, 3, 4, 5 };

    roundCounter = 0;

    final RelativeLayout diceContainer = (RelativeLayout) findViewById(R.id.dice_frame);
    final RelativeLayout diceRowTwo = (RelativeLayout) findViewById(R.id.dice_frame_second);

    //buttons
    final Button rollDiceButton = (Button) findViewById(R.id.button);
    rollDiceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (allTrue(isLocked)) {
                for (int k = 0; k < dice.length; k++) {
                    dice[k].setBackground(getResources().getDrawable(R.drawable.dice_final));
                }
                finalResult.setVisibility(View.VISIBLE);
                rollDiceButton.setText(getString(R.string.new_round_button));
                roundCounter = 3;
                for (int k = 0; k < isLocked.length; k++) {
                    isLocked[k] = false;
                }
            } else {

                if (diceContainer.getChildCount() > 0)
                    diceContainer.removeAllViews();
                if (diceRowTwo.getChildCount() > 0)
                    diceRowTwo.removeAllViews();
                setDice(rollDice(5));

                if (roundCounter == 0) {
                    for (int k = 0; k < dice.length; k++) {
                        dice[k].setBackground(getResources().getDrawable(R.drawable.dice));
                    }
                }

                if (roundCounter == 2) {
                    for (int k = 0; k < dice.length; k++) {
                        dice[k].setBackground(getResources().getDrawable(R.drawable.dice_final));
                    }
                    finalResult.setVisibility(View.VISIBLE);
                    rollDiceButton.setText(getString(R.string.new_round_button));
                }

                if (roundCounter == 3) {
                    resetInterface();
                    finalResult.setVisibility(View.INVISIBLE);
                    rollDiceButton.setText(getString(R.string.roll_button));

                } else {
                    roundCounter++;
                }
                TextView roundCounterTextView = (TextView) findViewById(R.id.roundTextView);
                roundCounterTextView.setText(Integer.toString(roundCounter));
                flashResult();
            }
        }
    });

    Button resetButton = (Button) findViewById(R.id.resetButton);
    resetButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (roundCounter != 0) {
                resetInterface();
                finalResult.setVisibility(View.INVISIBLE);
            }

        }
    });

    for (int j = 0; j < dice.length; j++) {
        final int finalJ = j;
        dice[j].setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (roundCounter == 0) {
                } else if (roundCounter != 3) {
                    setLock(finalJ, v);
                }
            }
        });
    }

}

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:com.twjg.chromecast2048.activities.MainActivity.java

private void seekbarUpdated() {
    SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar);
    TextView seekBarValue = (TextView) findViewById(R.id.seekBarValue);
    DragTriggerView dragArea = (DragTriggerView) findViewById(R.id.dragArea);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    float width = display.getWidth();
    float progress = seekbar.getProgress();
    this.mDragThreshold = Math.round(width * (progress / 100.0f));
    seekBarValue.setText("" + this.mDragThreshold + "px");
    dragArea.setDragThreshold(this.mDragThreshold);
}

From source file:com.netpace.expressit.activity.UploadVideoStoryActivity.java

@SuppressLint("NewApi")
private Point getDisplayDimensions() {

    Point size = new Point();
    Display display = getWindowManager().getDefaultDisplay();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);//w  w w .java2s.  com
    } else {
        size.set(display.getWidth(), display.getHeight());
    }

    return size;
}

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 av  a2s .  c o  m
    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.//from   ww  w .ja v  a2s . 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.p3authentication.preferences.Prefs.java

@SuppressWarnings("deprecation")
private void calibrate(float x, float y, float pressure, float size) {

    Display display = Prefs.this.getWindowManager().getDefaultDisplay();
    float mCurRadius = (size * (display.getWidth() / 3));
    // fingsize.setText(String.valueOf(mCurRadius));
    CalList.add(mCurRadius);/*  www .  j  av a  2 s  .  c o  m*/
}

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 .  ja  v a2 s .  c o m

    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);
}