Search in sources :

Example 66 with ListView

use of android.widget.ListView in project android-testing by googlesamples.

the class LongListActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.list_activity);
    populateData();
    ListView listView = (ListView) findViewById(R.id.list);
    String[] from = new String[] { ROW_TEXT, ROW_ENABLED };
    int[] to = new int[] { R.id.rowContentTextView, R.id.rowToggleButton };
    layoutInflater = getLayoutInflater();
    // Create the adapter for the list.
    ListAdapter adapter = new LongListAdapter(from, to);
    // Send the data to the list.
    listView.setAdapter(adapter);
}
Also used : ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter)

Example 67 with ListView

use of android.widget.ListView in project MusicDNA by harjot-oberai.

the class HomeActivity method showAddToPlaylistDialog.

public void showAddToPlaylistDialog(final UnifiedTrack track) {
    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.add_to_playlist_dialog);
    dialog.setTitle("Add to Playlist");
    ListView lv = (ListView) dialog.findViewById(R.id.playlist_list);
    AddToPlaylistAdapter adapter;
    if (allPlaylists.getPlaylists() != null && allPlaylists.getPlaylists().size() != 0) {
        adapter = new AddToPlaylistAdapter(allPlaylists.getPlaylists(), ctx);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Playlist temp = allPlaylists.getPlaylists().get(position);
                boolean isRepeat = false;
                for (UnifiedTrack ut : temp.getSongList()) {
                    if (track.getType() && ut.getType() && track.getLocalTrack().getTitle().equals(ut.getLocalTrack().getTitle())) {
                        isRepeat = true;
                        break;
                    } else if (!track.getType() && !ut.getType() && track.getStreamTrack().getTitle().equals(ut.getStreamTrack().getTitle())) {
                        isRepeat = true;
                        break;
                    }
                }
                if (!isRepeat) {
                    temp.addSong(track);
                    playlistsRecycler.setVisibility(View.VISIBLE);
                    playlistNothingText.setVisibility(View.INVISIBLE);
                    pAdapter.notifyDataSetChanged();
                    Toast.makeText(ctx, "Added to Playlist : " + temp.getPlaylistName(), Toast.LENGTH_SHORT).show();
                    new SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    dialog.dismiss();
                } else {
                    Toast.makeText(ctx, "Song already present in Playlist", Toast.LENGTH_SHORT).show();
                }
            }
        });
    } else {
        lv.setVisibility(GONE);
    }
    // set the custom dialog components - text, image and button
    final EditText text = (EditText) dialog.findViewById(R.id.new_playlist_name);
    ImageView image = (ImageView) dialog.findViewById(R.id.confirm_button);
    // if button is clicked, close the custom dialog
    image.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isNameRepeat = false;
            if (text.getText().toString().trim().equals("")) {
                text.setError("Enter Playlist Name!");
            } else {
                for (int i = 0; i < allPlaylists.getPlaylists().size(); i++) {
                    if (text.getText().toString().equals(allPlaylists.getPlaylists().get(i).getPlaylistName())) {
                        isNameRepeat = true;
                        text.setError("Playlist with same name exists!");
                        break;
                    }
                }
                if (!isNameRepeat) {
                    List<UnifiedTrack> l = new ArrayList<UnifiedTrack>();
                    l.add(track);
                    Playlist pl = new Playlist(l, text.getText().toString().trim());
                    allPlaylists.addPlaylist(pl);
                    playlistsRecycler.setVisibility(View.VISIBLE);
                    playlistNothingText.setVisibility(View.INVISIBLE);
                    pAdapter.notifyDataSetChanged();
                    dialog.dismiss();
                    new SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            }
        }
    });
    dialog.show();
}
Also used : EditText(android.widget.EditText) AddToPlaylistAdapter(com.sdsmdg.harjot.MusicDNA.adapters.playlistdialogadapter.AddToPlaylistAdapter) ImageView(android.widget.ImageView) VisualizerView(com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WheelView(com.lantouzi.wheelview.WheelView) ListView(android.widget.ListView) TextPaint(android.text.TextPaint) Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) ListView(android.widget.ListView) Dialog(android.app.Dialog) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) AdapterView(android.widget.AdapterView) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView)

Example 68 with ListView

use of android.widget.ListView in project MusicDNA by harjot-oberai.

the class HomeActivity method showSaveQueueDialog.

public void showSaveQueueDialog() {
    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.add_to_playlist_dialog);
    dialog.setTitle("Save Queue");
    ListView lv = (ListView) dialog.findViewById(R.id.playlist_list);
    lv.setVisibility(GONE);
    // set the custom dialog components - text, image and button
    final EditText text = (EditText) dialog.findViewById(R.id.new_playlist_name);
    ImageView image = (ImageView) dialog.findViewById(R.id.confirm_button);
    // if button is clicked, close the custom dialog
    image.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isNameRepeat = false;
            if (text.getText().toString().trim().equals("")) {
                text.setError("Enter Playlist Name!");
            } else {
                for (int i = 0; i < allPlaylists.getPlaylists().size(); i++) {
                    if (text.getText().toString().equals(allPlaylists.getPlaylists().get(i).getPlaylistName())) {
                        isNameRepeat = true;
                        text.setError("Playlist with same name exists!");
                        break;
                    }
                }
                if (!isNameRepeat) {
                    Playlist pl = new Playlist(text.getText().toString());
                    for (int i = 0; i < queue.getQueue().size(); i++) {
                        pl.getSongList().add(queue.getQueue().get(i));
                    }
                    allPlaylists.addPlaylist(pl);
                    playlistsRecycler.setVisibility(View.VISIBLE);
                    playlistNothingText.setVisibility(View.INVISIBLE);
                    pAdapter.notifyDataSetChanged();
                    new SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    Toast.makeText(HomeActivity.this, "Queue saved!", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }
            }
        }
    });
    dialog.show();
}
Also used : EditText(android.widget.EditText) Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) ListView(android.widget.ListView) Dialog(android.app.Dialog) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ImageView(android.widget.ImageView) VisualizerView(com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WheelView(com.lantouzi.wheelview.WheelView) ListView(android.widget.ListView)

Example 69 with ListView

use of android.widget.ListView in project cardslib by gabrielemariotti.

the class MultiChoiceAdapterHelperBase method correctPositionAccountingForHeader.

private int correctPositionAccountingForHeader(AdapterView<?> adapterView, int position) {
    ListView listView = (adapterView instanceof ListView) ? (ListView) adapterView : null;
    int headersCount = listView == null ? 0 : listView.getHeaderViewsCount();
    if (headersCount > 0) {
        position -= listView.getHeaderViewsCount();
    }
    return position;
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Example 70 with ListView

use of android.widget.ListView in project cardslib by gabrielemariotti.

the class SwipeDismissListViewTouchListener method onTouch.

/**
     * Returns an {@link AbsListView.OnScrollListener} to be added to the {@link
     * ListView} using {@link ListView#setOnScrollListener(AbsListView.OnScrollListener)}.
     * If a scroll listener is already assigned, the caller should still pass scroll changes through
     * to this listener. This will ensure that this {@link SwipeDismissListViewTouchListener} is
     * paused during list view scrolling.</p>
     *
     * @see SwipeDismissListViewTouchListener
     */
/*
    public AbsListView.OnScrollListener makeScrollListener() {
        return new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            }

            @Override
            public void onScroll(AbsListView absListView, int i, int i1, int i2) {
            }
        };
    }*/
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mListView.getWidth();
    }
    switch(motionEvent.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            {
                if (mPaused) {
                    return false;
                }
                if (mSwiping) {
                    return true;
                }
                // TODO: ensure this is a finger, and set a flag
                // Find the child view that was touched (perform a hit test)
                Rect rect = new Rect();
                int childCount = mListView.getChildCount();
                int headerCount = mListView.getHeaderViewsCount();
                int footerCount = mListView.getFooterViewsCount();
                int[] listViewCoords = new int[2];
                mListView.getLocationOnScreen(listViewCoords);
                int x = (int) motionEvent.getRawX() - listViewCoords[0];
                int y = (int) motionEvent.getRawY() - listViewCoords[1];
                View child = null;
                for (int i = headerCount; i < (childCount - footerCount); i++) {
                    child = mListView.getChildAt(i);
                    child.getHitRect(rect);
                    if (rect.contains(x, y)) {
                        mDownView = child;
                        break;
                    }
                }
                if (mDownView != null) {
                    mDownX = motionEvent.getRawX();
                    mDownY = motionEvent.getRawY();
                    mDownPosition = mListView.getPositionForView(mDownView);
                    if (mDownPosition != ListView.INVALID_POSITION && mDownPosition < mListView.getAdapter().getCount()) {
                        if (mListView.getAdapter().getItem(mDownPosition) instanceof Card) {
                            if (mCallbacks.canDismiss(mDownPosition, (Card) mListView.getAdapter().getItem(mDownPosition))) {
                                mVelocityTracker = VelocityTracker.obtain();
                                mVelocityTracker.addMovement(motionEvent);
                            } else {
                                mDownView = null;
                            }
                        } else {
                            mDownView = null;
                        }
                    } else {
                        mDownView = null;
                    }
                }
                view.onTouchEvent(motionEvent);
                return true;
            //return false;
            }
        case MotionEvent.ACTION_UP:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                float deltaX = motionEvent.getRawX() - mDownX;
                mVelocityTracker.addMovement(motionEvent);
                mVelocityTracker.computeCurrentVelocity(1000);
                float velocityX = mVelocityTracker.getXVelocity();
                float absVelocityX = Math.abs(velocityX);
                float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
                boolean dismiss = false;
                boolean dismissRight = false;
                if (Math.abs(deltaX) > mViewWidth / swipeDistanceDivisor && mSwiping) {
                    dismiss = true;
                    dismissRight = deltaX > 0;
                } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX && mSwiping) {
                    // dismiss only if flinging in the same direction as dragging
                    dismiss = (velocityX < 0) == (deltaX < 0);
                    dismissRight = mVelocityTracker.getXVelocity() > 0;
                }
                if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
                    // dismiss
                    dismiss(mDownView, mDownPosition - mListView.getHeaderViewsCount(), dismissRight);
                } else {
                    // cancel
                    mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
                }
                mVelocityTracker.recycle();
                mVelocityTracker = null;
                mDownX = 0;
                mDownY = 0;
                mDownView = null;
                mDownPosition = ListView.INVALID_POSITION;
                if (mSwiping) {
                    //To prevent onClick event with a fast swipe
                    mSwiping = false;
                    return true;
                }
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_CANCEL:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                if (mDownView != null) {
                    // cancel
                    mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
                }
                mVelocityTracker.recycle();
                mVelocityTracker = null;
                mDownX = 0;
                mDownY = 0;
                mDownView = null;
                mDownPosition = ListView.INVALID_POSITION;
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_MOVE:
            {
                if (mVelocityTracker == null || mPaused) {
                    break;
                }
                mVelocityTracker.addMovement(motionEvent);
                float deltaX = motionEvent.getRawX() - mDownX;
                float deltaY = motionEvent.getRawY() - mDownY;
                boolean movementAllowed = isSwipeMovementAllowed(deltaX);
                if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2 && movementAllowed) {
                    mSwiping = true;
                    mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
                    mListView.requestDisallowInterceptTouchEvent(true);
                    // Cancel ListView's touch (un-highlighting the item)
                    MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
                    cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                    mListView.onTouchEvent(cancelEvent);
                    view.onTouchEvent(cancelEvent);
                    cancelEvent.recycle();
                }
                if (mSwiping) {
                    mDownView.setTranslationX(deltaX - mSwipingSlop);
                    mDownView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
                    return true;
                }
                break;
            }
    }
    return false;
}
Also used : Rect(android.graphics.Rect) AbsListView(android.widget.AbsListView) View(android.view.View) ListView(android.widget.ListView) Card(it.gmariotti.cardslib.library.internal.Card) MotionEvent(android.view.MotionEvent)

Aggregations

ListView (android.widget.ListView)1139 View (android.view.View)739 AdapterView (android.widget.AdapterView)444 TextView (android.widget.TextView)389 ImageView (android.widget.ImageView)167 Intent (android.content.Intent)148 AbsListView (android.widget.AbsListView)135 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)97 ArrayAdapter (android.widget.ArrayAdapter)97 ArrayList (java.util.ArrayList)81 ViewGroup (android.view.ViewGroup)75 ListAdapter (android.widget.ListAdapter)71 OnClickListener (android.view.View.OnClickListener)65 LayoutInflater (android.view.LayoutInflater)63 Bundle (android.os.Bundle)57 Button (android.widget.Button)55 LinearLayout (android.widget.LinearLayout)50 SuppressLint (android.annotation.SuppressLint)34 DialogInterface (android.content.DialogInterface)34 ScrollView (android.widget.ScrollView)31