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:flex.android.magiccube.activity.ActivityBattleMode.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mode_battle);
    btMoveBack = (ImageButton) findViewById(R.id.bt_battle_moveback);
    btMoveForward = (ImageButton) findViewById(R.id.bt_battle_moveforward);
    btStartOb = (ImageButton) findViewById(R.id.bt_battle_startob);

    clock = (ImageView) findViewById(R.id.img_battle_clock);
    txtTime = (TextView) findViewById(R.id.txt_battle_time);
    txtNStep = (TextView) findViewById(R.id.txt_battle_nStep);
    img_nstep = (ImageView) findViewById(R.id.img_battle_nstep);
    progress = (SeekBar) findViewById(R.id.sbar_battle_timer);

    /*/*w w w .  j  a va2s .c o m*/
     * clock.setVisibility(View.VISIBLE);
     * btMoveForward.setVisibility(View.VISIBLE);
     * btMoveBack.setVisibility(View.VISIBLE);
     */

    glView = (ViewBattleMode) findViewById(R.id.game_view_battle);
    glView.SetOnTimerListener(this);
    // glView.setOnStateListener(this);
    glView.SetOnStepListener(this);
    glView.SetMessageSender(this);
    glView.SetDrawCube(false);
    glView.setOnStateListener(this);

    glView2 = (ViewBattleMode) findViewById(R.id.game_view_battle2);
    glView2.SetCanMove(false);

    btMoveBack.setOnClickListener(buttonListener);
    btMoveForward.setOnClickListener(buttonListener);
    btStartOb.setOnClickListener(buttonListener);

    float fontsize = 25.f;
    Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Angies New House.ttf");
    txtTime.setTypeface(typeFace);
    txtTime.setTextColor(Color.GRAY);
    txtTime.setTextSize(fontsize);

    txtNStep.setTypeface(typeFace);
    txtNStep.setTextColor(Color.GRAY);
    txtNStep.setTextSize(fontsize);

    State = OnStateListener.NONE;

    BgVolume = MagiccubePreference.GetPreference(MagiccubePreference.BgVolume, this);
    LinearBgVolume = MusicPlayThread.GetLinearVolume(BgVolume);

    GamingbgmPlayer = MediaPlayer.create(this, R.raw.bg2);
    ObservingbgmPlayer = MediaPlayer.create(this, R.raw.bg);
    FinishbgmPlayer = MediaPlayer.create(this, R.raw.finish);

    GamingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume);
    ObservingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume);
    FinishbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume);

    Init();

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "...", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    width = wm.getDefaultDisplay().getWidth();
    height = wm.getDefaultDisplay().getHeight();

    layout_moveforward = (LinearLayout) findViewById(R.id.layout_battle_moveforward);
    layout_moveback = (LinearLayout) findViewById(R.id.layout_battle_moveback);

    int buttonwidth = width / 5;
    int buttonheight = height / 13;

    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(buttonwidth, buttonheight);

    btMoveForward.setLayoutParams(parms);
    btMoveBack.setLayoutParams(parms);

    layout_moveforward.setPadding(width / 2 - buttonwidth / 2, height - buttonheight, 0, 0);
    layout_moveback.setPadding(width / 15, height - buttonheight, 0, 0);

}

From source file:com.miz.functions.MizLib.java

public static int getDisplaySize(Context c, int type) {
    WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    display.getSize(size);/*from   ww w. j  a  v  a  2 s .  c  o  m*/

    return type == HEIGHT ? size.y : size.x;
}

From source file:com.miz.functions.MizLib.java

public static String getBackdropUrlSize(Context c) {
    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);/*from w ww. j  av  a2s .  c  o  m*/

    final int width = Math.max(size.x, size.y);

    if (width > 1280 && isTablet(c)) // We only want to download full size images on tablets, as these are the only devices where you can see the difference
        return "original";
    else if (width > 780)
        return "w1280";
    return "w780";
}

From source file:com.miz.functions.MizLib.java

public static String getBackdropThumbUrlSize(Context c) {
    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);//from w  w  w .j a  v  a2  s. co  m

    final int width = Math.min(size.x, size.y);

    if (width >= 780)
        return "w780";
    if (width >= 400)
        return "w500";
    return "w300";
}

From source file:com.miz.functions.MizLib.java

public static String getImageUrlSize(Context c) {
    final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);

    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);/*w ww .j a  v  a  2  s.c om*/

    final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing));

    if (numColumns > 0) {
        final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing;

        if (columnWidth > 300)
            return "w500";
        else if (columnWidth > 185)
            return "w300";
    }

    return "w185";
}

From source file:com.miz.functions.MizLib.java

public static String getActorUrlSize(Context c) {
    final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);

    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);//from   w ww.  ja v a2s  . com

    final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing));

    if (numColumns > 0) {
        final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing;

        if (columnWidth > 400)
            return "h632";

        if (columnWidth >= 300)
            return "w300";
    }

    return "w185";
}

From source file:com.miz.functions.MizLib.java

public static int getThumbnailSize(Context c) {
    final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);

    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);//from www .j a v a  2  s. co m

    final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing));

    if (numColumns > 0) {
        final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing;

        if (columnWidth > 320)
            return 440;
        else if (columnWidth > 240)
            return 320;
        else if (columnWidth > 180)
            return 240;
    }

    return 180;
}

From source file:org.cryptsecure.Utility.java

/**
 * Get the screen width.//from  ww w .  ja v  a  2 s .  c  o m
 * 
 * @param context
 *            the context
 * @return the screen width
 */
@SuppressWarnings("deprecation")
public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    return display.getWidth(); // API LEVEL 11
    // API LEVEL 13
    // Point size = new Point();
    // display.getSize(size);
    // int width = size.x;
    // int height = size.y;
    // return width;
}

From source file:org.cryptsecure.Utility.java

/**
 * Get the screen height./*from  w  w  w  .j  ava2 s.c o  m*/
 * 
 * @param context
 *            the context
 * @return the screen height
 */
@SuppressWarnings("deprecation")
public static int getScreenHeight(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    return display.getHeight();
    // API LEVEL 11
    // API LEVEL 13
    // Point size = new Point();
    // display.getSize(size);
    // int width = size.x;
    // int height = size.y;
    // return height;
}

From source file:com.miz.functions.MizLib.java

public static void resizeBitmapFileToCoverSize(Context c, String filepath) {

    final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);

    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);//  w  w w. ja va2s.  c om

    final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing));

    if (numColumns > 0) {
        final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing;

        int imageWidth = 0;

        if (columnWidth > 300)
            imageWidth = 500;
        else if (columnWidth > 240)
            imageWidth = 320;
        else if (columnWidth > 180)
            imageWidth = 240;
        else
            imageWidth = 180;

        if (new File(filepath).exists())
            try {
                Bitmap bm = decodeSampledBitmapFromFile(filepath, imageWidth, (int) (imageWidth * 1.5));
                bm = Bitmap.createScaledBitmap(bm, imageWidth, (int) (imageWidth * 1.5), true);
                FileOutputStream out = new FileOutputStream(filepath);
                bm.compress(Bitmap.CompressFormat.JPEG, 90, out);
                out.close();
                bm.recycle();
            } catch (Exception e) {
            }
    }
}