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.dragon.lib.IndicatorView.java

public int getScreenHeight() {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay().getHeight();
}

From source file:com.dragon.lib.IndicatorView.java

public int getScreenWidth() {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay().getWidth();
}

From source file:com.viewpagerindicator.NewTabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId, int backGroundId, int textSize,
        int textColor) {
    final TabView tabView = new TabView(getContext(), index);
    tabView.mIndex = index;//from w  ww .j  a v a2 s.  c o  m
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);// ?
    int width = dm.widthPixels;
    // tabView.setPadding(
    // (int) dp2Pixel((int) width > 1000 ? 11 : ((width > 600 ? 10
    // : (width > 479 ? 8 : (width > 319 ? 7 : 6)))), context),
    // 0, 0, 0);
    if (textSize != 0) {
        tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    } else {
        tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    }
    ColorStateList csl;
    if (textColor != 0) {
        csl = (ColorStateList) context.getResources().getColorStateList(textColor);
    } else {

        csl = (ColorStateList) context.getResources().getColorStateList(R.color.perm_title_color);
    }
    if (csl != null) {
        tabView.setTextColor(csl);
    }
    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
        // tabView.setBackgroundResource(iconResId);
    }
    if (backGroundId != 0) {
        // tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0,
        // 0);
        tabView.setBackgroundResource(backGroundId);
    }
    mTabLayout.addView(tabView, new LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java

Bitmap loadBitmapBlocking(String woeid, boolean isDay, int conditionCode) {
    File[] files = mWeatherUtils.getCityPhotos(WeatherActivity.this, woeid);
    Bitmap bitmap;//from w ww. j  a v a2s . c  o  m

    if (files != null) {
        int N = files.length;
        Random random = new Random();
        int idx = random.nextInt(N);
        File file = files[idx];
        WindowManager windowManager = mWindowManager;
        Display defaultDisplay = windowManager.getDefaultDisplay();
        int dimen = Math.max(defaultDisplay.getWidth(), defaultDisplay.getHeight());
        bitmap = mBitmapUtils.decodeSampledBitmapFromFile(file, dimen, dimen);
        return bitmap;
    }

    int resId = ImageDownloadHelper.getFallbackDrawableForConditionCode(isDay, conditionCode);
    return BitmapFactory.decodeResource(getResources(), resId);
}

From source file:com.viewpagerindicator.NewTabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId, int backGroundId, int textSize, int textColor,
        boolean isNew) {

    final TabView tabView = new TabView(getContext(), index);
    tabView.mIndex = index;//from w  w w .j a v  a2  s.com
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);// ?
    int width = dm.widthPixels;
    // tabView.setPadding(
    // (int) dp2Pixel(paddingLeft == 0 ? (int) width > 1000 ? 17
    // : ((width > 600 ? 16 : (width > 479 ? 13
    // : (width > 319 ? 12 : 11)))) : paddingLeft,
    // context), 0,
    // paddingRight == 0 ? (int) dp2Pixel(2, context) : paddingRight,
    // 0);
    if (textSize != 0) {
        tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    } else {
        tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    }
    ColorStateList csl;
    if (textColor != 0) {
        csl = (ColorStateList) context.getResources().getColorStateList(textColor);
    } else {

        csl = (ColorStateList) context.getResources().getColorStateList(R.color.perm_title_color);
    }
    if (csl != null) {
        tabView.setTextColor(csl);
    }
    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0,
                isNew ? R.drawable.friend_play_new_point : 0, 0);
        // tabView.setBackgroundResource(iconResId);
    }
    if (backGroundId != 0) {
        // tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0,
        // 0);
        tabView.setBackgroundResource(backGroundId);
    }
    LayoutParams lp = new LayoutParams(0, MATCH_PARENT, 1);
    // if(index==0)
    // {
    // lp.gravity=Gravity.RIGHT;
    // lp.rightMargin=PixelUtil.dp2Pixel(20, context);
    // }
    // else
    // {
    // lp.gravity=Gravity.LEFT;
    // lp.leftMargin=PixelUtil.dp2Pixel(20, context);
    // }
    mTabLayout.addView(tabView, lp);
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    com.ranorex.android.RanorexAndroidAutomation.Hook(this);
    // Get text views
    textoSsid = (TextView) findViewById(R.id.ssid);
    textoPassword = (TextView) findViewById(R.id.password);
    descripcion = (TextView) findViewById(R.id.descripcion);
    icon = (ImageView) findViewById(R.id.icon);
    //textoCifrado = (TextView) findViewById(R.id.cifrado);

    settings = getSharedPreferences(MainActivity.PREFS, 0);

    // if(settings.contains("connected_wifi_5ghz") && settings.getBoolean("connected_wifi_5ghz", false))
    //      descripcion.setText("");

    final ProgressDialog dialog = new ProgressDialog(EncoderActivity.this);

    dialog.setMessage("Generando Qr...");
    dialog.show();//from  w  w  w .j  ava 2  s  .c  om
    dialog.setCancelable(false);

    try {

        if (settings.contains("ssid") && settings.contains("password1")) {
            // Get ssid, psk and encrypted of settings.

            if (!getIntent().getBooleanExtra("is_5ghz", false)) // Network 2.4 GHz.
            {
                cifradoSettings = settings.getString("cifrado", "WPA");
                ssidSettings = settings.getString("ssid", "");
                pskSettings = settings.getString("password1", "");
                if (settings.contains("connected_wifi_5ghz")
                        && !settings.getBoolean("connected_wifi_5ghz", false)
                        || !settings.contains("connected_wifi_5ghz")) {
                    descripcion.setVisibility(View.VISIBLE);
                }
            } else // Network 5 GHz.
            {
                cifradoSettings = settings.getString("cifrado5ghz", "WPA");
                ssidSettings = settings.getString("ssid5ghz", "");
                pskSettings = settings.getString("password5ghz", "");
                icon.setImageResource(R.drawable.wifiplus120);
                ((TextView) findViewById(R.id.textView1)).setText("WifiPlus");
                if (settings.contains("connected_wifi_5ghz")
                        && settings.getBoolean("connected_wifi_5ghz", false)) {
                    descripcion.setVisibility(View.VISIBLE);
                }
            }

            ssidFull = ssidSettings;
            pskFull = pskSettings;

            if (cifradoSettings.contains("WPA")) {
                cifradoQR = "WPA";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;";
            } else if (cifradoSettings.contains("abierta")) {
                cifradoQR = "nopass";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";;";
            } else if (cifradoSettings.contains("WEP")) {
                cifradoQR = "WEP";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;";
            }

            // Update texts
            textoSsid.setText(ssidSettings);

            try {
                if (pskSettings.length() > 39)
                    pskSettings = ellipsis(pskSettings, 39);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (pskSettings.equalsIgnoreCase("sin password") || pskSettings.equalsIgnoreCase(""))
                pskSettings = "Sin password";

            textoPassword.setText(pskSettings);

        }

    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not encode barcode", e);
    }

    new AsyncTask<String, Integer, Bitmap>() {

        @Override
        protected Bitmap doInBackground(String... params) {
            QRCodeEncoder qrCodeEncoder = null;
            // This assumes the view is full screen, which is a good assumption
            WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
            Display display = manager.getDefaultDisplay();
            int width = display.getWidth();
            int height = display.getHeight();
            int smallerDimension = width < height ? width : height;
            smallerDimension = smallerDimension * 7 / 8;

            try {
                qrCodeEncoder = new QRCodeEncoder(string, null, Contents.Type.TEXT,
                        BarcodeFormat.QR_CODE.toString(), smallerDimension);
                Hashtable hints = new Hashtable();
                hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
                QRCodeWriter qrcw = new QRCodeWriter();
                BitMatrix matrix = qrcw.encode(string, BarcodeFormat.QR_CODE, width, height, hints);
                bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                for (int y = 0; y < matrix.getHeight(); y++) {
                    for (int x = 0; x < matrix.getWidth(); x++) {
                        if (!matrix.get(x, y))
                            bm.setPixel(x, y, Color.WHITE);
                        else
                            bm.setPixel(x, y, Color.BLACK);
                    }
                }
            } catch (WriterException we) {
                we.printStackTrace();
                Log.e(TAG, "Could not encode barcode", we);
            }

            return bm;
        }

        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap != null) {
                viewCode = (ImageView) findViewById(R.id.image_view);
                viewCode.setImageBitmap(bitmap);//bitmap);
                dialog.dismiss();
            } else {
                Toast.makeText(EncoderActivity.this, "Problema al generar Qr", Toast.LENGTH_LONG).show();
            }
        }
    }.execute();

    if (bm != null) {
        dialog.dismiss();
    }

}

From source file:com.mediatek.galleryfeature.stereo.fancycolor.FancyColorActivity.java

private void initViewSize() {
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    mViewWidth = metrics.widthPixels;/*from  ww w  .jav a2s . c  om*/
    mViewHeight = metrics.heightPixels;
    FancyColorHelper.setViewSize(mViewWidth, mViewHeight);
}

From source file:com.example.appdetail_optimization.PagerSlidingTabStrip.java

@SuppressWarnings("deprecation")
private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//w  ww  .j av  a  2  s.  c  o m
    tab.setGravity(Gravity.CENTER);
    tab.setPadding(0, 0, 0, 0);

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int width = wm.getDefaultDisplay().getWidth();
    tab.setMaxWidth(width / tabCount - tabPadding * 2);
    tab.setEllipsize(TruncateAt.END);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:com.magic.cube.views.PagerSlidingTabStrip.java

public int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

From source file:com.playhaven.android.req.PlayHavenRequest.java

@SuppressWarnings("deprecation")
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    try {/*from  w w  w.  j  a v  a2  s .co m*/
        SharedPreferences pref = PlayHaven.getPreferences(context);

        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer));
        builder.path(context.getResources().getString(getApiPath(context)));
        builder.queryParam("app", getString(pref, AppPkg));
        builder.queryParam("opt_out", getString(pref, OptOut, "0"));
        builder.queryParam("app_version", getString(pref, AppVersion));
        builder.queryParam("os", getInt(pref, OSVersion, 0));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        builder.queryParam("orientation", display.getRotation());
        builder.queryParam("hardware", getString(pref, DeviceModel));
        PlayHaven.ConnectionType connectionType = getConnectionType(context);
        builder.queryParam("connection", connectionType.ordinal());
        builder.queryParam("idiom",
                context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

        /**
         * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically
         * account for rotation and screen decorations like the status bar. We only want to know available space.
         *
         * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth!
         */
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
        builder.queryParam("width", size.x);
        builder.queryParam("height", size.y);

        /**
         * SDK Version needs to be reported as a dotted numeric value
         * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build
         * IE: 2.0.0.20130201
         * as opposed to an actual released build, which would be like 2.0.0
         */
        String sdkVersion = getString(pref, SDKVersion);
        String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]");
        sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", ""));
        builder.queryParam("sdk_version", sdkVersion);

        builder.queryParam("plugin", getString(pref, PluginIdentifer));

        Locale locale = context.getResources().getConfiguration().locale;
        builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage()));
        builder.queryParam("token", getString(pref, Token));

        builder.queryParam("device", getString(pref, DeviceId));
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        builder.queryParam("dpi", metrics.densityDpi);

        String uuid = UUID.randomUUID().toString();
        String nonce = base64Digest(uuid);
        builder.queryParam("nonce", nonce);

        ktsid = KontagentUtil.getSenderId(context);
        if (ktsid != null)
            builder.queryParam("sid", ktsid);

        addSignature(builder, pref, nonce);

        // Setup for signature verification
        String secret = getString(pref, Secret);
        SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC);
        sigMac = Mac.getInstance(HMAC);
        sigMac.init(key);
        sigMac.update(nonce.getBytes(UTF8));

        return builder;
    } catch (Exception e) {
        throw new PlayHavenException(e);
    }
}