Skip to content

Commit

Permalink
updated flexible space pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Suleiman56060 committed Mar 6, 2017
1 parent 5668b3b commit 2942ac5
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 57 deletions.
25 changes: 1 addition & 24 deletions MaterialSample/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
Expand Down Expand Up @@ -47,63 +46,40 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.amulyakhare/com.amulyakhare.textdrawable/1.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-utils/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-fragment/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/transition/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.ozodrukh/CircularReveal/1.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.schibsted.spain/parallax-layer-layout/1.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
Expand All @@ -118,6 +94,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@
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;
import com.suleiman.material.adapter.DessertAdapter;

public class AnimateToolbar extends AppCompatActivity {

private CollapsingToolbarLayout collapsingToolbar;
private AppBarLayout appBarLayout;
private RecyclerView recyclerView;

private SimpleRecyclerAdapter simpleRecyclerAdapter;
private DessertAdapter dessertAdapter;

private Menu collapsedMenu;
private boolean appBarExpanded = true;
Expand All @@ -42,12 +38,13 @@ protected void onCreate(Bundle savedInstanceState) {

final Toolbar toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

appBarLayout = (AppBarLayout) findViewById(R.id.appbar);

collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setTitle("Suleiman Ali Shakir");
collapsingToolbar.setTitle(getString(R.string.android_desserts));

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.header);
Expand All @@ -64,25 +61,14 @@ public void onGenerated(Palette palette) {

recyclerView = (RecyclerView) findViewById(R.id.scrollableview);

// Use when your list size is constant for better performance
recyclerView.setHasFixedSize(true);

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);

// Create fake list data
List<String> listData = new ArrayList<String>();
int ct = 0;
for (int i = 0; i < VersionModel.data.length * 2; i++) {
listData.add(VersionModel.data[ct]);
ct++;
if (ct == VersionModel.data.length) {
ct = 0;
}
}

if (simpleRecyclerAdapter == null) {
simpleRecyclerAdapter = new SimpleRecyclerAdapter(listData);
recyclerView.setAdapter(simpleRecyclerAdapter);
}
dessertAdapter = new DessertAdapter(this);
recyclerView.setAdapter(dessertAdapter);

appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
Expand All @@ -106,7 +92,8 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {

if (!appBarExpanded || collapsedMenu.size() != 1) {
if (collapsedMenu != null
&& (!appBarExpanded || collapsedMenu.size() != 1)) {
//collapsed
collapsedMenu.add("Add")
.setIcon(R.drawable.ic_action_add)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.suleiman.material.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.suleiman.material.R;
import com.suleiman.material.model.Dessert;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Suleiman on 02/03/17.
*/

public class DessertAdapter extends RecyclerView.Adapter<DessertAdapter.DessertVh> {


private List<Dessert> desserts = new ArrayList<>();

private Context context;

public DessertAdapter(Context context) {
this.context = context;

desserts = Dessert.prepareDesserts(
context.getResources().getStringArray(R.array.dessert_names),
context.getResources().getStringArray(R.array.dessert_descriptions));
}

@Override
public DessertVh onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.item_dessert, parent, false);
return new DessertAdapter.DessertVh(view);
}

@Override
public void onBindViewHolder(DessertVh holder, int position) {
Dessert dessert = desserts.get(position);

holder.mName.setText(dessert.getName());
holder.mDescription.setText(dessert.getDescription());
holder.mFirstLetter.setText(String.valueOf(dessert.getFirstLetter()));

}

@Override
public int getItemCount() {
return desserts == null ? 0 : desserts.size();
}

public static class DessertVh extends RecyclerView.ViewHolder {

private TextView mName;
private TextView mDescription;
private TextView mFirstLetter;

public DessertVh(View itemView) {
super(itemView);

mName = (TextView) itemView.findViewById(R.id.txt_name);
mDescription = (TextView) itemView.findViewById(R.id.txt_desc);
mFirstLetter = (TextView) itemView.findViewById(R.id.txt_firstletter);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.suleiman.material.model;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Suleiman on 02/03/17.
*/

public class Dessert {

private String name;
private String description;
private String firstLetter;

public Dessert(String name, String description) {
this.name = name;
this.firstLetter = String.valueOf(name.charAt(0));
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getFirstLetter() {
return firstLetter;
}

public void setFirstLetter(String firstLetter) {
this.firstLetter = firstLetter;
}

public static List<Dessert> prepareDesserts(String[] names, String[] descriptions) {
List<Dessert> desserts = new ArrayList<>(names.length);

for (int i = 0; i < names.length; i++) {
Dessert dessert = new Dessert(names[i], descriptions[i]);
desserts.add(dessert);
}

return desserts;
}
}
8 changes: 8 additions & 0 deletions MaterialSample/app/src/main/res/drawable/scrim.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="#66000000"/>
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginStart="@dimen/activity_margin_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

<ImageView
Expand All @@ -31,6 +30,12 @@
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<View
android:layout_width="match_parent"
android:layout_height="128dp"
android:layout_gravity="bottom"
android:background="@drawable/scrim"/>

<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
Expand All @@ -57,6 +62,7 @@
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:src="@drawable/ic_action_add"
app:backgroundTint="#279AF1"
app:layout_anchor="@+id/appbar"
app:layout_anchorGravity="bottom|right|end"/>

Expand Down
67 changes: 67 additions & 0 deletions MaterialSample/app/src/main/res/layout/item_dessert.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:orientation="horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_horizontal_margin"
tools:background="@android:color/white"
tools:ignore="RtlSymmetry">

<TextView
android:id="@+id/txt_firstletter"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="40dp"
android:layout_height="40dp"
android:alpha="0.30"
android:gravity="center"
android:textStyle="bold"
tools:text="N"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/txt_name"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
tools:targetApi="jelly_bean"
tools:text="Nougat"/>

<TextView
android:id="@+id/txt_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_margin_half"
android:ellipsize="end"
android:maxLines="2"
tools:text="A family of confections made with sugar or honey, roasted nuts, whipped egg whites, and sometimes chopped candied fruit. The consistency of nougat is chewy, and it is used in a variety of candy bars and chocolates."/>


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.12"
android:background="@android:color/black"/>

</LinearLayout>

</LinearLayout>
Loading

0 comments on commit 2942ac5

Please sign in to comment.