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:android.percent.support.PercentLayoutHelper.java

private void getScreenSize() {
    WindowManager wm = (WindowManager) mHost.getContext().getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    mWidthScreen = outMetrics.widthPixels;
    mHeightScreen = outMetrics.heightPixels;
}

From source file:com.jinfukeji.jinyihuiup.indexBannerClick.ZhiboActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:

        break;/*from w w  w. j a v a  2  s .com*/
    case MotionEvent.ACTION_MOVE:
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        float rawX = ev.getRawX();
        float rawY = ev.getRawY();
        float x = ev.getX();
        float y = ev.getY();
        if (rawX < width / 2) {
            if (rawY < y) {
                streamVolume++;
                changeAudio(streamVolume);
            } else {
                streamVolume--;
                changeAudio(streamVolume);
            }
        } else {
            if (rawY < y) {

            } else {

            }
        }
        break;
    case MotionEvent.ACTION_UP:

        break;
    case MotionEvent.ACTION_SCROLL:

        break;
    }
    return super.dispatchTouchEvent(ev);
}

From source file:com.xuejian.client.lxp.module.toolbox.im.IMMainActivity.java

private void showActionDialog() {
    final Activity act = this;
    final AlertDialog dialog = new AlertDialog.Builder(act).create();
    View contentView = View.inflate(act, R.layout.dialog_city_detail_action, null);
    Button btn = (Button) contentView.findViewById(R.id.btn_go_plan);
    btn.setText("Talk");
    btn.setOnClickListener(new View.OnClickListener() {
        @Override//ww w. j  a v  a 2  s . c  o m
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_create_new_talk");
            startActivityForResult(new Intent(IMMainActivity.this, PickContactsWithCheckboxActivity.class)
                    .putExtra("request", NEW_CHAT_REQUEST_CODE), NEW_CHAT_REQUEST_CODE);
            dialog.dismiss();
        }
    });
    Button btn1 = (Button) contentView.findViewById(R.id.btn_go_share);
    btn1.setText("?");
    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_add_new_friend");
            startActivity(new Intent(IMMainActivity.this, AddContactActivity.class));
            dialog.dismiss();
        }
    });
    contentView.findViewById(R.id.btn_cancle).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
    WindowManager windowManager = act.getWindowManager();
    Window window = dialog.getWindow();
    window.setContentView(contentView);
    Display display = windowManager.getDefaultDisplay();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = (int) (display.getWidth()); // 
    window.setAttributes(lp);
    window.setGravity(Gravity.BOTTOM); // ?dialog?
    window.setWindowAnimations(R.style.SelectPicDialog); // 
}

From source file:com.zhy.android.percent.support.PercentLayoutHelper.java

private void getScreenSize() {
    WindowManager wm = (WindowManager) mHost.getContext().getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    mWidthScreen = outMetrics.widthPixels;
    mHeightScreen = outMetrics.heightPixels;
    mSmallEdge = Math.min(mWidthScreen, mHeightScreen);
    mLongEdge = Math.max(mWidthScreen, mHeightScreen);
}

From source file:tw.com.sti.store.api.android.AndroidApiService.java

private AndroidApiService(Context context, Configuration config) {
    this.config = config;
    this.apiUrl = new ApiUrl(config);
    if (Logger.DEBUG)
        L.d("new ApiService()");

    sdkVer = Build.VERSION.SDK;//  www  .  j  a va2  s.  c o  m
    sdkRel = Build.VERSION.RELEASE;
    try {
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_ACTIVITIES);
        storeId = pi.packageName;
        clientVer = "" + pi.versionCode;
    } catch (NameNotFoundException e) {
    }
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId();
    macAddress = NetworkUtils.getDeviceMacAddress(context);
    subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId();
    simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    try {
        Class<Display> cls = Display.class;
        Method method = cls.getMethod("getRotation");
        Object retobj = method.invoke(display);
        int rotation = Integer.parseInt(retobj.toString());
        if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) {
            wpx = "" + display.getWidth();
            hpx = "" + display.getHeight();
        } else {
            wpx = "" + display.getHeight();
            hpx = "" + display.getWidth();
        }
    } catch (Exception e) {
        if (display.getOrientation() == 1) {
            wpx = "" + display.getHeight();
            hpx = "" + display.getWidth();
        } else {
            wpx = "" + display.getWidth();
            hpx = "" + display.getHeight();
        }
    }

    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    //      token = pref.getString(PREF_KEY_TOKEN, "");
    //      uid = pref.getString(PREF_KEY_UID, "");
    //      userId = pref.getString(PREF_KEY_USER_ID, "");
    appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0);
    // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true);

    // ??SIM?
    String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0");
    String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0");
    if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) {
        if (Logger.DEBUG)
            L.d("Change SIM card.");
        cleanCredential(context);
    }
    this.getCredential(context);
}

From source file:com.example.yudiandrean.socioblood.FeedActivity.java

@SuppressLint("NewApi")
@Override//w  ww  . ja  v  a 2s  .  c  om
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final Dialog d = new Dialog(context);
    setContentView(R.layout.feed_activity);
    postrequest = (TextView) findViewById(R.id.editText);

    WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);
    final int width, height;
    ActionBar.LayoutParams params;

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
        width = manager.getDefaultDisplay().getWidth();
        height = manager.getDefaultDisplay().getHeight();
    } else {
        Point point = new Point();
        manager.getDefaultDisplay().getSize(point);
        width = point.x;
        height = point.y;
    }

    session = new SessionManager(getApplicationContext());

    // Check if user is already logged in or not
    if (!session.isLoggedIn()) {
        // User is already logged in. Take him to main activity
        Intent intent = new Intent(FeedActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }

    listView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
    feedItems = new ArrayList<FeedItem>();

    listAdapter = new FeedListAdapter(this, feedItems);
    listView.setAdapter(listAdapter);

    swipeRefreshLayout.setOnRefreshListener(this);

    // add button listener
    postrequest.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            try {
                d.requestWindowFeature(Window.FEATURE_NO_TITLE);
                d.setContentView(R.layout.post_request);
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                lp.copyFrom(d.getWindow().getAttributes());
                lp.width = width;
                lp.height = height;
                d.getWindow().setAttributes(lp);
            } catch (AndroidRuntimeException e) {
            } catch (Exception e) {
            }

            final Spinner rhesusspinner = (Spinner) d.findViewById(R.id.rhesus_spinner);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(FeedActivity.this,
                    android.R.layout.simple_spinner_dropdown_item) {

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {

                    View v = super.getView(position, convertView, parent);
                    if (position == getCount()) {
                        ((TextView) v.findViewById(android.R.id.text1)).setText("");
                        ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
                    }

                    return v;
                }

                @Override
                public int getCount() {
                    return super.getCount() - 1; // you dont display last item. It is used as hint.
                }

            };

            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            adapter.add("+");
            adapter.add("-");
            adapter.add("Rhesus");

            rhesusspinner.setAdapter(adapter);
            rhesusspinner.setSelection(adapter.getCount()); //display hint

            final Spinner bloodspinner = (Spinner) d.findViewById(R.id.bloodtype_spinner);
            ArrayAdapter<String> bloodadapter = new ArrayAdapter<String>(FeedActivity.this,
                    android.R.layout.simple_spinner_dropdown_item) {

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {

                    View v = super.getView(position, convertView, parent);
                    if (position == getCount()) {
                        ((TextView) v.findViewById(android.R.id.text1)).setText("");
                        ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
                    }

                    return v;
                }

                @Override
                public int getCount() {
                    return super.getCount() - 1; // you dont display last item. It is used as hint.
                }

            };

            bloodadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            bloodadapter.add("O");
            bloodadapter.add("A");
            bloodadapter.add("B");
            bloodadapter.add("AB");
            bloodadapter.add("Desired Type");

            bloodspinner.setAdapter(bloodadapter);
            bloodspinner.setSelection(bloodadapter.getCount()); //display hint

            //Buttons-Editexts
            Button btnpost = (Button) d.findViewById(R.id.post);
            final EditText userInput = (EditText) d.findViewById(R.id.editTextDialogUserInput);

            d.show();

            btnpost.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (bloodspinner.getSelectedItem().toString().equals("Desired Type")) {
                        Toast.makeText(getApplicationContext(), "Input Blood Type!", Toast.LENGTH_SHORT).show();
                    } else if (rhesusspinner.getSelectedItem().toString().equals("Rhesus")) {
                        Toast.makeText(getApplicationContext(), "Input Rhesus!", Toast.LENGTH_SHORT).show();
                    } else if (userInput.getText().toString().equals("")) {
                        Toast.makeText(getApplicationContext(), "Input your request message!",
                                Toast.LENGTH_SHORT).show();
                    } else {

                        int uid = session.currentUID();

                        String message = userInput.getText().toString();
                        String post_bloodtype = bloodspinner.getSelectedItem().toString();
                        String post_rhesus = rhesusspinner.getSelectedItem().toString();

                        NetAsync(d, view, uid, message, post_bloodtype, post_rhesus);

                    }
                }
            });

        }
    });

    //        // We first check for cached request
    //        Cache cache = FeedController.getInstance().getRequestQueue().getCache();
    //        Entry entry = cache.get(URL_FEED);
    //        if (entry != null) {
    //            // fetch the data from cache
    //            try {
    //                String data = new String(entry.data, "UTF-8");
    //                try {
    //                    parseJsonFeed(new JSONObject(data));
    //                } catch (JSONException e) {
    //                    e.printStackTrace();
    //                }
    //            } catch (UnsupportedEncodingException e) {
    //                e.printStackTrace();
    //            }
    //
    //        } else {
    // making fresh volley request and getting json

    /**
     * Showing Swipe Refresh animation on activity create
     * As animation won't start on onCreate, post runnable is used
     */
    swipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            swipeRefreshLayout.setRefreshing(true);
            getTimelineAsync();
        }
    });

}

From source file:com.freeme.filemanager.FileExplorerTabActivity.java

@Override
protected void onResume() {
    super.onResume();
    MobclickAgent.onResume(this);
    WindowManager wm = this.getWindowManager();
    int width = wm.getDefaultDisplay().getWidth();
    int height = wm.getDefaultDisplay().getHeight();
    Log.i("liuhaoran", "width = " + width + "height = " + height);
    Log.i("liuhaoran", "onResume");
    invalidateOptionsMenu();//from  www.j a  v  a 2  s  . c om
    isSearch = getIntent().getBooleanExtra("isSearch", false);
    if (getIntent() != null && isSearch) {
        isSearch = false;
        mViewPager.setCurrentItem(1);
        getIntent().putExtra("isSearch", false);
    }

    //*/ Added by Droi Kimi Wu on 20160413 [begin] for scanning garbage items size
    scanGarbageItems();
    //*/

}

From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java

private void enableParallaxEffect(ObservableScrollView scrollView, final View parallaxingView) {
    scrollView.setScrollViewListener(new ScrollViewListener() {
        @Override/*ww  w  . ja  v a  2  s .  co  m*/
        public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {

            WindowManager win = getWindowManager();
            Display d = win.getDefaultDisplay();
            int displayHeight = d.getHeight(); // Height of the actual device

            if (imageSize.getHeight() > displayHeight) {
                float[] values = new float[9];
                photoViewAttacher.getDrawMatrix().getValues(values);
                float imageHeight = imageSize.getHeight();

                float diff = imageHeight / displayHeight;

                if (y > oldy) {
                    diff = -diff;
                }

                photoViewAttacher.onDrag(0, diff);

            } else {
                float pY = -(y / 3.0f);
                parallaxingView.setTranslationY(pY);
            }

        }
    });
}

From source file:com.tealeaf.NativeShim.java

public DisplayMetrics getDisplayMetrics() {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:com.qingsongchou.library.widget.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*w ww. j  a v  a  2 s .c  om*/
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabNormalTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabNormalTextSize, dm);
    mTabSelectTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabSelectTextSize, dm);

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscDividerWidth,
            mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscScrollOffset,
            mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsQscTabBackground,
            mTabBackgroundResId);
    mTabNormalTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabNormalTextSize,
            mTabNormalTextSize);
    mTabSelectTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabSelectTextSize,
            mTabSelectTextSize);

    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsQscTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsQscTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsQscTabTextStyle,
            mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsQscTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsQscTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}