Skip to content

Commit

Permalink
Layout and bug fixes
Browse files Browse the repository at this point in the history
Improve layout for display on lower dpi screens:
-Squish things closer together vertically
-Move Game Mode setting under network popup menu
-Move team number display to the TEAM label at the top

Fix crash when trying to join a server by IP
  • Loading branch information
Dees-Troy committed Feb 15, 2018
1 parent 32feb13 commit 7830add
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.simplecoil.simplecoil"
minSdkVersion 21
targetSdkVersion 26
versionCode 7
versionName "1.6"
versionCode 8
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
36 changes: 15 additions & 21 deletions app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
Expand All @@ -99,8 +98,6 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import javax.microedition.khronos.opengles.GL;

/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
Expand All @@ -120,7 +117,6 @@ public class FullscreenActivity extends AppCompatActivity implements PopupMenu.O
private Button mEndGameButton = null;
private Button mEndNetworkGameButton = null;
private Button mPlayerDataButton = null;
private Button mGameModeButton = null;
private ImageView mNetworkStatusIV = null;
private TextView mNetworkPlayerCountTV = null;
private TextView mScoreTV = null;
Expand All @@ -136,6 +132,7 @@ public class FullscreenActivity extends AppCompatActivity implements PopupMenu.O
private TextView mShotsRemainingTV = null;
private TextView mRecoilModeTV = null;
private TextView mHitsTakenTV = null;
private TextView mTeamLabelTV = null;
private TextView mTeamTV = null;
private TextView mShotModeTV = null;
private TextView mEliminatedTV = null;
Expand Down Expand Up @@ -509,6 +506,7 @@ public void onClick(View v) {
mShotsRemainingLabelTV = findViewById(R.id.shots_label_tv);
mShotsRemainingTV = findViewById(R.id.shots_remaining_tv);
mHitsTakenTV = findViewById(R.id.hits_taken_tv);
mTeamLabelTV = findViewById(R.id.team_label_tv);
mTeamTV = findViewById(R.id.team_tv);
mRecoilModeTV = findViewById(R.id.recoil_tv);
mShotModeTV = findViewById(R.id.shot_mode_tv);
Expand Down Expand Up @@ -601,18 +599,6 @@ public void onClick(View v) {
}
}));
}
mGameModeButton = findViewById(R.id.game_mode_toggle_button);
if (mGameModeButton != null) {
mGameModeButton.setOnClickListener((new View.OnClickListener() {
public void onClick(View v) {
PopupMenu popup = new PopupMenu(FullscreenActivity.this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.game_mode_menu, popup.getMenu());
popup.setOnMenuItemClickListener(FullscreenActivity.this);
popup.show();
}
}));
}
mGameModeLabelTV = findViewById(R.id.game_mode_label_tv);
mGameModeTV = findViewById(R.id.game_mode_tv);
mScoreLabelTV = findViewById(R.id.score_label_tv);
Expand Down Expand Up @@ -674,7 +660,8 @@ private void setNetworkMenu(int networkMenuType) {
mNetworkPopup.getMenu().add(0, R.id.join_ip_item, 30, R.string.join_ip_button);
mNetworkPopup.getMenu().add(0, R.id.create_server_item, 40, R.string.create_server_button);
mNetworkPopup.getMenu().add(0, R.id.player_name_item, 50, getString(R.string.player_name_button, Globals.getInstance().mPlayerName));
mNetworkPopup.getMenu().add(0, R.id.disable_network_item, 60, R.string.no_network_button);
mNetworkPopup.getMenu().add(0, R.id.game_mode_item, 60, R.string.game_mode_toggle_button);
mNetworkPopup.getMenu().add(0, R.id.disable_network_item, 70, R.string.no_network_button);
return;
case NETWORK_TYPE_JOINING:
mNetworkPopup.getMenu().add(0, R.id.please_wait_item, 1, R.string.please_wait);
Expand All @@ -695,6 +682,7 @@ public boolean onMenuItemClick(MenuItem item) {
displayAllNetworkingOptions(false);
mUseNetwork = false;
mUseNetworkingButton.setText(R.string.use_network_button);
setTeam();
return true;
case R.id.join_item:
if (Globals.getInstance().mPlayerID == 0) {
Expand Down Expand Up @@ -725,6 +713,13 @@ public boolean onMenuItemClick(MenuItem item) {
case R.id.player_name_item:
requestPlayerName();
return true;
case R.id.game_mode_item:
PopupMenu popup = new PopupMenu(FullscreenActivity.this, mUseNetworkingButton);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.game_mode_menu, popup.getMenu());
popup.setOnMenuItemClickListener(FullscreenActivity.this);
popup.show();
return true;
case R.id.please_wait_item:
return true;
case R.id.cancel_server_item:
Expand Down Expand Up @@ -1034,7 +1029,6 @@ private void setReady(boolean sendPlayerLeft) {
}
mTeamMinusButton.setVisibility(View.INVISIBLE);
mTeamPlusButton.setVisibility(View.INVISIBLE);
mGameModeButton.setVisibility(View.GONE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mGameLimitButton.setVisibility(View.GONE);
} else {
Expand All @@ -1051,7 +1045,6 @@ private void setReady(boolean sendPlayerLeft) {
mTeamMinusButton.setVisibility(View.VISIBLE);
mTeamPlusButton.setVisibility(View.VISIBLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mGameModeButton.setVisibility(View.VISIBLE);
mServerIPTV.setVisibility(View.GONE);
mGameLimitButton.setVisibility(View.VISIBLE);
setNetworkMenu(NETWORK_TYPE_ENABLED);
Expand Down Expand Up @@ -1241,10 +1234,12 @@ else if (Globals.getInstance().mPlayerID > x)
mNetworkTeam = 2;
}
int player = (Globals.getInstance().mPlayerID - (byte)(x * (mNetworkTeam - 1)));
mTeamTV.setText(getString(R.string.network_team, mNetworkTeam, player));
mTeamLabelTV.setText(getString(R.string.team_number_label, mNetworkTeam));
mTeamTV.setText(getString(R.string.network_team, player));
mTeamScoreLabelTV.setVisibility(View.VISIBLE);
mTeamScoreTV.setVisibility(View.VISIBLE);
} else {
mTeamLabelTV.setText(R.string.team_label);
String teamStr = "" + Globals.getInstance().mPlayerID;
mTeamTV.setText(teamStr);
mTeamScoreLabelTV.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -2339,7 +2334,6 @@ private static IntentFilter makeUDPUpdateIntentFilter() {

private void displayAllNetworkingOptions(boolean enabled) {
int visibility = enabled ? View.VISIBLE : View.INVISIBLE;
mGameModeButton.setVisibility(visibility);
mGameModeLabelTV.setVisibility(visibility);
mGameModeTV.setVisibility(visibility);
mScoreLabelTV.setVisibility(visibility);
Expand Down
43 changes: 25 additions & 18 deletions app/src/main/java/com/simplecoil/simplecoil/UDPListenerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;

import javax.microedition.khronos.opengles.GL;
Expand Down Expand Up @@ -370,26 +372,31 @@ public void joinServer(InetAddress serverIP, Integer port) {
}

private void joinFailCheck(final InetAddress serverIP, final Integer port) {
new CountDownTimer(2000, 500) {

public void onTick(long millisUntilFinished) {
if (mScanRunning) {
Log.d(TAG, "Sending join request");
sendUDPMessage(NetMsg.MESSAGE_PREFIX + NetMsg.NETMSG_JOIN + NetMsg.NETWORK_VERSION + Globals.getInstance().mPlayerID, serverIP, port);
} else {
this.cancel();
}
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
new CountDownTimer(2000, 500) { // We send 3 join requests over 2 seconds and quit if we don't get connected

public void onTick(long millisUntilFinished) {
if (mScanRunning) {
Log.d(TAG, "Sending join request");
sendUDPMessage(NetMsg.MESSAGE_PREFIX + NetMsg.NETMSG_JOIN + NetMsg.NETWORK_VERSION + Globals.getInstance().mPlayerID, serverIP, port);
} else {
this.cancel();
}
}

public void onFinish() {
if (mScanRunning) {
Log.d(TAG, "join failed, could not find a server");
mScanRunning = false;
keepListening = false;
sendFailedJoin();
}
public void onFinish() {
if (mScanRunning) {
Log.d(TAG, "join failed, could not find a server");
mScanRunning = false;
keepListening = false;
sendFailedJoin();
}
}
}.start();
}
}.start();
});
}

private void sendFailedJoin() {
Expand Down
46 changes: 18 additions & 28 deletions app/src/main/res/layout/activity_fullscreen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="30dp"
android:text="0"
android:textAppearance="@android:style/TextAppearance.Material.Large.Inverse" />
Expand All @@ -132,7 +132,7 @@
android:id="@+id/team_label_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:text="@string/team_label"
android:textAppearance="@android:style/TextAppearance.Material.Small.Inverse" />
Expand All @@ -142,7 +142,7 @@
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginTop="35dp"
android:layout_marginStart="15dp"
android:visibility="invisible"
android:text="-" />
Expand All @@ -152,7 +152,7 @@
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginTop="35dp"
android:layout_marginEnd="15dp"
android:layout_alignParentEnd="true"
android:visibility="invisible"
Expand All @@ -163,7 +163,7 @@
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginTop="35dp"
android:layout_marginStart="15dp"
android:visibility="gone"
android:text="@string/scoreboard_button" />
Expand All @@ -172,7 +172,7 @@
android:id="@+id/team_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:text="@string/no_team"
android:textAppearance="@android:style/TextAppearance.Material.Large.Inverse" />
Expand All @@ -182,7 +182,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/team_tv"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:layout_marginStart="15dp"
android:text="@string/shots_remaining_label"
android:textAppearance="@android:style/TextAppearance.Material.Small.Inverse" />
Expand Down Expand Up @@ -211,7 +211,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/team_tv"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:text="@string/recoil_label"
android:textAppearance="@android:style/TextAppearance.Material.Small.Inverse" />
Expand All @@ -231,7 +231,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/team_tv"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_alignParentEnd="true"
android:text="@string/shot_mode_label"
Expand Down Expand Up @@ -264,7 +264,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/shot_mode_tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:layout_marginTop="5dp"
android:text="@string/health_label"
android:textAppearance="@android:style/TextAppearance.Material.Small.Inverse" />

Expand All @@ -275,7 +275,7 @@
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_below="@+id/health_label_tv"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:minHeight="20dip"
android:maxHeight="20dip"
style="@android:style/Widget.ProgressBar.Horizontal"
Expand Down Expand Up @@ -326,7 +326,7 @@
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginTop="7dp"
android:layout_marginStart="15dp"
android:layout_below="@id/health_pb"
android:text="@string/start_game_button" />
Expand All @@ -336,7 +336,7 @@
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="15dp"
android:layout_alignParentEnd="true"
android:layout_below="@id/health_pb"
Expand All @@ -360,7 +360,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/start_game_button"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:text="@string/use_network_button" />

<TextView
Expand All @@ -380,7 +380,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/use_network_button"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:text="@string/firing_mode_outdoor_no_cone" />

<TextView
Expand All @@ -397,21 +397,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:text="@string/game_mode_2teams"
android:textAppearance="@android:style/TextAppearance.Material.Large.Inverse" />

<Button
android:id="@+id/game_mode_toggle_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_centerHorizontal="true"
android:layout_above="@id/game_mode_label_tv"
android:text="@string/game_mode_toggle_button" />

<Button
android:id="@+id/game_limit_button"
style="@style/Widget.AppCompat.Button.Colored"
Expand All @@ -438,7 +428,7 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="15dp"
android:layout_marginBottom="20dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="true"
android:text="0"
android:textAppearance="@android:style/TextAppearance.Material.Large.Inverse" />
Expand All @@ -459,7 +449,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginBottom="20dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="true"
android:layout_above="@id/score_label_tv"
android:text="0"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/menu/network_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
android:title="@string/create_server_button" />
<item android:id="@+id/player_name_item"
android:title="@string/player_name_button" />
<item android:id="@+id/game_mode_item"
android:title="@string/game_mode_toggle_button" />
<item android:id="@+id/please_wait_item"
android:title="@string/please_wait" />
<item android:id="@+id/leave_item"
Expand Down
Loading

0 comments on commit 7830add

Please sign in to comment.