Skip to content

Commit

Permalink
switch users
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Gravener committed May 19, 2012
1 parent 3799737 commit caa8367
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
4 changes: 2 additions & 2 deletions res/layout/main.xml
Expand Up @@ -444,7 +444,7 @@
android:id="@+id/choose_category_round"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" >
android:visibility="gone" >

<RelativeLayout
android:id="@+id/header_container"
Expand Down Expand Up @@ -480,7 +480,7 @@
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/timer"
android:layout_toLeftOf="@+id/category_timer"
android:layout_toRightOf="@id/info"
android:indeterminate="false"
android:max="60000"
Expand Down
2 changes: 1 addition & 1 deletion res/raw/rounds.txt
Expand Up @@ -8,4 +8,4 @@ Presidential
STDs
Games
Playstation
Food
Food
1 change: 1 addition & 0 deletions res/values/settings.xml
Expand Up @@ -5,6 +5,7 @@
<item name="secondsPerRound" type="integer">5</item>
<item name="secondsPerVotingRound" type="integer">10</item>
<item name="secondsPerResultsRound" type="integer">10</item>
<item name="secondsPerChooseCategoryRound" type="integer">10</item>
<string name="serverUrl">ws://192.168.43.200:8080/websocket</string>
<string name="facebookAppId">135742016560988</string>
<string name="facebookAppSecret">ee70cce63d156cbf177721b1412e5a31</string>
Expand Down
87 changes: 79 additions & 8 deletions src/com/happytap/acro/AcroActivity.java
Expand Up @@ -24,6 +24,7 @@
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
Expand Down Expand Up @@ -126,7 +127,14 @@ public void run() {
ProgressBar _progress;

View _chooseCategoryRound;


ProgressBar _chooseCategoryProgress;

Future<?> _chooseCategoryFuture;

TextView _chooseCategoryTimer;


Runnable _requestRoomList = new Runnable() {
public void run() {
try {
Expand All @@ -141,6 +149,10 @@ public void run() {

ListView _rooms;

ListView _categories;

ArrayAdapter<String> _categoryAdapter;

Runnable _roundUiRunnable = new Runnable() {
public void run() {
int k = (int) Math.ceil(_config.getSecondsPerRound()
Expand Down Expand Up @@ -242,6 +254,22 @@ public void run() {
}

};

Runnable _chooseCategoryRoundRunnable = new Runnable() {

@Override
public void run() {
int newProgress = _chooseCategoryProgress.getProgress() + 100;
_chooseCategoryProgress.setProgress(newProgress);
int k = (int) Math.ceil(_config.getSecondsPerChooseCategory()
- newProgress / 1000d);
if (k == 0) {
_chooseCategoryFuture.cancel(true);
}
runOnUiThread(_chooseCategoryUiRunnable);
}

};

Future<?> _resultsRoundRunnableFuture;

Expand Down Expand Up @@ -277,7 +305,25 @@ private void onResultsRoundOver() {

};
};

Runnable _chooseCategoryUiRunnable = new Runnable() {
public void run() {

int k = (int) Math.ceil(_config.getSecondsPerChooseCategory()
- _chooseCategoryProgress.getProgress() / 1000d);
_chooseCategoryTimer.setText(String.valueOf(k));
if (k == 0) {
onChooseCategoryRoundOver();
}
}


};

private void onChooseCategoryRoundOver() {
// TODO Auto-generated method stub

}
InputMethodManager imm;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -328,6 +374,13 @@ public void onClick(View v) {
t.setGravity(Gravity.CENTER);
_chat.addView(t, lp);
}
if(showUsers) {
//switch to chat
_chatList.setAdapter(null);
} else {
//switch to users
_chatList.setAdapter(null);
}
_chat.invalidate();
} else {
startConnectionToServer();
Expand All @@ -336,6 +389,7 @@ public void onClick(View v) {

@Override
public void onConnected() {
//runOnUiThread(_onChatRoundRunnable);
runOnUiThread(_onUiJoinRoomRunnable);
//runOnUiThread(_joinRoomRound);
//startJoinRoomRound();
Expand Down Expand Up @@ -380,7 +434,10 @@ public void onCreate(Bundle savedInstanceState) {
_resultsProgress = findView(R.id.results_progress_bar);
_resultsText = findView(R.id.results_timer);
_chooseCategoryRound = findView(R.id.choose_category_round);

_chooseCategoryProgress = findView(R.id.category_progress_bar);
_chooseCategoryProgress.setMax(_config.getSecondsPerChooseCategory() * 1000);
_chooseCategoryTimer = findView(R.id.category_timer);
_categories = findView(R.id.categories);
// two = findView(R.id.two);

// three = findView(R.id.three);
Expand All @@ -397,9 +454,10 @@ public void onCreate(Bundle savedInstanceState) {
//startSentenceRound();
// startConnectionToServer();
// startJoinRoomRound();
startSentenceRound();
//startSentenceRound();
// startJoinRoomRound();
// startLoginRound();
//startChooseCategoryRound();

}

Expand Down Expand Up @@ -532,12 +590,9 @@ private void requestRoomList() {
}

private void startChatRound() {
hideAllViews();
_chatRound.setVisibility(View.VISIBLE);
_joinRoomRound.setVisibility(View.GONE);
_rooms.setVisibility(View.GONE);
_votingRound.setVisibility(View.GONE);
_socketDroppedRound.setVisibility(View.GONE);
_sentenceRound.setVisibility(View.GONE);
_root.invalidate();
}

private void startConnectionToServer() {
Expand All @@ -556,6 +611,19 @@ private void startJoinRoomRound() {
_rooms.setOnItemClickListener(this);
}

private void startChooseCategoryRound() {
hideAllViews();
String[] cats = getResources().getStringArray(R.array.rounds);

_chooseCategoryRound.setVisibility(View.VISIBLE);
_root.invalidate();
_chooseCategoryProgress.setProgress(0);
_chooseCategoryTimer.setText(String.valueOf(_config.getSecondsPerRound()));
_chooseCategoryFuture = ThreadHelper.getScheduler()
.scheduleAtFixedRate(_chooseCategoryRoundRunnable, 0, 100,
TimeUnit.MILLISECONDS);
}

private void startSentenceRound() {
hideAllViews();
_sentenceRound.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -602,6 +670,9 @@ private void killAllTasks() {
if (_votingRoundRunnableFuture != null) {
_votingRoundRunnableFuture.cancel(true);
}
if(_chooseCategoryFuture!=null) {
_chooseCategoryFuture.cancel(true);
}
}

private void startVotingRound() {
Expand Down
4 changes: 4 additions & 0 deletions src/com/happytap/acro/Configuration.java
Expand Up @@ -24,6 +24,10 @@ public boolean isTest() {
public int getSecondsPerRound() {
return ctx.getResources().getInteger(R.integer.secondsPerRound);
}

public int getSecondsPerChooseCategory() {
return ctx.getResources().getInteger(R.integer.secondsPerChooseCategoryRound);
}

public int getSecondsPerVotingRound() {
return ctx.getResources().getInteger(R.integer.secondsPerVotingRound);
Expand Down

0 comments on commit caa8367

Please sign in to comment.