1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04: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.pm.ResolveInfo;
import android.content.res.Configuration;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@ -313,7 +312,7 @@ public class MessageView extends K9Activity implements OnClickListener {
mTopView = mToggleScrollView = (ToggleScrollView) findViewById(R.id.top_view);
mMessageView = (SingleMessageView) findViewById(R.id.message_view);
mMessageView.initialize(this, isScreenReaderActive());
mMessageView.initialize(this);
setTitle("");
Intent intent = getIntent();
@ -409,10 +408,8 @@ public class MessageView extends K9Activity implements OnClickListener {
// Perhaps the ScrollButtons should be global, instead of account-specific
Account.ScrollButtons scrollButtons = mAccount.getScrollMessageViewButtons();
if
((Account.ScrollButtons.ALWAYS == scrollButtons)
||
(Account.ScrollButtons.KEYBOARD_AVAILABLE == scrollButtons &&
if ((Account.ScrollButtons.ALWAYS == scrollButtons)
|| (Account.ScrollButtons.KEYBOARD_AVAILABLE == scrollButtons &&
(this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))) {
scrollButtons();
} 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
protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference);

View File

@ -1,7 +1,12 @@
package com.fsck.k9.view;
import android.app.Activity;
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.util.AttributeSet;
import android.util.Log;
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.store.LocalStore;
import java.util.List;
/**
*/
@ -36,7 +43,7 @@ public class SingleMessageView extends LinearLayout {
private LayoutInflater mInflater;
public void initialize(Activity activity, Boolean isScreenReaderActive) {
public void initialize(Activity activity) {
mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
mAccessibleMessageContentView = (AccessibleWebView) findViewById(R.id.accessible_message_content);
mAttachments = (LinearLayout) findViewById(R.id.attachments);
@ -53,14 +60,15 @@ public class SingleMessageView extends LinearLayout {
mAttachments.setVisibility(View.GONE);
if (isScreenReaderActive) {
if (isScreenReaderActive(activity)) {
mAccessibleMessageContentView.setVisibility(View.VISIBLE);
mMessageContentView.setVisibility(View.GONE);
mScreenReaderEnabled = true;
} else {
mAccessibleMessageContentView.setVisibility(View.GONE);
mMessageContentView.setVisibility(View.VISIBLE);
mScreenReaderEnabled = false;
}
mScreenReaderEnabled = isScreenReaderActive;
}
@ -68,6 +76,42 @@ public class SingleMessageView extends LinearLayout {
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() {
return mShowPictures;
}