From 9d9e669d65086f7a2ae700425822eb46f375b246 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 3 Sep 2010 02:15:57 +0000 Subject: [PATCH] Code cleanup --- src/com/fsck/k9/activity/ChooseIdentity.java | 38 +----------- .../web/AccessibleEmailContentActivity.java | 29 ++++----- src/com/fsck/k9/web/AccessibleWebView.java | 60 ++++++------------- 3 files changed, 34 insertions(+), 93 deletions(-) diff --git a/src/com/fsck/k9/activity/ChooseIdentity.java b/src/com/fsck/k9/activity/ChooseIdentity.java index d9c0499e2..7c6336ad8 100644 --- a/src/com/fsck/k9/activity/ChooseIdentity.java +++ b/src/com/fsck/k9/activity/ChooseIdentity.java @@ -3,7 +3,6 @@ package com.fsck.k9.activity; import android.content.Intent; import android.os.Bundle; -import android.os.Handler; import android.view.View; import android.view.Window; import android.widget.AdapterView; @@ -58,6 +57,7 @@ public class ChooseIdentity extends K9ListActivity protected void refreshView() { + adapter.setNotifyOnChange(false); adapter.clear(); identities = mAccount.getIdentities(); @@ -71,6 +71,7 @@ public class ChooseIdentity extends K9ListActivity adapter.add(description); } + adapter.notifyDataSetChanged(); } protected void setupClickListeners() @@ -98,39 +99,4 @@ public class ChooseIdentity extends K9ListActivity }); } - - class ChooseIdentityHandler extends Handler - { - - private static final int MSG_PROGRESS = 2; - private static final int MSG_DATA_CHANGED = 3; - - @Override - public void handleMessage(android.os.Message msg) - { - switch (msg.what) - { - case MSG_PROGRESS: - setProgressBarIndeterminateVisibility(msg.arg1 != 0); - break; - case MSG_DATA_CHANGED: - adapter.notifyDataSetChanged(); - break; - } - } - - public void progress(boolean progress) - { - android.os.Message msg = new android.os.Message(); - msg.what = MSG_PROGRESS; - msg.arg1 = progress ? 1 : 0; - sendMessage(msg); - } - - public void dataChanged() - { - sendEmptyMessage(MSG_DATA_CHANGED); - } - } - } diff --git a/src/com/fsck/k9/web/AccessibleEmailContentActivity.java b/src/com/fsck/k9/web/AccessibleEmailContentActivity.java index c63d7c0f3..115efb708 100644 --- a/src/com/fsck/k9/web/AccessibleEmailContentActivity.java +++ b/src/com/fsck/k9/web/AccessibleEmailContentActivity.java @@ -17,7 +17,6 @@ package com.fsck.k9.web; import java.util.ArrayList; - import android.app.ListActivity; import android.os.Bundle; import android.text.Html; @@ -26,41 +25,39 @@ import android.widget.ArrayAdapter; public class AccessibleEmailContentActivity extends ListActivity { - String[] listItems = - { - "" - }; + /** + * Immutable empty String array + */ + private static final String[] EMPTY_STRING_ARRAY = new String[0]; - private String htmlSource; - - private ArrayList cleanedList; - - /** Called when the activity is first created. */ + /** + * Called when the activity is first created. + */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - htmlSource = getIntent().getStringExtra("content"); + String htmlSource = getIntent().getStringExtra("content"); Spanned parsedHtml = Html.fromHtml(htmlSource, null, null); String[] rawListItems = parsedHtml.toString().split("\n"); - cleanedList = new ArrayList(); + ArrayList cleanedList = new ArrayList(); for (int i = 0; i < rawListItems.length; i++) { if (rawListItems[i].trim().length() > 0) { - addToCleanedList(rawListItems[i]); + addToCleanedList(cleanedList, rawListItems[i]); } } - listItems = cleanedList.toArray(listItems); + String[] listItems = cleanedList.toArray(EMPTY_STRING_ARRAY); setContentView(com.fsck.k9.R.layout.accessible_email_content); - setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems)); + setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems)); } - private void addToCleanedList(String line) + private void addToCleanedList(ArrayList cleanedList, String line) { if (line.length() < 80) { diff --git a/src/com/fsck/k9/web/AccessibleWebView.java b/src/com/fsck/k9/web/AccessibleWebView.java index 3b601f269..2b0cf8cd5 100644 --- a/src/com/fsck/k9/web/AccessibleWebView.java +++ b/src/com/fsck/k9/web/AccessibleWebView.java @@ -16,7 +16,6 @@ package com.fsck.k9.web; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.text.Html; @@ -28,34 +27,26 @@ import android.widget.TextView; public class AccessibleWebView extends TextView { - private Activity parent; - - private String htmlSource; - - private WebView dummyWebView; + private Context mContext; + private String mHtmlSource; + private WebView mDummyWebView; public AccessibleWebView(Context context) { super(context); - parent = (Activity) context; - dummyWebView = new WebView(context); - setFocusable(true); - setFocusableInTouchMode(true); - setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View arg0) - { - diveIn(); - } - }); + init(context); } public AccessibleWebView(Context context, AttributeSet attributes) { super(context, attributes); - parent = (Activity) context; - dummyWebView = new WebView(context); + init(context); + } + + private void init(Context context) + { + mContext = context; + mDummyWebView = new WebView(context); setFocusable(true); setFocusableInTouchMode(true); setOnClickListener(new OnClickListener() @@ -66,37 +57,24 @@ public class AccessibleWebView extends TextView diveIn(); } }); - } public void loadData(String data, String mimeType, String encoding) { - htmlSource = data; - this.setText(Html.fromHtml(htmlSource, null, null)); + mHtmlSource = data; + this.setText(Html.fromHtml(mHtmlSource, null, null)); } public WebSettings getSettings() { - return dummyWebView.getSettings(); - } - - public void setVerticalScrollbarOverlay(boolean booleanValue) - { - // Do nothing here; dummy stub method to maintain compatibility with - // standard WebView. + return mDummyWebView.getSettings(); } public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) { - htmlSource = data; - this.setText(Html.fromHtml(htmlSource, null, null)); - } - - public void loadUrl(String url) - { - // Do nothing here; dummy stub method to maintain compatibility with - // standard WebView. + mHtmlSource = data; + this.setText(Html.fromHtml(mHtmlSource, null, null)); } public boolean zoomIn() @@ -122,8 +100,8 @@ public class AccessibleWebView extends TextView private void diveIn() { Intent i = new Intent(); - i.setClass(parent, AccessibleEmailContentActivity.class); - i.putExtra("content", htmlSource); - parent.startActivity(i); + i.setClass(mContext, AccessibleEmailContentActivity.class); + i.putExtra("content", mHtmlSource); + mContext.startActivity(i); } }