Skip to content

Commit 340e8c9

Browse files
committed
see 08/18 log
1 parent 2679130 commit 340e8c9

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

utilcode/lib/src/main/java/com/blankj/utilcode/util/ScreenUtils.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ private ScreenUtils() {
4141
*/
4242
public static int getScreenWidth() {
4343
WindowManager wm = (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
44+
if (wm == null) return -1;
4445
Point point = new Point();
4546
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
46-
//noinspection ConstantConditions
4747
wm.getDefaultDisplay().getRealSize(point);
4848
} else {
49-
//noinspection ConstantConditions
5049
wm.getDefaultDisplay().getSize(point);
5150
}
5251
return point.x;
@@ -59,17 +58,42 @@ public static int getScreenWidth() {
5958
*/
6059
public static int getScreenHeight() {
6160
WindowManager wm = (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
61+
if (wm == null) return -1;
6262
Point point = new Point();
6363
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
64-
//noinspection ConstantConditions
6564
wm.getDefaultDisplay().getRealSize(point);
6665
} else {
67-
//noinspection ConstantConditions
6866
wm.getDefaultDisplay().getSize(point);
6967
}
7068
return point.y;
7169
}
7270

71+
/**
72+
* Return the application's width of screen, in pixel.
73+
*
74+
* @return the application's width of screen, in pixel
75+
*/
76+
public static int getAppScreenWidth() {
77+
WindowManager wm = (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
78+
if (wm == null) return -1;
79+
Point point = new Point();
80+
wm.getDefaultDisplay().getSize(point);
81+
return point.x;
82+
}
83+
84+
/**
85+
* Return the application's height of screen, in pixel.
86+
*
87+
* @return the application's height of screen, in pixel
88+
*/
89+
public static int getAppScreenHeight() {
90+
WindowManager wm = (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
91+
if (wm == null) return -1;
92+
Point point = new Point();
93+
wm.getDefaultDisplay().getSize(point);
94+
return point.y;
95+
}
96+
7397
/**
7498
* Return the density of screen.
7599
*

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/screen/ScreenActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class ScreenActivity : BaseTitleActivity() {
9595
SpanUtils.with(screenAboutTv)
9696
.appendLine("getScreenWidth: " + ScreenUtils.getScreenWidth())
9797
.appendLine("getScreenHeight: " + ScreenUtils.getScreenHeight())
98+
.appendLine("getAppScreenWidth: " + ScreenUtils.getAppScreenWidth())
99+
.appendLine("getAppScreenHeight: " + ScreenUtils.getAppScreenHeight())
98100
.appendLine("getScreenDensity: " + ScreenUtils.getScreenDensity())
99101
.appendLine("getScreenDensityDpi: " + ScreenUtils.getScreenDensityDpi())
100102
.appendLine("isFullScreen: " + ScreenUtils.isFullScreen(this))

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package com.blankj.utilcode.pkg.helper
22

33
import android.graphics.Bitmap
4+
import android.graphics.drawable.ColorDrawable
45
import android.support.v7.app.AlertDialog
56
import android.text.method.ScrollingMovementMethod
7+
import android.view.Gravity
68
import android.view.LayoutInflater
79
import android.view.View
10+
import android.view.Window
811
import android.widget.Button
912
import android.widget.EditText
1013
import android.widget.ImageView
1114
import android.widget.TextView
1215
import com.blankj.utilcode.pkg.R
13-
import com.blankj.utilcode.util.ActivityUtils
14-
import com.blankj.utilcode.util.KeyboardUtils
15-
import com.blankj.utilcode.util.PermissionUtils
16+
import com.blankj.utilcode.util.*
1617
import com.blankj.utilcode.util.PermissionUtils.OnRationaleListener.ShouldRequest
17-
import com.blankj.utilcode.util.ToastUtils
1818

1919
/**
2020
* ```
@@ -56,7 +56,9 @@ object DialogHelper {
5656
val topActivity = ActivityUtils.getTopActivity()
5757
if (!ActivityUtils.isActivityAlive(topActivity)) return
5858
val dialogView = LayoutInflater.from(topActivity).inflate(R.layout.dialog_keyboard, null)
59-
val dialog = AlertDialog.Builder(topActivity).setView(dialogView).create()
59+
val dialog = AlertDialog.Builder(topActivity)
60+
.setView(dialogView)
61+
.create()
6062
dialog.setCanceledOnTouchOutside(false)
6163
val keyboardDialogEt = dialogView.findViewById<EditText>(R.id.keyboardDialogEt)
6264
val listener = View.OnClickListener { v ->
@@ -74,15 +76,18 @@ object DialogHelper {
7476
dialogView.findViewById<View>(R.id.keyboardDialogShowSoftInputBtn).setOnClickListener(listener)
7577
dialogView.findViewById<View>(R.id.keyboardDialogToggleSoftInputBtn).setOnClickListener(listener)
7678
dialogView.findViewById<View>(R.id.keyboardDialogCloseBtn).setOnClickListener(listener)
77-
dialog.show()
7879

79-
// val attributes = dialog.window.attributes
80-
// attributes.y = SizeUtils.dp2px(300f)
81-
// attributes.height = ScreenUtils.getScreenHeight() / 2
82-
// dialog.window.attributes = attributes
83-
// dialog.window.decorView.setPadding(0, 0, 0, 0)
80+
val window = dialog.window
81+
window.requestFeature(Window.FEATURE_NO_TITLE)
82+
83+
dialog.show()
8484

85-
KeyboardUtils.fixAndroidBug5497(dialog.window)
85+
window.setBackgroundDrawable(ColorDrawable(0))
86+
val attributes = dialog.window.attributes
87+
attributes.gravity = Gravity.BOTTOM
88+
attributes.width = ScreenUtils.getAppScreenWidth()
89+
attributes.height = ScreenUtils.getAppScreenHeight() //* 2 / 5
90+
dialog.window.attributes = attributes
8691
}
8792

8893
fun showFragmentDialog(info: CharSequence) {

utilcode/pkg/src/main/res/layout/dialog_keyboard.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6+
android:background="@color/mediumGray"
67
android:fillViewport="true">
78

89
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

0 commit comments

Comments
 (0)