diff --git a/xwords4/android/XWords4/build.xml b/xwords4/android/XWords4/build.xml index 8a06e6265..639fc5858 100644 --- a/xwords4/android/XWords4/build.xml +++ b/xwords4/android/XWords4/build.xml @@ -101,7 +101,7 @@ diff --git a/xwords4/android/XWords4/res/layout/loc_list_item.xml b/xwords4/android/XWords4/res/layout/loc_list_item.xml new file mode 100644 index 000000000..ee62d71e1 --- /dev/null +++ b/xwords4/android/XWords4/res/layout/loc_list_item.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/xwords4/android/XWords4/res/layout/loc_main.xml b/xwords4/android/XWords4/res/layout/loc_main.xml index 3720870f0..4d30da871 100644 --- a/xwords4/android/XWords4/res/layout/loc_main.xml +++ b/xwords4/android/XWords4/res/layout/loc_main.xml @@ -10,11 +10,11 @@ - - @@ -53,8 +53,10 @@ diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListAdapter.java index 0eb07c25d..e3cc4d7e0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListAdapter.java @@ -33,7 +33,7 @@ public abstract class XWListAdapter extends BaseAdapter implements ListAdapter { private int m_count; - public XWListAdapter( ) { + public XWListAdapter() { this( 0 ); } public XWListAdapter( int count ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/.gitignore b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/.gitignore index a799a8361..bc990fc27 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/.gitignore +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/.gitignore @@ -1 +1 @@ -/LocIDs.java +/LocIDsData.java diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java index 038c3ba0d..ab6d1e185 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java @@ -21,6 +21,7 @@ package org.eehouse.android.xw4.loc; import android.app.ListActivity; import android.os.Bundle; +import android.widget.ListView; import org.eehouse.android.xw4.DelegateBase; import org.eehouse.android.xw4.R; @@ -29,6 +30,7 @@ import org.eehouse.android.xw4.R; public class LocDelegate extends DelegateBase { private ListActivity m_activity; + private LocListAdapter m_adapter; protected LocDelegate( ListActivity activity, Bundle savedInstanceState ) { @@ -40,6 +42,10 @@ public class LocDelegate extends DelegateBase { private void init( Bundle savedInstanceState ) { m_activity.setContentView( R.layout.loc_main ); + + ListView listview = m_activity.getListView(); + m_adapter = new LocListAdapter( m_activity, listview ); + m_activity.setListAdapter( m_adapter ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocIDs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocIDs.java new file mode 100644 index 000000000..8398ecf2a --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocIDs.java @@ -0,0 +1,58 @@ +/* -*- 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 java.util.HashMap; +import java.util.Iterator; + +public class LocIDs extends LocIDsData { + private static String[] s_keys; + + protected static String getNthKey( int indx ) + { + if ( null == s_keys ) { + HashMap map = LocIDsData.s_map; + s_keys = new String[map.size()]; + Iterator iter = map.keySet().iterator(); + for ( int ii = 0; iter.hasNext(); ++ii ) { + s_keys[ii] = iter.next(); + } + } + + return s_keys[indx]; + } + + protected static int getID( String key ) + { + return LocIDsData.s_map.get( key ); + } + + protected static int size() + { + return LocIDsData.s_map.size(); + } + + protected static int get( String key ) + { + return LocIDsData.s_map.get( key ); + } + +} diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java new file mode 100644 index 000000000..8270fa497 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java @@ -0,0 +1,56 @@ +/* -*- compile-command: "find-and-ant.sh debug install"; -*- */ +/* + * Copyright 2009 - 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.widget.ListView; +import android.view.View; +import android.view.ViewGroup; + +import org.eehouse.android.xw4.XWListAdapter; +import org.eehouse.android.xw4.DbgUtils; + +public class LocListAdapter extends XWListAdapter { + + private Context m_context; + private ListView m_listView; + + protected LocListAdapter( Context context, ListView listView ) + { + m_context = context; + m_listView = listView; + } + + @Override + public int getCount() + { + int count = LocIDs.size(); + DbgUtils.logf(" LocListAdapter.getCount() => %d", count ); + return count; + } + + public View getView( int position, View convertView, ViewGroup parent ) + { + DbgUtils.logf( "LocListAdapter.getView(position=%d)", position ); + String key = LocIDs.getNthKey( position ); + return LocListItem.create( m_context, key, position ); + } +} diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java new file mode 100644 index 000000000..0fe3bcd6f --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java @@ -0,0 +1,63 @@ +/* -*- 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.widget.LinearLayout; +import android.content.Context; +import android.util.AttributeSet; +import android.widget.TextView; + +import org.eehouse.android.xw4.R; +import org.eehouse.android.xw4.Utils; +import org.eehouse.android.xw4.DbgUtils; + +public class LocListItem extends LinearLayout { + + private Context m_context; + private String m_key; + private int m_position; + + public LocListItem( Context cx, AttributeSet as ) + { + super( cx, as ); + m_context = cx; + } + + private void setEnglish() + { + int id = LocIDs.get( m_key ); + String str = m_context.getString( id ); + TextView tv = (TextView)findViewById( R.id.english_view ); + tv.setText( str ); + DbgUtils.logf( "setEnglish: set to %s", str ); + } + + protected static LocListItem create( Context context, String key, + int position ) + { + LocListItem result = + (LocListItem)Utils.inflate( context, R.layout.loc_list_item ); + result.m_key = key; + result.m_position = position; + result.setEnglish(); + return result; + } +} diff --git a/xwords4/android/scripts/gen_loc_ids.py b/xwords4/android/scripts/gen_loc_ids.py index 79776a242..05cac7bec 100755 --- a/xwords4/android/scripts/gen_loc_ids.py +++ b/xwords4/android/scripts/gen_loc_ids.py @@ -70,7 +70,7 @@ import java.util.HashMap; import org.eehouse.android.xw4.R; -public class LocIDs { +public class LocIDsData { public static final int NOT_FOUND = -1; protected static HashMap s_map; static { @@ -83,15 +83,6 @@ for key in pairs.keys(): # Now the end of the class print """ } - - protected static int getID( String key ) - { - int result = NOT_FOUND; - if ( s_map.containsKey( key ) ) { - result = s_map.get( key ); - } - return result; - } } /* end generated file */ """