Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android ACTION UP没有';即使返回真值,也不能工作_Java_Android_Ontouchlistener - Fatal编程技术网

Java Android ACTION UP没有';即使返回真值,也不能工作

Java Android ACTION UP没有';即使返回真值,也不能工作,java,android,ontouchlistener,Java,Android,Ontouchlistener,我试图在onTouch方法中使用MotionEvent,但。。。它永远不起作用 我还在谷歌上搜索,发现在onTouch方法中,它需要返回true 我做了,但仍然不工作 有什么想法吗 imageViewCancel.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) {

我试图在onTouch方法中使用MotionEvent,但。。。它永远不起作用

我还在谷歌上搜索,发现在onTouch方法中,它需要返回true

我做了,但仍然不工作

有什么想法吗

        imageViewCancel.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            Log.d(TAG, "ACTION : " +  event.getAction());
            switch(event.getAction()){
                case MotionEvent.ACTION_UP:
                    Log.d(TAG, "ACTION UP");
                    view.setVisibility(View.VISIBLE);
                    break;
                case MotionEvent.ACTION_DOWN:
                    Log.d(TAG, "ACTION DOWN");
                    ClipData data = ClipData.newPlainText("", "");
                    View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                            view);
                    view.startDrag(data, shadowBuilder, view, 0);
                    view.setVisibility(View.INVISIBLE);
                    break;

                default:
                    break;
            }
            return true;
        }
    });
这是我的xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#85d2ce">

<LinearLayout
    android:layout_width="145dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="100dp"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:id="@+id/linearLayout">
    <ImageView
        android:id="@+id/imageViewWakeUp"
        android:layout_width="140.5dp"
        android:layout_height="121.5dp"
        android:src="@drawable/messages"
        android:layout_gravity="center_horizontal"/>

    <ImageView
        android:id="@+id/imageViewAlarmClock"
        android:layout_width="157.5dp"
        android:layout_height="153.5dp"
        android:src="@drawable/ic_alarm"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="15dp"
        />

    <TextView
        android:id="@+id/textViewAmPm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:textColor="#fff"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp"
        fontPath="fonts/Roboto-Bold.ttf"
        />

    <TextView
        android:id="@+id/textViewRingingTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="44dp"
        android:textColor="#fff"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        android:textStyle="bold"
        fontPath="fonts/Roboto-Bold.ttf"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout_cancelWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_horizontal"
    android:weightSum="1"
    android:layout_below="@+id/linearLayout"
    android:layout_alignParentStart="true">

    <LinearLayout
        android:id="@+id/linearLayoutLeftArrowWrapper"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_weight="0.21">

        <ImageView
            android:id="@+id/imageViewLeftArrow"
            android:layout_width="47dp"
            android:layout_height="24.5dp"
            android:layout_gravity="center_vertical"
            android:src="@drawable/arrow_left"
            />
    </LinearLayout>

    <ImageView
        android:id="@+id/imageViewSnooze"
        android:layout_width="0dp"
        android:layout_height="64dp"
        android:layout_weight="0.17"
        android:clickable="true"
        android:src="@drawable/ic_alarm_10min"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.22">

    </LinearLayout>

    <ImageView
        android:id="@+id/imageViewCancel"
        android:layout_width="0dp"
        android:layout_height="64dp"
        android:layout_weight="0.17"
        android:clickable="true"
        android:src="@drawable/ic_alarm_off"/>

    <LinearLayout
        android:id="@+id/linearLayoutRightArrowWrapper"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_weight="0.21">

        <ImageView
            android:id="@+id/imageViewRightArrow"
            android:layout_width="47dp"
            android:layout_height="23dp"
            android:layout_gravity="center_vertical"
            android:src="@drawable/arrow_right"/>
    </LinearLayout>

</LinearLayout>

这是我的活动java代码

public class AlarmAlertLvOneActivity extends AppCompatActivity {
private static final String TAG = "AlarmAlertLvOneActivity";

private Alarm alarm;

private SharedPreferences sharedPreferences;

private AlarmLogDataBaseManager alarmLogDataBaseManager;
private SnoozeDataBaseManager snoozeDataBaseManager;

private int time;
private long timeInMillis;

private AlarmAlert alarmAlert;


@Override
public void onCreate(Bundle savedInstanceState) {
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alarm_alert_lv_one);


    Bundle bundle = getIntent().getExtras();
    alarm = bundle.getParcelable("Alarm");


    sharedPreferences = getSharedPreferences("app_setting", MODE_PRIVATE);

    alarmLogDataBaseManager = new AlarmLogDataBaseManager(getApplicationContext(), null, null, -1);
    snoozeDataBaseManager = new SnoozeDataBaseManager(getApplicationContext(), null, null, -1);

    if (getIntent().getStringExtra("mode") != null && getIntent().getStringExtra("mode").equals("snooze")) {
        snoozeDataBaseManager.snoozeOff(getIntent().getLongExtra("snoozeId", 0));

        AppController.getInstance().setNotificationController(getApplicationContext());
        AppController.getInstance().getNotificationController().notifyNotificationChanged(NotificationController
                .NOTI_SNOOZE);

    }

    alarmAlert = new AlarmAlert(getApplicationContext(), alarm);

    time = 60 * Calendar.getInstance().get(Calendar.MINUTE) + 60 * 60 * Calendar.getInstance().get(Calendar
            .HOUR_OF_DAY);
    timeInMillis = Calendar.getInstance().getTimeInMillis();

    setArrowAnimation();
    initViews();
    initSoundAndVibrate();

}

@Override
protected void onResume() {
    super.onResume();
}

Animation fadeInOutAnimcation;

private void setArrowAnimation() {
    fadeInOutAnimcation = new AlphaAnimation(0, 1);
    fadeInOutAnimcation.setInterpolator(new LinearInterpolator());
    fadeInOutAnimcation.setDuration(1000);
    fadeInOutAnimcation.setRepeatMode(Animation.REVERSE);
    fadeInOutAnimcation.setRepeatCount(Animation.INFINITE);
}


ImageView imageViewCancel, imageViewSnooze, imageViewRightArrow, imageViewLeftArrow;
LinearLayout linearLayoutRightArrowWrapper, linearLayoutLeftArrowWrapper;
TextView textViewRingingClock, textViewAmPm;

private void initViews() {

    setTextViewAmPm();
    setTextViewRingingClock();

    linearLayoutLeftArrowWrapper = (LinearLayout) findViewById(R.id.linearLayoutLeftArrowWrapper);
    linearLayoutLeftArrowWrapper.setAnimation(fadeInOutAnimcation);

    imageViewLeftArrow = (ImageView) findViewById(R.id.imageViewLeftArrow);

    imageViewSnooze = (ImageView) findViewById(R.id.imageViewSnooze);
    imageViewSnooze.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            return false;
        }
    });

    linearLayoutRightArrowWrapper = (LinearLayout) findViewById(R.id.linearLayoutRightArrowWrapper);
    linearLayoutRightArrowWrapper.setAnimation(fadeInOutAnimcation);

    imageViewRightArrow = (ImageView) findViewById(R.id.imageViewRightArrow);
    imageViewRightArrow.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch(event.getAction()){
                case DragEvent.ACTION_DROP:
                    Log.d(TAG, "Arrow ACTION DROP");
                    finish();
                    break;
                default:
                    break;
            }
            return true;
        }
    });

    imageViewCancel = (ImageView) findViewById(R.id.imageViewCancel);
    imageViewCancel.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            Log.d(TAG, "ACTION : " +  event.getAction());
            switch(event.getAction()){
                case MotionEvent.ACTION_UP:
                    Log.d(TAG, "ACTION UP");
                    //view.setVisibility(View.VISIBLE);
                    break;
                case MotionEvent.ACTION_CANCEL:
                    Log.d(TAG, "ACTION CANCEL");
                    //view.setVisibility(View.VISIBLE);
                    break;
                case MotionEvent.ACTION_DOWN:
                    Log.d(TAG, "ACTION DOWN");
                    ClipData data = ClipData.newPlainText("", "");
                    View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                            view);
                    if(android.os.Build.VERSION.SDK_INT >= 24)
                        view.startDragAndDrop(data, shadowBuilder,view,0);
                    else
                        view.startDrag(data, shadowBuilder, view, 0);
                    view.setVisibility(View.INVISIBLE);
                    break;
                default:
                    break;
            }
            return true;
        }
    });

}

private void setTextViewAmPm(){
    textViewAmPm = (TextView) findViewById(R.id.textViewAmPm);
    if ((Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) > 12)
        textViewAmPm.setText("PM");
    else
        textViewAmPm.setText("AM");
}

private void setTextViewRingingClock(){
    textViewRingingClock = (TextView) findViewById(R.id.textViewRingingTime);
    if (sharedPreferences.getBoolean("24Hour_OnOff", false)) {
        if ((Calendar.getInstance().get(Calendar.MINUTE)) < 10)
            textViewRingingClock.setText((Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) + ":" + "0" +
                    (Calendar.getInstance().get(Calendar.MINUTE)));
        else
            textViewRingingClock.setText((Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) + ":" + (Calendar
                    .getInstance().get(Calendar.MINUTE)));
    } else {
        if ((Calendar.getInstance().get(Calendar.MINUTE)) < 10)
            textViewRingingClock.setText((Calendar.getInstance().get(Calendar.HOUR)) + ":" + "0" + (Calendar
                    .getInstance().get(Calendar.MINUTE)));
        else
            textViewRingingClock.setText((Calendar.getInstance().get(Calendar.HOUR)) + ":" + (Calendar
                    .getInstance().get(Calendar.MINUTE)));
    }
}

private void initSoundAndVibrate() {
    alarmAlert.initSoundAndVibrate(alarm.isVibrationIsOn(), alarm.getSoundUriInString());
}

protected void onDestroy() {
    super.onDestroy();

    alarmAlert.quitSonndAndVibrate();
    alarmLogDataBaseManager.saveLogData(
            Calendar.getInstance().get(Calendar.YEAR),
            Calendar.getInstance().get(Calendar.MONTH),
            Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
            time,
            alarm.getTime(),
            (int) (Calendar.getInstance().getTimeInMillis() - timeInMillis) / 1000,
            true);

    Log.e("Elapsed", (Calendar.getInstance().getTimeInMillis() - timeInMillis) / 1000 + "");

    AppController.getInstance().setNotificationController(getApplicationContext());
    AppController.getInstance().getNotificationController().notifyNotificationChanged(NotificationController
            .NOTI_ALARM);
    AppController.getInstance().getNotificationController().notifyNotificationChanged(NotificationController
            .NOTI_SNOOZE);
}
公共类AlarmAlertLvOneActivity扩展了AppCompatActivity{
私有静态最终字符串标记=“AlarmAlertLvOneActivity”;
私人报警;
私人共享引用共享引用;
专用AlarmLogDataBaseManager AlarmLogDataBaseManager;
私家小吃店经理小吃店经理;
私人整数时间;
私人长时间单位;
私人警报;
@凌驾
创建时的公共void(Bundle savedInstanceState){
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_锁定时显示
|WindowManager.LayoutParams.FLAG\u保持屏幕\u打开
|WindowManager.LayoutParams.FLAG(打开屏幕);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u alarm\u alert\u lv\u one);
Bundle Bundle=getIntent().getExtras();
报警=bundle.getParcelable(“报警”);
SharedReferences=GetSharedReferences(“应用程序设置”,模式为私有);
alarmLogDataBaseManager=新的alarmLogDataBaseManager(getApplicationContext(),null,null,-1);
snoozeDataBaseManager=新的snoozeDataBaseManager(getApplicationContext(),null,null,-1);
如果(getIntent().getStringExtra(“mode”)!=null&&getIntent().getStringExtra(“mode”).equals(“snooze”)){
snoozeDataBaseManager.snoozeOff(getIntent().getLongExtra(“snoozeId”,0));
AppController.getInstance().setNotificationController(getApplicationContext());
AppController.getInstance().getNotificationController().notifyNotificationChanged(NotificationController
(不打瞌睡);
}
alarmAlert=新的alarmAlert(getApplicationContext(),报警);
时间=60*Calendar.getInstance().get(Calendar.MINUTE)+60*60*Calendar.getInstance().get(Calendar
.每天的小时);
timeInMillis=Calendar.getInstance().getTimeInMillis();
setarrow动画();
initViews();
初始化声音和振动();
}
@凌驾
受保护的void onResume(){
super.onResume();
}
动画发散模拟;
私有void setarrow动画(){
FadeInutanimation=新字母动画(0,1);
setInterpolator(新的LinearInterpolator());
设置持续时间(1000);
FadeInutanimation.setRepeatMode(动画.反转);
setRepeatCount(Animation.INFINITE);
}
ImageView imageViewCancel、imageViewSnooze、imageViewRightArrow、imageViewLeftArrow;
LinearLayout LinearLayoutArrowWrapper、linearLayoutLeftArrowWrapper;
TextView textViewRingingClock,textViewAmPm;
私有void initViews(){
setTextViewAmPm();
settextviewringclock();
linearLayoutLeftArrowWrapper=(LinearLayout)findViewById(R.id.linearLayoutLeftArrowWrapper);
linearLayoutLeftArrowWrapper.setAnimation(FadeInutanimation);
imageViewLeftArrow=(ImageView)findViewById(R.id.imageViewLeftArrow);
imageViewSnooze=(ImageView)findViewById(R.id.imageViewSnooze);
imageViewSnooze.setOnDragListener(新视图.OnDragListener(){
@凌驾
公共布尔onDrag(视图v,DrageEvent事件){
返回false;
}
});
linearlayautrihtarrowwrapper=(LinearLayout)findViewById(R.id.linearlayautrihtarrowwrapper);
linearlayautrihtarrowwrapper.setAnimation(fadeInutanimation);
imageViewRightArrow=(ImageView)findViewById(R.id.imageViewRightArrow);
imageViewRightArrow.setOnDragListener(新视图.OnDragListener(){
@凌驾
公共布尔onDrag(视图v,DrageEvent事件){
开关(event.getAction()){
案例DrageEvent.ACTION_DROP:
Log.d(标签“箭头动作下降”);
完成();
打破
违约:
打破
}
返回true;
}
});
imageViewCancel=(ImageView)findViewById(R.id.imageViewCancel);
imageViewCancel.setOnTouchListener(新视图.OnTouchListener(){
@凌驾
公共布尔onTouch(视图、运动事件){
Log.d(标记“ACTION:+event.getAction());
开关(event.getAction()){
case MotionEvent.ACTION\u UP:
日志d(标记“行动起来”);
//view.setVisibility(view.VISIBLE);
打破
case MotionEvent.ACTION\u取消:
Log.d(标记“操作取消”);
//view.setVisibility(view.VISIBLE);
打破
case MotionEvent.ACTION\u DOWN:
Log.d(标记“动作停止”);
ClipData data=ClipData.newPlainText(“,”);
View.DragShadowBuilder shadowBuilder=新建View.DragShadowBuilder(
视图);
如果(android.os.Build.VERSION.SDK_INT>=24)
view.startDragAndDrop(数据,阴影生成器,视图,0);
其他的
view.startDrag(数据,shadowBuilder,视图,0);
view.setVisibility(view.INVISIBLE);
打破
违约:
打破
}
返回true;
}
});
}
私有void setTextViewAmPm(){
textViewAmPm=(TextView)findViewById(R.id.textViewAmPm);
如果((Calendar.getInstance().get(Calendar.HOUR/OF/u DAY))>12)
textViewAmPm.setText(“PM”);
其他的
textViewAmPm.setText(“AM”);
}
私有void settExtViewingClock(){
textViewRingClock=(TextView)findViewById(R.id.textViewRingTime);
if(sharedPreferences.getBool