mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 14:15:30 +00:00
Bug 796886 - Tapping anywhere in main layout should close tabs panel on phones (r=mfinkle)
This commit is contained in:
parent
767c08f204
commit
c69d77ea98
@ -94,7 +94,6 @@ public class AboutHomeContent extends ScrollView
|
||||
protected AboutHomeSection mRemoteTabs;
|
||||
|
||||
private View.OnClickListener mRemoteTabClickListener;
|
||||
private OnInterceptTouchListener mOnInterceptTouchListener;
|
||||
|
||||
public interface UriLoadCallback {
|
||||
public void callback(String uriSpec);
|
||||
@ -347,24 +346,6 @@ public class AboutHomeContent extends ScrollView
|
||||
update(AboutHomeContent.UpdateFlags.ALL); // Refresh all elements.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onInterceptTouchEvent(this, event))
|
||||
return true;
|
||||
return super.onInterceptTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onTouch(this, event))
|
||||
return true;
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public void setOnInterceptTouchListener(OnInterceptTouchListener listener) {
|
||||
mOnInterceptTouchListener = listener;
|
||||
}
|
||||
|
||||
private String readFromZipFile(String filename) {
|
||||
ZipFile zip = null;
|
||||
String str = null;
|
||||
|
@ -24,6 +24,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -32,6 +33,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Interpolator;
|
||||
@ -208,6 +210,8 @@ abstract public class BrowserApp extends GeckoApp
|
||||
LinearLayout actionBar = (LinearLayout) getActionBarLayout();
|
||||
mMainLayout.addView(actionBar, 0);
|
||||
|
||||
((GeckoApp.MainLayout) mMainLayout).setOnInterceptTouchListener(new HideTabsTouchListener());
|
||||
|
||||
mBrowserToolbar = new BrowserToolbar(this);
|
||||
mBrowserToolbar.from(actionBar);
|
||||
|
||||
@ -675,7 +679,6 @@ abstract public class BrowserApp extends GeckoApp
|
||||
mAboutHomeStartupTimer.stop();
|
||||
}
|
||||
});
|
||||
mAboutHomeContent.setOnInterceptTouchListener(new ContentTouchListener());
|
||||
} else {
|
||||
mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES,
|
||||
AboutHomeContent.UpdateFlags.REMOTE_TABS));
|
||||
@ -687,6 +690,51 @@ abstract public class BrowserApp extends GeckoApp
|
||||
}
|
||||
}
|
||||
|
||||
private class HideTabsTouchListener implements OnInterceptTouchListener {
|
||||
private boolean mIsHidingTabs = false;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
// We need to account for scroll state for the touched view otherwise
|
||||
// tapping on an "empty" part of the view will still be considered a
|
||||
// valid touch event.
|
||||
if (view.getScrollX() != 0 || view.getScrollY() != 0) {
|
||||
Rect rect = new Rect();
|
||||
view.getHitRect(rect);
|
||||
rect.offset(-view.getScrollX(), -view.getScrollY());
|
||||
|
||||
int[] viewCoords = new int[2];
|
||||
view.getLocationOnScreen(viewCoords);
|
||||
|
||||
int x = (int) event.getRawX() - viewCoords[0];
|
||||
int y = (int) event.getRawY() - viewCoords[1];
|
||||
|
||||
if (!rect.contains(x, y))
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the tab tray is showing, hide the tab tray and don't send the event to content.
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
|
||||
mIsHidingTabs = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (mIsHidingTabs) {
|
||||
// Keep consuming events until the gesture finishes.
|
||||
int action = event.getActionMasked();
|
||||
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
||||
mIsHidingTabs = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void addAddonMenuItem(final int id, final String label, final String icon) {
|
||||
if (mMenu == null) {
|
||||
if (mAddonMenuItemsCache == null)
|
||||
|
@ -2539,17 +2539,19 @@ abstract public class GeckoApp
|
||||
protected void connectGeckoLayerClient() {
|
||||
mLayerView.getLayerClient().notifyGeckoReady();
|
||||
|
||||
mLayerView.getTouchEventHandler().setOnTouchListener(new ContentTouchListener() {
|
||||
mLayerView.getTouchEventHandler().setOnTouchListener(new OnInterceptTouchListener() {
|
||||
private PointF initialPoint = null;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (event == null)
|
||||
return true;
|
||||
|
||||
if (super.onTouch(view, event))
|
||||
return true;
|
||||
|
||||
int action = event.getAction();
|
||||
PointF point = new PointF(event.getX(), event.getY());
|
||||
if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
|
||||
@ -2572,30 +2574,30 @@ abstract public class GeckoApp
|
||||
});
|
||||
}
|
||||
|
||||
protected class ContentTouchListener implements OnInterceptTouchListener {
|
||||
private boolean mIsHidingTabs = false;
|
||||
public static class MainLayout extends LinearLayout {
|
||||
private OnInterceptTouchListener mOnInterceptTouchListener;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
// If the tab tray is showing, hide the tab tray and don't send the event to content.
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
|
||||
mIsHidingTabs = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public MainLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mOnInterceptTouchListener = null;
|
||||
}
|
||||
|
||||
public void setOnInterceptTouchListener(OnInterceptTouchListener listener) {
|
||||
mOnInterceptTouchListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (mIsHidingTabs) {
|
||||
// Keep consuming events until the gesture finishes.
|
||||
int action = event.getActionMasked();
|
||||
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
||||
mIsHidingTabs = false;
|
||||
}
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onInterceptTouchEvent(this, event))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return super.onInterceptTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onTouch(this, event))
|
||||
return true;
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,8 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory {
|
||||
return new BrowserToolbarBackground(context, attrs);
|
||||
else if (TextUtils.equals(viewName, "FormAssistPopup"))
|
||||
return new FormAssistPopup(context, attrs);
|
||||
else if (TextUtils.equals(viewName, "GeckoApp$MainLayout"))
|
||||
return new GeckoApp.MainLayout(context, attrs);
|
||||
else if (TextUtils.equals(viewName, "LinkTextView"))
|
||||
return new LinkTextView(context, attrs);
|
||||
else if (TextUtils.equals(viewName, "FindInPageBar"))
|
||||
|
@ -15,8 +15,9 @@
|
||||
android:background="@drawable/tabs_tray_bg_repeat"
|
||||
gecko:sidebar="true"/>
|
||||
|
||||
<LinearLayout android:id="@+id/main_layout"
|
||||
style="@style/Screen.Transparent">
|
||||
<view class="org.mozilla.gecko.GeckoApp$MainLayout"
|
||||
android:id="@+id/main_layout"
|
||||
style="@style/Screen.Transparent">
|
||||
|
||||
<!-- BrowserToolbar will be added dynamically -->
|
||||
|
||||
@ -41,6 +42,6 @@
|
||||
style="@style/FindBar"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
</view>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -15,8 +15,9 @@
|
||||
android:background="@drawable/tabs_tray_bg_repeat"
|
||||
gecko:sidebar="false"/>
|
||||
|
||||
<LinearLayout android:id="@+id/main_layout"
|
||||
style="@style/Screen.Transparent">
|
||||
<view class="org.mozilla.gecko.GeckoApp$MainLayout"
|
||||
android:id="@+id/main_layout"
|
||||
style="@style/Screen.Transparent">
|
||||
|
||||
<!-- BrowserToolbar will be added dynamically -->
|
||||
|
||||
@ -41,6 +42,6 @@
|
||||
style="@style/FindBar"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
</view>
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user