Code snipet

if(chat.getAuthor().getAvatarId() == 0){
	
	Picasso.with(getContext()).load(android.R.color.transparent).into(chat_author_avatar);
		chat_author_avatar.setBackgroundColor(chat.getAuthor().getColor());
} else {
	Picasso.with(getContext()).load(chat.getAuthor().getAvatarId()).into(
		chat_author_avatar);
	chat_author_avatar.setBackgroundColor(Color.TRANSPARENT);
}

public int compute Fibonacci(int positionInFibSequence)
{
if (positionInFibSequence <= 2){ return 1; } else { return computeFibonacci(positionInFibSequence -1) + computeFibonacci(positionInFibSequence -2) } }[/python] [python] private class SepiaFilterTask extends AsyncTask { protected Bitmap doInBackground(Bitmap... bitmaps){ Bitmap loadedBitmap = bitmaps[0]; } sepiaBitmap.setPixel(x, y, Color.argb(alpha, outRed, outGreen, outBlue)); } } return sepiaBitmap; }[/python]

Creating Paper Transformations

ViewAnimationUtils.createCircularReveal(
View view,
int centerX,
int centerY,
float startRadius,
float endRadius
)

@Override
public void onClick(View view){
	boolean isVeggie = ((ColorDrawable)viewe.getBackground()) != null && ((ColorDrawable)view)

	int finalRadius = (int)Math.hypot(view.getWidth()/2, view.getHeight()/2);

	if (isVeggie){
		text1.setText(baconTitle);
		text2.setText(baconText);
		view.setBackgroundColor(white);
	} else {
		Animator anim = ViewAnimationUnits.createCircularReveal(
			view, (int) view.getWidth()/2, (int) view.getHeight()/2, 0, finalRadius);
		text1.setText(veggieTitle);
		text2.setText(veggieText);
		view.setBackgroundColor(green);
		anim.start();
	}
}

res/layout/activity.xml

<android.support.design.widget.CoordinatorLayout
	xmlns:android="http://schemas.android.com/apk/res.android"
	xmlns:app="http://schemas.android.com/apk/res-auto"
	...>

CoordinatorLayout
->AppBarLayout
android:layout_height = “168dp”
android:background=”@color/indigo_500″
-> CollapsingToolbarLayout
app:layout_scrollFlags=”scroll|exitUnitCollapsed”>
-> Toolbar
android:layout_height=”56dp”
app:layout_collapseMode=”pin” />
RecyclerView
app:layout_behavior=”@string/appbar_scrolling_view_behavior” />

Color palette

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<color name="indigo_300">#7986CB</color>
	<color name="indigo_500">#3F51B5</color>
	<color name="indigo_700">#303F9F</color>
	<color name="pink_a200">#FF4081</color>
</resources>

https://developer.android.com/training/material/theme.html

Fonts within a font family and weight, style

onClick

TransitionManager.go(
	Scene.getSceneForLayout(
	(ViewGroup) findViewById(R.id.root),
	R.layout.activity_main_scene_info,
	MainActivity.this));
res/transition/grid_exit.xml
<explode xmlns... />

res/values/styles.xml
<style name="AppTheme.Home">
	<item name="android:windowExitTransition">
		@transition/grid_exit</item>
</style>

Implementing Surfaces

<LinearLayout
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:orientation="vertical">

	<FrameLayout
		android:layout_width="match_parent"
		android:layout_height="200dp"
		android:layout_margin="16dp"
		android:background="#fff"
		android:elevation="4dp" />

	<FrameLayout
		android:layout_width="match_parent"
		android:layout_height="200dp"
		android:layout_margin="16dp"
		android:background="#fff"
		android:elevation="8dp" />

	<FrameLayout
		android:layout_width="match_parent"
		android:layout_height="200dp"
		android:layout_margin="16dp"
		android:background="#fff"
		android:elevation="16dp" />

</LinearLayout>

f-a-b => FAB

dependencies {
	compile fileTree(dir: 'libs', include: ['*.jar'])
	compile 'com.android.support:appcompat-v7:22.2.0'
	compile 'com.android.support:design:22.2.0'
}

activity_main.xml

<android.support.design.widget.FloatingActionButton
	app:fabSize="normal"
	app:elevation="6dp"
	app:layout_gravity="end"
	app:pressedTranslationZ="12dp"

	android:id="@+id/fab"
	android:src="@drawable/fab_plus"

	android:layout_height="wrap_content"
	android:layout_width="wrap_content"
	android:layout_margin="16dp"
/>

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="AppTheme" parent="android:Theme.Material.Light">
	</style>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="AppTheme" parent="Theme.AppCompat.Light">
	</style>
</resources>

Android Design

Working with density-independent pixels
1px / 1dp = 160dpi / 160dpi
2px / 1dp = 320dpi / 160dpi
※ dpi = dot per inch
7inch nexus^7 1280x800pixel => 960x600dp

Density buckets
LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI

res/drawable/checkbox.xml

<selector>
	<item android:state_pressed="true"
		android:state_checked="true"
		android:drawable="@drawable/box_checked_pressed">

	<item android:state_pressed="true"
		android:drawable="@drawable/box_pressed">

	<item android:state_checked="true"
		android:drawable="@drawable/box_checked">

	<item android:drawable="@drawable/box_default">

</selector>

content, padding, margins
FrameLayout, LinearLayout, RelativeLayout, GridLayout, ScrollView, ListView, ViewPager

styles.xml

<resources>

	<!-- Base application theme. -->
	<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
		<!-- Customize theme here -->
	</style>

	<style name="MyStyle">
		<item name="android:textColor">#FF255F26</item>
	</style>

	<style name="AnotherStyle">
		<item name="android:textColor">#1D175F</item>
		<item name="android:textStyle">bold</item>
	</style>
</resources>

Loading and showing interstitial AD

Interstitial Ad – AdListener
loadAd -> onAdLoaded -> show, isLoaded

public class InterstitialActivity extends Activity {
	private Button mShowButton;
	private InterstitialAd mInterstitial;

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_interstitial);

		mShowButton = (Button) findViewById(R.id.showButton);
		mShowButton.setEnabled(false);
	}

	public void loadInterstitial(View unusedView){
		mShowButton.setEnabled(false);
		mShowButton.setText("Loading Interstitial");

		mInterstitial = new InterstitialAd(this);
		mInterstitial.setAdUnitId("ca-app-pub-xxxx/xxxx");
		mInterstitial.astAdListener(new ToastAdListener(this){
			@Override
			public void onAdLoaded(){
				super.onAdLoaded();
				mShowButton.setText("Show Interstitial");
				mShowButton.setEnabled(true);
			}
			@Override
			public void onAdFailedToLoad(int errorCode){
				super.onAdFailedToLoad(errorCode);
				mShowButton.setText(getErrorReason());
			}
			});
			AdRequest.on = new AdRequest.Builder().build();
			mInterstitial.loadAd(ar);
		}

	public void showInterstitial(view unusedView){
		if (mInterstitial.isLoaded()){
			mInterstitial.show();
		}
		mShowButton.setText("Interstitial Not Ready");
		mShowButton.setEnabled(false);
	}
}

loadInterstitial
-Create InterstitialAd
-Set AdUnit Id
-Create Listener – onAdLoaded – show, onAdFailedToLoad – error
-Create AdRequest & LiadAd

Implementing an interstitial AD

InterstitialActivity
callback: loadInterstitial
Disable button
Set text to “Loading Interstitial”
Property: mShowButton
callback: showInterstitial (empty)
set to disable in onCreate

interstitial_ad_unit_id

<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/linearLayout"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<Button
		android:id="@+id/loadButton"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="Load Interstitial"
		android:onClick="loadInterstitial"/>
	<Button
		android:id="@+id/showButton"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="Interstitial Not Ready"
		android:onClick="showInterstitial" />
</LinearLayout>	
public class InterstitialActivity extends Activity {
	private Button mShowButton;

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_interstitial);

		mShowButton = (Button) findViewById(R.id.showButton);
		mShowButton.setEnabled(false);
	}

	public void loadInterstitial(View unusedView){
		mShowButton.setEnabled(false);
		mShowButton.setText("Loading Interstitial");
	}

	public void showInterstitial(view unusedView){
	}
}

Adding AdListener

import ...

public class ToastAdListener extends AdListener {
	private Context mContext;
	private String mErrorReason;

	public ToastAdListener(Context context) { this.mContext = context; }

	@Override
	public void onAdLoaded(){
		Toast.makeText(mContext,
			"onAdLoaded()",
			Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onAdOpened(){
		Toast.makeText(mContext,
			"onAdOpened()",
			Toast.LENGTH_SHORT).show();
	}
}

Banner Ad

package com.example.adviewer;

import ...

public class BannerActivity extends Activity {
	private AdView mAdView;

	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_banner);

		mAdView = (AdView) findViewById(R.id.adView);
		AdRequest adRequest = new AdRequest.Builder()
			.build();
		mAdView.loadAd(adRequest);
	}
}

AdListener
public void onAdLoaded()
public void onAdFailedToLoad(int code) {AdRequest Error}
public void onAdOpened()
public void onAdLeftApplication() (e.g. BROWSER)

AdMob

Easy to Launch, Long Term, User Value
Paid Donwloads: no, no, yes
Subscription: no, yes, yes
Displaying ADs: yes, yes, yes
In-app purchase: yes, yes, yes

Common Monetization Models
-ADs & In-app purchases, subscription & in-app purchases, paid download & in-app purchases

USERS -> APPS(publishers) -> AdMob -> ADVERTISERS
https://www.google.co.jp/admob/

Types of ADs
-Banner ADs: TEXT, Image
-Interstitional ADs: Text, image, video
-Native ADs

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:ads="http://schemas.android.com/apk/res-auto"
	android:id="@+id/mainLayout"
	android:layout_width="match_parent"
	android:layout_height="match_parent">

	<com.google.android.gms.ads.AdView
		android:id="@+id/adView"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_alignParentBottom="true"
		android:layout_alignParentLeft="true"
		ads:adSize="BANNER"
		ads:adUnitId="cp-app-pub-xxxx/xxxx"/>
</RelativeLayout>