Commit 6694d3fc authored by Anthony Vallee-Dubois's avatar Anthony Vallee-Dubois Committed by Commit Bot

Add shadows when explicit language ask list is scrollable

Bug: 896089
Change-Id: Ifbf356ab0cb0e7fa222db7e9440adef927246e3a
Reviewed-on: https://chromium-review.googlesource.com/c/1301875Reviewed-by: default avatarBecky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: anthonyvd <anthonyvd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603386}
parent 24ebb695
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="14dp"
android:id="@+id/list_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/top_shadow"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_shadow_height"
android:src="@drawable/modern_toolbar_shadow"
android:scaleType="fitXY"
android:importantForAccessibility="no"
android:layout_gravity="top"
android:visibility="invisible" />
<ImageView
android:id="@+id/bottom_shadow"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_shadow_height"
android:src="@drawable/modern_toolbar_shadow"
android:scaleType="fitXY"
android:scaleY="-1"
android:importantForAccessibility="no"
android:layout_gravity="bottom" />
</FrameLayout>
...@@ -205,6 +205,34 @@ public class LanguageAskPrompt implements ModalDialogView.Controller { ...@@ -205,6 +205,34 @@ public class LanguageAskPrompt implements ModalDialogView.Controller {
} }
} }
private class ListScrollListener extends RecyclerView.OnScrollListener {
private RecyclerView mList;
private ImageView mTopShadow;
private ImageView mBottomShadow;
public ListScrollListener(RecyclerView list, ImageView topShadow, ImageView bottomShadow) {
mList = list;
mTopShadow = topShadow;
mBottomShadow = bottomShadow;
mList.setOnScrollListener(this);
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (mList.canScrollVertically(-1)) {
mTopShadow.setVisibility(View.VISIBLE);
} else {
mTopShadow.setVisibility(View.GONE);
}
if (mList.canScrollVertically(1)) {
mBottomShadow.setVisibility(View.VISIBLE);
} else {
mBottomShadow.setVisibility(View.GONE);
}
}
}
/** /**
* Displays the Explicit Language Ask prompt if the experiment is enabled. * Displays the Explicit Language Ask prompt if the experiment is enabled.
* @param activity The current activity to display the prompt into. * @param activity The current activity to display the prompt into.
...@@ -222,6 +250,7 @@ public class LanguageAskPrompt implements ModalDialogView.Controller { ...@@ -222,6 +250,7 @@ public class LanguageAskPrompt implements ModalDialogView.Controller {
return true; return true;
} }
private ListScrollListener mListScrollListener;
private ModalDialogManager mModalDialogManager; private ModalDialogManager mModalDialogManager;
private ModalDialogView mDialog; private ModalDialogView mDialog;
private HashSet<String> mLanguagesUpdate; private HashSet<String> mLanguagesUpdate;
...@@ -272,14 +301,19 @@ public class LanguageAskPrompt implements ModalDialogView.Controller { ...@@ -272,14 +301,19 @@ public class LanguageAskPrompt implements ModalDialogView.Controller {
params.negativeButtonTextId = R.string.cancel; params.negativeButtonTextId = R.string.cancel;
params.cancelOnTouchOutside = true; params.cancelOnTouchOutside = true;
RecyclerView list = new RecyclerView(activity); params.customView = LayoutInflater.from(activity).inflate(
R.layout.language_ask_prompt_content, null, false);
RecyclerView list = (RecyclerView) params.customView.findViewById(R.id.recycler_view);
LanguageItemAdapter adapter = new LanguageItemAdapter(activity, mLanguagesUpdate); LanguageItemAdapter adapter = new LanguageItemAdapter(activity, mLanguagesUpdate);
list.setAdapter(adapter); list.setAdapter(adapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
list.setLayoutManager(linearLayoutManager); list.setLayoutManager(linearLayoutManager);
list.setHasFixedSize(true); list.setHasFixedSize(true);
params.customView = list;
ImageView topShadow = (ImageView) params.customView.findViewById(R.id.top_shadow);
ImageView bottomShadow = (ImageView) params.customView.findViewById(R.id.bottom_shadow);
mListScrollListener = new ListScrollListener(list, topShadow, bottomShadow);
List<LanguageItem> languages = PrefServiceBridge.getInstance().getChromeLanguageList(); List<LanguageItem> languages = PrefServiceBridge.getInstance().getChromeLanguageList();
LinkedHashSet<String> currentGeoLanguages = LinkedHashSet<String> currentGeoLanguages =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment