package com.tejia.lijin.app.ui.recommend;
|
|
import android.app.Notification;
|
import android.app.NotificationManager;
|
import android.content.Intent;
|
import android.graphics.Bitmap;
|
import android.graphics.PixelFormat;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Message;
|
import android.util.Base64;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.webkit.DownloadListener;
|
import android.webkit.WebChromeClient;
|
import android.webkit.WebSettings;
|
import android.webkit.WebView;
|
import android.webkit.WebViewClient;
|
import android.widget.FrameLayout;
|
import android.widget.ProgressBar;
|
import android.widget.RemoteViews;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.ali.auth.third.ui.context.CallbackContext;
|
import com.alibaba.baichuan.android.trade.AlibcTrade;
|
import com.alibaba.baichuan.android.trade.model.AlibcShowParams;
|
import com.alibaba.baichuan.android.trade.model.OpenType;
|
import com.alibaba.baichuan.android.trade.page.AlibcDetailPage;
|
import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams;
|
import com.tejia.lijin.app.util.JumpActivityUtil;
|
import com.umeng.analytics.MobclickAgent;
|
import com.tejia.lijin.app.BuXinConstant;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.callBack.MiDuoTradeCallback;
|
import com.tejia.lijin.app.entity.RecommendGoods;
|
import com.tejia.lijin.app.ui.BaseActivity;
|
import com.tejia.lijin.app.ui.category.CategoryActivity;
|
import com.tejia.lijin.app.util.TopStatusSettings;
|
import com.tejia.lijin.app.util.downutil.DownFiles;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import java.util.HashMap;
|
import java.util.Iterator;
|
|
/**
|
* 特卖
|
*/
|
public class SpecialBrowserActivity extends BaseActivity implements OnClickListener {
|
|
private TextView tv_top_bar_left;
|
private TextView tv_top_bar_left2;
|
private TextView tv_top_bar_middle;
|
private WebView webview;
|
private FrameLayout fl_webview;
|
ProgressBar progressBar;
|
|
String url;
|
RecommendGoods mInfo;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_goods_brower);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
mInfo = (RecommendGoods) getIntent().getSerializableExtra("info");
|
url = getIntent().getStringExtra("url");
|
|
findViewById(R.id.ll_bottom).setVisibility(View.GONE);
|
findViewById(R.id.tv_prombt).setVisibility(View.GONE);
|
findViewById(R.id.tv_share_make_money).setVisibility(View.GONE);
|
|
getWindow().setFormat(PixelFormat.TRANSLUCENT);
|
tv_top_bar_left = findViewById(R.id.tv_top_bar_left);
|
tv_top_bar_left2 = findViewById(R.id.tv_top_bar_left2);
|
tv_top_bar_left2.setVisibility(View.VISIBLE);
|
tv_top_bar_middle = findViewById(R.id.tv_top_bar_middle);
|
fl_webview = findViewById(R.id.fl_webview);
|
// tv_top_bar_left2.setText("关闭");
|
tv_top_bar_left.setOnClickListener(this);
|
tv_top_bar_left2.setOnClickListener(this);
|
|
webview = new WebView(SpecialBrowserActivity.this);
|
fl_webview.addView(webview, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
FrameLayout.LayoutParams.MATCH_PARENT));
|
WebSettings webSettings = webview.getSettings();
|
webSettings.setJavaScriptEnabled(true);
|
webSettings.setDomStorageEnabled(true);
|
webSettings.setTextZoom(100);
|
|
webview.setDrawingCacheEnabled(true);
|
webview.setDownloadListener(new MyWebViewDownLoadListener());
|
webview.setWebViewClient(new WebViewClient() {
|
@Override
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
if (url != null && url.startsWith("yestv://")) {
|
String murl = url.split("yestv://")[1];
|
String[] params = murl.split("#");
|
if (params[0].equalsIgnoreCase("getgoodsdetail")) {
|
// Intent intent = new Intent(SpecialBrowserActivity.this, GoodsDetailBrowerActivity.class);
|
Intent intent = new Intent(SpecialBrowserActivity.this, GoodsDetailActivity.class);
|
intent.putExtra("goodsId", params[1]);
|
intent.putExtra("url", params[2]);
|
intent.putExtra("title", params[3]);
|
startActivity(intent);
|
} else if (params[0].equalsIgnoreCase("jumppage")) {
|
Intent intent = null;
|
try {
|
Class<String> forName = (Class<String>) Class.forName(JumpActivityUtil.filterActivityName(params[1]));
|
intent = new Intent(SpecialBrowserActivity.this, forName);
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}
|
if (params.length > 2) {
|
String str = params[2];
|
JSONObject obj = null;
|
try {
|
obj = new JSONObject(str);
|
} catch (JSONException e) {
|
}
|
Iterator<String> its = obj.keys();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = obj.optString(key);
|
intent.putExtra(key, value);
|
}
|
}
|
startActivity(intent);
|
} else if (params[0].equalsIgnoreCase("cate")) {
|
Intent intent = new Intent(SpecialBrowserActivity.this, CategoryActivity.class);
|
intent.putExtra("cateId", params[1]);
|
|
String title = params[2];
|
byte[] raw = Base64.decode(title, Base64.DEFAULT);
|
try {
|
title = new String(raw);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
intent.putExtra("key", title);
|
intent.putExtra("catename", title);
|
startActivity(intent);
|
} else if (params[0].equalsIgnoreCase("goods")) {
|
AlibcShowParams alibcShowParams = new AlibcShowParams();
|
alibcShowParams.setOpenType(OpenType.Auto);
|
AlibcTaokeParams alibcTaokeParams = new AlibcTaokeParams("", "", "");
|
alibcTaokeParams.setPid(BuXinConstant.BAICHUAN_PID);
|
alibcTaokeParams.setAdzoneid(BuXinConstant.BAICHUAN_ADZONE_ID);
|
alibcTaokeParams.pid = BuXinConstant.BAICHUAN_PID;
|
alibcTaokeParams.adzoneid = BuXinConstant.BAICHUAN_ADZONE_ID;
|
alibcTaokeParams.extraParams = new HashMap<>();
|
alibcTaokeParams.extraParams.put("taokeAppkey", BuXinConstant.TAO_BAO_KE_KEY);
|
String mUrl = "";
|
AlibcDetailPage alibcBasePage = new AlibcDetailPage(mUrl);
|
// AlibcTrade.show(SpecialBrowserActivity.this, webview, new WebViewClient(), new WebChromeClient(), alibcBasePage,
|
// alibcShowParams, alibcTaokeParams, null, new MiDuoTradeCallback(mUrl));
|
AlibcTrade.openByBizCode(SpecialBrowserActivity.this, alibcBasePage, webview, new WebViewClient(), new WebChromeClient(), "special",
|
alibcShowParams, alibcTaokeParams, null, new MiDuoTradeCallback(""));
|
}
|
return true;
|
}
|
return super.shouldOverrideUrlLoading(view, url);
|
}
|
|
@Override
|
public void onPageFinished(WebView webView, String s) {
|
super.onPageFinished(webView, s);
|
}
|
|
@Override
|
public void onPageStarted(WebView webView, String s, Bitmap bitmap) {
|
super.onPageStarted(webView, s, bitmap);
|
}
|
});
|
progressBar = findViewById(R.id.myProgressBar);
|
progressBar.setMax(100);
|
progressBar.setProgressDrawable(this.getResources()
|
.getDrawable(R.drawable.color_progressbar));
|
// tv_top_bar_middle.setText(getIntent().getStringExtra("title"));
|
webview.setWebChromeClient(new WebChromeClient() {
|
|
@Override
|
public void onReceivedTitle(WebView view, String title) {
|
tv_top_bar_middle.setText(title);
|
}
|
|
@Override
|
public void onProgressChanged(WebView webView, int i) {
|
if (i == 100) {
|
progressBar.setVisibility(View.GONE);
|
} else {
|
if (View.INVISIBLE == progressBar.getVisibility()) {
|
progressBar.setVisibility(View.VISIBLE);
|
}
|
progressBar.setProgress(i);
|
}
|
super.onProgressChanged(webView, i);
|
}
|
});
|
webview.loadUrl(url);
|
findViewById(R.id.iv_top_bar_right1).setOnClickListener(this);
|
findViewById(R.id.iv_top_bar_right2).setOnClickListener(this);
|
// webview.loadUrl("http://192.168.1.122:8020/Test/css/test.html");
|
}
|
|
// 文件下载监听
|
private class MyWebViewDownLoadListener implements DownloadListener {
|
|
@Override
|
public void onDownloadStart(String url, String userAgent,
|
String contentDisposition, String mimetype, long contentLength) {
|
startDownLoadFile(url);
|
/*
|
* Uri uri = Uri.parse(url); Intent intent = new
|
* Intent(Intent.ACTION_VIEW, uri);
|
* startActivity(intent);
|
*/
|
}
|
}
|
|
private NotificationManager manager;
|
private Notification notif;
|
int j = -1;
|
|
private void startDownLoadFile(String url) {
|
|
new DownFiles(this, new DownFiles.IProgress() {
|
|
@Override
|
public void getProgress(int p) {
|
// stub
|
if (p == 100) {
|
handler.sendEmptyMessage(1);
|
} else {
|
if (manager == null || notif == null) {
|
Toast.makeText(SpecialBrowserActivity.this, "文件已经开始下载",
|
Toast.LENGTH_SHORT).show();
|
|
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
notif = new Notification();
|
notif.icon = R.drawable.ic_launcher;
|
notif.tickerText = "热门应用下载";
|
notif.contentView = new RemoteViews(getPackageName(),
|
R.layout.notify_item);
|
notif.contentView.setTextViewText(
|
R.id.content_view_text1, "热门应用下载");
|
}
|
|
Message msg = handler.obtainMessage();
|
if (j != p) {
|
msg.what = 0;
|
msg.arg1 = p;
|
handler.sendMessage(msg);
|
}
|
j = p;
|
}
|
}
|
|
}).execute(url);
|
|
}
|
|
@Override
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
CallbackContext.onActivityResult(requestCode, resultCode, data);
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
}
|
|
@Override
|
protected void onDestroy() {
|
webview.reload();
|
super.onDestroy();
|
|
}
|
|
private Handler handler = new Handler() {
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
switch (msg.what) {
|
case 0:
|
notif.contentView.setTextViewText(R.id.content_view_per,
|
msg.arg1 + "%");
|
manager.notify(0, notif);
|
break;
|
case 1:
|
notif.contentView
|
.setTextViewText(R.id.content_view_per, "下载完成");
|
manager.notify(0, notif);
|
j = 100;
|
manager.cancelAll();
|
break;
|
default:
|
break;
|
}
|
}
|
|
};
|
|
@Override
|
protected void onStop() {
|
super.onStop();
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left: {
|
if (!webview.canGoBack())
|
finish();
|
else {
|
webview.goBack();
|
}
|
}
|
break;
|
case R.id.tv_top_bar_left2: {
|
finish();
|
}
|
break;
|
case R.id.iv_top_bar_right1: {
|
webview.loadUrl(url);
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
|
class MyWebChromeClient extends WebChromeClient {
|
@Override
|
public void onReceivedTitle(WebView view, String title) {
|
// tv_top_bar_middle.setText(title);
|
}
|
|
@Override
|
public void onProgressChanged(WebView webView, int i) {
|
if (i == 100) {
|
progressBar.setVisibility(View.GONE);
|
} else {
|
if (View.INVISIBLE == progressBar.getVisibility()) {
|
progressBar.setVisibility(View.VISIBLE);
|
}
|
progressBar.setProgress(i);
|
}
|
super.onProgressChanged(webView, i);
|
}
|
}
|
|
@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);
|
}
|
|
// private UMShareListener shareListener = new UMShareListener() {
|
// @Override
|
// public void onStart(SHARE_MEDIA platform) {
|
// SocializeUtils.safeShowDialog(dialog);
|
// }
|
//
|
// @Override
|
// public void onResult(SHARE_MEDIA platform) {
|
// Toast.makeText(SpecialBrowserActivity.this, "成功了", Toast.LENGTH_LONG).show();
|
// SocializeUtils.safeCloseDialog(dialog);
|
// }
|
//
|
// @Override
|
// public void onError(SHARE_MEDIA platform, Throwable t) {
|
// SocializeUtils.safeCloseDialog(dialog);
|
// Toast.makeText(SpecialBrowserActivity.this, "失败" + t.getMessage(), Toast.LENGTH_LONG).show();
|
// }
|
//
|
// @Override
|
// public void onCancel(SHARE_MEDIA platform) {
|
// SocializeUtils.safeCloseDialog(dialog);
|
// Toast.makeText(SpecialBrowserActivity.this, "取消了", Toast.LENGTH_LONG).show();
|
//
|
// }
|
// };
|
|
}
|