Skip to content

Commit 0a89abf

Browse files
committed
Added project files
0 parents  commit 0a89abf

28 files changed

+569
-0
lines changed

.gitignore

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#Android generated
2+
bin
3+
gen
4+
lint.xml
5+
lint
6+
7+
#Eclipse
8+
.project
9+
.classpath
10+
.settings
11+
.checkstyle
12+
13+
#IntelliJ IDEA
14+
.idea
15+
*.iml
16+
*.ipr
17+
*.iws
18+
classes
19+
gen-external-apklibs
20+
21+
#gradle
22+
.gradle
23+
local.properties
24+
gradlew
25+
gradlew.bat
26+
gradle/
27+
build/
28+
29+
#vi
30+
*.swp
31+
32+
#other editors
33+
*.bak
34+
35+
#Maven
36+
target
37+
release.properties
38+
pom.xml.*
39+
40+
#Ant
41+
build.xml
42+
ant.properties
43+
local.properties
44+
proguard.cfg
45+
proguard-project.txt
46+
47+
#Other
48+
.DS_Store
49+
Thumbs.db
50+
tmp
51+
*.tgz
52+
*.lock
53+
*.lck
54+
com_crashlytics_export_strings.xml

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 22
5+
buildToolsVersion "23.0.0 rc3"
6+
7+
defaultConfig {
8+
applicationId "saulmm.myapplication"
9+
minSdkVersion 21
10+
targetSdkVersion 22
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile 'com.android.support:appcompat-v7:22.2.1'
25+
compile "com.android.support:design:22.2.1"
26+
compile 'de.hdodenhof:circleimageview:1.3.0'
27+
compile 'com.android.support:cardview-v7:22.2.1'
28+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/saulmm/android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="saulmm.myapplication" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
<activity
11+
android:name=".MainActivity"
12+
android:label="@string/app_name" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package saulmm.myapplication;
2+
3+
import android.content.Context;
4+
import android.support.design.widget.CoordinatorLayout;
5+
import android.support.v7.widget.Toolbar;
6+
import android.util.AttributeSet;
7+
import android.view.View;
8+
9+
import de.hdodenhof.circleimageview.CircleImageView;
10+
11+
@SuppressWarnings("unused")
12+
public class AvatarImageBehavior extends CoordinatorLayout.Behavior<CircleImageView> {
13+
14+
private final static float MIN_AVATAR_PERCENTAGE_SIZE = 0.3f;
15+
private final static int EXTRA_FINAL_AVATAR_PADDING = 80;
16+
17+
private final static String TAG = "behavior";
18+
private final Context mContext;
19+
private float mAvatarMaxSize;
20+
private float mMarginTop;
21+
22+
public AvatarImageBehavior(Context context, AttributeSet attrs) {
23+
mContext = context;
24+
init();
25+
}
26+
27+
private void init() {
28+
mAvatarMaxSize = mContext.getResources().getDimension(R.dimen.image_width);
29+
mMarginTop = mContext.getResources().getDimension(R.dimen.image_margin);
30+
}
31+
32+
@Override
33+
public boolean layoutDependsOn(CoordinatorLayout parent, CircleImageView child, View dependency) {
34+
35+
return dependency instanceof Toolbar;
36+
}
37+
38+
@Override
39+
public boolean onMeasureChild(CoordinatorLayout parent, CircleImageView child,
40+
int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
41+
42+
return super.onMeasureChild(parent, child, parentWidthMeasureSpec, widthUsed,
43+
parentHeightMeasureSpec, heightUsed);
44+
}
45+
46+
@Override
47+
public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) {
48+
49+
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
50+
51+
final int maxNumber = (int) (mMarginTop - getStatusBarHeight());
52+
53+
float percentageFactor = dependency.getY() / maxNumber;
54+
int proportionalAvatarSize = (int) (mAvatarMaxSize * (percentageFactor));
55+
56+
float childMarginTop = dependency.getY() - (child.getHeight() / 2);
57+
float childMarginLeft = (dependency.getWidth() / 2) - (child.getWidth() / 2);
58+
float pChildMarginLeft = childMarginLeft * percentageFactor;
59+
60+
int extraFinalPadding = (int) (EXTRA_FINAL_AVATAR_PADDING * (1f - percentageFactor));
61+
62+
if (percentageFactor >= MIN_AVATAR_PERCENTAGE_SIZE) {
63+
lp.width = proportionalAvatarSize;
64+
lp.height = proportionalAvatarSize;
65+
}
66+
67+
lp.setMargins(
68+
(int) pChildMarginLeft + extraFinalPadding,
69+
(int) childMarginTop + extraFinalPadding,
70+
lp.rightMargin,
71+
lp.bottomMargin
72+
);
73+
74+
child.setLayoutParams(lp);
75+
return true;
76+
}
77+
78+
public int getStatusBarHeight() {
79+
int result = 0;
80+
int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
81+
82+
if (resourceId > 0) {
83+
result = mContext.getResources().getDimensionPixelSize(resourceId);
84+
}
85+
return result;
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package saulmm.myapplication;
2+
3+
import android.os.Bundle;
4+
import android.support.design.widget.AppBarLayout;
5+
import android.support.design.widget.CollapsingToolbarLayout;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.Toolbar;
8+
import android.view.Menu;
9+
import android.view.View;
10+
import android.view.animation.AlphaAnimation;
11+
import android.widget.FrameLayout;
12+
import android.widget.ImageView;
13+
import android.widget.LinearLayout;
14+
import android.widget.TextView;
15+
16+
public class MainActivity extends AppCompatActivity
17+
implements AppBarLayout.OnOffsetChangedListener {
18+
19+
private static final float PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR = 0.9f;
20+
private static final float PERCENTAGE_TO_HIDE_TITLE_DETAILS = 0.3f;
21+
private static final int ALPHA_ANIMATIONS_DURATION = 200;
22+
23+
private boolean mIsTheTitleVisible = false;
24+
private boolean mIsTheTitleContainerVisible = true;
25+
26+
private LinearLayout mTitleContainer;
27+
private TextView mTitle;
28+
private AppBarLayout mAppBarLayout;
29+
private ImageView mImageparallax;
30+
private FrameLayout mFrameParallax;
31+
private Toolbar mToolbar;
32+
33+
34+
@Override
35+
protected void onCreate(Bundle savedInstanceState) {
36+
37+
super.onCreate(savedInstanceState);
38+
setContentView(R.layout.activity_main);
39+
40+
bindActivity();
41+
42+
setSupportActionBar(mToolbar);
43+
startAlphaAnimation(mTitle, 0, View.INVISIBLE);
44+
mAppBarLayout.addOnOffsetChangedListener(this);
45+
initParallaxValues();
46+
}
47+
48+
private void bindActivity() {
49+
50+
mToolbar = (Toolbar) findViewById(R.id.main_toolbar);
51+
mTitle = (TextView) findViewById(R.id.main_textview_title);
52+
mTitleContainer = (LinearLayout) findViewById(R.id.main_linearlayout_title);
53+
mAppBarLayout = (AppBarLayout) findViewById(R.id.main_appbar);
54+
mImageparallax = (ImageView) findViewById(R.id.main_imageview_placeholder);
55+
mFrameParallax = (FrameLayout) findViewById(R.id.main_framelayout_title);
56+
}
57+
58+
private void initParallaxValues() {
59+
60+
CollapsingToolbarLayout.LayoutParams petDetailsLp =
61+
(CollapsingToolbarLayout.LayoutParams) mImageparallax.getLayoutParams();
62+
63+
CollapsingToolbarLayout.LayoutParams petBackgroundLp =
64+
(CollapsingToolbarLayout.LayoutParams) mFrameParallax.getLayoutParams();
65+
66+
petDetailsLp.setParallaxMultiplier(0.9f);
67+
petBackgroundLp.setParallaxMultiplier(0.3f);
68+
69+
mImageparallax.setLayoutParams(petDetailsLp);
70+
mFrameParallax.setLayoutParams(petBackgroundLp);
71+
}
72+
73+
@Override
74+
public boolean onCreateOptionsMenu(Menu menu) {
75+
76+
getMenuInflater().inflate(R.menu.menu_main, menu);
77+
return true;
78+
}
79+
80+
@Override
81+
public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {
82+
83+
int maxScroll = appBarLayout.getTotalScrollRange();
84+
float percentage = (float) Math.abs(offset) / (float) maxScroll;
85+
86+
handleAlphaOnTitle(percentage);
87+
handleToolbarTitleVisibility(percentage);
88+
89+
}
90+
91+
private void handleToolbarTitleVisibility(float percentage) {
92+
93+
if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {
94+
95+
if(!mIsTheTitleVisible) {
96+
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
97+
mIsTheTitleVisible = true;
98+
}
99+
100+
} else {
101+
102+
if (mIsTheTitleVisible) {
103+
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
104+
mIsTheTitleVisible = false;
105+
}
106+
}
107+
}
108+
109+
private void handleAlphaOnTitle(float percentage) {
110+
111+
if (percentage >= PERCENTAGE_TO_HIDE_TITLE_DETAILS) {
112+
113+
if(mIsTheTitleContainerVisible) {
114+
startAlphaAnimation(mTitleContainer, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
115+
mIsTheTitleContainerVisible = false;
116+
}
117+
118+
} else {
119+
120+
if (!mIsTheTitleContainerVisible) {
121+
startAlphaAnimation(mTitleContainer, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
122+
mIsTheTitleContainerVisible = true;
123+
}
124+
}
125+
}
126+
127+
public static void startAlphaAnimation (View v, long duration, int visibility) {
128+
129+
AlphaAnimation alphaAnimation = (visibility == View.VISIBLE)
130+
? new AlphaAnimation(0f, 1f)
131+
: new AlphaAnimation(1f, 0f);
132+
133+
alphaAnimation.setDuration(duration);
134+
alphaAnimation.setFillAfter(true);
135+
v.startAnimation(alphaAnimation);
136+
}
137+
}
Loading
286 Bytes
Loading
417 Bytes
Loading
Loading
Loading
454 KB
Loading
256 KB
Loading
344 KB
Loading
Loading
Loading

0 commit comments

Comments
 (0)