Integrated Crashlytics and replaced keyboard input with on-screen buttons for input

This commit is contained in:
William Brawner 2017-07-28 17:16:32 -05:00
parent 205548e89c
commit 82006e9e09
9 changed files with 345 additions and 26 deletions

View file

@ -1,4 +1,19 @@
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android { android {
compileSdkVersion 25 compileSdkVersion 25
@ -27,4 +42,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1' compile 'com.android.support:support-v4:25.1.1'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
transitive = true;
}
} }

View file

@ -15,6 +15,10 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="c98817787b84dc58d2227919559a45a537529aa3" />
</application> </application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest> </manifest>

View file

@ -15,6 +15,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.Map; import java.util.Map;
@ -22,7 +23,7 @@ import java.util.Map;
public class GameFragment extends Fragment { public class GameFragment extends Fragment {
private EditText guessInput; private TextView guessInput;
private Button guessButton; private Button guessButton;
private Player user; private Player user;
private NumberGuess ng; private NumberGuess ng;
@ -50,7 +51,40 @@ public class GameFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_game, container, false); View rootView = inflater.inflate(R.layout.fragment_game, container, false);
guessInput = (EditText) rootView.findViewById(R.id.guessInput); guessInput = (TextView) rootView.findViewById(R.id.guessInput);
for (int i = 0; i <= 9; i++) {
int buttonId = getActivity().getResources().getIdentifier(
"button_" + i,
"id",
getActivity().getPackageName()
);
final Button inputBtn = (Button) rootView.findViewById(buttonId);
inputBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (guessInput.length() < 3)
guessInput.append(inputBtn.getText());
}
});
}
((Button) rootView.findViewById(R.id.button_clear)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
guessInput.setText("");
}
});
((Button) rootView.findViewById(R.id.button_delete)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (guessInput.getText().length() > 0)
guessInput.setText(
guessInput.getText().toString().substring(
0,
guessInput.getText().length() - 1
)
);
}
});
guessButton = (Button) rootView.findViewById(R.id.guessButton); guessButton = (Button) rootView.findViewById(R.id.guessButton);
guessButton.setOnClickListener(new View.OnClickListener() { guessButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -85,7 +119,6 @@ public class GameFragment extends Fragment {
public void resetGame() { public void resetGame() {
guessInput.setText("50"); guessInput.setText("50");
guessInput.setSelection(2);
user = null; user = null;
ng = null; ng = null;

View file

@ -3,6 +3,8 @@ package com.wbrawner.numberguess;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements GameOverDialogFragment.GameOverListener { implements GameOverDialogFragment.GameOverListener {
@ -12,6 +14,7 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
if (savedInstanceState == null) { if (savedInstanceState == null) {

View file

@ -0,0 +1,152 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:id="@+id/fragment_game"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.wbrawner.numberguess.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/guess_prompt"
android:textAlignment="center"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:layout_marginBottom="50dp"
android:id="@+id/guessPrompt" />
<TextView
android:id="@+id/guessInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="3"
android:textSize="40sp"
android:text="50"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="0dp"
android:orientation="horizontal">
<Button
android:id="@+id/button_1"
style="@style/inputButton"
android:text="1" />
<Button
android:id="@+id/button_2"
style="@style/inputButton"
android:text="2" />
<Button
android:id="@+id/button_3"
style="@style/inputButton"
android:text="3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_4"
style="@style/inputButton"
android:text="4" />
<Button
android:id="@+id/button_5"
style="@style/inputButton"
android:text="5" />
<Button
android:id="@+id/button_6"
style="@style/inputButton"
android:text="6" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_7"
style="@style/inputButton"
android:text="7" />
<Button
android:id="@+id/button_8"
style="@style/inputButton"
android:text="8" />
<Button
android:id="@+id/button_9"
style="@style/inputButton"
android:text="9" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_clear"
style="@style/inputButton"
android:text="CE" />
<Button
android:id="@+id/button_0"
style="@style/inputButton"
android:text="0" />
<Button
android:id="@+id/button_delete"
style="@style/inputButton"
android:text="Del" />
</LinearLayout>
<Button
android:id="@+id/guessButton"
style="@style/inputButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:padding="0dp"
android:text="@string/guess_button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -1,5 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/fragment_game" android:id="@+id/fragment_game"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -15,6 +16,7 @@
android:text="@string/guess_prompt" android:text="@string/guess_prompt"
android:textAlignment="center" android:textAlignment="center"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:textSize="20sp"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
@ -22,36 +24,133 @@
<LinearLayout <LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_below="@id/guessPrompt" android:layout_below="@id/guessPrompt"
android:layout_marginTop="50dp" android:layout_marginTop="50dp"
android:weightSum="10"> android:orientation="vertical">
<EditText <TextView
android:imeOptions="flagNoExtractUi"
android:layout_weight="5"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="number"
android:maxLength="3"
android:id="@+id/guessInput" android:id="@+id/guessInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:textAlignment="center" android:imeOptions="flagNoExtractUi"
android:text="50" /> android:maxLength="3"
android:textSize="20sp"
android:text="50"
android:textAlignment="center" />
<Button <LinearLayout
android:layout_width="wrap_content" android:layout_width="300dp"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="5" android:layout_gravity="center"
android:id="@+id/guessButton" android:gravity="center"
android:text="@string/guess_button" /> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="0dp"
android:orientation="horizontal">
<Button
android:id="@+id/button_1"
style="@style/inputButton"
android:text="1" />
<Button
android:id="@+id/button_2"
style="@style/inputButton"
android:text="2" />
<Button
android:id="@+id/button_3"
style="@style/inputButton"
android:text="3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_4"
style="@style/inputButton"
android:text="4" />
<Button
android:id="@+id/button_5"
style="@style/inputButton"
android:text="5" />
<Button
android:id="@+id/button_6"
style="@style/inputButton"
android:text="6" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_7"
style="@style/inputButton"
android:text="7" />
<Button
android:id="@+id/button_8"
style="@style/inputButton"
android:text="8" />
<Button
android:id="@+id/button_9"
style="@style/inputButton"
android:text="9" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_clear"
style="@style/inputButton"
android:text="CE" />
<Button
android:id="@+id/button_0"
style="@style/inputButton"
android:text="0" />
<Button
android:id="@+id/button_delete"
style="@style/inputButton"
android:text="Del" />
</LinearLayout>
<Button
android:id="@+id/guessButton"
style="@style/inputButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/button_0"
android:layout_weight="0"
android:background="@color/colorAccent"
android:padding="0dp"
android:text="@string/guess_button" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</RelativeLayout> </LinearLayout>

View file

@ -8,4 +8,14 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="inputButton">
<item name="android:background">@android:color/transparent</item>
<item name="android:textSize">20sp</item>
<item name="android:layout_height">50dp</item>
<item name="android:layout_width">100dp</item>
<item name="android:layout_weight">2</item>
<item name="android:layout_margin">0dp</item>
<item name="android:padding">0dp</item>
</style>
</resources> </resources>

View file

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015 #Fri Apr 28 15:04:17 PDT 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip