| | |
| | | import android.provider.Settings; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.MotionEvent; |
| | | import android.view.View; |
| | | import android.view.WindowManager; |
| | | import android.view.inputmethod.InputMethodManager; |
| | | import android.widget.EditText; |
| | | import android.widget.Toast; |
| | | |
| | | import androidx.annotation.ColorRes; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.annotation.StringRes; |
| | | import androidx.appcompat.app.AppCompatActivity; |
| | | import androidx.core.content.FileProvider; |
| | | import androidx.viewbinding.ViewBinding; |
| | |
| | | } catch (Exception e) { |
| | | } |
| | | TAG = this.getClass().getSimpleName(); |
| | | initViews(); |
| | | } |
| | | |
| | | public abstract void initViews(); |
| | | |
| | | |
| | | public void setStatusBarTransparent(boolean isBlack){ |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean dispatchTouchEvent(MotionEvent ev) { |
| | | if (ev.getAction() == MotionEvent.ACTION_DOWN) { //把操作放在用户点击的时候 |
| | | View v = getCurrentFocus(); //得到当前页面的焦点,ps:有输入框的页面焦点一般会被输入框占据 |
| | | if (isShouldHideKeyboard(v, ev)) { //判断用户点击的是否是输入框以外的区域 |
| | | hideSoftKeyboard (); //收起键盘 |
| | | } |
| | | } |
| | | return super.dispatchTouchEvent(ev); |
| | | } |
| | | |
| | | /** |
| | | * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时则不能隐藏 |
| | | * |
| | | * @param v |
| | | * @param event |
| | | * @return |
| | | */ |
| | | private boolean isShouldHideKeyboard(View v, MotionEvent event) { |
| | | if (v != null && (v instanceof EditText)) { //判断得到的焦点控件是否包含EditText |
| | | int[] l = {0, 0}; |
| | | v.getLocationInWindow(l); |
| | | int left = l[0], //得到输入框在屏幕中上下左右的位置 |
| | | top = l[1], |
| | | bottom = top + v.getHeight(), |
| | | right = left + v.getWidth(); |
| | | if (event.getX() > left && event.getX() < right |
| | | && event.getY() > top && event.getY() < bottom) { |
| | | // 点击位置如果是EditText的区域,忽略它,不收起键盘。 |
| | | return false; |
| | | } else { |
| | | return true; |
| | | } |
| | | } |
| | | // 如果焦点不是EditText则忽略 |
| | | return false; |
| | | } |
| | | /** |
| | | * 判断软键盘输入法是否弹出 |
| | | */ |
| | | public boolean isKeyboardVisbility(Context context, View v) { |
| | | InputMethodManager imm = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE); |
| | | if (imm.hideSoftInputFromWindow(v.getWindowToken(), 0)) { |
| | | imm.showSoftInput(v, 0); |
| | | return true;//键盘显示中 |
| | | } else { |
| | | return false;//键盘未显示 |
| | | } |
| | | } |
| | | protected void hideSoftKeyboard() { |
| | | if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { |
| | | if (getCurrentFocus() != null) |
| | | ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), |
| | | InputMethodManager.HIDE_NOT_ALWAYS); |
| | | } |
| | | } |
| | | /** |
| | | * 状态栏高度 |
| | | * @return |
| | |
| | | //quitApp(); |
| | | } |
| | | } |
| | | public void showToast(String message){ |
| | | Toast.makeText(this,message,Toast.LENGTH_SHORT).show(); |
| | | } |
| | | |
| | | public void showToast(@StringRes int msg){ |
| | | showToast(getString(msg)); |
| | | } |
| | | ApkUpGradeResult.AppInfo apkUpGrade; |
| | | ProgressDialog progressDialog ; |
| | | |