Java Code Examples for android.view.Display#getSize()

The following examples show how to use android.view.Display#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidDeviceDetailsInfo.java    From applivery-android-sdk with Apache License 2.0 6 votes vote down vote up
@Override public String getScreenResolution() {
  Context context = AppliverySdk.getApplicationContext();
  WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Display display = windowManager.getDefaultDisplay();

  int width;
  int height;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    Point size = new Point();
    display.getSize(size);
    width = size.x;
    height = size.y;
  } else {
    width = display.getWidth();
    height = display.getHeight();
  }

  String screenResolution = String.format(Locale.getDefault(), "%dx%d", width, height);

  return screenResolution;
}
 
Example 2
Source File: BIGChart.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    display.getSize(displaySize);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clock");

    specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
            View.MeasureSpec.EXACTLY);
    specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
            View.MeasureSpec.EXACTLY);
    sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    sharedPrefs.registerOnSharedPreferenceChangeListener(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutView = inflater.inflate(R.layout.activity_bigchart, null);
    performViewSetup();
}
 
Example 3
Source File: FloatingActionButton.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
protected void init(Context context, AttributeSet attributeSet) {
    mColorNormal = getColor(android.R.color.holo_blue_dark);
    mColorPressed = getColor(android.R.color.holo_blue_light);
    mIcon = 0;
    mSize = SIZE_NORMAL;
    if (attributeSet != null) {
        initAttributes(context, attributeSet);
    }

    mCircleSize = getCircleSize(mSize);
    mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
    mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
    mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);

    //point size overhead
    WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        mYHidden = size.y;
    } else mYHidden = display.getHeight();

    updateBackground();
}
 
Example 4
Source File: CircleWatchface.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CreateWakelock");
    wakeLock.acquire(30000);

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    display.getSize(displaySize);

    specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
            View.MeasureSpec.EXACTLY);
    specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
            View.MeasureSpec.EXACTLY);

    sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    sharedPrefs.registerOnSharedPreferenceChangeListener(this);

    //register Message Receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(Intent.ACTION_SEND));

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    myLayout = inflater.inflate(R.layout.modern_layout, null);
    prepareLayout();
    prepareDrawTime();

    //ListenerService.requestData(this); //usually connection is not set up yet

    wakeLock.release();
}
 
Example 5
Source File: SystemInfo.java    From kakao-android-sdk-standalone with Apache License 2.0 5 votes vote down vote up
@TargetApi(13)
private static Point getSize(Display display) {
    Point point = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(point);
    } else {
        point.set(display.getWidth(), display.getHeight());
    }
    return point;
}
 
Example 6
Source File: Helper.java    From AirPanel with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(Activity activity) {
    mRootView = activity.getWindow().getDecorView();
    // Get DisplayHeight
    WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    mDisplayHeight = size.y;
    Util.log("setup mDisplayHeight:%s point:%s", mDisplayHeight, size.toString());
}
 
Example 7
Source File: PongActivity.java    From Learning-Java-by-Building-Android-Games-Second-Edition with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    mPongGame = new PongGame(this, size.x, size.y);
    setContentView(mPongGame);
}
 
Example 8
Source File: MizLib.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
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);

    return type == HEIGHT ?
            size.y : size.x;
}
 
Example 9
Source File: ControllerView.java    From androidtv-VisualGameController with Apache License 2.0 5 votes vote down vote up
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = 0;
    int height = 0;

    Display display = mWindowManager.getDefaultDisplay();
    display.getSize(mSize);
    int displayWidth = mSize.x;
    int displayHeight = mSize.y;
    displayWidth = getWidth();
    displayHeight = getHeight();

    int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
    Log.d(TAG, "widthSpecSize=" + widthSpecSize + ", heightSpecSize=" + heightSpecSize);

    if (widthSpecMode == MeasureSpec.EXACTLY) {
        width = widthSpecSize;
    } else if (widthSpecMode == MeasureSpec.AT_MOST) {
        width = Math.min(displayWidth, widthSpecSize);
    } else {
        width = displayWidth;
    }

    if (heightSpecMode == MeasureSpec.EXACTLY) {
        height = heightSpecSize;
    } else if (heightSpecMode == MeasureSpec.AT_MOST) {
        height = Math.min(displayHeight, heightSpecSize);
    } else {
        height = displayHeight;
    }

    setMeasuredDimension(width, height);

    if (width > 0 && height > 0) {
        loadBitmaps(width, height);
    }
}
 
Example 10
Source File: Utils.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
public static Point getDisplayDimen(Context context) {
	Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
			.getDefaultDisplay();
	Point size = new Point();
	display.getSize(size);
	return size;
}
 
Example 11
Source File: ThemeAdapter.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
private void setDisplaySize() {
    final WindowManager wm
            = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    final Point p = new Point();
    display.getSize(p);
    final Float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            HEADER_LAYOUT_HEIGHT, getContext().getResources().getDisplayMetrics());
    height = (p.y - ht_px.intValue()) / Theme.values().length;
    width = p.x;
}
 
Example 12
Source File: MizLib.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
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);

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

    if (width >= 780)
        return "w780";
    if (width >= 400)
        return "w500";
    return "w300";
}
 
Example 13
Source File: Utils.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
/**
 * Returns the screen/display size
 *
 * @param context
 * @return
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    return new Point(width, height);
}
 
Example 14
Source File: VitamioMedia.java    From Vitamio-Cordova-Plugin with MIT License 5 votes vote down vote up
private void fixMediaSize() {
    if (mMediaPlayer == null || !mIsMediaReadyToBePlayed)
        return;
    int width = mMediaPlayer.getVideoWidth();
    int height = mMediaPlayer.getVideoHeight();
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int screenHeight = size.y;
    android.view.ViewGroup.LayoutParams videoParams = mMediaView.getLayoutParams();

    if (width > 0 && height > 0) {
        Log.i(TAG, "Video is: " + width + " x " + height);

        if (width > height) {
            videoParams.width = screenWidth;
            videoParams.height = screenWidth * height / width;
        } else {
            videoParams.width = screenHeight * width / height;
            videoParams.height = screenHeight;
        }
    } else {
        videoParams.width = 0;
        videoParams.height = 0;
    }

    Log.i(TAG, "Setting dimensions to: " + videoParams.width + " x " + videoParams.height);
    mMediaView.setLayoutParams(videoParams);
}
 
Example 15
Source File: ImageUtils.java    From LikeYahooWeather with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the screen width.
 * 
 * @param context
 * @return the screen width
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getScreenWidth(Activity context) {

	Display display = context.getWindowManager().getDefaultDisplay();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
		Point size = new Point();
		display.getSize(size);
		return size.x;
	}
	return display.getWidth();
}
 
Example 16
Source File: Utils.java    From CumulusTV with MIT License 5 votes vote down vote up
/**
 * Returns the screen/display size
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size;
}
 
Example 17
Source File: ChatActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setHasOptionsMenu(true);
    Display display = parentActivity.getWindowManager().getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT < 13) {
        displaySize.set(display.getWidth(), display.getHeight());
    } else {
        display.getSize(displaySize);
    }


}
 
Example 18
Source File: BannerAdView.java    From mobile-sdk-android with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
protected void expandToFitScreenWidth(int adWidth, int adHeight,  View view) {
    //Determine the width of the screen
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    @SuppressWarnings("UnusedAssignment") int width = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point p = new Point();
        display.getSize(p);
        width = p.x;
    } else {
        width = display.getWidth();
    }

    float ratio_delta = ((float) width) / ((float) adWidth);
    int new_height = (int) Math.floor(adHeight * ratio_delta);
    if(getLayoutParams() != null) {
        oldH = getLayoutParams().height;
        oldW = getLayoutParams().width;

        //Adjust width of container
        if (getLayoutParams().width > 0 || getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT) {
            getLayoutParams().width = width;
        }

        //Adjust height of container
        getLayoutParams().height = new_height;
    }

    if(view instanceof WebView) {

        //Adjust height of webview
        if (view.getLayoutParams() == null) {
            view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        } else {
            view.getLayoutParams().width = FrameLayout.LayoutParams.MATCH_PARENT;
            view.getLayoutParams().height = FrameLayout.LayoutParams.MATCH_PARENT;
        }
        ((WebView)view).setInitialScale((int) Math.ceil(ratio_delta * 100));
    }else{
        int adWidthInPixel = ViewUtil.getValueInPixel(getContext(), adWidth);
        float widthRatio = (float) width / (float) adWidthInPixel;
        view.setScaleX(widthRatio);
        view.setScaleY(widthRatio);
    }
    view.invalidate();
    shouldResetContainer = true;

}
 
Example 19
Source File: LoginActivity.java    From android-login with MIT License 4 votes vote down vote up
private int[] screenSize() {
  Display display = getWindowManager().getDefaultDisplay();
  Point size = new Point();
  display.getSize(size);
  return new int[]{size.x, size.y};
}
 
Example 20
Source File: eReceipt.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.e_receipt);
        ButterKnife.bind(this);

        // Instantiating the database
        database = new SCWallDatabase(this);

        // Retrieving the currently active account from the legacy tinyDB implementation
        tinyDB = new TinyDB(this);
        ArrayList<AccountDetails> accountDetails = tinyDB.getListObject(getString(R.string.pref_wallet_accounts), AccountDetails.class);
        for (AccountDetails accountDetail : accountDetails) {
            if (accountDetail.isSelected) {
                user = database.fillUserDetails(new UserAccount(accountDetail.account_id));
            }
        }

        // Deserializing the HistoricalTransferEntry object, which contains all
        // detailed information about this transfer.
        Gson gson = new Gson();
        String jsonOperation = getIntent().getExtras().getString(TableViewClickListener.KEY_OPERATION_ENTRY);
        historicalTransferEntry = gson.fromJson(jsonOperation, HistoricalTransferEntry.class);

        // Setting the memo message
        TransferOperation transfer = historicalTransferEntry.getHistoricalTransfer().getOperation();
        memo.setText(String.format(memo.getText().toString(), transfer.getMemo().getPlaintextMessage()));

        transactionId = historicalTransferEntry.getHistoricalTransfer().getId();

        progressDialog = new ProgressDialog(this);
        Application.registerBalancesDelegateEReceipt(this);
        setTitle(getResources().getString(R.string.e_receipt_activity_name));
        hideProgressBar();
        Intent intent = getIntent();
        String eReciept = intent.getStringExtra(getResources().getString(R.string.e_receipt));

        memoMsg = intent.getStringExtra("Memo");
        date = intent.getStringExtra("Date");
        time = intent.getStringExtra("Time");
        timeZone = intent.getStringExtra("TimeZone");

        UserAccount fromUser = historicalTransferEntry.getHistoricalTransfer().getOperation().getFrom();
        UserAccount toUser = historicalTransferEntry.getHistoricalTransfer().getOperation().getTo();
        if (fromUser.getObjectId().equals(user.getObjectId())) {
            ivImageTag.setImageResource(R.drawable.send);
            tvUserStatus.setText(getString(R.string.sender_account));
            tvOtherStatus.setText(getString(R.string.receiver_account));
            otherName = toUser.getName();
            userName = fromUser.getName();
        } else {
            tvUserStatus.setText(getString(R.string.receiver_account));
            tvOtherStatus.setText(getString(R.string.sender_account));
            ivImageTag.setImageResource(R.drawable.receive);
            otherName = fromUser.getName();
            userName = toUser.getName();
        }

        tvOtherName.setText(otherName);
        tvUserName.setText(userName);
//        TvBlockNum.setText(date);
        tvTime.setText(time + " " + timeZone);

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;

        ivOtherGravatar.requestLayout();

        ivOtherGravatar.getLayoutParams().height = (width * 40) / 100;
        ivOtherGravatar.getLayoutParams().width = (width * 40) / 100;


        fetchGravatarInfo(get_email(otherName));

        setBackButton(true);

        HistoricalTransfer historicalTransfer = historicalTransferEntry.getHistoricalTransfer();
        tvBlockNumber.setText(String.format("%d", historicalTransfer.getBlockNum()));
        tvTrxInBlock.setText(String.format("%s", historicalTransfer.getId()));

        double amount = Util.fromBase(historicalTransfer.getOperation().getAssetAmount());
        String symbol = historicalTransfer.getOperation().getAssetAmount().getAsset().getSymbol();
        int precision = historicalTransfer.getOperation().getAssetAmount().getAsset().getPrecision();
        String textFormat = String.format("%%.%df %%s", precision);
        tvPaymentAmount.setText(String.format(textFormat, amount, symbol));

        if (historicalTransferEntry.getEquivalentValue() != null) {
            double eqValueAmount = Util.fromBase(historicalTransferEntry.getEquivalentValue());
            String eqValueSymbol = historicalTransferEntry.getEquivalentValue().getAsset().getSymbol();
            tvPaymentEquivalent.setText(String.format("%.2f %s", eqValueAmount, eqValueSymbol));
        }
    }