dispatch backPressed to the right-most fragment before, if still

unhandled, letting super interpret it as a pop-fragment action.
This commit is contained in:
Eric House 2016-07-13 12:23:36 -07:00
parent 4fc2dd97b3
commit 54e5e61e4d
10 changed files with 33 additions and 9 deletions

View file

@ -87,7 +87,7 @@ public class DelegateBase implements DlgClickNotify,
protected void onStop() {}
protected void onDestroy() {}
protected void onWindowFocusChanged( boolean hasFocus ) {}
protected boolean onBackPressed() { return false; }
protected boolean handleBackPressed() { return false; }
public void orientationChanged() {}
protected void requestWindowFeature( int feature ) {}

View file

@ -571,7 +571,8 @@ public class DictsDelegate extends ListDelegateBase
}
}
protected boolean onBackPressed()
@Override
protected boolean handleBackPressed()
{
boolean handled = 0 < m_selDicts.size();
if ( handled ) {

View file

@ -59,4 +59,13 @@ public class DualpaneDelegate extends DelegateBase {
DbgUtils.logf( "DualpaneDelegate.handleNewIntent() => %b", handled );
return handled;
}
@Override
protected boolean handleBackPressed()
{
MainActivity main = (MainActivity)m_activity;
boolean handled = main.dispatchBackPressed();
DbgUtils.logf( "DualpaneDelegate.handleBackPressed() => %b", handled );
return handled;
}
}

View file

@ -307,7 +307,7 @@ public class DwnldDelegate extends ListDelegateBase {
} // init
@Override
protected boolean onBackPressed()
protected boolean handleBackPressed()
{
// cancel any tasks that remain
for ( Iterator<DownloadFilesTask> iter = m_dfts.iterator();
@ -315,7 +315,7 @@ public class DwnldDelegate extends ListDelegateBase {
DownloadFilesTask dft = iter.next();
dft.cancel( true );
}
return super.onBackPressed();
return super.handleBackPressed();
}
private void mkListAdapter()

View file

@ -755,7 +755,7 @@ public class GameConfigDelegate extends DelegateBase
} // onClick
@Override
protected boolean onBackPressed()
protected boolean handleBackPressed()
{
boolean consumed = false;
if ( ! isFinishing() ) {

View file

@ -1303,7 +1303,7 @@ public class GamesListDelegate extends ListDelegateBase
}
@Override
protected boolean onBackPressed()
protected boolean handleBackPressed()
{
boolean handled = 0 < m_selGames.size() || 0 < m_selGroupIDs.size();
if ( handled ) {

View file

@ -145,6 +145,19 @@ public class MainActivity extends XWActivity
return handled;
}
/**
* The right-most pane only gets a chance to handle on-back-pressed.
*/
protected boolean dispatchBackPressed()
{
View child = m_root.getChildAt( m_root.getChildCount() - 1 );
Fragment frag = getSupportFragmentManager()
.findFragmentById( child.getId() );
boolean handled = ((XWFragment)frag).getDelegate()
.handleBackPressed();
return handled;
}
//////////////////////////////////////////////////////////////////////
// Delegator interface
//////////////////////////////////////////////////////////////////////

View file

@ -86,7 +86,7 @@ public class StudyListDelegate extends ListDelegateBase
}
@Override
protected boolean onBackPressed()
protected boolean handleBackPressed()
{
boolean handled = 0 < m_checkeds.size();
if ( handled ) {

View file

@ -128,7 +128,7 @@ public class XWActivity extends FragmentActivity implements Delegator {
@Override
public void onBackPressed() {
if ( !m_dlgt.onBackPressed() ) {
if ( !m_dlgt.handleBackPressed() ) {
super.onBackPressed();
}
}

View file

@ -56,7 +56,8 @@ public class LocDelegate extends ListDelegateBase
m_activity = delegator.getActivity();
}
protected boolean onBackPressed()
@Override
protected boolean handleBackPressed()
{
LocUtils.saveLocalData( m_activity );
return false;