5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-11-09 10:20:25 +00:00

add menu with options to test server connection, or edit settings

This commit is contained in:
Jesse Young 2011-09-11 21:21:42 -07:00
parent fc6cda4ea3
commit 8f15a8c8f2
4 changed files with 55 additions and 13 deletions

9
res/menu/mainmenu.xml Executable file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:icon="@drawable/icon"
android:title="@string/settings" />
<item android:id="@+id/test"
android:icon="@drawable/icon"
android:title="@string/test" />
</menu>

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">KalSMS Envaya</string>
<string name="settings">Settings</string>
<string name="test">Test</string>
</resources>

View File

@ -29,6 +29,7 @@ public class App {
public static final String ACTION_OUTGOING = "outgoing";
public static final String ACTION_INCOMING = "incoming";
public static final String ACTION_SEND_STATUS = "send_status";
public static final String ACTION_TEST = "test";
public static final int STATUS_QUEUED = 1;
public static final int STATUS_FAILED = 2;

View File

@ -10,14 +10,20 @@ import android.preference.PreferenceManager;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import org.apache.http.HttpResponse;
import org.apache.http.message.BasicNameValuePair;
public class Main extends Activity {
private App app;
private BroadcastReceiver logReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -25,6 +31,19 @@ public class Main extends Activity {
}
};
private class TestTask extends HttpTask
{
public TestTask() {
super(app);
}
@Override
protected void handleResponse(HttpResponse response) throws Exception
{
app.log("Server connection OK!");
}
}
private long lastLogTime = 0;
public void showLogMessage(String message)
@ -85,7 +104,7 @@ public class Main extends Activity {
App.debug("STARTED");
App app = App.getInstance(this.getApplication());
this.app = App.getInstance(this.getApplication());
setContentView(R.layout.main);
PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
@ -104,25 +123,36 @@ public class Main extends Activity {
logReceiverFilter.addAction(App.LOG_INTENT);
registerReceiver(logReceiver, logReceiverFilter);
app.setOutgoingMessageAlarm();
for (int i = 0; i < 30; i++)
{
showLogMessage(" " + i);
}
app.setOutgoingMessageAlarm();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, Prefs.class));
return true;
case R.id.test:
app.log("Testing server connection...");
new TestTask().execute(
new BasicNameValuePair("action", App.ACTION_TEST)
);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
// first time the Menu key is pressed
@Override
public boolean onCreateOptionsMenu(Menu menu) {
startActivity(new Intent(this, Prefs.class));
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
return(true);
}
// any other time the Menu key is pressed
public boolean onPrepareOptionsMenu(Menu menu) {
startActivity(new Intent(this, Prefs.class));
return(true);
}
@Override
protected void onStop(){