|
@@ -1,7 +1,6 @@
|
|
|
package com.topsoft.jianyu;
|
|
|
|
|
|
|
|
|
-
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.SharedPreferences;
|
|
@@ -19,10 +18,10 @@ import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebSettings;
|
|
|
import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
|
-import android.widget.LinearLayout;
|
|
|
|
|
|
|
|
|
import com.topsoft.jianyu.appUpdate.UpdateVersionController;
|
|
|
+import com.topsoft.jianyu.listener.KeyBoardListener;
|
|
|
import com.topsoft.jianyu.util.AppUtil;
|
|
|
import com.umeng.socialize.UMShareAPI;
|
|
|
|
|
@@ -38,12 +37,12 @@ import cn.jpush.android.api.JPushInterface;
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
- private WebView wv;
|
|
|
- private final String LOG_TAG = "JC_WebView";
|
|
|
- private Context ctx;
|
|
|
- private String rgsid = "";
|
|
|
- private Timer timer;
|
|
|
- private String pushurl;
|
|
|
+ private static WebView wv;
|
|
|
+ private static final String LOG_TAG = "JC_WebView";
|
|
|
+ private static Context ctx;
|
|
|
+ private static String rgsid = "";
|
|
|
+ private static Timer timer;
|
|
|
+ private static String pushurl;
|
|
|
|
|
|
//qq分享需添加此项
|
|
|
@Override
|
|
@@ -56,22 +55,14 @@ public class MainActivity extends AppCompatActivity {
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
- AppUtil.setAndroidNativeLightStatusBar(this,true,true);
|
|
|
ctx = this;
|
|
|
//初始化WebView
|
|
|
- pushurl=getIntent().getStringExtra("url");
|
|
|
-
|
|
|
- //判断是否是点击推送打开的
|
|
|
- if(pushurl==null||"".equals(pushurl)){
|
|
|
- SharedPreferences sp = getSharedPreferences("jy", Context.MODE_PRIVATE);
|
|
|
- String token = sp.getString("token", "");
|
|
|
- if("".equals(token)){
|
|
|
- initWebview(AppUtil.AppUrl+"/jyapp/free/login");
|
|
|
- }else{
|
|
|
- initWebview(AppUtil.AppUrl+"/jyapp/free/login?sign="+token+"&url="+URLEncoder.encode("/jyapp/jylab/mainSearch"));
|
|
|
- }
|
|
|
+ SharedPreferences sp = getSharedPreferences("jy", Context.MODE_PRIVATE);
|
|
|
+ String token = sp.getString("token", "");
|
|
|
+ if("".equals(token)){
|
|
|
+ initWebview(AppUtil.AppUrl+"/jyapp/free/login");
|
|
|
}else{
|
|
|
- initWebview(AppUtil.AppUrl+pushurl);
|
|
|
+ initWebview(AppUtil.AppUrl+"/jyapp/free/login?sign="+token+"&url="+URLEncoder.encode("/jyapp/jylab/mainSearch"));
|
|
|
}
|
|
|
|
|
|
//初始化配置
|
|
@@ -81,10 +72,11 @@ public class MainActivity extends AppCompatActivity {
|
|
|
Boolean b=mPowerManager.isIgnoringBatteryOptimizations(ctx.getPackageName());
|
|
|
Toast.makeText(ctx,b+"加入程序白名单",Toast.LENGTH_SHORT).show();*/
|
|
|
|
|
|
- /*findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
|
|
|
+ /*
|
|
|
+ findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- //查询本地数据库所有信息
|
|
|
+ //查询本地数据库所有信息Z
|
|
|
DBHelper dbHelper = new DBHelper(ctx,"jy_db",null,1);
|
|
|
SQLiteDatabase db =dbHelper.getWritableDatabase();
|
|
|
Cursor cursor = db.query("jy_message", new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "", new String[]{}, null, null, "comeintime desc");
|
|
@@ -131,11 +123,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
//初始化Webview
|
|
|
protected void initWebview(String url) {
|
|
|
- LinearLayout mLayout = (LinearLayout) findViewById(R.id.webview_layout);
|
|
|
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
- wv = new WebView(this);
|
|
|
- wv.setLayoutParams(params);
|
|
|
- mLayout.addView(wv);
|
|
|
+ wv=findViewById(R.id.webView);
|
|
|
wv.setWebViewClient(new WebViewClient() {
|
|
|
});
|
|
|
wv.setWebChromeClient(new WebChromeClient() {
|
|
@@ -148,7 +136,13 @@ public class MainActivity extends AppCompatActivity {
|
|
|
public void onProgressChanged(WebView view, int newProgress) {
|
|
|
//通过点击提示进入改页面 返回键需要改变
|
|
|
if(newProgress==100&&!(pushurl==null||"".equals(pushurl))){
|
|
|
- wv.loadUrl("javascript:afterOpenPushMessage()");
|
|
|
+ wv.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ int result=wv.canGoBack()?1:0;
|
|
|
+ wv.loadUrl("javascript:afterOpenPushMessage("+result+")");
|
|
|
+ }
|
|
|
+ });
|
|
|
pushurl=null;
|
|
|
}
|
|
|
}
|
|
@@ -178,12 +172,14 @@ public class MainActivity extends AppCompatActivity {
|
|
|
//初始化其他配置设置
|
|
|
private void initconfigure(){
|
|
|
UMShareAPI.get(this);
|
|
|
- mHandler.obtainMessage(1).sendToTarget();
|
|
|
- mHandler.obtainMessage(2).sendToTarget();
|
|
|
+ AppUtil.setAndroidNativeLightStatusBar(this,true,true);//全屏显示
|
|
|
+ KeyBoardListener.getInstance(this).init(ctx);//键盘显示监听事件
|
|
|
+ mHandler.obtainMessage(1).sendToTarget();//初始化极光推送
|
|
|
+ mHandler.obtainMessage(2).sendToTarget();//检测更新
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Handler mHandler = new Handler() {
|
|
|
+ public static Handler mHandler = new Handler() {
|
|
|
public void handleMessage(Message msg) {
|
|
|
switch (msg.what) {
|
|
|
case 1:
|
|
@@ -194,8 +190,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
timer.schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- rgsid=JPushInterface.getRegistrationID(getApplicationContext());
|
|
|
- Log.d(LOG_TAG, "------rgsid=");
|
|
|
+ rgsid=JPushInterface.getRegistrationID(ctx);
|
|
|
if(!"".equals(rgsid)){
|
|
|
Log.d(LOG_TAG, "最终------rgsid=" + rgsid);
|
|
|
AppUtil.JPUSH_CLIENT_RGSID=rgsid;
|
|
@@ -203,15 +198,40 @@ public class MainActivity extends AppCompatActivity {
|
|
|
}
|
|
|
}
|
|
|
}, 0, 500);
|
|
|
-
|
|
|
- //样式
|
|
|
-
|
|
|
break;
|
|
|
case 2:
|
|
|
//监测更新
|
|
|
- UpdateVersionController.getInstance(MainActivity.this).appUpdateCheck();
|
|
|
+ UpdateVersionController.getInstance(ctx).appUpdateCheck();
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ //点击通知消息,更新页面url
|
|
|
+ Bundle bundle = msg.getData();
|
|
|
+ pushurl=bundle.getString("url", "");
|
|
|
+ if(!"".equals(pushurl)){
|
|
|
+ System.out.println("pushurl"+pushurl);
|
|
|
+ wv.loadUrl(AppUtil.AppUrl+pushurl);
|
|
|
+ }else{
|
|
|
+ SharedPreferences sp = ctx.getSharedPreferences("jy", Context.MODE_PRIVATE);
|
|
|
+ String token = sp.getString("token", "");
|
|
|
+ if("".equals(token)){
|
|
|
+ wv.loadUrl(AppUtil.AppUrl+"/jyapp/free/login");
|
|
|
+ }else{
|
|
|
+ wv.loadUrl(AppUtil.AppUrl+"/jyapp/free/login?sign="+token+"&url="+URLEncoder.encode("/jyapp/jylab/mainSearch"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Intent start = new Intent(ctx,MainActivity.class);
|
|
|
+ start.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
|
+ ctx.startActivity(start);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ //增加未读消息小红点提醒
|
|
|
+ wv.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ wv.loadUrl("javascript:afterReceiveNewMsg();");
|
|
|
+ }
|
|
|
+ });
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
};
|