修改 问题3
parent
63f04c9f65
commit
a45040d9df
@ -0,0 +1,54 @@
|
||||
package com.example.as_trak.dialog;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.database.Observable;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Vibrator;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ObservableBoolean;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.example.as_trak.R;
|
||||
import com.example.as_trak.databinding.DialogTipBinding;
|
||||
|
||||
public class TipDialog extends Dialog {
|
||||
private MediaPlayer music;
|
||||
private MediaPlayer musicSuccess;
|
||||
private Vibrator vibrator;
|
||||
private ObservableBoolean state;
|
||||
private DialogTipBinding binding;
|
||||
|
||||
public TipDialog(@NonNull Context context) {
|
||||
super(context, R.style.dialog_style);
|
||||
music = MediaPlayer.create(context, R.raw.error);
|
||||
musicSuccess = MediaPlayer.create(context, R.raw.success);
|
||||
vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_tip, null, false);
|
||||
setContentView(binding.getRoot());
|
||||
state = new ObservableBoolean();
|
||||
setCanceledOnTouchOutside(false);
|
||||
binding.setState(state);
|
||||
binding.tipDialogOver.setOnClickListener(v -> dismiss());
|
||||
}
|
||||
|
||||
|
||||
public void showError(String msg) {
|
||||
super.show();
|
||||
music.start();
|
||||
vibrator.vibrate(500); // 震动1/2秒
|
||||
state.set(false);
|
||||
binding.toastMsg.setText(msg);
|
||||
}
|
||||
|
||||
public void showSuccess(String msg) {
|
||||
super.show();
|
||||
musicSuccess.start();
|
||||
state.set(true);
|
||||
binding.toastMsg.setText(msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="6dp"
|
||||
/>
|
||||
<solid android:color="#2AA515"/>
|
||||
</shape>
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="state"
|
||||
type="androidx.databinding.ObservableBoolean" />
|
||||
|
||||
<import type="android.view.View" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@{state?@drawable/bg_suecss:@drawable/button_delete}"
|
||||
android:orientation="vertical"
|
||||
android:theme="@android:style/Theme.DeviceDefault.Light">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="30dp"
|
||||
android:src="@mipmap/ic_yes"
|
||||
android:visibility="@{state?View.VISIBLE:View.GONE}" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="30dp"
|
||||
android:src="@mipmap/ic_no"
|
||||
android:visibility="@{state?View.GONE:View.VISIBLE}" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toast_msg"
|
||||
android:layout_width="400dp"
|
||||
android:layout_height="315dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/tip_dialog_over"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="55dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:backgroundTint="@color/white"
|
||||
android:text="关闭"
|
||||
android:textColor="@color/black"
|
||||
android:textStyle="bold"
|
||||
android:textSize="20sp"
|
||||
android:letterSpacing="0.5"/>
|
||||
</LinearLayout>
|
||||
</layout>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
>
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="删除" />
|
||||
<item
|
||||
android:id="@+id/action_edit"
|
||||
android:title="修改" />
|
||||
</menu>
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
Loading…
Reference in New Issue