MP1_CalebFontenot
1
Book Files/32_Animations/Sunset/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
30
Book Files/32_Animations/Sunset/app/build.gradle
Normal file
@@ -0,0 +1,30 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '25.0.2'
|
||||
defaultConfig {
|
||||
applicationId "com.bignerdranch.android.sunset"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:25.3.0'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
25
Book Files/32_Animations/Sunset/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /Users/chris/AndroidDeveloper/sdk/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 *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@@ -0,0 +1,26 @@
|
||||
package com.bignerdranch.android.sunset;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumentation test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.bignerdranch.android.sunset", appContext.getPackageName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.bignerdranch.android.sunset"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".SunsetActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@@ -0,0 +1,27 @@
|
||||
package com.bignerdranch.android.sunset;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
public abstract class SingleFragmentActivity extends AppCompatActivity {
|
||||
|
||||
protected abstract Fragment createFragment();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fragment);
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
|
||||
|
||||
if (fragment == null) {
|
||||
fragment = createFragment();
|
||||
fm.beginTransaction()
|
||||
.add(R.id.fragment_container, fragment)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.bignerdranch.android.sunset;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
public class SunsetActivity extends SingleFragmentActivity {
|
||||
|
||||
@Override
|
||||
protected Fragment createFragment() {
|
||||
return SunsetFragment.newInstance();
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package com.bignerdranch.android.sunset;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
|
||||
public class SunsetFragment extends Fragment {
|
||||
|
||||
private View mSceneView;
|
||||
private View mSunView;
|
||||
private View mSkyView;
|
||||
|
||||
private int mBlueSkyColor;
|
||||
private int mSunsetSkyColor;
|
||||
private int mNightSkyColor;
|
||||
|
||||
public static SunsetFragment newInstance() {
|
||||
return new SunsetFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_sunset, container, false);
|
||||
|
||||
mSceneView = view;
|
||||
mSunView = view.findViewById(R.id.sun);
|
||||
mSkyView = view.findViewById(R.id.sky);
|
||||
|
||||
Resources resources = getResources();
|
||||
mBlueSkyColor = resources.getColor(R.color.blue_sky);
|
||||
mSunsetSkyColor = resources.getColor(R.color.sunset_sky);
|
||||
mNightSkyColor = resources.getColor(R.color.night_sky);
|
||||
|
||||
mSceneView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startAnimation();
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void startAnimation() {
|
||||
float sunYStart = mSunView.getTop();
|
||||
float sunYEnd = mSkyView.getHeight();
|
||||
|
||||
ObjectAnimator heightAnimator = ObjectAnimator
|
||||
.ofFloat(mSunView, "y", sunYStart, sunYEnd)
|
||||
.setDuration(3000);
|
||||
heightAnimator.setInterpolator(new AccelerateInterpolator());
|
||||
|
||||
ObjectAnimator sunsetSkyAnimator = ObjectAnimator
|
||||
.ofInt(mSkyView, "backgroundColor", mBlueSkyColor, mSunsetSkyColor)
|
||||
.setDuration(3000);
|
||||
sunsetSkyAnimator.setEvaluator(new ArgbEvaluator());
|
||||
|
||||
ObjectAnimator nightSkyAnimator = ObjectAnimator
|
||||
.ofInt(mSkyView, "backgroundColor", mSunsetSkyColor, mNightSkyColor)
|
||||
.setDuration(1500);
|
||||
nightSkyAnimator.setEvaluator(new ArgbEvaluator());
|
||||
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet
|
||||
.play(heightAnimator)
|
||||
.with(sunsetSkyAnimator)
|
||||
.before(nightSkyAnimator);
|
||||
animatorSet.start();
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/bright_sun" />
|
||||
</shape>
|
@@ -0,0 +1,4 @@
|
||||
<FrameLayout android:id="@+id/fragment_container"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:id="@+id/activity_sunset"
|
||||
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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.bignerdranch.android.sunset.SunsetActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/activity_sunset"
|
||||
app:layout_constraintLeft_toLeftOf="@+id/activity_sunset"
|
||||
app:layout_constraintRight_toRightOf="@+id/activity_sunset"
|
||||
app:layout_constraintTop_toTopOf="@+id/activity_sunset"/>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<FrameLayout
|
||||
android:id="@+id/sky"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.61"
|
||||
android:background="@color/blue_sky">
|
||||
<ImageView
|
||||
android:id="@+id/sun"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/sun"
|
||||
/>
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.39"
|
||||
android:background="@color/sea"
|
||||
/>
|
||||
</LinearLayout>
|
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 9.8 KiB |
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
|
||||
<color name="bright_sun">#fcfcb7</color>
|
||||
<color name="blue_sky">#1e7ac7</color>
|
||||
<color name="sunset_sky">#ec8100</color>
|
||||
<color name="night_sky">#05192e</color>
|
||||
<color name="sea">#224869</color>
|
||||
</resources>
|
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Sunset</string>
|
||||
</resources>
|
@@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@@ -0,0 +1,17 @@
|
||||
package com.bignerdranch.android.sunset;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|