Procházet zdrojové kódy

Merge branch 'master' of http://10.8.230.114:3000/kemllor/small_sheep_android

zhaoyi před 8 roky
rodič
revize
bfe42cd0a4

+ 60 - 3
app/src/main/java/com/sheep/jiuyan/samllsheep/page/WebActivity.java

@@ -1,7 +1,9 @@
 package com.sheep.jiuyan.samllsheep.page;
 
 import android.content.Intent;
+import android.text.TextUtils;
 import android.view.View;
+import android.webkit.JavascriptInterface;
 import android.webkit.WebChromeClient;
 import android.webkit.WebResourceRequest;
 import android.webkit.WebView;
@@ -11,8 +13,18 @@ import android.widget.TextView;
 
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.base.BaseActivity;
+import com.sheep.jiuyan.samllsheep.net.NetManager;
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
+import com.sheep.jiuyan.samllsheep.net.Url;
+import com.sheep.jiuyan.samllsheep.page.entry.WXAccount;
+import com.sheep.jiuyan.samllsheep.utils.G;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+
 /**
  * Created by kemllor on 2018/1/2.
  */
@@ -21,6 +33,8 @@ public class WebActivity extends BaseActivity {
 
     private WebView mWeb;
     public final static String INTENT_URL = "url";
+    public final static String INTENT_TITLE = "INTENT_TITLE";
+    public final static String INTENT_LOAD_JS = "INTENT_LOAD_JS";//只要此INTENT有就会载入
 
     @Override
     protected int getLayoutId() {
@@ -29,6 +43,11 @@ public class WebActivity extends BaseActivity {
 
     @Override
     public void initView() {
+        if (!getIntent().hasExtra(INTENT_URL)) {
+            G.showToast("网址打开失败!");
+            finish();
+            return;
+        }
         mWeb = (WebView) findViewById(R.id.web);
         mWeb.setWebChromeClient(new WebChromeClient() {
 
@@ -42,18 +61,56 @@ public class WebActivity extends BaseActivity {
             }
         });
         TitleBarUtils.getInstance()
-                .setTitle(this, "任务攻略")
+                .setTitle(this, getIntent().hasExtra(INTENT_TITLE) ?
+                        getIntent().getStringExtra(INTENT_TITLE) : "任务攻略")
                 .setTitleFinish(this);
+
+        if (getIntent().hasExtra(INTENT_LOAD_JS)) {
+            mWeb.addJavascriptInterface(new PublicJavaScript(), "PublicJavaScript");
+        }
+    }
+
+
+    /**
+     * JS调用方法
+     */
+    public class PublicJavaScript {
+        @JavascriptInterface
+        public void submit(String user, String pass, String phone) {
+            HashMap<String, String> map = new HashMap<>();
+            map.put("wx_open_id", SpUtils.getOpenId(WebActivity.this));
+            map.put("wx_1", user);
+            map.put("ps_1", pass);
+            map.put("phone", phone);
+            NetManager.get(Url.WXACCOUNT, map, WebActivity.this,
+                    new SheepCallback<String>(WebActivity.this) {
+                        @Override
+                        public void success(String string) {
+                            G.showToast("申请成功!");
+                            finish();
+                        }
+                    });
+        }
+
+        @JavascriptInterface
+        public void finish() {
+            WebActivity.this.finish();
+        }
+
+        @JavascriptInterface
+        public void setTitle(String title) {
+            TitleBarUtils.getInstance().setTitle(WebActivity.this, title);
+        }
     }
 
+
     @Override
     public void initListener() {
     }
 
     @Override
     public void initData() {
-        Intent intent = getIntent();
-        String url = intent.getStringExtra("url");
+        String url = getIntent().getStringExtra(INTENT_URL);
         mWeb.loadUrl(url);
     }
 

+ 16 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/page/fragment/FgtMainPageOffline.java

@@ -1,5 +1,6 @@
 package com.sheep.jiuyan.samllsheep.page.fragment;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.widget.LinearLayoutManager;
@@ -13,6 +14,7 @@ import com.sheep.jiuyan.samllsheep.base.BaseFragment;
 import com.sheep.jiuyan.samllsheep.net.NetManager;
 import com.sheep.jiuyan.samllsheep.net.SheepCallback;
 import com.sheep.jiuyan.samllsheep.net.Url;
+import com.sheep.jiuyan.samllsheep.page.WebActivity;
 import com.sheep.jiuyan.samllsheep.page.adapter.AdpTaskList;
 import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
 import com.sheep.jiuyan.samllsheep.page.entry.WXAccount;
@@ -43,6 +45,7 @@ public class FgtMainPageOffline extends BaseFragment {
     private int mIntLastPage = 0;//上次的页码
     private AdpTaskList mAdpTaskList;
     private RecyleViewLoadMoreUtils mRecyleViewLoadMoreUtils;
+    private View mLayoutStartTask;//开始挂机点击View
 
     @Override
     public int getLayoutId() {
@@ -54,6 +57,7 @@ public class FgtMainPageOffline extends BaseFragment {
         mViewEmpty = findViewById(R.id.layout_fgt_main_page_offline_empty);
         mViewList = findViewById(R.id.layout_fgt_main_page_offline_task);
         mRecyclerView = findViewById(R.id.recy_fgt_main_page_offline_task);
+        mLayoutStartTask = findViewById(R.id.layout_start_task);
 
         mRecyleViewLoadMoreUtils = new RecyleViewLoadMoreUtils();
         mAdpTaskList = new AdpTaskList(getActivity());
@@ -66,6 +70,18 @@ public class FgtMainPageOffline extends BaseFragment {
             }
         });
         initData(false);
+
+
+        mLayoutStartTask.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                Intent intent = new Intent(getActivity(), WebActivity.class);
+                intent.putExtra(WebActivity.INTENT_URL, "http://10.8.210.190:8081");
+                intent.putExtra(WebActivity.INTENT_LOAD_JS, "1");
+                intent.putExtra(WebActivity.INTENT_TITLE, "申请挂机");
+                startActivity(intent);
+            }
+        });
     }
 
 

+ 1 - 0
app/src/main/res/layout/fgt_main_page_offline_empty.xml

@@ -6,6 +6,7 @@
               android:orientation="vertical">
 
     <RelativeLayout
+        android:id="@+id/layout_start_task"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center"

+ 5 - 7
app/src/main/res/layout/web_activity.xml

@@ -1,16 +1,14 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:layout_width="match_parent"
-              android:layout_height="match_parent"
-              android:orientation="vertical">
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
 
-    <include
-        layout="@layout/title"/>
+    <include layout="@layout/title" />
 
     <WebView
         android:id="@+id/web"
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
-    </WebView>
+        android:layout_height="match_parent"></WebView>
 
 </LinearLayout>

+ 8 - 9
app/src/main/res/values/common.xml

@@ -52,7 +52,6 @@
         <item name="android:paddingRight">8dp</item>
         <item name="android:textColorHint">@color/black_text_light</item>
         <item name="android:background">@drawable/sp_edt_background_common</item>
-
     </style>
 
     <!--APP中的主要内容的各种间距值pading默认值和较大值-->
@@ -62,14 +61,14 @@
 
 
     <!--下面的tagid用于设置tag使用-->
-    <item name="tagid1" type="id"/>
-    <item name="tagid2" type="id"/>
-    <item name="tagid3" type="id"/>
-    <item name="tagid4" type="id"/>
-    <item name="tagid5" type="id"/>
-    <item name="tagid6" type="id"/>
-    <item name="tagid7" type="id"/>
-    <item name="tagid8" type="id"/>
+    <item name="tagid1" type="id" />
+    <item name="tagid2" type="id" />
+    <item name="tagid3" type="id" />
+    <item name="tagid4" type="id" />
+    <item name="tagid5" type="id" />
+    <item name="tagid6" type="id" />
+    <item name="tagid7" type="id" />
+    <item name="tagid8" type="id" />
 
 
 </resources>