Skip to content

Commit

Permalink
Created the elevation sample
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed Nov 27, 2014
1 parent e8a64be commit 3f1102b
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 132 deletions.
28 changes: 14 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
android:icon="@drawable/ic_launcher"
android:label=""
android:theme="@style/AppTheme" >

<activity
android:name=".activities.TransitionFirstActivity">
<activity android:name="com.saulmm.material.activities.TransitionFirstActivity" >
</activity>

<activity
android:name=".activities.TransitionSecondActivity"
android:name="com.saulmm.material.activities.TransitionSecondActivity"
android:label="@string/title_activity_my_activity2" >
</activity>

<activity
android:name=".activities.SlidingActivity" >
<activity android:name="com.saulmm.material.activities.SlidingActivity" >
</activity>
<activity
android:name="com.saulmm.material.activities.DialerSampleActivity"
android:screenOrientation="portrait" >

<activity android:name=".activities.DialerSampleActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.saulmm.material.activities.ColorActivity"
android:label="@string/title_activity_color" />
<activity
android:name="com.saulmm.material.activities.ElevationSampleActivity"
android:label="@string/title_activity_elevation_sample" >

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

<activity
android:name=".activities.ColorActivity"
android:label="@string/title_activity_color" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.saulmm.material.views.adapters.SamplePagerAdapter;
import com.saulmm.material.views.widgets.SlidingTabLayout;

public class DialerSampleActivity extends ActionBarActivity implements ViewPager.OnPageChangeListener {
public class DialerSampleActivity extends ActionBarActivity {

private int screenWidth;
private ImageButton fabButton;
Expand All @@ -35,50 +35,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_dialer);

configureToolbar();
configurePager();
configureFab();
configureDialer();

dialerKeysContainer = (FrameLayout) findViewById(R.id.activity_dialer_frame_container);

// Get the screen with
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
}

private void configureFab() {

fabButton = (ImageButton) findViewById(R.id.view_fab_button);
fabButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

absolutefabPosition = v.getX();
GUIUtils.hideViewByScale(fabButton);
dialerKeysContainer.setVisibility(View.VISIBLE);

Animation showDialerContainerAnimation = AnimationUtils.loadAnimation(DialerSampleActivity.this, R.anim.translate_down_on);
showDialerContainerAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}

@Override
public void onAnimationEnd(Animation animation) {

fabButton.setBackgroundResource(R.drawable.ripple_dialer_call);
fabButton.setX(screenWidth / 2 - fabButton.getWidth() / 2);
GUIUtils.showViewByScale(fabButton);
}

@Override
public void onAnimationRepeat(Animation animation) {}
});

dialerKeysContainer.startAnimation(showDialerContainerAnimation);
}
});
}

private void configureToolbar() {
Expand All @@ -88,77 +44,4 @@ private void configureToolbar() {
setSupportActionBar(mainToolbar);
getSupportActionBar().setTitle("Dialer");
}

private void configurePager() {

ViewPager tabsViewPAger = (ViewPager) findViewById(R.id.activity_dialer_pager);
tabsViewPAger.setAdapter(new SamplePagerAdapter(this));
tabsViewPAger.setCurrentItem(1);

SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.activity_dialer_tabs);
mSlidingTabLayout.addPagerListener(this);
mSlidingTabLayout.setViewPager(tabsViewPAger);
}

private void configureDialer() {

GridView dialerGrid = (GridView) findViewById(R.id.activity_dialer_pad);
dialerGrid.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item_dialer,
getResources().getStringArray(R.array.dialer_numbers)));
}

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

float fabButtonPosition = (screenWidth / 2 - fabButton.getWidth()) * positionOffset;


if (fabButtonPosition != 0 && position != 1) {

absolutefabPosition = fabButtonPosition + (screenWidth/2 - fabButton.getWidth()/2);
fabButton.setX(absolutefabPosition);
}
}

@Override
public void onBackPressed() {

if (dialerKeysContainer.getVisibility() == View.VISIBLE) {

Animation hideAnimation = AnimationUtils.loadAnimation(this, R.anim.translate_down_off);
hideAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

GUIUtils.hideViewByScale(fabButton);
}

@Override
public void onAnimationEnd(Animation animation) {

dialerKeysContainer.setVisibility(View.INVISIBLE);
fabButton.setBackgroundResource(R.drawable.ripple_dialer_idle);
GUIUtils.showViewByScale(fabButton);

fabButton.setX(absolutefabPosition);
}

@Override
public void onAnimationRepeat(Animation animation) {}
});

dialerKeysContainer.startAnimation(hideAnimation);



} else {
super.onBackPressed();
}
}

@Override
public void onPageSelected(int position) {}

@Override
public void onPageScrollStateChanged(int state) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.saulmm.material.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.saulmm.material.R;

public class ElevationSampleActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elevation_sample);
}
}
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/translation_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="@android:integer/config_shortAnimTime"
android:valueTo="10dp"
android:valueType="floatType"/>
</set>
</item>
<item
android:state_pressed="false"
>
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="2dp"
android:valueType="floatType"/>
</set>
</item>
</selector>
61 changes: 61 additions & 0 deletions app/src/main/res/layout/activity_elevation_sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EAEAEA"
>

<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?android:colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="5dp"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
>

<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="96dp"
android:layout_marginTop="16dp"
android:stateListAnimator="@drawable/translation_selector"
android:elevation="2dp"
android:clickable="true"
card_view:cardCornerRadius="4dp"
/>

<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="96dp"
android:layout_marginTop="16dp"
android:stateListAnimator="@drawable/translation_selector"
android:elevation="2dp"
android:clickable="true"
card_view:cardCornerRadius="4dp"
/>

<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="96dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:stateListAnimator="@drawable/translation_selector"
android:elevation="2dp"
android:clickable="true"
card_view:cardCornerRadius="4dp"
/>

</LinearLayout>
</FrameLayout>
8 changes: 8 additions & 0 deletions app/src/main/res/menu/menu_elevation_sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.saulmm.material.activities.ElevationSampleActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never"/>
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
<item>#</item>
</string-array>

<string name="title_activity_elevation_sample">ElevationSampleActivity</string>

</resources>

1 comment on commit 3f1102b

@dengshiwei
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

Please sign in to comment.