install gradle into CentOS

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget https://services.gradle.org/distributions/gradle-3.1-all.zip
[root@localhost src]# unzip gradle-3.1-all.zip 
[root@localhost src]# mv gradle-3.1 /usr/local/bin/

環境パスを追加

[root@localhost src]# vi ~/.bash_profile
export PATH=$PATH:/usr/local/bin/gradle-3.1/bin

反映

export PATH=$PATH:/usr/local/bin/gradle-3.1/bin

バージョン確認

[root@localhost src]# gradle -v

------------------------------------------------------------
Gradle 3.1
------------------------------------------------------------

Build time:   2016-09-19 10:53:53 UTC
Revision:     13f38ba699afd86d7cdc4ed8fd7dd3960c0b1f97

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_111 (Oracle Corporation 25.111-b15)
OS:           Linux 2.6.32-642.6.2.el6.x86_64 amd64

Try gradle

git clone and run shell script

[vagrant@localhost 1.01-Exercise-RunYourFirstTask]$ ./gradlew hello
Downloading https://services.gradle.org/distributions/gradle-3.3-bin.zip
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Unzipping /home/vagrant/.gradle/wrapper/dists/gradle-3.3-bin/64bhckfm0iuu9gap9hg3r7ev2/gradle-3.3-bin.zip to /home/vagrant/.gradle/wrapper/dists/gradle-3.3-bin/64bhckfm0iuu9gap9hg3r7ev2
Set executable permissions for: /home/vagrant/.gradle/wrapper/dists/gradle-3.3-bin/64bhckfm0iuu9gap9hg3r7ev2/gradle-3.3/bin/gradle
Starting a Gradle Daemon (subsequent builds will be faster)
:hello
Hello World!

BUILD SUCCESSFUL

Total time: 1 mins 7.442 secs
task hello {
    doLast {
        println "Hello, Jeremy"
    }
}

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();
	}
}