add new class that listens for SDCard mounted event (could be

generalized for multiple events and map them to multiple notification
callbacks), and use it from DictsActivity to redraw the list when the
SD card comes back online.  While the default android behavior works
for the unmount case (relaunches DictsActivity which correctly draws
only those dicts still available) it needs this change to redraw after
the available set grows.
This commit is contained in:
Andy2 2011-08-20 11:59:32 -07:00
parent 6ca60438a1
commit 659c054696
2 changed files with 88 additions and 4 deletions

View file

@ -55,7 +55,8 @@ import org.eehouse.android.xw4.jni.JNIUtilsImpl;
import org.eehouse.android.xw4.jni.CommonPrefs;
public class DictsActivity extends ExpandableListActivity
implements View.OnClickListener, XWListItem.DeleteCallback {
implements View.OnClickListener, XWListItem.DeleteCallback,
SDCardWatcher.SDCardNotifiee {
private static final String DICT_DOLAUNCH = "do_launch";
private static final String DICT_LANG_EXTRA = "use_lang";
@ -75,9 +76,10 @@ public class DictsActivity extends ExpandableListActivity
private XWListItem m_rowView;
GameUtils.DictLoc m_moveFromLoc;
GameUtils.DictLoc m_moveToLoc;
String m_moveName;
private SDCardWatcher m_cardWatcher;
private String m_moveName;
LayoutInflater m_factory;
private LayoutInflater m_factory;
private class DictListAdapter implements ExpandableListAdapter {
private Context m_context;
@ -331,10 +333,17 @@ public class DictsActivity extends ExpandableListActivity
protected void onResume()
{
super.onResume();
m_cardWatcher = new SDCardWatcher( this, this );
mkListAdapter();
expandGroups();
}
protected void onPause() {
m_cardWatcher.close();
m_cardWatcher = null;
super.onPause();
}
public void onClick( View v )
{
askStartDownload( 0, null );
@ -429,7 +438,7 @@ public class DictsActivity extends ExpandableListActivity
showDialog( MOVE_DICT );
}
// DeleteCallback interface
// XWListItem.DeleteCallback interface
public void deleteCalled( int myPosition, final String dict )
{
int code = DictLangCache.getDictLangCode( this, dict );
@ -457,6 +466,13 @@ public class DictsActivity extends ExpandableListActivity
m_delegate.showConfirmThen( msg, action );
}
// SDCardWatcher.SDCardNotifiee interface
public void cardMounted()
{
mkListAdapter();
expandGroups();
}
private void deleteDict( String dict )
{
GameUtils.deleteDict( this, dict );

View file

@ -0,0 +1,68 @@
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
/*
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
public class SDCardWatcher {
public interface SDCardNotifiee {
void cardMounted();
}
private UmountReceiver m_rcvr;
private Context m_context;
private SDCardNotifiee m_notifiee;
private class UmountReceiver extends BroadcastReceiver {
@Override
public void onReceive( Context context, Intent intent )
{
if ( intent.getAction().
equals( Intent.ACTION_MEDIA_MOUNTED ) ) {
m_notifiee.cardMounted();
}
}
}
public SDCardWatcher( Context context, SDCardNotifiee notifiee )
{
m_context = context;
m_rcvr = new UmountReceiver();
m_notifiee = notifiee;
IntentFilter filter =
new IntentFilter( Intent.ACTION_MEDIA_MOUNTED );
// filter.addAction( Intent.ACTION_MEDIA_UNMOUNTED );
// filter.addAction( Intent.ACTION_MEDIA_EJECT );
filter.addDataScheme( "file" );
/*Intent intent = */context.getApplicationContext().
registerReceiver( m_rcvr, filter );
}
public void close()
{
m_context.getApplicationContext().unregisterReceiver( m_rcvr );
}
}