Browse Source

开江镇村android电视机大屏

master
18200396342 2 years ago
parent
commit
f8520d61a0
  1. 3
      .idea/.gitignore
  2. 1
      .idea/.name
  3. 6
      .idea/compiler.xml
  4. 20
      .idea/gradle.xml
  5. 25
      .idea/jarRepositories.xml
  6. 9
      .idea/misc.xml
  7. 10
      .idea/runConfigurations.xml
  8. 6
      .idea/vcs.xml
  9. 2
      app/build.gradle
  10. 6
      app/src/main/AndroidManifest.xml
  11. 82
      app/src/main/java/com/xy/kaijiang/zhencunscreen/BaseActivity.java
  12. 2
      app/src/main/java/com/xy/kaijiang/zhencunscreen/Constans.java
  13. 193
      app/src/main/java/com/xy/kaijiang/zhencunscreen/MainActivity.java
  14. 256
      app/src/main/java/com/xy/kaijiang/zhencunscreen/MyApplication.java
  15. 336
      app/src/main/java/com/xy/kaijiang/zhencunscreen/MyFocusListener.java
  16. 160
      app/src/main/java/com/xy/kaijiang/zhencunscreen/WebActivity.java

3
.idea/.gitignore

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/.name

@ -0,0 +1 @@
ZhenCunScreenAndroid

6
.idea/compiler.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>

20
.idea/gradle.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

25
.idea/jarRepositories.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

9
.idea/misc.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

10
.idea/runConfigurations.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

6
.idea/vcs.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

2
app/build.gradle

@ -5,7 +5,7 @@ android {
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.hc.hyycck.bigdatadisplay"
applicationId "com.xy.kaijiang.zhencunscreen"
minSdkVersion 19
targetSdkVersion 31
versionCode 1

6
app/src/main/AndroidManifest.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hc.hyycck.bigdatadisplay">
package="com.xy.kaijiang.zhencunscreen">
<application
android:usesCleartextTraffic="true"
@ -10,11 +10,13 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:directBootAware="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".WebActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.hisense.action.THIRDSTART"/>
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

82
app/src/main/java/com/hc/hyycck/bigdatadisplay/BaseActivity.java → app/src/main/java/com/xy/kaijiang/zhencunscreen/BaseActivity.java

@ -1,41 +1,41 @@
package com.hc.hyycck.bigdatadisplay;
import android.os.Bundle;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import me.jessyan.autosize.internal.CustomAdapt;
public class BaseActivity extends AppCompatActivity implements CustomAdapt {
private static final String TAG = "BaseActivity====";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
public boolean isBaseOnWidth() {
return true;
}
@Override
public float getSizeInDp() {
return 1920;
}
}
package com.xy.kaijiang.zhencunscreen;
import android.os.Bundle;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import me.jessyan.autosize.internal.CustomAdapt;
public class BaseActivity extends AppCompatActivity implements CustomAdapt {
private static final String TAG = "BaseActivity====";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
public boolean isBaseOnWidth() {
return true;
}
@Override
public float getSizeInDp() {
return 1920;
}
}

2
app/src/main/java/com/hc/hyycck/bigdatadisplay/Constans.java → app/src/main/java/com/xy/kaijiang/zhencunscreen/Constans.java

@ -1,4 +1,4 @@
package com.hc.hyycck.bigdatadisplay;
package com.xy.kaijiang.zhencunscreen;
public class Constans {

193
app/src/main/java/com/hc/hyycck/bigdatadisplay/MainActivity.java → app/src/main/java/com/xy/kaijiang/zhencunscreen/MainActivity.java

@ -1,96 +1,97 @@
package com.hc.hyycck.bigdatadisplay;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends BaseActivity implements View.OnKeyListener {
private TextView zhenTv,cunTv;
private String zhenUrl,cunUrl;
private TextView hintTv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
zhenTv = findViewById(R.id.zhenTv);
cunTv = findViewById(R.id.cunTv);
hintTv = findViewById(R.id.hint);
zhenTv.setOnFocusChangeListener(new MyFocusListener(1.2f,zhenTv));
cunTv.setOnFocusChangeListener(new MyFocusListener(1.2f,cunTv));
zhenTv.setOnKeyListener(this);
cunTv.setOnKeyListener(this);
zhenTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, WebActivity.class);
intent.putExtra("url",zhenUrl);
startActivity(intent);
}
});
cunTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, WebActivity.class);
intent.putExtra("url",cunUrl);
startActivity(intent);
}
});
// zhenUrl = "http://60.255.58.172:9001/qfsw/#/";
// zhenUrl = "http://www.baidu.com";
zhenUrl = "http://192.168.10.21:8080/#/gaotanTown";
// zhenUrl = "http://192.168.1.2:8080/#/test";
// zhenUrl = "http://60.255.58.172:9001/swhtml/html/home.html";
// zhenUrl = "http://www.baidu.com";
cunUrl = "http://192.168.1.2:8080/#/taiyangVillage";
PackageManager packageManager = getPackageManager();
// getPackageName()是你当前类的包名,0代表是获取版本信息
PackageInfo packInfo = null;
int version = 0;
try {
packInfo = packageManager.getPackageInfo(getPackageName(),0);
version = Integer.valueOf(android.os.Build.VERSION.SDK);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
hintTv.setText(version+"");
}
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
int keyCode = keyEvent.getKeyCode();
if (view.getId() == R.id.zhenTv) {
if (keyCode == Constans.KEY_ENTER || keyCode == Constans.KEY_OK) { //确认键
Intent intent = new Intent(this, WebActivity.class);
intent.putExtra("url",zhenUrl);
startActivity(intent);
}
else if(view.getId() == R.id.cunTv){
if (keyCode == Constans.KEY_ENTER || keyCode == Constans.KEY_OK) { //确认键
Intent intent = new Intent(this, WebActivity.class);
intent.putExtra("url",cunUrl);
startActivity(intent);
}
}
}
}
return false;
}
}
package com.xy.kaijiang.zhencunscreen;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends BaseActivity implements View.OnKeyListener {
private TextView zhenTv,cunTv;
private String zhenUrl,cunUrl;
private TextView hintTv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
zhenTv = findViewById(R.id.zhenTv);
cunTv = findViewById(R.id.cunTv);
hintTv = findViewById(R.id.hint);
zhenTv.setOnFocusChangeListener(new MyFocusListener(1.2f,zhenTv));
cunTv.setOnFocusChangeListener(new MyFocusListener(1.2f,cunTv));
zhenTv.setOnKeyListener(this);
cunTv.setOnKeyListener(this);
zhenTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, WebActivity.class);
intent.putExtra("url",zhenUrl);
startActivity(intent);
}
});
cunTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, WebActivity.class);
intent.putExtra("url",cunUrl);
startActivity(intent);
}
});
// zhenUrl = "http://60.255.58.172:9001/qfsw/#/";
// zhenUrl = "http://www.baidu.com";
zhenUrl = "http://192.168.10.21:8080/#/gaotanTown";
// zhenUrl = "http://192.168.1.2:8080/#/test";
// zhenUrl = "http://60.255.58.172:9001/swhtml/html/home.html";
// zhenUrl = "http://www.baidu.com";
cunUrl = "http://192.168.1.2:8080/#/taiyangVillage";
PackageManager packageManager = getPackageManager();
// getPackageName()是你当前类的包名,0代表是获取版本信息
PackageInfo packInfo = null;
int version = 0;
try {
packInfo = packageManager.getPackageInfo(getPackageName(),0);
version = Integer.valueOf(android.os.Build.VERSION.SDK);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
hintTv.setText(version+"");
}
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
int keyCode = keyEvent.getKeyCode();
if (view.getId() == R.id.zhenTv) {
if (keyCode == Constans.KEY_ENTER || keyCode == Constans.KEY_OK) { //确认键
Intent intent = new Intent(this, WebActivity.class);
intent.putExtra("url",zhenUrl);
startActivity(intent);
}
else if(view.getId() == R.id.cunTv){
if (keyCode == Constans.KEY_ENTER || keyCode == Constans.KEY_OK) { //确认键
Intent intent = new Intent(this, WebActivity.class);
intent.putExtra("url",cunUrl);
startActivity(intent);
}
}
}
}
return false;
}
}

256
app/src/main/java/com/hc/hyycck/bigdatadisplay/MyApplication.java → app/src/main/java/com/xy/kaijiang/zhencunscreen/MyApplication.java

@ -1,128 +1,128 @@
package com.hc.hyycck.bigdatadisplay;
import android.app.Activity;
import android.app.Application;
import me.jessyan.autosize.AutoSize;
import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.external.ExternalAdaptManager;
import me.jessyan.autosize.internal.CustomAdapt;
import me.jessyan.autosize.onAdaptListener;
import xyz.doikki.videoplayer.ijk.IjkPlayerFactory;
import xyz.doikki.videoplayer.player.VideoViewConfig;
import xyz.doikki.videoplayer.player.VideoViewManager;
//import com.squareup.leakcanary.LeakCanary;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
VideoViewManager.setConfig(VideoViewConfig.newBuilder()
//使用使用IjkPlayer解码
.setPlayerFactory(IjkPlayerFactory.create())
//使用ExoPlayer解码
// .setPlayerFactory(ExoMediaPlayerFactory.create())
// //使用MediaPlayer解码
// .setPlayerFactory(AndroidMediaPlayerFactory.create())
.build());
//当 App 中出现多进程, 并且您需要适配所有的进程, 就需要在 App 初始化时调用 initCompatMultiProcess()
//在 Demo 中跳转的三方库中的 DefaultErrorActivity 就是在另外一个进程中, 所以要想适配这个 Activity 就需要调用 initCompatMultiProcess()
AutoSize.initCompatMultiProcess(this);
//如果在某些特殊情况下出现 InitProvider 未能正常实例化, 导致 AndroidAutoSize 未能完成初始化
//可以主动调用 AutoSize.checkAndInit(this) 方法, 完成 AndroidAutoSize 的初始化后即可正常使用
AutoSize.checkAndInit(this);
// 如何控制 AndroidAutoSize 的初始化,让 AndroidAutoSize 在某些设备上不自动启动?https://github.com/JessYanCoding/AndroidAutoSize/issues/249
/**
* 以下是 AndroidAutoSize 可以自定义的参数, {@link AutoSizeConfig} 的每个方法的注释都写的很详细
* 使用前请一定记得跳进源码查看方法的注释, 下面的注释只是简单描述!!!
*/
AutoSizeConfig.getInstance()
//是否让框架支持自定义 Fragment 的适配参数, 由于这个需求是比较少见的, 所以须要使用者手动开启
//如果没有这个需求建议不开启
.setCustomFragment(true)
//是否屏蔽系统字体大小对 AndroidAutoSize 的影响, 如果为 true, App 内的字体的大小将不会跟随系统设置中字体大小的改变
//如果为 false, 则会跟随系统设置中字体大小的改变, 默认为 false
// .setExcludeFontScale(true)
//区别于系统字体大小的放大比例, AndroidAutoSize 允许 APP 内部可以独立于系统字体大小之外,独自拥有全局调节 APP 字体大小的能力
//当然, 在 APP 内您必须使用 sp 来作为字体的单位, 否则此功能无效, 不设置或将此值设为 0 则取消此功能
// .setPrivateFontScale(0.8f)
//屏幕适配监听器
.setOnAdaptListener(new onAdaptListener() {
@Override
public void onAdaptBefore(Object target, Activity activity) {
//使用以下代码, 可以解决横竖屏切换时的屏幕适配问题
//使用以下代码, 可支持 Android 的分屏或缩放模式, 但前提是在分屏或缩放模式下当用户改变您 App 的窗口大小时
//系统会重绘当前的页面, 经测试在某些机型, 某些情况下系统不会主动重绘当前页面, 所以这时您需要自行重绘当前页面
//ScreenUtils.getScreenSize(activity) 的参数一定要不要传 Application!!!
// AutoSizeConfig.getInstance().setScreenWidth(ScreenUtils.getScreenSize(activity)[0]);
// AutoSizeConfig.getInstance().setScreenHeight(ScreenUtils.getScreenSize(activity)[1]);
// AutoSizeLog.d(String.format(Locale.ENGLISH, "%s onAdaptBefore!", target.getClass().getName()));
}
@Override
public void onAdaptAfter(Object target, Activity activity) {
// AutoSizeLog.d(String.format(Locale.ENGLISH, "%s onAdaptAfter!", target.getClass().getName()));
}
})
//是否打印 AutoSize 的内部日志, 默认为 true, 如果您不想 AutoSize 打印日志, 则请设置为 false
// .setLog(false)
//是否使用设备的实际尺寸做适配, 默认为 false, 如果设置为 false, 在以屏幕高度为基准进行适配时
//AutoSize 会将屏幕总高度减去状态栏高度来做适配
//设置为 true 则使用设备的实际屏幕高度, 不会减去状态栏高度
//在全面屏或刘海屏幕设备中, 获取到的屏幕高度可能不包含状态栏高度, 所以在全面屏设备中不需要减去状态栏高度,所以可以 setUseDeviceSize(true)
// .setUseDeviceSize(true)
//是否全局按照宽度进行等比例适配, 默认为 true, 如果设置为 false, AutoSize 会全局按照高度进行适配
// .setBaseOnWidth(false)
//设置屏幕适配逻辑策略类, 一般不用设置, 使用框架默认的就好
// .setAutoAdaptStrategy(new AutoAdaptStrategy())
;
customAdaptForExternal();
// if(LeakCanary.isInAnalyzerProcess(this)){
// return;
// }
// LeakCanary.install(this);
}
/**
* 给外部的三方库 {@link Activity} 自定义适配参数, 因为三方库的 {@link Activity} 并不能通过实现
* {@link CustomAdapt} 接口的方式来提供自定义适配参数 (因为远程依赖改不了源码)
* 所以使用 {@link ExternalAdaptManager} 来替代实现接口的方式, 来提供自定义适配参数
*/
private void customAdaptForExternal() {
/**
* {@link ExternalAdaptManager} 是一个管理外部三方库的适配信息和状态的管理类, 详细介绍请看 {@link ExternalAdaptManager} 的类注释
*/
AutoSizeConfig.getInstance().getExternalAdaptManager();
//加入的 Activity 将会放弃屏幕适配, 一般用于三方库的 Activity, 详情请看方法注释
//如果不想放弃三方库页面的适配, 请用 addExternalAdaptInfoOfActivity 方法, 建议对三方库页面进行适配, 让自己的 App 更完美一点
// .addCancelAdaptOfActivity(DefaultErrorActivity.class)
//为指定的 Activity 提供自定义适配参数, AndroidAutoSize 将会按照提供的适配参数进行适配, 详情请看方法注释
//一般用于三方库的 Activity, 因为三方库的设计图尺寸可能和项目自身的设计图尺寸不一致, 所以要想完美适配三方库的页面
//就需要提供三方库的设计图尺寸, 以及适配的方向 (以宽为基准还是高为基准?)
//三方库页面的设计图尺寸可能无法获知, 所以如果想让三方库的适配效果达到最好, 只有靠不断的尝试
//由于 AndroidAutoSize 可以让布局在所有设备上都等比例缩放, 所以只要您在一个设备上测试出了一个最完美的设计图尺寸
//那这个三方库页面在其他设备上也会呈现出同样的适配效果, 等比例缩放, 所以也就完成了三方库页面的屏幕适配
//即使在不改三方库源码的情况下也可以完美适配三方库的页面, 这就是 AndroidAutoSize 的优势
//但前提是三方库页面的布局使用的是 dp 和 sp, 如果布局全部使用的 px, 那 AndroidAutoSize 也将无能为力
//经过测试 DefaultErrorActivity 的设计图宽度在 380dp - 400dp 显示效果都是比较舒服的
// .addExternalAdaptInfoOfActivity(DefaultErrorActivity.class, new ExternalAdaptInfo(true, 400));
}
}
package com.xy.kaijiang.zhencunscreen;
import android.app.Activity;
import android.app.Application;
import me.jessyan.autosize.AutoSize;
import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.external.ExternalAdaptManager;
import me.jessyan.autosize.internal.CustomAdapt;
import me.jessyan.autosize.onAdaptListener;
import xyz.doikki.videoplayer.ijk.IjkPlayerFactory;
import xyz.doikki.videoplayer.player.VideoViewConfig;
import xyz.doikki.videoplayer.player.VideoViewManager;
//import com.squareup.leakcanary.LeakCanary;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
VideoViewManager.setConfig(VideoViewConfig.newBuilder()
//使用使用IjkPlayer解码
.setPlayerFactory(IjkPlayerFactory.create())
//使用ExoPlayer解码
// .setPlayerFactory(ExoMediaPlayerFactory.create())
// //使用MediaPlayer解码
// .setPlayerFactory(AndroidMediaPlayerFactory.create())
.build());
//当 App 中出现多进程, 并且您需要适配所有的进程, 就需要在 App 初始化时调用 initCompatMultiProcess()
//在 Demo 中跳转的三方库中的 DefaultErrorActivity 就是在另外一个进程中, 所以要想适配这个 Activity 就需要调用 initCompatMultiProcess()
AutoSize.initCompatMultiProcess(this);
//如果在某些特殊情况下出现 InitProvider 未能正常实例化, 导致 AndroidAutoSize 未能完成初始化
//可以主动调用 AutoSize.checkAndInit(this) 方法, 完成 AndroidAutoSize 的初始化后即可正常使用
AutoSize.checkAndInit(this);
// 如何控制 AndroidAutoSize 的初始化,让 AndroidAutoSize 在某些设备上不自动启动?https://github.com/JessYanCoding/AndroidAutoSize/issues/249
/**
* 以下是 AndroidAutoSize 可以自定义的参数, {@link AutoSizeConfig} 的每个方法的注释都写的很详细
* 使用前请一定记得跳进源码查看方法的注释, 下面的注释只是简单描述!!!
*/
AutoSizeConfig.getInstance()
//是否让框架支持自定义 Fragment 的适配参数, 由于这个需求是比较少见的, 所以须要使用者手动开启
//如果没有这个需求建议不开启
.setCustomFragment(true)
//是否屏蔽系统字体大小对 AndroidAutoSize 的影响, 如果为 true, App 内的字体的大小将不会跟随系统设置中字体大小的改变
//如果为 false, 则会跟随系统设置中字体大小的改变, 默认为 false
// .setExcludeFontScale(true)
//区别于系统字体大小的放大比例, AndroidAutoSize 允许 APP 内部可以独立于系统字体大小之外,独自拥有全局调节 APP 字体大小的能力
//当然, 在 APP 内您必须使用 sp 来作为字体的单位, 否则此功能无效, 不设置或将此值设为 0 则取消此功能
// .setPrivateFontScale(0.8f)
//屏幕适配监听器
.setOnAdaptListener(new onAdaptListener() {
@Override
public void onAdaptBefore(Object target, Activity activity) {
//使用以下代码, 可以解决横竖屏切换时的屏幕适配问题
//使用以下代码, 可支持 Android 的分屏或缩放模式, 但前提是在分屏或缩放模式下当用户改变您 App 的窗口大小时
//系统会重绘当前的页面, 经测试在某些机型, 某些情况下系统不会主动重绘当前页面, 所以这时您需要自行重绘当前页面
//ScreenUtils.getScreenSize(activity) 的参数一定要不要传 Application!!!
// AutoSizeConfig.getInstance().setScreenWidth(ScreenUtils.getScreenSize(activity)[0]);
// AutoSizeConfig.getInstance().setScreenHeight(ScreenUtils.getScreenSize(activity)[1]);
// AutoSizeLog.d(String.format(Locale.ENGLISH, "%s onAdaptBefore!", target.getClass().getName()));
}
@Override
public void onAdaptAfter(Object target, Activity activity) {
// AutoSizeLog.d(String.format(Locale.ENGLISH, "%s onAdaptAfter!", target.getClass().getName()));
}
})
//是否打印 AutoSize 的内部日志, 默认为 true, 如果您不想 AutoSize 打印日志, 则请设置为 false
// .setLog(false)
//是否使用设备的实际尺寸做适配, 默认为 false, 如果设置为 false, 在以屏幕高度为基准进行适配时
//AutoSize 会将屏幕总高度减去状态栏高度来做适配
//设置为 true 则使用设备的实际屏幕高度, 不会减去状态栏高度
//在全面屏或刘海屏幕设备中, 获取到的屏幕高度可能不包含状态栏高度, 所以在全面屏设备中不需要减去状态栏高度,所以可以 setUseDeviceSize(true)
// .setUseDeviceSize(true)
//是否全局按照宽度进行等比例适配, 默认为 true, 如果设置为 false, AutoSize 会全局按照高度进行适配
// .setBaseOnWidth(false)
//设置屏幕适配逻辑策略类, 一般不用设置, 使用框架默认的就好
// .setAutoAdaptStrategy(new AutoAdaptStrategy())
;
customAdaptForExternal();
// if(LeakCanary.isInAnalyzerProcess(this)){
// return;
// }
// LeakCanary.install(this);
}
/**
* 给外部的三方库 {@link Activity} 自定义适配参数, 因为三方库的 {@link Activity} 并不能通过实现
* {@link CustomAdapt} 接口的方式来提供自定义适配参数 (因为远程依赖改不了源码)
* 所以使用 {@link ExternalAdaptManager} 来替代实现接口的方式, 来提供自定义适配参数
*/
private void customAdaptForExternal() {
/**
* {@link ExternalAdaptManager} 是一个管理外部三方库的适配信息和状态的管理类, 详细介绍请看 {@link ExternalAdaptManager} 的类注释
*/
AutoSizeConfig.getInstance().getExternalAdaptManager();
//加入的 Activity 将会放弃屏幕适配, 一般用于三方库的 Activity, 详情请看方法注释
//如果不想放弃三方库页面的适配, 请用 addExternalAdaptInfoOfActivity 方法, 建议对三方库页面进行适配, 让自己的 App 更完美一点
// .addCancelAdaptOfActivity(DefaultErrorActivity.class)
//为指定的 Activity 提供自定义适配参数, AndroidAutoSize 将会按照提供的适配参数进行适配, 详情请看方法注释
//一般用于三方库的 Activity, 因为三方库的设计图尺寸可能和项目自身的设计图尺寸不一致, 所以要想完美适配三方库的页面
//就需要提供三方库的设计图尺寸, 以及适配的方向 (以宽为基准还是高为基准?)
//三方库页面的设计图尺寸可能无法获知, 所以如果想让三方库的适配效果达到最好, 只有靠不断的尝试
//由于 AndroidAutoSize 可以让布局在所有设备上都等比例缩放, 所以只要您在一个设备上测试出了一个最完美的设计图尺寸
//那这个三方库页面在其他设备上也会呈现出同样的适配效果, 等比例缩放, 所以也就完成了三方库页面的屏幕适配
//即使在不改三方库源码的情况下也可以完美适配三方库的页面, 这就是 AndroidAutoSize 的优势
//但前提是三方库页面的布局使用的是 dp 和 sp, 如果布局全部使用的 px, 那 AndroidAutoSize 也将无能为力
//经过测试 DefaultErrorActivity 的设计图宽度在 380dp - 400dp 显示效果都是比较舒服的
// .addExternalAdaptInfoOfActivity(DefaultErrorActivity.class, new ExternalAdaptInfo(true, 400));
}
}

336
app/src/main/java/com/hc/hyycck/bigdatadisplay/MyFocusListener.java → app/src/main/java/com/xy/kaijiang/zhencunscreen/MyFocusListener.java

@ -1,168 +1,168 @@
package com.hc.hyycck.bigdatadisplay;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
public class MyFocusListener implements View.OnFocusChangeListener {
private final static String TAG = "MyFocusListener====";
private int xF ,yF; //yF:-1 ->向下,0->居中,1->向上,xF :-1 ->向左,0->居中,1->向右
private float scaleTime = 1.05f;
private View view;
private int zIndex = -1;
public MyFocusListener(int xF, int yF){
this.xF = xF;
this.yF = yF;
}
public MyFocusListener(int xF, int yF, View view){
this.xF = xF;
this.yF = yF;
this.view = view;
}
public MyFocusListener(int xF, int yF, float scaleTime){
this.xF = xF;
this.yF = yF;
this.scaleTime = scaleTime;
}
public MyFocusListener(int xF, int yF, float scaleTime, View view){
this.xF = xF;
this.yF = yF;
this.scaleTime = scaleTime;
this.view = view;
}
public MyFocusListener(float scaleTime, View view){
this.scaleTime = scaleTime;
this.view = view;
}
public MyFocusListener(){
}
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
// bringToIndex(view);
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation animation ;
if(xF == 0 && yF == 0){ //居中放大
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 0 && yF == -1){ //垂直方向向下,水平方居中
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 0 && yF == 1){ //垂直方向向上,水平方居中
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == -1 && yF == 0 ){ //垂直方向居中,水平方向向左
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == -1 && yF == -1){ //垂直向下,水平向左
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == -1 && yF == 1){ //垂直向上,水平向左
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == 1 && yF == 0){//垂直方向居中,水平方向向右
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 1 && yF == -1){ //垂直方向向下,水平方向向右
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 1 && yF == 1){ //垂直方向向上,水平方向向右
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
}
else{
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
animation.setDuration(200);
animation.setFillAfter(true);
animationSet.addAnimation(animation);
animationSet.setFillAfter(true);
view.clearAnimation();
view.startAnimation(animationSet);
}
else{
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation animation;
if(xF == 0 && yF == 0){ //居中缩小
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 0 && yF == -1){ //垂直方向向下,水平方居中
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 0 && yF == 1){ //垂直方向向上,水平方居中
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == -1 && yF == 0 ){ //垂直方向居中,水平方向向左
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == -1 && yF == -1){ //垂直向下,水平向左
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == -1 && yF == 1){ //垂直向上,水平向左
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == 1 && yF == 0){//垂直方向居中,水平方向向右
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 1 && yF == -1){ //垂直方向向下,水平方向向右
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 1 && yF == 1){ //垂直方向向上,水平方向向右
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
}
else{
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
animation.setDuration(200);
animation.setFillAfter(true);
animationSet.addAnimation(animation);
animationSet.setFillAfter(true);
view.startAnimation(animationSet);
}
}
private void bringToIndex(View child){
ViewGroup mParent = (ViewGroup) child.getParent();
int childCount = mParent.getChildCount();
if (childCount > 0) {
mParent.removeView(child);
mParent.addView(child, childCount-1);
mParent.requestLayout();
mParent.invalidate();
}
}
}
package com.xy.kaijiang.zhencunscreen;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
public class MyFocusListener implements View.OnFocusChangeListener {
private final static String TAG = "MyFocusListener====";
private int xF ,yF; //yF:-1 ->向下,0->居中,1->向上,xF :-1 ->向左,0->居中,1->向右
private float scaleTime = 1.05f;
private View view;
private int zIndex = -1;
public MyFocusListener(int xF, int yF){
this.xF = xF;
this.yF = yF;
}
public MyFocusListener(int xF, int yF, View view){
this.xF = xF;
this.yF = yF;
this.view = view;
}
public MyFocusListener(int xF, int yF, float scaleTime){
this.xF = xF;
this.yF = yF;
this.scaleTime = scaleTime;
}
public MyFocusListener(int xF, int yF, float scaleTime, View view){
this.xF = xF;
this.yF = yF;
this.scaleTime = scaleTime;
this.view = view;
}
public MyFocusListener(float scaleTime, View view){
this.scaleTime = scaleTime;
this.view = view;
}
public MyFocusListener(){
}
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
// bringToIndex(view);
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation animation ;
if(xF == 0 && yF == 0){ //居中放大
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 0 && yF == -1){ //垂直方向向下,水平方居中
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 0 && yF == 1){ //垂直方向向上,水平方居中
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == -1 && yF == 0 ){ //垂直方向居中,水平方向向左
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == -1 && yF == -1){ //垂直向下,水平向左
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == -1 && yF == 1){ //垂直向上,水平向左
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == 1 && yF == 0){//垂直方向居中,水平方向向右
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 1 && yF == -1){ //垂直方向向下,水平方向向右
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 1 && yF == 1){ //垂直方向向上,水平方向向右
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
}
else{
animation = new ScaleAnimation(1.0f, scaleTime, 1.0f, scaleTime,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
animation.setDuration(200);
animation.setFillAfter(true);
animationSet.addAnimation(animation);
animationSet.setFillAfter(true);
view.clearAnimation();
view.startAnimation(animationSet);
}
else{
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation animation;
if(xF == 0 && yF == 0){ //居中缩小
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 0 && yF == -1){ //垂直方向向下,水平方居中
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 0 && yF == 1){ //垂直方向向上,水平方居中
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == -1 && yF == 0 ){ //垂直方向居中,水平方向向左
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == -1 && yF == -1){ //垂直向下,水平向左
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == -1 && yF == 1){ //垂直向上,水平向左
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
}
else if(xF == 1 && yF == 0){//垂直方向居中,水平方向向右
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else if(xF == 1 && yF == -1){ //垂直方向向下,水平方向向右
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
}
else if(xF == 1 && yF == 1){ //垂直方向向上,水平方向向右
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
}
else{
animation = new ScaleAnimation(scaleTime, 1.0f, scaleTime, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
animation.setDuration(200);
animation.setFillAfter(true);
animationSet.addAnimation(animation);
animationSet.setFillAfter(true);
view.startAnimation(animationSet);
}
}
private void bringToIndex(View child){
ViewGroup mParent = (ViewGroup) child.getParent();
int childCount = mParent.getChildCount();
if (childCount > 0) {
mParent.removeView(child);
mParent.addView(child, childCount-1);
mParent.requestLayout();
mParent.invalidate();
}
}
}

160
app/src/main/java/com/hc/hyycck/bigdatadisplay/WebActivity.java → app/src/main/java/com/xy/kaijiang/zhencunscreen/WebActivity.java

@ -1,79 +1,81 @@
package com.hc.hyycck.bigdatadisplay;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebActivity extends BaseActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webpage);
webView = (WebView) findViewById(R.id.vw);
//获取WebSettings类的实例,此类用于对WebView加载的网页进行设置
WebSettings webSettings = webView.getSettings();
//使WebView可以使用JavaScript
//设置支持js
webSettings.setJavaScriptEnabled(true);
//设置适应屏幕
webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
webSettings.setPluginState(WebSettings.PluginState.ON);//设置是否支持插件
webSettings.setSupportZoom(true); //支持缩放
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
//设置存储模式
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAllowFileAccess(true);
//setDomStorageEnabled解决了webview白屏问题 设置支持DomStorage
webSettings.setDomStorageEnabled(true);
//设置支持本地存储
webSettings.setDatabaseEnabled(true);
//设置缓存
webSettings.setAppCacheEnabled(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//支持通过JS打开新窗口
webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
webSettings.setDefaultTextEncodingName("utf-8");
//请求加载,并交由Webclient去处理
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Town?name=丰禾镇&areaCode=511623113000&from=TV"; //丰禾镇
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Town?areaCode=511623108000&name=坛同镇&from=TV"; //坛同镇
String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Town?areaCode=511623118000&name=石滓镇&from=TV"; //石滓镇
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Village?name=五华山村&areaCode=wuhuashancun";
// String url = "http://192.168.10.21:8080/#/Town?name=丰禾镇&areaCode=2021030891230011&from=TV";
webView.loadUrl(url);
//webView.loadUrl("http://www.baidu.com");
//使用WebViewClient设置监听并处理WebView的请求事件
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//根据url真正去加载网页的操作
view.loadUrl(url);
//在当前WebView中打开网页,而不在浏览器中
return true;
}
});
}
@Override
public void onBackPressed() {
if(webView.canGoBack()){
webView.goBack();
}
else{
super.onBackPressed();
}
}
}
package com.xy.kaijiang.zhencunscreen;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebActivity extends BaseActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webpage);
webView = (WebView) findViewById(R.id.vw);
//获取WebSettings类的实例,此类用于对WebView加载的网页进行设置
WebSettings webSettings = webView.getSettings();
//使WebView可以使用JavaScript
//设置支持js
webSettings.setJavaScriptEnabled(true);
//设置适应屏幕
webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
webSettings.setPluginState(WebSettings.PluginState.ON);//设置是否支持插件
webSettings.setSupportZoom(true); //支持缩放
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
//设置存储模式
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAllowFileAccess(true);
//setDomStorageEnabled解决了webview白屏问题 设置支持DomStorage
webSettings.setDomStorageEnabled(true);
//设置支持本地存储
webSettings.setDatabaseEnabled(true);
//设置缓存
webSettings.setAppCacheEnabled(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//支持通过JS打开新窗口
webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setMediaPlaybackRequiresUserGesture(false);//设置音频自动播放
//请求加载,并交由Webclient去处理
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Town?name=丰禾镇&areaCode=511623113000&from=TV"; //丰禾镇
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Town?areaCode=511623108000&name=坛同镇&from=TV"; //坛同镇
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Town?areaCode=511623118000&name=石滓镇&from=TV"; //石滓镇
// String url = "http://60.255.174.144:9010/LinShuiSmartServerWeb/#/Village?name=五华山村&areaCode=wuhuashancun";
// String url = "http://192.168.10.21:8080/#/Town?name=丰禾镇&areaCode=2021030891230011&from=TV";
String url="http://192.168.1.49:8080/#/screenTwo?areaCode=2c9f90cc818653f40181865428380000&areaName=%E4%BB%BB%E5%B8%82%E9%95%87";
webView.loadUrl(url);
//webView.loadUrl("http://www.baidu.com");
//使用WebViewClient设置监听并处理WebView的请求事件
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//根据url真正去加载网页的操作
view.loadUrl(url);
//在当前WebView中打开网页,而不在浏览器中
return true;
}
});
}
@Override
public void onBackPressed() {
if(webView.canGoBack()){
webView.goBack();
}
else{
super.onBackPressed();
}
}
}
Loading…
Cancel
Save