Commit 5a0202b2 authored by leslie0216's avatar leslie0216
Browse files

-disable log

-add color selector
parent c76c7886
......@@ -4,22 +4,70 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import java.util.HashMap;
import java.util.Locale;
public class LoginActivity extends Activity {
private static final HashMap<String, Integer> m_ColorNameMap;
static {
m_ColorNameMap = new HashMap<>();
m_ColorNameMap.put("black", Color.BLACK);
m_ColorNameMap.put("darkgray", Color.DKGRAY);
m_ColorNameMap.put("gray", Color.GRAY);
m_ColorNameMap.put("lightgray", Color.LTGRAY);
m_ColorNameMap.put("white", Color.WHITE);
m_ColorNameMap.put("red", Color.RED);
m_ColorNameMap.put("green", Color.GREEN);
m_ColorNameMap.put("blue", Color.BLUE);
m_ColorNameMap.put("yellow", Color.YELLOW);
m_ColorNameMap.put("cyan", Color.CYAN);
m_ColorNameMap.put("magenta", Color.MAGENTA);
m_ColorNameMap.put("aqua", 0xFF00FFFF);
m_ColorNameMap.put("fuchsia", 0xFFFF00FF);
m_ColorNameMap.put("darkgrey", Color.DKGRAY);
m_ColorNameMap.put("grey", Color.GRAY);
m_ColorNameMap.put("lightgrey", Color.LTGRAY);
m_ColorNameMap.put("lime", 0xFF00FF00);
m_ColorNameMap.put("maroon", 0xFF800000);
m_ColorNameMap.put("navy", 0xFF000080);
m_ColorNameMap.put("olive", 0xFF808000);
m_ColorNameMap.put("purple", 0xFF800080);
m_ColorNameMap.put("silver", 0xFFC0C0C0);
m_ColorNameMap.put("teal", 0xFF008080);
}
private static final String[] Colors = {"Black", "DarkGrey", "Grey", "LightGrey", "White", "Red", "Green", "Blue", "Yellow", "Cyan", "Magenta", "Aqua", "Fuchsia", "Lime", "Maroon", "Navy", "Olive", "Purple", "Silver", "Teal"};
private TextView m_spinnerTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
m_spinnerTextView = (TextView)findViewById(R.id.txt_color);
Spinner spinner = (Spinner) findViewById(R.id.spinner_color);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, Colors);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new SpinnerSelectedListener());
spinner.setVisibility(View.VISIBLE);
Button btnPrev=(Button)this.findViewById(R.id.btn_go);
btnPrev.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -32,6 +80,7 @@ public class LoginActivity extends Activity {
Bundle bundle = new Bundle();
bundle.putString("user", user);
bundle.putString("id", id);
bundle.putInt("color", m_spinnerTextView.getCurrentTextColor());
intent.putExtras(bundle);
LoginActivity.this.startActivity(intent);
LoginActivity.this.finish();
......@@ -40,6 +89,19 @@ public class LoginActivity extends Activity {
});
}
class SpinnerSelectedListener implements AdapterView.OnItemSelectedListener {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String color = Colors[arg2];
m_spinnerTextView.setText("Color : "+color);
m_spinnerTextView.setTextColor(m_ColorNameMap.get(color.toLowerCase(Locale.ROOT)));
}
public void onNothingSelected(AdapterView<?> arg0) {
}
}
public String getUserName() {
TextView user = (TextView)this.findViewById(R.id.txt_userName);
return user.getText().toString();
......
......@@ -34,6 +34,7 @@ import java.util.UUID;
public class MainActivity extends Activity {
private String m_userName;
private String m_userId;
private int m_userColor;
/** BT begin
*/
private ClientThread m_clientThread = null;
......@@ -89,8 +90,15 @@ public class MainActivity extends Activity {
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
m_userName = bundle.getString("user");
m_userId = bundle.getString("id");
if (bundle.containsKey("user")) {
m_userName = bundle.getString("user");
}
if (bundle.containsKey("id")) {
m_userId = bundle.getString("id");
}
if (bundle.containsKey("color")) {
m_userColor = bundle.getInt("color");
}
setTitle(m_userId + " : " + m_userName + " - " + getResources().getString(R.string.app_name));
......@@ -362,6 +370,8 @@ public class MainActivity extends Activity {
return m_userId;
}
public int getUserColor() {return m_userColor;}
private class ConnectedThread extends Thread {
public ConnectedThread() {
try {
......
......@@ -27,7 +27,7 @@ public class MainView extends View {
private String m_id;
private String m_name;
private int m_color;
private static final int m_messageTextSize = 50;
private static final int m_messageTextSize = 70;
private static final int m_textStrokeWidth = 2;
private static final int m_boundaryStrokeWidth = 10;
......@@ -125,8 +125,9 @@ public class MainView extends View {
m_message = "No Message";
m_id = ((MainActivity)(context)).getUserId();
m_name = ((MainActivity)(context)).getUserName();
Random rnd = new Random();
m_color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
//Random rnd = new Random();
//m_color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
m_color = ((MainActivity)(context)).getUserColor();
m_touchedBallId = -1;
m_balls = new ArrayList<>();
......@@ -202,7 +203,7 @@ public class MainView extends View {
showMessage(canvas);
showRemotePhones(canvas);
showBalls(canvas);
showProgress(canvas);
//showProgress(canvas);
}
public void showBoundary(Canvas canvas) {
......@@ -240,7 +241,7 @@ public class MainView extends View {
canvas.drawText(remotePhoneInfo.m_name, textX, textY, m_paint);
}
m_paint.setStrokeWidth(8);
m_paint.setStrokeWidth(12);
m_paint.setStyle(Paint.Style.STROKE);
canvas.drawCircle(remotePhoneInfo.m_wormholeInfo.m_x, remotePhoneInfo.m_wormholeInfo.m_y, remotePhoneInfo.m_wormholeInfo.m_radius, m_paint);
}
......@@ -257,6 +258,7 @@ public class MainView extends View {
* experiment begin
*/
m_paint.setStrokeWidth(m_textStrokeWidth);
m_paint.setTextSize(m_messageTextSize);
float textX = ball.m_ballX - m_ballRadius;
float textY = ball.m_ballY - m_ballRadius;
if (ball.m_name.length() > 5) {
......@@ -428,7 +430,7 @@ public class MainView extends View {
}
if (show) {
handler.postDelayed(mLongPressed, 1000);
handler.postDelayed(mLongPressed, 500);
}
} else {
m_numberOfTouchBall++;
......@@ -680,9 +682,10 @@ public class MainView extends View {
resetBlock();
m_logger = new MainLogger(getContext(), m_id+"_"+m_name+"_"+getResources().getString(R.string.app_name));
m_logger = null;
//m_logger = new MainLogger(getContext(), m_id+"_"+m_name+"_"+getResources().getString(R.string.app_name));
//<participantID> <participantName> <condition> <block#> <trial#> <receiver name> <elapsed time for this trial> <number of errors for this trial> <number of release for this trial> <number of drops for this trial> <number of touch for this trial> <number of touch ball for this trial> <number of long press for this trial> <timestamp>
m_logger.writeHeaders("participantID" + "," + "participantName" + "," + "condition" + "," + "block" + "," + "trial" + "," + "receiverName" + "," + "elapsedTime" + "," + "errors" + "," + "release" + "," + "drops" + "," + "touch" + "," + "touchBall" + "," + "longPress" + "," + "timestamp");
//m_logger.writeHeaders("participantID" + "," + "participantName" + "," + "condition" + "," + "block" + "," + "trial" + "," + "receiverName" + "," + "elapsedTime" + "," + "errors" + "," + "release" + "," + "drops" + "," + "touch" + "," + "touchBall" + "," + "longPress" + "," + "timestamp");
((MainActivity)getContext()).runOnUiThread(new Runnable() {
@Override
......@@ -780,7 +783,7 @@ public class MainView extends View {
}
// reset self color
m_color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
//m_color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
resetCounters();
}
......@@ -829,7 +832,7 @@ public class MainView extends View {
//<participantID> <participantName> <condition> <block#> <trial#> <receiver name> <elapsed time for this trial> <number of errors for this trial> <number of release for this trial> <number of drops for this trial> <number of touch for this trial> <number of touch ball for this trial> <number of long press for this trial> <timestamp>
if (m_logger != null) {
m_logger.write(m_id + "," + m_name + "," + getResources().getString(R.string.app_name) + "," + m_currentBlock + "," + m_currentTrail + "," + m_receiverName + "," + timeElapse + "," + m_numberOfErrors + "," + m_numberOfRelease + "," + m_numberOfDrops + "," + m_numberOfTouch + "," + m_numberOfTouchBall + "," + m_numberOfLongPress + "," + trailEndTime, true);
//m_logger.write(m_id + "," + m_name + "," + getResources().getString(R.string.app_name) + "," + m_currentBlock + "," + m_currentTrail + "," + m_receiverName + "," + timeElapse + "," + m_numberOfErrors + "," + m_numberOfRelease + "," + m_numberOfDrops + "," + m_numberOfTouch + "," + m_numberOfTouchBall + "," + m_numberOfLongPress + "," + trailEndTime, true);
}
if (m_currentTrail < m_maxTrails) {
......
......@@ -61,6 +61,24 @@
android:maxLength="10">
</EditText>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="#C0C0C0"/>
<TextView android:id="@+id/txt_color"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"/>
<Spinner android:id="@+id/spinner_color"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"/>
<Button
android:id="@+id/btn_go"
android:layout_width="fill_parent"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment