Use recycler view in beast mode preferences

pull/493/head
Alex Baker 8 years ago
parent b6ab3627f7
commit f30ae42143

@ -14,9 +14,6 @@ import android.util.TypedValue;
import android.view.View;
import android.widget.ListView;
import com.commonsware.cwac.tlv.TouchListView.DropListener;
import com.commonsware.cwac.tlv.TouchListView.GrabberClickListener;
import com.commonsware.cwac.tlv.TouchListView.SwipeListener;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskListFragment;
@ -29,6 +26,9 @@ import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.DraggableListView;
import com.todoroo.astrid.ui.DraggableListView.DropListener;
import com.todoroo.astrid.ui.DraggableListView.GrabberClickListener;
import com.todoroo.astrid.ui.DraggableListView.SwipeListener;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;

@ -1,446 +0,0 @@
/*
* Copyright (c) 2010 CommonsWare, LLC
* Portions Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
package com.commonsware.cwac.tlv;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import org.tasks.R;
public class TouchListView extends ListView {
private ImageView mDragView;
private WindowManager mWindowManager;
private WindowManager.LayoutParams mWindowParams;
private int mDragPos; // which item is being dragged
private int mFirstDragPos; // where was the dragged item originally
private int mDragPoint; // at what offset inside the item did the user grab it
private int mCoordOffset; // the difference between screen coordinates and coordinates in this view
private float mDragStartX;
private DropListener mDropListener;
private int mUpperBound;
private int mLowerBound;
private int mHeight;
private static final int SLIDE_RIGHT = 1;
private static final int SLIDE_LEFT = 2;
private int mRemoveMode = -1;
private final Rect mTempRect = new Rect();
private Bitmap mDragBitmap;
private final int mTouchSlop;
private int mItemHeightNormal=-1;
private int mItemHeightExpanded=-1;
private int grabberId=-1;
private int dragndropBackgroundColor=0x00000000;
private Thread longPressThread;
public TouchListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TouchListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.TouchListView, 0, 0);
mItemHeightNormal = a.getDimensionPixelSize(
R.styleable.TouchListView_normal_height, 0);
mItemHeightExpanded = a.getDimensionPixelSize(
R.styleable.TouchListView_expanded_height,
mItemHeightNormal);
grabberId = a.getResourceId(R.styleable.TouchListView_grabber, -1);
dragndropBackgroundColor = a.getColor(
R.styleable.TouchListView_dragndrop_background, 0x00000000);
mRemoveMode = a.getInt(R.styleable.TouchListView_remove_mode, -1);
a.recycle();
}
}
@Override
final public void addHeaderView (View v, Object data, boolean isSelectable) {
throw new RuntimeException("Headers are not supported with TouchListView");
}
@Override
final public void addHeaderView (View v) {
throw new RuntimeException("Headers are not supported with TouchListView");
}
@Override
final public void addFooterView (View v, Object data, boolean isSelectable) {
if (mRemoveMode == SLIDE_LEFT || mRemoveMode == SLIDE_RIGHT) {
throw new RuntimeException("Footers are not supported with TouchListView in conjunction with remove_mode");
}
}
@Override
final public void addFooterView (View v) {
if (mRemoveMode == SLIDE_LEFT || mRemoveMode == SLIDE_RIGHT) {
throw new RuntimeException("Footers are not supported with TouchListView in conjunction with remove_mode");
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mDropListener != null) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
int x = (int) ev.getX();
int y = (int) ev.getY();
int itemnum = pointToPosition(x, y);
if (itemnum == AdapterView.INVALID_POSITION) {
break;
}
View item = getChildAt(itemnum - getFirstVisiblePosition());
if (isDraggableRow(item)) {
mDragPoint = y - item.getTop();
mCoordOffset = ((int)ev.getRawY()) - y;
View dragger = item.findViewById(grabberId);
Rect r = mTempRect;
// dragger.getDrawingRect(r);
r.left=dragger.getLeft();
r.right=dragger.getRight();
r.top=dragger.getTop();
r.bottom=dragger.getBottom();
if ((r.left<x) && (x<r.right)) {
item.setDrawingCacheEnabled(true);
// Create a copy of the drawing cache so that it does not get recycled
// by the framework when the list tries to clean up memory
Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
item.setDrawingCacheEnabled(false);
Rect listBounds=new Rect();
getGlobalVisibleRect(listBounds, null);
startDragging(bitmap, listBounds.left, y);
mDragPos = itemnum;
mFirstDragPos = mDragPos;
mHeight = getHeight();
mDragStartX = ev.getX();
int touchSlop = mTouchSlop;
mUpperBound = Math.min(y - touchSlop, mHeight / 3);
mLowerBound = Math.max(y + touchSlop, mHeight * 2 /3);
return false;
}
mDragView = null;
}
break;
}
}
return super.onInterceptTouchEvent(ev);
}
private boolean isDraggableRow(View view) {
return(view.findViewById(grabberId)!=null);
}
/*
* pointToPosition() doesn't consider invisible views, but we
* need to, so implement a slightly different version.
*/
private int myPointToPosition(int x, int y) {
Rect frame = mTempRect;
final int count = getChildCount();
for (int i = count - 1; i >= 0; i--) {
final View child = getChildAt(i);
child.getHitRect(frame);
if (frame.contains(x, y)) {
return getFirstVisiblePosition() + i;
}
}
return INVALID_POSITION;
}
private int getItemForPosition(int y) {
int adjustedy = y - mDragPoint - (mItemHeightNormal/2);
int pos = myPointToPosition(0, adjustedy);
if (pos >= 0) {
if (pos <= mFirstDragPos) {
pos += 1;
}
} else if (adjustedy < 0) {
pos = 0;
}
return pos;
}
private void adjustScrollBounds(int y) {
if (y >= mHeight / 3) {
mUpperBound = mHeight / 3;
}
if (y <= mHeight * 2 / 3) {
mLowerBound = mHeight * 2 / 3;
}
}
/*
* Restore size and visibility for all listitems
*/
private void unExpandViews(boolean deletion) {
for (int i = 0;; i++) {
View v = getChildAt(i);
if (v == null) {
if (deletion) {
// HACK force update of mItemCount
int position = getFirstVisiblePosition();
int y = getChildAt(0).getTop();
setAdapter(getAdapter());
setSelectionFromTop(position, y);
// end hack
}
layoutChildren(); // force children to be recreated where needed
v = getChildAt(i);
if (v == null) {
break;
}
}
if (isDraggableRow(v)) {
ViewGroup.LayoutParams params = v.getLayoutParams();
params.height = mItemHeightNormal;
v.setLayoutParams(params);
v.setVisibility(View.VISIBLE);
}
}
}
/* Adjust visibility and size to make it appear as though
* an item is being dragged around and other items are making
* room for it:
* If dropping the item would result in it still being in the
* same place, then make the dragged listitem's size normal,
* but make the item invisible.
* Otherwise, if the dragged listitem is still on screen, make
* it as small as possible and expand the item below the insert
* point.
* If the dragged item is not on screen, only expand the item
* below the current insertpoint.
*/
private void doExpansion() {
int childnum = mDragPos - getFirstVisiblePosition();
if (mDragPos > mFirstDragPos) {
childnum++;
}
View first = getChildAt(mFirstDragPos - getFirstVisiblePosition());
for (int i = 0;; i++) {
View vv = getChildAt(i);
if (vv == null) {
break;
}
int height = mItemHeightNormal;
int visibility = View.VISIBLE;
if (vv.equals(first)) {
// processing the item that is being dragged
if (mDragPos == mFirstDragPos) {
// hovering over the original location
visibility = View.INVISIBLE;
} else {
// not hovering over it
height = 1;
}
} else if (i == childnum) {
if (mDragPos < getCount() - 1) {
height = mItemHeightExpanded;
}
}
if (isDraggableRow(vv)) {
ViewGroup.LayoutParams params = vv.getLayoutParams();
params.height = height;
vv.setLayoutParams(params);
vv.setVisibility(visibility);
}
}
// Request re-layout since we changed the items layout
// and not doing this would cause bogus hitbox calculation
// in myPointToPosition
layoutChildren();
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if ((mDropListener != null) && mDragView != null) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Rect r = mTempRect;
mDragView.getDrawingRect(r);
stopDragging();
if (mDragPos == mFirstDragPos && ev.getX() > mDragStartX + 20) {
unExpandViews(true);
} else if (mDragPos == mFirstDragPos && ev.getX() < mDragStartX - 20) {
unExpandViews(true);
} else {
if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
mDropListener.drop(mFirstDragPos, mDragPos);
}
unExpandViews(false);
}
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
int x = (int) ev.getX();
int y = (int) ev.getY();
dragView(x, y);
int itemnum = getItemForPosition(y);
if (itemnum >= 0) {
if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
mDragPos = itemnum;
doExpansion();
}
int speed = 0;
adjustScrollBounds(y);
if (y > mLowerBound) {
// scroll the list up a bit
speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
} else if (y < mUpperBound) {
// scroll the list down a bit
speed = y < mUpperBound / 2 ? -16 : -4;
}
if (speed != 0) {
int ref = pointToPosition(0, mHeight / 2);
if (ref == AdapterView.INVALID_POSITION) {
//we hit a divider or an invisible view, check somewhere else
ref = pointToPosition(0, mHeight / 2 + getDividerHeight() + 64);
}
View v = getChildAt(ref - getFirstVisiblePosition());
if (v!= null) {
int pos = v.getTop();
setSelectionFromTop(ref, pos - speed);
}
}
}
break;
}
return true;
}
return super.onTouchEvent(ev);
}
private void startDragging(Bitmap bm, int x, int y) {
stopDragging();
mWindowParams = new WindowManager.LayoutParams();
mWindowParams.gravity = Gravity.TOP|Gravity.START;
mWindowParams.x = x;
mWindowParams.y = y - mDragPoint + mCoordOffset;
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
ImageView v = new ImageView(getContext());
v.setBackgroundColor(dragndropBackgroundColor);
v.setImageBitmap(bm);
mDragBitmap = bm;
mWindowManager = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(v, mWindowParams);
mDragView = v;
}
private void dragView(int x, int y) {
float alpha = 1.0f;
int width = mDragView.getWidth();
if (mRemoveMode == SLIDE_RIGHT) {
if (x > width / 2) {
alpha = ((float)(width - x)) / (width / 2);
}
mWindowParams.alpha = alpha;
}
else if (mRemoveMode == SLIDE_LEFT) {
if (x < width / 2) {
alpha = ((float)x) / (width / 2);
}
mWindowParams.alpha = alpha;
}
mWindowParams.y = y - mDragPoint + mCoordOffset;
mWindowManager.updateViewLayout(mDragView, mWindowParams);
}
private void stopDragging() {
if (mDragBitmap != null) {
mDragBitmap.recycle();
mDragBitmap = null;
}
if (mDragView != null) {
WindowManager wm = (WindowManager) getContext().getSystemService(
Context.WINDOW_SERVICE);
wm.removeView(mDragView);
mDragView.setImageDrawable(null);
mDragView = null;
}
if(longPressThread != null) {
longPressThread.interrupt();
longPressThread = null;
}
}
public void setDropListener(DropListener l) {
mDropListener = l;
}
public interface GrabberClickListener {
void onClick(View v);
void onLongClick(View v);
}
public interface DropListener {
void drop(int from, int to);
}
public interface SwipeListener {
void swipeLeft(int which);
void swipeRight(int which);
}
}

@ -6,49 +6,44 @@
package com.todoroo.astrid.activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.commonsware.cwac.tlv.TouchListView;
import com.google.common.base.Strings;
import org.tasks.R;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import org.tasks.preferences.beast.BeastModeRecyclerAdapter;
import org.tasks.ui.MenuColorizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import static android.R.id.list;
import static java.util.Arrays.asList;
public class BeastModePreferences extends ThemedInjectingAppCompatActivity implements Toolbar.OnMenuItemClickListener {
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(android.R.id.list) TouchListView touchList;
private ArrayAdapter<String> adapter;
private ArrayList<String> items;
@BindView(list) RecyclerView recyclerView;
private static final String BEAST_MODE_ORDER_PREF = "beast_mode_order_v3"; //$NON-NLS-1$
private static final String BEAST_MODE_PREF_ITEM_SEPARATOR = ";"; //$NON-NLS-1$
private static final String BEAST_MODE_PREF_ITEM_SEPARATOR = ";";
private HashMap<String, String> prefsToDescriptions;
private BeastModeRecyclerAdapter adapter;
@Inject Preferences preferences;
@ -65,28 +60,10 @@ public class BeastModePreferences extends ThemedInjectingAppCompatActivity imple
toolbar.setOnMenuItemClickListener(this);
MenuColorizer.colorToolbar(this, toolbar);
prefsToDescriptions = new HashMap<>();
buildDescriptionMap(getResources());
items = constructOrderedControlList(preferences, this);
adapter = new ArrayAdapter<String>(this, R.layout.preference_draggable_row, R.id.text, items) {
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView display = (TextView) v.findViewById(R.id.text);
display.setText(prefsToDescriptions.get(getItem(position)));
return v;
}
};
touchList.setAdapter(adapter);
touchList.setOnTouchListener((v, event) -> false);
touchList.setDropListener((from, to) -> {
String s = items.remove(from);
items.add(to, s);
adapter.notifyDataSetChanged();
});
adapter = new BeastModeRecyclerAdapter(this, constructOrderedControlList(preferences, this));
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter.applyToRecyclerView(recyclerView);
}
@Override
@ -98,35 +75,20 @@ public class BeastModePreferences extends ThemedInjectingAppCompatActivity imple
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_reset_to_defaults:
resetToDefault();
String[] prefsArray = getResources().getStringArray(R.array.TEA_control_sets_prefs);
adapter.setItems(asList(prefsArray));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void buildDescriptionMap(Resources r) {
String[] keys = r.getStringArray(R.array.TEA_control_sets_prefs);
String[] descriptions = r.getStringArray(R.array.TEA_control_sets_beast);
for (int i = 0; i < keys.length && i < descriptions.length; i++) {
prefsToDescriptions.put(keys[i], descriptions[i]);
}
}
private void resetToDefault() {
String[] prefsArray = getResources().getStringArray(R.array.TEA_control_sets_prefs);
while (items.size() > 0) {
items.remove(0);
}
Collections.addAll(items, prefsArray);
adapter.notifyDataSetChanged();
}
@Override
public void finish() {
List<String> items = adapter.getItems();
StringBuilder newSetting = new StringBuilder();
for (int i = 0; i < adapter.getCount(); i++) {
newSetting.append(adapter.getItem(i));
for (int i = 0; i < items.size(); i++) {
newSetting.append(items.get(i));
newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
}
String oldValue = preferences.getStringValue(BEAST_MODE_ORDER_PREF);

@ -9,9 +9,6 @@ import android.util.TypedValue;
import android.view.View;
import android.widget.ListView;
import com.commonsware.cwac.tlv.TouchListView.DropListener;
import com.commonsware.cwac.tlv.TouchListView.GrabberClickListener;
import com.commonsware.cwac.tlv.TouchListView.SwipeListener;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
@ -27,6 +24,9 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.DraggableListView;
import com.todoroo.astrid.ui.DraggableListView.DropListener;
import com.todoroo.astrid.ui.DraggableListView.GrabberClickListener;
import com.todoroo.astrid.ui.DraggableListView.SwipeListener;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;

@ -35,9 +35,6 @@ import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import com.commonsware.cwac.tlv.TouchListView.DropListener;
import com.commonsware.cwac.tlv.TouchListView.GrabberClickListener;
import com.commonsware.cwac.tlv.TouchListView.SwipeListener;
import com.todoroo.astrid.utility.Flags;
import org.tasks.R;
@ -518,4 +515,16 @@ public class DraggableListView extends ListView {
"Headers are not supported with TouchListView");
}
public interface GrabberClickListener {
void onClick(View v);
void onLongClick(View v);
}
public interface DropListener {
void drop(int from, int to);
}
public interface SwipeListener {
void swipeLeft(int which);
void swipeRight(int which);
}
}

@ -0,0 +1,96 @@
package org.tasks.preferences.beast;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.tasks.R;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class BeastModeRecyclerAdapter extends RecyclerView.Adapter<BeastModeViewHolder> {
private final List<String> items = new ArrayList<>();
private final HashMap<String, String> prefsToDescriptions = new HashMap<>();
private final ItemTouchHelper itemTouchHelper;
public BeastModeRecyclerAdapter(Context context, List<String> items) {
this.items.addAll(items);
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback());
buildDescriptionMap(context.getResources());
}
public void applyToRecyclerView(RecyclerView recyclerView) {
recyclerView.setAdapter(this);
itemTouchHelper.attachToRecyclerView(recyclerView);
}
public List<String> getItems() {
return items;
}
public void setItems(List<String> items) {
this.items.clear();
this.items.addAll(items);
notifyDataSetChanged();
}
@Override
public BeastModeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.preference_draggable_row, parent, false);
return new BeastModeViewHolder(view, itemTouchHelper);
}
@Override
public void onBindViewHolder(final BeastModeViewHolder holder, int position) {
String key = items.get(position);
String value = prefsToDescriptions.get(key);
holder.setText(value);
}
@Override
public int getItemCount() {
return items.size();
}
private void buildDescriptionMap(Resources r) {
String[] keys = r.getStringArray(R.array.TEA_control_sets_prefs);
String[] descriptions = r.getStringArray(R.array.TEA_control_sets_beast);
for (int i = 0; i < keys.length && i < descriptions.length; i++) {
prefsToDescriptions.put(keys[i], descriptions[i]);
}
}
private class ItemTouchHelperCallback extends ItemTouchHelper.Callback {
@Override
public boolean isItemViewSwipeEnabled() {
return false;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder from, RecyclerView.ViewHolder to) {
int fromPosition = from.getAdapterPosition();
int toPosition = to.getAdapterPosition();
Collections.swap(items, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
}
}
}

@ -0,0 +1,38 @@
package org.tasks.preferences.beast;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import org.tasks.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnTouch;
class BeastModeViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.text) TextView textView;
private final ItemTouchHelper itemTouchHelper;
BeastModeViewHolder(View itemView, ItemTouchHelper itemTouchHelper) {
super(itemView);
this.itemTouchHelper = itemTouchHelper;
ButterKnife.bind(this, itemView);
}
void setText(String text) {
textView.setText(text);
}
@OnTouch(R.id.grabber)
boolean onTouch(View view, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
itemTouchHelper.startDrag(this);
}
return false;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 728 B

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M20,9H4v2h16V9zM4,15h16v-2H4v2z"/>
</vector>

@ -1,9 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -12,18 +7,9 @@
<include layout="@layout/toolbar" />
<com.commonsware.cwac.tlv.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/org.tasks"
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:scrollbars="vertical"
android:cacheColorHint="#00000000"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"
tlv:normal_height="52dip"
tlv:grabber="@+id/row_body" />
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

@ -1,39 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="52dip"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="4dip"
android:paddingRight="4dip"
android:orientation="horizontal">
<!-- grabber -->
<LinearLayout
android:id="@+id/row_body"
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight"
android:layout_margin="8dp"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardCornerRadius="2dp">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView android:id="@+id/grabber"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/grabber"/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingRight="0dp"
android:paddingEnd="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
</LinearLayout>
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/keyline_first"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_first"
android:layout_marginStart="@dimen/keyline_first"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/grabber"
android:layout_width="?listPreferredItemHeight"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:scaleType="center"
android:src="@drawable/ic_drag_handle_black_24dp"
android:tint="?attr/icon_tint" />
</android.support.v7.widget.CardView>
Loading…
Cancel
Save