Permalink
Browse files

Various DB fixes / optimisations

 - OpenDatabase instead of OpenAndCreate
 - Checking for locks
 - Checking for open / close
  • Loading branch information...
1 parent 8b5cb0e commit 98c10d3aac77154c152bb9c65bf1a0823daf7d18 @NetworksAreMadeOfString committed Mar 8, 2012
View
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.networksaremadeofstring.rhybudd"
- android:installLocation="auto" android:versionCode="8" android:versionName="2.0">
+ android:installLocation="auto" android:versionCode="9" android:versionName="2.2">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
@@ -6,23 +6,23 @@
<TextView android:textSize="10dp" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/CurrentTaskLabel" android:text="Refreshing...." android:layout_height="wrap_content" android:layout_alignBottom="@+id/progressBar1" android:layout_toLeftOf="@+id/progressBar1" android:visibility="invisible"></TextView>
</RelativeLayout>
- <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_below="@+id/HomeHeader" android:layout_height="wrap_content" android:background="#929ba4">
- <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:id="@+id/EventTitle" android:text="Title" android:textStyle="bold"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventTitle" android:layout_alignParentLeft="true" android:id="@+id/ComponantLabel" android:textStyle="bold" android:layout_width="wrap_content" android:text="@string/eventDetailsComponentLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/ComponantLabel" android:layout_alignParentLeft="true" android:id="@+id/Componant" android:textColor="#FFFFFF" android:layout_marginLeft="8dp"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Componant" android:layout_alignParentLeft="true" android:id="@+id/EventClassLabel" android:textStyle="bold" android:text="@string/eventDetailsEventClassLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClassLabel" android:layout_alignLeft="@+id/Componant" android:id="@+id/EventClass" android:textColor="#FFFFFF"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClass" android:layout_alignParentLeft="true" android:id="@+id/SummaryLabel" android:textStyle="bold" android:text="@string/eventDetailsSummaryLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/SummaryLabel" android:layout_alignLeft="@+id/EventClass" android:id="@+id/Summary" android:textColor="#FFFFFF"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Summary" android:layout_alignParentLeft="true" android:id="@+id/StartTimeLabel" android:layout_marginTop="24dp" android:textStyle="bold" android:text="@string/eventDetailsFirstSeenLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/StartTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EndTimeLabel" android:textStyle="bold" android:text="@string/eventDetailslastSeenLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/FirstTime" android:text="...." android:layout_toRightOf="@+id/StartTimeLabel" android:layout_alignBaseline="@+id/StartTimeLabel" android:layout_marginLeft="8dp"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/EndTimeLabel" android:layout_alignBottom="@+id/EndTimeLabel" android:id="@+id/LastTime" android:text="...." android:layout_toRightOf="@+id/EndTimeLabel" android:layout_marginLeft="11dp"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EndTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EventCountLabel" android:textStyle="bold" android:layout_marginTop="8dp" android:text="@string/eventDetailsEventCountLabel"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/EventCountLabel" android:layout_alignBottom="@+id/EventCountLabel" android:layout_toRightOf="@+id/EventCountLabel" android:id="@+id/EventCount" android:text="0" android:layout_marginLeft="20dp"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventCountLabel" android:layout_alignParentLeft="true" android:id="@+id/AgentLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsAgentLabel"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/AgentLabel" android:layout_alignBottom="@+id/AgentLabel" android:layout_toRightOf="@+id/AgentLabel" android:id="@+id/Agent" android:text="unknown" android:layout_marginLeft="20dp"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/AgentLabel" android:layout_alignParentLeft="true" android:id="@+id/LogLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsLogLabel"></TextView>
+ <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_below="@+id/HomeHeader" android:layout_height="wrap_content" android:background="@drawable/background_gradient_2">
+ <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:id="@+id/EventTitle" android:text="Title" android:textStyle="bold" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventTitle" android:layout_alignParentLeft="true" android:id="@+id/ComponantLabel" android:textStyle="bold" android:layout_width="wrap_content" android:text="@string/eventDetailsComponentLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/ComponantLabel" android:layout_alignParentLeft="true" android:id="@+id/Componant" android:textColor="#FFFFFF" android:layout_marginLeft="8dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Componant" android:layout_alignParentLeft="true" android:id="@+id/EventClassLabel" android:textStyle="bold" android:text="@string/eventDetailsEventClassLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClassLabel" android:layout_alignLeft="@+id/Componant" android:id="@+id/EventClass" android:textColor="#FFFFFF" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClass" android:layout_alignParentLeft="true" android:id="@+id/SummaryLabel" android:textStyle="bold" android:text="@string/eventDetailsSummaryLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/SummaryLabel" android:layout_alignLeft="@+id/EventClass" android:id="@+id/Summary" android:textColor="#FFFFFF" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Summary" android:layout_alignParentLeft="true" android:id="@+id/StartTimeLabel" android:layout_marginTop="24dp" android:textStyle="bold" android:text="@string/eventDetailsFirstSeenLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/StartTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EndTimeLabel" android:textStyle="bold" android:text="@string/eventDetailslastSeenLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/FirstTime" android:text="...." android:layout_toRightOf="@+id/StartTimeLabel" android:layout_alignBaseline="@+id/StartTimeLabel" android:layout_marginLeft="8dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/EndTimeLabel" android:layout_alignBottom="@+id/EndTimeLabel" android:id="@+id/LastTime" android:text="...." android:layout_toRightOf="@+id/EndTimeLabel" android:layout_marginLeft="11dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EndTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EventCountLabel" android:textStyle="bold" android:layout_marginTop="8dp" android:text="@string/eventDetailsEventCountLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/EventCountLabel" android:layout_alignBottom="@+id/EventCountLabel" android:layout_toRightOf="@+id/EventCountLabel" android:id="@+id/EventCount" android:text="0" android:layout_marginLeft="20dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventCountLabel" android:layout_alignParentLeft="true" android:id="@+id/AgentLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsAgentLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/AgentLabel" android:layout_alignBottom="@+id/AgentLabel" android:layout_toRightOf="@+id/AgentLabel" android:id="@+id/Agent" android:text="unknown" android:layout_marginLeft="20dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/AgentLabel" android:layout_alignParentLeft="true" android:id="@+id/LogLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsLogLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
<ListView android:layout_width="match_parent" android:id="@+id/LogList" android:layout_height="wrap_content" android:layout_below="@+id/LogLabel" android:fadingEdge="none" android:cacheColorHint="#929ba4" android:minHeight="200dp" android:layout_marginLeft="8dp"></ListView>
</RelativeLayout>
@@ -184,7 +184,7 @@ private Boolean CheckDB()
try
{
- rhybuddCache = this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
+ rhybuddCache = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READONLY);
dbResults = rhybuddCache.query("devices",new String[]{"rhybuddDeviceID","productionState","ipAddress","name","uid","infoEvents","debugEvents","warningEvents","errorEvents","criticalEvents"},null, null, null, null, null);
}
catch(Exception e)
@@ -27,9 +27,7 @@
import org.json.JSONObject;
import android.app.Activity;
-import android.app.AlertDialog;
import android.content.ContentValues;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
@@ -39,6 +37,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -374,6 +373,9 @@ public void run()
// Try again later if the app is still live
runnablesHandler.postDelayed(this, 3604000);// 1 hour
+
+ if(cacheDB.isOpen())
+ cacheDB.close();
}
};
devicesRefreshThread.start();
@@ -427,8 +429,11 @@ public void run()
ContentValues values = new ContentValues(2);
try
{
+
CurrentEvent = Events.getJSONObject(i);
-
+
+ //Log.i("evi",CurrentEvent.getString("evid"));
+
values.put("EVID",CurrentEvent.getString("evid"));
values.put("device", CurrentEvent.getJSONObject("device").getString("text"));
values.put("summary", CurrentEvent.getString("summary"));
@@ -25,11 +25,13 @@
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
+import android.graphics.PixelFormat;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
+import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
@@ -52,6 +54,13 @@
Dialog addMessageDialog;
String[] LogEntries;
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ Window window = getWindow();
+ window.setFormat(PixelFormat.RGBA_8888);
+ }
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
Oops, something went wrong.

0 comments on commit 98c10d3

Please sign in to comment.