mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-09 22:00:39 +01:00
associate strings with the contexts in which they're looked up and
implement that filter. I'm tracking by the name of the class rather than a WeakReference, which means that the hashsets of keys will never be freed. Will need to see how much memory that means I'm using.
This commit is contained in:
parent
c44a676808
commit
3c4ed7de46
10 changed files with 117 additions and 43 deletions
|
@ -547,8 +547,10 @@ public class BoardDelegate extends DelegateBase
|
||||||
waitCloseGame( true );
|
waitCloseGame( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
|
super.onResume();
|
||||||
m_handler = new Handler();
|
m_handler = new Handler();
|
||||||
m_blockingDlgID = DlgID.NONE;
|
m_blockingDlgID = DlgID.NONE;
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,15 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
||||||
public boolean onPrepareOptionsMenu( Menu menu ) { return false; }
|
public boolean onPrepareOptionsMenu( Menu menu ) { return false; }
|
||||||
public boolean onOptionsItemSelected( MenuItem item ) { return false; }
|
public boolean onOptionsItemSelected( MenuItem item ) { return false; }
|
||||||
protected void onStart() {}
|
protected void onStart() {}
|
||||||
protected void onResume() {}
|
|
||||||
protected void onPause() {}
|
protected void onPause() {}
|
||||||
protected void onStop() {}
|
protected void onStop() {}
|
||||||
protected void onDestroy() {}
|
protected void onDestroy() {}
|
||||||
|
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
LocUtils.setLatestContext( m_activity );
|
||||||
|
}
|
||||||
|
|
||||||
// public boolean onOptionsItemSelected( MenuItem item )
|
// public boolean onOptionsItemSelected( MenuItem item )
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -238,8 +238,10 @@ public class DictBrowseDelegate extends ListDelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
|
super.onResume();
|
||||||
if ( null == m_browseState ) {
|
if ( null == m_browseState ) {
|
||||||
m_browseState = DBUtils.dictsGetOffset( m_activity, m_name, m_loc );
|
m_browseState = DBUtils.dictsGetOffset( m_activity, m_name, m_loc );
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,8 +408,11 @@ public class DictsDelegate extends DelegateBase
|
||||||
m_origTitle = getTitle();
|
m_origTitle = getTitle();
|
||||||
} // onCreate
|
} // onCreate
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
MountEventReceiver.register( this );
|
MountEventReceiver.register( this );
|
||||||
|
|
||||||
mkListAdapter();
|
mkListAdapter();
|
||||||
|
|
|
@ -433,8 +433,10 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
loadGame();
|
loadGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
|
super.onResume();
|
||||||
loadGame();
|
loadGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,9 @@ public class NewGameDelegate extends DelegateBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
checkEnableBT( false );
|
checkEnableBT( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,10 +156,12 @@ public class PrefsDelegate extends DelegateBase
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
|
super.onResume();
|
||||||
getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class LocSearcher {
|
||||||
FilterFunc proc = s_falseProc;
|
FilterFunc proc = s_falseProc;
|
||||||
switch ( showBy ) {
|
switch ( showBy ) {
|
||||||
case LOC_FILTERS_SCREEN:
|
case LOC_FILTERS_SCREEN:
|
||||||
|
proc = s_screenProc;
|
||||||
break;
|
break;
|
||||||
case LOC_FILTERS_MENU:
|
case LOC_FILTERS_MENU:
|
||||||
proc = s_menuProc;
|
proc = s_menuProc;
|
||||||
|
@ -157,9 +158,15 @@ public class LocSearcher {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static FilterFunc s_screenProc = new FilterFunc() {
|
||||||
|
public boolean passes( Context context, Pair pair ) {
|
||||||
|
return LocUtils.inLatestScreen( pair.getKey() );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static FilterFunc s_menuProc = new FilterFunc() {
|
private static FilterFunc s_menuProc = new FilterFunc() {
|
||||||
public boolean passes( Context context, Pair pair ) {
|
public boolean passes( Context context, Pair pair ) {
|
||||||
return LocUtils.inLatestMenu( context, pair.getKey() );
|
return LocUtils.inLatestMenu( pair.getKey() );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,27 +81,11 @@ public class LocUtils {
|
||||||
private static WeakReference<Menu> s_latestMenuRef;
|
private static WeakReference<Menu> s_latestMenuRef;
|
||||||
private static HashMap<WeakReference<Menu>, HashSet<String> > s_menuSets
|
private static HashMap<WeakReference<Menu>, HashSet<String> > s_menuSets
|
||||||
= new HashMap<WeakReference<Menu>, HashSet<String> >();
|
= new HashMap<WeakReference<Menu>, HashSet<String> >();
|
||||||
|
private static String s_latestContextName;
|
||||||
public interface LocIface {
|
private static String s_newContextName;
|
||||||
void setText( CharSequence text );
|
private static HashMap<String, HashSet<String> > s_contextSets
|
||||||
}
|
= new HashMap<String, HashSet<String> >();
|
||||||
|
|
||||||
// public static void loadStrings( Context context, AttributeSet as, LocIface view )
|
|
||||||
// {
|
|
||||||
// // There should be a way to look up the index of "strid" but I don't
|
|
||||||
// // have it yet. This got things working.
|
|
||||||
// int count = as.getAttributeCount();
|
|
||||||
// for ( int ii = 0; ii < count; ++ii ) {
|
|
||||||
// if ( "strid".equals( as.getAttributeName(ii) ) ) {
|
|
||||||
// String value = as.getAttributeValue(ii);
|
|
||||||
// Assert.assertTrue( '@' == value.charAt(0) );
|
|
||||||
// int id = Integer.parseInt( value.substring(1) );
|
|
||||||
// view.setText( getString( context, id ) );
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static void localeChanged( Context context, String newLocale )
|
public static void localeChanged( Context context, String newLocale )
|
||||||
{
|
{
|
||||||
saveLocalData( context );
|
saveLocalData( context );
|
||||||
|
@ -111,6 +95,14 @@ public class LocUtils {
|
||||||
s_enabled = null;
|
s_enabled = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLatestContext( Context context )
|
||||||
|
{
|
||||||
|
String newName = context.getClass().getName();
|
||||||
|
s_latestContextName = s_newContextName;
|
||||||
|
s_newContextName = newName;
|
||||||
|
DbgUtils.logf( "setLatestContext(%s): now %s", newName, s_latestContextName );
|
||||||
|
}
|
||||||
|
|
||||||
public static View inflate( Context context, int resID )
|
public static View inflate( Context context, int resID )
|
||||||
{
|
{
|
||||||
LayoutInflater factory = LayoutInflater.from( context );
|
LayoutInflater factory = LayoutInflater.from( context );
|
||||||
|
@ -140,8 +132,9 @@ public class LocUtils {
|
||||||
|
|
||||||
public static void xlateView( Context context, View view )
|
public static void xlateView( Context context, View view )
|
||||||
{
|
{
|
||||||
// DbgUtils.logf( "xlateView() top level" );
|
// DbgUtils.logf( "xlateView(%s, %s)", context.getClass().getName(),
|
||||||
xlateView( context, view, 0 );
|
// view.getClass().getName() );
|
||||||
|
xlateView( context, context.getClass().getName(), view, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void xlateMenu( Activity activity, Menu menu )
|
public static void xlateMenu( Activity activity, Menu menu )
|
||||||
|
@ -160,9 +153,13 @@ public class LocUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String xlateString( Context context, String str )
|
private static String xlateString( Context context, String str,
|
||||||
|
boolean associate )
|
||||||
{
|
{
|
||||||
if ( LocIDs.getS_MAP( context ).containsKey( str ) ) {
|
if ( LocIDs.getS_MAP( context ).containsKey( str ) ) {
|
||||||
|
if ( associate ) {
|
||||||
|
associateContextString( context, str );
|
||||||
|
}
|
||||||
String xlation = getXlation( context, str, true );
|
String xlation = getXlation( context, str, true );
|
||||||
if ( null != xlation ) {
|
if ( null != xlation ) {
|
||||||
str = xlation;
|
str = xlation;
|
||||||
|
@ -171,6 +168,11 @@ public class LocUtils {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String xlateString( Context context, String str )
|
||||||
|
{
|
||||||
|
return xlateString( context, str, true );
|
||||||
|
}
|
||||||
|
|
||||||
public static CharSequence[] xlateStrings( Context context, CharSequence[] strs )
|
public static CharSequence[] xlateStrings( Context context, CharSequence[] strs )
|
||||||
{
|
{
|
||||||
CharSequence[] result = new CharSequence[strs.length];
|
CharSequence[] result = new CharSequence[strs.length];
|
||||||
|
@ -206,6 +208,7 @@ public class LocUtils {
|
||||||
String result = null;
|
String result = null;
|
||||||
String key = keyForID( context, id );
|
String key = keyForID( context, id );
|
||||||
if ( null != key ) {
|
if ( null != key ) {
|
||||||
|
associateContextString( context, key );
|
||||||
result = getXlation( context, key, canUseDB );
|
result = getXlation( context, key, canUseDB );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +393,7 @@ public class LocUtils {
|
||||||
if ( LocIDs.getS_MAP( activity ).containsKey(title) ) {
|
if ( LocIDs.getS_MAP( activity ).containsKey(title) ) {
|
||||||
associateMenuString( rootRef, title );
|
associateMenuString( rootRef, title );
|
||||||
|
|
||||||
title = xlateString( activity, title );
|
title = xlateString( activity, title, false );
|
||||||
item.setTitle( title );
|
item.setTitle( title );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,25 +481,28 @@ public class LocUtils {
|
||||||
return s_idsToKeys.get( id );
|
return s_idsToKeys.get( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void xlateView( Context context, View view, int depth )
|
private static void xlateView( Context context, String contextName,
|
||||||
|
View view, int depth )
|
||||||
{
|
{
|
||||||
// DbgUtils.logf( "xlateView(depth=%d, view=%s, canRecurse=%b)", depth,
|
// DbgUtils.logf( "xlateView(depth=%d, view=%s, canRecurse=%b)", depth,
|
||||||
// view.getClass().getName(), view instanceof ViewGroup );
|
// view.getClass().getName(), view instanceof ViewGroup );
|
||||||
if ( view instanceof Button ) {
|
if ( view instanceof Button ) {
|
||||||
Button button = (Button)view;
|
Button button = (Button)view;
|
||||||
String str = xlateString( context, button.getText().toString() );
|
String str = xlateAndStore( context, button.getText() );
|
||||||
button.setText( str );
|
if ( null != str ) {
|
||||||
|
button.setText( str );
|
||||||
|
}
|
||||||
} else if ( view instanceof TextView ) {
|
} else if ( view instanceof TextView ) {
|
||||||
TextView tv = (TextView)view;
|
TextView tv = (TextView)view;
|
||||||
tv.setText( xlateString( context, tv.getText().toString() ) );
|
String str = xlateAndStore( context, tv.getText() );
|
||||||
|
if ( null != str ) {
|
||||||
|
tv.setText( str );
|
||||||
|
}
|
||||||
} else if ( view instanceof Spinner ) {
|
} else if ( view instanceof Spinner ) {
|
||||||
Spinner sp = (Spinner)view;
|
Spinner sp = (Spinner)view;
|
||||||
CharSequence prompt = sp.getPrompt();
|
String str = xlateAndStore( context, sp.getPrompt() );
|
||||||
if ( null != prompt ) {
|
if ( null != str ) {
|
||||||
String xlation = xlateString( context, prompt.toString() );
|
sp.setPrompt( str );
|
||||||
if ( null != xlation ) {
|
|
||||||
sp.setPrompt( xlation );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SpinnerAdapter adapter = sp.getAdapter();
|
SpinnerAdapter adapter = sp.getAdapter();
|
||||||
if ( null != adapter ) {
|
if ( null != adapter ) {
|
||||||
|
@ -510,7 +516,7 @@ public class LocUtils {
|
||||||
int count = asGroup.getChildCount();
|
int count = asGroup.getChildCount();
|
||||||
for ( int ii = 0; ii < count; ++ii ) {
|
for ( int ii = 0; ii < count; ++ii ) {
|
||||||
View child = asGroup.getChildAt( ii );
|
View child = asGroup.getChildAt( ii );
|
||||||
xlateView( context, child, depth + 1 );
|
xlateView( context, contextName, child, depth + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -565,7 +571,7 @@ public class LocUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean inLatestMenu( Context context, String key )
|
public static boolean inLatestMenu( String key )
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if ( null != s_latestMenuRef ) {
|
if ( null != s_latestMenuRef ) {
|
||||||
|
@ -577,6 +583,36 @@ public class LocUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean inLatestScreen( String key )
|
||||||
|
{
|
||||||
|
boolean result = false;
|
||||||
|
Assert.assertNotNull( s_latestContextName );
|
||||||
|
HashSet<String> keys = s_contextSets.get( s_latestContextName );
|
||||||
|
Assert.assertNotNull( keys ); // failing
|
||||||
|
result = keys.contains( key );
|
||||||
|
// DbgUtils.logf( "inLatestScreen(%s [in %s])=>%b", key, s_latestContextName, result );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String xlateAndStore( Context context, CharSequence cs )
|
||||||
|
{
|
||||||
|
String result = null;
|
||||||
|
if ( null == cs ) {
|
||||||
|
// DbgUtils.logf( "xlateAndStore: cs null" );
|
||||||
|
} else if ( 0 == cs.length() ) {
|
||||||
|
Assert.assertTrue( 0 == cs.toString().length() );
|
||||||
|
// DbgUtils.logf( "xlateAndStore: cs 0 len" );
|
||||||
|
} else {
|
||||||
|
String key = cs.toString();
|
||||||
|
// DbgUtils.logf( "xlateAndStore: key=%s", key );
|
||||||
|
result = xlateString( context, key );
|
||||||
|
if ( null != result ) {
|
||||||
|
associateContextString( context, key );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// This is for testing, but the ability to pull the formatters will be
|
// This is for testing, but the ability to pull the formatters will be
|
||||||
// critical for validating local transations of strings containing
|
// critical for validating local transations of strings containing
|
||||||
// formatters.
|
// formatters.
|
||||||
|
@ -621,11 +657,27 @@ public class LocUtils {
|
||||||
if ( null == keys ) {
|
if ( null == keys ) {
|
||||||
keys = new HashSet<String>();
|
keys = new HashSet<String>();
|
||||||
s_menuSets.put( ref, keys );
|
s_menuSets.put( ref, keys );
|
||||||
// Watch for leaking -- currently nothing ever removed from s_menuSets
|
|
||||||
}
|
}
|
||||||
keys.add( key );
|
keys.add( key );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void associateContextString( Context context, final String key )
|
||||||
|
{
|
||||||
|
associateContextString( context.getClass().getName(), key );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void associateContextString( String contextName, final String key )
|
||||||
|
{
|
||||||
|
HashSet<String> keys = s_contextSets.get( contextName );
|
||||||
|
if ( null == keys ) {
|
||||||
|
keys = new HashSet<String>();
|
||||||
|
s_contextSets.put( contextName, keys );
|
||||||
|
// DbgUtils.logf( "adding keys hash to %s", contextName );
|
||||||
|
}
|
||||||
|
keys.add( key );
|
||||||
|
// DbgUtils.logf( "associated with context %s string '%s'", contextName, key );
|
||||||
|
}
|
||||||
|
|
||||||
private static Pattern s_patUnicode = Pattern.compile("(\\\\[Uu][0-9a-fA-F]{4})");
|
private static Pattern s_patUnicode = Pattern.compile("(\\\\[Uu][0-9a-fA-F]{4})");
|
||||||
private static Pattern s_patCr = Pattern.compile("\\\\n");
|
private static Pattern s_patCr = Pattern.compile("\\\\n");
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ public class XlatingSpinnerAdapter implements SpinnerAdapter {
|
||||||
public View getDropDownView( int position, View convertView, ViewGroup parent )
|
public View getDropDownView( int position, View convertView, ViewGroup parent )
|
||||||
{
|
{
|
||||||
View view = m_adapter.getDropDownView( position, convertView, parent );
|
View view = m_adapter.getDropDownView( position, convertView, parent );
|
||||||
// DbgUtils.logf( "getDropDownView()=>%s", view.getClass().getName() );
|
|
||||||
LocUtils.xlateView( m_context, view );
|
LocUtils.xlateView( m_context, view );
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,6 @@ public class XlatingSpinnerAdapter implements SpinnerAdapter {
|
||||||
public View getView( int position, View convertView, ViewGroup parent )
|
public View getView( int position, View convertView, ViewGroup parent )
|
||||||
{
|
{
|
||||||
View view = m_adapter.getView( position, convertView, parent );
|
View view = m_adapter.getView( position, convertView, parent );
|
||||||
// DbgUtils.logf( "getView()=>%s", view.getClass().getName() );
|
|
||||||
LocUtils.xlateView( m_context, view );
|
LocUtils.xlateView( m_context, view );
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue