mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
beginnings of framework to allow localized strings to be read from downloaded modules: in xml replace string references with a custom attribute that's the same thing, then in overridden view subclasses pull the reference from the AttributeSet and look it up myself. Works to uppercase all strings in the NewGames dialog.
This commit is contained in:
parent
eff00c1743
commit
bd02a10fc3
5 changed files with 173 additions and 42 deletions
|
@ -15,20 +15,22 @@
|
|||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:custom="http://schemas.android.com/apk/res/org.eehouse.android.xw4"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
|
||||
<!-- local game -->
|
||||
<TextView style="@style/config_separator"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_local_header"
|
||||
/>
|
||||
<org.eehouse.android.xw4.loc.LocTextView
|
||||
style="@style/config_separator"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
custom:strid="@string/newgame_local_header"
|
||||
/>
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -50,21 +52,21 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_local"
|
||||
android:text="@string/newgame_local"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_local"
|
||||
custom:strid="@string/newgame_local"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
<Button android:id="@+id/newgame_local_config"
|
||||
android:text="@string/newgame_local_config"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_local_config"
|
||||
custom:strid="@string/newgame_local_config"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- networked game -->
|
||||
<TextView style="@style/config_separator"
|
||||
<org.eehouse.android.xw4.loc.LocTextView style="@style/config_separator"
|
||||
android:layout_marginTop="10dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_networked_header"
|
||||
custom:strid="@string/newgame_networked_header"
|
||||
/>
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
|
@ -79,7 +81,7 @@
|
|||
android:layout_weight="0"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
/>
|
||||
<TextView android:text="@string/newgame_networked_desc"
|
||||
<org.eehouse.android.xw4.loc.LocTextView custom:strid="@string/newgame_networked_desc"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
@ -88,23 +90,23 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_invite_net"
|
||||
android:text="@string/newgame_invite"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_invite_net"
|
||||
custom:strid="@string/newgame_invite"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/newgame_net_config"
|
||||
android:text="@string/newgame_net_config"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_net_config"
|
||||
custom:strid="@string/newgame_net_config"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- SMS game -->
|
||||
<TextView android:id="@+id/sms_separator"
|
||||
<org.eehouse.android.xw4.loc.LocTextView android:id="@+id/sms_separator"
|
||||
style="@style/config_separator"
|
||||
android:layout_marginTop="10dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_sms_header"
|
||||
custom:strid="@string/newgame_sms_header"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
|
@ -114,13 +116,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView android:text="@string/sms_disabled"
|
||||
<org.eehouse.android.xw4.loc.LocTextView custom:strid="@string/sms_disabled"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
<Button android:id="@+id/newgame_enable_sms"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_enable_sms"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_enable_sms"
|
||||
custom:strid="@string/newgame_enable_sms"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -142,7 +144,7 @@
|
|||
android:layout_weight="0"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
/>
|
||||
<TextView android:text="@string/sms_networked_desc"
|
||||
<org.eehouse.android.xw4.loc.LocTextView custom:strid="@string/sms_networked_desc"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
@ -151,24 +153,24 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_invite_sms"
|
||||
android:text="@string/newgame_invite"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_invite_sms"
|
||||
custom:strid="@string/newgame_invite"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/newgame_sms_config"
|
||||
android:text="@string/newgame_net_config"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_sms_config"
|
||||
custom:strid="@string/newgame_net_config"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Bluetooth -->
|
||||
<TextView android:id="@+id/bt_separator"
|
||||
<org.eehouse.android.xw4.loc.LocTextView android:id="@+id/bt_separator"
|
||||
style="@style/config_separator"
|
||||
android:layout_marginTop="10dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_bt_header"
|
||||
custom:strid="@string/newgame_bt_header"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
|
@ -178,13 +180,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView android:text="@string/bt_disabled"
|
||||
<org.eehouse.android.xw4.loc.LocTextView custom:strid="@string/bt_disabled"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
<Button android:id="@+id/newgame_enable_bt"
|
||||
<org.eehouse.android.xw4.loc.LocButton android:id="@+id/newgame_enable_bt"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_enable_bt"
|
||||
custom:strid="@string/newgame_enable_bt"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -206,7 +208,7 @@
|
|||
android:layout_weight="0"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
/>
|
||||
<TextView android:text="@string/bt_networked_desc"
|
||||
<org.eehouse.android.xw4.loc.LocTextView custom:strid="@string/bt_networked_desc"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
@ -215,15 +217,17 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_invite_bt"
|
||||
android:text="@string/newgame_invite"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
<org.eehouse.android.xw4.loc.LocButton
|
||||
android:id="@+id/newgame_invite_bt"
|
||||
custom:strid="@string/newgame_invite"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/newgame_bt_config"
|
||||
android:text="@string/newgame_net_config"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
<org.eehouse.android.xw4.loc.LocButton
|
||||
android:id="@+id/newgame_bt_config"
|
||||
custom:strid="@string/newgame_net_config"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
7
xwords4/android/XWords4/res/values/attrs.xml
Normal file
7
xwords4/android/XWords4/res/values/attrs.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<resources>
|
||||
<declare-styleable name="LocText">
|
||||
<!-- It doesn't matter the format: string, integer and
|
||||
reference all "work" -->
|
||||
<attr name="strid" format="integer" />
|
||||
</declare-styleable>
|
||||
</resources>
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- 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.Button;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class LocButton extends Button implements LocUtils.LocIface {
|
||||
|
||||
public LocButton( Context cx, AttributeSet as )
|
||||
{
|
||||
super( cx, as );
|
||||
LocUtils.loadStrings( cx, as, this );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- 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.TextView;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class LocTextView extends TextView implements LocUtils.LocIface {
|
||||
|
||||
public LocTextView( Context cx, AttributeSet as )
|
||||
{
|
||||
super( cx, as );
|
||||
LocUtils.loadStrings( cx, as, this );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/* -*- 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.util.AttributeSet;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.DbgUtils;
|
||||
|
||||
public class LocUtils {
|
||||
|
||||
public interface LocIface {
|
||||
void setText( CharSequence text );
|
||||
}
|
||||
|
||||
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( context.getString( id ).toUpperCase() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue