drew 6 yıl önce
ebeveyn
işleme
a8d1f42a22

BIN
app/src/main/assets/video_background.mp4


+ 5 - 3
app/src/main/java/com/ht/gate/CustomKeyboardView.java

@@ -154,7 +154,7 @@ public class CustomKeyboardView extends View {
         setVisibility(VISIBLE);
         TranslateAnimation animate = new TranslateAnimation(0, 0, getHeight() <= 0 ? targetHeight : getHeight(), 0);
         animate.setDuration(200);
-        animate.setFillAfter(true);
+        animate.setFillAfter(false);
         animate.setInterpolator(new AccelerateDecelerateInterpolator());
         startAnimation(animate);
     }
@@ -162,7 +162,7 @@ public class CustomKeyboardView extends View {
     public void hide() {
         TranslateAnimation animate = new TranslateAnimation(0, 0, 0, getHeight());
         animate.setDuration(200);
-        animate.setFillAfter(true);
+        animate.setFillAfter(false);
         animate.setAnimationListener(new Animation.AnimationListener() {
             @Override
             public void onAnimationStart(Animation animation) {
@@ -200,7 +200,7 @@ public class CustomKeyboardView extends View {
         mKeyOffsetY = dp2px(12);
         source_han_sans_sc_normal = ResourcesCompat.getFont(getContext(), R.font.source_han_sans_sc_normal);
         source_han_sans_sc_medium = ResourcesCompat.getFont(getContext(), R.font.source_han_sans_sc_medium);
-        roboto_normal =  ResourcesCompat.getFont(getContext(), R.font.roboto_normal);
+        roboto_normal = ResourcesCompat.getFont(getContext(), R.font.roboto_normal);
         filter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
 
         mBitmapPaint = new Paint();
@@ -435,6 +435,8 @@ public class CustomKeyboardView extends View {
                 mKeyboardActionListener.onKey(code, codes);
                 mKeyboardActionListener.onRelease(code);
 
+                SoundUtil.getInstance(getContext()).play(SoundUtil.KEYBOARD);
+
                 if (mKeys[index].label.equals("shift")) {
                     setCap(!cap);
                     postInvalidate();

+ 3 - 2
app/src/main/java/com/ht/gate/LoginActivity.java

@@ -47,7 +47,9 @@ public class LoginActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_login);
         ButterKnife.bind(this);
-
+        if (MyApplication.roomInfo != null) {
+           // et.setText(MyApplication.roomInfo.getDeviceCode());
+        }
         unlockView.setUnlockListener(() -> {
             unlockView.setVisibility(View.GONE);
             et.setVisibility(View.VISIBLE);
@@ -106,7 +108,6 @@ public class LoginActivity extends AppCompatActivity {
                                             .putString(Constants.PREF_ROOM_INFO, response.body().toBase64())
                                             .apply();
                                     MyApplication.roomInfo = response.body();
-                                    MyApplication.setPassword(LoginActivity.this, response.body().getDevicePassword());
                                     startActivity(new Intent(LoginActivity.this, MainActivity.class));
                                     finish();
                                 } else {

+ 32 - 61
app/src/main/java/com/ht/gate/MainActivity.java

@@ -10,6 +10,9 @@ import android.animation.ValueAnimator;
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.ServiceConnection;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.SoundPool;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -119,36 +122,11 @@ public class MainActivity extends AppCompatActivity {
                             mDoorBinder.getService().openDoor();
                         }
                         Toasty.normal(MainActivity.this, "已解锁").show();
-
-//                        try {
-//                            Meeting meeting = MyApplication.todayMeetings.get(0).getMeetings().get(0);
-//                            RetrofitManager.getInstance().getRetrofit().create(ApiService.class)
-//                                    .getEmpInfo(meeting.getCreateUser().getUserId()).enqueue(new Callback<EmpInfo>() {
-//                                @Override
-//                                public void onResponse(@NonNull Call<EmpInfo> call, @NonNull Response<EmpInfo> response) {
-//                                    if (response.code() == 200) {
-//                                        WelcomeActivity.start(MainActivity.this, meeting, response.body());
-//                                    } else {
-//                                        try {
-//                                            Toasty.error(MainActivity.this, response.errorBody().string()).show();
-//                                        } catch (IOException e) {
-//                                            e.printStackTrace();
-//                                        }
-//                                    }
-//                                }
-//
-//                                @Override
-//                                public void onFailure(@NonNull Call<EmpInfo> call, @NonNull Throwable t) {
-//                                    Toasty.error(MainActivity.this, "设备绑定失败,请稍后再试").show();
-//                                }
-//                            });
-//                        } catch (Exception e) {
-//                            e.printStackTrace();
-//                        }
-
+                        SoundUtil.getInstance(MainActivity.this).play(SoundUtil.UNLOCK_SUCCESS);
                     } else {
                         Toasty.normal(MainActivity.this, "密码错误", ContextCompat.getDrawable(MainActivity.this, R.mipmap.toast_icon_warn_fill))
                                 .show();
+                        SoundUtil.getInstance(MainActivity.this).play(SoundUtil.UNLOCK_FAIL);
                     }
                     Message msg = new Message();
                     msg.what = HIDE_BAR;
@@ -221,45 +199,38 @@ public class MainActivity extends AppCompatActivity {
             rlMeetings.setVisibility(View.VISIBLE);
         }
         adapter.notifyDataSetChanged();
-        boolean b = false;
-        for (RoomMeetings todayMeeting : MyApplication.todayMeetings) {
-            for (Meeting meeting : todayMeeting.getMeetings()) {
-                try {
-                    Date start = Utils.parseDateTime(meeting.getBeginTimeStr());
-                    start.setTime(start.getTime() - 10 * 60 * 1000);
-                    Date end = Utils.parseDateTime(meeting.getEndTimeStr());
-                    Date date = new Date();
-                    if ((date.equals(start) || date.after(start)) && (date.equals(end) || date.before(end))) {
-                        MyApplication.setPassword(MainActivity.this, todayMeeting.getRoom().getDevicePassword());
-                        RetrofitManager.getInstance().getRetrofit().create(ApiService.class)
-                                .getEmpInfo(meeting.getCreateUser().getUserId()).enqueue(new Callback<EmpInfo>() {
-                            @Override
-                            public void onResponse(@NonNull Call<EmpInfo> call, @NonNull Response<EmpInfo> response) {
-                                if (response.code() == 200) {
-                                    WelcomeActivity.start(MainActivity.this, meeting, response.body());
-                                } else {
-                                    try {
-                                        Toasty.error(MainActivity.this, response.errorBody().string()).show();
-                                    } catch (IOException e) {
-                                        e.printStackTrace();
-                                    }
+
+        for (Meeting meeting : MyApplication.todayMeetings) {
+            try {
+                Date start = Utils.parseDateTime(meeting.getBeginTimeStr());
+                start.setTime(start.getTime() - 10 * 60 * 1000);
+                Date end = Utils.parseDateTime(meeting.getEndTimeStr());
+                Date date = new Date();
+                if ((date.equals(start) || date.after(start)) && (date.equals(end) || date.before(end))) {
+                    RetrofitManager.getInstance().getRetrofit().create(ApiService.class)
+                            .getEmpInfo(meeting.getCreateUser().getUserId()).enqueue(new Callback<EmpInfo>() {
+                        @Override
+                        public void onResponse(@NonNull Call<EmpInfo> call, @NonNull Response<EmpInfo> response) {
+                            if (response.code() == 200) {
+                                WelcomeActivity.start(MainActivity.this, meeting, response.body());
+                            } else {
+                                try {
+                                    Toasty.error(MainActivity.this, response.errorBody().string()).show();
+                                } catch (IOException e) {
+                                    e.printStackTrace();
                                 }
                             }
+                        }
 
-                            @Override
-                            public void onFailure(@NonNull Call<EmpInfo> call, @NonNull Throwable t) {
-                                Toasty.error(MainActivity.this, "投顾信息获取失败,请稍后再试").show();
-                            }
-                        });
-                        b = true;
-                        break;
-                    }
-                } catch (ParseException e) {
-                    e.printStackTrace();
-                }
-                if (b) {
+                        @Override
+                        public void onFailure(@NonNull Call<EmpInfo> call, @NonNull Throwable t) {
+                            Toasty.error(MainActivity.this, "投顾信息获取失败,请稍后再试").show();
+                        }
+                    });
                     break;
                 }
+            } catch (ParseException e) {
+                e.printStackTrace();
             }
         }
     }

+ 2 - 5
app/src/main/java/com/ht/gate/MeetingAdapter.java

@@ -34,7 +34,7 @@ public class MeetingAdapter extends RecyclerView.Adapter<MeetingAdapter.MeetingH
         if (MyApplication.todayMeetings.isEmpty()) {
             return;
         }
-        Meeting meeting = MyApplication.todayMeetings.get(0).getMeetings().get(position);
+        Meeting meeting = MyApplication.todayMeetings.get(position);
         holder.tvContent.setText(Utils.formatDateStr(meeting.getBeginDate()) + " "
                 + Utils.getWeekDay(meeting.getBeginDate()) + " "
                 + Utils.getTimeStr(meeting.getBeginTimeStr()) + "-"
@@ -44,10 +44,7 @@ public class MeetingAdapter extends RecyclerView.Adapter<MeetingAdapter.MeetingH
 
     @Override
     public int getItemCount() {
-        if (MyApplication.todayMeetings.isEmpty()) {
-            return 0;
-        }
-        return MyApplication.todayMeetings.get(0).getMeetings().size();
+        return MyApplication.todayMeetings.size();
     }
 
     public class MeetingHolder extends RecyclerView.ViewHolder {

+ 1 - 1
app/src/main/java/com/ht/gate/MockServer.java

@@ -18,7 +18,7 @@ public class MockServer {
         MockNet mockNet = MockNet.create();
         mockNet.addConnection(MockConnectionFactory.getInstance()
                 .createGeneralConnection(MockConnection.POST,
-                        "/meeting/service-api/crmnew/bind-device/share-SH8001-5-A02",
+                        "/meeting/service-api/crmnew/bind-device/111",
                         "text/json",
                         loadAssetTextAsString(context, "mockData/Room.json")))
                 .addConnection(MockConnectionFactory.getInstance()

+ 49 - 24
app/src/main/java/com/ht/gate/MyApplication.java

@@ -16,14 +16,19 @@ import com.squareup.picasso.Picasso;
 import org.greenrobot.eventbus.EventBus;
 
 import java.io.IOException;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 import cat.ereza.customactivityoncrash.config.CaocConfig;
 import es.dmoral.toasty.Toasty;
@@ -35,25 +40,25 @@ import retrofit2.Response;
 
 public class MyApplication extends Application {
 
-    public static List<RoomMeetings> todayMeetings;
+    public static List<Meeting> todayMeetings;
     public static Room roomInfo;
     private static String password;
 
+    private ScheduledExecutorService executorService;
     private SharedPreferences sharedPreferences;
 
+
     public static void setPassword(Context context, String password) {
         MyApplication.password = password;
         SharedPreferences sharedPreferences = context.getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
         sharedPreferences.edit().putString(Constants.PREF_PASSWORD, password).apply();
     }
 
-    public static String getPassword() {
-        return password;
-    }
 
     @Override
     public void onCreate() {
         super.onCreate();
+        executorService = Executors.newScheduledThreadPool(2);
         sharedPreferences = getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
         roomInfo = Room.fromBase64(sharedPreferences.getString(Constants.PREF_ROOM_INFO, null));
         if (roomInfo != null) {
@@ -70,12 +75,16 @@ public class MyApplication extends Application {
             todayMeetings = new ArrayList<>();
         }
         MockServer.start(this);
-        new Timer().schedule(new TimerTask() {
-            @Override
-            public void run() {
-                getMeetings();
-            }
-        }, 0, 10 * 1000);
+
+        executorService.scheduleAtFixedRate(this::getMeetings, 0, 10 * 1000, TimeUnit.MILLISECONDS);
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                getMeetings();
+//            }
+//        }, 0, 10 * 1000);
+
+        SoundUtil.init(this);
 
         CaocConfig.Builder.create()
                 .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
@@ -101,23 +110,39 @@ public class MyApplication extends Application {
                         @Override
                         public void onResponse(@NonNull Call<List<RoomMeetings>> call, @NonNull Response<List<RoomMeetings>> response) {
                             if (response.code() == 200) {
-                                todayMeetings = response.body();
-                                if (todayMeetings != null) {
-                                    for (RoomMeetings todayMeeting : todayMeetings) {
-                                        if (todayMeeting.getMeetings() != null) {
-                                            todayMeeting.getMeetings().sort((o1, o2) -> {
-                                                try {
-                                                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
-                                                    Date date1 = sdf.parse(o1.getBeginTimeStr());
-                                                    Date date2 = sdf.parse(o2.getBeginTimeStr());
-                                                    return date1.compareTo(date2);
-                                                } catch (Exception e) {
-                                                    return 0;
-                                                }
-                                            });
+                                if (response.body() == null) {
+                                    return;
+                                }
+                                List<Meeting> list = new ArrayList<>();
+                                for (RoomMeetings roomMeetings : response.body()) {
+                                    if (roomMeetings.getMeetings() != null) {
+                                        list.addAll(roomMeetings.getMeetings());
+                                    }
+                                }
+                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
+                                Iterator<Meeting> iterable = list.iterator();
+                                while (iterable.hasNext()) {
+                                    Meeting meeting = iterable.next();
+                                    try {
+                                        Date end = sdf.parse(meeting.getEndTimeStr());
+                                        if (end != null && end.before(new Date())) {
+                                            iterable.remove();
                                         }
+                                    } catch (ParseException e) {
+                                        e.printStackTrace();
                                     }
                                 }
+
+                                list.sort((o1, o2) -> {
+                                    try {
+                                        Date date1 = sdf.parse(o1.getBeginTimeStr());
+                                        Date date2 = sdf.parse(o2.getBeginTimeStr());
+                                        return date1.compareTo(date2);
+                                    } catch (Exception e) {
+                                        return 0;
+                                    }
+                                });
+                                todayMeetings = list;
                                 EventBus.getDefault().post(Constants.EVENT_MEETINGS);
                             } else {
                                 try {

+ 56 - 0
app/src/main/java/com/ht/gate/SoundUtil.java

@@ -0,0 +1,56 @@
+package com.ht.gate;
+
+import android.content.Context;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.SoundPool;
+
+public class SoundUtil {
+
+    private static SoundUtil instance;
+
+    private SoundPool soundPool;
+    public static int UNLOCK_SUCCESS;
+    public static int KEYBOARD;
+    public static int UNLOCK_FAIL;
+    private boolean loaded = false;
+
+    private SoundUtil(Context context) {
+        SoundPool.Builder builder = new SoundPool.Builder();
+        //传入最多播放音频数量,
+        builder.setMaxStreams(3);
+        //AudioAttributes是一个封装音频各种属性的方法
+        AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
+        //设置音频流的合适的属性
+        attrBuilder.setLegacyStreamType(AudioManager.STREAM_MUSIC);
+        //加载一个AudioAttributes
+        builder.setAudioAttributes(attrBuilder.build());
+        soundPool = builder.build();
+        UNLOCK_SUCCESS = soundPool.load(context.getApplicationContext(), R.raw.unlock_success, 1);
+        UNLOCK_FAIL = soundPool.load(context.getApplicationContext(), R.raw.unlock_fail, 1);
+        KEYBOARD = soundPool.load(context.getApplicationContext(), R.raw.keyboard, 1);
+        //异步需要等待加载完成,音频才能播放成功
+        soundPool.setOnLoadCompleteListener((soundPool, sampleId, status) -> {
+            if (status == 0) {
+                loaded = true;
+            }
+        });
+    }
+
+    public void play(int id) {
+        if (loaded) {
+            soundPool.play(id, 1, 1, 1, 0, 1);
+        }
+    }
+
+    public static SoundUtil getInstance(Context context) {
+        if (instance == null) {
+            instance = new SoundUtil(context.getApplicationContext());
+        }
+        return instance;
+    }
+
+    public static SoundUtil init(Context context) {
+        return getInstance(context);
+    }
+}

+ 3 - 5
app/src/main/java/com/ht/gate/WelcomeActivity.java

@@ -151,8 +151,10 @@ public class WelcomeActivity extends AppCompatActivity {
                         if (mDoorBinder != null) {
                             mDoorBinder.getService().openDoor();
                         }
+                        SoundUtil.getInstance(WelcomeActivity.this).play(SoundUtil.UNLOCK_SUCCESS);
                         Toasty.normal(WelcomeActivity.this, "已解锁").show();
                     } else {
+                        SoundUtil.getInstance(WelcomeActivity.this).play(SoundUtil.UNLOCK_FAIL);
                         Toasty.normal(WelcomeActivity.this, "密码错误", ContextCompat.getDrawable(WelcomeActivity.this, R.mipmap.toast_icon_warn_fill))
                                 .show();
                     }
@@ -310,11 +312,7 @@ public class WelcomeActivity extends AppCompatActivity {
         }
         adapter.notifyDataSetChanged();
 
-        List<Meeting> meetings = new ArrayList<>();
-        for (RoomMeetings todayMeeting : MyApplication.todayMeetings) {
-            meetings.addAll(todayMeeting.getMeetings());
-        }
-        if (meetings.stream().noneMatch(meeting1 -> meeting1.getUuid().equals(meeting.getUuid()))) {
+        if (MyApplication.todayMeetings.stream().noneMatch(meeting1 -> meeting1.getUuid().equals(meeting.getUuid()))) {
             finish();
         }
     }

BIN
app/src/main/res/raw/keyboard.wav


BIN
app/src/main/res/raw/unlock_fail.mp3


BIN
app/src/main/res/raw/unlock_success.mp3