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.pickr.tasks.PhotoLoader.java

@Override
protected Bitmap doInBackground() {
    try {/*from   w  ww  . ja v  a 2s  . c o m*/
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        int resolution = display.getWidth() * display.getHeight();

        Flickr flickr = FlickrHandler.getFlickr();
        List<PhotoSize> sizes = flickr.getPhotosService().getSizes(mPhoto);

        return loadBitmap(PhotoSizeWeight.getOptimalPhotoSize(sizes, resolution), display);

    } catch (Throwable ex) {
        ex.printStackTrace();
        LOGGER.e("Error loading photo", ex);
    }
    return null;
}

From source file:com.example.textviewsample.MainActivityFragment.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override/*from w w w .  j  a  va  2s  .c om*/
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    sourceCodeText = (TextView) view.findViewById(R.id.textView7);
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    display.getMetrics(metrics);

    int widthInPixels = metrics.widthPixels;
    int heightInPixels = metrics.heightPixels;

    float scaleFactor = metrics.density;

    float widthDp = widthInPixels / scaleFactor;
    float heightDp = heightInPixels / scaleFactor;

    TextView tv1 = (TextView) view.findViewById(R.id.textView1);
    tv1.setText(String.format(Locale.getDefault(),
            "Density: %s, sw%s, w%s\nDevice year: " + "%d\nCPU " + "Cores: %d, " + "MaxFreq: %d",
            getString(R.string.density), DisplayUtils.getSmallestWidth(getActivity()), widthDp,
            YearClass.get(getActivity()), DeviceInfo.getNumberOfCPUCores(), DeviceInfo.getCPUMaxFreqKHz()));

    ExpandableTextView etv = (ExpandableTextView) view.findViewById(R.id.textView6);
    etv.setContracted(true);

    new Shimmer().setDuration(1500).setStartDelay(4000).setRepeatDelay(5000)
            .start((ShimmerTextView) view.findViewById(R.id.textView12));
}

From source file:com.figo.campaignhelper.GenerateActivity.java

Bitmap encodeAsBitmap(String contents) throws WriterException {
    String contentsToEncode = contents;
    if (contentsToEncode == null) {
        return null;
    }//from www . j a va 2 s. co  m
    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contentsToEncode);
    if (encoding != null) {
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();

    WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int widthD = display.getWidth();
    int heightD = display.getHeight();
    int dimension = widthD < heightD ? widthD : heightD;
    dimension = dimension * 7 / 8;

    BitMatrix result = writer.encode(contentsToEncode, BarcodeFormat.QR_CODE, dimension, dimension, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

From source file:ly.count.android.api.DeviceInfoTests.java

public void testGetResolution_getDefaultDisplayReturnsNull() {
    final WindowManager mockWindowMgr = mock(WindowManager.class);
    when(mockWindowMgr.getDefaultDisplay()).thenReturn(null);
    final Context mockContext = mock(Context.class);
    when(mockContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mockWindowMgr);
    assertEquals("", DeviceInfo.getResolution(mockContext));
}

From source file:com.paperpad.mybox.GcmBroadcastReceiver.java

/**
* Sends the registration ID to your server over HTTP, so it can use GCM/HTTP
* or CCS to send messages to your app. Not needed for this demo since the
* device sends upstream messages to a server that echoes back the message
* using the 'from' address in the message.
 * @param regId //from   ww  w .j a  v a 2s.  co  m
*/
private void sendRegistrationIdToBackend(Context context, String regId) {
    int id_menu = 0;
    String application_unique_identifier = Installation.id(context);
    String application_version = "0.2.8";
    try {
        application_version = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {

        e.printStackTrace();
    }
    ;

    String device_type = "";
    boolean isTablet = context.getResources().getBoolean(R.bool.isTablet);
    if (isTablet) {
        device_type = "tablet";
    } else {
        device_type = "smartphone";
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

        display.getSize(size);
    } else {
        size.x = display.getWidth(); // deprecated
        size.y = display.getHeight();
    }

    String device_screen_resolution = size.x + "x" + size.y;

    //      ArrayList<AppHit> hits = new ArrayList<AppHit>();
    AppSession appSession = new AppSession(id_menu, "production", "MyBox", application_unique_identifier,
            application_version, regId, Build.MANUFACTURER, Build.MODEL, "android", device_screen_resolution, 5,
            Build.VERSION.SDK_INT + "", device_type, "", System.currentTimeMillis() / 1000,
            System.currentTimeMillis() / 1000, null);
    ArrayList<AppSession> appSessions = new ArrayList<AppSession>();
    appSessions.add(appSession);
    AppJsonWriter appJsonWriter = new AppJsonWriter();
    String str = appJsonWriter.writeJson(appSessions);
    String endpoint = SERVER_URL;
    String body = str;
    int status = 0;
    try {
        status = AppJsonWriter.post(endpoint, body);
    } catch (IOException e) {
        Log.e("GcmBroadcastReceiver", "request couldn't be sent " + status);
        e.printStackTrace();
    }
}

From source file:com.paperpad.MoulinsDuDuc.GcmBroadcastReceiver.java

/**
* Sends the registration ID to your server over HTTP, so it can use GCM/HTTP
* or CCS to send messages to your app. Not needed for this demo since the
* device sends upstream messages to a server that echoes back the message
* using the 'from' address in the message.
 * @param regId /*from   w  w w  . java 2 s. co m*/
*/
private void sendRegistrationIdToBackend(Context context, String regId) {
    int id_menu = 0;
    String application_unique_identifier = Installation.id(context);
    String application_version = "0.2.8";
    try {
        application_version = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {

        e.printStackTrace();
    }
    ;

    String device_type = "";
    boolean isTablet = context.getResources().getBoolean(R.bool.isTablet);
    if (isTablet) {
        device_type = "tablet";
    } else {
        device_type = "smartphone";
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

        display.getSize(size);
    } else {
        size.x = display.getWidth(); // deprecated
        size.y = display.getHeight();
    }

    String device_screen_resolution = size.x + "x" + size.y;

    //      ArrayList<AppHit> hits = new ArrayList<AppHit>();
    AppSession appSession = new AppSession(id_menu, "production", "MyBox", application_unique_identifier,
            application_version, regId, android.os.Build.MANUFACTURER, android.os.Build.MODEL, "android",
            device_screen_resolution, 5, android.os.Build.VERSION.SDK_INT + "", device_type, "",
            System.currentTimeMillis() / 1000, System.currentTimeMillis() / 1000, null);
    ArrayList<AppSession> appSessions = new ArrayList<AppSession>();
    appSessions.add(appSession);
    AppJsonWriter appJsonWriter = new AppJsonWriter();
    String str = appJsonWriter.writeJson(appSessions);
    String endpoint = SERVER_URL;
    String body = str;
    int status = 0;
    try {
        status = AppJsonWriter.post(endpoint, body);
    } catch (IOException e) {
        Log.e("GcmBroadcastReceiver", "request couldn't be sent " + status);
        e.printStackTrace();
    }
}

From source file:com.euphor.paperpad.GcmBroadcastReceiver.java

/**
* Sends the registration ID to your server over HTTP, so it can use GCM/HTTP
* or CCS to send messages to your app. Not needed for this demo since the
* device sends upstream messages to a server that echoes back the message
* using the 'from' address in the message.
 * @param regId /*from w  ww  .jav a  2s .  c om*/
*/
private void sendRegistrationIdToBackend(Context context, String regId) {
    int id_menu = MainActivity.params.getId();
    String application_unique_identifier = Installation.id(context);
    String application_version = "0.2.8";
    try {
        application_version = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {

        e.printStackTrace();
    }
    ;

    String device_type = "";
    if (MainActivity.isTablet) {
        device_type = "tablet";
    } else {
        device_type = "smartphone";
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

        display.getSize(size);
    } else {
        size.x = display.getWidth(); // deprecated
        size.y = display.getHeight();
    }

    String device_screen_resolution = size.x + "x" + size.y;

    ArrayList<AppHit> hits = new ArrayList<AppHit>();
    AppSession appSession = new AppSession(id_menu, MainActivity.prod_or_sand, "sales",
            application_unique_identifier, application_version, regId, Build.MANUFACTURER, Build.MODEL,
            "android", device_screen_resolution, 5, Build.VERSION.SDK_INT + "", device_type, "",
            System.currentTimeMillis() / 1000, System.currentTimeMillis() / 1000, hits);
    ArrayList<AppSession> appSessions = new ArrayList<AppSession>();
    appSessions.add(appSession);
    AppJsonWriter appJsonWriter = new AppJsonWriter();
    String str = appJsonWriter.writeJson(appSessions);
    String endpoint = SERVER_URL;
    String body = str;
    int status = 0;
    try {
        status = AppJsonWriter.post(endpoint, body);
    } catch (IOException e) {
        Log.e("GcmBroadcastReceiver", "request couldn't be sent " + status);
        e.printStackTrace();
    }
}

From source file:net.kevxu.muzei.interfacelift.InterfaceliftMacdropsClient.java

/**
 * Get suitable photo size based on the screen size of phone.
 *
 * @return Dimension Dimension of suitable photo size.
 *///from w  ww  .ja  v  a 2 s .com
protected Dimension getSuitablePhotoDimension() {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getRealSize(size);
    final int width = size.x;
    final int height = size.y;

    int screenLayout = mContext.getResources().getConfiguration().screenLayout;
    boolean isXlarge = ((screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
    boolean isLarge = ((screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    final boolean isTablet = isXlarge || isLarge;

    Dimension dimen;

    if (!isTablet) {
        // Wallpaper for phone needs at least [width x 2] x height
        dimen = new Dimension(width * 2, height);
    } else {
        // Wallpaper for tablet needs at least [long edge] x [long edge]
        int longEdge = width > height ? width : height;
        dimen = new Dimension(longEdge, longEdge);
    }

    return dimen;
}

From source file:com.drjane.promise.ui.fragment.CalendarFragment.java

private void initGridView() {
    // ??/*w  w w .j a  v a  2  s.c o  m*/
    WindowManager windowManager = getActivity().getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    int Width = display.getWidth();
    int Height = display.getHeight();

    mGridView = new CustomGridView(getActivity());
    mGridView.setNumColumns(7);
    mGridView.setColumnWidth(40);
    // gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    if (Width == 720 && Height == 1280) {
        mGridView.setColumnWidth(40);
    }
    mGridView.setGravity(Gravity.CENTER_VERTICAL);
    mGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
    // gridView
    mGridView.setVerticalSpacing(1);
    mGridView.setHorizontalSpacing(1);

    mHandler.post(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            mGridView.setAdapter(calendarGridViewAdapter);

        }
    });
}

From source file:com.example.androidmillgame.GamePanel.java

public GamePanel(Context context, long period) {
    super(context);
    this.period = period;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display wsize = wm.getDefaultDisplay();
    Point size = new Point();
    wsize.getSize(size);// w  w w  .  j a va2  s .  c o  m
    DisplayMetrics displayMetrics = new DisplayMetrics();
    wsize.getMetrics(displayMetrics);
    this.dpi = displayMetrics.densityDpi;
    this.PWIDTH = size.x;
    this.PHEIGHT = size.y;

    setFocusable(true);
    requestFocus();// ...............................................the.JPane.now.has.focus,.so.receives.key.events
    imgres = new Images(context);// ..............................................................preload.resources
    generatedJoints = new SmartJointFactory(context);
    DraggablePoint = new DragPlayer();
    backgroundRect = new Rect(PWIDTH / 2 - PHEIGHT / 2, 0, PWIDTH / 2 + PHEIGHT / 2, PHEIGHT);
    background = new Rect(0, 0, imgres.getImage("background").getWidth(),
            imgres.getImage("background").getHeight());
    scale = imgres.getImage("background").getHeight() / PHEIGHT;
    int resumescaled = imgres.getImage("resumenop").getWidth();
    resumeRect = new Rect(PWIDTH / 2 - resumescaled / 2, PHEIGHT / 2 - resumescaled / 2 + Pd2px.pd2px(50),
            PWIDTH / 2 + resumescaled / 2, PHEIGHT / 2 + resumescaled / 2 + Pd2px.pd2px(50));
    GC = new GameController(generatedJoints.Joints, DraggablePoint, context);
    Display = new HUD(PWIDTH / 2, PHEIGHT / 2, imgres.getImage("hud"));
    this.startGame();
}