mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Remove AccessibleWebView
Only used on pre-ICS devices
This commit is contained in:
parent
0fba273357
commit
028f6f9055
@ -26,11 +26,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"/>
|
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 -->
|
<!-- Attachments area -->
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,19 +6,15 @@ import java.io.InputStream;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@ -91,11 +87,9 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
private static final int DISPLAY_NAME_INDEX = 1;
|
private static final int DISPLAY_NAME_INDEX = 1;
|
||||||
|
|
||||||
|
|
||||||
private boolean mScreenReaderEnabled;
|
|
||||||
private MessageCryptoView mCryptoView;
|
private MessageCryptoView mCryptoView;
|
||||||
private MessageOpenPgpView mOpenPgpView;
|
private MessageOpenPgpView mOpenPgpView;
|
||||||
private MessageWebView mMessageContentView;
|
private MessageWebView mMessageContentView;
|
||||||
private AccessibleWebView mAccessibleMessageContentView;
|
|
||||||
private MessageHeader mHeaderContainer;
|
private MessageHeader mHeaderContainer;
|
||||||
private LinearLayout mAttachments;
|
private LinearLayout mAttachments;
|
||||||
private Button mShowHiddenAttachments;
|
private Button mShowHiddenAttachments;
|
||||||
@ -118,7 +112,6 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
public void initialize(Fragment fragment) {
|
public void initialize(Fragment fragment) {
|
||||||
Activity activity = fragment.getActivity();
|
Activity activity = fragment.getActivity();
|
||||||
mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
|
mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
|
||||||
mAccessibleMessageContentView = (AccessibleWebView) findViewById(R.id.accessible_message_content);
|
|
||||||
mMessageContentView.configure();
|
mMessageContentView.configure();
|
||||||
activity.registerForContextMenu(mMessageContentView);
|
activity.registerForContextMenu(mMessageContentView);
|
||||||
mMessageContentView.setOnCreateContextMenuListener(this);
|
mMessageContentView.setOnCreateContextMenuListener(this);
|
||||||
@ -151,25 +144,15 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
|
mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
|
||||||
mDownloadRemainder.setVisibility(View.GONE);
|
mDownloadRemainder.setVisibility(View.GONE);
|
||||||
mAttachmentsContainer.setVisibility(View.GONE);
|
mAttachmentsContainer.setVisibility(View.GONE);
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
|
mMessageContentView.setVisibility(View.VISIBLE);
|
||||||
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
|
// the HTC version of WebView tries to force the background of the
|
||||||
// titlebar, which is really unfair.
|
// titlebar, which is really unfair.
|
||||||
TypedValue outValue = new TypedValue();
|
TypedValue outValue = new TypedValue();
|
||||||
getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
|
getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
|
||||||
mHeaderContainer.setBackgroundColor(outValue.data);
|
mHeaderContainer.setBackgroundColor(outValue.data);
|
||||||
// also set background of the whole view (including the attachments view)
|
// also set background of the whole view (including the attachments view)
|
||||||
setBackgroundColor(outValue.data);
|
setBackgroundColor(outValue.data);
|
||||||
}
|
|
||||||
|
|
||||||
mShowHiddenAttachments.setOnClickListener(this);
|
mShowHiddenAttachments.setOnClickListener(this);
|
||||||
mShowMessageAction.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() {
|
public boolean showPictures() {
|
||||||
return mShowPictures;
|
return mShowPictures;
|
||||||
}
|
}
|
||||||
@ -640,12 +586,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadBodyFromText(String emailText) {
|
private void loadBodyFromText(String emailText) {
|
||||||
if (mScreenReaderEnabled) {
|
mMessageContentView.setText(emailText);
|
||||||
mAccessibleMessageContentView.setText(emailText);
|
|
||||||
} else {
|
|
||||||
mMessageContentView.setText(emailText);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCryptoLayout(CryptoProvider cp, PgpData pgpData, Message message) {
|
public void updateCryptoLayout(CryptoProvider cp, PgpData pgpData, Message message) {
|
||||||
@ -710,14 +651,10 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void zoom(KeyEvent event) {
|
public void zoom(KeyEvent event) {
|
||||||
if (mScreenReaderEnabled) {
|
if (event.isShiftPressed()) {
|
||||||
mAccessibleMessageContentView.zoomIn();
|
mMessageContentView.zoomIn();
|
||||||
} else {
|
} else {
|
||||||
if (event.isShiftPressed()) {
|
mMessageContentView.zoomOut();
|
||||||
mMessageContentView.zoomIn();
|
|
||||||
} else {
|
|
||||||
mMessageContentView.zoomOut();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user