mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
translate spinners by replacing their adapters with new class that
delegates to old then translates any views returned
This commit is contained in:
parent
6165fc2201
commit
1170a31385
2 changed files with 76 additions and 3 deletions
|
@ -25,10 +25,10 @@ import android.content.Context;
|
|||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -39,6 +39,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.SpinnerAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -424,8 +425,8 @@ public class LocUtils {
|
|||
|
||||
private static void xlateView( Context context, View view, int depth )
|
||||
{
|
||||
// DbgUtils.logf( "xlateView(depth=%d, view=%s, canRecurse=%b)", depth,
|
||||
// view.getClass().getName(), view instanceof ViewGroup );
|
||||
DbgUtils.logf( "xlateView(depth=%d, view=%s, canRecurse=%b)", depth,
|
||||
view.getClass().getName(), view instanceof ViewGroup );
|
||||
if ( view instanceof Button ) {
|
||||
Button button = (Button)view;
|
||||
String str = xlateString( context, button.getText().toString() );
|
||||
|
@ -442,6 +443,8 @@ public class LocUtils {
|
|||
sp.setPrompt( xlation );
|
||||
}
|
||||
}
|
||||
SpinnerAdapter adapter = sp.getAdapter();
|
||||
sp.setAdapter( new XlatingSpinnerAdapter( context, adapter ) );
|
||||
}
|
||||
|
||||
// A Spinner, for instance, ISA ViewGroup, so this is a separate test.
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2014 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.loc;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.DataSetObserver;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.SpinnerAdapter;
|
||||
|
||||
import org.eehouse.android.xw4.DbgUtils;
|
||||
|
||||
public class XlatingSpinnerAdapter implements SpinnerAdapter {
|
||||
|
||||
private SpinnerAdapter m_adapter;
|
||||
private Context m_context;
|
||||
|
||||
public XlatingSpinnerAdapter( Context context, SpinnerAdapter adapter )
|
||||
{
|
||||
m_adapter = adapter;
|
||||
m_context = context;
|
||||
}
|
||||
|
||||
public View getDropDownView( int position, View convertView, ViewGroup parent )
|
||||
{
|
||||
View view = m_adapter.getDropDownView( position, convertView, parent );
|
||||
// DbgUtils.logf( "getDropDownView()=>%s", view.getClass().getName() );
|
||||
LocUtils.xlateView( m_context, view );
|
||||
return view;
|
||||
}
|
||||
|
||||
public View getView( int position, View convertView, ViewGroup parent )
|
||||
{
|
||||
View view = m_adapter.getView( position, convertView, parent );
|
||||
// DbgUtils.logf( "getView()=>%s", view.getClass().getName() );
|
||||
LocUtils.xlateView( m_context, view );
|
||||
return view;
|
||||
}
|
||||
|
||||
public int getCount() { return m_adapter.getCount(); }
|
||||
public Object getItem(int position) { return m_adapter.getItem(position); }
|
||||
public long getItemId(int position) { return m_adapter.getItemId(position); }
|
||||
public int getItemViewType(int position) { return m_adapter.getItemViewType(position); }
|
||||
public int getViewTypeCount() { return m_adapter.getViewTypeCount(); }
|
||||
public boolean hasStableIds() { return m_adapter.hasStableIds(); }
|
||||
public boolean isEmpty() { return m_adapter.isEmpty(); }
|
||||
public void registerDataSetObserver(DataSetObserver observer) {
|
||||
m_adapter.registerDataSetObserver(observer);
|
||||
}
|
||||
public void unregisterDataSetObserver(DataSetObserver observer) {
|
||||
m_adapter.unregisterDataSetObserver(observer);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue