зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1325440 - Use 16:9 keyline for BottomSheet menu r=sebastian
Newer versions of the support library do this automatically, but we need to roll our own implentation for now. 16:9 keyline means that the top of the menu is placed such that a 16:9 window of application content is still visible above the menu. This is illustrated in: https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-keylines-spacing (The menu itself is _not_ 16:9.) MozReview-Commit-ID: FSUdssb5eBN --HG-- extra : rebase_source : 735cfb9ce7f78e4247780011c76850560f67d40e
This commit is contained in:
Родитель
3ef6514406
Коммит
f254b7dc1a
|
@ -4,9 +4,11 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package org.mozilla.gecko.home.activitystream.menu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomSheetBehavior;
|
||||
import android.support.design.widget.BottomSheetDialog;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -35,6 +37,9 @@ import static org.mozilla.gecko.activitystream.ActivityStream.extractLabel;
|
|||
|
||||
private final NavigationView navigationView;
|
||||
|
||||
final View content;
|
||||
final View activityView;
|
||||
|
||||
public BottomSheetContextMenu(final Context context,
|
||||
final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
|
||||
final MenuMode mode,
|
||||
|
@ -50,10 +55,13 @@ import static org.mozilla.gecko.activitystream.ActivityStream.extractLabel;
|
|||
onUrlOpenListener,
|
||||
onUrlOpenInBackgroundListener);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
final View content = inflater.inflate(R.layout.activity_stream_contextmenu_bottomsheet, null);
|
||||
// The View encompassing the activity area
|
||||
this.activityView = ((Activity) context).findViewById(android.R.id.content);
|
||||
|
||||
bottomSheetDialog = new BottomSheetDialog(context);
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
this.content = inflater.inflate(R.layout.activity_stream_contextmenu_bottomsheet, (ViewGroup) activityView, false);
|
||||
|
||||
bottomSheetDialog.setContentView(content);
|
||||
|
||||
((TextView) content.findViewById(R.id.title)).setText(item.getTitle());
|
||||
|
@ -95,6 +103,19 @@ import static org.mozilla.gecko.activitystream.ActivityStream.extractLabel;
|
|||
|
||||
@Override
|
||||
public void show() {
|
||||
// Try to use a 16:9 "keyline", i.e. we leave a 16:9 window of activity content visible
|
||||
// above the menu. We only do this in portrait mode - in landscape mode, 16:9 is likely
|
||||
// to be similar to the size of the display, so we'd only show very little, or even none of,
|
||||
// the menu.
|
||||
// Note that newer versions of the support library (possibly 25+) will do this automatically,
|
||||
// so we can remove that code then.
|
||||
if (activityView.getHeight() > activityView.getWidth()) {
|
||||
final int peekHeight = activityView.getHeight() - (activityView.getWidth() * 9 / 16);
|
||||
|
||||
BottomSheetBehavior<View> bsBehaviour = BottomSheetBehavior.from((View) content.getParent());
|
||||
bsBehaviour.setPeekHeight(peekHeight);
|
||||
}
|
||||
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class HighlightItem extends StreamItem implements IconCallback {
|
|||
.set(ActivityStreamTelemetry.Contract.ACTION_POSITION, position)
|
||||
.forHighlightSource(highlight.getSource());
|
||||
|
||||
ActivityStreamContextMenu.show(v.getContext(),
|
||||
ActivityStreamContextMenu.show(itemView.getContext(),
|
||||
menuButton,
|
||||
extras,
|
||||
ActivityStreamContextMenu.MenuMode.HIGHLIGHT,
|
||||
|
|
|
@ -63,7 +63,7 @@ import java.util.concurrent.Future;
|
|||
.forTopSite(topSite)
|
||||
.set(ActivityStreamTelemetry.Contract.ACTION_POSITION, absolutePosition);
|
||||
|
||||
ActivityStreamContextMenu.show(v.getContext(),
|
||||
ActivityStreamContextMenu.show(itemView.getContext(),
|
||||
menuButton,
|
||||
extras,
|
||||
ActivityStreamContextMenu.MenuMode.TOPSITE,
|
||||
|
|
Загрузка…
Ссылка в новой задаче