diff --git a/demo/build.gradle b/demo/build.gradle index 1f045dc..4d41eed 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -20,5 +20,6 @@ android { dependencies { compile project(':library') - compile 'com.android.support:appcompat-v7:21.0.3' + compile 'com.android.support:appcompat-v7:22.0.0' + compile 'com.android.support:recyclerview-v7:22.0.0' } diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index fab0085..3cdd73d 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -20,6 +20,10 @@ android:name=".DemoListActivity" android:label="@string/app_name"> + + diff --git a/demo/src/main/java/com/balysv/materialripple/demo/DemoActivity.java b/demo/src/main/java/com/balysv/materialripple/demo/DemoActivity.java index 42b5111..0597f4d 100644 --- a/demo/src/main/java/com/balysv/materialripple/demo/DemoActivity.java +++ b/demo/src/main/java/com/balysv/materialripple/demo/DemoActivity.java @@ -40,7 +40,7 @@ protected void onCreate(Bundle savedInstanceState) { } @Override public boolean onLongClick(View v) { - if(v.getId()==R.id.ripple_layout_1){ + if (v.getId() == R.id.ripple_layout_1) { Toast.makeText(this, "Long click not consumed", Toast.LENGTH_SHORT).show(); return false; } @@ -50,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_list, menu); + getMenuInflater().inflate(R.menu.menu_button, menu); return true; } @@ -61,6 +61,10 @@ public boolean onOptionsItemSelected(MenuItem item) { startActivity(new Intent(this, DemoListActivity.class)); finish(); return true; + } else if (id == R.id.switch_recycler) { + startActivity(new Intent(this, DemoRecyclerActivity.class)); + finish(); + return true; } return super.onOptionsItemSelected(item); } diff --git a/demo/src/main/java/com/balysv/materialripple/demo/DemoListActivity.java b/demo/src/main/java/com/balysv/materialripple/demo/DemoListActivity.java index 0ce2198..327b676 100644 --- a/demo/src/main/java/com/balysv/materialripple/demo/DemoListActivity.java +++ b/demo/src/main/java/com/balysv/materialripple/demo/DemoListActivity.java @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_button, menu); + getMenuInflater().inflate(R.menu.menu_list, menu); return true; } @@ -60,6 +60,10 @@ public boolean onOptionsItemSelected(MenuItem item) { startActivity(new Intent(this, DemoActivity.class)); finish(); return true; + } else if (id == R.id.switch_recycler) { + startActivity(new Intent(this, DemoRecyclerActivity.class)); + finish(); + return true; } return super.onOptionsItemSelected(item); } diff --git a/demo/src/main/java/com/balysv/materialripple/demo/DemoRecyclerActivity.java b/demo/src/main/java/com/balysv/materialripple/demo/DemoRecyclerActivity.java new file mode 100644 index 0000000..f37f5be --- /dev/null +++ b/demo/src/main/java/com/balysv/materialripple/demo/DemoRecyclerActivity.java @@ -0,0 +1,117 @@ +package com.balysv.materialripple.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +import com.balysv.materialripple.MaterialRippleLayout; + +import java.util.UUID; + +public class DemoRecyclerActivity extends ActionBarActivity { + + private final static String[] data; + + static { + data = new String[50]; + for (int i = 0; i < data.length; i++) { + data[i] = UUID.randomUUID().toString(); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.demo_recycler); + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setAdapter(new MyAdapter()); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_recycler, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.switch_button) { + startActivity(new Intent(this, DemoActivity.class)); + finish(); + return true; + } else if (id == R.id.switch_list) { + startActivity(new Intent(this, DemoListActivity.class)); + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private static class MyAdapter extends RecyclerView.Adapter { + + @Override + public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext()); + return new MyViewHolder( + MaterialRippleLayout.on(inflater.inflate(R.layout.demo_recycler_item, viewGroup, false)) + .rippleOverlay(true) + .rippleAlpha(0.2f) + .rippleColor(0xFF585858) + .rippleHover(true) + .create() + ); + } + + @Override + public void onBindViewHolder(MyViewHolder viewHolder, int i) { + viewHolder.text.setText(data[i]); + } + + @Override + public int getItemCount() { + return data.length; + } + } + + private static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, + View.OnLongClickListener { + + TextView text; + + public MyViewHolder(View itemView) { + super(itemView); + text = (TextView) itemView.findViewById(android.R.id.text1); + itemView.setOnClickListener(this); + itemView.setOnLongClickListener(this); + } + + @Override + public void onClick(View v) { + Toast.makeText(v.getContext(), "Rippled item: " + getAdapterPosition(), Toast.LENGTH_SHORT).show(); + } + + @Override + public boolean onLongClick(View v) { + if (getAdapterPosition() % 2 == 0) { + Toast.makeText(v.getContext(), "long item: " + getAdapterPosition() + " and not consumed", + Toast.LENGTH_SHORT) + .show(); + return false; + } + Toast.makeText(v.getContext(), "long item: " + getAdapterPosition() + " and consumed", Toast.LENGTH_SHORT) + .show(); + return true; + } + } +} diff --git a/demo/src/main/res/layout/demo_list_item.xml b/demo/src/main/res/layout/demo_list_item.xml index 8c860b8..0b16462 100644 --- a/demo/src/main/res/layout/demo_list_item.xml +++ b/demo/src/main/res/layout/demo_list_item.xml @@ -1,26 +1,24 @@ - + app:mrl_rippleColor="#585858" + app:mrl_rippleHover="true" + app:mrl_rippleOverlay="true"> + android:singleLine="true" + android:textSize="20sp" /> \ No newline at end of file diff --git a/demo/src/main/res/layout/demo_recycler.xml b/demo/src/main/res/layout/demo_recycler.xml new file mode 100644 index 0000000..d2934f3 --- /dev/null +++ b/demo/src/main/res/layout/demo_recycler.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/demo/src/main/res/layout/demo_recycler_item.xml b/demo/src/main/res/layout/demo_recycler_item.xml new file mode 100644 index 0000000..64e4251 --- /dev/null +++ b/demo/src/main/res/layout/demo_recycler_item.xml @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/demo/src/main/res/menu/menu_button.xml b/demo/src/main/res/menu/menu_button.xml index 245ebdb..f9ac030 100644 --- a/demo/src/main/res/menu/menu_button.xml +++ b/demo/src/main/res/menu/menu_button.xml @@ -4,7 +4,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + android:title="@string/switch_list"/> + + \ No newline at end of file diff --git a/demo/src/main/res/menu/menu_list.xml b/demo/src/main/res/menu/menu_list.xml index ef2b26d..af55862 100644 --- a/demo/src/main/res/menu/menu_list.xml +++ b/demo/src/main/res/menu/menu_list.xml @@ -4,7 +4,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + android:title="@string/switch_button"/> + + \ No newline at end of file diff --git a/demo/src/main/res/menu/menu_recycler.xml b/demo/src/main/res/menu/menu_recycler.xml new file mode 100644 index 0000000..6faaf99 --- /dev/null +++ b/demo/src/main/res/menu/menu_recycler.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml index 1e537ff..c453b51 100644 --- a/demo/src/main/res/values/strings.xml +++ b/demo/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ Material Ripple Demo - Switch to ListView - Switch to Buttons + ListView + Buttons + RecyclerView