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:mits.uwi.com.ourmobileenvironment.SlidingTabLayout.java

/**
 * Sets the Width of the Action bar based on How many Tabs will be used
 * @param tabNum//from w ww  .j av a  2s .  c o  m
 * @param tabTitleView
 */

private void setActionBarWidth(int tabNum, TextView tabTitleView) {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    tabTitleView.setWidth(size.x / tabNum);
    if (getResources().getConfiguration().orientation == getResources()
            .getConfiguration().ORIENTATION_LANDSCAPE) {
        tabTitleView.setWidth((int) Math.ceil(size.x * 0.34));
    }

}

From source file:com.example.rachid.myapplication.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*  w  w w . j  a  va  2s. co m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    // AADIDO: Ajustar pantalla
    // ---------------------------------------------------------------------------------------
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);
    // ---------------------------------------------------------------------------------------

    return textView;
}

From source file:com.dtd.thevyshka.Utils.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from   w w w . ja v  a2 s .co m*/
 */
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / mTabCount);

    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(12);//TODO adapting to all
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(ContextCompat.getColor(context, R.color.white));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding / 2, padding, padding / 2, padding);

    return textView;
}

From source file:com.av.benzandroid.views.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from   ww w . ja va 2  s .  co m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    //Fit tabs in parent view width
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / mRowCount);

    textView.setTextColor(DEFAULT_TEXTVIEW_COLOR);
    //        textView.setTextColor(SELECTED_TEXTVIEW_COLOR);
    return textView;
}

From source file:com.syaona.petalierapp.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from w  w  w  .  j  av a 2s .  c  o m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(false);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    //Fit tabs in parent view width
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / mRowCount);

    textView.setTextColor(DEFAULT_TEXTVIEW_COLOR);
    //        textView.setTextColor(SELECTED_TEXTVIEW_COLOR);
    return textView;
}

From source file:org.xwalk.runtime.extension.api.device_capabilities.DeviceCapabilitiesDisplay.java

public JSONObject convertDisplayToJSON(Display disp) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    disp.getRealMetrics(displayMetrics);

    Point realSize = new Point();
    disp.getRealSize(realSize);//from  ww  w  .j  a  v  a  2s  .com

    Point availSize = new Point();
    disp.getSize(availSize);

    JSONObject out = new JSONObject();
    try {
        out.put("id", disp.getDisplayId());
        out.put("name", disp.getName());
        out.put("isPrimary", disp.getDisplayId() == disp.DEFAULT_DISPLAY);
        out.put("isInternal", disp.getDisplayId() == disp.DEFAULT_DISPLAY);
        out.put("dpiX", (int) displayMetrics.xdpi);
        out.put("dpiY", (int) displayMetrics.ydpi);
        out.put("width", realSize.x);
        out.put("height", realSize.y);
        out.put("availWidth", availSize.x);
        out.put("availHeight", availSize.y);
    } catch (JSONException e) {
        return mDeviceCapabilities.setErrorMessage(e.toString());
    }
    return out;
}

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

@SuppressWarnings("unchecked")
public SelectMultiWidgetGridLayout(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mPrompt = prompt;//from w w w.j  ava2 s .  com
    mCheckboxes = new ArrayList<CheckBox>();

    // SurveyCTO-added support for dynamic select content (from .csv files)
    XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint());
    if (xPathFuncExpr != null) {
        mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr);
    } else {
        mItems = prompt.getSelectChoices();
    }

    setOrientation(LinearLayout.VERTICAL);

    Vector<Selection> ve = new Vector<Selection>();
    if (prompt.getAnswerValue() != null) {
        ve = (Vector<Selection>) prompt.getAnswerValue().getValue();
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int height = size.y;

    int halfScreenWidth = (int) (screenWidth * 0.5);
    int quarterScreenWidth = (int) (halfScreenWidth * 0.5);

    glayout = new GridLayout(getContext());
    glayout.setOrientation(0);
    glayout.setColumnCount(2);
    //glayout.setRowCount(2);

    int row_index = 0;
    int col_index = 0;

    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {
            // no checkbox group so id by answer + offset
            CheckBox c = new CheckBox(getContext());
            c.setTag(Integer.valueOf(i));
            c.setId(QuestionWidget.newUniqueId());
            c.setText(prompt.getSelectChoiceText(mItems.get(i)));
            c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
            c.setFocusable(!prompt.isReadOnly());
            c.setEnabled(!prompt.isReadOnly());

            for (int vi = 0; vi < ve.size(); vi++) {
                // match based on value, not key
                if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) {
                    c.setChecked(true);
                    break;
                }

            }
            mCheckboxes.add(c);
            // when clicked, check for readonly before toggling
            c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (!mCheckboxInit && mPrompt.isReadOnly()) {
                        if (buttonView.isChecked()) {
                            buttonView.setChecked(false);
                            Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                    "onItemClick.deselect",
                                    mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex());
                        } else {
                            buttonView.setChecked(true);
                            Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                    "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(),
                                    mPrompt.getIndex());
                        }
                    }
                }
            });

            String audioURI = null;
            audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO);

            String imageURI;
            if (mItems.get(i) instanceof ExternalSelectChoice) {
                imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage();
            } else {
                imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                        FormEntryCaption.TEXT_FORM_IMAGE);
            }

            String videoURI = null;
            videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video");

            String bigImageURI = null;
            bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image");

            MediaLayout mediaLayout = new MediaLayout(getContext());
            mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), c, audioURI, imageURI, videoURI,
                    bigImageURI);
            // mediaLayout.setAVT(index, selectionDesignator, text, audioURI, imageURI, videoURI, bigImageURI);
            // addView(mediaLayout);

            row_index = i / 2 + 1;
            col_index = i % 2;

            int orientation = display.getOrientation();
            if (orientation == 1) {
                halfScreenWidth = height / 2;
            } else {
                halfScreenWidth = screenWidth / 2;
            }

            Spec row = GridLayout.spec(row_index);
            Spec col = GridLayout.spec(col_index);
            GridLayout.LayoutParams first = new GridLayout.LayoutParams(row, col);
            first.width = halfScreenWidth;
            // first.height = quarterScreenWidth * 2;
            glayout.addView(mediaLayout, first);

            // Last, add the dividing line between elements (except for the last element)
            ImageView divider = new ImageView(getContext());
            divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            if (i != mItems.size() - 1) {
                if (col_index == 0)
                    glayout.addView(divider);
            }

        }
    }
    addView(glayout);
    mCheckboxInit = false;

}

From source file:com.microsoft.mimickeralarm.mimics.MimicWithCameraFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_camera_mimic, container, false);

    SurfaceView previewView = (SurfaceView) view.findViewById(R.id.camera_preview_view);

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    mSize = size;/*from ww  w. j a  v a 2s.  co m*/
    double aspectRatio = size.y > size.x ? (double) size.y / (double) size.x
            : (double) size.x / (double) size.y;
    mCameraPreview = new CameraPreview(previewView, aspectRatio, CameraFacing);

    View overlay = view.findViewById(R.id.camera_preview_overlay);
    overlay.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                // Camera sensor ranges from -1000 to 1000 regardless of aspect ratio, sizes, resolution, ...
                int deltaX = (int) (((float) mSize.x - event.getX()) / mSize.x * -2000) + 1000;
                int deltaY = (int) (((float) mSize.y - event.getY()) / mSize.y * -2000) + 1000;
                mCameraPreview.onFocus(deltaX, deltaY);
            }
            return true;
        }
    });

    ProgressButton progressButton = (ProgressButton) view.findViewById(R.id.capture_button);
    progressButton.setReadyState(ProgressButton.State.ReadyCamera);

    mStateManager = new MimicStateManager();
    mStateManager.registerCountDownTimer((CountDownTimerView) view.findViewById(R.id.countdown_timer),
            TIMEOUT_MILLISECONDS);
    mStateManager.registerStateBanner((MimicStateBanner) view.findViewById(R.id.mimic_state));
    mStateManager.registerProgressButton(progressButton, MimicButtonBehavior.CAMERA);
    mStateManager.registerMimic(this);

    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    if (mSensorManager != null) {
        mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    }
    mLightSensorListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.values[0] < LIGHT_THRESHOLD && CameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                mTooDarkToast.show();
            } else {
                mTooDarkToast.cancel();
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }
    };
    // This toast is only shown when there is not enough light
    mTooDarkToast = Toast.makeText(getActivity(), getString(R.string.mimic_camera_too_dark),
            Toast.LENGTH_SHORT);

    return view;
}

From source file:org.protocoderrunner.base.BaseActivity.java

public Point getScrenSize() {

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

    return size;//from  w  w  w.  j a  va  2 s.co  m
}

From source file:com.phicdy.mycuration.ui.TopActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top);

    curationFragment = new CurationListFragment();
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.addOnPageChangeListener(new PageChangeListener());
    track = (ViewGroup) findViewById(R.id.track);
    trackScroller = (HorizontalScrollView) findViewById(R.id.track_scroller);
    indicator = (View) findViewById(R.id.indicator);

    WindowManager wm = getWindowManager();
    Display disp = wm.getDefaultDisplay();
    Point size = new Point();
    disp.getSize(size);
    int displayWidth = size.x;
    LayoutInflater inflater = LayoutInflater.from(this);
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        final int position = i;
        ImageView ivTab = (ImageView) inflater.inflate(R.layout.tab_item, track, false);
        ivTab.setImageResource(mSectionsPagerAdapter.getImageResource(position));
        ivTab.setOnClickListener(new View.OnClickListener() {
            @Override/*ww  w  .ja  va 2 s.co m*/
            public void onClick(View v) {
                mViewPager.setCurrentItem(position);
            }
        });
        final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) ivTab.getLayoutParams();
        layoutParams.width = displayWidth / mSectionsPagerAdapter.getCount();
        ivTab.setLayoutParams(layoutParams);
        track.addView(ivTab);
    }

    final float density = getResources().getDisplayMetrics().density;
    indicatorOffset = (int) (INDICATOR_OFFSET_DP * density);

    setTitle(getString(R.string.home));

    dbAdapter = DatabaseAdapter.getInstance(getApplicationContext());
    setAlarmManager();
}