package com.terry.lock;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.Toast;
public class main extends Activity {
/** Called when the activity is first created. */
ImageView view;
boolean flag=false;
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
//int x= (int)event.getX()-10;
int[] location = new int[2];
view.getLocationInWindow(location);
int y=(int)event.getY()-80;
LayoutParams Params=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT
,location[0], y);
if(flag){
view.setLayoutParams(Params);
if(event.getAction()==MotionEvent.ACTION_UP){
Toast.makeText(main.this,"解锁",2000).show();
flag=false;
finish();
}
}
return super.onTouchEvent(event);
}
@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
//android底层系统把HOME键屏蔽了,但如果发现它是TYPE_KEYGUARD类的窗体,则不会过滤。所以把Activity修改成TYPE_KEYGUARD
//类就好了
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch(keyCode) {
case KeyEvent.KEYCODE_HOME:
Log.e("God", "丫的,看你住哪里跑!");
break;
case KeyEvent.KEYCODE_POWER:
Log.e("God", "电源键按下");
}
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view=(ImageView)findViewById(R.id.image);
Intent i = new Intent(main.this,OtherService.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startService(i);
main.this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
Intent intent=new Intent(main.this,LockService.class);
startService(intent);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
flag=true;
return false;
}
});
}
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页