Hi,
I have a view which basically cover the full screen to capture key
input. It works well if I add it to activity, but if I display it from
background service using WindowManager.addView, it doesn't work.
Another quesiton is why onKeyDown/onKeyUp doesn't work? As you see I
have to use setOnKeyListener(mkeylistener);
====================
class myView extends TextView {
private Paint mLoadPaint;
private final String TAG="HUDView";
OnKeyListener mkeylistener= new OnKeyListener(){
public boolean onKey (View v, int keyCode, KeyEvent event){
Log.d("mkeylistener", "onKey:"+keyCode
+":Keyaction:"+event.getAction());
return true;
}
};
public myView(Context context) {
super(context);
//Toast.makeText(getContext(),"HUDView",
Toast.LENGTH_LONG).show();
mLoadPaint = new Paint();
mLoadPaint.setAntiAlias(true);
mLoadPaint.setTextSize(10);
mLoadPaint.setARGB(255, 255, 0, 0);
setOnKeyListener(mkeylistener);
setFocusable(true);
setFocusableInTouchMode(true);
this.setText("TEST");
this.setLayoutParams(new
LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
setOnFocusChangeListener(new View.OnFocusChangeListener(){
@Override
public void onFocusChange(View arg0, boolean
arg1) {
// TODO Auto-generated method stub
Log.d(TAG, arg0.toString()+":"+arg1);
}
});
}
@Override
public boolean onKeyUp (int keyCode, KeyEvent event){
Log.d(TAG, "onKeyUp:keyCode"+keyCode);
return true;
}
@Override
public boolean onKeyDown (int keyCode, KeyEvent event){
Log.d(TAG, "onKeyDown:keyCode"+keyCode);
return true;
}
@Override
protected void onAttachedToWindow (){
Log.d(TAG, "onAttachedToWindow");
requestFocus();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//canvas.drawText("Hello World", 5, 15, mLoadPaint);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int
arg3, int arg4) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//return super.onTouchEvent(event);
Toast.makeText(getContext(),"onTouchEvent",
Toast.LENGTH_LONG).show();
Log.d(TAG,String.format("top:%d,bottom:%d,left:%d,right:%d",
this.getTop(),
this.getBottom(),this.getLeft(),this.getRight()));
Log.d(TAG,"ontouch, is focused?"+this.isFocused());
testactivity.this.finish();
return true;
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en