Skip to content

Commit

Permalink
almost finished for beta testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPalmer committed Oct 13, 2014
1 parent 46c5919 commit ac20e1c
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 276 deletions.
6 changes: 3 additions & 3 deletions SUDEAU/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.movelab.sudeau"
android:versionCode="2"
android:versionCode="3"
android:installLocation="internalOnly"
android:versionName="1.01" >
android:versionName="1.03" >

<uses-sdk
android:minSdkVersion="9"
Expand Down Expand Up @@ -33,7 +33,7 @@
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/maps_api_key_production" />
android:value="@string/maps_api_key_debugging" />
<activity
android:name="net.movelab.sudeau.Switchboard"
android:theme="@android:style/Theme.Holo"
Expand Down
5 changes: 3 additions & 2 deletions SUDEAU/res/layout/interactive_image_activity_heatmap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/heatMapScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:layout_height="fill_parent">

<FrameLayout
android:id="@+id/my_frame"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">

<ImageView
android:id="@+id/int_image"
Expand Down
180 changes: 0 additions & 180 deletions SUDEAU/src/net/movelab/sudeau/ChooseItineraryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ public class ChooseItineraryActivity extends Activity {

private SharedPreferences mPreferences;

// TODO fix this... move all this logic to DB
public boolean r7downloaded;

private static final String TAG = "ChooseItineraryActivity";

private String currentLocale;
Expand All @@ -121,11 +118,6 @@ protected void onCreate(Bundle savedInstanceState) {
currentLocale = PropertyHolder.getLocale();
mPreferences = getSharedPreferences("EruletPreferences", MODE_PRIVATE);

// TODO just for testing
// mPreferences.edit().putBoolean("r7d", false).apply();

r7downloaded = mPreferences.getBoolean("r7d", false);

progressBar = (ProgressBar) findViewById(R.id.pbChooseItinerary);
//setUpDBIfNeeded();
setUpMapIfNeeded();
Expand Down Expand Up @@ -183,7 +175,6 @@ public void showItineraryOptions(){
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final Route r = routeTable.get(selectedMarker);
if(r7downloaded){
builder.setTitle(r.getName(currentLocale));
builder.setIcon(R.drawable.ic_pin_info);
builder.setMessage(r.getDescription(currentLocale));
Expand Down Expand Up @@ -220,24 +211,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
startActivity(intent); }
});
}
} else{
builder.setTitle(r.getName(currentLocale));
builder.setMessage(r.getDescription(currentLocale) + "\n\nYou have not yet downloaded the content for this route to your phone. Would you like to download it now?");
builder.setPositiveButton("Download", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startDownload();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});

builder.setCancelable(true);
}
builder.show();
}

Expand Down Expand Up @@ -452,159 +426,5 @@ private MapBoxOfflineTileProvider initTileProvider(Context context) {
}


private void startDownload() {
// TODO unhardcode the route number and pass it instead
String url = "http://107.170.174.182/media/holet/zipped_routes/content_route7.zip";
new DownloadFileAsync().execute(url);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DOWNLOAD_PROGRESS:
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Downloading route content...please wait");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}


class DownloadFileAsync extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}

@Override
protected String doInBackground(String... aurl) {
int count;

try {

URL url = new URL(aurl[0]);
Log.d("ANDRO_ASYNC", "uRL: " + url.toString());

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.connect();

int lenghtOfFile = conn.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

Log.d("ANDRO_ASYNC", "SD path: " + Environment.getExternalStorageDirectory().getPath());

File destinationFile = new File(Environment.getExternalStorageDirectory().getPath(), Util.baseFolder + "/route.zip");
String destinationPath = destinationFile.getPath();
Log.d("ANDRO_ASYNC", "Save path: " + destinationPath);

InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(destinationPath);

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*90)/lenghtOfFile));
output.write(data, 0, count);
}

output.flush();
output.close();
input.close();


// NOW UNZIP IT
ZipFile thisZipfile = new ZipFile(destinationPath);
int nEntries = thisZipfile.size();
int zipCounter = 0;

String zipFilePath = destinationPath;
Log.d("ANDRO_ASYNC", "read path: " + destinationPath);
// TODO take out hard coded route 7
File target_directory = new File(Environment.getExternalStorageDirectory().getPath(), Util.baseFolder + "/" + Util.routeMediaFolder + "/route_7");
String destDirectory = target_directory.getPath();
Log.d("ANDRO_ASYNC", "Save path: " + destDirectory);

UnzipUtility unzipper = new UnzipUtility();
try {
// unzipper.unzip(zipFilePath, destDirectory);
// publishProgress(""+100);

final int BUFFER_SIZE = 4096;

File destDir = new File(destDirectory);
if (!destDir.exists()) {
destDir.mkdirs();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null) {
String filePath = destDirectory + File.separator + entry.getName();
if (!entry.isDirectory()) {
// if the entry is a file, extracts it
// extractFile(zipIn, filePath);

File f = new File(filePath);
File dir = new File(f.getParent());
dir.mkdirs();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[BUFFER_SIZE];
int read = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);

}
bos.close();


} else {
// if the entry is a directory, make the directory
File dir = new File(filePath);
dir.mkdirs();
}

publishProgress(""+(int)(90+ ((++zipCounter*10)/nEntries)));

zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();



mPreferences.edit().putBoolean("r7d", true).apply();
r7downloaded = true;

} catch (Exception ex) {
// some errors occurred
ex.printStackTrace();
}

} catch (Exception e) {}


return null;

}
protected void onProgressUpdate(String... progress) {
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}

@Override
protected void onPostExecute(String unused) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
showItineraryOptions();
}
}

}
52 changes: 24 additions & 28 deletions SUDEAU/src/net/movelab/sudeau/DetailItineraryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.json.JSONException;
import org.json.JSONObject;

import net.movelab.sudeau.database.DataBaseHelper;
import net.movelab.sudeau.database.DataContainer;
import net.movelab.sudeau.model.FileManifest;
import net.movelab.sudeau.model.HighLight;
Expand Down Expand Up @@ -41,6 +42,7 @@
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Property;
import android.view.Display;
import android.view.Gravity;
import android.view.Menu;
Expand Down Expand Up @@ -417,7 +419,7 @@ private void saveHighLight(HighLight h) {
Log.d("saveHighLight", "Step id not found " + stepBeingEditedId);
} else {
DataContainer.addHighLightToStep(s, h,
DataContainer.getAndroidId(getContentResolver()),
PropertyHolder.getUserId(),
app.getDataBaseHelper());
}
}
Expand Down Expand Up @@ -767,7 +769,7 @@ private void setUpRoutes() {
.getId() : null;
routeInProgress = DataContainer.createEmptyRoute(locale,
app.getDataBaseHelper(),
DataContainer.getAndroidId(getContentResolver()),
PropertyHolder.getUserId(),
idRouteBasedOn);
}
}
Expand Down Expand Up @@ -892,6 +894,7 @@ public void onInfoWindowClick(Marker marker) {
DetailHighLightActivity.class);
i.putExtra("step_j", s_j_string);
if(s!=null){
DataBaseHelper.
i.putExtra("route_id", s.getTrack().getRoute().getId());
}
if(h!=null){
Expand Down Expand Up @@ -1554,39 +1557,32 @@ private void refreshDecorations(List<Step> steps) {
}

private MapBoxOfflineTileProvider initTileProvider() {
// File sdcard = Environment.getExternalStorageDirectory();
File sdcard = new File(Environment.getExternalStorageDirectory(),
Util.baseFolder + "/" + Util.routeMapsFolder);
if (selectedRoute.getLocalCarto() != null) {
File f = new File(sdcard, selectedRoute.getLocalCarto());
String mapPath = selectedRoute.getLocalCarto();
if (mapPath != null && !mapPath.isEmpty()) {
File f = new File(mapPath);
Log.e("CARTO", f.getPath());

// File f = new File(getCacheDir() +
// "/OSMPublicTransport_HiRes.mbtiles");
if (f.exists()) {
Log.e("CARTO EXISTS", f.getPath());

// try {
// InputStream is = getAssets().open(
// "OSMPublicTransport_HiRes.mbtiles");
// FileInputStream is = new FileInputStream(f);
// int size = is.available();
// byte[] buffer = new byte[size];
// is.read(buffer);
// is.close();
// FileOutputStream fos = new FileOutputStream(f);
// fos.write(buffer);
// fos.close();
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
return new MapBoxOfflineTileProvider(f.getPath());
return new MapBoxOfflineTileProvider(f.getPath());
} else {
Log.d(TAG,
"Fitxer cartografia no trobat " + f.getAbsolutePath());
}
}
return null;
// If not returned by now, try the general map path instead
mapPath = PropertyHolder.getGeneralMapPath();
if (mapPath != null && !mapPath.isEmpty()) {
File f = new File(mapPath);
Log.e("CARTO", f.getPath());
if (f.exists()) {
Log.e("CARTO EXISTS", f.getPath());
return new MapBoxOfflineTileProvider(f.getPath());
} else {
Log.d(TAG,
"Fitxer cartografia no trobat " + f.getAbsolutePath());
}
}
return null;
}

public class FixReceiver extends BroadcastReceiver {
Expand Down Expand Up @@ -1768,7 +1764,7 @@ public void onReceive(Context context, Intent intent) {
int order = stepsInProgress.size();
s.setOrder(order);
DataContainer.addStepToTrack(s, routeInProgress.getTrack(),
DataContainer.getAndroidId(getContentResolver()),
PropertyHolder.getUserId(),
app.getDataBaseHelper());
}
Log.d("onReceive", "Received new location " + lat + " " + lng
Expand Down
2 changes: 1 addition & 1 deletion SUDEAU/src/net/movelab/sudeau/EditHighLightActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ protected void onCreate(Bundle savedInstanceState) {
app = (EruletApp) getApplicationContext();
}

// To stop keyboard from popping up immediately and blocking everything
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

setContentView(R.layout.highlight_activity);


setUpInterface();
Bundle extras = getIntent().getExtras();
if (extras != null) {
Expand Down
Loading

0 comments on commit ac20e1c

Please sign in to comment.