|
1 | 1 | package org.wordpress.android.ui.main; |
2 | 2 |
|
| 3 | +import android.animation.ObjectAnimator; |
3 | 4 | import android.app.Activity; |
4 | 5 | import android.app.Fragment; |
5 | 6 | import android.content.Intent; |
6 | 7 | import android.os.AsyncTask; |
| 8 | +import android.os.Build; |
7 | 9 | import android.os.Bundle; |
8 | 10 | import android.os.Handler; |
9 | 11 | import android.support.design.widget.TabLayout; |
@@ -62,6 +64,7 @@ public class WPMainActivity extends Activity implements Bucket.Listener<Note> { |
62 | 64 | private WPMainTabLayout mTabLayout; |
63 | 65 | private WPMainTabAdapter mTabAdapter; |
64 | 66 | private TextView mConnectionBar; |
| 67 | + private int mAppBarElevation; |
65 | 68 |
|
66 | 69 | public static final String ARG_OPENED_FROM_PUSH = "opened_from_push"; |
67 | 70 |
|
@@ -126,17 +129,30 @@ public void onTabReselected(TabLayout.Tab tab) { |
126 | 129 | } |
127 | 130 | }); |
128 | 131 |
|
| 132 | + mAppBarElevation = getResources().getDimensionPixelSize(R.dimen.appbar_elevation); |
| 133 | + |
129 | 134 | mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); |
130 | 135 | mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { |
131 | 136 | @Override |
132 | 137 | public void onPageSelected(int position) { |
133 | 138 | AppPrefs.setMainTabIndex(position); |
134 | 139 |
|
135 | 140 | switch (position) { |
| 141 | + case WPMainTabAdapter.TAB_MY_SITE: |
| 142 | + setTabLayoutElevation(mAppBarElevation); |
| 143 | + break; |
| 144 | + case WPMainTabAdapter.TAB_READER: |
| 145 | + setTabLayoutElevation(0); |
| 146 | + break; |
| 147 | + case WPMainTabAdapter.TAB_ME: |
| 148 | + setTabLayoutElevation(mAppBarElevation); |
| 149 | + break; |
136 | 150 | case WPMainTabAdapter.TAB_NOTIFS: |
| 151 | + setTabLayoutElevation(mAppBarElevation); |
137 | 152 | new UpdateLastSeenTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
138 | 153 | break; |
139 | 154 | } |
| 155 | + |
140 | 156 | trackLastVisibleTab(position, true); |
141 | 157 | } |
142 | 158 |
|
@@ -176,6 +192,19 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse |
176 | 192 | } |
177 | 193 | } |
178 | 194 |
|
| 195 | + private void setTabLayoutElevation(float newElevation){ |
| 196 | + if (mTabLayout == null) return; |
| 197 | + |
| 198 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 199 | + float oldElevation = mTabLayout.getElevation(); |
| 200 | + if (oldElevation != newElevation) { |
| 201 | + ObjectAnimator.ofFloat(mTabLayout, "elevation", oldElevation, newElevation) |
| 202 | + .setDuration(1000L) |
| 203 | + .start(); |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + |
179 | 208 | @Override |
180 | 209 | protected void onNewIntent(Intent intent) { |
181 | 210 | super.onNewIntent(intent); |
|
0 commit comments