Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
420 additions
and
266 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="saulmm.test" > | ||
package="saulmm.test" | ||
> | ||
|
||
<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" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" | ||
> | ||
<activity | ||
android:name=".MediaActivity" | ||
android:label="@string/app_name" | ||
/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,64 @@ | ||
package saulmm.test; | ||
|
||
import android.animation.Animator; | ||
import android.animation.AnimatorListenerAdapter; | ||
import android.animation.ObjectAnimator; | ||
import android.animation.ValueAnimator; | ||
import android.os.Bundle; | ||
import android.support.v7.app.ActionBarActivity; | ||
import android.support.design.widget.NavigationView; | ||
import android.support.v4.widget.DrawerLayout; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Gravity; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewPropertyAnimator; | ||
import android.view.animation.AccelerateInterpolator; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
|
||
|
||
public class MainActivity extends ActionBarActivity { | ||
|
||
private View mFab; | ||
private FrameLayout mFabContainer; | ||
private LinearLayout mControlsContainer; | ||
|
||
public final static float SCALE_FACTOR = 13f; | ||
public final static int ANIMATION_DURATION = 300; | ||
public final static int MINIMUN_X_DISTANCE = 200; | ||
|
||
private boolean mRevealFlag; | ||
private float mFabSize; | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
mFab = findViewById(R.id.fab); | ||
mFabSize = getResources().getDimensionPixelSize(R.dimen.fab_size); | ||
|
||
mFabContainer = (FrameLayout) findViewById(R.id.fab_container); | ||
mControlsContainer = (LinearLayout) findViewById(R.id.media_controls_container); | ||
} | ||
|
||
public void onFabPressed(View view) { | ||
|
||
final float startX = mFab.getX(); | ||
|
||
AnimatorPath path = new AnimatorPath(); | ||
path.moveTo(0, 0); | ||
path.curveTo(-200, 200, -400, 100, -600, 50); | ||
|
||
final ObjectAnimator anim = ObjectAnimator.ofObject(this, "fabLoc", | ||
new PathEvaluator(), path.getPoints().toArray()); | ||
|
||
anim.setInterpolator(new AccelerateInterpolator()); | ||
anim.setDuration(ANIMATION_DURATION); | ||
anim.start(); | ||
|
||
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
|
||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
|
||
if (Math.abs(startX - mFab.getX()) > MINIMUN_X_DISTANCE) { | ||
|
||
if (!mRevealFlag) { | ||
mFabContainer.setY(mFabContainer.getY() + mFabSize / 2); | ||
|
||
mFab.animate() | ||
.scaleXBy(SCALE_FACTOR) | ||
.scaleYBy(SCALE_FACTOR) | ||
.setListener(mEndRevealListener) | ||
.setDuration(ANIMATION_DURATION); | ||
|
||
mRevealFlag = true; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private AnimatorListenerAdapter mEndRevealListener = new AnimatorListenerAdapter() { | ||
|
||
@Override | ||
public void onAnimationEnd(Animator animation) { | ||
|
||
super.onAnimationEnd(animation); | ||
|
||
mFab.setVisibility(View.INVISIBLE); | ||
mFabContainer.setBackgroundColor(getResources() | ||
.getColor(R.color.brand_accent)); | ||
|
||
for (int i = 0; i < mControlsContainer.getChildCount(); i++) { | ||
|
||
View v = mControlsContainer.getChildAt(i); | ||
ViewPropertyAnimator animator = v.animate() | ||
.scaleX(1).scaleY(1) | ||
.setDuration(ANIMATION_DURATION); | ||
|
||
animator.setStartDelay(i * 50); | ||
animator.start(); | ||
} | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* We need this setter to translate between the information the animator | ||
* produces (a new "PathPoint" describing the current animated location) | ||
* and the information that the button requires (an xy location). The | ||
* setter will be called by the ObjectAnimator given the 'fabLoc' | ||
* property string. | ||
*/ | ||
public void setFabLoc(PathPoint newLoc) { | ||
|
||
mFab.setTranslationX(newLoc.mX); | ||
|
||
|
||
if (mRevealFlag) | ||
mFab.setTranslationY(newLoc.mY - (mFabSize / 2)); | ||
else | ||
mFab.setTranslationY(newLoc.mY); | ||
} | ||
public class MainActivity extends AppCompatActivity { | ||
|
||
private NavigationView mNavigation; | ||
private DrawerLayout mDrawerLayout; | ||
private Toolbar mToolbar; | ||
|
||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
bindViews(); | ||
initToolbar(); | ||
initNavigation(); | ||
} | ||
|
||
private void bindViews() { | ||
mDrawerLayout = (DrawerLayout) findViewById(R.id.main_drawer); | ||
mNavigation = (NavigationView) findViewById(R.id.main_navigation); | ||
} | ||
|
||
private void initToolbar() { | ||
mToolbar = (Toolbar) findViewById(R.id.main_toolbar); | ||
mToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_menu_24dp, getTheme())); | ||
mToolbar.setTitle(getString(R.string.app_name)); | ||
mToolbar.setNavigationOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
|
||
if (!mDrawerLayout.isDrawerOpen(Gravity.LEFT)) | ||
mDrawerLayout.openDrawer(Gravity.LEFT); | ||
else mDrawerLayout.closeDrawer(Gravity.LEFT); | ||
} | ||
}); | ||
} | ||
|
||
private void initNavigation() { | ||
mNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { | ||
@Override | ||
public boolean onNavigationItemSelected(MenuItem menuItem) { | ||
|
||
if (menuItem.getItemId() == R.id.drawer_item_1) | ||
return true; | ||
|
||
if (menuItem.getItemId() == R.id.drawer_item_2) | ||
return true; | ||
|
||
mDrawerLayout.closeDrawer(Gravity.LEFT); | ||
return false; | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.