Multiple Touch sample code

20. 十月 2011
@Override
public boolean onTouch(View v, MotionEvent event) {
   // Dump touch event to log
   dumpEvent(event);
   return true; // indicate event was handled 
} 

private void dumpEvent(MotionEvent event) {
   String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
      "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
   StringBuilder sb = new StringBuilder();
   int action = event.getAction();
   int actionCode = action & MotionEvent.ACTION_MASK;
   sb.append("event ACTION_" ).append(names[actionCode]);
   if (actionCode == MotionEvent.ACTION_POINTER_DOWN
         || actionCode == MotionEvent.ACTION_POINTER_UP) {
      sb.append("(pid " ).append(
      action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
      sb.append(")" );
   }
   sb.append("[" );
   for (int i = 0; i < event.getPointerCount(); i++) {
      sb.append("#" ).append(i);
      sb.append("(pid " ).append(event.getPointerId(i));
      sb.append(")=" ).append((int) event.getX(i));
      sb.append("," ).append((int) event.getY(i));
      if (i + 1 < event.getPointerCount())
         sb.append(";" );
   }
   sb.append("]" );
   Log.d(TAG, sb.toString());
}

Android笔记, Android小技术

[Objective C] の [Byte]

5. 七月 2011
 在Objective里面定义了一个 Byte 变量 shiftS 并通过计算, 赋值为3.

shiftS = 3;

但是在
shiftS *= -1;

的时候出现错误,
NSLog (@"shiftS = %d", shiftS);   //输出是250左右的一个数,具体忘了.

事实证明,Byte是一个无符号的 8 bit int.

objective c ,

Android自定义控件示例

30. 三月 2011
 

package org.woa.view;
 
import org.woa.activity.R;
 
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
 
public class TableView extends TableLayout {
 
private int mColNum, mRowNum;
 
private boolean mHeader;
 
private int mTableHeight, mTableWidth;
 
private int mCellBackgroundResource;
 
private Drawable mCellBackgroundDrawable;
 
private TableRow[] trList;
private View[][] cellList;
 
public TableView(Context context, AttributeSet attrs) {
super(context, attrs);
 
this.bindAttributes(context, attrs);
 
// setup the table view
this.trList = new TableRow[this.mRowNum];
this.cellList = new View[this.mRowNum][this.mColNum];
View cell;
TableRow tr;
char A = 'A';
for (int row = 0; row < this.mRowNum; row++) {
tr = trList[row] = new TableRow(context);
for (int col = 0; col < this.mColNum; col++) {
if (mHeader && row == 0 && col != 0) {
cell = new TextView(context);
((TextView) cell).setText(A++ + "");
((TextView) cell).setTextColor(Color.BLACK);
} else if (mHeader && col == 0 && row != 0) {
cell = new TextView(context);
((TextView) cell).setText(row + "");
((TextView) cell).setTextColor(Color.BLACK);
} else {
cell = new View(context);
}
 
cellList[row][col] = cell;
cell.setId(row * 10 + col);
if (mCellBackgroundResource == -1) {
cell.setBackgroundDrawable(mCellBackgroundDrawable);
} else {
cell.setBackgroundResource(this.mCellBackgroundResource);
}
 
if (cell instanceof TextView) {
((TextView) cell).setGravity(Gravity.CENTER);
((TextView) cell).setTextSize(20);
}
TableRow.LayoutParams lp_cell = new TableRow.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
lp_cell.weight = 1;
cell.setLayoutParams(lp_cell);
tr.addView(cell, col);
}
TableLayout.LayoutParams lp_tr = new TableLayout.LayoutParams();
lp_tr.weight = 1;
this.addView(tr, lp_tr);
}
}
 
public void bindAttributes(Context context, AttributeSet attrs) {
 
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.TableView);
 
this.mHeader = a.getBoolean(R.styleable.TableView_mHeader, false);
this.mCellBackgroundResource = a.getInt(
R.styleable.TableView_mCellBackgroundResource, -1);
this.mCellBackgroundDrawable = a
.getDrawable(R.styleable.TableView_mCellBackgroundDrawable);
 
this.mColNum = a.getInt(R.styleable.TableView_mColNum, 4);
this.mRowNum = a.getInt(R.styleable.TableView_mRowNum, 4);
if (mHeader) {
this.mColNum++;
this.mRowNum++;
}
}
 
public int getTableHeight() {
return mTableHeight;
}
 
public void setTableHeight(int tableHeight) {
this.mTableHeight = tableHeight;
}
 
public int getTableWidth() {
return mTableWidth;
}
 
public void setTableWidth(int tableWidth) {
this.mTableWidth = tableWidth;
}
 
public int getTableColNum() {
return mColNum;
}
 
public void setTableColNum(int tableColNum) {
this.mColNum = tableColNum;
}
 
public int getTableRowNum() {
return mRowNum;
}
 
public void setTableRowNum(int tableRowNum) {
this.mRowNum = tableRowNum;
}
}


attribute:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TableView">
<attr format="string" name="mColNum" />
<attr format="string" name="mRowNum" />
<attr format="string" name="mHeader" />
<attr format="string" name="mCellBackgroundResource" />
<attr format="string" name="mCellBackgroundDrawable" />
</declare-styleable>
</resources>

 
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fsms="http://schemas.android.com/apk/res/org.woa.activity"
android:orientation="horizontal" android:baselineAligned="true"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<org.woa.view.TableView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/playground"
fsms:mRowNum="6" fsms:mColNum="6" fsms:mHeader="true"
fsms:mCellBackgroundDrawable="@android:drawable/btn_default"
android:background="@android:drawable/toast_frame">
</org.woa.view.TableView>
</LinearLayout>
 
 

Android小技术, WOA ,

2011年6月15日更新Android SDK & NDK & ADT 下载地址

1. 三月 2011
SDK:

Platform Package Size MD5 Checksum
Windows android-sdk_r11-windows.zip 32837554 bytes 0a2c52b8f8d97a4871ce8b3eb38e3072
installer_r11-windows.exe (Recommended) 32883649 bytes 3dc8a29ae5afed97b40910ef153caa2b
Mac OS X (intel) android-sdk_r11-mac_x86.zip 28844968 bytes 85bed5ed25aea51f6a447a674d637d1e
Linux (i386) android-sdk_r11-linux_x86.tgz 26984929 bytes 026c67f82627a3a70efb197ca3360d0a
 


NDK:

Platform Package Size MD5 Checksum
Windows android-ndk-r5c-windows.zip 61627716 bytes 2c7423842fa0f46871eab118495d4b45
Mac OS X (intel) android-ndk-r5c-darwin-x86.tar.bz2 50714712 bytes 183bfbbd85cf8e4c0bd7531e8803e75d
Linux 32/64-bit (x86) android-ndk-r5c-linux-x86.tar.bz2 44539890 bytes 7659dfdc97026ed1d913e224d0531f61
 


ADT:

Name Package Size MD5 Checksum
ADT 11.0.0 ADT-11.0.0.zip 5520455 bytes 8f01ecf456f28a90ba3dcf89cfeb37dc
 

, , , ,

版本号定义

27. 二月 2011
1.2.3.4
1.第一发正式版
2.基于第一个正式版的第二个beta版
3.基于1.2版本下的第3个内部开发版
4.修正版,用于Bug或其他临时修改。

WOA

网址收藏

23. 二月 2011
http://www.189works.com/engine/libGDX/ 
http://www.andengine.org/forums/ 
http://blog.sina.com.cn/s/blog_46dcb65d0100o4cy.html  http://www.appbrain.com/

Android平台游戏引擎Angle学习笔记--开始篇

21. 十二月 2010

  虽然自己设计的游戏,在界面,功能上并不复杂,但始终不可以让脚步停在这里,于是想找些游戏引擎来学习一下。

在网上随手搜一下“Android 游戏引擎”,被广为转载的是一篇名为:《或许您还不知道的八款开源Android游戏引擎》。里面介绍的8款游戏引擎各有特点,不过以我对自己的了解来看,我的能力只能挑个最简单的来学学。

Angle,Rokon,LGame,AndEngine,libgdx,jPCT,Alien3d,Catcake。

  其实有三个简单了解了一下:
Angle,小巧灵珑,整个引擎只有28个类,虽然文档没有,网络资料又少,示例也仅有几个,不过相信学起来比较容易;
  LGame,是国人写的,功能全,文档示例较多,就是体积较大;
AndEngine,在Market上面下载了示例,很精致,让我很有好感,不过比起Angle,这个也是体积很大。

Angle示例之一:
整个示例只有下面这十几行,功能是在屏幕上显示一个sprite(精灵),代码如下:

// Tutorial01.java
        public class Tutorial01 extends AngleActivity {
         @Override
         public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          AngleSpriteLayout mLogoLayout = new AngleSpriteLayout(mGLSurfaceView, R.drawable.anglelogo);
          AngleSprite mLogo = new AngleSprite (mLogoLayout);
          mLogo.mPosition.set(160, 200);
          mGLSurfaceView.addObject(mLogo);
          setContentView(mGLSurfaceView);
         }
        }

这个示例中主要使用了几个Angle中的封装类(加粗表示)。
AngleActivity:是Angle对Android中Activity的封装,里面包含了一个SurfaceView的实现,即mGLSurfaceView。
AngleSpriteLayout:指定sprite的源文件
AngleSprite:Sprite对象,加载AngleSpriteLayout,并指定位置mPosition(向量类型)。

Angle示例之二:
// Tutorial02.java
public class Tutorial02 extends AngleActivity
{
 private class MyAnimatedSprite extends AngleRotatingSprite
 {
  public MyAnimatedSprite(int x, int y, AngleSpriteLayout layout)
  {
   super(x, y, layout);
  }

  @Override
  public void step(float secondsElapsed)
  {
   mRotation+=secondsElapsed*10;//10º per second
   super.step(secondsElapsed);
  }
 };
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  mGLSurfaceView.addObject(new MyAnimatedSprite (160, 200, new AngleSpriteLayout(mGLSurfaceView, R.drawable.anglelogo)));
  FrameLayout mMainLayout=new FrameLayout(this);
  mMainLayout.addView(mGLSurfaceView);
  setContentView(mMainLayout);
 }
}

与示例1不同的地方在于,这次的精灵是AngleRotatingSprite.一个旋转的对象.
MyAnimatedSprite继承自AngleRotatingSprite,在构造方法中指定了对象的坐标,
重写了step方法设置了旋转速度.

onCreate中,没有将mGLSurfaceView传给setContecnView里,而是通过FrameLayout,事实上单从这一个例子上来看,这没什么不同.
 

Android笔记

JDK与Eclipse历史版本的下载地址

25. 十一月 2010
SUN被oracle收了当小弟之后似乎不怎么待见,一直没找到JDK 6.0 update 20的下载地址。
不过还算是有下面这个地址可以用。
你可以从这里下载jdk所有的版本:)   
http://java.sun.com/products/archive/index.html

eclipse各种版本下载地址

http://archive.eclipse.org/eclipse/downloads/

记事

服务端Defect List

12. 十一月 2010

D0001: 线程独占CPU,程CPU使用率99%,加Thread.sleep(1)解决.
D0002: Spring中ApplicationContext,应该是一个全局的对象,而不是哪有有需要,哪里new一个.这样浪费内存.
D0003: 使用老旧的java.io做socket监听,太浪费资源,改用nio的框架netty.

服务器参数

26. 十月 2010
server.port
server.tableSize
server.maxClientAmount
jdbc.driverClassName
jdbc.url

WOA