Kaynağa Gözat

H5定位

master
Zhao 2 gün önce
ebeveyn
işleme
42268c0a14
10 değiştirilmiş dosya ile 281 ekleme ve 44 silme
  1. +48
    -1
      app/src/main/java/com/nsgk/ruralWeb/FullscreenActivity.java
  2. +3
    -2
      app/src/main/java/com/nsgk/ruralWeb/enums/NSEnums.java
  3. +5
    -3
      app/src/main/java/com/nsgk/ruralWeb/location/NSAMapLocation.java
  4. +5
    -3
      app/src/main/java/com/nsgk/ruralWeb/location/NSRealtimeLocation.java
  5. +9
    -2
      app/src/main/java/com/nsgk/ruralWeb/sys/NSConstants.java
  6. +6
    -4
      app/src/main/java/com/nsgk/ruralWeb/sys/NSPreference.java
  7. +62
    -7
      app/src/main/java/com/nsgk/ruralWeb/ui/SettingsFragment.java
  8. +108
    -6
      app/src/main/java/com/nsgk/ruralWeb/web/NSEnvWindowObject.java
  9. +14
    -12
      app/src/main/res/values/arrays.xml
  10. +21
    -4
      app/src/main/res/xml/settings_preference.xml

+ 48
- 1
app/src/main/java/com/nsgk/ruralWeb/FullscreenActivity.java Dosyayı Görüntüle

@@ -1,16 +1,21 @@
package com.nsgk.ruralWeb;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions;
import android.webkit.WebBackForwardList;
import android.webkit.WebHistoryItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@@ -57,6 +62,9 @@ public class FullscreenActivity extends AppCompatActivity {

setContentView(R.layout.activity_fullscreen);
String appHomeUrl = GetHomeUrl();
boolean logcatConsole = GetPreference().GetBool(NSPreference.LOGCAT_CONSOLE_OUTPUT, NSContextUtils.BuildIsDebug(this));
if(logcatConsole)
Log.i(ID_TAG, logcatConsole ? "输出控制台到logcat" : "不输出控制台");
//appHomeUrl = "http://192.168.0.250:85/sunVillage_info/login";
Log.i(ID_TAG, "App home url: " + appHomeUrl);
// init();
@@ -84,6 +92,38 @@ public class FullscreenActivity extends AppCompatActivity {
}
m_lastUrl = url;
}

@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage)
{
if(logcatConsole)
{
String text = "[" + consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + "] " + consoleMessage.message();
switch(consoleMessage.messageLevel())
{
case WARNING:
Log.w("Console", text);
break;
case ERROR:
Log.e("Console", text);
break;
case DEBUG:
Log.d("Console", text);
break;
case LOG:
default:
Log.i("Console", text);
break;
}
}
return super.onConsoleMessage(consoleMessage);
}

@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
super.onGeolocationPermissionsShowPrompt(origin, callback);
}
})
.setWebViewClient(new WebViewClient() {
})//WebViewClient , 与 WebView 使用一致 ,但是请勿获取WebView调用setWebViewClient(xx)方法了,会覆盖AgentWeb DefaultWebClient,同时相应的中间件也会失效。
@@ -111,14 +151,21 @@ public class FullscreenActivity extends AppCompatActivity {

mAgentWeb = builder.go(appHomeUrl); //WebView载入该url地址的页面并显示。

WebSettings settings = GetWebView().getSettings();

int fontScale = GetPreference().GetInt(NSPreference.FONT_SCALE);
Log.i(ID_TAG, "全局字体缩放: " + fontScale + "%");
if(fontScale > 0 && fontScale != 100)
GetWebView().getSettings().setTextZoom(fontScale);
settings.setTextZoom(fontScale);

settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setGeolocationEnabled(true);

// 注入宿主对象
envWindowObject = new NSEnvWindowObject(this, new Handler(), GetWebView());
mAgentWeb.getJsInterfaceHolder().addJavaObject("_Native_object", envWindowObject);
mAgentWeb.getJsInterfaceHolder().addJavaObject("Android", envWindowObject);

/* 上边url是各个APP项目的入口地址
事项审批 http://116.255.223.226:82/yinnongLogin 图标 ic_launcher_sxsp 或者 ic_launcher_yhzl


+ 3
- 2
app/src/main/java/com/nsgk/ruralWeb/enums/NSEnums.java Dosyayı Görüntüle

@@ -2,13 +2,14 @@ package com.nsgk.ruralWeb.enums;

public final class NSEnums
{
public final class LocationScheme
public final class LocationMode
{
public static final String SYSTEM = "system";
public static final String GAODE = "gaode";
public static final String REALTIME = "realtime";
public static final String H5 = "h5";

private LocationScheme() {}
private LocationMode() {}
}

public final class LocationProvider


+ 5
- 3
app/src/main/java/com/nsgk/ruralWeb/location/NSAMapLocation.java Dosyayı Görüntüle

@@ -410,7 +410,7 @@ public class NSAMapLocation implements AMapLocationListener
/**
* 同步调用, 会锁住线程
*/
public NSLocationInfo Read(int count)
public NSLocationInfo Read(int count, int timeout)
{
CheckInitialization(true);
/* if(IsRunning())
@@ -418,14 +418,16 @@ public class NSAMapLocation implements AMapLocationListener
throw new RuntimeException("请先停止定位");
}*/

Log.d(ID_TAG, "定位线程: " + Thread.currentThread().getId());
if(timeout < 0)
timeout = 0;
Log.d(ID_TAG, "AMap定位线程: " + Thread.currentThread().getId() + ", 超时设置: " + timeout);
synchronized(m_lock)
{
try
{
CleanLastLocation();
Run(count);
m_lock.wait();
m_lock.wait(timeout);
}
catch(Exception e)
{


+ 5
- 3
app/src/main/java/com/nsgk/ruralWeb/location/NSRealtimeLocation.java Dosyayı Görüntüle

@@ -303,7 +303,7 @@ public class NSRealtimeLocation implements LocationListener
/**
* 同步调用, 会锁住线程
*/
public NSLocationInfo Read(int count)
public NSLocationInfo Read(int count, int timeout)
{
CheckInitialization(true);
/* if(IsRunning())
@@ -311,14 +311,16 @@ public class NSRealtimeLocation implements LocationListener
throw new RuntimeException("请先停止定位");
}*/

Log.d(ID_TAG, "定位线程: " + Thread.currentThread().getId());
if(timeout < 0)
timeout = 0;
Log.d(ID_TAG, "实时定位线程: " + Thread.currentThread().getId() + ", 超时设置: " + timeout);
synchronized(m_lock)
{
try
{
CleanLastLocation();
Run(count);
m_lock.wait();
m_lock.wait(timeout);
}
catch(Exception e)
{


+ 9
- 2
app/src/main/java/com/nsgk/ruralWeb/sys/NSConstants.java Dosyayı Görüntüle

@@ -42,16 +42,23 @@ public final class NSConstants
return BuildConfig.APP_ICON;
}

public static boolean IsHttps()
{
return AppHomeUrl().startsWith("https://");
}

// 偏好默认值
public static final String DEFAULT_LOCATION_SCHEME = NSEnums.LocationScheme.REALTIME;
public static final String DEFAULT_LOCATION_MODE = NSEnums.LocationMode.REALTIME;
public static final int DEFAULT_LOCATION_GAODE_INTERVAL = 1000;
public static final int DEFAULT_LOCATION_GAODE_READ_COUNT = 1;
public static final String DEFAULT_LOCATION_PROVIDER = LocationManager.GPS_PROVIDER;
public static final int DEFAULT_LOCATION_REALTIME_INTERVAL = 1000;
public static final int DEFAULT_LOCATION_REALTIME_DISTANCE = 1;
public static final int DEFAULT_LOCATION_REALTIME_DISTANCE = 0; // 1
public static final int DEFAULT_LOCATION_REALTIME_READ_COUNT = 1;
public static final boolean DEFAULT_OPEN_LAST_URL = false;
public static final int DEFAULT_FONT_SCALE = 100;
public static final boolean DEFAULT_LOGCAT_CONSOLE_OUTPUT = false;
public static final int DEFAULT_LOCATION_TIMEOUT = 0;

private NSConstants() {}
}

+ 6
- 4
app/src/main/java/com/nsgk/ruralWeb/sys/NSPreference.java Dosyayı Görüntüle

@@ -8,19 +8,21 @@ import com.nsgk.ruralWeb.utils.NSStr;

public final class NSPreference
{
public static final String LOCATION_SCHEME = "location_scheme";
public static final String LOCATION_MODE = "location_mode";
public static final String LOCATION_GAODE_INTERVAL = "location_gaode_interval";
public static final String LOCATION_GAODE_READ_COUNT = "location_gaode_read_count";
public static final String LOCATION_PROVIDER = "location_provider";
public static final String LOCATION_PROVIDER = "location_provider";
public static final String LOCATION_REALTIME_INTERVAL = "location_realtime_interval";
public static final String LOCATION_REALTIME_DISTANCE = "location_realtime_distance";
public static final String LOCATION_REALTIME_READ_COUNT = "location_realtime_read_count";
public static final String OPEN_LAST_URL = "open_last_url";
public static final String LAST_ACCESS_URL = "last_access_url";
public static final String COOKIES = "cookies";
public static final String FONT_SCALE = "font_scale";
public static final String FONT_SCALE = "font_scale";
public static final String LOGCAT_CONSOLE_OUTPUT = "logcat_console_output";
public static final String LOCATION_TIMEOUT = "location_timeout";
public static final String RESET_SETTINGS = "RESET_SETTINGS";
public static final String VERSION = "VERSION";
public static final String VERSION = "VERSION";

private final Context context;



+ 62
- 7
app/src/main/java/com/nsgk/ruralWeb/ui/SettingsFragment.java Dosyayı Görüntüle

@@ -5,6 +5,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
@@ -15,10 +16,14 @@ import androidx.preference.SeekBarPreference;

import com.nsgk.ruralWeb.BuildConfig;
import com.nsgk.ruralWeb.R;
import com.nsgk.ruralWeb.enums.NSEnums;
import com.nsgk.ruralWeb.sys.NSConstants;
import com.nsgk.ruralWeb.sys.NSPreference;
import com.nsgk.ruralWeb.utils.NSContextUtils;
import com.nsgk.ruralWeb.utils.NSMisc;
import com.nsgk.ruralWeb.utils.NSStr;

import java.util.Objects;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
@@ -33,8 +38,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
Preference preference;
final Context context = getContext();

preference = findPreference(NSPreference.LOCATION_SCHEME);
preference.setDefaultValue(NSConstants.DEFAULT_LOCATION_SCHEME);
preference = findPreference(NSPreference.LOCATION_MODE);
preference.setDefaultValue(NSConstants.DEFAULT_LOCATION_MODE);
preference.setOnPreferenceChangeListener(this);

preference = findPreference(NSPreference.LOCATION_GAODE_INTERVAL);
@@ -69,11 +74,22 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
preference.setDefaultValue(NSConstants.DEFAULT_FONT_SCALE);
preference.setOnPreferenceChangeListener(this);

preference = findPreference(NSPreference.LOGCAT_CONSOLE_OUTPUT);
preference.setDefaultValue("" + NSConstants.DEFAULT_LOGCAT_CONSOLE_OUTPUT);
preference.setOnPreferenceChangeListener(this);

preference = findPreference(NSPreference.LOCATION_TIMEOUT);
preference.setDefaultValue("" + NSConstants.DEFAULT_LOCATION_TIMEOUT);
preference.setOnPreferenceChangeListener(this);

preference = findPreference(NSPreference.RESET_SETTINGS);
preference.setOnPreferenceClickListener(this);

preference = findPreference(NSPreference.VERSION);
preference.setOnPreferenceClickListener(this);

preference = findPreference("location_gaode");
preference.setVisible(false);
}

private boolean CheckValueIsNumber(Object newValue, Integer min)
@@ -128,6 +144,10 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
if(!CheckValueIsNumber(newValue, 1))
return false;
break;
case NSPreference.LOCATION_TIMEOUT:
if(!CheckValueIsNumber(newValue, 0))
return false;
break;
case NSPreference.FONT_SCALE: {
int i = (int)newValue;
int newi = Math.round((float)i / 10.0f) * 10;
@@ -143,6 +163,22 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
}
break;
}
case NSPreference.LOCATION_MODE:
if(Objects.equals(NSEnums.LocationMode.GAODE, newValue))
{
Log.w(ID_TAG, "高德定位被禁用");
return false;
}
if(Objects.equals(NSEnums.LocationMode.H5, newValue))
{
if(!NSConstants.IsHttps())
{
Log.w(ID_TAG, "非https不支持H5定位");
Toast.makeText(getContext(), "当前不支持H5定位", Toast.LENGTH_SHORT).show();
return false;
}
}
break;
}

SetSummary(key, newValue);
@@ -174,7 +210,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
{
NSPreference preference = new NSPreference(getContext());
preference.Write()
.putString(NSPreference.LOCATION_SCHEME, NSConstants.DEFAULT_LOCATION_SCHEME)
.putString(NSPreference.LOCATION_MODE, NSConstants.DEFAULT_LOCATION_MODE)
.putString(NSPreference.LOCATION_GAODE_INTERVAL, "" + NSConstants.DEFAULT_LOCATION_GAODE_INTERVAL)
.putString(NSPreference.LOCATION_GAODE_READ_COUNT, "" + NSConstants.DEFAULT_LOCATION_GAODE_READ_COUNT)
.putBoolean(NSPreference.OPEN_LAST_URL, NSConstants.DEFAULT_OPEN_LAST_URL)
@@ -183,6 +219,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
.putString(NSPreference.LOCATION_REALTIME_DISTANCE, "" + NSConstants.DEFAULT_LOCATION_REALTIME_DISTANCE)
.putString(NSPreference.LOCATION_REALTIME_READ_COUNT, "" + NSConstants.DEFAULT_LOCATION_REALTIME_READ_COUNT)
.putInt(NSPreference.FONT_SCALE, NSConstants.DEFAULT_FONT_SCALE)
.putString(NSPreference.LOCATION_TIMEOUT, "" + NSConstants.DEFAULT_LOCATION_TIMEOUT)
.putBoolean(NSPreference.LOGCAT_CONSOLE_OUTPUT, NSConstants.DEFAULT_LOGCAT_CONSOLE_OUTPUT)
.commit()
;
}
@@ -229,11 +267,11 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
int i;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

if(key == null || NSPreference.LOCATION_SCHEME.equals(key))
if(key == null || NSPreference.LOCATION_MODE.equals(key))
{
preference = findPreference(NSPreference.LOCATION_SCHEME);
value = newValue != null ? newValue.toString() : sharedPreferences.getString(NSPreference.LOCATION_SCHEME, NSConstants.DEFAULT_LOCATION_SCHEME);
summary = NSContextUtils.GetListName(context, value, R.array.location_scheme_values, R.array.location_scheme_labels);
preference = findPreference(NSPreference.LOCATION_MODE);
value = newValue != null ? newValue.toString() : sharedPreferences.getString(NSPreference.LOCATION_MODE, NSConstants.DEFAULT_LOCATION_MODE);
summary = NSContextUtils.GetListName(context, value, R.array.location_mode_values, R.array.location_mode_labels);
preference.setSummary(summary);
}

@@ -303,6 +341,23 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
preference.setSummary(summary);
}

if(key == null || NSPreference.LOCATION_TIMEOUT.equals(key))
{
preference = findPreference(NSPreference.LOCATION_TIMEOUT);
value = newValue != null && StrUtil.isNotBlank(newValue.toString()) ? newValue.toString() : sharedPreferences.getString(NSPreference.LOCATION_TIMEOUT, "" + NSConstants.DEFAULT_LOCATION_TIMEOUT);
i = NSStr.parseInt_s(value, 0);
summary = i > 0 ? i + "毫秒" : "不超时";
preference.setSummary(summary);
}

if(key == null || NSPreference.LOGCAT_CONSOLE_OUTPUT.equals(key))
{
preference = findPreference(NSPreference.LOGCAT_CONSOLE_OUTPUT);
b = newValue != null ? (Boolean)newValue : sharedPreferences.getBoolean(NSPreference.LOGCAT_CONSOLE_OUTPUT, NSConstants.DEFAULT_LOGCAT_CONSOLE_OUTPUT);
summary = b ? "控制台输出到logcat" : "不输出控制台";
preference.setSummary(summary);
}

findPreference(NSPreference.VERSION).setSummary(NSContextUtils.GetAppVersion(getContext()));
}
}


+ 108
- 6
app/src/main/java/com/nsgk/ruralWeb/web/NSEnvWindowObject.java Dosyayı Görüntüle

@@ -3,7 +3,9 @@ package com.nsgk.ruralWeb.web;
import android.app.Activity;

import android.Manifest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Handler;
@@ -16,6 +18,7 @@ import android.widget.Toast;
import androidx.core.app.ActivityCompat;

import com.nsgk.ruralWeb.FullscreenActivity;
import com.nsgk.ruralWeb.R;
import com.nsgk.ruralWeb.enums.NSEnums;
import com.nsgk.ruralWeb.location.NSLocationInfo;
import com.nsgk.ruralWeb.location.NSAMapLocation;
@@ -25,6 +28,10 @@ import com.nsgk.ruralWeb.sys.NSConstants;
import com.nsgk.ruralWeb.sys.NSPreference;
import com.nsgk.ruralWeb.utils.NSContextUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class NSEnvWindowObject
{
private static final String ID_TAG = NSEnvWindowObject.class.getName();
@@ -95,22 +102,22 @@ public class NSEnvWindowObject
}

NSLocationInfo loc;
String location = preference.GetString(NSPreference.LOCATION_SCHEME, NSConstants.DEFAULT_LOCATION_SCHEME);
String location = CurrentLocationMode();
String provider = preference.GetString(NSPreference.LOCATION_PROVIDER, NSConstants.DEFAULT_LOCATION_PROVIDER);
Log.d(ID_TAG, "定位提供器: " + provider);
switch(location)
{
case NSEnums.LocationScheme.GAODE:
case NSEnums.LocationMode.GAODE:
loc = GetAMapLocation();
if(null == loc)
loc = GetBuiltInLocation(provider);
break;
case NSEnums.LocationScheme.REALTIME:
case NSEnums.LocationMode.REALTIME:
loc = GetRealtimeLocation();
if(null == loc)
loc = GetBuiltInLocation(provider);
break;
case NSEnums.LocationScheme.SYSTEM:
case NSEnums.LocationMode.SYSTEM:
default:
loc = GetBuiltInLocation(provider);
break;
@@ -119,6 +126,97 @@ public class NSEnvWindowObject
return SetLastLocation(loc);
}

public String CurrentLocationMode()
{
return preference.GetString(NSPreference.LOCATION_MODE, NSConstants.DEFAULT_LOCATION_MODE);
}

@JavascriptInterface
public String GetLocationMode()
{
return CurrentLocationMode();
}

@JavascriptInterface
public int GetLocationTimeout()
{
return preference.GetIntFromString(NSPreference.LOCATION_TIMEOUT, NSConstants.DEFAULT_LOCATION_TIMEOUT);
}

@JavascriptInterface
public String SelectLocationMode()
{
final Object lock = new Object();
String current = CurrentLocationMode();
String[] res = { current };
synchronized(lock) {
try
{
RunOnUIThread(() -> {
AlertDialog.Builder builder = new AlertDialog.Builder(m_context);
String[] locationModeLabels = m_context.getResources().getStringArray(R.array.location_mode_labels);
String[] locationModeValues = m_context.getResources().getStringArray(R.array.location_mode_values);

List<String> locationModeList = new ArrayList<>(Arrays.asList(locationModeLabels));
List<String> locationModeValueList = new ArrayList<>(Arrays.asList(locationModeValues));

int[] selected = { locationModeValueList.indexOf(current) };

builder.setTitle("选择定位方式")
.setSingleChoiceItems(locationModeList.toArray(new String[0]), selected[0], (DialogInterface dialog, int which) -> {
selected[0] = which;
})
//.setCancelable(false)
;

builder.setPositiveButton("确定", (DialogInterface dialog, int which) -> {
if(selected[0] >= 0)
{
String mode = locationModeValueList.get(selected[0]);
if(NSEnums.LocationMode.H5.equalsIgnoreCase(mode))
{
if(!NSConstants.IsHttps())
{
Toast.makeText(m_context, "当前不支持H5定位", Toast.LENGTH_SHORT).show();
return;
}
}

preference.SetString(NSPreference.LOCATION_MODE, mode);
res[0] = mode;
String name = locationModeList.get(selected[0]);
Toast.makeText(m_context, "使用" + name + "定位", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(m_context, "请选择定位方式", Toast.LENGTH_SHORT).show();
});
builder.setNeutralButton("默认", (DialogInterface dialog, int which) -> {
res[0] = NSConstants.DEFAULT_LOCATION_MODE;
preference.SetString(NSPreference.LOCATION_MODE, res[0]);
int choose = locationModeValueList.indexOf(res[0]);
String name = locationModeList.get(choose);
Toast.makeText(m_context, "使用" + name + "定位", Toast.LENGTH_SHORT).show();
});
builder.setNegativeButton("取消", null);

AlertDialog dialog = builder.create();
dialog.setOnDismissListener((DialogInterface d) -> {
synchronized(lock) {
lock.notifyAll();
}
});
dialog.show();
});
lock.wait();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return res[0];
}

private String ReturnLocation(NSLocationInfo loc)
{
return loc.longitude + "," + loc.latitude;
@@ -170,7 +268,9 @@ public class NSEnvWindowObject
realtimeLocation.Init(flag);
}
long start = System.currentTimeMillis();
loc = realtimeLocation.Read(preference.GetIntFromString(NSPreference.LOCATION_REALTIME_READ_COUNT, NSConstants.DEFAULT_LOCATION_REALTIME_READ_COUNT));
int count = preference.GetIntFromString(NSPreference.LOCATION_REALTIME_READ_COUNT, NSConstants.DEFAULT_LOCATION_REALTIME_READ_COUNT);
int timeout = preference.GetIntFromString(NSPreference.LOCATION_TIMEOUT, NSConstants.DEFAULT_LOCATION_TIMEOUT);
loc = realtimeLocation.Read(count, timeout);
long end = System.currentTimeMillis();
Log.i(ID_TAG, "系统实时定位结果: " + loc + ", 耗时=" + (end - start) + "毫秒");
}
@@ -194,7 +294,9 @@ public class NSEnvWindowObject
amapLocation.Init(NSAMapLocation.DEFAULT_FLAG | NSAMapLocation.FLAG_BUILTIN_THREAD);
}
long start = System.currentTimeMillis();
loc = amapLocation.Read(preference.GetIntFromString(NSPreference.LOCATION_GAODE_READ_COUNT, NSConstants.DEFAULT_LOCATION_GAODE_READ_COUNT));
int count = preference.GetIntFromString(NSPreference.LOCATION_GAODE_READ_COUNT, NSConstants.DEFAULT_LOCATION_GAODE_READ_COUNT);
int timeout = preference.GetIntFromString(NSPreference.LOCATION_TIMEOUT, NSConstants.DEFAULT_LOCATION_TIMEOUT);
loc = amapLocation.Read(count, timeout);
long end = System.currentTimeMillis();
Log.i(ID_TAG, "高德定位结果: " + loc + ", 耗时=" + (end - start) + "毫秒");
}


+ 14
- 12
app/src/main/res/values/arrays.xml Dosyayı Görüntüle

@@ -2,25 +2,27 @@

<resources>

<string-array name="location_scheme_values">
<item>system</item>
<item>gaode</item>
<string-array name="location_mode_labels">
<item>系统(实时)</item>
<item>系统</item>
<item>H5</item>
<!--<item>高德</item>-->
</string-array>

<string-array name="location_mode_values">
<item>realtime</item>
<item>system</item>
<item>h5</item>
<!--<item>gaode</item>-->
</string-array>

<string-array name="location_scheme_labels">
<item>系统</item>
<item>高德</item>
<item>系统实时</item>
<string-array name="location_provider_labels">
<item>卫星</item>
<item>网络</item>
</string-array>

<string-array name="location_provider_values">
<item>gps</item>
<item>network</item>
</string-array>

<string-array name="location_provider_labels">
<item>GPS</item>
<item>网络</item>
</string-array>
</resources>

+ 21
- 4
app/src/main/res/xml/settings_preference.xml Dosyayı Görüntüle

@@ -26,14 +26,23 @@
/>
<ListPreference
android:dialogTitle="定位方式"
android:key="location_scheme"
android:entries="@array/location_scheme_labels"
android:entryValues="@array/location_scheme_values"
android:key="location_mode"
android:entries="@array/location_mode_labels"
android:entryValues="@array/location_mode_values"
android:summary="定位方式"
android:persistent="true"
android:title="选择定位方式"
android:defaultValue="realtime"
/>
<EditTextPreference
android:dialogTitle="定位超时(毫秒) 0为不超时"
android:key="location_timeout"
android:summary="定位超时"
android:persistent="true"
android:title="设置定位超时"
android:inputType="number"
android:defaultValue="0"
/>
</PreferenceCategory>

<PreferenceCategory
@@ -90,7 +99,7 @@
android:persistent="true"
android:title="设置定位距离"
android:inputType="number"
android:defaultValue="1"
android:defaultValue="0"
/>
<EditTextPreference
android:dialogTitle="每次定位次数"
@@ -107,6 +116,14 @@
android:key="other"
android:title="其他"
>
<SwitchPreference
android:title="控制台输出到logcat"
android:key="logcat_console_output"
android:persistent="true"
android:defaultValue="false"
android:summary="控制台输出到logcat"
/>

<Preference
android:key="RESET_SETTINGS"
android:summary="重置所有设置为默认值"


Yükleniyor…
İptal
Kaydet