-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
298 additions
and
11 deletions.
There are no files selected for viewing
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
203 changes: 203 additions & 0 deletions
203
MaterialSample/app/src/main/java/com/suleiman/material/activities/TabsHeaderActivity.java
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 |
---|---|---|
@@ -0,0 +1,203 @@ | ||
package com.suleiman.material.activities; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.os.Bundle; | ||
import android.support.design.widget.CollapsingToolbarLayout; | ||
import android.support.design.widget.TabLayout; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentPagerAdapter; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.graphics.Palette; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.FrameLayout; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
import com.suleiman.material.R; | ||
import com.suleiman.material.adapter.SimpleRecyclerAdapter; | ||
import com.suleiman.material.model.VersionModel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TabsHeaderActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_tabs_header); | ||
|
||
final Toolbar toolbar = (Toolbar) findViewById(R.id.htab_toolbar); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setTitle("Parallax Tabs"); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
||
final ViewPager viewPager = (ViewPager) findViewById(R.id.htab_viewpager); | ||
setupViewPager(viewPager); | ||
|
||
|
||
TabLayout tabLayout = (TabLayout) findViewById(R.id.htab_tabs); | ||
tabLayout.setupWithViewPager(viewPager); | ||
|
||
final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.htab_collapse_toolbar); | ||
collapsingToolbarLayout.setTitleEnabled(false); | ||
|
||
ImageView header = (ImageView) findViewById(R.id.header); | ||
|
||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), | ||
R.drawable.header); | ||
|
||
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { | ||
@SuppressWarnings("ResourceType") | ||
@Override | ||
public void onGenerated(Palette palette) { | ||
|
||
int vibrantColor = palette.getVibrantColor(R.color.primary_500); | ||
int vibrantDarkColor = palette.getDarkVibrantColor(R.color.primary_700); | ||
collapsingToolbarLayout.setContentScrimColor(vibrantColor); | ||
collapsingToolbarLayout.setStatusBarScrimColor(vibrantDarkColor); | ||
} | ||
}); | ||
|
||
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { | ||
@Override | ||
public void onTabSelected(TabLayout.Tab tab) { | ||
|
||
viewPager.setCurrentItem(tab.getPosition()); | ||
|
||
switch (tab.getPosition()) { | ||
case 0: | ||
showToast("One"); | ||
break; | ||
case 1: | ||
showToast("Two"); | ||
|
||
break; | ||
case 2: | ||
showToast("Three"); | ||
|
||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public void onTabUnselected(TabLayout.Tab tab) { | ||
|
||
} | ||
|
||
@Override | ||
public void onTabReselected(TabLayout.Tab tab) { | ||
|
||
} | ||
}); | ||
} | ||
|
||
|
||
void showToast(String msg) { | ||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
private void setupViewPager(ViewPager viewPager) { | ||
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); | ||
adapter.addFrag(new DummyFragment(getResources().getColor(R.color.accent_material_light)), "CAT"); | ||
adapter.addFrag(new DummyFragment(getResources().getColor(R.color.ripple_material_light)), "DOG"); | ||
adapter.addFrag(new DummyFragment(getResources().getColor(R.color.button_material_dark)), "MOUSE"); | ||
viewPager.setAdapter(adapter); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.menu_main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case android.R.id.home: | ||
finish(); | ||
return true; | ||
case R.id.action_settings: | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
static class ViewPagerAdapter extends FragmentPagerAdapter { | ||
private final List<Fragment> mFragmentList = new ArrayList<>(); | ||
private final List<String> mFragmentTitleList = new ArrayList<>(); | ||
|
||
public ViewPagerAdapter(FragmentManager manager) { | ||
super(manager); | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
return mFragmentList.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mFragmentList.size(); | ||
} | ||
|
||
public void addFrag(Fragment fragment, String title) { | ||
mFragmentList.add(fragment); | ||
mFragmentTitleList.add(title); | ||
} | ||
|
||
@Override | ||
public CharSequence getPageTitle(int position) { | ||
return mFragmentTitleList.get(position); | ||
} | ||
} | ||
|
||
public static class DummyFragment extends Fragment { | ||
int color; | ||
SimpleRecyclerAdapter adapter; | ||
|
||
public DummyFragment() { | ||
} | ||
|
||
@SuppressLint("ValidFragment") | ||
public DummyFragment(int color) { | ||
this.color = color; | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.dummy_fragment, container, false); | ||
|
||
final FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.dummyfrag_bg); | ||
frameLayout.setBackgroundColor(color); | ||
|
||
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.dummyfrag_scrollableview); | ||
|
||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity().getBaseContext()); | ||
recyclerView.setLayoutManager(linearLayoutManager); | ||
recyclerView.setHasFixedSize(true); | ||
|
||
List<String> list = new ArrayList<String>(); | ||
for (int i = 0; i < VersionModel.data.length; i++) { | ||
list.add(VersionModel.data[i]); | ||
} | ||
|
||
adapter = new SimpleRecyclerAdapter(list); | ||
recyclerView.setAdapter(adapter); | ||
|
||
return view; | ||
} | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
MaterialSample/app/src/main/res/layout/activity_tabs_header.xml
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/htab_maincontent" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:id="@+id/htab_appbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fitsSystemWindows="true" | ||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> | ||
|
||
<android.support.design.widget.CollapsingToolbarLayout | ||
android:id="@+id/htab_collapse_toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="256dp" | ||
android:fitsSystemWindows="true" | ||
app:contentScrim="?attr/colorPrimary" | ||
app:layout_scrollFlags="scroll|exitUntilCollapsed"> | ||
|
||
<ImageView | ||
android:id="@+id/htab_header" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@drawable/header" | ||
android:fitsSystemWindows="true" | ||
android:scaleType="centerCrop" | ||
app:layout_collapseMode="parallax" /> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/htab_toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="104dp" | ||
android:gravity="top" | ||
android:minHeight="?attr/actionBarSize" | ||
app:layout_collapseMode="pin" | ||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" | ||
app:titleMarginTop="13dp" /> | ||
|
||
<android.support.design.widget.TabLayout | ||
android:id="@+id/htab_tabs" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:layout_gravity="bottom" | ||
app:tabIndicatorColor="@android:color/white" /> | ||
|
||
</android.support.design.widget.CollapsingToolbarLayout> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<android.support.v4.view.ViewPager | ||
android:id="@+id/htab_viewpager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
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,7 +1,10 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context="com.suleiman.material.activities.GmailStyleActivity"> | ||
<item android:id="@+id/action_settings" android:title="@string/action_settings" | ||
android:orderInCategory="100" app:showAsAction="never" /> | ||
tools:context="com.suleiman.material.activities.TabsHeaderActivity"> | ||
<item | ||
android:id="@+id/action_settings" | ||
android:orderInCategory="100" | ||
android:title="@string/action_settings" | ||
app:showAsAction="never" /> | ||
</menu> |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context="com.suleiman.material.activities.TabsHeaderActivity"> | ||
|
||
<item | ||
android:id="@+id/action_switch" | ||
android:title="Switch" | ||
app:showAsAction="ifRoom" /> | ||
</menu> |
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