package com.tejia.lijin.app.ui.recommend;
|
|
import android.content.Intent;
|
import android.graphics.drawable.Drawable;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.provider.Settings;
|
import androidx.annotation.Nullable;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.webkit.JavascriptInterface;
|
import android.webkit.WebChromeClient;
|
import android.webkit.WebResourceRequest;
|
import android.webkit.WebSettings;
|
import android.webkit.WebView;
|
import android.webkit.WebViewClient;
|
import android.widget.AdapterView;
|
import android.widget.FrameLayout;
|
import android.widget.LinearLayout;
|
import android.widget.ListView;
|
import android.widget.ProgressBar;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.alibaba.baichuan.android.trade.model.AlibcShowParams;
|
import com.alibaba.baichuan.android.trade.model.OpenType;
|
import com.alibaba.fastjson.JSON;
|
import com.google.gson.Gson;
|
import com.tejia.lijin.app.util.Constant;
|
import com.umeng.analytics.MobclickAgent;
|
import com.wpc.library.DeviceUuidFactory;
|
import com.wpc.library.util.GetManifestDataUtil;
|
import com.wpc.library.util.MobileUtil;
|
import com.wpc.library.util.NetUtils;
|
import com.wpc.library.util.common.PackageUtils2;
|
import com.wpc.library.util.common.StringUtils;
|
import com.wpc.library.util.security.MD5Utils;
|
import com.tejia.lijin.app.BuXinConstant;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ui.BaseActivity;
|
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
|
import com.tejia.lijin.app.util.JumpActivityUtil;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
|
import org.json.JSONArray;
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 9.9/19.9/29.9/49.9精选包邮
|
*/
|
public class ChoicenessFreightFreeActivity extends BaseActivity implements View.OnClickListener {
|
private TextView tv_top_bar_left;
|
private TextView tv_top_bar_middle;
|
private WebView webView;
|
private ProgressBar choicenessfreightfree_ProgressBar;
|
private FrameLayout choicenessfreightfree_linear;//弹窗布局
|
private FrameLayout choicenessfreightfree_button;//半透明背景
|
private ListView choicenessfreightfree_listview;//listview
|
|
private LinearLayout ll_no_net, ll_recommend_content, ll_no_data, ll_request_failture;
|
|
private boolean sign = false;//标记 标题右边图片
|
private JSONArray mJsonArray;//传过来的 参数的值为json字符串:
|
private ArrayList<HashMap<String, String>> mList = new ArrayList<>();
|
private ChoicenessFreightFreeAdapter dapter;
|
ShapeLoadingDialog pd = null;
|
|
@Override
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_choicenessfreightfree);
|
// TopStatusSettings.setStatusViewAndDeepColor(this);//设置状态栏
|
inint();
|
setListeners();
|
setWebView();
|
setProgressBar();
|
|
titlesign(sign);
|
String Data = getIntent().getStringExtra("data");
|
try {
|
// mJsonArray = new JSONArray(" [{\n" +
|
// " \"name\": \"9块9\",\n" +
|
// " \"url\": \"https://blog.csdn.net\"\n" +
|
// " },\n" +
|
// " {\n" +
|
// " \"name\": \"19块9\",\n" +
|
// " \"url\": \"https://uniapp.dcloud.io\"\n" +
|
// " }, {\n" +
|
// " \"name\": \"29块9\",\n" +
|
// " \"url\": \"http://elife.bm001.com/esj\"\n" +
|
// " }, {\n" +
|
// " \"name\": \"49块9\",\n" +
|
// " \"url\": \"https://baike.so.com/doc/663437-702310.html\"\n" +
|
// " }\n" +
|
// "]");
|
mJsonArray = new JSONArray(Data);
|
setJsonArray(mJsonArray != null ? mJsonArray : null);
|
} catch (JSONException e) {
|
e.printStackTrace();
|
mJsonArray = null;
|
}
|
if (pd == null) {
|
pd = new ShapeLoadingDialog.Builder(this).build();
|
}
|
//设置状态栏
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
Window window = getWindow();
|
//设置状态栏颜色为白色
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
window.setStatusBarColor(getResources().getColor(R.color.white));
|
}
|
//设置状态栏文字颜色及图标为深色
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
}
|
}
|
|
private void setJsonArray(JSONArray mJsonArray) throws JSONException {
|
if (mJsonArray != null) {
|
for (int i = 0; i < mJsonArray.length(); i++) {
|
JSONObject obj = (JSONObject) mJsonArray.get(i);
|
HashMap<String, String> map = new HashMap<>();
|
map.put("name", obj.optString("name"));
|
map.put("url", obj.optString("url"));
|
if (i == 0) {
|
choicenessfreightfree_ProgressBar.setVisibility(View.VISIBLE);
|
tv_top_bar_middle.setText(obj.optString("name"));
|
webView.loadUrl(obj.optString("url"));
|
map.put("boolean", "true");
|
} else {
|
map.put("boolean", "false");
|
}
|
mList.add(map);
|
}
|
|
dapter = new ChoicenessFreightFreeAdapter(getApplication(), mList);
|
choicenessfreightfree_listview.setAdapter(dapter);
|
}
|
|
choicenessfreightfree_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
@Override
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
mList.get(position).put("boolean", "true");
|
for (int i = 0; i < mList.size(); i++) {
|
if (i != position) {
|
mList.get(i).put("boolean", "false");
|
}
|
}
|
dapter.notifyDataSetChanged();
|
choicenessfreightfree_ProgressBar.setVisibility(View.VISIBLE);
|
tv_top_bar_middle.setText(mList.get(position).get("name"));
|
webView.loadUrl(mList.get(position).get("url") + "");
|
sign = false;
|
titlesign(sign);
|
choicenessfreightfree_linear.setVisibility(View.GONE);
|
}
|
});
|
}
|
|
private void setProgressBar() {
|
choicenessfreightfree_ProgressBar.setMax(100);
|
choicenessfreightfree_ProgressBar.setProgressDrawable(this.getResources().getDrawable(R.drawable.color_progressbar));
|
}
|
|
private void setWebView() {
|
WebSettings webSettings = webView.getSettings();
|
webSettings.setJavaScriptEnabled(true);
|
webSettings.setDomStorageEnabled(true);
|
webSettings.setUseWideViewPort(true);
|
webSettings.setLoadWithOverviewMode(true);
|
webSettings.setTextZoom(100);
|
webView.setDrawingCacheEnabled(true);
|
webView.addJavascriptInterface(new JavaInterface(), "yestv");
|
webView.setWebChromeClient(new WebChromeClient() {
|
@Override
|
public void onReceivedTitle(WebView view, String title) {
|
// if (null != title && !StringUtils.isEmpty(title.trim())) {//设置网页标题 进标题栏
|
//// tv_top_bar_middle.setText(title);
|
// }
|
}
|
|
@Override
|
public void onProgressChanged(WebView webView, int i) {
|
if (i == 100) {
|
choicenessfreightfree_ProgressBar.setVisibility(View.GONE);
|
} else {
|
if (View.INVISIBLE == choicenessfreightfree_ProgressBar.getVisibility()) {
|
choicenessfreightfree_ProgressBar.setVisibility(View.VISIBLE);
|
}
|
choicenessfreightfree_ProgressBar.setProgress(i);
|
}
|
super.onProgressChanged(webView, i);
|
}
|
});
|
webView.setWebViewClient(new WebViewClient() {
|
@Override
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
//该方法在Build.VERSION_CODES.LOLLIPOP以前有效,从Build.VERSION_CODES.LOLLIPOP起,建议使用shouldOverrideUrlLoading(WebView, WebResourceRequest)} instead
|
//返回false,意味着请求过程里,不管有多少次的跳转请求(即新的请求地址),均交给webView自己处理,这也是此方法的默认处理
|
//返回true,说明你自己想根据url,做新的跳转,比如在判断url符合条件的情况下,我想让webView加载http://www.baidu.com
|
return false;
|
}
|
|
@Override
|
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
//返回false,意味着请求过程里,不管有多少次的跳转请求(即新的请求地址),均交给webView自己处理,这也是此方法的默认处理
|
//返回true,说明你自己想根据url,做新的跳转,比如在判断url符合条件的情况下,我想让webView加载http://www.baidu.com
|
return false;
|
}
|
|
@Override
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
super.onReceivedError(view, errorCode, description, failingUrl);
|
if (errorCode == -5 && description.equals("net::ERR_PROXY_CONNECTION_FAILED")) {//网络链接异常 有网络链接但获取不到数据
|
requestState(2);
|
}
|
}
|
});
|
}
|
|
|
private void inint() {
|
tv_top_bar_left = findViewById(R.id.tv_top_bar_left);
|
tv_top_bar_middle = findViewById(R.id.tv_top_bar_middle);
|
webView = findViewById(R.id.choicenessfreightfree_web);
|
choicenessfreightfree_listview = findViewById(R.id.choicenessfreightfree_listview);
|
choicenessfreightfree_ProgressBar = findViewById(R.id.choicenessfreightfree_ProgressBar);
|
choicenessfreightfree_linear = findViewById(R.id.choicenessfreightfree_linear);
|
choicenessfreightfree_button = findViewById(R.id.choicenessfreightfree_button);
|
|
ll_no_net = findViewById(R.id.ll_no_net);
|
ll_no_data = findViewById(R.id.ll_no_data);
|
ll_request_failture = findViewById(R.id.ll_request_failture);
|
|
|
choicenessfreightfree_linear.setVisibility(View.GONE);
|
choicenessfreightfree_button.setOnClickListener(this);
|
|
findViewById(R.id.tv_net_setting).setOnClickListener(this);
|
findViewById(R.id.tv_refresh).setOnClickListener(this);
|
}
|
|
/**
|
* 设置监听
|
*/
|
private void setListeners() {
|
tv_top_bar_middle.setOnClickListener(this);
|
tv_top_bar_left.setOnClickListener(this);
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left://返回
|
finish();
|
break;
|
case R.id.tv_top_bar_middle://点击标题 选择包邮种类
|
if (sign) {
|
sign = false;
|
choicenessfreightfree_linear.setVisibility(View.GONE);
|
} else {
|
sign = true;
|
choicenessfreightfree_linear.setVisibility(View.VISIBLE);
|
}
|
titlesign(sign);
|
break;
|
case R.id.choicenessfreightfree_button:
|
sign = false;
|
titlesign(sign);
|
choicenessfreightfree_linear.setVisibility(View.GONE);
|
break;
|
case R.id.tv_net_setting:
|
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
break;
|
case R.id.tv_refresh:
|
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
break;
|
default:
|
|
break;
|
}
|
}
|
|
/**
|
* 改变标题右边小箭头图标
|
*
|
* @param sign
|
*/
|
private void titlesign(boolean sign) {
|
Drawable drawable = getResources().getDrawable(sign ? R.drawable.sign_up : R.drawable.sign_below);//R.mipmap.work_shouqi_jiantou);
|
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
|
tv_top_bar_middle.setCompoundDrawables(null, null, drawable, null);
|
tv_top_bar_middle.setCompoundDrawablePadding(20);
|
}
|
|
/**
|
* 拦截返回 返回webview的上一级
|
*
|
* @param keyCode
|
* @param event
|
* @return
|
*/
|
@Override
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
|
if (webView.canGoBack()) {
|
webView.goBack(); // goBack()表示返回WebView的上一页面
|
return true;
|
} else {
|
finish();
|
}
|
}
|
return super.onKeyDown(keyCode, event);
|
}
|
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
if (NetUtils.getNetworkState(this).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
|
requestState(3);
|
Toast.makeText(this, "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
|
}
|
|
// else if (NetUtils.isNetConnected(this)) {
|
// requestState(2);
|
// Toast.makeText(this, "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
|
// }
|
}
|
|
/**
|
* 请求状态 0 数据正常展示;1 返回数据为空;2 网络请求失败;3 没有连接网络
|
*
|
* @param state
|
*/
|
private void requestState(int state) {
|
// ll_recommend_content.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
|
ll_no_data.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
|
ll_request_failture.setVisibility(state == 2 ? View.VISIBLE : View.GONE);
|
ll_no_net.setVisibility(state == 3 ? View.VISIBLE : View.GONE);
|
}
|
|
|
class JavaInterface {
|
|
@JavascriptInterface
|
public String getUid() {
|
return getSharedPreferences("user", MODE_PRIVATE).getString("uid", "0");
|
}
|
|
@JavascriptInterface
|
public void setTitle(final String title) {
|
// tv_top_bar_middle.setText(title);
|
tv_top_bar_middle.post(new Runnable() {
|
@Override
|
public void run() {
|
if (null != title && !StringUtils.isEmpty(title.trim())) {
|
// tv_top_bar_middle.setText(title);
|
}
|
}
|
});
|
}
|
|
@JavascriptInterface
|
public String getVersion() {
|
return PackageUtils2.getVersionCode(ChoicenessFreightFreeActivity.this) + "";
|
}
|
|
@JavascriptInterface
|
public void toast(String str) {
|
Toast.makeText(ChoicenessFreightFreeActivity.this, str, Toast.LENGTH_LONG).show();
|
}
|
|
@JavascriptInterface
|
public String getSign(String str) {
|
return MD5Utils.getMD532(str + "@?,223Hbb88lll");
|
}
|
|
|
@JavascriptInterface
|
public void jumpGoodsSplash(long id) {
|
Intent intent = new Intent(ChoicenessFreightFreeActivity.this, GoodsDetailActivity.class);
|
intent.putExtra("goodsId", id + "");
|
intent.putExtra("goodsType", Constant.GOODS_TYPE_TB);
|
startActivity(intent);
|
}
|
|
|
@JavascriptInterface
|
public void jumpBaiChuan(String tbClientInfo, String url, String auctionId) {
|
AlibcShowParams alibcShowParams = new AlibcShowParams();
|
alibcShowParams.setOpenType(OpenType.Native);
|
JumpActivityUtil.jumpBaiChuan(ChoicenessFreightFreeActivity.this,
|
tbClientInfo, url, auctionId, alibcShowParams);
|
}
|
|
@JavascriptInterface
|
public void jumpSearch(String key) {
|
Intent intent = new Intent(ChoicenessFreightFreeActivity.this, SearchActivity.class);
|
intent.putExtra("key", key);
|
startActivity(intent);
|
}
|
|
@JavascriptInterface
|
public void jumpGoodsDetail(long id) {
|
Intent intent = new Intent(ChoicenessFreightFreeActivity.this, GoodsDetailBrowerActivity.class);
|
intent.putExtra("id", id + "");
|
intent.putExtra("isTrolley", true);
|
startActivity(intent);
|
}
|
|
|
@JavascriptInterface
|
public void jumpPage(String pageClassName, String paramJson) {
|
Intent intent = null;
|
JSONObject param = null;
|
try {
|
if (StringUtils.isEmpty(paramJson)) {
|
param = null;
|
} else {
|
param = new JSONObject(paramJson);
|
}
|
if (StringUtils.isEmpty(pageClassName)) {
|
return;
|
} else {
|
intent = new Intent(ChoicenessFreightFreeActivity.this, Class.forName(JumpActivityUtil.filterActivityName(pageClassName)));
|
}
|
} catch (JSONException e) {
|
param = null;
|
e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (null != param) {
|
@SuppressWarnings("unchecked")
|
Iterator<String> its = param.keys();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = param.optString(key);
|
intent.putExtra(key, value);
|
// Log.e("mResult", "key--" + key);
|
// Log.e("mResult", "value--" + value);
|
}
|
}
|
startActivity(intent);
|
}
|
|
@JavascriptInterface
|
public void jumpPageWithFinishCurrentPage(String pageClassName, String paramJson) {
|
Intent intent = null;
|
JSONObject param = null;
|
try {
|
if (StringUtils.isEmpty(paramJson)) {
|
param = null;
|
} else {
|
param = new JSONObject(paramJson);
|
}
|
if (StringUtils.isEmpty(pageClassName)) {
|
return;
|
} else {
|
intent = new Intent(ChoicenessFreightFreeActivity.this, Class.forName(JumpActivityUtil.filterActivityName(pageClassName)));
|
}
|
} catch (JSONException e) {
|
param = null;
|
e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (null != param) {
|
@SuppressWarnings("unchecked")
|
Iterator<String> its = param.keys();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = param.optString(key);
|
intent.putExtra(key, value);
|
}
|
}
|
startActivity(intent);
|
ChoicenessFreightFreeActivity.this.finish();
|
}
|
|
@JavascriptInterface
|
public void login() {
|
UserUtil.jumpLogin(ChoicenessFreightFreeActivity.this);
|
}
|
|
|
@JavascriptInterface
|
public String getRequestBaseParams(String json) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<>();
|
int version = PackageUtils2.getVersionCode(ChoicenessFreightFreeActivity.this);
|
long time = System.currentTimeMillis();
|
String deviceType = MobileUtil.getSystemModel();
|
if (!StringUtils.isEmpty(json)) {
|
JSONObject jsonObject = null;
|
try {
|
jsonObject = new JSONObject(json);
|
Iterator<String> iterator = jsonObject.keys();
|
while (iterator.hasNext()) {
|
String key = iterator.next();
|
params.put(key, jsonObject.optString(key));
|
}
|
} catch (JSONException e) {
|
|
}
|
}
|
params.put("packages", getPackageName());
|
params.put("Version", version + "");
|
params.put("appkey", BuXinConstant.TAO_BAO_KE_KEY);
|
params.put("platform", "android");
|
params.put("uid", getSharedPreferences("user", MODE_PRIVATE).getString("uid", ""));
|
params.put("apiversion", "1");
|
params.put("channel", GetManifestDataUtil.getAppMetaData(ChoicenessFreightFreeActivity.this, "UMENG_CHANNEL"));
|
String imei = MobileUtil.getIMEI(ChoicenessFreightFreeActivity.this);
|
if (!StringUtils.isEmpty(imei))
|
params.put("imei", imei);
|
params.put("osVersion", MobileUtil.getSystemVersion());
|
params.put("network", NetUtils.getNetworkState(ChoicenessFreightFreeActivity.this));
|
params.put("deviceType", StringUtils.isEmpty(deviceType) ? "" : deviceType);
|
params.put("time", time + "");
|
params.put("Device", new DeviceUuidFactory(ChoicenessFreightFreeActivity.this).getDeviceUuid() + "");
|
Iterator<String> its = params.keySet().iterator();
|
List<String> list = new ArrayList<>();
|
while (its.hasNext()) {
|
String key = its.next();
|
Object value = params.get(key);
|
list.add(key + "=" + value);
|
}
|
Collections.sort(list);
|
String sign = "";
|
for (String str : list) {
|
sign += str + "&";
|
}
|
params.put("sign", MD5Utils.getMD532(sign + "buXiNjie2017!"));
|
Gson gson = new Gson();
|
String str = gson.toJson(params);
|
// Log.e("mResult", str);
|
return str;
|
}
|
|
@JavascriptInterface
|
public void hideLoading() {
|
tv_top_bar_middle.post(new Runnable() {
|
@Override
|
public void run() {
|
if (pd != null && pd.isShowing())
|
pd.dismiss();
|
}
|
});
|
|
}
|
|
@JavascriptInterface
|
public void showLoading() {
|
tv_top_bar_middle.post(new Runnable() {
|
@Override
|
public void run() {
|
if (pd == null) {
|
pd = new ShapeLoadingDialog.Builder(ChoicenessFreightFreeActivity.this).build();
|
}
|
pd.show();
|
}
|
});
|
|
}
|
|
@JavascriptInterface
|
public void finishPage() {
|
tv_top_bar_middle.post(new Runnable() {
|
@Override
|
public void run() {
|
finish();
|
}
|
});
|
}
|
|
@JavascriptInterface
|
public void umEventCount(String eventId, String paramsJSON) {
|
Map map = JSON.parseObject(paramsJSON);
|
MobclickAgent.onEventObject(ChoicenessFreightFreeActivity.this, eventId, map);
|
}
|
|
@JavascriptInterface
|
public void umEventCompute(String eventId, String paramsJSON, int du) {
|
Map map = JSON.parseObject(paramsJSON);
|
MobclickAgent.onEventValue(ChoicenessFreightFreeActivity.this, eventId, map, du);
|
}
|
|
|
}
|
}
|