Permalink
Browse files

Initial Check in. Currently only managing users is supported.

  • Loading branch information...
0 parents commit 01768bf76aa1394b50cf6420cbb58e900ebf956c johnwayner committed May 24, 2010
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.johnwayner.android.tichu.scorer" android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".actions.ManagePlayers"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+
+</manifest>
@@ -0,0 +1,13 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Indicates whether an apk should be generated for each density.
+split.density=false
+# Project target.
+target=android-7
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,12 @@
+<?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"
+ >
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello"
+ />
+</LinearLayout>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:id="@+id/player_edit_layout">
+
+<TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:id="@+id/name_label" android:text="@string/name_label" android:textSize="16sp" android:padding="10dp" android:singleLine="true"></TextView><EditText android:layout_height="wrap_content" android:id="@+id/name_edit_text" android:layout_toRightOf="@id/name_label" android:lines="1" android:maxLines="1" android:layout_marginRight="10dp" android:layout_width="fill_parent" android:inputType="textPersonName"></EditText>
+
+
+</RelativeLayout>
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu
+ xmlns:android="http://schemas.android.com/apk/res/android">
+<item android:title="New Player" android:id="@+id/new_player_menu_item"></item>
+<item android:title="Delete All" android:id="@+id/delete_all_menu_item"></item>
+</menu>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, CreateNewGame!</string>
+ <string name="app_name">Tichu Scorer</string>
+<string name="name_label">Name:</string>
+<string name="create_new_player_title">Create New Player</string>
+
+<string name="player_edit_save_button_label">Save Player</string>
+<string name="edit_player_title">Edit Player</string>
+<string name="cancel_button_label">Cancel</string>
+</resources>
@@ -0,0 +1,32 @@
+package com.johnwayner.android.tichu.scorer.actions;
+
+import java.io.IOException;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import com.johnwayner.android.tichu.scorer.R;
+import com.johnwayner.android.tichu.scorer.models.ApplicationState;
+import com.johnwayner.android.tichu.scorer.models.Player;
+
+public class CreateNewGame extends Activity {
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ApplicationState appState = ApplicationState.getState(this.getApplicationContext());
+ appState.getPlayers().add(new Player("Steve"));
+ setContentView(R.layout.main);
+ }
+
+ @Override
+ protected void onPause() {
+ try {
+ ApplicationState.saveState();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ super.onPause();
+ }
+}
@@ -0,0 +1,187 @@
+/**
+ *
+ */
+package com.johnwayner.android.tichu.scorer.actions;
+
+import java.io.IOException;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.ListActivity;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.text.Selection;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnKeyListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.AdapterView.OnItemClickListener;
+
+import com.johnwayner.android.tichu.scorer.R;
+import com.johnwayner.android.tichu.scorer.models.ApplicationState;
+import com.johnwayner.android.tichu.scorer.models.Player;
+
+/**
+ * @author johnwayner
+ *
+ */
+public class ManagePlayers extends ListActivity {
+ private final static int DIALOG_NEW = 0;
+ private final static int DIALOG_EDIT = 1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final ApplicationState appState = ApplicationState.getState(this);
+ arrayAdapter =
+ new ArrayAdapter<Player>(
+ this,
+ android.R.layout.simple_list_item_single_choice,
+ appState.getPlayers());
+
+ setListAdapter(arrayAdapter);
+
+ getListView().setTextFilterEnabled(true);
+
+ getListView().setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position,
+ long arg3) {
+ playerToEdit = arrayAdapter.getItem(position);
+ showDialog(DIALOG_EDIT);
+
+ }
+
+ });
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.manage_players_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case R.id.new_player_menu_item:
+// startActivity(new Intent(EditPlayer.NEW_USER_ACTION_NAME));
+// arrayAdapter.notifyDataSetChanged();
+ showDialog(DIALOG_NEW);
+ return true;
+ case R.id.delete_all_menu_item:
+ arrayAdapter.clear();
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ protected Dialog onCreateDialog(int id)
+ {
+ return createEditorDialog(id);
+ }
+
+ private Dialog createEditorDialog(final int id)
+ {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+
+ if(DIALOG_NEW == id) {
+ builder.setTitle(R.string.create_new_player_title);
+ } else {
+ builder.setTitle(R.string.edit_player_title);
+ }
+
+ View content = getLayoutInflater().inflate(R.layout.player_edit,
+ (ViewGroup) findViewById(R.id.player_edit_layout));
+ builder.setView(content);
+
+ final EditText nameField = (EditText)
+ content.findViewById(R.id.name_edit_text);
+
+ nameField.setOnKeyListener(new OnKeyListener() {
+
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if((null != event) && (KeyEvent.KEYCODE_ENTER == event.getKeyCode())) {
+ return true;
+ }
+ return false;
+ }
+ });
+
+ builder.setPositiveButton(R.string.player_edit_save_button_label,
+ new DialogInterface.OnClickListener()
+ {
+
+ public void onClick(DialogInterface dialog, int which)
+ {
+ String newName = nameField.getText().toString();
+
+ if(DIALOG_NEW == id) {
+ arrayAdapter.add(
+ new Player(newName));
+ } else {
+ playerToEdit.setName(newName);
+ }
+
+ arrayAdapter.notifyDataSetChanged();
+ dialog.dismiss();
+ }
+ });
+
+ builder.setNegativeButton(R.string.cancel_button_label,
+ new DialogInterface.OnClickListener()
+ {
+
+ public void onClick(DialogInterface dialog, int which)
+ {
+ dialog.dismiss();
+ }
+ });
+
+ return builder.create();
+ }
+
+ @Override
+ protected void onPrepareDialog(int id, Dialog dialog) {
+ super.onPrepareDialog(id, dialog);
+
+ EditText nameField = (EditText)
+ dialog.findViewById(R.id.name_edit_text);
+
+ if(DIALOG_EDIT == id) {
+ nameField.setText(playerToEdit.getName());
+ } else {
+ nameField.setText("");
+ }
+
+ //Work around to put the cursor at the end
+ Selection.setSelection(
+ nameField.getText(),
+ nameField.getText().length());
+ }
+
+ @Override
+ protected void onPause() {
+ try {
+ ApplicationState.saveState();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ super.onPause();
+ }
+
+ private Player playerToEdit;
+ private ArrayAdapter<Player> arrayAdapter;
+
+}
@@ -0,0 +1,38 @@
+/**
+ *
+ */
+package com.johnwayner.android.tichu.scorer.models;
+
+import java.io.Serializable;
+
+/**
+ * Generic ID-adding class.
+ * @author johnwayner
+ *
+ */
+public abstract class AbstractIdentifiedObject implements Serializable {
+ private static final long serialVersionUID = 8647346339618617912L;
+ private static final long NO_ID = 0;
+ private static long nextID = 1;
+ private static Object IDLock = new Object();
+
+ public AbstractIdentifiedObject() {
+ super();
+ this.id = getNextID();
+ }
+
+ protected long getNextID() {
+ synchronized (IDLock) {
+ return nextID++;
+ }
+ }
+
+ protected long id;
+
+ public long getId() {
+ if(NO_ID == id) {
+ id = getNextID();
+ }
+ return id;
+ }
+}
Oops, something went wrong.

0 comments on commit 01768bf

Please sign in to comment.