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_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 HTTP_CONNECTION_TIMEOUT = 10000; // ms
@ -437,6 +437,8 @@ public final class App extends Application {
Log.d(LOG_NAME, msg);
}
private int logEpoch = 0;
public synchronized void log(CharSequence msg)
{
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");
logEpoch++;
}
// display a timestamp in the log occasionally
@ -474,6 +477,16 @@ public final class App extends Application {
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()
{
return displayedLog;

View File

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

View File

@ -176,6 +176,11 @@ public class Outbox {
{
outgoingQueue.remove(message);
}
else if (message.getProcessingState() == OutgoingMessage.ProcessingState.Sending)
{
numSendingOutgoingMessages--;
}
notifyMessageStatus(message, App.STATUS_FAILED,
"deleted by user");
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
{
public TestTask() {
@ -45,12 +48,30 @@ public class Main extends Activity {
}
}
private int lastLogEpoch = -1;
public void updateLogView()
{
final ScrollView scrollView = (ScrollView) this.findViewById(R.id.info_scroll);
TextView info = (TextView) this.findViewById(R.id.info);
int logEpoch = app.getLogEpoch();
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.fullScroll(View.FOCUS_DOWN);
@ -67,7 +88,9 @@ public class Main extends Activity {
setContentView(R.layout.main);
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());
updateLogView();

View File

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