Skip to content

Commit

Permalink
add basic menus
Browse files Browse the repository at this point in the history
Add a menu on the main layout to exit the app.  Added a menu on the
display of database statistics to stop monitoring and return to the main
layout.
  • Loading branch information
markwkm committed Jul 5, 2010
1 parent e798d15 commit 7992b3a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
2 changes: 0 additions & 2 deletions res/layout/pg_stat_database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
android:layout_height="wrap_content"></TextView>
<TextView android:id="@+id/tup_deleted" android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<Button android:text="Monitor Another Database" android:id="@+id/stop"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
4 changes: 4 additions & 0 deletions res/menu/exit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/exit" android:title="Exit" />
</menu>
4 changes: 4 additions & 0 deletions res/menu/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/stop" android:title="Stop Monitoring" />
</menu>
48 changes: 29 additions & 19 deletions src/org/postgresql/top/PGStatDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class PGStatDatabase extends Activity implements OnClickListener,
Runnable {
public class PGStatDatabase extends Activity implements Runnable {
private String pgDatabase;
private String url;
private String pgUser;
Expand Down Expand Up @@ -125,22 +124,13 @@ private void getDatabaseStats() throws SQLException {
conn.close();
}

public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pg_stat_database);

state = State.RUNNING;

final Button stopButton = (Button) findViewById(R.id.stop);
stopButton.setOnClickListener(this);

try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
Expand All @@ -150,11 +140,11 @@ public void onCreate(Bundle savedInstanceState) {
return;
}

SharedPreferences settings = getSharedPreferences("PGTopPrefs", 0);
pgDatabase = settings.getString("pgdatabase", "");
url = settings.getString("pgurl", "");
pgUser = settings.getString("pguser", "");
pgPassword = settings.getString("pgpassword", "");
SharedPreferences preferences = getSharedPreferences("PGTopPrefs", 0);
pgDatabase = preferences.getString("pgdatabase", "");
url = preferences.getString("pgurl", "");
pgUser = preferences.getString("pguser", "");
pgPassword = preferences.getString("pgpassword", "");

headerTextView = (TextView) findViewById(R.id.displayheader);
numbackendsTextView = (TextView) findViewById(R.id.numbackends);
Expand All @@ -171,12 +161,32 @@ public void onCreate(Bundle savedInstanceState) {
thread = new Thread(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

@Override
protected void onDestroy() {
super.onDestroy();
state = State.EXITING;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.stop:
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
protected void onPause() {
super.onPause();
Expand Down
21 changes: 21 additions & 0 deletions src/org/postgresql/top/PGTop.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
Expand Down Expand Up @@ -59,4 +62,22 @@ public void onCreate(Bundle savedInstanceState) {
final Button startButton = (Button) findViewById(R.id.start);
startButton.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.exit, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.exit:
System.exit(0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

0 comments on commit 7992b3a

Please sign in to comment.