summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnnie Chin <afchin@google.com>2016-12-08 17:27:19 -0800
committerAnnie Chin <afchin@google.com>2016-12-13 12:12:37 -0800
commiteb36f95b9fc2816c6503272f960660982a661b16 (patch)
tree24af4d2d70a5225d98699945878dad400147bcf5
parent74f5e59ea9afdd89b43adbdf1edb4f517dea1f26 (diff)
downloadandroid_packages_apps_ExactCalculator-eb36f95b9fc2816c6503272f960660982a661b16.tar.gz
android_packages_apps_ExactCalculator-eb36f95b9fc2816c6503272f960660982a661b16.tar.bz2
android_packages_apps_ExactCalculator-eb36f95b9fc2816c6503272f960660982a661b16.zip
Support accessibility in History.
Fixes: 33429660 Toggle accessibility importance of main Calculator elements based on the open state of DragLayout. This is necessary due to the fact that Talkback does not use visibility as a cue for determining accessibility importance in RelativeLayout, which is the base class of DragLayout. Without this workaround, it's possible to traverse to main Calculator elements even when HistoryFragment is open. Change-Id: Iff3d775ec72aa50fe8972c1def32f4999d90a8f9
-rw-r--r--res/layout/activity_calculator_main.xml4
-rw-r--r--src/com/android/calculator2/Calculator.java24
-rw-r--r--src/com/android/calculator2/HistoryFragment.java2
3 files changed, 23 insertions, 7 deletions
diff --git a/res/layout/activity_calculator_main.xml b/res/layout/activity_calculator_main.xml
index 9d19b53..4173d33 100644
--- a/res/layout/activity_calculator_main.xml
+++ b/res/layout/activity_calculator_main.xml
@@ -21,7 +21,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <include layout="@layout/activity_calculator" />
+ <include
+ android:id="@+id/main_calculator"
+ layout="@layout/activity_calculator" />
<FrameLayout
android:id="@+id/history_frame"
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java
index b45597a..44ad0ac 100644
--- a/src/com/android/calculator2/Calculator.java
+++ b/src/com/android/calculator2/Calculator.java
@@ -277,6 +277,7 @@ public class Calculator extends Activity
private View mDeleteButton;
private View mClearButton;
private View mEqualButton;
+ private View mMainCalculator;
private TextView mInverseToggle;
private TextView mModeToggle;
@@ -390,6 +391,7 @@ public class Calculator extends Activity
}
});
+ mMainCalculator = findViewById(R.id.main_calculator);
mDisplayView = (CalculatorDisplay) findViewById(R.id.display);
mModeView = (TextView) findViewById(R.id.mode);
mFormulaText = (CalculatorFormula) findViewById(R.id.formula);
@@ -463,6 +465,14 @@ public class Calculator extends Activity
if (mDisplayView.isToolbarVisible()) {
showAndMaybeHideToolbar();
}
+ // If HistoryFragment is showing, hide the main Calculator elements from accessibility.
+ // This is because Talkback does not use visibility as a cue for RelativeLayout elements,
+ // and RelativeLayout is the base class of DragLayout.
+ // If we did not do this, it would be possible to traverse to main Calculator elements from
+ // HistoryFragment.
+ mMainCalculator.setImportantForAccessibility(
+ mDragLayout.isOpen() ? View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
+ : View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
}
@Override
@@ -734,11 +744,13 @@ public class Calculator extends Activity
private void removeHistoryFragment() {
final FragmentManager manager = getFragmentManager();
- if (manager == null || manager.isDestroyed()) {
- return;
+ if (manager != null && !manager.isDestroyed()) {
+ manager.popBackStackImmediate(HistoryFragment.TAG,
+ FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
- manager.popBackStackImmediate(HistoryFragment.TAG,
- FragmentManager.POP_BACK_STACK_INCLUSIVE);
+
+ // When HistoryFragment is hidden, the main Calculator is important for accessibility again.
+ mMainCalculator.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
}
/**
@@ -1329,6 +1341,10 @@ public class Calculator extends Activity
.addToBackStack(HistoryFragment.TAG)
.commit();
manager.executePendingTransactions();
+
+ // When HistoryFragment is visible, hide all descendants of the main Calculator view.
+ mMainCalculator.setImportantForAccessibility(
+ View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
// TODO: pass current scroll position of result
}
diff --git a/src/com/android/calculator2/HistoryFragment.java b/src/com/android/calculator2/HistoryFragment.java
index 2401f36..86ab138 100644
--- a/src/com/android/calculator2/HistoryFragment.java
+++ b/src/com/android/calculator2/HistoryFragment.java
@@ -26,7 +26,6 @@ import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toolbar;
@@ -130,7 +129,6 @@ public class HistoryFragment extends Fragment {
getActivity().onBackPressed();
}
});
-
return view;
}