master
lijie 2023-08-04 15:29:51 +08:00
parent 08d7801637
commit 7c136a4db2
31 changed files with 345 additions and 566 deletions

View File

@ -1,92 +1,110 @@
package com.cmx.hydrology.activity;
package com.cmx.hydrology.activity
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import com.cmx.hydrology.databinding.ActivityLoginBinding
import com.cmx.hydrology.model.LoginBean
import com.cmx.hydrology.model.LoginRes
import com.cmx.hydrology.retrofit.RetrofitAPIManager
import com.cmx.hydrology.utils.MyUtils
import com.cmx.hydrology.utils.SpUtils
import es.dmoral.toasty.Toasty
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import androidx.annotation.RequiresApi;
class LoginActivity : BaseActivity() {
private var binding: ActivityLoginBinding? = null
private val REQUIRED_PERMISSION_LIST = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
)
private val REQUEST_PERMISSION_CODE = 99
private var allPermission = true
import com.cmx.hydrology.databinding.ActivityLoginBinding;
import com.cmx.hydrology.model.LoginBean;
import com.cmx.hydrology.model.LoginRes;
import com.cmx.hydrology.retrofit.RetrofitAPIManager;
import com.cmx.hydrology.utils.MyUtils;
import com.cmx.hydrology.utils.SpUtils;
import es.dmoral.toasty.Toasty;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class LoginActivity extends BaseActivity {
private ActivityLoginBinding binding;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityLoginBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
MyUtils.setFullscreen(this, true, true);
binding.btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
// if (TextUtils.isEmpty(binding.edtUsername.getText().toString().trim())) {
// Toasty.info(LoginActivity.this, "请输入用户名").show();
// return;
// }
// if (TextUtils.isEmpty(binding.edtPassword.getText().toString().trim())) {
// Toasty.info(LoginActivity.this, "请输入密码").show();
// return;
// }
// toLogin();
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding!!.root)
MyUtils.setFullscreen(this, true, true)
checkAllPermission()
binding!!.btnLogin.setOnClickListener(View.OnClickListener {
if (TextUtils.isEmpty(binding!!.edtUsername.text.toString().trim { it <= ' ' })) {
Toasty.info(this@LoginActivity, "请输入用户名").show()
return@OnClickListener
}
});
if (TextUtils.isEmpty(binding!!.edtPassword.text.toString().trim { it <= ' ' })) {
Toasty.info(this@LoginActivity, "请输入密码").show()
return@OnClickListener
}
toLogin()
})
}
/**
* 登录
*/
private void toLogin() {
showDialog();
LoginBean LoginBean = new LoginBean();
LoginBean.setUsername(binding.edtUsername.getText().toString().trim());
LoginBean.setPassword(binding.edtPassword.getText().toString().trim());
Call<LoginRes> call = RetrofitAPIManager.provideClientApi().login(LoginBean);
call.enqueue(new Callback<LoginRes>() {
@Override
public void onResponse(Call<LoginRes> call, Response<LoginRes> response) {
disDialog();
if (response.isSuccessful() && response.body().getCode() == 0) {
SpUtils.putString(LoginActivity.this, "token", response.body().getAccess_token());
SpUtils.putString(LoginActivity.this, "admin", response.body().getIs_admin());
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
private fun toLogin() {
showDialog()
val LoginBean = LoginBean()
LoginBean.username = binding!!.edtUsername.text.toString().trim { it <= ' ' }
LoginBean.password = binding!!.edtPassword.text.toString().trim { it <= ' ' }
val call = RetrofitAPIManager.provideClientApi().login(LoginBean)
call.enqueue(object : Callback<LoginRes> {
override fun onResponse(call: Call<LoginRes>, response: Response<LoginRes>) {
disDialog()
if (response.isSuccessful && response.body()!!.code == 0) {
SpUtils.putString(this@LoginActivity, "token", response.body()!!.access_token)
val intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
finish()
} else {
Toasty.error(LoginActivity.this, response.body().getMessage()).show();
Toasty.error(this@LoginActivity, response.body()!!.message).show()
}
}
@Override
public void onFailure(Call<LoginRes> call, Throwable t) {
disDialog();
Toasty.info(LoginActivity.this, "登录失败").show();
override fun onFailure(call: Call<LoginRes>, t: Throwable) {
disDialog()
Toasty.info(this@LoginActivity, "登录失败").show()
}
});
})
}
@Override
public void onDestroy() {
super.onDestroy();
binding = null;
public override fun onDestroy() {
super.onDestroy()
binding = null
}
/**
* 权限检查
*/
private fun checkAllPermission() {
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSION_LIST, REQUEST_PERMISSION_CODE)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String?>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_PERMISSION_CODE) {
for (i in grantResults.indices.reversed()) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
allPermission = false
}
}
if (!allPermission) {
Toasty.info(this, "权限已拒绝,请手动开启!").show()
finish()
}
}
}
}

View File

@ -1,114 +0,0 @@
package com.cmx.hydrology.activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.RequiresApi;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;
import com.cmx.hydrology.R;
import com.cmx.hydrology.constant.Events;
import com.cmx.hydrology.databinding.ActivityMainBinding;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.lsxiao.apollo.core.Apollo;
import com.lsxiao.apollo.core.annotations.Receive;
public class MainActivity extends BaseActivity {
private ActivityMainBinding binding;
private BottomNavigationView navView;
private NavController navController;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
navView = findViewById(R.id.nav_view);
navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
NavigationUI.setupWithNavController(binding.navView, navController);
}
/**
* tabbar
*/
@Receive(Events.JS_OPEN_TABBAR_SHOW)
public void showTab() {
binding.navView.setVisibility(View.VISIBLE);
}
/**
* tabbar
*/
@Receive(Events.JS_OPEN_TABBAR_HIDE)
public void hideTab() {
binding.navView.setVisibility(View.GONE);
}
/**
* web
*/
@Receive(Events.JS_OPEN_OPEN_WEB)
public void openWeb(String url) {
Intent intent = new Intent(this, WebActivity.class);
intent.putExtra("url", url);
startActivity(intent);
}
/**
* tab
*/
@Receive(Events.JS_OPEN_TAB)
public void ckTab(String mode) {
Apollo.emit(Events.JS_OPEN_CLOSE_WEB);
switch (mode) {
case "1":
Menu menu = navView.getMenu();
MenuItem menuItem = menu.getItem(0); // 将index替换为您想要点击的项目的索引
menuItem.setChecked(true);
navController.navigate(R.id.navigation_home);
break;
case "2":
Menu menu2 = navView.getMenu();
MenuItem menuItem2 = menu2.getItem(1); // 将index替换为您想要点击的项目的索引
menuItem2.setChecked(true);
navController.navigate(R.id.navigation_msg);
break;
case "3":
Menu menu3 = navView.getMenu();
MenuItem menuItem3 = menu3.getItem(2); // 将index替换为您想要点击的项目的索引
menuItem3.setChecked(true);
navController.navigate(R.id.navigation_map);
break;
case "4":
Menu menu4 = navView.getMenu();
MenuItem menuItem4 = menu4.getItem(3); // 将index替换为您想要点击的项目的索引
menuItem4.setChecked(true);
navController.navigate(R.id.navigation_my);
break;
}
}
/**
* 退
*/
@Receive(Events.JS_OPEN_LOGOUT)
public void exit() {
Apollo.emit(Events.JS_OPEN_CLOSE_WEB);
finish();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
}

View File

@ -0,0 +1,105 @@
package com.cmx.hydrology.activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.annotation.RequiresApi
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import com.cmx.hydrology.R
import com.cmx.hydrology.constant.Events
import com.cmx.hydrology.databinding.ActivityMainBinding
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.lsxiao.apollo.core.Apollo
import com.lsxiao.apollo.core.annotations.Receive
import kotlinx.android.synthetic.main.activity_main.nav_view
class MainActivity : BaseActivity() {
private var navController: NavController? = null
@RequiresApi(api = Build.VERSION_CODES.M)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main)
NavigationUI.setupWithNavController(nav_view, navController!!)
nav_view.itemIconTintList = null
}
/**
* 显示tabbar
*/
@Receive(Events.JS_OPEN_TABBAR_SHOW)
fun showTab() {
nav_view.visibility = View.VISIBLE
}
/**
* 隐藏tabbar
*/
@Receive(Events.JS_OPEN_TABBAR_HIDE)
fun hideTab() {
nav_view.visibility = View.GONE
}
/**
* 打开新的web
*/
@Receive(Events.JS_OPEN_OPEN_WEB)
fun openWeb(url: String?) {
val intent = Intent(this, WebActivity::class.java)
intent.putExtra("url", url)
startActivity(intent)
}
/**
* 选择tab
*/
@Receive(Events.JS_OPEN_TAB)
fun ckTab(mode: String?) {
Apollo.emit(Events.JS_OPEN_CLOSE_WEB)
when (mode) {
"1" -> {
val menu = nav_view!!.menu
val menuItem = menu.getItem(0) // 将index替换为您想要点击的项目的索引
menuItem.isChecked = true
navController!!.navigate(R.id.navigation_home)
}
"2" -> {
val menu2 = nav_view!!.menu
val menuItem2 = menu2.getItem(1) // 将index替换为您想要点击的项目的索引
menuItem2.isChecked = true
navController!!.navigate(R.id.navigation_msg)
}
"3" -> {
val menu3 = nav_view!!.menu
val menuItem3 = menu3.getItem(2) // 将index替换为您想要点击的项目的索引
menuItem3.isChecked = true
navController!!.navigate(R.id.navigation_map)
}
"4" -> {
val menu4 = nav_view!!.menu
val menuItem4 = menu4.getItem(3) // 将index替换为您想要点击的项目的索引
menuItem4.isChecked = true
navController!!.navigate(R.id.navigation_my)
}
}
}
/**
* 退出登录
*/
@Receive(Events.JS_OPEN_LOGOUT)
fun exit() {
Apollo.emit(Events.JS_OPEN_CLOSE_WEB)
finish()
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
}
}

View File

@ -6,8 +6,13 @@ package com.cmx.hydrology.constant
*/
interface Events {
companion object {
const val WEB_SERVER_URL = "http://8.222.137.126:80"
const val SERVER_URL = "http://192.168.110.174:8000"
const val WEB_SERVER_URL = "https://cmx.bskies.cc:8000"
const val SERVER_URL = "http://106.54.217.74:6622"
const val WEB_HOME_URL = "$WEB_SERVER_URL/cmx-hydrology-h5/#/home"
const val WEB_MSG_URL = WEB_SERVER_URL + ""
const val WEB_MAP_URL = "$WEB_SERVER_URL/cmx-hydrology-h5/#/map"
const val WEB_MY_URL = WEB_SERVER_URL + ""
/**
* tabbar显示

View File

@ -8,14 +8,12 @@ public class LoginRes {
* code : 0
* message :
* access_token : 1914936f8c87fddd11836ebebb65317bb7f57506
* is_admin : 1
*/
private int code;
private String message;
private String access_token;
private String is_admin;
public int getCode() {
return code;
@ -41,11 +39,4 @@ public class LoginRes {
this.access_token = access_token;
}
public String getIs_admin() {
return is_admin;
}
public void setIs_admin(String is_admin) {
this.is_admin = is_admin;
}
}

View File

@ -0,0 +1,92 @@
package com.cmx.hydrology.ui
import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.fragment.app.Fragment
import com.cmx.hydrology.utils.AndroidtoJs
import com.cmx.hydrology.utils.MyUtils
import com.cmx.hydrology.view.BaseLoadingDialog
import com.lsxiao.apollo.core.Apollo
import com.lsxiao.apollo.core.contract.ApolloBinder
open class BaseFragment : Fragment() {
var mBaseLoadingDialog: BaseLoadingDialog? = null
var mApolloBinder: ApolloBinder? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(null, container, false)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBaseLoadingDialog = BaseLoadingDialog(activity)
MyUtils.setFullscreen(requireActivity(), false, false)
MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true)
mApolloBinder = Apollo.bind(this)
}
/**
* 相关属性设置
*/
fun setWebView(webView: WebView) {
val webSettings = webView!!.settings
webSettings.javaScriptEnabled = true
webSettings.cacheMode = WebSettings.LOAD_NO_CACHE
webSettings.domStorageEnabled = true
webSettings.allowFileAccess = true //文件访问
webSettings.allowFileAccessFromFileURLs = true
webView!!.addJavascriptInterface(AndroidtoJs(), "AndroidtoJs")
webView!!.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
showDialog()
}
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
view.loadUrl(url)
return true
}
override fun onPageFinished(view: WebView, url: String) {
disDialog()
}
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
disDialog()
}
}
}
override fun onDestroyView() {
super.onDestroyView()
if (mApolloBinder != null) {
mApolloBinder!!.unbind()
}
}
fun showDialog() {
mBaseLoadingDialog = BaseLoadingDialog(activity)
if (!mBaseLoadingDialog!!.isShowing) {
mBaseLoadingDialog!!.show()
}
}
fun disDialog() {
if (mBaseLoadingDialog!!.isShowing) {
mBaseLoadingDialog!!.dismiss()
}
}
}

View File

@ -1,6 +1,9 @@
package com.cmx.hydrology.ui;
import static com.cmx.hydrology.constant.Events.WEB_HOME_URL;
import static com.cmx.hydrology.constant.Events.WEB_SERVER_URL;
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
@ -35,12 +38,10 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class HomeFragment extends Fragment {
public class HomeFragment extends BaseFragment {
private FragmentHomeBinding binding;
private BaseLoadingDialog mBaseLoadingDialog;
private WebView mWebView;
private ApolloBinder mApolloBinder;
private ValueCallback<Uri[]> mUploadMessage;
private String mCameraPhotoPath = null;
private long size = 0;
@ -49,66 +50,19 @@ public class HomeFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentHomeBinding.inflate(inflater, container, false);
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
View root = binding.getRoot();
MyUtils.setFullscreen(requireActivity(), false, false);
MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true);
mWebView = binding.wvHome;
mApolloBinder = Apollo.bind(this);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccess(true);//文件访问
webSettings.setAllowFileAccessFromFileURLs(true);
mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs");
mWebView.loadUrl("https://cmx.bskies.cc:8000/cmx-hydrology-h5/#/home");
showDialog();
setWebView(mWebView);
mWebView.loadUrl(WEB_HOME_URL);
mWebView.setWebChromeClient(new PQChromeClient());
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使用WebView加载显示url
view.loadUrl(url);
//返回true
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
disDialog();
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
disDialog();
}
}
);
return root;
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
if (mApolloBinder != null) {
mApolloBinder.unbind();
}
}
public void showDialog() {
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
if (!mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.show();
}
}
public void disDialog() {
if (mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.dismiss();
}
}

View File

@ -1,6 +1,9 @@
package com.cmx.hydrology.ui;
import static com.cmx.hydrology.constant.Events.WEB_MAP_URL;
import static com.cmx.hydrology.constant.Events.WEB_SERVER_URL;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -21,49 +24,17 @@ import com.cmx.hydrology.view.BaseLoadingDialog;
import com.lsxiao.apollo.core.Apollo;
import com.lsxiao.apollo.core.contract.ApolloBinder;
public class MapFragment extends Fragment {
public class MapFragment extends BaseFragment {
private FragmentMapBinding binding;
private BaseLoadingDialog mBaseLoadingDialog;
private WebView mWebView;
private ApolloBinder mApolloBinder;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentMapBinding.inflate(inflater, container, false);
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
View root = binding.getRoot();
mApolloBinder = Apollo.bind(this);
MyUtils.setFullscreen(requireActivity(), false, false);
MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true);
mWebView = binding.wvMine;
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setDomStorageEnabled(true);
mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs");
// mWebView.loadUrl(SERVER_URL + "/nigeria/?lang=English#/my");
// showDialog();
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使用WebView加载显示url
view.loadUrl(url);
//返回true
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
disDialog();
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
disDialog();
}
}
);
setWebView(mWebView);
mWebView.loadUrl(WEB_MAP_URL);
return root;
}
@ -72,22 +43,6 @@ public class MapFragment extends Fragment {
public void onDestroyView() {
super.onDestroyView();
binding = null;
if (mApolloBinder != null) {
mApolloBinder.unbind();
}
}
public void showDialog() {
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
if (!mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.show();
}
}
public void disDialog() {
if (mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.dismiss();
}
}
}

View File

@ -1,6 +1,8 @@
package com.cmx.hydrology.ui;
import static com.cmx.hydrology.constant.Events.SERVER_URL;
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
@ -35,57 +37,18 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MsgFragment extends Fragment {
public class MsgFragment extends BaseFragment {
private FragmentMsgBinding binding;
private BaseLoadingDialog mBaseLoadingDialog;
private WebView mWebView;
private ApolloBinder mApolloBinder;
private ValueCallback<Uri[]> mUploadMessage;
private String mCameraPhotoPath = null;
private long size = 0;
private static final int INPUT_FILE_REQUEST_CODE = 1;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentMsgBinding.inflate(inflater, container, false);
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
View root = binding.getRoot();
MyUtils.setFullscreen(requireActivity(), false, false);
MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true);
mWebView = binding.wvLoan;
mApolloBinder = Apollo.bind(this);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccess(true);//文件访问
webSettings.setAllowFileAccessFromFileURLs(true);
mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs");
setWebView(mWebView);
// mWebView.loadUrl(SERVER_URL + "/nigeria/?lang=English#/loans");
// showDialog();
mWebView.setWebChromeClient(new PQChromeClient());
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使用WebView加载显示url
view.loadUrl(url);
//返回true
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
disDialog();
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
disDialog();
}
}
);
return root;
}
@ -94,139 +57,7 @@ public class MsgFragment extends Fragment {
public void onDestroyView() {
super.onDestroyView();
binding = null;
if (mApolloBinder != null) {
mApolloBinder.unbind();
}
}
public void showDialog() {
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
if (!mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.show();
}
}
public void disDialog() {
if (mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.dismiss();
}
}
public class PQChromeClient extends WebChromeClient {
// For Android 5.0+
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
// Double check that we don't have any existing callbacks
if (mUploadMessage != null) {
mUploadMessage.onReceiveValue(null);
}
mUploadMessage = filePath;
Log.e("FileCooserParams => ", filePath.toString());
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
// Error occurred while creating the File
Log.e("test", "Unable to create Image File", ex);
}
// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
} else {
takePictureIntent = null;
}
}
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
contentSelectionIntent.setType("image/*");
Intent[] intentArray;
if (takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else {
intentArray = new Intent[2];
}
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(Intent.createChooser(chooserIntent, "Select images"), 1);
return true;
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */);
return imageFile;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != INPUT_FILE_REQUEST_CODE || mUploadMessage == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
try {
String file_path = mCameraPhotoPath.replace("file:", "");
File file = new File(file_path);
size = file.length();
} catch (Exception e) {
Log.e("Error!", "Error while opening image file" + e.getLocalizedMessage());
}
if (data != null || mCameraPhotoPath != null) {
Integer count = 1;
ClipData images = null;
try {
images = data.getClipData();
} catch (Exception e) {
Log.e("Error!", e.getLocalizedMessage());
}
if (images == null && data != null && data.getDataString() != null) {
count = data.getDataString().length();
} else if (images != null) {
count = images.getItemCount();
}
Uri[] results = new Uri[count];
// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
if (size != 0) {
// If there is not data, then we may have taken a photo
if (mCameraPhotoPath != null) {
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
}
} else if (data.getClipData() == null) {
results = new Uri[]{Uri.parse(data.getDataString())};
} else {
for (int i = 0; i < images.getItemCount(); i++) {
results[i] = images.getItemAt(i).getUri();
}
}
}
mUploadMessage.onReceiveValue(results);
mUploadMessage = null;
}
}
}

View File

@ -21,49 +21,17 @@ import com.cmx.hydrology.view.BaseLoadingDialog;
import com.lsxiao.apollo.core.Apollo;
import com.lsxiao.apollo.core.contract.ApolloBinder;
public class MyFragment extends Fragment {
public class MyFragment extends BaseFragment {
private FragmentMyBinding binding;
private BaseLoadingDialog mBaseLoadingDialog;
private WebView mWebView;
private ApolloBinder mApolloBinder;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentMyBinding.inflate(inflater, container, false);
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
View root = binding.getRoot();
mApolloBinder = Apollo.bind(this);
MyUtils.setFullscreen(requireActivity(), false, false);
MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true);
mWebView = binding.wvMine;
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setDomStorageEnabled(true);
mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs");
setWebView(mWebView);
// mWebView.loadUrl(SERVER_URL + "/nigeria/?lang=English#/my");
// showDialog();
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使用WebView加载显示url
view.loadUrl(url);
//返回true
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
disDialog();
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
disDialog();
}
}
);
return root;
}
@ -72,22 +40,6 @@ public class MyFragment extends Fragment {
public void onDestroyView() {
super.onDestroyView();
binding = null;
if (mApolloBinder != null) {
mApolloBinder.unbind();
}
}
public void showDialog() {
mBaseLoadingDialog = new BaseLoadingDialog(getActivity());
if (!mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.show();
}
}
public void disDialog() {
if (mBaseLoadingDialog.isShowing()) {
mBaseLoadingDialog.dismiss();
}
}
}

View File

@ -20,17 +20,6 @@ public class AndroidtoJs {
return SpUtils.getString(MyApplication.getmInstance(), "token");
}
/**
*
*
* @return
*/
@JavascriptInterface
public String getUser() {
L.e("JS--", "getUser()");
return SpUtils.getString(MyApplication.getmInstance(), "admin");
}
@JavascriptInterface
public String getAppVersion() {

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
</vector>

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
</vector>

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/icon_home_on" android:state_checked="true" />
<item android:drawable="@mipmap/icon_home_off" android:state_checked="false" />
</selector>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/icon_map_on" android:state_checked="true" />
<item android:drawable="@mipmap/icon_map_off" android:state_checked="false" />
</selector>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/icon_msg_on" android:state_checked="true" />
<item android:drawable="@mipmap/icon_msg_off" android:state_checked="false" />
</selector>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/icon_my_on" android:state_checked="true" />
<item android:drawable="@mipmap/icon_my_off" android:state_checked="false" />
</selector>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/black" android:state_checked="false" />
<item android:color="#60AAFE" android:state_checked="true" />
</selector>

View File

@ -59,6 +59,7 @@
android:hint="请输入用户名"
android:paddingStart="10dip"
android:singleLine="true"
android:text="superuser"
android:textColorHint="#919191"
android:textSize="16sp" />
@ -76,6 +77,7 @@
android:inputType="textPassword"
android:paddingStart="10dip"
android:singleLine="true"
android:text="Cmx170904"
android:textColorHint="#919191"
android:textSize="16sp" />

View File

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="32dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
@ -13,6 +13,7 @@
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:itemTextColor="@drawable/sel_tab_col"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"

View File

@ -3,21 +3,21 @@
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:icon="@drawable/sel_home"
android:title="站点" />
<item
android:id="@+id/navigation_msg"
android:icon="@drawable/ic_dashboard_black_24dp"
android:icon="@drawable/sel_msg"
android:title="消息" />
<item
android:id="@+id/navigation_map"
android:icon="@drawable/ic_notifications_black_24dp"
android:icon="@drawable/sel_map"
android:title="地图" />
<item
android:id="@+id/navigation_my"
android:icon="@drawable/ic_notifications_black_24dp"
android:icon="@drawable/sel_my"
android:title="我的" />
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB