1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-12 04:25:08 -05:00

Code cleanup

This commit is contained in:
cketti 2010-09-03 02:15:57 +00:00
parent b44bed2596
commit 9d9e669d65
3 changed files with 34 additions and 93 deletions

View File

@ -3,7 +3,6 @@ package com.fsck.k9.activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -58,6 +57,7 @@ public class ChooseIdentity extends K9ListActivity
protected void refreshView() protected void refreshView()
{ {
adapter.setNotifyOnChange(false);
adapter.clear(); adapter.clear();
identities = mAccount.getIdentities(); identities = mAccount.getIdentities();
@ -71,6 +71,7 @@ public class ChooseIdentity extends K9ListActivity
adapter.add(description); adapter.add(description);
} }
adapter.notifyDataSetChanged();
} }
protected void setupClickListeners() 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);
}
}
} }

View File

@ -17,7 +17,6 @@
package com.fsck.k9.web; package com.fsck.k9.web;
import java.util.ArrayList; import java.util.ArrayList;
import android.app.ListActivity; import android.app.ListActivity;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
@ -26,41 +25,39 @@ import android.widget.ArrayAdapter;
public class AccessibleEmailContentActivity extends ListActivity public class AccessibleEmailContentActivity extends ListActivity
{ {
String[] listItems = /**
{ * Immutable empty String array
"" */
}; private static final String[] EMPTY_STRING_ARRAY = new String[0];
private String htmlSource; /**
* Called when the activity is first created.
private ArrayList<String> cleanedList; */
/** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
htmlSource = getIntent().getStringExtra("content"); String htmlSource = getIntent().getStringExtra("content");
Spanned parsedHtml = Html.fromHtml(htmlSource, null, null); Spanned parsedHtml = Html.fromHtml(htmlSource, null, null);
String[] rawListItems = parsedHtml.toString().split("\n"); String[] rawListItems = parsedHtml.toString().split("\n");
cleanedList = new ArrayList<String>(); ArrayList<String> cleanedList = new ArrayList<String>();
for (int i = 0; i < rawListItems.length; i++) for (int i = 0; i < rawListItems.length; i++)
{ {
if (rawListItems[i].trim().length() > 0) 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); setContentView(com.fsck.k9.R.layout.accessible_email_content);
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems)); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems));
} }
private void addToCleanedList(String line) private void addToCleanedList(ArrayList<String> cleanedList, String line)
{ {
if (line.length() < 80) if (line.length() < 80)
{ {

View File

@ -16,7 +16,6 @@
package com.fsck.k9.web; package com.fsck.k9.web;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.text.Html; import android.text.Html;
@ -28,34 +27,26 @@ import android.widget.TextView;
public class AccessibleWebView extends TextView public class AccessibleWebView extends TextView
{ {
private Activity parent; private Context mContext;
private String mHtmlSource;
private String htmlSource; private WebView mDummyWebView;
private WebView dummyWebView;
public AccessibleWebView(Context context) public AccessibleWebView(Context context)
{ {
super(context); super(context);
parent = (Activity) context; init(context);
dummyWebView = new WebView(context);
setFocusable(true);
setFocusableInTouchMode(true);
setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
diveIn();
}
});
} }
public AccessibleWebView(Context context, AttributeSet attributes) public AccessibleWebView(Context context, AttributeSet attributes)
{ {
super(context, attributes); super(context, attributes);
parent = (Activity) context; init(context);
dummyWebView = new WebView(context); }
private void init(Context context)
{
mContext = context;
mDummyWebView = new WebView(context);
setFocusable(true); setFocusable(true);
setFocusableInTouchMode(true); setFocusableInTouchMode(true);
setOnClickListener(new OnClickListener() setOnClickListener(new OnClickListener()
@ -66,37 +57,24 @@ public class AccessibleWebView extends TextView
diveIn(); diveIn();
} }
}); });
} }
public void loadData(String data, String mimeType, String encoding) public void loadData(String data, String mimeType, String encoding)
{ {
htmlSource = data; mHtmlSource = data;
this.setText(Html.fromHtml(htmlSource, null, null)); this.setText(Html.fromHtml(mHtmlSource, null, null));
} }
public WebSettings getSettings() public WebSettings getSettings()
{ {
return dummyWebView.getSettings(); return mDummyWebView.getSettings();
}
public void setVerticalScrollbarOverlay(boolean booleanValue)
{
// Do nothing here; dummy stub method to maintain compatibility with
// standard WebView.
} }
public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding,
String historyUrl) String historyUrl)
{ {
htmlSource = data; mHtmlSource = data;
this.setText(Html.fromHtml(htmlSource, null, null)); this.setText(Html.fromHtml(mHtmlSource, null, null));
}
public void loadUrl(String url)
{
// Do nothing here; dummy stub method to maintain compatibility with
// standard WebView.
} }
public boolean zoomIn() public boolean zoomIn()
@ -122,8 +100,8 @@ public class AccessibleWebView extends TextView
private void diveIn() private void diveIn()
{ {
Intent i = new Intent(); Intent i = new Intent();
i.setClass(parent, AccessibleEmailContentActivity.class); i.setClass(mContext, AccessibleEmailContentActivity.class);
i.putExtra("content", htmlSource); i.putExtra("content", mHtmlSource);
parent.startActivity(i); mContext.startActivity(i);
} }
} }