fix:接口是字典报错
parent
9c8cfb1467
commit
01be82f0b1
@ -0,0 +1,41 @@
|
|||||||
|
package com.example.tyre;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
public class AllBaseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||||
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
View v = getCurrentFocus();
|
||||||
|
boolean isKeyboardShown = v != null && (v instanceof EditText) && isKeyboardShowing(getCurrentFocus(), this);
|
||||||
|
if (isKeyboardShown) {
|
||||||
|
Rect outRect = new Rect();
|
||||||
|
v.getGlobalVisibleRect(outRect);
|
||||||
|
if (!outRect.contains((int)ev.getRawX(), (int)ev.getRawY())) {
|
||||||
|
hideSoftKeyboard(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.dispatchTouchEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideSoftKeyboard(Activity activity) {
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isKeyboardShowing(View v, Context context) {
|
||||||
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
return imm.isAcceptingText();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.example.tyre.maintenance.receiver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wanghao
|
||||||
|
* @date 2024/7/9 17:24
|
||||||
|
*/
|
||||||
|
public interface MyKeyInfoCall {
|
||||||
|
void onkeyDown();
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.example.tyre.maintenance.receiver;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
public class MyKeyReceiver extends BroadcastReceiver {
|
||||||
|
private MyKeyInfoCall myKeyInfoCall;
|
||||||
|
|
||||||
|
public MyKeyReceiver() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyKeyReceiver(MyKeyInfoCall myKeyInfoCall) {
|
||||||
|
this.myKeyInfoCall = myKeyInfoCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Log.e("TAG", "onReceive:" + intent.getAction());
|
||||||
|
var keydown = intent.getBooleanExtra("keydown", false);
|
||||||
|
var keyCode = intent.getIntExtra("keyCode", 0);
|
||||||
|
Log.e("TAG", "onReceive:" + keydown + " --" + keyCode);
|
||||||
|
if (keydown && (keyCode == 135 || keyCode ==136)) {
|
||||||
|
myKeyInfoCall.onkeyDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Loading…
Reference in New Issue