Skip to content

Commit

Permalink
Added project files
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed Aug 16, 2015
0 parents commit 0a89abf
Show file tree
Hide file tree
Showing 28 changed files with 569 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#Android generated
bin
gen
lint.xml
lint

#Eclipse
.project
.classpath
.settings
.checkstyle

#IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws
classes
gen-external-apklibs

#gradle
.gradle
local.properties
gradlew
gradlew.bat
gradle/
build/

#vi
*.swp

#other editors
*.bak

#Maven
target
release.properties
pom.xml.*

#Ant
build.xml
ant.properties
local.properties
proguard.cfg
proguard-project.txt

#Other
.DS_Store
Thumbs.db
tmp
*.tgz
*.lock
*.lck
com_crashlytics_export_strings.xml
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"

defaultConfig {
applicationId "saulmm.myapplication"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile "com.android.support:design:22.2.1"
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:cardview-v7:22.2.1'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/saulmm/android-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 *;
#}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="saulmm.myapplication" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
87 changes: 87 additions & 0 deletions app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package saulmm.myapplication;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;

import de.hdodenhof.circleimageview.CircleImageView;

@SuppressWarnings("unused")
public class AvatarImageBehavior extends CoordinatorLayout.Behavior<CircleImageView> {

private final static float MIN_AVATAR_PERCENTAGE_SIZE = 0.3f;
private final static int EXTRA_FINAL_AVATAR_PADDING = 80;

private final static String TAG = "behavior";
private final Context mContext;
private float mAvatarMaxSize;
private float mMarginTop;

public AvatarImageBehavior(Context context, AttributeSet attrs) {
mContext = context;
init();
}

private void init() {
mAvatarMaxSize = mContext.getResources().getDimension(R.dimen.image_width);
mMarginTop = mContext.getResources().getDimension(R.dimen.image_margin);
}

@Override
public boolean layoutDependsOn(CoordinatorLayout parent, CircleImageView child, View dependency) {

return dependency instanceof Toolbar;
}

@Override
public boolean onMeasureChild(CoordinatorLayout parent, CircleImageView child,
int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {

return super.onMeasureChild(parent, child, parentWidthMeasureSpec, widthUsed,
parentHeightMeasureSpec, heightUsed);
}

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) {

CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();

final int maxNumber = (int) (mMarginTop - getStatusBarHeight());

float percentageFactor = dependency.getY() / maxNumber;
int proportionalAvatarSize = (int) (mAvatarMaxSize * (percentageFactor));

float childMarginTop = dependency.getY() - (child.getHeight() / 2);
float childMarginLeft = (dependency.getWidth() / 2) - (child.getWidth() / 2);
float pChildMarginLeft = childMarginLeft * percentageFactor;

int extraFinalPadding = (int) (EXTRA_FINAL_AVATAR_PADDING * (1f - percentageFactor));

if (percentageFactor >= MIN_AVATAR_PERCENTAGE_SIZE) {
lp.width = proportionalAvatarSize;
lp.height = proportionalAvatarSize;
}

lp.setMargins(
(int) pChildMarginLeft + extraFinalPadding,
(int) childMarginTop + extraFinalPadding,
lp.rightMargin,
lp.bottomMargin
);

child.setLayoutParams(lp);
return true;
}

public int getStatusBarHeight() {
int result = 0;
int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");

if (resourceId > 0) {
result = mContext.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
}
137 changes: 137 additions & 0 deletions app/src/main/java/saulmm/myapplication/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package saulmm.myapplication;

import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
implements AppBarLayout.OnOffsetChangedListener {

private static final float PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR = 0.9f;
private static final float PERCENTAGE_TO_HIDE_TITLE_DETAILS = 0.3f;
private static final int ALPHA_ANIMATIONS_DURATION = 200;

private boolean mIsTheTitleVisible = false;
private boolean mIsTheTitleContainerVisible = true;

private LinearLayout mTitleContainer;
private TextView mTitle;
private AppBarLayout mAppBarLayout;
private ImageView mImageparallax;
private FrameLayout mFrameParallax;
private Toolbar mToolbar;


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

bindActivity();

setSupportActionBar(mToolbar);
startAlphaAnimation(mTitle, 0, View.INVISIBLE);
mAppBarLayout.addOnOffsetChangedListener(this);
initParallaxValues();
}

private void bindActivity() {

mToolbar = (Toolbar) findViewById(R.id.main_toolbar);
mTitle = (TextView) findViewById(R.id.main_textview_title);
mTitleContainer = (LinearLayout) findViewById(R.id.main_linearlayout_title);
mAppBarLayout = (AppBarLayout) findViewById(R.id.main_appbar);
mImageparallax = (ImageView) findViewById(R.id.main_imageview_placeholder);
mFrameParallax = (FrameLayout) findViewById(R.id.main_framelayout_title);
}

private void initParallaxValues() {

CollapsingToolbarLayout.LayoutParams petDetailsLp =
(CollapsingToolbarLayout.LayoutParams) mImageparallax.getLayoutParams();

CollapsingToolbarLayout.LayoutParams petBackgroundLp =
(CollapsingToolbarLayout.LayoutParams) mFrameParallax.getLayoutParams();

petDetailsLp.setParallaxMultiplier(0.9f);
petBackgroundLp.setParallaxMultiplier(0.3f);

mImageparallax.setLayoutParams(petDetailsLp);
mFrameParallax.setLayoutParams(petBackgroundLp);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {

int maxScroll = appBarLayout.getTotalScrollRange();
float percentage = (float) Math.abs(offset) / (float) maxScroll;

handleAlphaOnTitle(percentage);
handleToolbarTitleVisibility(percentage);

}

private void handleToolbarTitleVisibility(float percentage) {

if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {

if(!mIsTheTitleVisible) {
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
mIsTheTitleVisible = true;
}

} else {

if (mIsTheTitleVisible) {
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
mIsTheTitleVisible = false;
}
}
}

private void handleAlphaOnTitle(float percentage) {

if (percentage >= PERCENTAGE_TO_HIDE_TITLE_DETAILS) {

if(mIsTheTitleContainerVisible) {
startAlphaAnimation(mTitleContainer, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
mIsTheTitleContainerVisible = false;
}

} else {

if (!mIsTheTitleContainerVisible) {
startAlphaAnimation(mTitleContainer, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
mIsTheTitleContainerVisible = true;
}
}
}

public static void startAlphaAnimation (View v, long duration, int visibility) {

AlphaAnimation alphaAnimation = (visibility == View.VISIBLE)
? new AlphaAnimation(0f, 1f)
: new AlphaAnimation(1f, 0f);

alphaAnimation.setDuration(duration);
alphaAnimation.setFillAfter(true);
v.startAnimation(alphaAnimation);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_menu_add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_menu_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-nodpi/quila.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-nodpi/quila2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-nodpi/sea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0a89abf

Please sign in to comment.