Selaa lähdekoodia

字段搜索修改为全部可搜索

Bitliker 7 vuotta sitten
vanhempi
commit
deb044bf6a

+ 2 - 0
app_core/common/src/main/java/com/core/app/MyApplication.java

@@ -39,6 +39,7 @@ import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
 import com.tencent.mm.opensdk.openapi.IWXAPI;
 import com.tencent.mm.opensdk.openapi.WXAPIFactory;
 import com.uas.applocation.UasLocationHelper;
+import com.uas.applocation.utils.AreaUtils;
 import com.umeng.analytics.MobclickAgent;
 import com.umeng.socialize.Config;
 import com.umeng.socialize.PlatformConfig;
@@ -172,6 +173,7 @@ public class MyApplication extends BaseApplication {
     }
 
     private void initLocation(){
+        AreaUtils.initArea(this);
         UasLocationHelper.getInstance().initConfig(this);
     }
     public void initShareAPI() {

+ 1 - 0
app_modular/applocation/build.gradle

@@ -16,6 +16,7 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     }
+
 }
 
 dependencies {

+ 7 - 2
app_modular/applocation/src/main/AndroidManifest.xml

@@ -1,8 +1,13 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    package="com.uas.applocation" >
+    package="com.uas.applocation">
 
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
-    <uses-permission android:name="android.permission.WRITE_SETTINGS"
+    <uses-permission
+        android:name="android.permission.WRITE_SETTINGS"
         tools:ignore="ProtectedPermissions" />
+
+    <application>
+        <activity android:name=".test.LocationTestSetActivity" />
+    </application>
 </manifest>

+ 12 - 0
app_modular/applocation/src/main/java/com/uas/applocation/UasLocationHelper.java

@@ -50,8 +50,17 @@ public class UasLocationHelper implements BaseLocationManager {
                 mLocationHelper = new NativeLocationManager(this.ct);
                 break;
         }
+        if (mLocationHelper!=null){
+            mLocationHelper.requestLocation(mOnLocationListener);
+        }
     }
 
+    //TODO 正式版本需要去除,必须去除
+    private UASLocation mTestUASLocation;
+    public void testStopLocation(UASLocation mUASLocation){
+        this.mTestUASLocation=mUASLocation;
+        release();
+    }
 
     @Override
     public void release() {
@@ -81,6 +90,9 @@ public class UasLocationHelper implements BaseLocationManager {
 
     @Override
     public UASLocation getUASLocation() {
+        if (this.mTestUASLocation!=null){
+            return this.mTestUASLocation;
+        }
         return mLocationHelper == null ? new UASLocation(UASLocation.TYPE_BAIDU) : mLocationHelper.getUASLocation();
     }
 

+ 2 - 0
app_modular/applocation/src/main/java/com/uas/applocation/base/NativeLocationManager.java

@@ -99,6 +99,8 @@ public class NativeLocationManager implements BaseLocationManager {
         mUASLocation.setAddress(address.getAddressLine(0));
         LatLng latlng = CoordinateUtils.common2Baidu(new LatLng(address.getLatitude(), address.getLongitude()));
 //         latlng = CoordinateUtils.common2Baidu(new LatLng(33.144513, 103.910688));
+        mUASLocation.setGpsLatitude(address.getLatitude());
+        mUASLocation.setGpsLongitude(address.getLongitude());
         mUASLocation.setLatitude(latlng.latitude);
         mUASLocation.setLongitude(latlng.longitude);
         if (mOnLocationListener != null) {

+ 16 - 0
app_modular/applocation/src/main/java/com/uas/applocation/model/UASLocation.java

@@ -102,6 +102,22 @@ public class UASLocation implements Parcelable {
         this.latitude = latitude;
     }
 
+    public double getGpsLatitude() {
+        return gpsLatitude;
+    }
+
+    public void setGpsLatitude(double gpsLatitude) {
+        this.gpsLatitude = gpsLatitude;
+    }
+
+    public double getGpsLongitude() {
+        return gpsLongitude;
+    }
+
+    public void setGpsLongitude(double gpsLongitude) {
+        this.gpsLongitude = gpsLongitude;
+    }
+
     public double getLongitude() {
         return longitude;
     }

+ 148 - 0
app_modular/applocation/src/main/java/com/uas/applocation/test/LocationTestSetActivity.java

@@ -0,0 +1,148 @@
+package com.uas.applocation.test;
+
+import android.content.DialogInterface;
+import android.location.Address;
+import android.location.Geocoder;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.baidu.mapapi.model.LatLng;
+import com.uas.applocation.R;
+import com.uas.applocation.UasLocationHelper;
+import com.uas.applocation.model.UASLocation;
+import com.uas.applocation.utils.AreaUtils;
+import com.uas.applocation.utils.CoordinateUtils;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Locale;
+
+public class LocationTestSetActivity extends AppCompatActivity {
+    private TextView currentInfoTv;
+    private CheckBox userNativeCb;
+    private CheckBox inventedCb;
+    private EditText longitudeEd;
+    private EditText latitudeEd;
+    private Button saveBtn;
+    private RelativeLayout inventedRl;
+    private LinearLayout inventedLL;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_location_test_set);
+        initView();
+    }
+
+    private void initView() {
+        currentInfoTv = (TextView) findViewById(R.id.currentInfoTv);
+        userNativeCb = (CheckBox) findViewById(R.id.userNativeCb);
+        inventedCb = (CheckBox) findViewById(R.id.inventedCb);
+        longitudeEd = (EditText) findViewById(R.id.longitudeEd);
+        latitudeEd = (EditText) findViewById(R.id.latitudeEd);
+        saveBtn = (Button) findViewById(R.id.saveBtn);
+        inventedRl = findViewById(R.id.inventedRl);
+        inventedLL = findViewById(R.id.inventedLL);
+
+        saveBtn.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                new AlertDialog.Builder(LocationTestSetActivity.this)
+                        .setTitle("UU提示")
+                        .setMessage("保存模拟定位以后,将不会再自动定位,直到退出应用或关闭虚拟定位。是否确定保存")
+                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialogInterface, int i) {
+                                UASLocation mUASLocation=getInventedUASLocation();
+                                UasLocationHelper.getInstance().testStopLocation(mUASLocation);
+                                currentInfoTv.setText(mUASLocation.toString());
+                            }
+                        })
+                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialogInterface, int i) {
+
+                            }
+                        }).show();
+            }
+        });
+
+        UASLocation mUASLocation = UasLocationHelper.getInstance().getUASLocation();
+        if (mUASLocation != null) {
+            currentInfoTv.setText(mUASLocation.toString());
+            int type = AreaUtils.getLocationServiceType();
+            boolean userNative = type == UASLocation.TYPE_NATIVE;
+            userNativeCb.setChecked(userNative);
+            inventedRl.setVisibility(userNative ? View.VISIBLE : View.GONE);
+            showInventedLL(inventedCb.isChecked());
+            longitudeEd.setText(mUASLocation.getLongitude() + "");
+            latitudeEd.setText(mUASLocation.getLatitude() + "");
+        }
+        userNativeCb.setOnCheckedChangeListener(mOnCheckedChangeListener);
+        inventedCb.setOnCheckedChangeListener(mOnCheckedChangeListener);
+    }
+
+    private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
+        @Override
+        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+            if (compoundButton == userNativeCb) {
+                AreaUtils.type = b ? UASLocation.TYPE_NATIVE : UASLocation.TYPE_BAIDU;
+                UasLocationHelper.getInstance().initConfig(LocationTestSetActivity.this);
+                inventedRl.setVisibility(b ? View.VISIBLE : View.GONE);
+            } else if (inventedCb == compoundButton) {
+                showInventedLL(b);
+            }
+        }
+    };
+
+    private void showInventedLL(boolean clicked) {
+        int show = clicked ? View.VISIBLE : View.GONE;
+        inventedLL.setVisibility(show);
+        saveBtn.setVisibility(show);
+        if (!clicked) {
+            UasLocationHelper.getInstance().testStopLocation(null);
+        }
+
+    }
+
+    private UASLocation getInventedUASLocation() {
+        UASLocation mUASLocation = UasLocationHelper.getInstance().getUASLocation();
+        float latitude = Float.valueOf(latitudeEd.getText().toString());
+        float longitude = Float.valueOf(longitudeEd.getText().toString());
+        Geocoder gc = new Geocoder(this, Locale.getDefault());
+        List<Address> locationList = null;
+        try {
+            locationList = gc.getFromLocation(latitude, longitude, 1);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        if (locationList != null && locationList.size() > 0) {
+            Address address = locationList.get(0);//得到Address实例
+            mUASLocation.setLocationOk(true);
+            mUASLocation.setProvince(address.getLocality());
+            mUASLocation.setCityName(address.getSubAdminArea());
+            mUASLocation.setCountry(address.getCountryName());
+            mUASLocation.setName(address.getFeatureName());
+            mUASLocation.setDistrict(address.getThoroughfare());
+            mUASLocation.setAddress(address.getAddressLine(0));
+            LatLng latlng = CoordinateUtils.common2Baidu(new LatLng(address.getLatitude(), address.getLongitude()));
+            mUASLocation.setGpsLatitude(address.getLatitude());
+            mUASLocation.setGpsLongitude(address.getLongitude());
+            mUASLocation.setLatitude(latlng.latitude);
+            mUASLocation.setLongitude(latlng.longitude);
+        }
+        return mUASLocation;
+    }
+}

+ 81 - 1
app_modular/applocation/src/main/java/com/uas/applocation/utils/AreaUtils.java

@@ -1,16 +1,96 @@
 package com.uas.applocation.utils;
 
+import android.content.Context;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.Log;
+
 import com.uas.applocation.model.UASLocation;
 
+import java.util.Locale;
+
 /**
  * 判读当前所在的地区
  */
 public class AreaUtils {
-    public static int type=UASLocation.TYPE_BAIDU;
+    public static int type = UASLocation.TYPE_BAIDU;
+
+    /**
+     * 判断当前的卡是否是国内的卡,如果是国内的开,是不能使用google服务的
+     *
+     * @param context
+     */
+    public static void initArea(Context context) {
+        type = isChinaSimCard(context) ? UASLocation.TYPE_BAIDU : UASLocation.TYPE_NATIVE;
+        Log.i("gong","type="+type);
+    }
 
     public static int getLocationServiceType() {
         return type;
     }
 
+    /**
+     * 判断国家是否是国内用户
+     * <p>
+     * 方法一
+     *
+     * @return
+     */
+    public static boolean isCN(Context context) {
+        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+        String countryIso = tm.getSimCountryIso();
+        boolean isCN = false;//判断是不是大陆
+        if (!TextUtils.isEmpty(countryIso)) {
+            countryIso = countryIso.toUpperCase(Locale.US);
+            if (countryIso.contains("CN")) {
+                isCN = true;
+            }
+        }
+        return isCN;
 
+    }
+
+
+/**
+ * 方法二
+ */
+    /**
+     * 查询手机的 MCC+MNC
+     */
+    private static String getSimOperator(Context c) {
+        TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
+        try {
+            return tm.getSimOperator();
+        } catch (Exception e) {
+
+        }
+        return null;
+    }
+
+
+    /**
+     * 因为发现像华为Y300,联想双卡的手机,会返回 "null" "null,null" 的字符串
+     */
+    private static boolean isOperatorEmpty(String operator) {
+        if (operator == null) {
+            return true;
+        }
+        if (operator.equals("") || operator.toLowerCase(Locale.US).contains("null")) {
+            return true;
+        }
+        return false;
+    }
+
+
+    /**
+     * 判断是否是国内的 SIM 卡,优先判断注册时的mcc
+     */
+    public static boolean isChinaSimCard(Context c) {
+        String mcc = getSimOperator(c);
+        if (isOperatorEmpty(mcc)) {
+            return true;//默认是国内
+        } else {
+            return mcc.startsWith("460");
+        }
+    }
 }

+ 117 - 0
app_modular/applocation/src/main/res/layout/activity_location_test_set.xml

@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingLeft="8dp"
+    android:paddingRight="8dp">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/currentInfoTv"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="8dp"
+            android:layout_marginTop="8dp"
+            android:text="当前" />
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="1px"
+            android:background="#000000" />
+
+        <RelativeLayout
+            android:layout_width="match_parent"
+            android:layout_height="50dp">
+
+            <android.support.v7.widget.AppCompatTextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_centerVertical="true"
+                android:text="使用原生地图" />
+
+            <CheckBox
+                android:id="@+id/userNativeCb"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentRight="true"
+                android:layout_centerVertical="true" />
+        </RelativeLayout>
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="1px"
+            android:background="#000000" />
+
+
+        <RelativeLayout
+            android:id="@+id/inventedRl"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <RelativeLayout
+                android:layout_width="match_parent"
+                android:layout_height="50dp">
+
+                <android.support.v7.widget.AppCompatTextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_centerVertical="true"
+                    android:text="当前定位为国内,是否开启模拟定位" />
+
+                <CheckBox
+                    android:id="@+id/inventedCb"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentRight="true"
+                    android:layout_centerVertical="true" />
+            </RelativeLayout>
+
+
+            <LinearLayout
+                android:id="@+id/inventedLL"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="51dp"
+                android:orientation="horizontal">
+
+                <EditText
+                    android:id="@+id/longitudeEd"
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:hint="经度"
+                    android:inputType="numberDecimal" />
+
+                <EditText
+                    android:id="@+id/latitudeEd"
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:hint="纬度"
+                    android:inputType="numberDecimal" />
+            </LinearLayout>
+
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="1px"
+                android:layout_alignParentBottom="true"
+                android:background="#000000" />
+
+
+        </RelativeLayout>
+
+        <Button
+            android:id="@+id/saveBtn"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:layout_marginTop="20dp"
+            android:text="保存模拟定位" />
+
+    </LinearLayout>
+</ScrollView>

+ 10 - 20
app_modular/appme/src/main/java/com/uas/appme/settings/activity/SettingActivity.java

@@ -64,9 +64,7 @@ import com.me.network.app.http.rx.ResultListener;
 import com.me.network.app.http.rx.ResultSubscriber;
 import com.modular.apputils.utils.PopupWindowHelper;
 import com.scwang.smartrefresh.layout.util.DensityUtil;
-import com.uas.applocation.UasLocationHelper;
-import com.uas.applocation.model.UASLocation;
-import com.uas.applocation.utils.AreaUtils;
+import com.uas.applocation.test.LocationTestSetActivity;
 import com.uas.appme.R;
 import com.uas.appme.pedometer.view.NewStepActivity;
 import com.uas.appme.pedometer.view.StepSplashActivity;
@@ -128,7 +126,7 @@ public class SettingActivity extends SupportToolBarActivity implements View.OnCl
 
 
     private void initView() {
-        font_us_rl=findViewById(R.id.font_us_rl);
+        font_us_rl = findViewById(R.id.font_us_rl);
         uas_website_tv = (TextView) findViewById(R.id.uas_website_tv);
         tv_menu_setting = (TextView) findViewById(R.id.tv_menu_setting);
         cb_task_reply = (SwitchView) findViewById(R.id.cb_task_reply);
@@ -255,7 +253,7 @@ public class SettingActivity extends SupportToolBarActivity implements View.OnCl
                 }
             }
         });
-        
+
         new_step_rl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -276,7 +274,7 @@ public class SettingActivity extends SupportToolBarActivity implements View.OnCl
 
         speech_recognition_rl.setOnClickListener(this);
         sign_in_rl.setOnClickListener(this);
-        if (BaseConfig.isDebug()){
+        if (BaseConfig.isDebug()) {
             sign_in_rl.setOnLongClickListener(mTestOnLongClickListener);
         }
         sign_out_rl.setOnClickListener(this);
@@ -295,30 +293,23 @@ public class SettingActivity extends SupportToolBarActivity implements View.OnCl
         font_us_rl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-                startActivity(new Intent(SettingActivity.this,FontSizeActivity.class));
+                startActivity(new Intent(SettingActivity.this, FontSizeActivity.class));
             }
         });
     }
 
-    private View.OnLongClickListener mTestOnLongClickListener=new View.OnLongClickListener() {
+    private View.OnLongClickListener mTestOnLongClickListener = new View.OnLongClickListener() {
         @Override
         public boolean onLongClick(View view) {
 
-            if (BaseConfig.isDebug()){
-                if (view==sign_in_rl){
-                    if (AreaUtils.type== UASLocation.TYPE_NATIVE){
-                        AreaUtils.type=UASLocation.TYPE_BAIDU;
-                        ToastUtil.showToast(ct,"转成百度地图");
-                    }else{
-                        AreaUtils.type=  UASLocation.TYPE_NATIVE;
-                        ToastUtil.showToast(ct,"转成原生地图");
-                    }
-                   UasLocationHelper. getInstance().initConfig(ct.getApplicationContext());
-                }
+            if (BaseConfig.isDebug()) {
+                startActivity(new Intent(ct, LocationTestSetActivity.class));
+                return true;
             }
             return false;
         }
     };
+
     private void doShowBSettingJudge() {
         HttpClient httpClient = new HttpClient.Builder(Constants.IM_BASE_URL()).isDebug(true).build(true);
         httpClient.Api().send(new HttpClient.Builder()
@@ -387,7 +378,6 @@ public class SettingActivity extends SupportToolBarActivity implements View.OnCl
         startActivity(new Intent("com.modular.main.MainActivity"));
         super.onBackPressed();
     }
-    
 
 
     @Override