Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:com.yaoyumeng.v2ex.ui.fragment.PhotoViewFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (sPhotoSize == null) {
        final DisplayMetrics metrics = new DisplayMetrics();
        final WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        final ImageUtils.ImageSize imageSize = ImageUtils.sUseImageSize;
        wm.getDefaultDisplay().getMetrics(metrics);
        switch (imageSize) {
        case EXTRA_SMALL:
            // Use a photo that's 80% of the "small" size
            sPhotoSize = (Math.min(metrics.heightPixels, metrics.widthPixels) * 800) / 1000;
            break;
        case SMALL:
            // Fall through.
        case NORMAL:
            // Fall through.
        default:/*from w ww. jav  a  2  s .c  o m*/
            sPhotoSize = Math.min(metrics.heightPixels, metrics.widthPixels);
            break;
        }
    }

    final Bundle bundle = getArguments();
    if (bundle == null) {
        return;
    }

    mDownloadUrl = bundle.getString(ARG_PHOTO_DOWNLOAD_URL);
    mPosition = bundle.getInt(ARG_POSITION);
}

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  v a 2  s . c  om*/
 */
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.g_node.gca.abstracts.AbstractCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    /*//from  www . j av  a  2 s. c o m
     * TextView for showing Title
     */
    TextView title = (TextView) view.findViewById(R.id.abTitle);
    title.setText(cursor.getString(cursor.getColumnIndexOrThrow("TITLE")));
    /*
     * TextView for showing Topic
     */
    TextView topic = (TextView) view.findViewById(R.id.abTopic);
    topic.setText(cursor.getString(cursor.getColumnIndexOrThrow("TOPIC")));
    /*
     * TextView for Showing Type
     */
    TextView type = (TextView) view.findViewById(R.id.abType);
    int absSortID = cursor.getInt(cursor.getColumnIndexOrThrow("SORTID"));

    if (absSortID != 0) {
        int groupid = ((absSortID & (0xFFFF << 16)) >> 16);

        switch (groupid) {
        case 0:
            type.setText("Invited Talk");
            type.setBackgroundColor(Color.parseColor("#33B5E5"));
            break;

        case 1:
            type.setText("Contributed Talk");
            type.setBackgroundColor(Color.parseColor("#ef4172"));
            break;

        case 2:
            type.setText("Poster");
            type.setBackgroundColor(Color.parseColor("#AA66CC"));
            break;

        case 3:
            type.setText("Poster");
            type.setBackgroundColor(Color.parseColor("#AA66CC"));
            break;
        default:
            break;
        }

        //absSortID.append("Group ID: " + get_groupid_str(groupid));

    } else {
        //type.setVisibility(View.GONE);
        type.setTextSize(TypedValue.COMPLEX_UNIT_SP, 4);
        type.setVisibility(View.INVISIBLE);
    }

    /*
    Following piece of commented code isn't needed as Abstract Type is 
    selected now based on GroupID. Previously it was being selected based on 'isTalk' field
    but now it's selected on basis of GroupID extracted from SortID. 
            
    String typeText = cursor.getString(cursor.getColumnIndexOrThrow("TYPE"));
    type.setText(typeText.toUpperCase());
            
    if(typeText.compareToIgnoreCase("poster") == 0) {
       type.setBackgroundColor(Color.parseColor("#AA66CC"));
    } else {
       type.setBackgroundColor(Color.parseColor("#33B5E5"));
    }
    */

    /*
     * _id for getting Author Names
     */
    String value = cursor.getString(cursor.getColumnIndexOrThrow("_id"));

    String authorNamesQuery = "SELECT ABSTRACT_UUID, AUTHORS_DETAILS.AUTHOR_UUID, AUTHORS_DETAILS.AUTHOR_FIRST_NAME, AUTHOR_MIDDLE_NAME, AUTHOR_LAST_NAME, AUTHOR_EMAIL, ABSTRACT_AUTHOR_POSITION_AFFILIATION.AUTHOR_POSITION as _aPos FROM ABSTRACT_AUTHOR_POSITION_AFFILIATION LEFT OUTER JOIN AUTHORS_DETAILS USING (AUTHOR_UUID) WHERE ABSTRACT_UUID = '"
            + value + "' ORDER BY _aPos;";
    cursorOne = DatabaseHelper.database.rawQuery(authorNamesQuery, null);

    if (cursorOne != null) {
        cursorOne.moveToFirst();
        /*
         * Name format will be like this A, B & C or A,B,C & D. So, if the
         * name is the last name. We should use '&' before the name
         */
        do {

            if (cursorOne.getPosition() == 0) {
                /*
                 * First data
                 */
                getName = cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));
            } else if (cursorOne.isLast()) {
                /*
                 * Last Data
                 */
                getName = getName + " & "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));
            } else {
                getName = getName + " , "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));

            }

        } while (cursorOne.moveToNext());
    }

    /*
     * TextView for Author Names
     */
    TextView authorNames = (TextView) view.findViewById(R.id.absAuthorNames);
    /*
     * Get Width
     */
    WindowManager WinMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    @SuppressWarnings("deprecation")
    int displayWidth = WinMgr.getDefaultDisplay().getWidth();
    Paint paint = new Paint();
    Rect bounds = new Rect();
    int text_width = 0;
    paint.getTextBounds(getName, 0, getName.length(), bounds);
    /*
     * Getting Text Width
     */
    text_width = bounds.width();
    /*
     * If Text Width is greater than Display Width Then show First Name et
     * al.
     */
    if (text_width > displayWidth) {
        String output = getName.split(",")[0] + " et al. ";
        authorNames.setText(output);

    } else {
        /*
         * Name Format will be like this If the Name is Yasir Adnan So,It
         * will be Y.Adnan
         */
        authorNames.setText(getName.replaceAll("((?:^|[^A-Z.])[A-Z])[a-z]*\\s(?=[A-Z])", "$1."));
    }
}

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)}./* w  w w .  j  ava2s  .  com*/
 */
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:com.raspi.chatapp.ui.util.emojicon.EmojiconPopup.java

/**
 * set the size automatically to the softKeyboard size (if one exists)
 *///from w  ww. jav a2s  .c  o  m
public void setSoftKeyboardSize() {
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            rootView.getWindowVisibleDisplayFrame(r);

            int screenHeight = getUsableScreenHeight();
            int heightDiff = screenHeight - (r.bottom - r.top);
            int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0)
                heightDiff -= context.getResources().getDimensionPixelSize(resourceId);
            if (heightDiff > 100) {
                keyboardHeight = heightDiff;
                setSize(LayoutParams.MATCH_PARENT, keyboardHeight);
                if (!isOpen && onSoftKeyboardOpenCloseListener != null)
                    onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyboardHeight);
                isOpen = true;
                if (pendingOpen) {
                    showAtBottom();
                    pendingOpen = false;
                }
            } else {
                isOpen = false;
                if (onSoftKeyboardOpenCloseListener != null)
                    onSoftKeyboardOpenCloseListener.onKeyboardClose();
            }
        }

        private int getUsableScreenHeight() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                DisplayMetrics metrics = new DisplayMetrics();

                WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                manager.getDefaultDisplay().getMetrics(metrics);
                return metrics.heightPixels;
            }
            return rootView.getRootView().getHeight();
        }
    });
}

From source file:org.xwalk.embedding.asynctest.v6.XWalkViewTestAsync.java

@SmallTest
public void testSetInitialScale2() throws Throwable {

    WindowManager wm = (WindowManager) getInstrumentation().getTargetContext()
            .getSystemService(Context.WINDOW_SERVICE);
    Point screenSize = new Point();
    wm.getDefaultDisplay().getSize(screenSize);
    // Make sure after 50% scale, page width still larger than screen.
    int height = screenSize.y * 2 + 1;
    int width = screenSize.x * 2 + 1;
    final String page = "<html><body>" + "<p style='height:" + height + "px;width:" + width + "px'>"
            + "testSetInitialScale</p></body></html>";
    final float defaultScaleFactor = 0;
    final float defaultScale = 0.5f;
    final float scaleFactor = 0.25f;

    assertEquals(defaultScaleFactor, getScaleFactor(), .01f);
    loadDataSync(null, page, "text/html", false);
    assertEquals(scaleFactor, getScaleFactor(), .01f);

    int onScaleChangedCallCount = mTestHelperBridge.getOnScaleChangedHelper().getCallCount();
    setInitialScale(60);//from w w  w  .  j  a va2  s.c  om
    loadDataSync(null, page, "text/html", false);
    mTestHelperBridge.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(0.6f, getPixelScale(), .01f);

    onScaleChangedCallCount = mTestHelperBridge.getOnScaleChangedHelper().getCallCount();
    setInitialScale(500);
    loadDataSync(null, page, "text/html", false);
    mTestHelperBridge.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(5.0f, getPixelScale(), .01f);

    onScaleChangedCallCount = mTestHelperBridge.getOnScaleChangedHelper().getCallCount();
    // default min-scale will be used.
    setInitialScale(0);
    loadDataSync(null, page, "text/html", false);
    mTestHelperBridge.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(defaultScale, getPixelScale(), .01f);
}

From source file:com.charon.video.view.ScrollingTabs.java

private int getWindowWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

From source file:com.sudeep23.lollipoptabs.fixedtab.FixedTabLayout.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  ava  2 s .  c om*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
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);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = 0;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
    } else {
        width = display.getWidth(); // deprecated
    }
    textView.setWidth(width / tabCount);

    return textView;
}

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

/**
 * Creates the popup and assigns cached properties.
 *
 * @return an initialized popup/*from w w w .  ja  v  a2 s . c  om*/
 */
@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;
}

From source file:com.tekinarslan.material.sample.customui.slidingtab.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*from  w w  w.  j a  va 2s. co m*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    viewWidth = display.getWidth();
}