5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-12-04 20:45:32 +00:00

improve performance of displaying log in Main activity

This commit is contained in:
Jesse Young 2011-10-01 15:45:28 -07:00
parent cf1deeceab
commit dedfdb582a
5 changed files with 57 additions and 8 deletions

View File

@ -86,7 +86,7 @@ public final class App extends Application {
public static final String STATUS_EXTRA_INDEX = "status"; public static final String STATUS_EXTRA_INDEX = "status";
public static final String STATUS_EXTRA_NUM_PARTS = "num_parts"; public static final String STATUS_EXTRA_NUM_PARTS = "num_parts";
public static final int MAX_DISPLAYED_LOG = 4000; public static final int MAX_DISPLAYED_LOG = 8000;
public static final int LOG_TIMESTAMP_INTERVAL = 60000; // ms public static final int LOG_TIMESTAMP_INTERVAL = 60000; // ms
public static final int HTTP_CONNECTION_TIMEOUT = 10000; // ms public static final int HTTP_CONNECTION_TIMEOUT = 10000; // ms
@ -437,6 +437,8 @@ public final class App extends Application {
Log.d(LOG_NAME, msg); Log.d(LOG_NAME, msg);
} }
private int logEpoch = 0;
public synchronized void log(CharSequence msg) public synchronized void log(CharSequence msg)
{ {
Log.d(LOG_NAME, msg.toString()); Log.d(LOG_NAME, msg.toString());
@ -457,6 +459,7 @@ public final class App extends Application {
} }
displayedLog.replace(0, startPos, "[Older log messages not shown]\n"); displayedLog.replace(0, startPos, "[Older log messages not shown]\n");
logEpoch++;
} }
// display a timestamp in the log occasionally // display a timestamp in the log occasionally
@ -473,6 +476,16 @@ public final class App extends Application {
sendBroadcast(new Intent(App.LOG_CHANGED_INTENT)); sendBroadcast(new Intent(App.LOG_CHANGED_INTENT));
} }
/*
* Changes whenever we change the beginning of the displayed log.
* If it doesn't change, the Main activity can update the log view much
* faster by using TextView.append() instead of TextView.setText()
*/
public int getLogEpoch()
{
return logEpoch;
}
public synchronized CharSequence getDisplayedLog() public synchronized CharSequence getDisplayedLog()
{ {

View File

@ -79,6 +79,10 @@ public class Inbox {
{ {
incomingQueue.remove(message); incomingQueue.remove(message);
} }
else if (message.getProcessingState() == IncomingMessage.ProcessingState.Forwarding)
{
numForwardingMessages--;
}
app.log(message.getDescription() + " deleted"); app.log(message.getDescription() + " deleted");
notifyChanged(); notifyChanged();

View File

@ -176,6 +176,11 @@ public class Outbox {
{ {
outgoingQueue.remove(message); outgoingQueue.remove(message);
} }
else if (message.getProcessingState() == OutgoingMessage.ProcessingState.Sending)
{
numSendingOutgoingMessages--;
}
notifyMessageStatus(message, App.STATUS_FAILED, notifyMessageStatus(message, App.STATUS_FAILED,
"deleted by user"); "deleted by user");
app.log(message.getDescription() + " deleted"); app.log(message.getDescription() + " deleted");

View File

@ -31,6 +31,9 @@ public class Main extends Activity {
} }
}; };
private ScrollView scrollView;
private TextView info;
private class TestTask extends HttpTask private class TestTask extends HttpTask
{ {
public TestTask() { public TestTask() {
@ -44,14 +47,32 @@ public class Main extends Activity {
app.log("Server connection OK!"); app.log("Server connection OK!");
} }
} }
private int lastLogEpoch = -1;
public void updateLogView() public void updateLogView()
{ {
final ScrollView scrollView = (ScrollView) this.findViewById(R.id.info_scroll); int logEpoch = app.getLogEpoch();
TextView info = (TextView) this.findViewById(R.id.info); CharSequence displayedLog = app.getDisplayedLog();
info.setText(app.getDisplayedLog());
if (lastLogEpoch == logEpoch)
{
int beforeLen = info.getText().length();
int afterLen = displayedLog.length();
if (beforeLen == afterLen)
{
return;
}
info.append(displayedLog, beforeLen, afterLen);
}
else
{
info.setText(displayedLog);
lastLogEpoch = logEpoch;
}
scrollView.post(new Runnable() { public void run() { scrollView.post(new Runnable() { public void run() {
scrollView.fullScroll(View.FOCUS_DOWN); scrollView.fullScroll(View.FOCUS_DOWN);
} }); } });
@ -63,11 +84,13 @@ public class Main extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
app = (App) getApplication(); app = (App) getApplication();
setContentView(R.layout.main); setContentView(R.layout.main);
PreferenceManager.setDefaultValues(this, R.xml.prefs, false); PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
TextView info = (TextView) this.findViewById(R.id.info); scrollView = (ScrollView) this.findViewById(R.id.info_scroll);
info = (TextView) this.findViewById(R.id.info);
info.setMovementMethod(new ScrollingMovementMethod()); info.setMovementMethod(new ScrollingMovementMethod());
updateLogView(); updateLogView();

View File

@ -123,6 +123,8 @@ public class PendingMessages extends ListActivity {
displayedMessages = messages; displayedMessages = messages;
this.setTitle("EnvayaSMS : Pending Messages ("+messages.size()+")");
final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final DateFormat longFormat = new SimpleDateFormat("dd MMM hh:mm:ss"); final DateFormat longFormat = new SimpleDateFormat("dd MMM hh:mm:ss");
final DateFormat shortFormat = new SimpleDateFormat("hh:mm:ss"); final DateFormat shortFormat = new SimpleDateFormat("hh:mm:ss");
@ -169,6 +171,8 @@ public class PendingMessages extends ListActivity {
}; };
setListAdapter(arrayAdapter); setListAdapter(arrayAdapter);
} }
public void deleteMessage(QueuedMessage message) public void deleteMessage(QueuedMessage message)