mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
new activity/layout for picking tiles
This commit is contained in:
parent
a91f662327
commit
5c762466aa
2 changed files with 102 additions and 0 deletions
23
xwords4/android/XWords4/res/layout/tile_picker.xml
Normal file
23
xwords4/android/XWords4/res/layout/tile_picker.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp">
|
||||
|
||||
|
||||
<TableLayout android:id="@+id/tile_table"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="1">
|
||||
</TableLayout>
|
||||
|
||||
<Button android:id="@+id/cancel"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:text="@string/button_cancel" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,79 @@
|
|||
/* -*- compile-command: "cd ../../../../../; ant reinstall"; -*- */
|
||||
|
||||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.content.Intent;
|
||||
import android.widget.Button;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
|
||||
public class TilePicker extends Activity implements View.OnClickListener {
|
||||
static final int N_COLS = 5;
|
||||
private String[] m_tiles;
|
||||
private Button m_cancel;
|
||||
private int m_tileIndex = 0;
|
||||
|
||||
private TableLayout m_table;
|
||||
|
||||
class Finisher implements View.OnClickListener {
|
||||
int m_index;
|
||||
Activity m_activity;
|
||||
Finisher( Activity activity, int index ) {
|
||||
m_activity = activity;
|
||||
m_index = index;
|
||||
}
|
||||
public void onClick(View v) {
|
||||
m_activity.setResult( RESULT_FIRST_USER + m_index );
|
||||
m_activity.finish();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
Utils.logf( "TilePicker::onCreate() called" );
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
setContentView( R.layout.tile_picker );
|
||||
|
||||
Intent intent = getIntent();
|
||||
Bundle bundle = intent.getBundleExtra( XWConstants.PICK_TILE_TILES );
|
||||
m_tiles = bundle.getStringArray( XWConstants.PICK_TILE_TILES );
|
||||
|
||||
m_cancel = (Button)findViewById( R.id.cancel );
|
||||
m_cancel.setOnClickListener( this );
|
||||
|
||||
m_table = (TableLayout)findViewById( R.id.tile_table );
|
||||
|
||||
TableRow row = null;
|
||||
int ii;
|
||||
for ( ii = 0; ii < m_tiles.length; ) {
|
||||
if ( null == row ) {
|
||||
row = new TableRow( this );
|
||||
}
|
||||
Button button = new Button( this );
|
||||
button.setText( m_tiles[ii] );
|
||||
button.setOnClickListener( new Finisher( this, ii ) );
|
||||
row.addView( button );
|
||||
|
||||
++ii;
|
||||
if ( ii == m_tiles.length || ii % N_COLS == 0 ) {
|
||||
m_table.addView( row );
|
||||
row = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onClick( View v )
|
||||
{
|
||||
if ( m_cancel == v ) {
|
||||
setResult( RESULT_FIRST_USER + m_tileIndex );
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue