From 2ecba33052694dd816ac915d6d5ebdfb7120d970 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sat, 12 Jan 2019 17:54:08 +0100 Subject: [PATCH] Remove welcome slide dots from screen reading (fixes #216) (#217) * Remove welcome slide dots from screen reading according to advice from the prelaunch report. * Try setImportantForAccessibility on TextViews * Update APK version to 1.0.0.7 * Try setContentDescription * Update APK version to 1.0.0.8 * Update APK version to 1.0.0.9 * Add meaningful content description in case a screen reader unintentionally reads out loud * Update APK version to 1.0.0.10 * Fix type conversion * Update APK version to 1.0.0.11 * Add views/CustomViewPager * Use CustomViewPager in FirstStartActivity * FirstStartActivity: Use CustomViewPager * Add main menu string for screen readers * Reformat code * Try toolbar.setNavigationContentDescription * Update APK version to 1.0.0.12 * Import de translation --- app/build.gradle | 4 +- .../activities/FirstStartActivity.java | 23 ++++----- .../activities/MainActivity.java | 5 +- .../activities/SyncthingActivity.java | 1 + .../views/CustomViewPager.java | 50 +++++++++++++++++++ .../main/res/layout/activity_first_start.xml | 6 ++- app/src/main/res/values-de/strings.xml | 4 ++ app/src/main/res/values/strings.xml | 4 ++ 8 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/com/nutomic/syncthingandroid/views/CustomViewPager.java diff --git a/app/build.gradle b/app/build.gradle index 39dcd93c..f6783f42 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,8 +37,8 @@ android { applicationId "com.github.catfriend1.syncthingandroid" minSdkVersion 16 targetSdkVersion 26 - versionCode 1000006 - versionName "1.0.0.6" + versionCode 1000012 + versionName "1.0.0.12" testApplicationId 'com.github.catfriend1.syncthingandroid.test' testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' playAccountConfig = playAccountConfigs.defaultAccountConfig diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java index 638dadd0..9e83f827 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java @@ -23,14 +23,11 @@ import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.text.Html; import android.util.Log; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; -import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -45,6 +42,7 @@ import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.SyncthingRunnable.ExecutableNotFoundException; import com.nutomic.syncthingandroid.util.ConfigXml; import com.nutomic.syncthingandroid.util.Util; +import com.nutomic.syncthingandroid.views.CustomViewPager; import java.lang.ref.WeakReference; @@ -78,7 +76,7 @@ public class FirstStartActivity extends Activity { private int mSlidePosIgnoreDozePermission = -1; private int mSlidePosKeyGeneration = -1; - private ViewPager mViewPager; + private CustomViewPager mViewPager; private ViewPagerAdapter mViewPagerAdapter; private LinearLayout mDotsLayout; private TextView[] mDots; @@ -145,19 +143,12 @@ public class FirstStartActivity extends Activity { // Show first start welcome wizard UI. setContentView(R.layout.activity_first_start); - mViewPager = (ViewPager) findViewById(R.id.view_pager); + mViewPager = (CustomViewPager) findViewById(R.id.view_pager); mDotsLayout = (LinearLayout) findViewById(R.id.layoutDots); mBackButton = (Button) findViewById(R.id.btn_back); mNextButton = (Button) findViewById(R.id.btn_next); - mViewPager.setOnTouchListener(new OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - // Consume the event to prevent swiping through the slides. - v.performClick(); - return true; - } - }); + mViewPager.setPagingEnabled(false); // Add welcome slides to be shown. int[] colorsActive = getResources().getIntArray(R.array.array_dot_active); @@ -285,6 +276,10 @@ public class FirstStartActivity extends Activity { mDots[i].setText(Html.fromHtml("•")); mDots[i].setTextSize(35); mDots[i].setTextColor(mSlides[currentPage].dotColorInActive); + + // Prevent TalkBack from announcing a decorative TextView. + mDots[i].setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); + mDots[i].setContentDescription(getString(R.string.page_x_of_y, Integer.toString(i), Integer.toString(mDots.length))); mDotsLayout.addView(mDots[i]); } @@ -297,7 +292,7 @@ public class FirstStartActivity extends Activity { } // ViewPager change listener - ViewPager.OnPageChangeListener mViewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { + CustomViewPager.OnPageChangeListener mViewPagerPageChangeListener = new CustomViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index 413fae9f..84a1dc10 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -448,10 +448,11 @@ public class MainActivity extends SyncthingActivity @Override public boolean onKeyDown(int keyCode, KeyEvent e) { if (keyCode == KeyEvent.KEYCODE_MENU) { - if (!mDrawerLayout.isDrawerOpen(GravityCompat.START)) + if (!mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.openDrawer(GravityCompat.START); - else + } else { closeDrawer(); + } return true; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java index 0f920faa..83e19503 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java @@ -42,6 +42,7 @@ public abstract class SyncthingActivity extends AppCompatActivity implements Ser if (toolbar == null) { return; } + toolbar.setNavigationContentDescription(R.string.main_menu); setSupportActionBar(toolbar); //noinspection ConstantConditions diff --git a/app/src/main/java/com/nutomic/syncthingandroid/views/CustomViewPager.java b/app/src/main/java/com/nutomic/syncthingandroid/views/CustomViewPager.java new file mode 100644 index 00000000..528054e5 --- /dev/null +++ b/app/src/main/java/com/nutomic/syncthingandroid/views/CustomViewPager.java @@ -0,0 +1,50 @@ +package com.nutomic.syncthingandroid.views; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.view.MotionEvent; + +public class CustomViewPager extends ViewPager { + + private boolean isPagingEnabled = true; + + public CustomViewPager(Context context) { + super(context); + } + + public CustomViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean arrowScroll(int direction) { + return this.isPagingEnabled && super.arrowScroll(direction); + } + + // Required to satisfy lint. + @Override + public boolean performClick() { + return super.performClick(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + super.performClick(); + return this.isPagingEnabled && super.onTouchEvent(event); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + return this.isPagingEnabled && super.onInterceptTouchEvent(event); + } + + @Override + public boolean canScrollHorizontally(int direction) { + return this.isPagingEnabled && super.canScrollHorizontally(direction); + } + + public void setPagingEnabled(boolean b) { + this.isPagingEnabled = b; + } +} diff --git a/app/src/main/res/layout/activity_first_start.xml b/app/src/main/res/layout/activity_first_start.xml index 5b9c1662..40f00fe3 100644 --- a/app/src/main/res/layout/activity_first_start.xml +++ b/app/src/main/res/layout/activity_first_start.xml @@ -8,7 +8,7 @@ tools:context="com.nutomic.syncthingandroid.activities.FirstStartActivity" tools:showIn="@layout/activity_first_start"> - @@ -20,7 +20,9 @@ android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/dots_margin_bottom" android:gravity="center" - android:orientation="horizontal"> + android:orientation="horizontal" + android:importantForAccessibility="no" + android:descendantFocusability="blocksDescendants"> Ignorieren + Seite %1$s von %2$s + + Hauptmenü + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 30c056fa..4bf3a83c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,6 +51,10 @@ Please report any problems you encounter via Github. Ignore + Page %1$s of %2$s + + Main Menu +