Skeleton for tic-tac-toe sample.
Change-Id: I41e7013d469cb2eba9f475aa0a94c4630cacbb64
This commit is contained in:
7
samples/TicTacToeLib/.classpath
Executable file
7
samples/TicTacToeLib/.classpath
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
4
samples/TicTacToeLib/.gitignore
vendored
Normal file
4
samples/TicTacToeLib/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.svn
|
||||||
|
bin
|
||||||
|
gen
|
||||||
|
|
||||||
33
samples/TicTacToeLib/.project
Executable file
33
samples/TicTacToeLib/.project
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>TicTacToeLib</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
25
samples/TicTacToeLib/AndroidManifest.xml
Executable file
25
samples/TicTacToeLib/AndroidManifest.xml
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.tictactoe.library"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0">
|
||||||
|
<application>
|
||||||
|
<activity android:name="GameActivity" />
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
28
samples/TicTacToeLib/default.properties
Executable file
28
samples/TicTacToeLib/default.properties
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2010 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
android.library=true
|
||||||
|
# Project target.
|
||||||
|
target=android-7
|
||||||
BIN
samples/TicTacToeLib/res/drawable/lib_bg.9.png
Executable file
BIN
samples/TicTacToeLib/res/drawable/lib_bg.9.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
samples/TicTacToeLib/res/drawable/lib_circle.png
Executable file
BIN
samples/TicTacToeLib/res/drawable/lib_circle.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
samples/TicTacToeLib/res/drawable/lib_cross.png
Executable file
BIN
samples/TicTacToeLib/res/drawable/lib_cross.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
50
samples/TicTacToeLib/res/layout/lib_game.xml
Executable file
50
samples/TicTacToeLib/res/layout/lib_game.xml
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:weightSum="2"
|
||||||
|
>
|
||||||
|
|
||||||
|
<com.example.tictactoe.library.GameView
|
||||||
|
android:id="@+id/game_view"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_margin="20dip"
|
||||||
|
android:layout_weight="1"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/info_turn"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_weight="1"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/info_turn"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="20dip"
|
||||||
|
android:layout_marginRight="20dip"
|
||||||
|
android:layout_weight="1"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
21
samples/TicTacToeLib/res/values/strings.xml
Executable file
21
samples/TicTacToeLib/res/values/strings.xml
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
|
||||||
|
</resources>
|
||||||
53
samples/TicTacToeLib/src/com/example/tictactoe/library/GameActivity.java
Executable file
53
samples/TicTacToeLib/src/com/example/tictactoe/library/GameActivity.java
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.tictactoe.library;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class GameActivity extends Activity {
|
||||||
|
|
||||||
|
public final static String EXTRA_START_WITH_HUMAN =
|
||||||
|
"com.example.tictactoe.library.GameActivity.EXTRA_START_WITH_HUMAN";
|
||||||
|
|
||||||
|
private boolean mTurnIsHuman;
|
||||||
|
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IMPORTANT TIP: all resource IDs from this library must be
|
||||||
|
* different from the projects that will include it. E.g.
|
||||||
|
* if my layout were named "main.xml", I would have to use the ID
|
||||||
|
* R.layout.main; however there is already a *different*
|
||||||
|
* ID with the same name in the main project and when the library
|
||||||
|
* gets merged in the project the wrong ID would end up being used.
|
||||||
|
*
|
||||||
|
* To avoid such potential conflicts, it's probably a good idea
|
||||||
|
* to add a prefix to the library resource names.
|
||||||
|
*/
|
||||||
|
setContentView(R.layout.lib_game);
|
||||||
|
|
||||||
|
mTurnIsHuman = getIntent().getBooleanExtra(
|
||||||
|
EXTRA_START_WITH_HUMAN, true);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
152
samples/TicTacToeLib/src/com/example/tictactoe/library/GameView.java
Executable file
152
samples/TicTacToeLib/src/com/example/tictactoe/library/GameView.java
Executable file
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.tictactoe.library;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.BitmapFactory.Options;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Handler.Callback;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
public class GameView extends View {
|
||||||
|
|
||||||
|
private final static String TAG = "GameView";
|
||||||
|
|
||||||
|
private static final int MSG_FRAME = 1;
|
||||||
|
|
||||||
|
public static final long FPS_MS = 1000/2;
|
||||||
|
|
||||||
|
public static final int EMPTY = 0;
|
||||||
|
public static final int CROSS = 1;
|
||||||
|
public static final int CIRCLE = 2;
|
||||||
|
|
||||||
|
|
||||||
|
/** Contains one of {@link #EMPTY}, {@link #CROSS} or {@link #CIRCLE} */
|
||||||
|
private final int[] mData = new int[9];
|
||||||
|
|
||||||
|
private final Rect mBgRect = new Rect();
|
||||||
|
private final Rect mTempDst = new Rect();
|
||||||
|
|
||||||
|
private int mSxy;
|
||||||
|
private int mOffetX;
|
||||||
|
private int mOffetY;
|
||||||
|
private Paint mLinePaint;
|
||||||
|
private Drawable mDrawableBg;
|
||||||
|
|
||||||
|
|
||||||
|
public GameView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
requestFocus();
|
||||||
|
|
||||||
|
mDrawableBg = getResources().getDrawable(R.drawable.lib_bg);
|
||||||
|
|
||||||
|
mLinePaint = new Paint();
|
||||||
|
mLinePaint.setColor(0xFFFFFFFF);
|
||||||
|
mLinePaint.setStrokeWidth(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
int sxy = mSxy;
|
||||||
|
int s3 = sxy * 3;
|
||||||
|
int x7 = mOffetX;
|
||||||
|
int y7 = mOffetY;
|
||||||
|
|
||||||
|
mDrawableBg.draw(canvas);
|
||||||
|
|
||||||
|
for (int i = 0, k = sxy; i < 2; i++, k += sxy) {
|
||||||
|
canvas.drawLine(x7 , y7 + k, x7 + s3, y7 + k , mLinePaint);
|
||||||
|
canvas.drawLine(x7 + k, y7 , x7 + k , y7 + s3, mLinePaint);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0, k = 0, y = y7; j < 3; j++, y += sxy) {
|
||||||
|
for (int i = 0, x = x7; i < 3; i++, x += sxy) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
Log.d(TAG, String.format("onSizeChanged: %dx%d", w, h));
|
||||||
|
|
||||||
|
int sx = w / 3;
|
||||||
|
int sy = h / 3;
|
||||||
|
|
||||||
|
int size = sx < sy ? sx : sy;
|
||||||
|
|
||||||
|
mSxy = size;
|
||||||
|
mOffetX = (w - 3 * size) / 2;
|
||||||
|
mOffetY = (h - 3 * size) / 2;
|
||||||
|
|
||||||
|
mDrawableBg.setBounds(mOffetX, mOffetY,
|
||||||
|
mOffetX + 3 * size, mOffetY + 3 * size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
int action = event.getAction();
|
||||||
|
|
||||||
|
if (action == MotionEvent.ACTION_DOWN) {
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||||
|
float x = event.getX();
|
||||||
|
float y = event.getY();
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getResBitmap(int bmpResId) {
|
||||||
|
Options opts = new Options();
|
||||||
|
opts.inDither = false;
|
||||||
|
|
||||||
|
Resources res = getResources();
|
||||||
|
Bitmap bmp = BitmapFactory.decodeResource(res, bmpResId, opts);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
8
samples/TicTacToeMain/.classpath
Executable file
8
samples/TicTacToeMain/.classpath
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="src" path="TicTacToeLib"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
4
samples/TicTacToeMain/.gitignore
vendored
Normal file
4
samples/TicTacToeMain/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.svn
|
||||||
|
bin
|
||||||
|
gen
|
||||||
|
|
||||||
40
samples/TicTacToeMain/.project
Executable file
40
samples/TicTacToeMain/.project
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>TicTacToeMain</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
<linkedResources>
|
||||||
|
<link>
|
||||||
|
<name>TicTacToeLib</name>
|
||||||
|
<type>2</type>
|
||||||
|
<locationURI>_android_TicTacToeLib/src</locationURI>
|
||||||
|
</link>
|
||||||
|
</linkedResources>
|
||||||
|
</projectDescription>
|
||||||
39
samples/TicTacToeMain/AndroidManifest.xml
Executable file
39
samples/TicTacToeMain/AndroidManifest.xml
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.tictactoe"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0">
|
||||||
|
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||||
|
<activity android:name=".MainActivity"
|
||||||
|
android:label="@string/app_name">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<!-- This is defined in TicTacToeLib. Right now we need to manually
|
||||||
|
copy it here. Eventually it should get merged automatically. -->
|
||||||
|
<activity android:name=".library.GameActivity" />
|
||||||
|
|
||||||
|
|
||||||
|
</application>
|
||||||
|
<uses-sdk android:minSdkVersion="Froyo" />
|
||||||
|
|
||||||
|
</manifest>
|
||||||
28
samples/TicTacToeMain/default.properties
Executable file
28
samples/TicTacToeMain/default.properties
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2010 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
android.library.reference.1=../TicTacToeLib/
|
||||||
|
# Project target.
|
||||||
|
target=android-Froyo
|
||||||
BIN
samples/TicTacToeMain/res/drawable/icon.png
Executable file
BIN
samples/TicTacToeMain/res/drawable/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
69
samples/TicTacToeMain/res/layout/main.xml
Executable file
69
samples/TicTacToeMain/res/layout/main.xml
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="20dip"
|
||||||
|
android:layout_marginBottom="5dip"
|
||||||
|
android:text="@string/welcome"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_marginBottom="5dip"
|
||||||
|
android:text="@string/explain2"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_marginBottom="20dip"
|
||||||
|
android:text="@string/explain1"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/start_player"
|
||||||
|
android:text="@string/start_player"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/start_comp"
|
||||||
|
android:text="@string/start_comp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dip"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ImageView01"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/icon"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
26
samples/TicTacToeMain/res/values/strings.xml
Executable file
26
samples/TicTacToeMain/res/values/strings.xml
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<string name="start_comp">Start -- Computer goes first</string>
|
||||||
|
<string name="start_player">Start -- Player goes first</string>
|
||||||
|
<string name="welcome"><b>Welcome to the Tic-Tac-Toe Sample!</b></string>
|
||||||
|
<string name="explain1">This sample code demonstrates how to split an application in multiple projects by using the \'project library\' available in the Froyo SDK Tools.</string>
|
||||||
|
<string name="explain2">This activity is defined in one project. The second activity, launched by one of the buttons below, is located in another project which is a \"library\" to the main one and merged in the same APK.</string>
|
||||||
|
<string name="hello">Hello World, MainActivity!</string>
|
||||||
|
<string name="app_name">Tic-Tac-Toe Sample</string>
|
||||||
|
</resources>
|
||||||
53
samples/TicTacToeMain/src/com/example/tictactoe/MainActivity.java
Executable file
53
samples/TicTacToeMain/src/com/example/tictactoe/MainActivity.java
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.example.tictactoe;
|
||||||
|
|
||||||
|
import com.example.tictactoe.library.GameActivity;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
|
||||||
|
public class MainActivity extends Activity {
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
|
findViewById(R.id.start_player).setOnClickListener(
|
||||||
|
new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
startGame(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
findViewById(R.id.start_comp).setOnClickListener(
|
||||||
|
new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
startGame(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startGame(boolean startWithHuman) {
|
||||||
|
Intent i = new Intent(this, GameActivity.class);
|
||||||
|
i.putExtra(GameActivity.EXTRA_START_WITH_HUMAN, startWithHuman);
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user