2010-08-17 22:01:10 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The IDEAL Group
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.fsck.k9.web;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import android.app.ListActivity;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.Html;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
2010-08-17 22:48:55 -04:00
|
|
|
public class AccessibleEmailContentActivity extends ListActivity
|
|
|
|
{
|
2010-09-02 22:15:57 -04:00
|
|
|
/**
|
|
|
|
* Immutable empty String array
|
|
|
|
*/
|
|
|
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
2010-08-17 22:01:10 -04:00
|
|
|
|
2010-09-02 22:15:57 -04:00
|
|
|
/**
|
|
|
|
* Called when the activity is first created.
|
|
|
|
*/
|
2010-08-17 22:01:10 -04:00
|
|
|
@Override
|
2010-08-17 22:48:55 -04:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2010-08-17 22:01:10 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2010-09-02 22:15:57 -04:00
|
|
|
String htmlSource = getIntent().getStringExtra("content");
|
2010-08-17 22:01:10 -04:00
|
|
|
Spanned parsedHtml = Html.fromHtml(htmlSource, null, null);
|
|
|
|
String[] rawListItems = parsedHtml.toString().split("\n");
|
|
|
|
|
2010-09-02 22:15:57 -04:00
|
|
|
ArrayList<String> cleanedList = new ArrayList<String>();
|
2010-08-17 22:48:55 -04:00
|
|
|
for (int i = 0; i < rawListItems.length; i++)
|
|
|
|
{
|
|
|
|
if (rawListItems[i].trim().length() > 0)
|
|
|
|
{
|
2010-09-02 22:15:57 -04:00
|
|
|
addToCleanedList(cleanedList, rawListItems[i]);
|
2010-08-17 22:01:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 22:15:57 -04:00
|
|
|
String[] listItems = cleanedList.toArray(EMPTY_STRING_ARRAY);
|
2010-08-17 22:01:10 -04:00
|
|
|
|
|
|
|
setContentView(com.fsck.k9.R.layout.accessible_email_content);
|
2010-09-02 22:15:57 -04:00
|
|
|
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems));
|
2010-08-17 22:01:10 -04:00
|
|
|
}
|
|
|
|
|
2010-09-02 22:15:57 -04:00
|
|
|
private void addToCleanedList(ArrayList<String> cleanedList, String line)
|
2010-08-17 22:48:55 -04:00
|
|
|
{
|
|
|
|
if (line.length() < 80)
|
|
|
|
{
|
2010-08-17 22:01:10 -04:00
|
|
|
cleanedList.add(line);
|
2010-08-17 22:48:55 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (line.length() > 80)
|
|
|
|
{
|
2010-08-17 22:01:10 -04:00
|
|
|
int cutPoint = line.indexOf(" ", 80);
|
2010-08-17 22:48:55 -04:00
|
|
|
if ((cutPoint > 0) && (cutPoint < line.length()))
|
|
|
|
{
|
2010-08-17 22:01:10 -04:00
|
|
|
cleanedList.add(line.substring(0, cutPoint));
|
|
|
|
line = line.substring(cutPoint).trim();
|
2010-08-17 22:48:55 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-17 22:01:10 -04:00
|
|
|
cleanedList.add(line);
|
|
|
|
line = "";
|
|
|
|
}
|
|
|
|
}
|
2010-08-17 22:48:55 -04:00
|
|
|
if (line.length() > 0)
|
|
|
|
{
|
2010-08-17 22:01:10 -04:00
|
|
|
cleanedList.add(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|