-
Notifications
You must be signed in to change notification settings - Fork 135
Add some Function #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zgbdsg
wants to merge
2
commits into
frankiesardo:master
Choose a base branch
from
zgbdsg:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,13 @@ | |
| import android.content.Context; | ||
| import android.content.res.TypedArray; | ||
| import android.database.DataSetObserver; | ||
| import android.graphics.drawable.ColorDrawable; | ||
| import android.graphics.drawable.Drawable; | ||
| import android.util.AttributeSet; | ||
| import android.util.Log; | ||
| import android.view.SoundEffectConstants; | ||
| import android.view.View; | ||
| import android.widget.ArrayAdapter; | ||
| import android.widget.BaseAdapter; | ||
| import android.widget.ListAdapter; | ||
| import android.widget.WrapperListAdapter; | ||
|
|
||
| import com.linearlistview.internal.IcsLinearLayout; | ||
|
|
||
| /** | ||
| * An extension of a linear layout that supports the divider API of Android | ||
|
|
@@ -30,9 +27,11 @@ public class LinearListView extends IcsLinearLayout { | |
| private static final int LinearListView_dividerThickness = 1; | ||
|
|
||
| private View mEmptyView; | ||
| private ListAdapter mAdapter; | ||
| // private ListAdapter mAdapter; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not commit commented out code. |
||
| private BaseAdapter mAdapter; | ||
| private boolean mAreAllItemsSelectable; | ||
| private OnItemClickListener mOnItemClickListener; | ||
| private OnItemLongClickListener mOnItemLongClickListener; | ||
| private DataSetObserver mDataObserver = new DataSetObserver() { | ||
|
|
||
| @Override | ||
|
|
@@ -100,7 +99,7 @@ public void setDividerThickness(int thickness) { | |
| requestLayout(); | ||
| } | ||
|
|
||
| public ListAdapter getAdapter() { | ||
| public BaseAdapter getAdapter() { | ||
| return mAdapter; | ||
| } | ||
|
|
||
|
|
@@ -114,7 +113,7 @@ public ListAdapter getAdapter() { | |
| * | ||
| * @see #getAdapter() | ||
| */ | ||
| public void setAdapter(ListAdapter adapter) { | ||
| public void setAdapter(BaseAdapter adapter) { | ||
| if (mAdapter != null) { | ||
| mAdapter.unregisterDataSetObserver(mDataObserver); | ||
| } | ||
|
|
@@ -155,6 +154,32 @@ public interface OnItemClickListener { | |
| */ | ||
| void onItemClick(LinearListView parent, View view, int position, long id); | ||
| } | ||
|
|
||
| /** | ||
| * Interface definition for a callback to be invoked when an item in this | ||
| * LinearListView has been long clicked. | ||
| */ | ||
| public interface OnItemLongClickListener { | ||
|
|
||
| /** | ||
| * Callback method to be invoked when an item in this LinearListView has | ||
| * been long clicked. | ||
| * <p> | ||
| * Implementers can call getItemAtPosition(position) if they need to | ||
| * access the data associated with the selected item. | ||
| * | ||
| * @param parent | ||
| * The LinearListView where the long click happened. | ||
| * @param view | ||
| * The view within the LinearListView that was long clicked (this | ||
| * will be a view provided by the adapter) | ||
| * @param position | ||
| * The position of the view in the adapter. | ||
| * @param id | ||
| * The row id of the item that was long clicked. | ||
| */ | ||
| void onItemLongClick(LinearListView parent, View view, int position, long id); | ||
| } | ||
|
|
||
| /** | ||
| * Register a callback to be invoked when an item in this LinearListView has | ||
|
|
@@ -166,6 +191,17 @@ public interface OnItemClickListener { | |
| public void setOnItemClickListener(OnItemClickListener listener) { | ||
| mOnItemClickListener = listener; | ||
| } | ||
|
|
||
| /** | ||
| * Register a callback to be invoked when an item in this LinearListView has | ||
| * been clicked. | ||
| * | ||
| * @param listener | ||
| * The callback that will be invoked. | ||
| */ | ||
| public void setOnItemLongClickListener(OnItemLongClickListener listener) { | ||
| mOnItemLongClickListener = listener; | ||
| } | ||
|
|
||
| /** | ||
| * @return The callback to be invoked with an item in this LinearListView has | ||
|
|
@@ -175,6 +211,14 @@ public final OnItemClickListener getOnItemClickListener() { | |
| return mOnItemClickListener; | ||
| } | ||
|
|
||
| /** | ||
| * @return The callback to be invoked with an item in this LinearListView has | ||
| * been long clicked, or null id no callback has been set. | ||
| */ | ||
| public final OnItemLongClickListener getOnItemLongClickListener() { | ||
| return mOnItemLongClickListener; | ||
| } | ||
|
|
||
| /** | ||
| * Call the OnItemClickListener, if it is defined. | ||
| * | ||
|
|
@@ -196,14 +240,37 @@ public boolean performItemClick(View view, int position, long id) { | |
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Call the OnItemLongClickListener, if it is defined. | ||
| * | ||
| * @param view | ||
| * The view within the LinearListView that was clicked. | ||
| * @param position | ||
| * The position of the view in the adapter. | ||
| * @param id | ||
| * The row id of the item that was clicked. | ||
| * @return True if there was an assigned OnItemLongClickListener that was | ||
| * called, false otherwise is returned. | ||
| */ | ||
| public boolean performItemLongClick(View view, int position, long id) { | ||
| if (mOnItemLongClickListener != null) { | ||
| playSoundEffect(SoundEffectConstants.CLICK); | ||
| mOnItemLongClickListener.onItemLongClick(this, view, position, id); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Sets the view to show if the adapter is empty | ||
| */ | ||
| public void setEmptyView(View emptyView) { | ||
| mEmptyView = emptyView; | ||
|
|
||
| final ListAdapter adapter = getAdapter(); | ||
| final BaseAdapter adapter = getAdapter(); | ||
| final boolean empty = ((adapter == null) || adapter.isEmpty()); | ||
| updateEmptyStatus(empty); | ||
| } | ||
|
|
@@ -256,7 +323,13 @@ private void setupChildren() { | |
| View child = mAdapter.getView(i, null, this); | ||
| if (mAreAllItemsSelectable || mAdapter.isEnabled(i)) { | ||
| child.setOnClickListener(new InternalOnClickListener(i)); | ||
| child.setOnLongClickListener(new InternalOnLongClickListener(i)); | ||
| } | ||
|
|
||
| // if(child.getLayoutParams() == null){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not commit these lines |
||
| // child.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); | ||
| // } | ||
|
|
||
| addViewInLayout(child, -1, child.getLayoutParams(), true); | ||
| } | ||
| } | ||
|
|
@@ -283,4 +356,30 @@ public void onClick(View v) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Internal OnLongClickListener that this view associate of each of its children | ||
| * so that they can respond to OnItemLongClick listener's events. Avoid setting | ||
| * an OnLongClickListener manually. If you need it you can wrap the child in a | ||
| * simple {@link android.widget.FrameLayout}. | ||
| */ | ||
| private class InternalOnLongClickListener implements OnLongClickListener { | ||
|
|
||
| int mPosition; | ||
|
|
||
| public InternalOnLongClickListener(int position) { | ||
| mPosition = position; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onLongClick(View v) { | ||
| // TODO Auto-generated method stub | ||
| if ((mOnItemLongClickListener != null) && (mAdapter != null)) { | ||
| mOnItemLongClickListener.onItemLongClick(LinearListView.this, v, | ||
| mPosition, mAdapter.getItemId(mPosition)); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these import changes correct? Except swapping ListAdapter for BaseAdapter everything should stay the same.