Commit b987e500 authored by Kristin Muterspaw's avatar Kristin Muterspaw
Browse files

New 'Current Database Information' on the bottom of Database Actions Activity....

New 'Current Database Information' on the bottom of Database Actions Activity. It displays: last time uploaded, last time downloaded, last time cleaned, current size, current status which could be: empty, initialized but no reading or streaming data, initialized with reading and streaming data, or initialized and just reading or streaming data. Font is set to 'Appearance Medium.' Only layout for portrait mode currently.
parent 615f1a03
......@@ -15,11 +15,13 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.format.Formatter;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.sql.Connection;
......@@ -30,6 +32,7 @@ import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
......@@ -43,6 +46,7 @@ public class DatabaseActionsActivity extends Activity {
private String uname, database, pass, host, pNum;
public static String trip, url;
public static int tripID, downloadColumnCount = 0, uploadColumnCount = 0;
private TextView cleanTV, uploadTV, downloadTV, dbSizeTV, dbStatusTV;
public String[] tripArray, tripIds;
Resources res;
View button;
......@@ -70,14 +74,26 @@ public class DatabaseActionsActivity extends Activity {
settings= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
editor = settings.edit();
for (String table : ReadingsDatabase.tables){
for (String table : ReadingsDatabase.tables) {
downloadColumnCount += db.getColumns(table).length;
}
for (String table : uploadTables){
for (String table : uploadTables) {
uploadColumnCount += db.getColumns(table).length;
}
dbSizeTV = (TextView) findViewById(R.id.databaseSize);
dbSizeTV.setText(String.format(res.getString(R.string.databaseSize), Formatter.formatFileSize(this, db.getSize())));
dbStatusTV = (TextView) findViewById(R.id.databaseStatus);
dbStatusTV.setText(String.format(res.getString(R.string.databaseStatus), ""));
getDatabaseStatus(db.getStatus());
cleanTV = (TextView) findViewById(R.id.lastClean);
cleanTV.setText(String.format(res.getString(R.string.lastClean), settings.getString("lastClean", "")));
uploadTV = (TextView) findViewById(R.id.lastUpload);
uploadTV.setText(String.format(res.getString(R.string.lastUpload), settings.getString("lastUpload", "")));
downloadTV = (TextView) findViewById(R.id.lastDownload);
downloadTV.setText(String.format(res.getString(R.string.lastDownload), settings.getString("lastDownload", "")));
dbName = (EditText) findViewById(R.id.database);
database = settings.getString("database_name", null);
dbName.setText(settings.getString("database_name", ""));
......@@ -244,6 +260,9 @@ public class DatabaseActionsActivity extends Activity {
if(db.copyDatabase("archive")){
makeToast("Cleaned local database.");
db.cleanDatabase();
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
editor.apply();
}
}
else { new connectToDB().execute(); }
......@@ -416,6 +435,11 @@ public class DatabaseActionsActivity extends Activity {
}
protected void onPostExecute(Boolean result) {
if (result) {
editor.putString("lastDownload", getTimestamp());
downloadTV.setText(String.format(res.getString(R.string.lastDownload), getTimestamp()));
editor.apply();
}
progressDialog.dismiss();
}
}
......@@ -562,8 +586,13 @@ public class DatabaseActionsActivity extends Activity {
else if (result) {
if(db.copyDatabase("archive")){
db.cleanDatabase();
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
editor.putString("trip", "");
}
editor.putString("lastUpload", getTimestamp());
uploadTV.setText(String.format(res.getString(R.string.lastUpload), getTimestamp()));
editor.apply();
makeToast("Successfully uploaded tables.");
}
progressDialog.dismiss();
......@@ -576,4 +605,31 @@ public class DatabaseActionsActivity extends Activity {
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
public String getTimestamp(){
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
return s.format(new Date());
}
public void getDatabaseStatus(int status){
switch(status){
case 0:
dbStatusTV.setText(String.format(res.getString(R.string.databaseStatus), "Empty"));
break;
case 1:
dbStatusTV.setText(String.format(res.getString(R.string.databaseStatus), "Initialized, readings table populated."));
break;
case 2:
dbStatusTV.setText(String.format(res.getString(R.string.databaseStatus), "Initialized, readings and streamings table populated."));
break;
case 3:
dbStatusTV.setText(String.format(res.getString(R.string.databaseStatus), "Initialized, no readings or streaming data."));
break;
case 4:
dbStatusTV.setText(String.format(res.getString(R.string.databaseStatus), "Initialized, streamings table populated."));
break;
default:
break;
}
}
}
......@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
......@@ -420,7 +421,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
String[] columns = {"sectorName"};
Cursor c = db.query(T_SECTOR, columns, null, null, null, null, null);
List<String> values = new ArrayList<String>();
while (c.moveToNext()){
while (c.moveToNext()) {
values.add(c.getString(c.getColumnIndex("sectorName")));
}
c.close();
......@@ -432,13 +433,43 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
String[] columns = {"siteName"};
Cursor c = db.query(T_SITE, columns, null, null, null, null, null);
List<String> values = new ArrayList<String>();
while (c.moveToNext()){
while (c.moveToNext()) {
values.add(c.getString(c.getColumnIndex("siteName")));
}
c.close();
return values;
}
public long getSize() {
return dbPath.length();
}
public int getStatus() {
int readings = query(T_READING, null, null).getCount();
Log.d("ReadingsDatabase", "Readings Counts:" + Integer.toString(readings));
int streaming = query(T_STREAM, null, null).getCount();
Log.d("ReadingsDatabase", "Streamings Counts:" + Integer.toString(streaming));
// Empty database
if (getSize() == 0){
return 0;
} else if (getSites().size() != 0) {
if (readings != 0) {
if (streaming == 0) {
// Just readings populated
return 1;
} else {
return 2;
}
} else {
if (streaming != 0) {
return 4;
} else {
return 3;
}
// Initialized but no readings
}
}
return 0;
}
}
......@@ -214,7 +214,7 @@ public class SensorSampleService extends Service implements SensorEventListener
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Sampling wake lock");
mWakeLock.acquire();
if (sampleOnce){
if (sampleOnce) {
writeToDB();
} else {
dbHandler.postDelayed(dbRunner, loggingInterval);
......
......@@ -10,8 +10,11 @@
android:hint="@string/server_ip"
android:layout_marginTop="31dp"
android:layout_alignParentTop="true"
android:singleLine="true"
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:layout_alignStart="@id/serverIp"
android:layout_alignEnd="@id/serverIp"
android:textCursorDrawable="@null"
android:layout_centerHorizontal="true" />
......@@ -23,7 +26,10 @@
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:singleLine="true"
android:hint="@string/database_name"
android:layout_alignStart="@id/serverIp"
android:layout_alignEnd="@id/serverIp"
android:layout_below="@+id/serverIp"
android:layout_centerHorizontal="true" />
......@@ -35,6 +41,9 @@
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:text=""
android:singleLine="true"
android:layout_alignStart="@id/serverIp"
android:layout_alignEnd="@id/serverIp"
android:hint="@string/username"
android:layout_below="@+id/database"
android:layout_centerHorizontal="true" />
......@@ -48,6 +57,9 @@
android:hint="@string/password"
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:layout_alignStart="@id/serverIp"
android:singleLine="true"
android:layout_alignEnd="@id/serverIp"
android:textCursorDrawable="@null"
android:layout_below="@+id/username"
android:layout_centerHorizontal="true" />
......@@ -61,6 +73,9 @@
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:hint="@string/port_of_db"
android:layout_alignStart="@id/serverIp"
android:layout_alignEnd="@id/serverIp"
android:singleLine="true"
android:fontFamily="sans-serif"
android:layout_below="@+id/password"
android:layout_centerHorizontal="true" />
......@@ -70,26 +85,79 @@
android:layout_height="wrap_content"
android:text="@string/connect"
android:id="@+id/setupDbButton"
android:layout_marginTop="77dp"
android:layout_below="@id/port"
android:layout_toStartOf="@+id/uploadButton"
android:layout_marginEnd="67dp" />
android:layout_below="@+id/port"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/upload"
android:id="@+id/uploadButton"
android:layout_alignTop="@id/setupDbButton"
android:layout_toEndOf="@id/port" />
android:layout_alignTop="@+id/setupDbButton"
android:layout_toStartOf="@+id/database" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wipeDB"
android:id="@+id/wipeDatabase"
android:layout_centerVertical="true"
android:layout_alignEnd="@+id/username" />
android:layout_alignTop="@+id/setupDbButton"
android:layout_toEndOf="@+id/database" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lastUpload"
android:id="@+id/lastUpload"
android:layout_alignStart="@id/uploadButton"
android:textColor="@color/dark_gray_blue"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:layout_above="@+id/lastDownload" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lastDownload"
android:id="@+id/lastDownload"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textColor="@color/dark_gray_blue"
android:textStyle="bold"
android:layout_above="@+id/lastClean"
android:layout_alignStart="@+id/lastUpload" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lastClean"
android:id="@+id/lastClean"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue"
android:layout_alignStart="@id/lastUpload"
android:layout_above="@+id/databaseSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/databaseSize"
android:id="@+id/databaseSize"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue"
android:layout_above="@+id/databaseStatus"
android:layout_alignStart="@id/lastUpload" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/databaseStatus"
android:id="@+id/databaseStatus"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue"
android:layout_alignParentBottom="true"
android:layout_alignStart="@id/lastUpload"
android:layout_marginBottom="25dp" />
</RelativeLayout>
\ No newline at end of file
......@@ -81,12 +81,17 @@
<string name="password">Password of user to connect with</string>
<string name="port_of_db">Port to connect to</string>
<string name="default_port">5432</string>
<string name="connect">Set up local database</string>
<string name="connect">Setup local database</string>
<string name="upload">Upload tables</string>
<string name="spotQuery">select count(*) as rowcount from fieldday_spot where tripID = %1$s and siteID = %2$s and sectorID = %3$s and spotID = %4$s;</string>
<string name="cannot_connect">Cannot connect. Make sure to fill out all of your information.</string>
<string name="wipeDB">Clear local database</string>
<string name="updateDB">Update local database</string>
<string name="lastUpload">Last upload of tables: "%1$s"</string>
<string name="lastDownload">Last setup of local database: "%1$s"</string>
<string name="lastClean">Last clear of local database: "%1$s"</string>
<string name="databaseSize">Current database size: "%1$s"</string>
<string name="databaseStatus">Current database status: "%1$s"</string>
<!-- My Documents strings -->
<string name="fileHost">URL of server where the files are hosted.</string>
......
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