paid/free flavors
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
productFlavors {
|
||||
free {
|
||||
applicationId = "com.udacity.gradle.builditbigger.free"
|
||||
}
|
||||
paid {
|
||||
applicationId = "com.udacity.gradle.builditbigger.pro"
|
||||
}
|
||||
}
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "22.0.1"
|
||||
|
||||
@@ -21,10 +29,9 @@ android {
|
||||
|
||||
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'
|
||||
freeCompile 'com.google.android.gms:play-services-ads:8.3.0'
|
||||
compile project(path: ':jokesbackend', configuration: 'android-endpoints')
|
||||
compile 'com.android.support:design:23.1.0'
|
||||
}
|
||||
|
||||
18
app/src/free/AndroidManifest.xml
Normal file
18
app/src/free/AndroidManifest.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.udacity.gradle.builditbigger">
|
||||
|
||||
|
||||
<!-- 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" />
|
||||
|
||||
<application>
|
||||
<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>
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.udacity.gradle.builditbigger;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.RelativeLayout.LayoutParams;
|
||||
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import com.google.android.gms.ads.AdView;
|
||||
|
||||
public class MainActivityFlavoredFragment extends MainActivityFragment {
|
||||
|
||||
public static String TAG = MainActivityFlavoredFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
RelativeLayout view = (RelativeLayout) super.onCreateView(inflater, container, savedInstanceState);
|
||||
attachBannerAd(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void attachBannerAd(RelativeLayout rootView) {
|
||||
// initialize the adview
|
||||
AdView adView = (AdView) LayoutInflater.from(rootView.getContext()).inflate(R.layout.adview, rootView, false);
|
||||
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
adView.setLayoutParams(params);
|
||||
rootView.addView(adView);
|
||||
AdRequest adRequest = new AdRequest.Builder()
|
||||
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
|
||||
.build();
|
||||
adView.loadAd(adRequest);
|
||||
}
|
||||
}
|
||||
5
app/src/free/res/layout/adview.xml
Normal file
5
app/src/free/res/layout/adview.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<com.google.android.gms.ads.AdView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:ads="http://schemas.android.com/apk/res-auto" 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" />
|
||||
@@ -12,11 +12,6 @@
|
||||
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" >
|
||||
@@ -33,11 +28,6 @@
|
||||
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>
|
||||
|
||||
@@ -8,9 +8,6 @@ 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;
|
||||
|
||||
@@ -18,7 +15,7 @@ import net.headlezz.jokesbackend.myApi.model.Joke;
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class MainActivityFragment extends Fragment implements View.OnClickListener, JokeLoaderTask.JokeLoaderCallback {
|
||||
public abstract class MainActivityFragment extends Fragment implements View.OnClickListener, JokeLoaderTask.JokeLoaderCallback {
|
||||
|
||||
JokeLoaderTask mJokeLoaderTask;
|
||||
|
||||
@@ -29,19 +26,10 @@ public class MainActivityFragment extends Fragment implements View.OnClickListen
|
||||
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();
|
||||
|
||||
@@ -1,5 +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"
|
||||
android:name="com.udacity.gradle.builditbigger.MainActivityFlavoredFragment"
|
||||
tools:layout="@layout/fragment_main" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<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"
|
||||
@@ -22,15 +21,4 @@
|
||||
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>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.udacity.gradle.builditbigger;
|
||||
|
||||
public class MainActivityFlavoredFragment extends MainActivityFragment {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user