Merge "Disable the scrollable ability on app bar area" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4dc80769d5
@@ -27,6 +27,8 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@@ -95,6 +97,7 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
|
|||||||
LinearLayoutManager.VERTICAL, /* reverseLayout */ false));
|
LinearLayoutManager.VERTICAL, /* reverseLayout */ false));
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
mAppBarLayout = getActivity().findViewById(R.id.app_bar);
|
mAppBarLayout = getActivity().findViewById(R.id.app_bar);
|
||||||
|
disableToolBarScrollableBehavior();
|
||||||
|
|
||||||
// Initialize TimeZoneDataLoader only when mRecyclerView is ready to avoid race
|
// Initialize TimeZoneDataLoader only when mRecyclerView is ready to avoid race
|
||||||
// during onDateLoaderReady callback.
|
// during onDateLoaderReady callback.
|
||||||
@@ -160,13 +163,15 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
|
|||||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||||
// To prevent a large space on tool bar.
|
// To prevent a large space on tool bar.
|
||||||
mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/);
|
mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/);
|
||||||
// To prevent user can expand the collpasing tool bar view.
|
// To prevent user can expand the collapsing tool bar view.
|
||||||
ViewCompat.setNestedScrollingEnabled(mRecyclerView, false);
|
ViewCompat.setNestedScrollingEnabled(mRecyclerView, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||||
|
// We keep the collapsed status after user cancel the search function.
|
||||||
|
mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/);
|
||||||
ViewCompat.setNestedScrollingEnabled(mRecyclerView, true);
|
ViewCompat.setNestedScrollingEnabled(mRecyclerView, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -188,4 +193,17 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
|
|||||||
void onListItemClick(T item);
|
void onListItemClick(T item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableToolBarScrollableBehavior() {
|
||||||
|
CoordinatorLayout.LayoutParams params =
|
||||||
|
(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
|
||||||
|
AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
|
||||||
|
behavior.setDragCallback(
|
||||||
|
new AppBarLayout.Behavior.DragCallback() {
|
||||||
|
@Override
|
||||||
|
public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
params.setBehavior(behavior);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user