|
@@ -1,25 +1,42 @@
|
|
package com.topsoft.jianyu;
|
|
package com.topsoft.jianyu;
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+import android.app.Notification;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
+import android.database.Cursor;
|
|
|
|
+import android.database.sqlite.SQLiteDatabase;
|
|
|
|
+import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
|
|
+import android.os.Message;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
import android.view.KeyEvent;
|
|
import android.view.KeyEvent;
|
|
|
|
+import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
|
+import android.webkit.ValueCallback;
|
|
|
|
+import android.webkit.WebChromeClient;
|
|
import android.webkit.WebSettings;
|
|
import android.webkit.WebSettings;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebViewClient;
|
|
import android.webkit.WebViewClient;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
-import com.topsoft.jianyu.util.StatusBar;
|
|
|
|
|
|
+import com.topsoft.jianyu.SQLite.DBHelper;
|
|
|
|
+import com.topsoft.jianyu.appUpdate.UpdateVersionController;
|
|
|
|
+import com.topsoft.jianyu.util.AppUtil;
|
|
|
|
+import com.umeng.socialize.UMShareAPI;
|
|
|
|
+
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Timer;
|
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
|
|
+import cn.jpush.android.api.BasicPushNotificationBuilder;
|
|
import cn.jpush.android.api.JPushInterface;
|
|
import cn.jpush.android.api.JPushInterface;
|
|
|
|
|
|
|
|
|
|
@@ -27,30 +44,61 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
private WebView wv;
|
|
private WebView wv;
|
|
private final String LOG_TAG = "JC_WebView";
|
|
private final String LOG_TAG = "JC_WebView";
|
|
- private final String JianYun_App_Home_Url = "https://www.jianyu360.com/";
|
|
|
|
-
|
|
|
|
|
|
+ private Context ctx;
|
|
|
|
+ private String rgsid = "";
|
|
|
|
+ private Timer timer;
|
|
|
|
+ private String pushurl;
|
|
|
|
|
|
|
|
+ //qq分享需添加此项
|
|
|
|
+ @Override
|
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
+ UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_main);
|
|
setContentView(R.layout.activity_main);
|
|
- StatusBar.setAndroidNativeLightStatusBar(this,true);
|
|
|
|
- initWebview();
|
|
|
|
-
|
|
|
|
- final Context ctx = this;
|
|
|
|
- new Handler().postDelayed(new Runnable() {
|
|
|
|
- public void run() {
|
|
|
|
- JPushInterface.setDebugMode(true);
|
|
|
|
- JPushInterface.init(ctx);
|
|
|
|
- String rgsid = JPushInterface.getRegistrationID(ctx);
|
|
|
|
- Log.d(LOG_TAG, "rgsid=" + rgsid);
|
|
|
|
- String uid = JPushInterface.getUdid(ctx);
|
|
|
|
- Log.d(LOG_TAG, "UID=" + uid);
|
|
|
|
-
|
|
|
|
- Toast.makeText(ctx, "你的RID::"+rgsid+"极光推送时要用到,请绑定到剑鱼用户,每次启动更新", Toast.LENGTH_LONG).show();
|
|
|
|
|
|
+ AppUtil.setAndroidNativeLightStatusBar(this,true,true);
|
|
|
|
+ ctx = this;
|
|
|
|
+ //初始化WebView
|
|
|
|
+ pushurl=getIntent().getStringExtra("url");
|
|
|
|
+
|
|
|
|
+ //判断是否是点击推送打开的
|
|
|
|
+ if(pushurl==null||"".equals(pushurl)){
|
|
|
|
+ initWebview(AppUtil.AppUrl+"/jyapp/free/me");
|
|
|
|
+ //initWebview("http://192.168.100.68:8020/jyAppWeb/index.html");
|
|
|
|
+ }else{
|
|
|
|
+ initWebview(AppUtil.AppUrl+pushurl);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //初始化配置
|
|
|
|
+ initconfigure();
|
|
|
|
+
|
|
|
|
+ findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ setStyleBasic();
|
|
|
|
+ /*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");
|
|
|
|
+ while(cursor.moveToNext()){
|
|
|
|
+ System.out.print("id="+cursor.getInt(cursor.getColumnIndex("id")));
|
|
|
|
+ System.out.print(" title="+cursor.getString(cursor.getColumnIndex("title")));
|
|
|
|
+ System.out.print(" content="+cursor.getString(cursor.getColumnIndex("content")));
|
|
|
|
+ System.out.print(" link="+cursor.getString(cursor.getColumnIndex("link")));
|
|
|
|
+ System.out.print(" category="+cursor.getString(cursor.getColumnIndex("category")));
|
|
|
|
+ System.out.print(" readed="+cursor.getInt(cursor.getColumnIndex("readed")));
|
|
|
|
+ System.out.print(" comeintime="+cursor.getInt(cursor.getColumnIndex("comeintime")));
|
|
|
|
+ System.out.print(" openid="+cursor.getString(cursor.getColumnIndex("openid")));
|
|
|
|
+ System.out.print(" descript="+cursor.getString(cursor.getColumnIndex("descript")));
|
|
|
|
+ System.out.println(" extend="+cursor.getString(cursor.getColumnIndex("extend")));
|
|
|
|
+ }
|
|
|
|
+ System.out.println("查询完成"+cursor.getCount()+"条");
|
|
|
|
+ db.close();*/
|
|
}
|
|
}
|
|
- }, 2000);
|
|
|
|
|
|
+ });
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,44 +112,108 @@ public class MainActivity extends AppCompatActivity {
|
|
return super.onKeyDown(keyCode, event);
|
|
return super.onKeyDown(keyCode, event);
|
|
}
|
|
}
|
|
|
|
|
|
- protected void initWebview() {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected void onDestroy() {
|
|
|
|
+ if (wv != null) {
|
|
|
|
+ wv.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
|
|
|
|
+ wv.clearHistory();
|
|
|
|
+ ((ViewGroup) wv.getParent()).removeView(wv);
|
|
|
|
+ wv.destroy();
|
|
|
|
+ wv = null;
|
|
|
|
+ }
|
|
|
|
+ super.onDestroy();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //初始化Webview
|
|
|
|
+ protected void initWebview(String url) {
|
|
LinearLayout mLayout = (LinearLayout) findViewById(R.id.webview_layout);
|
|
LinearLayout mLayout = (LinearLayout) findViewById(R.id.webview_layout);
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
wv = new WebView(this);
|
|
wv = new WebView(this);
|
|
wv.setLayoutParams(params);
|
|
wv.setLayoutParams(params);
|
|
mLayout.addView(wv);
|
|
mLayout.addView(wv);
|
|
- //
|
|
|
|
wv.setWebViewClient(new WebViewClient() {
|
|
wv.setWebViewClient(new WebViewClient() {
|
|
|
|
+ });
|
|
|
|
+ wv.setWebChromeClient(new WebChromeClient() {
|
|
@Override
|
|
@Override
|
|
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
|
- view.loadUrl(url);
|
|
|
|
|
|
+ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
|
|
|
|
+ super.onShowFileChooser(webView, filePathCallback, fileChooserParams);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgressChanged(WebView view, int newProgress) {
|
|
|
|
+ //通过点击提示进入改页面 返回键需要改变
|
|
|
|
+ if(newProgress==100&&!(pushurl==null||"".equals(pushurl))){
|
|
|
|
+ wv.loadUrl("javascript:afterOpenPushMessage()");
|
|
|
|
+ pushurl=null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
+
|
|
WebSettings webSettings = wv.getSettings();
|
|
WebSettings webSettings = wv.getSettings();
|
|
- webSettings.setJavaScriptEnabled(true);//设置支持javascript
|
|
|
|
- webSettings.setUseWideViewPort(true);
|
|
|
|
|
|
+ //设置支持javascript
|
|
|
|
+ webSettings.setJavaScriptEnabled(true);
|
|
|
|
+ webSettings.setDomStorageEnabled(true);
|
|
|
|
+ //允许JS弹窗
|
|
|
|
+ webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
|
+ webSettings.setSupportMultipleWindows(true);
|
|
|
|
|
|
- webSettings.setLoadWithOverviewMode(true);
|
|
|
|
- webSettings.setLoadsImagesAutomatically(true);
|
|
|
|
- webSettings.setAllowFileAccess(true); //可以访问文件
|
|
|
|
|
|
+ webSettings.setUseWideViewPort(true);//屏幕自适应
|
|
|
|
+ webSettings.setLoadWithOverviewMode(true);// 缩放至屏幕的大小
|
|
|
|
+ webSettings.setLoadsImagesAutomatically(true);//是否加载图片
|
|
|
|
+ //可以访问文件
|
|
|
|
+ webSettings.setAllowFileAccess(true);
|
|
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
|
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
map.put("User-Agent", "Android");
|
|
map.put("User-Agent", "Android");
|
|
- wv.loadUrl(JianYun_App_Home_Url, map);
|
|
|
|
- wv.addJavascriptInterface(new JavaObject(this, wv), "myObj");
|
|
|
|
|
|
+ wv.loadUrl(url, map);
|
|
|
|
+ wv.addJavascriptInterface(new JyObj(this, wv), "JyObj");
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- protected void onDestroy() {
|
|
|
|
- if (wv != null) {
|
|
|
|
- wv.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
|
|
|
|
- wv.clearHistory();
|
|
|
|
- ((ViewGroup) wv.getParent()).removeView(wv);
|
|
|
|
- wv.destroy();
|
|
|
|
- wv = null;
|
|
|
|
- }
|
|
|
|
- super.onDestroy();
|
|
|
|
|
|
+ //初始化其他配置设置
|
|
|
|
+ private void initconfigure(){
|
|
|
|
+ UMShareAPI.get(this);
|
|
|
|
+ mHandler.obtainMessage(1).sendToTarget();
|
|
|
|
+ mHandler.obtainMessage(2).sendToTarget();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ private void setStyleBasic() {
|
|
|
|
+ BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(MainActivity.this);
|
|
|
|
+ builder.statusBarDrawable = R.mipmap.ic_launcher;
|
|
|
|
+ builder.notificationFlags = Notification.FLAG_AUTO_CANCEL; //设置为点击后自动消失
|
|
|
|
+ builder.notificationDefaults = Notification.DEFAULT_SOUND; //设置为铃声( Notification.DEFAULT_SOUND)或者震动( Notification.DEFAULT_VIBRATE)
|
|
|
|
+ JPushInterface.setPushNotificationBuilder(1, builder);
|
|
}
|
|
}
|
|
|
|
+ private Handler mHandler = new Handler() {
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
+ switch (msg.what) {
|
|
|
|
+ case 1:
|
|
|
|
+ //初始化极光推送
|
|
|
|
+ JPushInterface.init(ctx);
|
|
|
|
+ //获取rgsid,第一次安装app,初始化时,不能及时获取到,定时获取
|
|
|
|
+ timer= new Timer();
|
|
|
|
+ timer.schedule(new TimerTask() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ rgsid=JPushInterface.getRegistrationID(getApplicationContext());
|
|
|
|
+ Log.d(LOG_TAG, "------rgsid=");
|
|
|
|
+ if(!"".equals(rgsid)){
|
|
|
|
+ Log.d(LOG_TAG, "最终------rgsid=" + rgsid);
|
|
|
|
+ AppUtil.JPUSH_CLIENT_RGSID=rgsid;
|
|
|
|
+ timer.cancel();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }, 0, 500);
|
|
|
|
+
|
|
|
|
+ //样式
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ //监测更新
|
|
|
|
+ UpdateVersionController.getInstance(MainActivity.this).appUpdateCheck();
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
}
|
|
}
|