Skip to content

Commit e9459f6

Browse files
committed
Allow the menu to be toggled by using a triple tap in preparation for free-form windows
1 parent 8c1264f commit e9459f6

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

presentation/src/main/java/com/jorge/boats/xkcd/view/stripe/StripeActivity.java

+25-13
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class StripeActivity extends BaseVisualActivity implements StripeContentV
7676
@Bind(R.id.toolbar)
7777
CustomTitleToolbar mToolbar;
7878
@Bind(R.id.navigation)
79-
NavigationLinearLayout mNavigation;
79+
NavigationLinearLayout mNavigationLayout;
8080
@Bind(R.id.progress_bar)
8181
View mLoading;
8282
@Bind(R.id.retry)
@@ -116,7 +116,7 @@ private void setupToolbar() {
116116

117117
private void setupNavigationLayout() {
118118
final RelativeLayout.LayoutParams navigationLayoutLp =
119-
(RelativeLayout.LayoutParams) mNavigation.getLayoutParams();
119+
(RelativeLayout.LayoutParams) mNavigationLayout.getLayoutParams();
120120
final boolean isLandscape =
121121
getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
122122

@@ -127,7 +127,7 @@ private void setupNavigationLayout() {
127127
navigationLayoutLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
128128
}
129129

130-
mNavigation.setLayoutParams(navigationLayoutLp);
130+
mNavigationLayout.setLayoutParams(navigationLayoutLp);
131131
}
132132

133133
private void setupLoading() {
@@ -141,7 +141,19 @@ private void setupLoading() {
141141

142142
@Override
143143
public boolean onTouchEvent(final @NonNull MotionEvent event) {
144-
return this.mGestureDetector.onTouchEvent(event) || super.onTouchEvent(event);
144+
return handleTriplePointerMenuToggle(event) || this.mGestureDetector.onTouchEvent(event) || super.onTouchEvent(event);
145+
}
146+
147+
private boolean handleTriplePointerMenuToggle(final @NonNull MotionEvent event) {
148+
if (event.getPointerCount() == 3 && event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
149+
if (mNavigationLayout.isExpanded()) {
150+
mNavigationLayout.hide();
151+
} else {
152+
mNavigationLayout.show();
153+
}
154+
return true;
155+
}
156+
return false;
145157
}
146158

147159
@Override
@@ -207,7 +219,7 @@ private void openModelInBrowser() {
207219
protected void createComponentAndInjectSelf() {
208220
DaggerStripeComponent.builder()
209221
.applicationComponent(getApplicationComponent())
210-
.stripeModule(new StripeModule(mNavigation, mToolbar, mRetry))
222+
.stripeModule(new StripeModule(mNavigationLayout, mToolbar, mRetry))
211223
.build()
212224
.inject(this);
213225
}
@@ -253,7 +265,7 @@ private void initializeStripePresenter() {
253265
}
254266

255267
private void initializeNavigation() {
256-
this.mNavigation.setStripePresenter(this.mStripePresenter);
268+
this.mNavigationLayout.setStripePresenter(this.mStripePresenter);
257269
}
258270

259271
private void initializeRetry() {
@@ -321,23 +333,23 @@ private void showNavigationTutorial() {
321333

322334
if (isLandscape) {
323335
if (!P.tutorialShownLandscape.get()) {
324-
mNavigation.showTutorial();
336+
mNavigationLayout.showTutorial();
325337
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
326338
@Override
327339
public void run() {
328340
P.tutorialShownLandscape.put(true).apply();
329-
mNavigation.hideTutorial();
341+
mNavigationLayout.hideTutorial();
330342
}
331343
}, resources.getInteger(R.integer.tutorial_show_duration_milliseconds));
332344
}
333345
} else {
334346
if (!P.tutorialShownPortrait.get()) {
335-
mNavigation.showTutorial();
347+
mNavigationLayout.showTutorial();
336348
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
337349
@Override
338350
public void run() {
339351
P.tutorialShownPortrait.put(true).apply();
340-
mNavigation.hideTutorial();
352+
mNavigationLayout.hideTutorial();
341353
}
342354
}, resources.getInteger(R.integer.tutorial_show_duration_milliseconds));
343355
}
@@ -389,7 +401,7 @@ public void hideLoading() {
389401

390402
@Override
391403
public void showRetry(final @NonNull Throwable throwable) {
392-
mNavigation.hide();
404+
mNavigationLayout.hide();
393405
mToolbar.setTitle(getString(R.string.content_error_title));
394406
mContent.setBackgroundColor(
395407
ResourceUtil.getColor(this, R.color.content_background_empty, getTheme()));
@@ -438,13 +450,13 @@ public boolean dispatchKeyEvent(final @NonNull KeyEvent event) {
438450
case KeyEvent.KEYCODE_VOLUME_UP:
439451
if (event.getAction() == KeyEvent.ACTION_UP) {
440452
mStripePresenter.actionPrevious();
441-
mNavigation.hide();
453+
mNavigationLayout.hide();
442454
}
443455
return true;
444456
case KeyEvent.KEYCODE_VOLUME_DOWN:
445457
if (event.getAction() == KeyEvent.ACTION_UP) {
446458
mStripePresenter.actionNext();
447-
mNavigation.hide();
459+
mNavigationLayout.hide();
448460
}
449461
return true;
450462
default:

0 commit comments

Comments
 (0)