This commit is contained in:
danijoo
2015-11-05 22:34:08 +01:00
commit 3821c3e494
48 changed files with 1306 additions and 0 deletions

1
app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

30
app/build.gradle Normal file
View File

@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.udacity.gradle.builditbigger"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// Added for AdMob
compile project(':androidjokepresenter')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile project(path: ':jokesbackend', configuration: 'android-endpoints')
compile 'com.android.support:design:23.1.0'
}

17
app/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/silver/Development/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@@ -0,0 +1,13 @@
package com.udacity.gradle.builditbigger;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.udacity.gradle.builditbigger" >
<!-- Include required permissions for Google Mobile Ads to run -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- This meta-data tag is required to use Google Play Services. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="net.headlezz.androidjokepresenter.JokePresenterActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>

View File

@@ -0,0 +1,60 @@
package com.udacity.gradle.builditbigger;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
import net.headlezz.jokesbackend.myApi.MyApi;
import net.headlezz.jokesbackend.myApi.model.Joke;
import java.io.IOException;
public class JokeLoaderTask extends AsyncTask<Void, Void, Joke> {
static final String ROOT_URL = "http://10.0.3.2:8080/_ah/api/";
MyApi mApi;
JokeLoaderCallback mCallback;
interface JokeLoaderCallback {
void onJokeLoaded(Joke joke);
void onError();
}
public JokeLoaderTask(@NonNull JokeLoaderCallback cb) {
mCallback = cb;
mApi = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
.setRootUrl(ROOT_URL)
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
}).build();
}
@Override
protected Joke doInBackground(Void... params) {
try {
return mApi.tellJoke().execute();
} catch (IOException e) {
return null;
}
}
@Override
protected void onPostExecute(Joke joke) {
if(isCancelled())
return;
if(joke != null) {
mCallback.onJokeLoaded(joke);
} else {
mCallback.onError();
}
}
}

View File

@@ -0,0 +1,40 @@
package com.udacity.gradle.builditbigger;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@@ -0,0 +1,76 @@
package com.udacity.gradle.builditbigger;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import net.headlezz.androidjokepresenter.JokePresenterActivity;
import net.headlezz.jokesbackend.myApi.model.Joke;
/**
* A placeholder fragment containing a simple view.
*/
public class MainActivityFragment extends Fragment implements View.OnClickListener, JokeLoaderTask.JokeLoaderCallback {
JokeLoaderTask mJokeLoaderTask;
public MainActivityFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_main, container, false);
initAds((AdView) root.findViewById(R.id.adView));
root.findViewById(R.id.btShowJoke).setOnClickListener(this);
return root;
}
private void initAds(AdView adView) {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
}
@Override
public void onClick(View v) {
downloadNewJoke();
}
private void downloadNewJoke() {
mJokeLoaderTask = new JokeLoaderTask(this);
mJokeLoaderTask.execute();
}
@Override
public void onJokeLoaded(Joke joke) {
Intent i = new Intent(getContext(), JokePresenterActivity.class);
i.putExtra(JokePresenterActivity.BUNDLE_ARG_JOKE, joke.getJoke());
startActivity(i);
}
@Override
public void onError() {
if (getView() != null)
Snackbar.make(getView(), R.string.joke_download_error, Snackbar.LENGTH_LONG)
.setAction(R.string.retry, this)
.show();
}
@Override
public void onStop() {
if(mJokeLoaderTask != null && !mJokeLoaderTask.isCancelled())
mJokeLoaderTask.cancel(true);
super.onStop();
}
}

View File

@@ -0,0 +1,5 @@
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment"
android:name="com.udacity.gradle.builditbigger.MainActivityFragment"
tools:layout="@layout/fragment_main" android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -0,0 +1,36 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivityFragment">
<TextView android:text="@string/instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/instructions_text_view"
android:layout_above="@+id/btShowJoke"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/btShowJoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>

View File

@@ -0,0 +1,6 @@
<menu 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" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@@ -0,0 +1,9 @@
<resources>
<string name="app_name">Build it Bigger</string>
<string name="instructions">Press the button for a delicious joke!</string>
<string name="button_text">Tell Joke</string>
<string name="action_settings">Settings</string>
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
<string name="joke_download_error">Failed to load joke</string>
<string name="retry">Retry</string>
</resources>

View File

@@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>