Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 028f6f90 authored by Joe Steele's avatar Joe Steele
Browse files

Remove AccessibleWebView

Only used on pre-ICS devices
parent 0fba2733
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -26,11 +26,6 @@
	            android:layout_height="wrap_content"
	            android:layout_width="fill_parent"/>
	
	        <com.fsck.k9.view.AccessibleWebView
	            android:id="@+id/accessible_message_content"
	            android:layout_height="wrap_content"
	            android:layout_width="fill_parent"/>
	
	        <!-- Attachments area -->
	
	        <LinearLayout
+0 −108
Original line number Diff line number Diff line
/*
 * 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.view;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.fsck.k9.activity.AccessibleEmailContentActivity;
import com.fsck.k9.controller.MessagingListener;

import java.util.Set;

public class AccessibleWebView extends TextView {
    private Context mContext;
    private String mHtmlSource;
    private WebView mDummyWebView;
    private Set<MessagingListener> mListeners = null;

    public AccessibleWebView(Context context) {
        super(context);
        init(context);
    }

    public AccessibleWebView(Context context, AttributeSet attributes) {
        super(context, attributes);
        init(context);
    }

    private void init(Context context) {
        mContext = context;
        mDummyWebView = new WebView(context);
        setFocusable(true);
        setFocusableInTouchMode(true);
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                diveIn();
            }
        });
    }

    public void loadData(String data, String mimeType, String encoding) {
        mHtmlSource = data;
        this.setText(Html.fromHtml(mHtmlSource, null, null));
    }

    public WebSettings getSettings() {
        return mDummyWebView.getSettings();
    }

    public void setText(String text) {
        this.setText(Html.fromHtml(text, null, null));

        // Let everyone know that loading has finished.
        if (mListeners != null) {
            for (MessagingListener l : mListeners) {
                l.messageViewFinished();
            }
        }
    }

    public boolean zoomIn() {
        if (getTextSize() < 100) {
            setTextSize(getTextSize() + 5);
            return true;
        }
        return false;
    }

    public boolean zoomOut() {
        if (getTextSize() > 5) {
            setTextSize(getTextSize() - 5);
            return true;
        }
        return false;
    }

    private void diveIn() {
        Intent i = new Intent();
        i.setClass(mContext, AccessibleEmailContentActivity.class);
        i.putExtra("content", mHtmlSource);
        mContext.startActivity(i);
    }

    public void setListeners(final Set<MessagingListener> listeners) {
        this.mListeners = listeners;
    }
}
+13 −76
Original line number Diff line number Diff line
@@ -6,19 +6,15 @@ import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.List;

import android.app.Activity;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -91,11 +87,9 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
    private static final int DISPLAY_NAME_INDEX = 1;


    private boolean mScreenReaderEnabled;
    private MessageCryptoView mCryptoView;
    private MessageOpenPgpView mOpenPgpView;
    private MessageWebView mMessageContentView;
    private AccessibleWebView mAccessibleMessageContentView;
    private MessageHeader mHeaderContainer;
    private LinearLayout mAttachments;
    private Button mShowHiddenAttachments;
@@ -118,7 +112,6 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
    public void initialize(Fragment fragment) {
        Activity activity = fragment.getActivity();
        mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
        mAccessibleMessageContentView = (AccessibleWebView) findViewById(R.id.accessible_message_content);
        mMessageContentView.configure();
        activity.registerForContextMenu(mMessageContentView);
        mMessageContentView.setOnCreateContextMenuListener(this);
@@ -151,16 +144,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
        mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
        mDownloadRemainder.setVisibility(View.GONE);
        mAttachmentsContainer.setVisibility(View.GONE);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
                isScreenReaderActive(activity)) {
            // Only use the special screen reader mode on pre-ICS devices with active screen reader
            mAccessibleMessageContentView.setVisibility(View.VISIBLE);
            mMessageContentView.setVisibility(View.GONE);
            mScreenReaderEnabled = true;
        } else {
            mAccessibleMessageContentView.setVisibility(View.GONE);
        mMessageContentView.setVisibility(View.VISIBLE);
            mScreenReaderEnabled = false;

        // the HTC version of WebView tries to force the background of the
        // titlebar, which is really unfair.
@@ -169,7 +153,6 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
        mHeaderContainer.setBackgroundColor(outValue.data);
        // also set background of the whole view (including the attachments view)
        setBackgroundColor(outValue.data);
        }

        mShowHiddenAttachments.setOnClickListener(this);
        mShowMessageAction.setOnClickListener(this);
@@ -443,43 +426,6 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
    }


    private boolean isScreenReaderActive(Activity activity) {
        final String SCREENREADER_INTENT_ACTION = "android.accessibilityservice.AccessibilityService";
        final String SCREENREADER_INTENT_CATEGORY = "android.accessibilityservice.category.FEEDBACK_SPOKEN";
        // Restrict the set of intents to only accessibility services that have
        // the category FEEDBACK_SPOKEN (aka, screen readers).
        Intent screenReaderIntent = new Intent(SCREENREADER_INTENT_ACTION);
        screenReaderIntent.addCategory(SCREENREADER_INTENT_CATEGORY);
        List<ResolveInfo> screenReaders = activity.getPackageManager().queryIntentServices(
                                              screenReaderIntent, 0);
        ContentResolver cr = activity.getContentResolver();
        Cursor cursor = null;
        int status = 0;
        for (ResolveInfo screenReader : screenReaders) {
            // All screen readers are expected to implement a content provider
            // that responds to
            // content://<nameofpackage>.providers.StatusProvider
            cursor = cr.query(Uri.parse("content://" + screenReader.serviceInfo.packageName
                                        + ".providers.StatusProvider"), null, null, null, null);
            try {
                if (cursor != null && cursor.moveToFirst()) {
                    // These content providers use a special cursor that only has
                    // one element,
                    // an integer that is 1 if the screen reader is running.
                    status = cursor.getInt(0);
                    if (status == 1) {
                        return true;
                    }
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
        return false;
    }

    public boolean showPictures() {
        return mShowPictures;
    }
@@ -640,14 +586,9 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
    }

    private void loadBodyFromText(String emailText) {
        if (mScreenReaderEnabled) {
            mAccessibleMessageContentView.setText(emailText);
        } else {
        mMessageContentView.setText(emailText);
    }

    }

    public void updateCryptoLayout(CryptoProvider cp, PgpData pgpData, Message message) {
        mCryptoView.updateLayout(cp, pgpData, message);
    }
@@ -710,16 +651,12 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
    }

    public void zoom(KeyEvent event) {
        if (mScreenReaderEnabled) {
            mAccessibleMessageContentView.zoomIn();
        } else {
        if (event.isShiftPressed()) {
            mMessageContentView.zoomIn();
        } else {
            mMessageContentView.zoomOut();
        }
    }
    }

    public void beginSelectingText() {
        mMessageContentView.emulateShiftHeld();