Skip to content

Commit

Permalink
Working on MainActivity UI #3
Browse files Browse the repository at this point in the history
  • Loading branch information
acasadoquijada committed Apr 16, 2020
1 parent f579665 commit 957ac10
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 14 deletions.
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# tell_me_a_joke
# Tell me a joke!
Telling joke app that provides with Jokes from Google Cloud Endpoints (GCE)



###Resources

Icon jesker:
Icons made by <a href="https://www.flaticon.com/authors/elias-bikbulatov" title="Elias Bikbulatov">Elias Bikbulatov</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ dependencies {
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation project(':jokeLibrary')
implementation project(':FunnyJoke')
implementation project(':jokelibraryandroid')

androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.udacity.gradle.builditbigger;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
Expand Down Expand Up @@ -29,6 +30,13 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

findViewById(R.id.jokeButton).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
new EndpointsAsyncTask().execute(getApplicationContext());
}
});
}


Expand All @@ -55,7 +63,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

public void tellJoke(View view) {

new EndpointsAsyncTask().execute(this);

// Toast.makeText(this, funnyJokes.tellAJoke(), Toast.LENGTH_SHORT).show();
Expand All @@ -64,6 +71,18 @@ public void tellJoke(View view) {
public class EndpointsAsyncTask extends AsyncTask<Context, Void, String> {
private MyApi myApiService = null;
private Context context;
private ProgressDialog loadingDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
loadingDialog = new ProgressDialog(MainActivity.this);
loadingDialog.setMessage("Loading a funny joke!");
loadingDialog.setIndeterminate(false);
loadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
loadingDialog.setCancelable(false);
loadingDialog.show();
}

@Override
protected String doInBackground(Context... params) {
Expand Down Expand Up @@ -97,7 +116,9 @@ public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientReques
@Override
protected void onPostExecute(String result) {

Intent intent = new Intent(context, JokeActivity.class);
loadingDialog.dismiss();

Intent intent = new Intent(getApplicationContext(), JokeActivity.class);

intent.putExtra(JokeActivity.JOKE_KEY,result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.os.Bundle;
import androidx.fragment.app.Fragment;

import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -16,6 +18,7 @@
public class MainActivityFragment extends Fragment {

public MainActivityFragment() {

}

@Override
Expand All @@ -31,6 +34,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);

return root;
}


}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_jester.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="64dp"
android:viewportHeight="64" android:viewportWidth="64"
android:width="64dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#F1F0F0" android:pathData="M60.5,20.761c-1.21,0 -2.278,0.618 -2.907,1.555c-3.921,-1.184 -13.482,-2.535 -19.954,9.32c-3.224,-7.261 -1.619,-11.465 0.374,-16.685c0.055,-0.145 0.112,-0.296 0.167,-0.442c0.728,0.756 1.745,1.231 2.875,1.231c2.206,0 4,-1.794 4,-4c0,-2.206 -1.794,-4 -4,-4c-2.206,0 -4,1.794 -4,4c0,0.167 0.029,0.327 0.049,0.489c-7.937,0.865 -12.745,7.761 -13.092,18.465c-3.64,-5.305 -9.331,-6.386 -15.744,-7.603c-0.435,-0.083 -0.882,-0.169 -1.327,-0.255C6.973,22.647 7,22.457 7,22.261c0,-1.93 -1.57,-3.5 -3.5,-3.5s-3.5,1.57 -3.5,3.5c0,1.93 1.57,3.5 3.5,3.5c0.897,0 1.707,-0.349 2.327,-0.905c9.608,9.938 12.647,13.094 11.538,25.405h-0.031c-1.838,0 -3.333,1.346 -3.333,3s1.495,3 3.333,3h30.334c1.838,0 3.333,-1.346 3.333,-3s-1.495,-3 -3.333,-3h-0.304c-2.948,-10.248 0.186,-18.216 9.827,-24.913c0.46,1.396 1.762,2.413 3.31,2.413c1.93,0 3.5,-1.57 3.5,-3.5C64,22.331 62.43,20.761 60.5,20.761zM41.056,9.739c1.103,0 2,0.897 2,2c0,1.103 -0.897,2 -2,2s-2,-0.897 -2,-2C39.056,10.636 39.953,9.739 41.056,9.739zM3.5,23.761c-0.827,0 -1.5,-0.673 -1.5,-1.5c0,-0.827 0.673,-1.5 1.5,-1.5c0.827,0 1.5,0.673 1.5,1.5C5,23.088 4.327,23.761 3.5,23.761zM44.308,43.261c-0.002,1.506 0.138,3.056 0.437,4.656l-4.614,-4.656H44.308zM20.835,50.168l4.829,-4.983l4.989,4.983H20.835zM34.586,50.168l4.653,-4.967l4.923,4.967H34.586zM32.637,49.324l-6.07,-6.063h11.749L32.637,49.324zM19.483,48.691c0.124,-2.023 0.12,-3.813 -0.016,-5.43h5.277L19.483,48.691zM49,53.261c0,0.542 -0.61,1 -1.333,1H17.333c-0.723,0 -1.333,-0.458 -1.333,-1c0,-0.542 0.61,-1 1.333,-1h30.334C48.39,52.261 49,52.719 49,53.261zM44.399,41.261H19.22c-1.015,-5.995 -4.247,-9.782 -10.219,-15.995c7.2,1.383 12.42,2.705 15.17,10.128c0.173,0.467 0.661,0.736 1.149,0.63c0.487,-0.105 0.821,-0.553 0.785,-1.05c-0.842,-11.537 2.864,-19.078 9.978,-20.578c-2.212,5.795 -4.067,10.85 0.647,19.958c0.175,0.339 0.561,0.559 0.908,0.541c0.381,-0.008 0.725,-0.232 0.886,-0.577c5.168,-11.08 12.773,-11.416 17.235,-10.424C48.783,28.828 45.026,34.573 44.399,41.261zM60.5,25.761c-0.827,0 -1.5,-0.673 -1.5,-1.5c0,-0.827 0.673,-1.5 1.5,-1.5c0.827,0 1.5,0.673 1.5,1.5C62,25.088 61.327,25.761 60.5,25.761z"/>
</vector>
17 changes: 17 additions & 0 deletions app/src/main/res/drawable/tell_joke_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Obtained form this stackoverflow post:
https://stackoverflow.com/questions/6674657/how-to-change-a-buttons-shape-using-xml-or-using-java
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#302226"
android:endColor="#6D7B8D"
android:angle="45"/>
<padding android:left="6dp"
android:top="6dp"
android:right="6dp"
android:bottom="6dp" />
<corners android:radius="30dp" />

</shape>
36 changes: 28 additions & 8 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -9,27 +9,47 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivityFragment">


<TextView
android:id="@+id/instructions_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/instructions" />
android:textSize="24sp"
android:gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/instructions"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toTopOf="parent" />

<Button
<include
layout="@layout/joke_layout"
android:id="@+id/jokeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/instructions_text_view"
android:onClick="tellJoke"
android:text="@string/button_text" />
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="@string/button_text"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toBottomOf="@+id/instructions_text_view" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
ads:adUnitId="@string/banner_ad_unit_id"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent" />

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
33 changes: 33 additions & 0 deletions app/src/main/res/layout/joke_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@drawable/tell_joke_shape"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/jokeIcon"
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_jester" />

<TextView
android:id="@+id/jokeButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_margin="8dp"
android:text="@string/joke_button"
app:layout_constraintBottom_toTopOf="@+id/jokeIcon"
app:layout_constraintStart_toEndOf="@+id/jokeIcon"
app:layout_constraintTop_toBottomOf="@+id/jokeIcon" />
</LinearLayout>
12 changes: 12 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#FF5722</color>
<color name="primary_dark">#E64A19</color>
<color name="primary_light">#FFCCBC</color>
<color name="accent">#607D8B</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#757575</color>
<color name="icons">#FFFFFF</color>
<color name="divider">#BDBDBD</color>
<color name="secondary">#6d4c41</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>

</resources>
2 changes: 1 addition & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ dependencies {
implementation 'javax.servlet:servlet-api:2.5'
implementation 'com.google.api-client:google-api-client:1.30.9'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
implementation project(':jokeLibrary')
implementation project(':FunnyJoke')

}
1 change: 1 addition & 0 deletions jokelibraryandroid/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="joke_label">Please admire below the magnificent quality of the joke</string>
<string name="joke_button">Tell me a joke!</string>
</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include ':app', ':backend'
include ':jokeLibrary'
include ':FunnyJoke'
include ':jokelibraryandroid'

0 comments on commit 957ac10

Please sign in to comment.