Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Data structure is changed for DroidRobo01.

  • Loading branch information...
commit f7f145be592abd803c93d55a49ea19c68352ed37 1 parent 23483d1
@cattaka authored
View
44 DroidDancerMotionWriter/src/jp/co/kayo/android/droiddancermotionwriter/EditActivity.java
@@ -1,3 +1,4 @@
+
package jp.co.kayo.android.droiddancermotionwriter;
import android.app.Activity;
@@ -10,61 +11,66 @@
public class EditActivity extends Activity {
private long uid;
+
private CheckBox checkbox1;
+
private EditText editText1;
+
private EditText editText2;
+
private EditText editText3;
+
private EditText editText4;
+
private EditText editText5;
-
-
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
-
+
checkbox1 = (CheckBox)findViewById(R.id.checkbox1);
editText1 = (EditText)findViewById(R.id.editText1);
editText2 = (EditText)findViewById(R.id.editText2);
editText3 = (EditText)findViewById(R.id.editText3);
editText4 = (EditText)findViewById(R.id.editText4);
editText5 = (EditText)findViewById(R.id.editText5);
-
+
findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
-
+
@Override
public void onClick(View v) {
finish();
}
});
findViewById(R.id.button2).setOnClickListener(new OnClickListener() {
-
+
@Override
public void onClick(View v) {
Intent data = new Intent();
data.putExtra("uid", uid);
data.putExtra("led", checkbox1.isChecked());
- data.putExtra("armleft", Byte.parseByte(editText1.getText().toString()));
- data.putExtra("armright", Byte.parseByte(editText2.getText().toString()));
- data.putExtra("rotleft", Byte.parseByte(editText3.getText().toString()));
- data.putExtra("rotright", Byte.parseByte(editText4.getText().toString()));
- data.putExtra("time", Byte.parseByte(editText5.getText().toString()));
+ data.putExtra("armleft", Integer.parseInt(editText1.getText().toString()));
+ data.putExtra("armright", Integer.parseInt(editText2.getText().toString()));
+ data.putExtra("rotleft", Integer.parseInt(editText3.getText().toString()));
+ data.putExtra("rotright", Integer.parseInt(editText4.getText().toString()));
+ data.putExtra("time", Integer.parseInt(editText5.getText().toString()));
setResult(100, data);
finish();
}
});
-
+
Intent intent = getIntent();
- if(intent != null){
+ if (intent != null) {
uid = intent.getLongExtra("uid", 0);
checkbox1.setChecked(intent.getBooleanExtra("led", false));
- editText1.setText(Byte.toString(intent.getByteExtra("armleft", (byte)0)));
- editText2.setText(Byte.toString(intent.getByteExtra("armright", (byte)0)));
- editText3.setText(Byte.toString(intent.getByteExtra("rotleft", (byte)0)));
- editText4.setText(Byte.toString(intent.getByteExtra("rotright", (byte)0)));
- editText5.setText(Byte.toString(intent.getByteExtra("time", (byte)0)));
+ editText1.setText(Integer.toString(intent.getIntExtra("armleft", 0)));
+ editText2.setText(Integer.toString(intent.getIntExtra("armright", 0)));
+ editText3.setText(Integer.toString(intent.getIntExtra("rotleft", 0)));
+ editText4.setText(Integer.toString(intent.getIntExtra("rotright", 0)));
+ editText5.setText(Integer.toString(intent.getIntExtra("time", 0)));
}
-
+
}
}
View
102 DroidDancerMotionWriter/src/jp/co/kayo/android/droiddancermotionwriter/MainActivity.java
@@ -3,12 +3,16 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import jp.co.kayo.android.droiddancermotionwriter.MotionItem.MotorDir;
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
@@ -17,13 +21,8 @@
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.os.Bundle;
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.util.Log;
import android.view.Menu;
-import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@@ -31,29 +30,36 @@
import android.widget.Button;
import android.widget.ListView;
import android.widget.SeekBar;
-import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.support.v4.app.NavUtils;
+import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG = "DroidDancerMotionWriter";
+
private TextView textView1;
+
private SeekBar seekBar1;
+
private ListView listView1;
+
private MotionListAdapter adapter;
+
private Button button1;
+
private List<MotionItem> items = new ArrayList<MotionItem>();
+
private NfcAdapter nfcadapter;
+
private IntentFilter[] nfcfilters = new IntentFilter[] {
- new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED)
+ new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED)
};
+
private String[][] nfctechLists = new String[][] {
new String[] {
- Ndef.class.getName()
- },
- new String[] {
- NdefFormatable.class.getName()
+ Ndef.class.getName()
+ }, new String[] {
+ NdefFormatable.class.getName()
}
};
@@ -63,10 +69,10 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
nfcadapter = NfcAdapter.getDefaultAdapter(this);
-
- listView1 = (ListView) findViewById(R.id.listView1);
- textView1 = (TextView) findViewById(R.id.textView1);
- seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
+
+ listView1 = (ListView)findViewById(R.id.listView1);
+ textView1 = (TextView)findViewById(R.id.textView1);
+ seekBar1 = (SeekBar)findViewById(R.id.seekBar1);
seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
@@ -83,18 +89,18 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
});
- button1 = (Button) findViewById(R.id.button1);
+ button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MotionItem item = new MotionItem();
item.setLed(false);
- item.setArmleft((byte) 0);
- item.setArmright((byte) 0);
- item.setRotleft((byte) 0);
- item.setRotright((byte) 0);
- item.setTime((byte) 1);
+ item.setArmleft((byte)0);
+ item.setArmright((byte)0);
+ item.setRotleft(MotorDir.STOP);
+ item.setRotright(MotorDir.STOP);
+ item.setTime((byte)1);
items.add(item);
adapter.setData(items);
adapter.notifyDataSetChanged();
@@ -137,11 +143,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
for (MotionItem item : items) {
if (item.getUid() == uid) {
item.setLed(data.getBooleanExtra("led", false));
- item.setArmleft(data.getByteExtra("armleft", (byte) 0));
- item.setArmright(data.getByteExtra("armright", (byte) 0));
- item.setRotleft(data.getByteExtra("rotleft", (byte) 0));
- item.setRotright(data.getByteExtra("rotright", (byte) 0));
- item.setTime(data.getByteExtra("time", (byte) 0));
+ item.setArmleft(data.getIntExtra("armleft", 0));
+ item.setArmright(data.getIntExtra("armright", 0));
+ item.setRotleft(MotorDir.parse(data.getIntExtra("rotleft", 0)));
+ item.setRotright(MotorDir.parse(data.getIntExtra("rotright", 0)));
+ item.setTime(data.getIntExtra("time", 0));
adapter.notifyDataSetChanged();
break;
}
@@ -188,18 +194,16 @@ private void writeNdefMotionTag(Tag tag) {
} finally {
ndef.close();
}
- }
- else if (Arrays.asList(tag.getTechList()).contains(Ndef.class.getName())) {
+ } else if (Arrays.asList(tag.getTechList()).contains(Ndef.class.getName())) {
Ndef ndef = Ndef.get(tag);
try {
if (!ndef.isConnected()) {
ndef.connect();
}
- if(ndef.isWritable()){
+ if (ndef.isWritable()) {
ndef.writeNdefMessage(createNdefMessage());
Toast.makeText(this, "Write Success.", Toast.LENGTH_SHORT).show();
- }
- else{
+ } else {
Toast.makeText(this, "Writing is not supported", Toast.LENGTH_SHORT).show();
}
} finally {
@@ -218,26 +222,30 @@ else if (Arrays.asList(tag.getTechList()).contains(Ndef.class.getName())) {
}
private NdefMessage createNdefMessage() throws IOException {
- byte[] mimeBytes = "application/jp.co.kayo.android.droiddancermotionwriter".getBytes(Charset.forName("US-ASCII"));
+ byte[] mimeBytes = "application/jp.co.kayo.android.droiddancermotionwriter"
+ .getBytes(Charset.forName("US-ASCII"));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] header = new byte[2];
- header[0] = new Integer(seekBar1.getProgress()).byteValue();
- header[1] = new Integer(items.size()).byteValue();
+ header[0] = (byte)(seekBar1.getProgress());
+ header[1] = (byte)(items.size());
bytes.write(header);
- for(MotionItem item : items){
+ for (MotionItem item : items) {
byte[] data = new byte[6];
- data[0] = new Integer(item.isLed()?1:0).byteValue();
- data[1] = new Integer(item.getArmleft()).byteValue();
- data[2] = new Integer(item.getArmright()).byteValue();
- data[3] = new Integer(item.getRotleft()).byteValue();
- data[4] = new Integer(item.getRotright()).byteValue();
- data[5] = new Integer(item.getTime()).byteValue();
+ data[0] = (byte)(item.isLed() ? 1 : 0);
+ data[1] = (byte)(item.getArmleft());
+ data[2] = (byte)(item.getArmright());
+ data[3] = (byte)(item.getRotleft().getIntValue());
+ data[4] = (byte)(item.getRotright().getIntValue());
+ data[5] = (byte)(item.getTime());
bytes.write(data);
}
-
- NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], bytes.toByteArray());
-
- return new NdefMessage(new NdefRecord[]{record});
+
+ NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0],
+ bytes.toByteArray());
+
+ return new NdefMessage(new NdefRecord[] {
+ record
+ });
}
}
View
81 DroidDancerMotionWriter/src/jp/co/kayo/android/droiddancermotionwriter/MotionItem.java
@@ -1,21 +1,52 @@
+
package jp.co.kayo.android.droiddancermotionwriter;
import java.util.Random;
public class MotionItem {
+ public enum MotorDir {
+ STOP(0), FORWARD(1), REVERSE(2);
+
+ private int intValue;
+
+ private MotorDir(int intValue) {
+ this.intValue = intValue;
+ }
+
+ public int getIntValue() {
+ return intValue;
+ }
+
+ public static MotorDir parse(int intValue) {
+ if (intValue < 0) {
+ return REVERSE;
+ } else if (intValue > 0) {
+ return FORWARD;
+ }
+ return STOP;
+ }
+ }
+
private static Random _rand = new Random(System.nanoTime());
+
private long uid;
+
private boolean led;
- private byte armleft;
- private byte armright;
- private byte rotleft;
- private byte rotright;
- private byte time;
-
- public MotionItem(){
+
+ private int armleft;
+
+ private int armright;
+
+ private MotorDir rotleft = MotorDir.STOP;
+
+ private MotorDir rotright = MotorDir.STOP;
+
+ private int time;
+
+ public MotionItem() {
uid = _rand.nextLong();
}
-
+
public long getUid() {
return uid;
}
@@ -27,39 +58,49 @@ public void setUid(long uid) {
public boolean isLed() {
return led;
}
+
public void setLed(boolean led) {
this.led = led;
}
- public byte getArmleft() {
+
+ public int getArmleft() {
return armleft;
}
- public void setArmleft(byte armleft) {
+
+ public void setArmleft(int armleft) {
this.armleft = armleft;
}
- public byte getArmright() {
+
+ public int getArmright() {
return armright;
}
- public void setArmright(byte armright) {
+
+ public void setArmright(int armright) {
this.armright = armright;
}
- public byte getRotleft() {
+
+ public MotorDir getRotleft() {
return rotleft;
}
- public void setRotleft(byte rotleft) {
+
+ public void setRotleft(MotorDir rotleft) {
this.rotleft = rotleft;
}
- public byte getRotright() {
+
+ public MotorDir getRotright() {
return rotright;
}
- public void setRotright(byte rotright) {
+
+ public void setRotright(MotorDir rotright) {
this.rotright = rotright;
}
- public byte getTime() {
+
+ public int getTime() {
return time;
}
- public void setTime(byte time) {
+
+ public void setTime(int time) {
this.time = time;
}
-
-
+
}
View
39 DroidDancerMotionWriter/src/jp/co/kayo/android/droiddancermotionwriter/MotionListAdapter.java
@@ -1,3 +1,4 @@
+
package jp.co.kayo.android.droiddancermotionwriter;
import java.util.List;
@@ -9,16 +10,17 @@
import android.widget.ArrayAdapter;
import android.widget.TextView;
-public class MotionListAdapter extends ArrayAdapter<MotionItem>{
+public class MotionListAdapter extends ArrayAdapter<MotionItem> {
LayoutInflater inflater;
+
public MotionListAdapter(Context context) {
super(context, 0);
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
-
- public void setData(List<MotionItem> items){
+
+ public void setData(List<MotionItem> items) {
clear();
- if(items!=null){
+ if (items != null) {
addAll(items);
}
}
@@ -26,7 +28,7 @@ public void setData(List<MotionItem> items){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
- if(convertView == null){
+ if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item, parent, false);
holder = new ViewHolder();
holder.textView1 = (TextView)convertView.findViewById(R.id.textView1);
@@ -35,31 +37,34 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.textView4 = (TextView)convertView.findViewById(R.id.textView4);
holder.textView5 = (TextView)convertView.findViewById(R.id.textView5);
holder.textView6 = (TextView)convertView.findViewById(R.id.textView6);
-
+
convertView.setTag(holder);
- }
- else{
+ } else {
holder = (ViewHolder)convertView.getTag();
}
MotionItem item = getItem(position);
-
+
holder.textView1.setText(Boolean.toString(item.isLed()));
- holder.textView2.setText(Byte.toString(item.getArmleft()));
- holder.textView3.setText(Byte.toString(item.getArmright()));
- holder.textView4.setText(Byte.toString(item.getRotleft()));
- holder.textView5.setText(Byte.toString(item.getRotright()));
- holder.textView6.setText(Byte.toString(item.getTime()));
-
+ holder.textView2.setText(String.valueOf(item.getArmleft()));
+ holder.textView3.setText(String.valueOf(item.getArmright()));
+ holder.textView4.setText(String.valueOf(item.getRotleft().getIntValue()));
+ holder.textView5.setText(String.valueOf(item.getRotright().getIntValue()));
+ holder.textView6.setText(String.valueOf(item.getTime()));
+
return convertView;
}
-
- private class ViewHolder{
+ private class ViewHolder {
TextView textView1;
+
TextView textView2;
+
TextView textView3;
+
TextView textView4;
+
TextView textView5;
+
TextView textView6;
}
Please sign in to comment.
Something went wrong with that request. Please try again.