I have a rooted Android device and want to replace the softkeys with an own overlay. This works with the app "full!screen" but I want to do this in my own app. I searched and found some questions here but there were no answers to them.
I figured out how to do it with the shell but it is very slow, "full!screen" has a much better performance.
My service with the shell command looks like this:
public class MainService extends Service {
ButtonView mView;
@Override
public void onCreate() {
super.onCreate();
final Bitmap BckBtn = BitmapFactory.decodeResource(getResources(),
R.drawable.back);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
BckBtn.getWidth(),
BckBtn.getHeight(),
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mView = new ButtonView(this,BckBtn);
mView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg1.getX()<BckBtn.getWidth() & arg1.getY()>0)
{
Process process = null;
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
e.printStackTrace();
}
OutputStream outputStream = process.getOutputStream();
String cmd = "input keyevent 4";
try {
outputStream.write((cmd + "\n").getBytes("ASCII"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
});
wm.addView(mView, params);
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
@SuppressLint("DrawAllocation")
class ButtonView extends ViewGroup {
Bitmap BckBtn;
public ButtonView(Context context,Bitmap BckBtn) {
super(context);
this.BckBtn=BckBtn;
}
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(BckBtn,0 , 0, null);
}
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
}
public boolean onTouchEvent(MotionEvent event) {
return true;
}
}