WiGLE WiFi Wardriving FOSS v2.63版本的 MD5 值为:20a157bff1dec2e81d8268d404e15cb5
以下内容为反编译后的 DataFragment.java 源代码,内容仅作参考
package net.wigle.wigleandroid;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import net.wigle.m8b.geodesy.mgrs;
import net.wigle.m8b.geodesy.utm;
import net.wigle.m8b.siphash.SipKey;
import net.wigle.wigleandroid.background.ApiListener;
import net.wigle.wigleandroid.background.KmlWriter;
import net.wigle.wigleandroid.background.ObservationImporter;
import net.wigle.wigleandroid.background.ObservationUploader;
import net.wigle.wigleandroid.background.QueryThread;
import net.wigle.wigleandroid.background.TransferListener;
import net.wigle.wigleandroid.db.DBException;
import net.wigle.wigleandroid.db.DatabaseHelper;
import net.wigle.wigleandroid.model.Pair;
import net.wigle.wigleandroid.ui.WiGLEToast;
import net.wigle.wigleandroid.util.FileUtility;
import net.wigle.wigleandroid.util.MagicEightUtil;
import net.wigle.wigleandroid.util.SearchUtil;
import org.json.JSONObject;
public final class DataFragment extends Fragment implements ApiListener, TransferListener, DialogListener {
private static final int BACKUP_DIALOG = 124;
private static final int CSV_DB_DIALOG = 121;
private static final int CSV_RUN_DIALOG = 120;
private static final int DELETE_DIALOG = 128;
private static final int EXPORT_GPX_DIALOG = 130;
private static final int EXPORT_M8B_DIALOG = 129;
private static final String GPX_FOOTER = "</trkseg></trk></gpx>";
private static final String GPX_HEADER_A = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"";
private static final String GPX_HEADER_B = "\" version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\"><trk>\n";
private static final int IMPORT_DIALOG = 125;
private static final int KML_DB_DIALOG = 123;
private static final int KML_RUN_DIALOG = 122;
private static final int MAX_OUT_DIALOG = 127;
private static final int SLICE_BITS = 30;
private static final int ZERO_OUT_DIALOG = 126;
private ProgressDialog pd = null;
@Override
public void requestComplete(JSONObject jSONObject, boolean z) throws WiGLEAuthException {
}
@Override
public void transferComplete() {
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
FragmentActivity activity = getActivity();
if (activity != null) {
MainActivity.setLocale(getActivity());
activity.setVolumeControlStream(3);
}
}
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
View inflate = layoutInflater.inflate(R.layout.data, viewGroup, false);
setupQueryButtons(inflate);
setupCsvButtons(inflate);
setupKmlButtons(inflate);
setupBackupDbButton(inflate);
setupImportObservedButton(inflate);
setupMarkerButtons(inflate);
setupM8bExport(inflate);
setupGpxExport(inflate);
return inflate;
}
private void setupQueryButtons(final View view) {
((Button) view.findViewById(R.id.search_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
String str = SearchUtil.setupQuery(view, DataFragment.this.getActivity(), true);
if (ListFragment.lameStatic.queryArgs != null) {
ListFragment.lameStatic.queryArgs.setSearchWiGLE(false);
}
if (str != null) {
WiGLEToast.showOverFragment(DataFragment.this.getActivity(), R.string.error_general, str);
return;
}
DataFragment.this.startActivity(new Intent(DataFragment.this.getActivity(), DBResultActivity.class));
}
});
((Button) view.findViewById(R.id.reset_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
SearchUtil.clearWiFiBtFields(view);
}
});
}
private void setupCsvButtons(View view) {
((Button) view.findViewById(R.id.csv_run_export_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.data_export_csv), R.id.nav_data, 120);
} else {
MainActivity.error("Null FragmentActivity setting up CSV run export button");
}
}
});
((Button) view.findViewById(R.id.csv_export_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.data_export_csv_db), R.id.nav_data, 121);
} else {
MainActivity.error("Null FragmentActivity setting up CSV export button");
}
}
});
}
private void setupKmlButtons(View view) {
((Button) view.findViewById(R.id.kml_run_export_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.data_export_kml_run), R.id.nav_data, 122);
} else {
MainActivity.error("Null FragmentActivity setting up KML run export button");
}
}
});
((Button) view.findViewById(R.id.kml_export_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.data_export_kml_db), R.id.nav_data, 123);
} else {
MainActivity.error("Null FragmentActivity setting up KML export button");
}
}
});
}
private void setupBackupDbButton(View view) {
((Button) view.findViewById(R.id.backup_db_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.data_backup_db), R.id.nav_data, 124);
} else {
MainActivity.error("Null FragmentActivity setting up backup confirmation");
}
}
});
}
private void setupImportObservedButton(View view) {
Button button = (Button) view.findViewById(R.id.import_observed_button);
FragmentActivity activity = getActivity();
SharedPreferences sharedPreferences = activity != null ? activity.getSharedPreferences(ListFragment.SHARED_PREFS, 0) : null;
if ((sharedPreferences != null ? sharedPreferences.getString(ListFragment.PREF_AUTHNAME, null) : null) == null) {
button.setEnabled(false);
} else if (MainActivity.getMainActivity().isTransferring()) {
button.setEnabled(false);
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity2 = DataFragment.this.getActivity();
if (activity2 != null) {
MainActivity.createConfirmation(activity2, DataFragment.this.getString(R.string.data_import_observed), R.id.nav_data, DataFragment.IMPORT_DIALOG);
} else {
MainActivity.error("unable to get fragment activity");
}
}
});
}
private void createAndStartImport() {
final MainActivity mainActivity = MainActivity.getMainActivity(this);
if (mainActivity != null) {
mainActivity.setTransferring();
}
try {
new ObservationImporter(getActivity(), ListFragment.lameStatic.dbHelper, new ApiListener() {
@Override
public void requestComplete(JSONObject jSONObject, boolean z) {
MainActivity mainActivity2 = mainActivity;
if (mainActivity2 != null) {
try {
mainActivity2.getState().dbHelper.getNetworkCountFromDB();
} catch (DBException e) {
MainActivity.warn("failed DB count update on import-observations", e);
}
mainActivity.transferComplete();
}
}
}).startDownload(this);
} catch (WiGLEAuthException unused) {
MainActivity.info("failed to authorize user on request");
}
}
private void setupMarkerButtons(View view) {
SharedPreferences sharedPreferences = getActivity() != null ? getActivity().getSharedPreferences(ListFragment.SHARED_PREFS, 0) : null;
TextView textView = (TextView) view.findViewById(R.id.reset_maxid_text);
if (sharedPreferences != null) {
textView.setText(getString(R.string.setting_high_up) + " " + sharedPreferences.getLong(ListFragment.PREF_DB_MARKER, 0L));
}
((Button) view.findViewById(R.id.reset_maxid_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.setting_zero_out), R.id.nav_data, DataFragment.ZERO_OUT_DIALOG);
} else {
MainActivity.error("unable to get fragment activity");
}
}
});
if (sharedPreferences != null) {
((TextView) view.findViewById(R.id.maxout_maxid_text)).setText(getString(R.string.setting_max_start) + " " + sharedPreferences.getLong(ListFragment.PREF_MAX_DB, 0L));
}
((Button) view.findViewById(R.id.maxout_maxid_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.setting_max_out), R.id.nav_data, DataFragment.MAX_OUT_DIALOG);
} else {
MainActivity.error("unable to get fragment activity");
}
}
});
((Button) view.findViewById(R.id.clear_db)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.delete_db_confirm), R.id.nav_data, 128);
} else {
MainActivity.error("unable to get fragment activity");
}
}
});
}
private void setupGpxExport(View view) {
if (getActivity() == null || !getActivity().getSharedPreferences(ListFragment.SHARED_PREFS, 0).getBoolean(ListFragment.PREF_LOG_ROUTES, false)) {
return;
}
view.findViewById(R.id.export_gpx_tools).setVisibility(0);
((Button) view.findViewById(R.id.export_gpx_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.export_gpx_detail), R.id.nav_data, DataFragment.EXPORT_GPX_DIALOG);
} else {
MainActivity.error("unable to get fragment activity");
}
}
});
}
private void setupM8bExport(View view) {
((Button) view.findViewById(R.id.export_m8b_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity != null) {
MainActivity.createConfirmation(activity, DataFragment.this.getString(R.string.export_m8b_detail), R.id.nav_data, DataFragment.EXPORT_M8B_DIALOG);
} else {
MainActivity.error("unable to get fragment activity");
}
}
});
}
@Override
public void handleDialog(int i) {
SharedPreferences sharedPreferences = getActivity() != null ? getActivity().getSharedPreferences(ListFragment.SHARED_PREFS, 0) : null;
SharedPreferences.Editor edit = sharedPreferences != null ? sharedPreferences.edit() : null;
View view = getView();
switch (i) {
case 120:
new ObservationUploader(getActivity(), ListFragment.lameStatic.dbHelper, this, true, false, true).start();
return;
case 121:
new ObservationUploader(getActivity(), ListFragment.lameStatic.dbHelper, this, true, true, false).start();
return;
case 122:
new KmlWriter(getActivity(), ListFragment.lameStatic.dbHelper, ListFragment.lameStatic.runNetworks, ListFragment.lameStatic.runBtNetworks).start();
return;
case 123:
new KmlWriter(getActivity(), ListFragment.lameStatic.dbHelper).start();
return;
case 124:
MainActivity mainActivity = MainActivity.getMainActivity(this);
if (mainActivity != null) {
new BackupTask(this, mainActivity).execute(new Object[0]);
return;
} else {
MainActivity.error("null mainActivity - can't create backup dialog.");
return;
}
case IMPORT_DIALOG:
createAndStartImport();
return;
case ZERO_OUT_DIALOG:
if (edit != null) {
edit.putLong(ListFragment.PREF_DB_MARKER, 0L);
edit.apply();
if (view != null) {
((TextView) view.findViewById(R.id.reset_maxid_text)).setText(getString(R.string.setting_max_id) + " 0");
return;
}
return;
}
MainActivity.error("Null editor - unable to update DB marker");
return;
case MAX_OUT_DIALOG:
if (sharedPreferences != null && edit != null) {
long j = sharedPreferences.getLong(ListFragment.PREF_MAX_DB, 0L);
edit.putLong(ListFragment.PREF_DB_MARKER, j);
edit.apply();
if (view != null) {
((TextView) view.findViewById(R.id.reset_maxid_text)).setText(getString(R.string.setting_max_id) + " " + j);
return;
}
return;
}
MainActivity.error("Null prefs/editor - unable to update DB marker");
return;
case 128:
ListFragment.lameStatic.dbHelper.clearDatabase();
if (edit != null) {
edit.putLong(ListFragment.PREF_DB_MARKER, 0L);
edit.putLong(ListFragment.PREF_DB_MARKER, 0L);
edit.apply();
if (view != null) {
((TextView) view.findViewById(R.id.reset_maxid_text)).setText(getString(R.string.setting_max_id) + " 0");
}
try {
ListFragment.lameStatic.dbHelper.getNetworkCountFromDB();
return;
} catch (DBException e) {
MainActivity.warn("Failed to update network count on DB clear: ", e);
return;
}
}
MainActivity.error("Null editor - unable to update DB marker");
return;
case EXPORT_M8B_DIALOG:
if (exportM8bFile()) {
return;
}
MainActivity.warn("Failed to export m8b.");
WiGLEToast.showOverFragment(getActivity(), R.string.error_general, getString(R.string.m8b_failed));
return;
case EXPORT_GPX_DIALOG:
if (exportRouteGpxFile()) {
return;
}
MainActivity.warn("Failed to export gpx.");
WiGLEToast.showOverFragment(getActivity(), R.string.error_general, getString(R.string.gpx_failed));
return;
default:
MainActivity.warn("Data unhandled dialogId: " + i);
return;
}
}
public class BackupTask extends AsyncTask<Object, Integer, Integer> {
private Pair<Boolean, String> dbResult;
private final Fragment fragment;
protected final MainActivity mainActivity;
private int prevProgress;
private BackupTask(Fragment fragment, MainActivity mainActivity) {
this.prevProgress = 0;
this.fragment = fragment;
this.mainActivity = mainActivity;
mainActivity.setTransferring();
}
@Override
public Integer doInBackground(Object... objArr) {
this.dbResult = ListFragment.lameStatic.dbHelper.copyDatabase(this);
return 0;
}
@Override
public void onPostExecute(Integer num) {
TextView textView;
this.mainActivity.transferComplete();
MainActivity.info("DB backup postExe");
View view = this.fragment.getView();
if (view != null && (textView = (TextView) view.findViewById(R.id.backup_db_text)) != null) {
textView.setText(this.mainActivity.getString(R.string.backup_db_text));
}
if (num != null) {
if (DataFragment.this.pd.isShowing()) {
DataFragment.this.pd.dismiss();
}
Pair<Boolean, String> pair = this.dbResult;
if (pair != null && pair.getFirst().booleanValue()) {
Intent intent = new Intent("android.intent.action.SEND");
intent.putExtra("android.intent.extra.SUBJECT", "WiGLE Database Backup");
intent.setType("application/xsqlite-3");
Context context = DataFragment.this.getContext();
if (context == null) {
MainActivity.error("null context in DB backup postExec");
return;
}
File file = new File(this.dbResult.getSecond());
MainActivity.info("backupfile: " + file.getAbsolutePath() + " exists: " + file.exists() + " read: " + file.canRead());
intent.putExtra("android.intent.extra.STREAM", FileProvider.getUriForFile(context, MainActivity.getMainActivity().getApplicationContext().getPackageName() + ".sqliteprovider", new File(this.dbResult.getSecond())));
intent.addFlags(268435456);
intent.addFlags(1);
DataFragment dataFragment = DataFragment.this;
dataFragment.startActivity(Intent.createChooser(intent, dataFragment.getResources().getText(R.string.send_to)));
return;
}
MainActivity.error("null or empty DB result in DB backup postExec");
}
}
public void progress(int i) {
if (this.prevProgress != i) {
this.prevProgress = i;
publishProgress(Integer.valueOf(i));
}
}
@Override
public void onProgressUpdate(Integer... numArr) {
if (DataFragment.this.pd != null) {
if (numArr.length == 1) {
MainActivity.info("progress: " + numArr[0]);
try {
if (numArr[0].intValue() > 0) {
DataFragment.this.pd.setIndeterminate(false);
if (100 == numArr[0].intValue()) {
if (DataFragment.this.pd.isShowing()) {
DataFragment.this.pd.dismiss();
return;
}
return;
}
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.backup_in_progress));
DataFragment.this.pd.setProgress(numArr[0].intValue());
return;
}
DataFragment.this.pd.setIndeterminate(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.backup_preparing));
DataFragment.this.pd.setProgress(numArr[0].intValue());
return;
} catch (IllegalStateException e) {
MainActivity.error("lost ability to update progress dialog - detatched fragment?", e);
return;
}
}
MainActivity.warn("too many values for DB Backup progress update");
return;
}
MainActivity.error("Progress dialog update failed - not defined");
}
@Override
protected void onPreExecute() {
DataFragment.this.pd = new ProgressDialog(DataFragment.this.getContext());
DataFragment.this.pd.setProgressStyle(1);
DataFragment.this.pd.setCancelable(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.backup_preparing));
DataFragment.this.pd.setIndeterminate(true);
DataFragment.this.pd.show();
}
}
@Override
public void onResume() {
MainActivity.info("resume data.");
super.onResume();
try {
if (getActivity() != null) {
getActivity().setTitle(R.string.data_activity_name);
} else {
MainActivity.error("Failed to set title on null activity onResume");
}
} catch (NullPointerException unused) {
}
}
private boolean exportM8bFile() {
long networkCount = ListFragment.lameStatic.dbHelper.getNetworkCount();
AsyncMagicEightBallExportTask asyncMagicEightBallExportTask = new AsyncMagicEightBallExportTask();
double d = networkCount;
Double.isNaN(d);
asyncMagicEightBallExportTask.execute(Integer.valueOf((int) (d / 1000.0d)), 0, 0);
return true;
}
private boolean exportRouteGpxFile() {
long currentRoutePointCount = ListFragment.lameStatic.dbHelper.getCurrentRoutePointCount();
if (currentRoutePointCount > 1) {
new AsyncGpxExportTask().execute(Long.valueOf(currentRoutePointCount));
} else {
MainActivity.error("no points to create route");
WiGLEToast.showOverFragment(getActivity(), R.string.gpx_failed, getString(R.string.gpx_no_points));
}
return true;
}
public class AsyncMagicEightBallExportTask extends AsyncTask<Integer, Integer, String> {
AsyncMagicEightBallExportTask() {
}
@Override
public String doInBackground(Integer... numArr) {
long j;
final File file;
try {
j = ListFragment.lameStatic.dbHelper.getNetsWithLocCountFromDB();
} catch (DBException unused) {
j = 0;
}
final long intValue = j == 0 ? numArr[0].intValue() : j / 1000;
if (FileUtility.hasSD()) {
try {
String m8bPath = FileUtility.getM8bPath();
if (m8bPath != null) {
File file2 = new File(m8bPath);
file2.mkdirs();
if (!file2.exists()) {
MainActivity.info("Got '!exists': " + file2);
}
file = new File(m8bPath + FileUtility.M8B_FILE_PREFIX + FileUtility.M8B_EXT);
} else {
MainActivity.error("Unable to determine m8b output base path.");
return "ERROR";
}
} catch (IOException e) {
e = e;
MainActivity.error("Unable to open output: ", e);
return "ERROR";
}
} else {
try {
FragmentActivity activity = DataFragment.this.getActivity();
if (activity == null) {
return "ERROR";
}
file = new File(activity.getApplication().getFilesDir(), "export.m8b");
} catch (IOException e2) {
e = e2;
MainActivity.error("Unable to open output: ", e);
return "ERROR";
}
}
final FileChannel channel = new FileOutputStream(file, false).getChannel();
final SipKey sipKey = new SipKey(new byte[16]);
final byte[] bArr = new byte[6];
final TreeMap treeMap = new TreeMap();
final long currentTimeMillis = System.currentTimeMillis();
ListFragment.lameStatic.dbHelper.addToQueue(new QueryThread.Request(DatabaseHelper.LOCATED_NETS_QUERY, new QueryThread.ResultHandler() {
int non_utm = 0;
int rows = 0;
int records = 0;
@Override
public boolean handleRow(Cursor cursor) {
int i;
String string;
float f;
float f2;
try {
string = cursor.getString(0);
f = cursor.getFloat(1);
f2 = cursor.getFloat(2);
} catch (IndexOutOfBoundsException e3) {
MainActivity.error("Bad UTM ", e3);
}
if (-80.0f <= f && f <= 84.0f) {
mgrs fromUtm = mgrs.fromUtm(utm.fromLatLon(f, f2));
Long extractKeyFrom = MagicEightUtil.extractKeyFrom(string, bArr, sipKey, 30);
if (extractKeyFrom != null) {
Set set = (Set) treeMap.get(extractKeyFrom);
if (set == null) {
set = new HashSet();
treeMap.put(Long.valueOf(extractKeyFrom.longValue()), set);
}
if (set.add(fromUtm)) {
this.records++;
}
}
i = this.rows + 1;
this.rows = i;
if (i % 1000 == 0) {
AsyncMagicEightBallExportTask asyncMagicEightBallExportTask = AsyncMagicEightBallExportTask.this;
double d = i;
Double.isNaN(d);
double d2 = intValue;
Double.isNaN(d2);
asyncMagicEightBallExportTask.publishProgress(Integer.valueOf((int) (((d / 1000.0d) / d2) * 100.0d)));
}
return true;
}
this.non_utm++;
i = this.rows + 1;
this.rows = i;
if (i % 1000 == 0) {
}
return true;
}
@Override
public void complete() {
MainActivity.info("m8b source export complete...");
if (channel != null) {
try {
Charset forName = Charset.forName("UTF-8");
ByteBuffer order = ByteBuffer.allocate(4096).order(ByteOrder.LITTLE_ENDIAN);
order.put("MJG\n".getBytes(forName));
order.put("2\n".getBytes(forName));
order.put("SIP-2-4\n".getBytes(forName));
order.put(String.format("%x\n", 30).getBytes(forName));
order.put("MGRS-1000\n".getBytes(forName));
order.put("4\n".getBytes(forName));
order.put("9\n".getBytes(forName));
order.put(String.format("%x\n", Integer.valueOf(this.records)).getBytes(forName));
order.flip();
while (order.hasRemaining()) {
channel.write(order);
}
order.clear();
byte[] bArr2 = new byte[9];
int i = 0;
for (Map.Entry entry : treeMap.entrySet()) {
long longValue = ((Long) entry.getKey()).longValue();
for (mgrs mgrsVar : (Set) entry.getValue()) {
if (order.remaining() < 13) {
order.flip();
while (order.hasRemaining()) {
channel.write(order);
}
order.clear();
}
mgrsVar.populateBytes(bArr2);
order.putInt((int) longValue).put(bArr2);
}
i++;
if (i % 100 == 0) {
AsyncMagicEightBallExportTask asyncMagicEightBallExportTask = AsyncMagicEightBallExportTask.this;
Integer[] numArr2 = new Integer[2];
numArr2[0] = 100;
double d = i;
double size = treeMap.size();
Double.isNaN(d);
Double.isNaN(size);
numArr2[1] = Integer.valueOf((int) ((d / size) * 100.0d));
asyncMagicEightBallExportTask.publishProgress(numArr2);
}
}
order.flip();
while (order.hasRemaining()) {
channel.write(order);
}
order.clear();
channel.close();
} catch (IOException e3) {
MainActivity.error("Failed to close m8b writer", e3);
}
}
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
StringBuilder append = new StringBuilder().append("completed m8b generation. Generation time: ");
double d2 = currentTimeMillis2;
Double.isNaN(d2);
MainActivity.info(append.append(d2 * 0.001d).append("s").toString());
AsyncMagicEightBallExportTask.this.publishProgress(100, 100);
Intent intent = new Intent("android.intent.action.SEND");
intent.putExtra("android.intent.extra.SUBJECT", "WiGLE.m8b");
intent.setType("application/wigle.m8b");
Context context = DataFragment.this.getContext();
if (context != null) {
intent.putExtra("android.intent.extra.STREAM", FileProvider.getUriForFile(context, MainActivity.getMainActivity().getApplicationContext().getPackageName() + ".m8bprovider", file));
intent.addFlags(268435456);
intent.addFlags(1);
DataFragment.this.startActivity(Intent.createChooser(intent, DataFragment.this.getResources().getText(R.string.send_to)));
return;
}
MainActivity.error("Unable to link m8b provider - null context");
}
}));
return null;
}
@Override
public void onPostExecute(String str) {
if (str != null) {
MainActivity.error("POST EXECUTE: " + str);
if (DataFragment.this.pd.isShowing()) {
DataFragment.this.pd.dismiss();
}
}
}
@Override
protected void onPreExecute() {
DataFragment.this.pd = new ProgressDialog(DataFragment.this.getContext());
DataFragment.this.pd.setProgressStyle(1);
DataFragment.this.pd.setCancelable(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.m8b_sizing));
DataFragment.this.pd.setIndeterminate(true);
DataFragment.this.pd.show();
}
@Override
public void onProgressUpdate(Integer... numArr) {
if (numArr.length != 2) {
DataFragment.this.pd.setIndeterminate(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.calculating_m8b));
DataFragment.this.pd.setProgress(numArr[0].intValue());
} else if (numArr[1].intValue() <= 0) {
DataFragment.this.pd.setIndeterminate(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.calculating_m8b));
DataFragment.this.pd.setProgress(numArr[0].intValue());
} else if (100 == numArr[1].intValue()) {
if (DataFragment.this.pd.isShowing()) {
DataFragment.this.pd.dismiss();
}
} else {
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.exporting_m8b_final));
DataFragment.this.pd.setProgress(numArr[1].intValue());
}
}
}
public class AsyncGpxExportTask extends AsyncTask<Long, Integer, String> {
File gpxDestFile;
AsyncGpxExportTask() {
}
@Override
public String doInBackground(Long... lArr) {
DateFormat simpleDateFormat;
boolean hasSD = FileUtility.hasSD();
String format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US).format(new Date());
CharSequence charSequence = "<name>" + format + "</name><trkseg>\n";
try {
if (hasSD) {
String gpxPath = FileUtility.getGpxPath();
if (gpxPath == null) {
MainActivity.error("Unable to determine external GPX path");
return null;
}
File file = new File(gpxPath);
file.mkdirs();
if (!file.exists()) {
MainActivity.info("Got '!exists': " + file);
}
this.gpxDestFile = new File(gpxPath + format + FileUtility.GPX_EXT);
} else if (DataFragment.this.getActivity() != null) {
this.gpxDestFile = new File(DataFragment.this.getActivity().getApplication().getFilesDir(), format + FileUtility.GPX_EXT);
} else {
MainActivity.error("set destination file due to null Activity in GPX export");
}
FileWriter fileWriter = new FileWriter(this.gpxDestFile, false);
fileWriter.append(DataFragment.GPX_HEADER_A);
String str = "WiGLE WiFi ";
try {
if (DataFragment.this.getActivity() != null) {
str = "WiGLE WiFi " + DataFragment.this.getActivity().getApplicationContext().getPackageManager().getPackageInfo(DataFragment.this.getActivity().getApplicationContext().getPackageName(), 0).versionName;
} else {
MainActivity.error("unable to get packageManager due to null Activity in GPX export");
}
} catch (Exception unused) {
str = str + "(unknown)";
}
fileWriter.append((CharSequence) str);
fileWriter.append(DataFragment.GPX_HEADER_B);
fileWriter.append(charSequence);
MainActivity.info("wrote " + writeSegmentsWithCursor(fileWriter, ListFragment.lameStatic.dbHelper.currentRouteIterator(), simpleDateFormat, lArr[0]) + " segments");
fileWriter.append(DataFragment.GPX_FOOTER);
fileWriter.flush();
fileWriter.close();
return "completed export";
} catch (IOException | InterruptedException | DBException e) {
MainActivity.error("Error writing GPX", e);
return null;
}
}
protected long writeSegmentsWithCursor(FileWriter fileWriter, Cursor cursor, DateFormat dateFormat, Long l) throws IOException, InterruptedException {
cursor.moveToFirst();
long j = 0;
while (!cursor.isAfterLast()) {
MainActivity.info("export: " + j + " / " + l);
fileWriter.append("<trkpt lat=\"").append((CharSequence) String.valueOf(cursor.getDouble(0))).append("\" lon=\"").append((CharSequence) String.valueOf(cursor.getDouble(1))).append("\"><time>").append((CharSequence) dateFormat.format(new Date(cursor.getLong(2)))).append("</time></trkpt>\n");
j++;
if (l.longValue() != 0) {
if (j == 0) {
onProgressUpdate(0);
} else {
publishProgress(Integer.valueOf((int) ((1000 * j) / l.longValue())));
}
cursor.moveToNext();
} else {
return l.longValue();
}
}
return j;
}
@Override
public void onPostExecute(String str) {
if (str != null) {
MainActivity.error("GPX POST EXECUTE: " + str);
if (DataFragment.this.pd.isShowing()) {
DataFragment.this.pd.dismiss();
}
Intent intent = new Intent("android.intent.action.SEND");
intent.putExtra("android.intent.extra.SUBJECT", "WiGLE.gpx");
intent.setType("application/gpx");
if (DataFragment.this.getContext() != null) {
intent.putExtra("android.intent.extra.STREAM", FileProvider.getUriForFile(DataFragment.this.getContext(), MainActivity.getMainActivity().getApplicationContext().getPackageName() + ".gpxprovider", this.gpxDestFile));
intent.addFlags(268435456);
intent.addFlags(1);
DataFragment dataFragment = DataFragment.this;
dataFragment.startActivity(Intent.createChooser(intent, dataFragment.getResources().getText(R.string.send_to)));
return;
}
MainActivity.error("Unable to initiate GPX export - null context");
}
}
@Override
protected void onPreExecute() {
DataFragment.this.pd = new ProgressDialog(DataFragment.this.getContext());
DataFragment.this.pd.setProgressStyle(1);
DataFragment.this.pd.setCancelable(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.gpx_preparing));
DataFragment.this.pd.setIndeterminate(true);
DataFragment.this.pd.show();
}
@Override
public void onProgressUpdate(Integer... numArr) {
if (numArr.length == 1) {
MainActivity.info("progress: " + numArr[0]);
if (numArr[0].intValue() <= 0) {
DataFragment.this.pd.setIndeterminate(false);
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.gpx_preparing));
DataFragment.this.pd.setProgress(numArr[0].intValue());
return;
} else if (100 == numArr[0].intValue()) {
if (DataFragment.this.pd.isShowing()) {
DataFragment.this.pd.dismiss();
return;
}
return;
} else {
DataFragment.this.pd.setMessage(DataFragment.this.getString(R.string.gpx_exporting));
DataFragment.this.pd.setProgress(numArr[0].intValue());
return;
}
}
MainActivity.warn("too many values for GPX progress update");
}
}
}