Merge branch 'jpshelley-create_recycler_adapter'
This commit is contained in:
commit
c739b4b736
|
|
@ -1,5 +1,9 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
|
||||
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
|
||||
|
|
@ -20,8 +24,10 @@ android {
|
|||
|
||||
dependencies {
|
||||
compile project(":library")
|
||||
compile 'com.nineoldandroids:library:2.4.0'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.daimajia.easing:library:1.0.0@aar'
|
||||
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
|
||||
compile 'com.nineoldandroids:library:2.4.0'
|
||||
// This dude gave a shoutout to you (daimajia) on his github page:
|
||||
compile 'jp.wasabeef:recyclerview-animators:1.0.3@aar'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.daimajia.swipedemo" >
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.daimajia.swipedemo">
|
||||
|
||||
<uses-sdk tools:overrideLibrary="org.lucasr.twowayview, org.lucasr.twowayview.widget, jp.wasabeef.recyclerview" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.daimajia.swipedemo.MyActivity"
|
||||
android:label="@string/app_name" >
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.daimajia.swipedemo.ListViewExample"/>
|
||||
<activity android:name="com.daimajia.swipedemo.GridViewExample"/>
|
||||
<activity android:name=".NestedExample"/>
|
||||
<activity android:name="com.daimajia.swipedemo.ListViewExample" />
|
||||
<activity android:name="com.daimajia.swipedemo.GridViewExample" />
|
||||
<activity android:name="com.daimajia.swipedemo.RecyclerViewExample" />
|
||||
<activity android:name=".NestedExample" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.widget.AdapterView;
|
|||
import android.widget.GridView;
|
||||
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.GridViewAdapter;
|
||||
|
||||
public class GridViewExample extends Activity{
|
||||
|
|
@ -18,7 +19,7 @@ public class GridViewExample extends Activity{
|
|||
setContentView(R.layout.gridview);
|
||||
final GridView gridView = (GridView)findViewById(R.id.gridview);
|
||||
final GridViewAdapter adapter = new GridViewAdapter(this);
|
||||
adapter.setMode(SwipeItemMangerImpl.Mode.Multiple);
|
||||
adapter.setMode(Attributes.Mode.Multiple);
|
||||
gridView.setAdapter(adapter);
|
||||
gridView.setSelected(false);
|
||||
gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.daimajia.swipedemo;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
|
@ -16,6 +18,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.ListViewAdapter;
|
||||
|
||||
public class ListViewExample extends Activity {
|
||||
|
|
@ -23,11 +26,18 @@ public class ListViewExample extends Activity {
|
|||
private ListView mListView;
|
||||
private ListViewAdapter mAdapter;
|
||||
private Context mContext = this;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.listview);
|
||||
mListView = (ListView)findViewById(R.id.listview);
|
||||
mListView = (ListView) findViewById(R.id.listview);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle("ListView");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The following comment is the sample usage of ArraySwipeAdapter.
|
||||
|
|
@ -40,7 +50,7 @@ public class ListViewExample extends Activity {
|
|||
|
||||
mAdapter = new ListViewAdapter(this);
|
||||
mListView.setAdapter(mAdapter);
|
||||
mAdapter.setMode(SwipeItemMangerImpl.Mode.Single);
|
||||
mAdapter.setMode(Attributes.Mode.Single);
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
|
@ -50,7 +60,7 @@ public class ListViewExample extends Activity {
|
|||
mListView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Log.e("ListView","OnTouch");
|
||||
Log.e("ListView", "OnTouch");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
@ -64,7 +74,7 @@ public class ListViewExample extends Activity {
|
|||
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
Log.e("ListView","onScrollStateChanged");
|
||||
Log.e("ListView", "onScrollStateChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -105,10 +115,14 @@ public class ListViewExample extends Activity {
|
|||
startActivity(new Intent(this, ListViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}else if(id == R.id.action_gridview){
|
||||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
} else if (id == R.id.action_recycler) {
|
||||
startActivity(new Intent(this, RecyclerViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,9 +113,11 @@ public class MyActivity extends Activity {
|
|||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
return true;
|
||||
} else if(id == R.id.action_nexted){
|
||||
} else if (id == R.id.action_nested) {
|
||||
startActivity(new Intent(this, NestedExample.class));
|
||||
return true;
|
||||
} else if (id == R.id.action_recycler) {
|
||||
startActivity(new Intent(this, RecyclerViewExample.class));
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
package com.daimajia.swipedemo;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.RecyclerViewAdapter;
|
||||
import com.daimajia.swipedemo.adapter.util.DividerItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jp.wasabeef.recyclerview.animators.FadeInLeftAnimator;
|
||||
|
||||
public class RecyclerViewExample extends Activity {
|
||||
|
||||
/**
|
||||
* RecyclerView: The new recycler view replaces the list view. Its more modular and therefore we
|
||||
* must implement some of the functionality ourselves and attach it to our recyclerview.
|
||||
* <p/>
|
||||
* 1) Position items on the screen: This is done with LayoutManagers
|
||||
* 2) Animate & Decorate views: This is done with ItemAnimators & ItemDecorators
|
||||
* 3) Handle any touch events apart from scrolling: This is now done in our adapter's ViewHolder
|
||||
*/
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
|
||||
private ArrayList<String> mDataSet;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.recyclerview);
|
||||
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle("RecyclerView");
|
||||
}
|
||||
}
|
||||
|
||||
// Layout Managers:
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
// Item Decorator:
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
|
||||
recyclerView.setItemAnimator(new FadeInLeftAnimator());
|
||||
|
||||
// Adapter:
|
||||
String[] adapterData = new String[]{"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
|
||||
mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
|
||||
mAdapter = new RecyclerViewAdapter(this, mDataSet);
|
||||
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
/* Listeners */
|
||||
recyclerView.setOnScrollListener(onScrollListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitute for our onScrollListener for RecyclerView
|
||||
*/
|
||||
RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
Log.e("ListView", "onScrollStateChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
// Could hide open views here if you wanted. //
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.my, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_listview) {
|
||||
startActivity(new Intent(this, ListViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.daimajia.swipedemo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.androidanimations.library.Techniques;
|
||||
import com.daimajia.androidanimations.library.YoYo;
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.adapters.RecyclerSwipeAdapter;
|
||||
import com.daimajia.swipe.implments.SwipeItemRecyclerMangerImpl;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RecyclerViewAdapter extends RecyclerSwipeAdapter<RecyclerViewAdapter.SimpleViewHolder> {
|
||||
|
||||
public static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
SwipeLayout swipeLayout;
|
||||
TextView textViewPos;
|
||||
TextView textViewData;
|
||||
Button buttonDelete;
|
||||
|
||||
public SimpleViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe);
|
||||
textViewPos = (TextView) itemView.findViewById(R.id.position);
|
||||
textViewData = (TextView) itemView.findViewById(R.id.text_data);
|
||||
buttonDelete = (Button) itemView.findViewById(R.id.delete);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d(getClass().getSimpleName(), "onItemSelected: " + textViewData.getText().toString());
|
||||
Toast.makeText(view.getContext(), "onItemSelected: " + textViewData.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private ArrayList<String> mDataset;
|
||||
|
||||
//protected SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
|
||||
|
||||
public RecyclerViewAdapter(Context context, ArrayList<String> objects) {
|
||||
this.mContext = context;
|
||||
this.mDataset = objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item, parent, false);
|
||||
return new SimpleViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
|
||||
String item = mDataset.get(position);
|
||||
viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
|
||||
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
|
||||
}
|
||||
});
|
||||
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
|
||||
mDataset.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
notifyItemRangeChanged(position, mDataset.size());
|
||||
mItemManger.closeAllItems();
|
||||
Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewData.getText().toString() + "!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
viewHolder.textViewPos.setText((position + 1) + ".");
|
||||
viewHolder.textViewData.setText(item);
|
||||
mItemManger.bindView(viewHolder.itemView, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataset.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwipeLayoutResourceId(int position) {
|
||||
return R.id.swipe;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
package com.daimajia.swipedemo.adapter.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private Drawable mDivider;
|
||||
private boolean mShowFirstDivider = false;
|
||||
private boolean mShowLastDivider = false;
|
||||
|
||||
|
||||
public DividerItemDecoration(Context context, AttributeSet attrs) {
|
||||
final TypedArray a = context
|
||||
.obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider});
|
||||
mDivider = a.getDrawable(0);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public DividerItemDecoration(Context context, AttributeSet attrs, boolean showFirstDivider,
|
||||
boolean showLastDivider) {
|
||||
this(context, attrs);
|
||||
mShowFirstDivider = showFirstDivider;
|
||||
mShowLastDivider = showLastDivider;
|
||||
}
|
||||
|
||||
public DividerItemDecoration(Drawable divider) {
|
||||
mDivider = divider;
|
||||
}
|
||||
|
||||
public DividerItemDecoration(Drawable divider, boolean showFirstDivider,
|
||||
boolean showLastDivider) {
|
||||
this(divider);
|
||||
mShowFirstDivider = showFirstDivider;
|
||||
mShowLastDivider = showLastDivider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
if (mDivider == null) {
|
||||
return;
|
||||
}
|
||||
if (parent.getChildPosition(view) < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
|
||||
outRect.top = mDivider.getIntrinsicHeight();
|
||||
} else {
|
||||
outRect.left = mDivider.getIntrinsicWidth();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
if (mDivider == null) {
|
||||
super.onDrawOver(c, parent, state);
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialization needed to avoid compiler warning
|
||||
int left = 0, right = 0, top = 0, bottom = 0, size;
|
||||
int orientation = getOrientation(parent);
|
||||
int childCount = parent.getChildCount();
|
||||
|
||||
if (orientation == LinearLayoutManager.VERTICAL) {
|
||||
size = mDivider.getIntrinsicHeight();
|
||||
left = parent.getPaddingLeft();
|
||||
right = parent.getWidth() - parent.getPaddingRight();
|
||||
} else { //horizontal
|
||||
size = mDivider.getIntrinsicWidth();
|
||||
top = parent.getPaddingTop();
|
||||
bottom = parent.getHeight() - parent.getPaddingBottom();
|
||||
}
|
||||
|
||||
for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
if (orientation == LinearLayoutManager.VERTICAL) {
|
||||
top = child.getTop() - params.topMargin;
|
||||
bottom = top + size;
|
||||
} else { //horizontal
|
||||
left = child.getLeft() - params.leftMargin;
|
||||
right = left + size;
|
||||
}
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
|
||||
// show last divider
|
||||
if (mShowLastDivider && childCount > 0) {
|
||||
View child = parent.getChildAt(childCount - 1);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
if (orientation == LinearLayoutManager.VERTICAL) {
|
||||
top = child.getBottom() + params.bottomMargin;
|
||||
bottom = top + size;
|
||||
} else { // horizontal
|
||||
left = child.getRight() + params.rightMargin;
|
||||
right = left + size;
|
||||
}
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
|
||||
private int getOrientation(RecyclerView parent) {
|
||||
if (parent.getLayoutManager() instanceof LinearLayoutManager) {
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
|
||||
return layoutManager.getOrientation();
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"DividerItemDecoration can only be used with a LinearLayoutManager.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.daimajia.swipedemo.adapter.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
|
||||
private OnItemClickListener mListener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
public void onItemClick(View view, int position);
|
||||
}
|
||||
|
||||
GestureDetector mGestureDetector;
|
||||
|
||||
public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
|
||||
mListener = listener;
|
||||
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
|
||||
View childView = view.findChildViewUnder(e.getX(), e.getY());
|
||||
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
|
||||
mListener.onItemClick(childView, view.getChildPosition(childView));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<!--
|
||||
~ Copyright (C) 2014 Lucas Rocha
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#cccccc"/>
|
||||
<size android:width="1dp"
|
||||
android:height="1dp" />
|
||||
|
||||
</shape>
|
||||
|
|
@ -1,53 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
xmlns:swipe="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
swipe:horizontalSwipeOffset="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:background="#FF5534"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
android:layout_height="80dp"
|
||||
android:background="#FF5534"
|
||||
android:gravity="center"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp" />
|
||||
android:layout_height="30dp"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/trash" />
|
||||
|
||||
<TextView
|
||||
android:text="Delete Item?"
|
||||
android:textSize="17sp"
|
||||
android:textColor="#fff"
|
||||
android:layout_weight="5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="5"
|
||||
android:text="Delete Item?"
|
||||
android:textColor="#fff"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:textColor="#FF5534"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="4"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:layout_weight="4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp" />
|
||||
android:textColor="#FF5534" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/item_selector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/item_selector"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
|
||||
android:id="@+id/text_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. " />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A RecyclerView with some commonly used attributes -->
|
||||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical" />
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:swipe="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
swipe:horizontalSwipeOffset="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:background="#FF5534"
|
||||
android:gravity="center"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/trash" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="5"
|
||||
android:text="Delete Item?"
|
||||
android:textColor="#fff"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="4"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:textColor="#FF5534" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/item_selector"
|
||||
android:elevation="5dp"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:tag="Hover"/>
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".MyActivity" >
|
||||
<item android:id="@+id/action_listview"
|
||||
android:title="ListView"
|
||||
tools:context=".MyActivity">
|
||||
<item
|
||||
android:id="@+id/action_listview"
|
||||
android:orderInCategory="100"
|
||||
/>
|
||||
<item android:id="@+id/action_gridview"
|
||||
android:title="GridView"
|
||||
android:title="ListView" />
|
||||
<item
|
||||
android:id="@+id/action_gridview"
|
||||
android:orderInCategory="100"
|
||||
/>
|
||||
<item android:id="@+id/action_nexted"
|
||||
android:title="Complicate"/>
|
||||
android:title="GridView" />
|
||||
<item
|
||||
android:id="@+id/action_recycler"
|
||||
android:orderInCategory="100"
|
||||
android:title="RecyclerView" />
|
||||
<item
|
||||
android:id="@+id/action_nested"
|
||||
android:title="Complicate" />
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,6 @@ VERSION_CODE=19
|
|||
GROUP=com.daimajia.swipelayout
|
||||
|
||||
ANDROID_BUILD_MIN_SDK_VERSION=8
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=20
|
||||
ANDROID_BUILD_SDK_VERSION=20
|
||||
ANDROID_BUILD_TOOLS_VERSION=20.0.0
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=21
|
||||
ANDROID_BUILD_SDK_VERSION=21
|
||||
ANDROID_BUILD_TOOLS_VERSION=21.0.0
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
|
|
@ -11,6 +11,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:20.+'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
}
|
||||
apply from: './gradle-mvn-push.gradle'
|
||||
|
|
@ -6,15 +6,17 @@ import android.view.ViewGroup;
|
|||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements SwipeItemMangerInterface,SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
{}
|
||||
public ArraySwipeAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
|
|
@ -67,6 +69,11 @@ public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements Swipe
|
|||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
|
|
@ -88,12 +95,12 @@ public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements Swipe
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,17 @@ import android.view.ViewGroup;
|
|||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
protected SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
protected SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
|
||||
/**
|
||||
* return the {@link com.daimajia.swipe.SwipeLayout} resource id, int the view item.
|
||||
|
|
@ -69,6 +71,11 @@ public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemM
|
|||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
|
|
@ -90,12 +97,12 @@ public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemM
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,17 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
|
||||
protected CursorSwipeAdapter(Context context, Cursor c, boolean autoRequery) {
|
||||
super(context, c, autoRequery);
|
||||
|
|
@ -73,12 +75,12 @@ public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeI
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
package com.daimajia.swipe.adapters;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemRecyclerMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RecyclerSwipeAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
public SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
|
||||
|
||||
@Override
|
||||
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
|
||||
|
||||
@Override
|
||||
public abstract void onBindViewHolder(VH viewHolder, final int position);
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,15 +7,17 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
|
||||
protected SimpleCursorSwipeAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
|
||||
super(context, layout, c, from, to, flags);
|
||||
|
|
@ -73,12 +75,12 @@ public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
|
||||
*/
|
||||
public class SwipeItemAdapterMangerImpl extends SwipeItemMangerImpl{
|
||||
|
||||
protected BaseAdapter mAdapter;
|
||||
|
||||
public SwipeItemAdapterMangerImpl(BaseAdapter adapter) {
|
||||
super(adapter);
|
||||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout) target.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
|
||||
mShownLayouts.add(swipeLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConvertView(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
SwipeLayout swipeLayout = (SwipeLayout) target.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View target, int position){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
|
|
@ -7,6 +8,7 @@ import com.daimajia.swipe.SimpleSwipeListener;
|
|||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -17,9 +19,9 @@ import java.util.Set;
|
|||
/**
|
||||
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
|
||||
*/
|
||||
public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
|
||||
private Mode mode = Mode.Single;
|
||||
private Attributes.Mode mode = Attributes.Mode.Single;
|
||||
public final int INVALID_POSITION = -1;
|
||||
|
||||
protected int mOpenPosition = INVALID_POSITION;
|
||||
|
|
@ -27,96 +29,108 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
protected Set<Integer> mOpenPositions = new HashSet<Integer>();
|
||||
protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();
|
||||
|
||||
protected BaseAdapter mAdapter;
|
||||
protected BaseAdapter mBaseAdapter;
|
||||
protected RecyclerView.Adapter mRecyclerAdapter;
|
||||
|
||||
public SwipeItemMangerImpl(BaseAdapter adapter) {
|
||||
if(adapter == null)
|
||||
if (adapter == null)
|
||||
throw new IllegalArgumentException("Adapter can not be null");
|
||||
|
||||
if(!(adapter instanceof SwipeItemMangerInterface))
|
||||
if (!(adapter instanceof SwipeItemMangerInterface))
|
||||
throw new IllegalArgumentException("adapter should implement the SwipeAdapterInterface");
|
||||
|
||||
this.mAdapter = adapter;
|
||||
this.mBaseAdapter = adapter;
|
||||
}
|
||||
|
||||
public enum Mode{
|
||||
Single, Multiple
|
||||
};
|
||||
public SwipeItemMangerImpl(RecyclerView.Adapter adapter) {
|
||||
if (adapter == null)
|
||||
throw new IllegalArgumentException("Adapter can not be null");
|
||||
|
||||
public Mode getMode(){
|
||||
if (!(adapter instanceof SwipeItemMangerInterface))
|
||||
throw new IllegalArgumentException("adapter should implement the SwipeAdapterInterface");
|
||||
|
||||
this.mRecyclerAdapter = adapter;
|
||||
}
|
||||
|
||||
public Attributes.Mode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(Mode mode){
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
this.mode = mode;
|
||||
mOpenPositions.clear();
|
||||
mShownLayouts.clear();
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
|
||||
public void initialize(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
/* initialize and updateConvertView used for AdapterManagerImpl */
|
||||
public abstract void initialize(View target, int position);
|
||||
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout)target.findViewById(resId);
|
||||
if(swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
public abstract void updateConvertView(View target, int position);
|
||||
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
/* bindView used for RecyclerViewManagerImpl */
|
||||
public abstract void bindView(View target, int position);
|
||||
|
||||
mShownLayouts.add(swipeLayout);
|
||||
}
|
||||
|
||||
public void updateConvertView(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
SwipeLayout swipeLayout = (SwipeLayout)target.findViewById(resId);
|
||||
if(swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
ValueBox valueBox = (ValueBox)swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
|
||||
private int getSwipeLayoutId(int position){
|
||||
return ((SwipeAdapterInterface)(mAdapter)).getSwipeLayoutResourceId(position);
|
||||
public int getSwipeLayoutId(int position) {
|
||||
if (mBaseAdapter != null) {
|
||||
return ((SwipeAdapterInterface) (mBaseAdapter)).getSwipeLayoutResourceId(position);
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
return ((SwipeAdapterInterface) (mRecyclerAdapter)).getSwipeLayoutResourceId(position);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(!mOpenPositions.contains(position))
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
if (!mOpenPositions.contains(position))
|
||||
mOpenPositions.add(position);
|
||||
}else{
|
||||
} else {
|
||||
mOpenPosition = position;
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
if (mBaseAdapter != null) {
|
||||
mBaseAdapter.notifyDataSetChanged();
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
mRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
if(mOpenPosition == position)
|
||||
} else {
|
||||
if (mOpenPosition == position)
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
if (mBaseAdapter != null) {
|
||||
mBaseAdapter.notifyDataSetChanged();
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
mRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
for(SwipeLayout s : mShownLayouts){
|
||||
if(s != layout)
|
||||
for (SwipeLayout s : mShownLayouts) {
|
||||
if (s != layout)
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
mOpenPositions.clear();
|
||||
} else {
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
for (SwipeLayout s : mShownLayouts) {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mShownLayouts.remove(layout);
|
||||
|
|
@ -124,9 +138,9 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
if(mode == Mode.Multiple){
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
return new ArrayList<Integer>(mOpenPositions);
|
||||
}else{
|
||||
} else {
|
||||
return Arrays.asList(mOpenPosition);
|
||||
}
|
||||
}
|
||||
|
|
@ -138,9 +152,9 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
return mOpenPositions.contains(position);
|
||||
}else{
|
||||
} else {
|
||||
return mOpenPosition == position;
|
||||
}
|
||||
}
|
||||
|
|
@ -157,7 +171,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
}
|
||||
}
|
||||
|
||||
class OnLayoutListener implements SwipeLayout.OnLayout{
|
||||
class OnLayoutListener implements SwipeLayout.OnLayout {
|
||||
|
||||
private int position;
|
||||
|
||||
|
|
@ -165,15 +179,15 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
this.position = position;
|
||||
}
|
||||
|
||||
public void setPosition(int position){
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(SwipeLayout v) {
|
||||
if(isOpen(position)){
|
||||
if (isOpen(position)) {
|
||||
v.open(false, false);
|
||||
}else{
|
||||
} else {
|
||||
v.close(false, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -190,23 +204,23 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public void onClose(SwipeLayout layout) {
|
||||
if(mode == Mode.Multiple){
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
} else {
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartOpen(SwipeLayout layout) {
|
||||
if(mode == Mode.Single) {
|
||||
if (mode == Attributes.Mode.Single) {
|
||||
closeAllExcept(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
if (mode == Mode.Multiple)
|
||||
if (mode == Attributes.Mode.Multiple)
|
||||
mOpenPositions.add(position);
|
||||
else {
|
||||
closeAllExcept(layout);
|
||||
|
|
@ -214,7 +228,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
}
|
||||
}
|
||||
|
||||
public void setPosition(int position){
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SwipeItemRecyclerMangerImpl is a helper class to help the RecyclerView to maintain open status.
|
||||
*/
|
||||
public class SwipeItemRecyclerMangerImpl extends SwipeItemMangerImpl{
|
||||
|
||||
protected RecyclerView.Adapter mAdapter;
|
||||
|
||||
public SwipeItemRecyclerMangerImpl(RecyclerView.Adapter adapter) {
|
||||
super(adapter);
|
||||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout) target.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
if (swipeLayout.getTag(resId) == null) {
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
mShownLayouts.add(swipeLayout);
|
||||
} else {
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(View target, int position) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConvertView(View target, int position) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.daimajia.swipe.interfaces;
|
|||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -12,6 +13,8 @@ public interface SwipeItemMangerInterface {
|
|||
public void closeItem(int position);
|
||||
|
||||
public void closeAllExcept(SwipeLayout layout);
|
||||
|
||||
public void closeAllItems();
|
||||
|
||||
public List<Integer> getOpenItems();
|
||||
|
||||
|
|
@ -21,7 +24,7 @@ public interface SwipeItemMangerInterface {
|
|||
|
||||
public boolean isOpen(int position);
|
||||
|
||||
public SwipeItemMangerImpl.Mode getMode();
|
||||
public Attributes.Mode getMode();
|
||||
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode);
|
||||
public void setMode(Attributes.Mode mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.daimajia.swipe.util;
|
||||
|
||||
|
||||
public class Attributes {
|
||||
|
||||
public enum Mode {
|
||||
Single, Multiple
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue