Skip to content

Commit dae16a8

Browse files
committed
Lots of changes to Container class to get it to work with ActionMode. Almost there, but right now touch ups kill the item selected on touch down.
1 parent 013bb46 commit dae16a8

File tree

2 files changed

+710
-108
lines changed

2 files changed

+710
-108
lines changed

CollectionViews2/src/org/freeflow/core/AbsLayoutContainer.java

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import java.util.ArrayList;
44
import java.util.HashMap;
5+
import java.util.Iterator;
6+
import java.util.Map;
57

68
import org.freeflow.layouts.AbstractLayout;
79

810
import android.content.Context;
911
import android.util.AttributeSet;
12+
import android.view.ContextMenu;
1013
import android.view.MotionEvent;
1114
import android.view.View;
1215
import android.view.View.OnTouchListener;
@@ -98,13 +101,13 @@ public final OnItemClickListener getOnItemClickListener() {
98101
* @return True if there was an assigned OnItemClickListener that was
99102
* called, false otherwise is returned.
100103
*/
101-
public boolean performItemClick(View view, ItemProxy proxy) {
104+
public boolean performItemClick(View view, int sectionIndex, int positionInSection, long id) {
102105
if (mOnItemClickListener != null) {
103106
// playSoundEffect(SoundEffectConstants.CLICK);
104107
if (view != null) {
105108
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
106109
}
107-
mOnItemClickListener.onItemClick(this, proxy);
110+
mOnItemClickListener.onItemClick(this, getItemProxyForVisibleItemAt(sectionIndex, positionInSection));
108111
return true;
109112
}
110113

@@ -207,5 +210,86 @@ protected void dispatchLayoutChanging(AbstractLayout oldLayout, AbstractLayout n
207210
listener.onLayoutChanging(oldLayout, newLayout);
208211
}
209212
}
213+
214+
OnItemLongClickListener mOnItemLongClickListener;
215+
216+
/**
217+
* Interface definition for a callback to be invoked when an item in this
218+
* view has been clicked and held.
219+
*/
220+
public interface OnItemLongClickListener {
221+
/**
222+
* Callback method to be invoked when an item in this view has been
223+
* clicked and held.
224+
*
225+
* Implementers can call getItemAtPosition(position) if they need to access
226+
* the data associated with the selected item.
227+
*
228+
* @param parent The AbsListView where the click happened
229+
* @param view The view within the AbsListView that was clicked
230+
* @param position The position of the view in the list
231+
* @param id The row id of the item that was clicked
232+
*
233+
* @return true if the callback consumed the long click, false otherwise
234+
*/
235+
boolean onItemLongClick(AbsLayoutContainer parent, View view, int sectionIndex, int positionInSection, long id);
236+
}
237+
238+
/**
239+
* Register a callback to be invoked when an item in this AdapterView has
240+
* been clicked and held
241+
*
242+
* @param listener The callback that will run
243+
*/
244+
public void setOnItemLongClickListener(OnItemLongClickListener listener) {
245+
if (!isLongClickable()) {
246+
setLongClickable(true);
247+
}
248+
mOnItemLongClickListener = listener;
249+
}
250+
251+
/**
252+
* @return The callback to be invoked with an item in this AdapterView has
253+
* been clicked and held, or null id no callback as been set.
254+
*/
255+
public final OnItemLongClickListener getOnItemLongClickListener() {
256+
return mOnItemLongClickListener;
257+
}
258+
259+
public static class AbsLayoutContainerContextMenuInfo implements ContextMenu.ContextMenuInfo {
260+
261+
public View targetView;
262+
public int sectionIndex;
263+
public int positionInSection;
264+
public long id;
265+
266+
public AbsLayoutContainerContextMenuInfo(View targetView, int sectionIndex, int positionInSection, long id) {
267+
this.targetView = targetView;
268+
this.sectionIndex = sectionIndex;
269+
this.positionInSection = positionInSection;
270+
this.id = id;
271+
}
272+
}
273+
274+
/**
275+
* Returns the ItemProxy instance of a view at position if that
276+
* view is visible or null if thats not currently visible
277+
* @param section The section index of the item
278+
* @param position The position of the item in the particular section
279+
* @return The <code>ItemProxy</code> instance representing that section and index. The proxy is guaranteed to have a view associated with it
280+
*/
281+
public ItemProxy getItemProxyForVisibleItemAt(int section, int position) {
282+
Iterator<?> it = frames.entrySet().iterator();
283+
ItemProxy proxy = null;
284+
while (it.hasNext()) {
285+
Map.Entry<?, ItemProxy> pairs = (Map.Entry<?, ItemProxy>) it.next();
286+
proxy = pairs.getValue();
287+
if (proxy.itemSection == section
288+
&& proxy.itemIndex == position) {
289+
return proxy;
290+
}
291+
}
292+
return null;
293+
}
210294

211295
}

0 commit comments

Comments
 (0)