Search in sources :

Example 1 with AppLocation

use of com.jamesfchen.map.model.AppLocation in project spacecraft-android by JamesfChen.

the class ILbsApiServer method mockRequestLocation.

private void mockRequestLocation() {
    if (listenerlist == null)
        return;
    Type type = new TypeToken<List<L7>>() {
    }.getType();
    List<L7> l7_list = new Gson().fromJson(ResourceUtils.readAssets2String("l7_list.json"), type);
    try {
        Thread.sleep(1500);
        for (L7 l7 : l7_list) {
            double lat = l7.appLocation.lat;
            double lon = l7.appLocation.lon;
            long cid = l7.appCellInfos.get(0).get(0).cid;
            long lac = l7.appCellInfos.get(0).get(0).lac;
            // startservice 回调(onHandleIntent) 和bindservice回调(onServiceConnected) 都是异步,所以sleep模拟onHandleIntent处理耗时,
            // Thread.sleep(500);
            final int N = listenerlist.beginBroadcast();
            for (int i = 0; i < N; i++) {
                ILbsListener l = listenerlist.getBroadcastItem(i);
                if (l == null)
                    continue;
                AppCellInfo appCellInfo = new AppCellInfo();
                appCellInfo.cid = cid;
                appCellInfo.lac = lac;
                appCellInfo.isRegistered = true;
                appCellInfo.isMockData = true;
                AppLocation appLocation = new AppLocation();
                appLocation.lat = lat;
                appLocation.lon = lon;
                appLocation.isMockData = true;
                ++count;
                l.onLocationChanged(appLocation, Collections.singletonList(appCellInfo), count);
            }
            listenerlist.finishBroadcast();
        }
    } catch (InterruptedException | RemoteException e) {
        e.printStackTrace();
    }
}
Also used : Gson(com.google.gson.Gson) L7(com.jamesfchen.map.model.L7) Type(java.lang.reflect.Type) AppCellInfo(com.jamesfchen.map.model.AppCellInfo) ILbsListener(com.jamesfchen.map.ILbsListener) RemoteCallbackList(android.os.RemoteCallbackList) List(java.util.List) AppLocation(com.jamesfchen.map.model.AppLocation) RemoteException(android.os.RemoteException)

Example 2 with AppLocation

use of com.jamesfchen.map.model.AppLocation in project spacecraft-android by JamesfChen.

the class FileIOUtils method write2File.

public static void write2File(File file, Location location, List<CellInfo> cellInfoList, long count, String auth) {
    if (file != null) {
        defalutLbsFile = file;
    }
    AppLocation appLocation = AppLocation.convertSysLocation(location);
    List<AppCellInfo> appCellInfos = AppCellInfo.convertSysCellInfo(cellInfoList);
    StringBuilder contentBuilder = new StringBuilder();
    contentBuilder.append("{");
    contentBuilder.append("\"myId\":" + count + ",");
    contentBuilder.append("\"auth\":" + "\"" + auth + "\"" + ",");
    contentBuilder.append("\"appCellInfos\":[");
    contentBuilder.append(appCellInfos.toString());
    contentBuilder.append("],");
    contentBuilder.append(appLocation.toString());
    contentBuilder.append("}");
    ReportApi.reportLocation(contentBuilder.toString());
    Log.d("FileUtils", "write2File: " + defalutLbsFile.getAbsolutePath() + "\n" + contentBuilder);
    if (!defalutLbsFile.exists()) {
        try {
            defalutLbsFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("FileUtils", "create new file error");
        }
    }
    JsonWriter jsonWriter = null;
    try {
        jsonWriter = new JsonWriter(new OutputStreamWriter(new FileOutputStream(defalutLbsFile, true)));
        jsonWriter.beginObject();
        jsonWriter.name("myId").value(count);
        jsonWriter.name("appCellInfos");
        jsonWriter.beginArray();
        for (int i = 0; i < appCellInfos.size(); i++) {
            AppCellInfo appCellInfo = appCellInfos.get(i);
            if (appCellInfo != null) {
                jsonWriter.beginObject();
                jsonWriter.name("bid").value(appCellInfo.bid);
                jsonWriter.name("cdmalat").value(appCellInfo.cdmalat);
                jsonWriter.name("cdmalon").value(appCellInfo.cdmalon);
                jsonWriter.name("cgiage").value(appCellInfo.cgiage);
                jsonWriter.name("cid").value(appCellInfo.cid);
                jsonWriter.name("lac").value(appCellInfo.lac);
                jsonWriter.name("mcc").value(appCellInfo.mcc);
                jsonWriter.name("mnc").value(appCellInfo.mnc);
                jsonWriter.name("nci").value(appCellInfo.nci);
                jsonWriter.name("nid").value(appCellInfo.nid);
                jsonWriter.name("pci").value(appCellInfo.pci);
                jsonWriter.name("radio_type").value(appCellInfo.radio_type);
                jsonWriter.name("rss").value(appCellInfo.rss);
                jsonWriter.name("sid").value(appCellInfo.sid);
                jsonWriter.name("tac").value(appCellInfo.tac);
                jsonWriter.endObject();
            }
        }
        jsonWriter.endArray();
        jsonWriter.name("location");
        jsonWriter.beginObject();
        jsonWriter.name("lat").value(appLocation.lat);
        jsonWriter.name("lon").value(appLocation.lon);
        jsonWriter.name("accu").value(appLocation.accu);
        jsonWriter.name("altit").value(appLocation.altit);
        jsonWriter.name("bearing").value(appLocation.bearing);
        jsonWriter.name("speed").value(appLocation.speed);
        jsonWriter.endObject();
        jsonWriter.endObject();
        jsonWriter.flush();
    } catch (IOException e) {
        e.printStackTrace();
        Log.e("FileUtils", "write2File: error");
    } finally {
        if (jsonWriter != null) {
            try {
                jsonWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : AppCellInfo(com.jamesfchen.map.model.AppCellInfo) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) AppLocation(com.jamesfchen.map.model.AppLocation) IOException(java.io.IOException) JsonWriter(android.util.JsonWriter)

Aggregations

AppCellInfo (com.jamesfchen.map.model.AppCellInfo)2 AppLocation (com.jamesfchen.map.model.AppLocation)2 RemoteCallbackList (android.os.RemoteCallbackList)1 RemoteException (android.os.RemoteException)1 JsonWriter (android.util.JsonWriter)1 Gson (com.google.gson.Gson)1 ILbsListener (com.jamesfchen.map.ILbsListener)1 L7 (com.jamesfchen.map.model.L7)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Type (java.lang.reflect.Type)1 List (java.util.List)1