package
org.androidtown.l;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.MotionEvent;
import
android.view.View;
import
android.view.View.OnTouchListener;
import
android.widget.EditText;
public
class
MainActivity
extends
Activity {
EditText editText1;
int
touchCount =
0
;
int
timeLimit =
30
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1 = (EditText) findViewById(R.id.editText1);
View view1 = (View) findViewById(R.id.view1);
view1.setOnTouchListener(
new
OnTouchListener() {
public
boolean
onTouch(View v, MotionEvent event){
if
(event.getAction() == MotionEvent.ACTION_DOWN){
incrTouchCount();
showTouchCount();
}
else
if
(event.getAction() != MotionEvent.ACTION_DOWN){
timeCheck();
}
return
true
;
}
});
}
private
void
incrTouchCount() {
touchCount = touchCount +
1
;
}
private
void
showTouchCount() {
editText1.setText(
"터치한 횟수 : "
+ touchCount);
}
private
void
timeCheck() {
long
time1 = System.currentTimeMillis ();
long
time2 = System.currentTimeMillis ();
long
time3 = ( time2 - time1 ) /
1000
;
long
endTime = timeLimit - time3;
if
(endTime <=
0
){
System.exit(
0
);
}
}
public
void
onButton1Clicked(View v) {
finish();
}
}