mirror of
https://github.com/cwinfo/envayasms.git
synced 2024-12-04 12:35:32 +00:00
improve performance of displaying log in Main activity
This commit is contained in:
parent
cf1deeceab
commit
dedfdb582a
@ -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
|
||||
@ -473,6 +476,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()
|
||||
{
|
||||
|
@ -79,6 +79,10 @@ public class Inbox {
|
||||
{
|
||||
incomingQueue.remove(message);
|
||||
}
|
||||
else if (message.getProcessingState() == IncomingMessage.ProcessingState.Forwarding)
|
||||
{
|
||||
numForwardingMessages--;
|
||||
}
|
||||
|
||||
app.log(message.getDescription() + " deleted");
|
||||
notifyChanged();
|
||||
|
@ -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");
|
||||
|
@ -31,6 +31,9 @@ public class Main extends Activity {
|
||||
}
|
||||
};
|
||||
|
||||
private ScrollView scrollView;
|
||||
private TextView info;
|
||||
|
||||
private class TestTask extends HttpTask
|
||||
{
|
||||
public TestTask() {
|
||||
@ -44,14 +47,32 @@ public class Main extends Activity {
|
||||
app.log("Server connection OK!");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
info.setText(app.getDisplayedLog());
|
||||
{
|
||||
int logEpoch = app.getLogEpoch();
|
||||
CharSequence displayedLog = 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);
|
||||
} });
|
||||
@ -63,11 +84,13 @@ public class Main extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
app = (App) getApplication();
|
||||
|
||||
|
||||
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();
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user