1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

Move the "isScreenReader" active code down into the MessageView

This commit is contained in:
Jesse Vincent 2011-02-14 11:54:01 -05:00
parent 04bc32db9e
commit 5aad882976
2 changed files with 50 additions and 42 deletions

View File

@ -8,7 +8,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -313,7 +312,7 @@ public class MessageView extends K9Activity implements OnClickListener {
mTopView = mToggleScrollView = (ToggleScrollView) findViewById(R.id.top_view); mTopView = mToggleScrollView = (ToggleScrollView) findViewById(R.id.top_view);
mMessageView = (SingleMessageView) findViewById(R.id.message_view); mMessageView = (SingleMessageView) findViewById(R.id.message_view);
mMessageView.initialize(this, isScreenReaderActive()); mMessageView.initialize(this);
setTitle(""); setTitle("");
Intent intent = getIntent(); Intent intent = getIntent();
@ -409,10 +408,8 @@ public class MessageView extends K9Activity implements OnClickListener {
// Perhaps the ScrollButtons should be global, instead of account-specific // Perhaps the ScrollButtons should be global, instead of account-specific
Account.ScrollButtons scrollButtons = mAccount.getScrollMessageViewButtons(); Account.ScrollButtons scrollButtons = mAccount.getScrollMessageViewButtons();
if if ((Account.ScrollButtons.ALWAYS == scrollButtons)
((Account.ScrollButtons.ALWAYS == scrollButtons) || (Account.ScrollButtons.KEYBOARD_AVAILABLE == scrollButtons &&
||
(Account.ScrollButtons.KEYBOARD_AVAILABLE == scrollButtons &&
(this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))) { (this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))) {
scrollButtons(); scrollButtons();
} else { // never or the keyboard is open } else { // never or the keyboard is open
@ -438,39 +435,6 @@ public class MessageView extends K9Activity implements OnClickListener {
} }
} }
private boolean isScreenReaderActive() {
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 = getPackageManager().queryIntentServices(
screenReaderIntent, 0);
ContentResolver cr = 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);
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);
cursor.close();
if (status == 1) {
return true;
}
}
}
return false;
}
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference); outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference);

View File

@ -1,7 +1,12 @@
package com.fsck.k9.view; package com.fsck.k9.view;
import android.app.Activity; import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -20,6 +25,8 @@ import com.fsck.k9.mail.*;
import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore;
import java.util.List;
/** /**
*/ */
@ -36,7 +43,7 @@ public class SingleMessageView extends LinearLayout {
private LayoutInflater mInflater; private LayoutInflater mInflater;
public void initialize(Activity activity, Boolean isScreenReaderActive) { public void initialize(Activity activity) {
mMessageContentView = (MessageWebView) findViewById(R.id.message_content); mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
mAccessibleMessageContentView = (AccessibleWebView) findViewById(R.id.accessible_message_content); mAccessibleMessageContentView = (AccessibleWebView) findViewById(R.id.accessible_message_content);
mAttachments = (LinearLayout) findViewById(R.id.attachments); mAttachments = (LinearLayout) findViewById(R.id.attachments);
@ -53,14 +60,15 @@ public class SingleMessageView extends LinearLayout {
mAttachments.setVisibility(View.GONE); mAttachments.setVisibility(View.GONE);
if (isScreenReaderActive) { if (isScreenReaderActive(activity)) {
mAccessibleMessageContentView.setVisibility(View.VISIBLE); mAccessibleMessageContentView.setVisibility(View.VISIBLE);
mMessageContentView.setVisibility(View.GONE); mMessageContentView.setVisibility(View.GONE);
mScreenReaderEnabled = true;
} else { } else {
mAccessibleMessageContentView.setVisibility(View.GONE); mAccessibleMessageContentView.setVisibility(View.GONE);
mMessageContentView.setVisibility(View.VISIBLE); mMessageContentView.setVisibility(View.VISIBLE);
mScreenReaderEnabled = false;
} }
mScreenReaderEnabled = isScreenReaderActive;
} }
@ -68,6 +76,42 @@ public class SingleMessageView extends LinearLayout {
super(context, attrs); super(context, attrs);
} }
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);
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);
cursor.close();
if (status == 1) {
return true;
}
}
}
return false;
}
public boolean showPictures() { public boolean showPictures() {
return mShowPictures; return mShowPictures;
} }