From 82006e9e09903350b9f9fd1ea5509f2701583543 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Fri, 28 Jul 2017 17:16:32 -0500 Subject: [PATCH] Integrated Crashlytics and replaced keyboard input with on-screen buttons for input --- app/build.gradle | 18 +++ app/src/main/AndroidManifest.xml | 4 + .../wbrawner/numberguess/GameFragment.java | 39 ++++- .../wbrawner/numberguess/MainActivity.java | 3 + .../main/res/layout-land/fragment_game.xml | 152 ++++++++++++++++++ app/src/main/res/layout/fragment_game.xml | 139 +++++++++++++--- app/src/main/res/values/styles.xml | 10 ++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 9 files changed, 345 insertions(+), 26 deletions(-) create mode 100644 app/src/main/res/layout-land/fragment_game.xml diff --git a/app/build.gradle b/app/build.gradle index 3e23cd2..edf9d01 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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: 'io.fabric' + +repositories { + maven { url 'https://maven.fabric.io/public' } +} + android { compileSdkVersion 25 @@ -27,4 +42,7 @@ dependencies { compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.android.support:support-v4:25.1.1' testCompile 'junit:junit:4.12' + compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') { + transitive = true; + } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ad5c6bf..2e18459 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,6 +15,10 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/wbrawner/numberguess/GameFragment.java b/app/src/main/java/com/wbrawner/numberguess/GameFragment.java index 4c29ba4..f3ef24f 100644 --- a/app/src/main/java/com/wbrawner/numberguess/GameFragment.java +++ b/app/src/main/java/com/wbrawner/numberguess/GameFragment.java @@ -15,6 +15,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; import android.widget.Toast; import java.util.Map; @@ -22,7 +23,7 @@ import java.util.Map; public class GameFragment extends Fragment { - private EditText guessInput; + private TextView guessInput; private Button guessButton; private Player user; private NumberGuess ng; @@ -50,7 +51,40 @@ public class GameFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 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.setOnClickListener(new View.OnClickListener() { @Override @@ -85,7 +119,6 @@ public class GameFragment extends Fragment { public void resetGame() { guessInput.setText("50"); - guessInput.setSelection(2); user = null; ng = null; diff --git a/app/src/main/java/com/wbrawner/numberguess/MainActivity.java b/app/src/main/java/com/wbrawner/numberguess/MainActivity.java index a937f3c..6e7c1ac 100644 --- a/app/src/main/java/com/wbrawner/numberguess/MainActivity.java +++ b/app/src/main/java/com/wbrawner/numberguess/MainActivity.java @@ -3,6 +3,8 @@ package com.wbrawner.numberguess; import android.app.DialogFragment; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import com.crashlytics.android.Crashlytics; +import io.fabric.sdk.android.Fabric; public class MainActivity extends AppCompatActivity implements GameOverDialogFragment.GameOverListener { @@ -12,6 +14,7 @@ public class MainActivity extends AppCompatActivity @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_main); if (savedInstanceState == null) { diff --git a/app/src/main/res/layout-land/fragment_game.xml b/app/src/main/res/layout-land/fragment_game.xml new file mode 100644 index 0000000..19a5ff3 --- /dev/null +++ b/app/src/main/res/layout-land/fragment_game.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + + +