Commit 9d78c49e authored by Administrator's avatar Administrator

udpate

parent 17de1ef6
......@@ -44,7 +44,7 @@ public class AppsActivity extends AppCompatActivity {
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
mRecyclerView.setHasFixedSize(true);
//创建并设置Adapter
mAppAdapter = new AppAdapter(AppsActivity.this);
mAppAdapter = new AppAdapter();
mRecyclerView.setAdapter(mAppAdapter);
initAppList(false);
}
......
......@@ -44,7 +44,7 @@ import top.littlerich.virtuallocation.listener.AsyncLocationResultListener;
import top.littlerich.virtuallocation.listener.GeoCoderListener;
import top.littlerich.virtuallocation.listener.MapClickListener;
import top.littlerich.virtuallocation.listener.MarkerDragListener;
import top.littlerich.virtuallocation.util.LocationUtil;
import top.littlerich.virtuallocation.model.Gps;
import top.littlerich.virtuallocation.util.PermissionUtil;
import top.littlerich.virtuallocation.view.TopBanner;
......@@ -207,7 +207,6 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mStopMock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LocationUtil.stopMockLocation();
Toast.makeText(MainActivity.this, "虚拟定位已暂停!", Toast.LENGTH_SHORT).show();
bt_Ok.setText("立即穿越");
}
......@@ -217,28 +216,13 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
@Override
protected void IniData() {
inilocation();
iniMap();
if (mOperatingAnim != null) {
mCurrentLocation.startAnimation(mOperatingAnim);
}
}
/**
* inilocation 初始化 位置模拟
*/
private void inilocation() {
try {
if (LocationUtil.initLocation(MainActivity.this)) {
LocationUtil.initLocationManager();
}
} catch (Exception e) {
Toast.makeText(MainActivity.this, "虚拟定位功能未打开!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
/**
* iniMap 初始化地图
......@@ -259,15 +243,14 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mLocClient.start();
initOverlay();
// 开启线程,一直修改GPS坐标
LocationUtil.startLocaton();
}
/**
* initOverlay 设置覆盖物,这里就是地图上那个点
*/
private void initOverlay() {
LatLng ll = new LatLng(AppApplication.mMockGps.mLatitude, AppApplication.mMockGps.mLongitude);
Gps configGPS = AppApplication.getConfigGPS();
LatLng ll = new LatLng(configGPS.mLatitude, configGPS.mLongitude);
OverlayOptions oo = new MarkerOptions().position(ll).icon(bd).zIndex(9)
.draggable(true);
mMarker = (Marker) (mBaiduMap.addOverlay(oo));
......@@ -357,13 +340,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
latitude = curLatlng.latitude;
longitude = curLatlng.longitude;
try {
LocationUtil.initLocation(MainActivity.this);
LocationUtil.initLocationManager();
LocationUtil.setLongitudeAndLatitude(curLatlng.longitude, curLatlng.latitude);
AppApplication.mMockGps.mLatitude = curLatlng.latitude;
AppApplication.mMockGps.mLongitude = curLatlng.longitude;
AppApplication.saveConfigGPS(longitude, latitude);
bt_Ok.setText("穿越完成");
} catch (Exception e) {
e.printStackTrace();
......
......@@ -18,11 +18,9 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.virjar.ratel.virtuallocation.R;
import top.littlerich.virtuallocation.presenter.JellyInterpolator;
import top.littlerich.virtuallocation.util.LocationUtil;
import top.littlerich.virtuallocation.view.TopBanner;
public class PreciseLocationActivity extends AppCompatActivity {
......@@ -48,8 +46,6 @@ public class PreciseLocationActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
try {
LocationUtil.setLongitudeAndLatitude(Double.valueOf(mLongitudeValue.getText().toString()),
Double.valueOf(mLatitudeValue.getText().toString()));
width = mBeginLocation.getMeasuredWidth();
float height = mBeginLocation.getMeasuredHeight();
inputAnimator(mBeginLocation, width, height);
......@@ -61,7 +57,7 @@ public class PreciseLocationActivity extends AppCompatActivity {
mTopbanner.setTopBannerListener(new TopBanner.OnTopBannerListener() {
@Override
public void leftClick(View v) {
finish();
finish();
}
@Override
......@@ -82,9 +78,10 @@ public class PreciseLocationActivity extends AppCompatActivity {
/**
* 使组件变回原有形状
*
* @param view
*/
private void repaintView(final View view){
private void repaintView(final View view) {
AnimatorSet set = new AnimatorSet();
ValueAnimator animator = ValueAnimator.ofFloat(width, 0);
......@@ -110,12 +107,12 @@ public class PreciseLocationActivity extends AppCompatActivity {
}
private void initViews() {
mLatitudeValue = (EditText)findViewById(R.id.et_latitude);
mLongitudeValue = (EditText)findViewById(R.id.et_longitude);
mBeginLocation = (AppCompatButton)findViewById(R.id.btn_precise_location);
mLatitudeValue = (EditText) findViewById(R.id.et_latitude);
mLongitudeValue = (EditText) findViewById(R.id.et_longitude);
mBeginLocation = (AppCompatButton) findViewById(R.id.btn_precise_location);
mTopbanner = (TopBanner) findViewById(R.id.topbanner);
mPbLocating = (ProgressBar)findViewById(R.id.pb_locating);
mTip = (TextView)findViewById(R.id.tv_tip);
mPbLocating = (ProgressBar) findViewById(R.id.pb_locating);
mTip = (TextView) findViewById(R.id.tv_tip);
}
......@@ -190,7 +187,7 @@ public class PreciseLocationActivity extends AppCompatActivity {
animator3.start();
}
public static void openActivity(Context context){
public static void openActivity(Context context) {
Intent intent = new Intent(context, PreciseLocationActivity.class);
context.startActivity(intent);
}
......
package top.littlerich.virtuallocation.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -13,7 +14,7 @@ import com.virjar.ratel.virtuallocation.R;
import java.util.ArrayList;
import java.util.List;
import top.littlerich.virtuallocation.common.AppApplication;
import top.littlerich.virtuallocation.model.MyAppInfo;
/**
......@@ -23,17 +24,24 @@ import top.littlerich.virtuallocation.model.MyAppInfo;
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.ViewHolder> {
List<MyAppInfo> mListData = new ArrayList<MyAppInfo>();
private Context mContext;
public AppAdapter(Context context) {
mContext = context;
public AppAdapter() {
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_app_info, parent, false);
ViewHolder vh = new ViewHolder(view);
return vh;
public ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_app_info, parent, false);
final ViewHolder viewHolder = new ViewHolder(view);
viewHolder.cbAppSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppApplication.setAppMock(viewHolder.myAppInfo.getPkgName(), isChecked);
}
});
return viewHolder;
}
@Override
......@@ -42,6 +50,10 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.ViewHolder> {
holder.iv_app_icon.setImageDrawable(myAppInfo.getImage());
holder.tx_app_name.setText(myAppInfo.getAppName());
holder.tx_app_pkg.setText(myAppInfo.getPkgName());
holder.myAppInfo = myAppInfo;
holder.cbAppSelect.setChecked(
AppApplication.getAppMockStatus(myAppInfo.getPkgName())
);
}
@Override
......@@ -82,12 +94,15 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.ViewHolder> {
ImageView iv_app_icon;
TextView tx_app_name;
TextView tx_app_pkg;
CheckBox cbAppSelect;
MyAppInfo myAppInfo;
public ViewHolder(View itemView) {
super(itemView);
iv_app_icon = (ImageView) itemView.findViewById(R.id.iv_app_icon);
tx_app_name = (TextView) itemView.findViewById(R.id.tv_app_name);
tx_app_pkg = (TextView)itemView.findViewById(R.id.tv_app_pkg);
iv_app_icon = itemView.findViewById(R.id.iv_app_icon);
tx_app_name = itemView.findViewById(R.id.tv_app_name);
tx_app_pkg = itemView.findViewById(R.id.tv_app_pkg);
cbAppSelect = itemView.findViewById(R.id.cb_app_select);
}
}
}
......@@ -9,8 +9,15 @@ import android.os.Vibrator;
import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import org.json.JSONObject;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import top.littlerich.virtuallocation.model.Gps;
import top.littlerich.virtuallocation.service.LocationService;
import top.littlerich.virtuallocation.util.FileUtils;
import top.littlerich.virtuallocation.util.PermissionUtil;
/**
......@@ -20,18 +27,12 @@ public class AppApplication extends Application {
public LocationService locationService;
public Vibrator mVibrator;
/**
* 全局GPS
*/
public static Gps mMockGps;
static {
mMockGps = Config.COMPANY;
}
private static AppApplication appApplication;
@Override
public void onCreate() {
super.onCreate();
appApplication = this;
/***
* 初始化定位sdk,建议在Application中创建
*/
......@@ -48,4 +49,56 @@ public class AppApplication extends Application {
}
public static void setAppMock(String pkg, boolean isChecked) {
File configFile = new File(appApplication.getFilesDir(), pkg + "_status.conf");
if (isChecked) {
try {
FileWriter fileWriter = new FileWriter(configFile);
fileWriter.write("mock");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
} else if (configFile.exists()) {
configFile.delete();
}
}
public static boolean getAppMockStatus(String pkg) {
File configFile = new File(appApplication.getFilesDir(), pkg + "_status.conf");
return configFile.exists();
}
public static Gps getConfigGPS() {
File configFile = new File(appApplication.getFilesDir(), "mockGPS.json");
if (!configFile.exists()) {
return Config.COMPANY;
}
try {
String config = FileUtils.readLine(configFile);
JSONObject jsonObject = new JSONObject(config);
double longitude = jsonObject.optDouble("longitude");
double latitude = jsonObject.optDouble("latitude");
return new Gps(latitude, longitude);
} catch (Exception e) {
e.printStackTrace();
return Config.COMPANY;
}
}
public static void saveConfigGPS(double longitude, double latitude) {
File configFile = new File(appApplication.getFilesDir(), "mockGPS.json");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("longitude", longitude);
jsonObject.put("latitude", latitude);
FileUtils.writeLine(configFile, jsonObject.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package top.littlerich.virtuallocation.presenter;
import android.util.Log;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import top.littlerich.virtuallocation.common.AppApplication;
/**
* Created by xuqingfu on 2017/5/26.
*/
......@@ -20,23 +14,23 @@ public class HookApis {
* @throws ClassNotFoundException
*/
public static void findMethodAmapLongitudeAndLatitude(ClassLoader classLoader) {
try {
Class aMapLocationClazz = classLoader.loadClass("com.amap.api.location.AMapLocation");
XposedHelpers.findAndHookMethod(aMapLocationClazz, "getLongitude", new Object[]{new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam arg3) throws Throwable {
arg3.setResult(Double.valueOf(AppApplication.mMockGps.mLongitude));
Log.d(TAG, "修改高德地图的经纬度值:" + AppApplication.mMockGps.mLongitude + ":" + AppApplication.mMockGps.mLatitude);
}
}});
XposedHelpers.findAndHookMethod(aMapLocationClazz, "getLatitude", new Object[]{new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam arg3) throws Throwable {
arg3.setResult(Double.valueOf(AppApplication.mMockGps.mLatitude));
}
}});
} catch (Exception e) {
Log.i(TAG, "该程序无高德地图模块,无法HOOK");
}
// try {
// Class aMapLocationClazz = classLoader.loadClass("com.amap.api.location.AMapLocation");
// XposedHelpers.findAndHookMethod(aMapLocationClazz, "getLongitude", new Object[]{new XC_MethodHook() {
// protected void beforeHookedMethod(MethodHookParam arg3) throws Throwable {
// arg3.setResult(Double.valueOf(AppApplication.mMockGps.mLongitude));
// Log.d(TAG, "修改高德地图的经纬度值:" + AppApplication.mMockGps.mLongitude + ":" + AppApplication.mMockGps.mLatitude);
// }
// }});
//
// XposedHelpers.findAndHookMethod(aMapLocationClazz, "getLatitude", new Object[]{new XC_MethodHook() {
// protected void beforeHookedMethod(MethodHookParam arg3) throws Throwable {
// arg3.setResult(Double.valueOf(AppApplication.mMockGps.mLatitude));
// }
// }});
// } catch (Exception e) {
// Log.i(TAG, "该程序无高德地图模块,无法HOOK");
// }
}
......
package top.littlerich.virtuallocation.util;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileUtils {
public static final boolean IS_USING_PROTECTED_STORAGE = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
/**
* Delete a file or a directory and its children.
*
* @param file The directory to delete.
* @throws IOException Exception when problem occurs during deleting the directory.
*/
public static void delete(File file) throws IOException {
for (File childFile : file.listFiles()) {
if (childFile.isDirectory()) {
delete(childFile);
} else {
if (!childFile.delete()) {
throw new IOException();
}
}
}
if (!file.delete()) {
throw new IOException();
}
}
public static String readLine(File file) {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return reader.readLine();
} catch (Throwable throwable) {
return "";
}
}
public static void writeLine(File file, String line) {
try {
file.createNewFile();
} catch (IOException ex) {
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(line);
writer.flush();
} catch (Throwable throwable) {
Log.e("virjar", "error writing line to file " + file + ": " + throwable.getMessage());
}
}
public static String getPackageName(String dataDir) {
if (TextUtils.isEmpty(dataDir)) {
Log.e("virjar", "getPackageName using empty dataDir");
return "";
}
int lastIndex = dataDir.lastIndexOf("/");
if (lastIndex < 0) {
return dataDir;
}
return dataDir.substring(lastIndex + 1);
}
public static String getDataPathPrefix() {
return IS_USING_PROTECTED_STORAGE ? "/data/user_de/0/" : "/data/data/";
}
}
package top.littlerich.virtuallocation.util;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
/**
* Created by xuqingfu on 2017/4/24.
*/
public class LocationUtil {
private static final String TAG = "silence";
private static Double mLatitude = 30.6363334898;
private static Double mLongitude = 104.0486168861;
private static LocationManager locationManager;
private static Thread mMockThread;
/**
* 初始化模拟定位,并检测是否开启ADB模拟定位
*
* @param context
* @return
*/
public static boolean initLocation(Context context) {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return false;
}
/**
* 配置LocationManger参数
*/
public static void initLocationManager() throws Exception {
}
/**
* 开启虚拟定位线程
*/
public static void startLocaton() {
}
/**
* GPS定位需要不停的刷新经纬度值
*/
private static void setLocation(double latitude, double longitude) throws Exception {
try {
String providerStr = LocationManager.GPS_PROVIDER;
Location mockLocation = new Location(providerStr);
mockLocation.setLatitude(latitude);
mockLocation.setLongitude(longitude);
mockLocation.setAltitude(0); // 高程(米)
mockLocation.setBearing(0); // 方向(度)
mockLocation.setSpeed(0); //速度(米/秒)
mockLocation.setAccuracy(2); // 精度(米)
mockLocation.setTime(System.currentTimeMillis()); // 本地时间
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
//api 16以上的需要加上这一句才能模拟定位 , 也就是targetSdkVersion > 16
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
} catch (Exception e) {
// 防止用户在软件运行过程中关闭模拟位置或选择其他应用
stopMockLocation();
throw e;
}
}
public static void stopMockLocation() {
}
/**
* 设置地理经纬度值
*
* @param mLongitude
* @param mLatitude
*/
public static void setLongitudeAndLatitude(Double mLongitude, Double mLatitude) {
LocationUtil.mLatitude = mLatitude;
LocationUtil.mLongitude = mLongitude;
}
/**
* 监听Location经纬度值的修改状态
*/
private static class LocationStatuListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
double lat = location.getLatitude();
double lng = location.getLongitude();
Log.i(TAG, String.format("location: x=%s y=%s", lat, lng));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
}
package top.littlerich.virtuallocation.util;
import android.content.Context;
import android.content.SharedPreferences;
import top.littlerich.virtuallocation.common.Common;
import static android.content.Context.MODE_PRIVATE;
/**
* Created by xuqingfu on 2017/3/14.
*/
public class SharePreferenceUtil {
private static final String SP_FILENAME = "config";
public static void saveData(Context context, String userName, String psd) {
SharedPreferences sp = context.getSharedPreferences(SP_FILENAME, MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(Common.SP_FILTER_APP_PKG_NAME, userName);
editor.commit();
}
public static boolean loadData(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_FILENAME, MODE_PRIVATE);
// Common.USER_NAME = sp.getString(Common.SP_FILTER_APP_PKG_NAME, "").toString();
/*if (TextUtils.isEmpty(Common.USER_NAME) || TextUtils.isEmpty(Common.USER_PWD)) {
return false;
}*/
return true;
}
public static void cleanData(Context context){
saveData(context, "", "");
}
}
......@@ -54,6 +54,7 @@
</LinearLayout>
<CheckBox
android:id="@+id/cb_app_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment