|
2 | 2 |
|
3 | 3 | import java.util.ArrayList;
|
4 | 4 | import java.util.HashMap;
|
| 5 | +import java.util.Iterator; |
| 6 | +import java.util.Map; |
5 | 7 |
|
6 | 8 | import org.freeflow.layouts.AbstractLayout;
|
7 | 9 |
|
8 | 10 | import android.content.Context;
|
9 | 11 | import android.util.AttributeSet;
|
| 12 | +import android.view.ContextMenu; |
10 | 13 | import android.view.MotionEvent;
|
11 | 14 | import android.view.View;
|
12 | 15 | import android.view.View.OnTouchListener;
|
@@ -98,13 +101,13 @@ public final OnItemClickListener getOnItemClickListener() {
|
98 | 101 | * @return True if there was an assigned OnItemClickListener that was
|
99 | 102 | * called, false otherwise is returned.
|
100 | 103 | */
|
101 |
| - public boolean performItemClick(View view, ItemProxy proxy) { |
| 104 | + public boolean performItemClick(View view, int sectionIndex, int positionInSection, long id) { |
102 | 105 | if (mOnItemClickListener != null) {
|
103 | 106 | // playSoundEffect(SoundEffectConstants.CLICK);
|
104 | 107 | if (view != null) {
|
105 | 108 | view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
|
106 | 109 | }
|
107 |
| - mOnItemClickListener.onItemClick(this, proxy); |
| 110 | + mOnItemClickListener.onItemClick(this, getItemProxyForVisibleItemAt(sectionIndex, positionInSection)); |
108 | 111 | return true;
|
109 | 112 | }
|
110 | 113 |
|
@@ -207,5 +210,86 @@ protected void dispatchLayoutChanging(AbstractLayout oldLayout, AbstractLayout n
|
207 | 210 | listener.onLayoutChanging(oldLayout, newLayout);
|
208 | 211 | }
|
209 | 212 | }
|
| 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 | + } |
210 | 294 |
|
211 | 295 | }
|
0 commit comments