zengjiebin лет назад: 7
Родитель
Сommit
b41d0deb1b

+ 30 - 0
app/src/main/java/com/sheep/gamegroup/module/home/adapter/AdpNotificationOfArrival.java

@@ -0,0 +1,30 @@
+package com.sheep.gamegroup.module.home.adapter;
+
+import android.support.annotation.Nullable;
+import android.widget.TextView;
+
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.BaseViewHolder;
+import com.sheep.gamegroup.model.entity.SystemNotification;
+import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.jiuyan.samllsheep.R;
+
+import java.util.List;
+
+/**
+ * Created by realicing on 2018/12/25.
+ * realicing@sina.com
+ *
+ * 用户入账通知
+ */
+public class AdpNotificationOfArrival extends BaseQuickAdapter<SystemNotification, BaseViewHolder> {
+    public AdpNotificationOfArrival(@Nullable List<SystemNotification> data) {
+        super(R.layout.item_notification_of_arrival, data);
+    }
+
+    @Override
+    protected void convert(BaseViewHolder helper, SystemNotification item) {
+        TextView item_noa_tv = helper.getView(R.id.item_noa_tv);
+        ViewUtil.setText(item_noa_tv, item.getContent());
+    }
+}

+ 10 - 1
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -16,6 +16,7 @@ import android.graphics.Paint;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
+import android.speech.tts.TextToSpeech;
 import android.support.v4.app.NotificationCompat;
 import android.support.v4.app.NotificationManagerCompat;
 import android.support.v7.app.AlertDialog;
@@ -32,6 +33,7 @@ import com.kfzs.cfyl.share_library.util.CallBackAPI;
 import com.kfzs.duanduan.utils.ApkUtils;
 import com.kfzs.duanduan.view.DialogStorageLow;
 import com.sheep.gamegroup.absBase.AbsObserver;
+import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.CreditCard;
 import com.sheep.gamegroup.model.entity.DialogConfig;
@@ -257,7 +259,7 @@ public class TestUtil {
      */
     public static void test(final Activity activity) {
         final String[] items = {"复制token", "添加token", "复制打点数据", "从jenkins下载小绵羊安装包", "测试表情包",
-                "游戏搜索", "测试插件","测试bitmap", "剪切视频", "我的关注", "足迹",
+                "朗读文字", "游戏搜索", "测试插件","测试bitmap", "剪切视频", "我的关注", "足迹",
                 "测试联通卡", "测试联通卡2", "测试签名1", "测试签名2", "测试孔剑秋faq正式服",
                 "跳转QQ1", "跳转QQ2", "跳转QQ3", "跳转白白QQ", "龙猫竞猜", "龙猫竞猜-scheme",
                 "有米科技", "手机型号测试", "测试通知栏", "测试自定义通知栏", "测试自定义通知栏2",
@@ -276,6 +278,9 @@ public class TestUtil {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
                         switch (items[which]) {
+                            case "朗读文字":
+                                testReadText("小绵羊666", 20);
+                                break;
                             case "测试插件":
                                 testPlugin(activity);
                                 break;
@@ -615,6 +620,10 @@ public class TestUtil {
         dialog.show();
     }
 
+    private static void testReadText(String msg, float pitch) {
+       TextToSpeechUtil.get().speakMsg(msg, pitch);
+    }
+
     //测试插件
     private static void testPlugin(Activity activity) {
         SheepPluginUtil.checkAndRunPlugin(activity, Plugin.media)

+ 173 - 0
app/src/main/java/com/sheep/gamegroup/util/TextToSpeechUtil.java

@@ -0,0 +1,173 @@
+package com.sheep.gamegroup.util;
+
+import android.speech.tts.TextToSpeech;
+import android.text.TextUtils;
+
+import com.bumptech.glide.Glide;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.G;
+
+import java.util.Locale;
+
+/**
+ * Created by realicing on 2018/12/25.
+ * realicing@sina.com
+ * 语音工具类
+ */
+public class TextToSpeechUtil {
+
+    private static TextToSpeechUtil instance;
+    /**
+     * Get the singleton.
+     *
+     * @return the singleton
+     */
+    public static TextToSpeechUtil get() {
+        if (instance == null) {
+            synchronized (Glide.class) {
+                if (instance == null) {
+                    instance = new TextToSpeechUtil();
+                }
+            }
+        }
+
+        return instance;
+    }
+    private TextToSpeech textToSpeech;
+    private TextToSpeech.OnInitListener onInitListener = new TextToSpeech.OnInitListener() {
+        /**
+         * 用来初始化TextToSpeech引擎
+         * status:SUCCESS或ERROR这2个值
+         * setLanguage设置语言,帮助文档里面写了有22种
+         * TextToSpeech.LANG_MISSING_DATA:表示语言的数据丢失。
+         * TextToSpeech.LANG_NOT_SUPPORTED:不支持
+         */
+        @Override
+        public void onInit(int status) {
+            switch (status) {
+                case TextToSpeech.SUCCESS:
+                    int result = textToSpeech.setLanguage(Locale.CHINA);
+                    switch (result) {
+                        case TextToSpeech.LANG_MISSING_DATA:
+                            if (TestUtil.isTest())
+                                G.showToast("语言的数据丢失");
+                            break;
+                        case TextToSpeech.LANG_NOT_SUPPORTED:
+                            if (TestUtil.isTest())
+                                G.showToast("不支持朗读【中文】文本信息");
+                            break;
+                        default:
+                            if(!TextUtils.isEmpty(msg)){//文本不为空,朗读文本
+                                if(pitch != -1){
+                                    speakMsg(msg, pitch);
+                                    pitch = -1;
+                                } else {
+                                    speakMsg(msg);
+                                }
+                                msg = null;
+                            }
+                            break;
+                    }
+                    break;
+                default:
+                    if (TestUtil.isTest())
+                        G.showToast("不支持朗读文本信息");
+                    break;
+            }
+        }
+    };
+    private float pitch = -1;
+    private String msg;
+
+    //初始化
+    private void initTextToSpeech() {
+        if(textToSpeech == null){
+            try {
+                textToSpeech = new TextToSpeech(SheepApp.getInstance(), onInitListener);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * 朗读文本
+     *
+     * @param msg 文本信息
+     */
+    public void speakMsg(String msg) {
+        if(textToSpeech == null) {
+            this.msg = msg;
+            initTextToSpeech();
+        } else if (canSpeakNow()) {
+            try {
+                int result = textToSpeech.speak(msg, TextToSpeech.QUEUE_FLUSH, null);
+                if(TestUtil.isDev())
+                    G.showToast("result = " + result);
+                if(result != 0){
+                    stopAndShutdownTTS();
+                    speakMsg(msg);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                if(TestUtil.isDev())
+                    G.showToast(e);
+            }
+        }
+    }
+
+    /**
+     * 朗读文本
+     *
+     * @param msg   文本信息
+     * @param pitch 音调 值越大声音越尖(女生),值越小则变成男声,1.0是常规
+     */
+    public void speakMsg(String msg, float pitch) {
+        if(textToSpeech == null) {
+            this.pitch = pitch;
+            this.msg = msg;
+            initTextToSpeech();
+        } else if (canSpeakNow()) {
+            try {
+                textToSpeech.setPitch(pitch);// 设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规
+                int result = textToSpeech.speak(msg, TextToSpeech.QUEUE_FLUSH, null);
+                if(TestUtil.isDev())
+                    G.showToast("result = " + result);
+                if(result != 0){
+                    stopAndShutdownTTS();
+                    speakMsg(msg, pitch);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                if(TestUtil.isDev())
+                    G.showToast(e);
+            }
+        }
+    }
+
+    /**
+     * 当前可以朗读文本
+     *
+     * @return
+     */
+    public boolean canSpeakNow() {
+        return textToSpeech != null && !textToSpeech.isSpeaking();
+    }
+
+    private void stopAndShutdownTTS() {
+        try {
+            if (textToSpeech != null) {
+                textToSpeech.stop(); // 不管是否正在朗读TTS都被打断
+                textToSpeech.shutdown(); // 关闭,释放资源
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    //释放TTS
+    public static void stopTTS(){
+        if(instance != null){
+            instance.stopAndShutdownTTS();
+        }
+    }
+}

+ 24 - 0
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSmallSheep.java

@@ -44,6 +44,7 @@ import android.widget.TextView;
 import com.alibaba.fastjson.JSONArray;
 import com.bumptech.glide.Glide;
 import com.bumptech.glide.request.RequestOptions;
+import com.chad.library.adapter.base.BaseQuickAdapter;
 import com.kfzs.duanduan.utils.NumberFormatUtils;
 import com.scwang.smartrefresh.layout.SmartRefreshLayout;
 import com.scwang.smartrefresh.layout.api.RefreshLayout;
@@ -65,9 +66,11 @@ import com.sheep.gamegroup.model.entity.Release_task;
 import com.sheep.gamegroup.model.entity.RequestParamEty;
 import com.sheep.gamegroup.model.entity.RobTask;
 import com.sheep.gamegroup.model.entity.SlideshowEty;
+import com.sheep.gamegroup.model.entity.SystemNotification;
 import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
 import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.module.home.adapter.AdpNotificationOfArrival;
 import com.sheep.gamegroup.presenter.SmallSheepContract;
 import com.sheep.gamegroup.presenter.SmallSheepPresenter;
 import com.sheep.gamegroup.presenter.TryMakeMoneyContract;
@@ -1728,4 +1731,25 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
                 });
 
     }
+
+    private RecyclerView home_page_notice_rv;
+    private List<SystemNotification> systemNotificationList = new ArrayList<>();
+    private void showNotificationOfArrivalList(List<SystemNotification> notificationList){
+        if(ListUtil.isEmpty(notificationList)){
+            return;
+        }
+        if(home_page_notice_rv == null){
+            home_page_notice_rv = findViewById(R.id.home_page_notice_rv);
+        }
+        systemNotificationList.clear();
+        systemNotificationList.addAll(notificationList);
+        if(home_page_notice_rv.getAdapter() == null){
+            home_page_notice_rv.setLayoutManager(new LinearLayoutManager(getContext()));
+            AdpNotificationOfArrival adapter = new AdpNotificationOfArrival(systemNotificationList);
+            adapter.bindToRecyclerView(home_page_notice_rv);
+        } else {
+            home_page_notice_rv.getAdapter().notifyDataSetChanged();
+        }
+        //TODO 用声音提示用户有到账信息
+    }
 }

+ 3 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -36,6 +36,7 @@ import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.MyFileNameGenerator;
 import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.SysAppUtil;
+import com.sheep.gamegroup.util.TextToSpeechUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.gamegroup.view.activity.GameCertificationActivity;
 import com.sheep.jiuyan.samllsheep.service.AutoCheckService;
@@ -501,6 +502,7 @@ public class SheepApp extends MultiDexApplication {
             activityRef.clear();
             activityRef = null;
         }
+        TextToSpeechUtil.stopTTS();
         try {
             OkDownload.with().downloadDispatcher().cancelAll();
         } catch (Exception ignore) {
@@ -540,6 +542,7 @@ public class SheepApp extends MultiDexApplication {
         PluginManager.getInstance(base).init();//插件化框架
     }
 
+    //应用退出的回调(模拟器才会回调)
     @Override
     public void onTerminate() {
         super.onTerminate();

+ 8 - 0
app/src/main/res/drawable/shape_white80_solid_rectangle_14.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <corners
+        android:radius="14dp" />
+    <solid android:color="#ccffffff" />
+
+</shape>

+ 8 - 2
app/src/main/res/layout/homepage_act_layout.xml

@@ -4,8 +4,8 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@color/white"
-    android:fitsSystemWindows="true"
-    android:clipChildren="true">
+    android:clipChildren="true"
+    android:fitsSystemWindows="true">
 
     <include
         android:id="@+id/to_search_but_rl"
@@ -183,4 +183,10 @@
         layout="@layout/view_float_title_card"
         android:visibility="visible" />
 
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/home_page_notice_rv"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_below="@id/to_search_but_rl"
+        android:layout_marginTop="12dp" />
 </RelativeLayout>

+ 26 - 0
app/src/main/res/layout/item_notification_of_arrival.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="27dp"
+    android:layout_marginStart="13dp"
+    android:layout_marginEnd="10dp"
+    android:background="@drawable/shape_white80_solid_rectangle_14">
+
+    <ImageView
+        android:layout_width="20dp"
+        android:layout_height="wrap_content"
+        android:adjustViewBounds="true"
+        android:scaleType="fitXY"
+        android:src="@mipmap/ic_yuan_bao" />
+
+    <TextView
+        android:id="@+id/item_noa_tv"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="100dp"
+        android:text="@string/get_money_x_yuan"
+        android:textColor="#ff333333"
+        android:textSize="12sp"
+        app:layout_constraintTop_toTopOf="parent" />
+</android.support.constraint.ConstraintLayout>

BIN
app/src/main/res/mipmap-xxhdpi/ic_yuan_bao.webp


+ 1 - 0
app/src/main/res/values/strings.xml

@@ -207,5 +207,6 @@
     <string name="pay_fail">支付失败</string>
     <string name="you_had_cancel_pay">您取消了支付</string>
     <string name="task_detail_vip_tip">做任务可提高收益哦,任务优先审核</string>
+    <string name="get_money_x_yuan">账户入账通知 尊敬的羊羊用户,恭喜元宝账户收入XXX元。</string>
 
 </resources>