Pārlūkot izejas kodu

主页添加无网络提示

zengjiebin 7 gadi atpakaļ
vecāks
revīzija
456af96db4

+ 17 - 1
app/src/main/java/com/kfzs/duanduan/fragment/FgtSmallSheep.java

@@ -69,6 +69,7 @@ import com.sheep.gamegroup.util.MyDbManager;
 import com.sheep.gamegroup.util.MyGridview;
 import com.sheep.gamegroup.util.MyListview;
 import com.sheep.gamegroup.util.PreferenceUtils;
+import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.gamegroup.view.activity.NotificationsUtils;
@@ -104,6 +105,7 @@ import butterknife.ButterKnife;
 import butterknife.OnClick;
 import butterknife.Unbinder;
 import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
 import rx.schedulers.Schedulers;
 
 public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContract.View, TryMakeMoneyContract.View {
@@ -162,6 +164,8 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
     MyListview home_list_gridview_listview;
     @BindView(R.id.home_list_gridview_layout)
     LinearLayout home_list_gridview_layout;
+    @BindView(R.id.check_net_ll)
+    View check_net_ll;
 
     @Inject
     SmallSheepPresenter pagePresenter;
@@ -309,7 +313,19 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
     }
 
     public void initData() {
-
+        SysAppUtil.checkNet(new Action1<Integer>() {
+            @Override
+            public void call(Integer result) {
+                if(result != 0){//无网络
+                    check_net_ll.setVisibility(View.VISIBLE);
+                } else {
+                    check_net_ll.setVisibility(View.GONE);
+                }
+            }
+        });
+        mInitData();
+    }
+    private void mInitData(){
         if (upview1 != null) {
             //停止滚动
             upview1.stopFlipping();

+ 22 - 0
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -198,4 +198,26 @@ public class SysAppUtil {
         }
         return TextUtils.isEmpty(sb) ? "Dalvik/2.1.0 (Linux; U; Android 5.1.1; letv x501 Build/LMY48Z)" : sb.toString();
     }
+
+    public static void checkNet(Action1<Integer> action1) {
+        Observable.just(1)
+                .map(new Func1<Integer, Integer>() {
+                    @Override
+                    public Integer call(Integer integer) {
+                        int result = -1;
+                        Runtime runtime = Runtime.getRuntime();
+                        try {
+                            Process p = runtime.exec("ping -c 1 -w 1 www.baidu.com");
+                            result = p.waitFor();
+                            LogUtil.println("ping", "Process:"+result);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                        return result;
+                    }
+                })
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(action1);
+    }
 }

+ 5 - 0
app/src/main/res/drawable/shape_oval_red.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval" >
+    <solid android:color="#ff0000" />
+</shape>

+ 25 - 0
app/src/main/res/layout/check_net_view.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/check_net_ll"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="#33ff0000"
+    android:visibility="gone"
+    android:orientation="horizontal">
+    <TextView
+        android:layout_width="24dp"
+        android:layout_height="24dp"
+        android:gravity="center"
+        android:layout_marginStart="@dimen/content_padding_10"
+        android:text="!"
+        android:textColor="@color/white"
+        android:textSize="18sp"
+        android:background="@drawable/shape_oval_red"/>
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:padding="@dimen/content_padding_10"
+        android:text="网络连接不可用"
+        android:textColor="@color/black_6_3"
+        android:textSize="18sp" />
+</LinearLayout>

+ 3 - 0
app/src/main/res/layout/homepage_act_layout.xml

@@ -23,6 +23,9 @@
                 layout="@layout/homepage_item_top2"/>
 
             <include
+                layout="@layout/check_net_view"/>
+
+            <include
                 layout="@layout/homepage_item_notice"/>
 
             <include