From cfbd06927ac634c1c2cf19c00af46fc8045f514f Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 22 Jul 2016 15:44:25 -0700 Subject: [PATCH] fix long-tap menus in dual-pane mode The DualpaneDelegate needed to handle (delegate) the necessary methods. --- .../org/eehouse/android/xw4/DelegateBase.java | 6 +-- .../eehouse/android/xw4/DualpaneDelegate.java | 20 ++++++++++ .../org/eehouse/android/xw4/MainActivity.java | 39 +++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java index 1b47adc6b..426cdcdda 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -89,9 +89,9 @@ public class DelegateBase implements DlgClickNotify, protected void onSaveInstanceState( Bundle outState ) {} public boolean onPrepareOptionsMenu( Menu menu ) { return false; } public boolean onOptionsItemSelected( MenuItem item ) { return false; } - public void onCreateContextMenu( ContextMenu menu, View view, - ContextMenuInfo menuInfo ) {} - public boolean onContextItemSelected( MenuItem item ) { return false; } + protected void onCreateContextMenu( ContextMenu menu, View view, + ContextMenuInfo menuInfo ) {} + protected boolean onContextItemSelected( MenuItem item ) { return false; } protected void onStop() {} protected void onDestroy() {} protected void onWindowFocusChanged( boolean hasFocus ) {} diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java index fc62a5e81..60437b206 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java @@ -24,6 +24,10 @@ import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.os.Bundle; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.ContextMenu; +import android.view.MenuItem; +import android.view.View; public class DualpaneDelegate extends DelegateBase { private Activity m_activity; @@ -75,4 +79,20 @@ public class DualpaneDelegate extends DelegateBase { MainActivity main = (MainActivity)m_activity; main.dispatchOnActivityResult( requestCode, resultCode, data ); } + + @Override + protected void onCreateContextMenu( ContextMenu menu, View view, + ContextMenuInfo menuInfo ) + { + MainActivity main = (MainActivity)m_activity; + main.dispatchOnCreateContextMenu( menu, view, menuInfo ); + } + + @Override + protected boolean onContextItemSelected( MenuItem item ) + { + MainActivity main = (MainActivity)m_activity; + return main.dispatchOnContextItemSelected( item ); + } + } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java index 8cc803b11..4f3f6b4a7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java @@ -34,6 +34,9 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager.BackStackEntry; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.ContextMenu; +import android.view.MenuItem; import android.view.View; import android.widget.FrameLayout; import android.widget.LinearLayout.LayoutParams; @@ -204,6 +207,28 @@ public class MainActivity extends XWActivity } } + protected void dispatchOnCreateContextMenu( ContextMenu menu, View view, + ContextMenuInfo menuInfo ) + { + XWFragment[] frags = getVisibleFragments(); + for ( XWFragment frag : frags ) { + frag.getDelegate().onCreateContextMenu( menu, view, menuInfo ); + } + } + + protected boolean dispatchOnContextItemSelected( MenuItem item ) + { + boolean handled = false; + XWFragment[] frags = getVisibleFragments(); + for ( XWFragment frag : frags ) { + handled = frag.getDelegate().onContextItemSelected( item ); + if ( handled ) { + break; + } + } + return handled; + } + protected Point getFragmentSize() { Rect rect = new Rect(); @@ -324,6 +349,20 @@ public class MainActivity extends XWActivity return frag; } + private XWFragment[] getVisibleFragments() + { + int childCount = m_root.getChildCount(); + int count = Math.min( m_maxPanes, childCount ); + XWFragment[] result = new XWFragment[count]; + for ( int ii = 0; ii < count; ++ii ) { + View child = m_root.getChildAt( childCount - 1 - ii ); + result[ii] = (XWFragment)getSupportFragmentManager() + .findFragmentById( child.getId() ); + } + + return result; + } + // Walk all Fragment children and if they care notify of change. private void tellOrientationChanged() {