Search in sources :

Example 6 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project drag-sort-listview by bauerca.

the class TestBedDSLV method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    FragmentTransaction transaction;
    DSLVFragment f = (DSLVFragment) getSupportFragmentManager().findFragmentByTag(mTag);
    DragSortListView dslv = (DragSortListView) f.getListView();
    DragSortController control = f.getController();
    switch(item.getItemId()) {
        case R.id.select_remove_mode:
            RemoveModeDialog rdialog = new RemoveModeDialog(mRemoveMode);
            rdialog.setRemoveOkListener(this);
            rdialog.show(getSupportFragmentManager(), "RemoveMode");
            return true;
        case R.id.select_drag_init_mode:
            DragInitModeDialog ddialog = new DragInitModeDialog(mDragStartMode);
            ddialog.setDragOkListener(this);
            ddialog.show(getSupportFragmentManager(), "DragInitMode");
            return true;
        case R.id.select_enables:
            EnablesDialog edialog = new EnablesDialog(mDragEnabled, mSortEnabled, mRemoveEnabled);
            edialog.setEnabledOkListener(this);
            edialog.show(getSupportFragmentManager(), "Enables");
            return true;
        case R.id.add_header:
            mNumHeaders++;
            transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.test_bed, getNewDslvFragment(), mTag);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            transaction.commit();
            return true;
        case R.id.add_footer:
            mNumFooters++;
            transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.test_bed, getNewDslvFragment(), mTag);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            transaction.commit();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) DragSortController(com.mobeta.android.dslv.DragSortController) DragSortListView(com.mobeta.android.dslv.DragSortListView)

Example 7 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project drag-sort-listview by bauerca.

the class CursorDSLV method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cursor_main);
    String[] cols = { "name" };
    int[] ids = { R.id.text };
    adapter = new MAdapter(this, R.layout.list_item_click_remove, null, cols, ids, 0);
    DragSortListView dslv = (DragSortListView) findViewById(android.R.id.list);
    dslv.setAdapter(adapter);
    // build a cursor from the String array
    MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "name" });
    String[] artistNames = getResources().getStringArray(R.array.jazz_artist_names);
    for (int i = 0; i < artistNames.length; i++) {
        cursor.newRow().add(i).add(artistNames[i]);
    }
    adapter.changeCursor(cursor);
}
Also used : DragSortListView(com.mobeta.android.dslv.DragSortListView) MatrixCursor(android.database.MatrixCursor)

Example 8 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project drag-sort-listview by bauerca.

the class SingleChoiceListView method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.checkable_main);
    String[] array = getResources().getStringArray(R.array.jazz_artist_names);
    ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(array));
    adapter = new ArrayAdapter<String>(this, R.layout.list_item_radio, R.id.text, arrayList);
    setListAdapter(adapter);
    DragSortListView list = getListView();
    list.setDropListener(onDrop);
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
Also used : ArrayList(java.util.ArrayList) DragSortListView(com.mobeta.android.dslv.DragSortListView)

Example 9 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project JamsMusicPlayer by psaravan.

the class NowPlayingQueueFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //Inflate the correct layout based on the selected theme.
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;
    nowPlayingQueueFragment = this;
    sharedPreferences = mContext.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);
    mCursor = mApp.getService().getCursor();
    View rootView = (ViewGroup) inflater.inflate(R.layout.now_playing_queue_layout, container, false);
    receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            updateSongInfo();
        }
    };
    //Notify the application that this fragment is now visible.
    sharedPreferences.edit().putBoolean("NOW_PLAYING_QUEUE_VISIBLE", true).commit();
    //Get the screen's parameters.
    displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    screenWidth = displayMetrics.widthPixels;
    screenHeight = displayMetrics.heightPixels;
    noMusicPlaying = (TextView) rootView.findViewById(R.id.now_playing_queue_no_music_playing);
    nowPlayingAlbumArt = (ImageView) rootView.findViewById(R.id.now_playing_queue_album_art);
    nowPlayingSongTitle = (TextView) rootView.findViewById(R.id.now_playing_queue_song_title);
    nowPlayingSongArtist = (TextView) rootView.findViewById(R.id.now_playing_queue_song_artist);
    nowPlayingSongContainer = (RelativeLayout) rootView.findViewById(R.id.now_playing_queue_current_song_container);
    noMusicPlaying.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    nowPlayingSongTitle.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    nowPlayingSongArtist.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    nowPlayingQueueListView = (DragSortListView) rootView.findViewById(R.id.now_playing_queue_list_view);
    progressBar = (ProgressBar) rootView.findViewById(R.id.now_playing_queue_progressbar);
    playPauseButton = (ImageButton) rootView.findViewById(R.id.now_playing_queue_play);
    nextButton = (ImageButton) rootView.findViewById(R.id.now_playing_queue_next);
    previousButton = (ImageButton) rootView.findViewById(R.id.now_playing_queue_previous);
    //Apply the card layout's background based on the color theme.
    if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("LIGHT_CARDS_THEME")) {
        rootView.setBackgroundColor(0xFFEEEEEE);
        nowPlayingQueueListView.setDivider(getResources().getDrawable(R.drawable.transparent_drawable));
        nowPlayingQueueListView.setDividerHeight(3);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(7, 3, 7, 3);
        nowPlayingQueueListView.setLayoutParams(layoutParams);
    } else if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("DARK_CARDS_THEME")) {
        rootView.setBackgroundColor(0xFF000000);
        nowPlayingQueueListView.setDivider(getResources().getDrawable(R.drawable.transparent_drawable));
        nowPlayingQueueListView.setDividerHeight(3);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(7, 3, 7, 3);
        nowPlayingQueueListView.setLayoutParams(layoutParams);
    }
    //Set the Now Playing container layout's background.
    nowPlayingSongContainer.setBackgroundColor(UIElementsHelper.getNowPlayingQueueBackground(mContext));
    //Loop through the service's cursor and retrieve the current queue's information.
    if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == false || mApp.getService().getCurrentMediaPlayer() == null) {
        //No audio is currently playing.
        noMusicPlaying.setVisibility(View.VISIBLE);
        nowPlayingAlbumArt.setImageBitmap(mApp.decodeSampledBitmapFromResource(R.drawable.default_album_art, screenWidth / 3, screenWidth / 3));
        nowPlayingQueueListView.setVisibility(View.GONE);
        nowPlayingSongTitle.setVisibility(View.GONE);
        nowPlayingSongArtist.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
    } else {
        //Set the current play/pause conditions.
        try {
            //Hide the progressBar and display the controls.
            progressBar.setVisibility(View.GONE);
            playPauseButton.setVisibility(View.VISIBLE);
            nextButton.setVisibility(View.VISIBLE);
            previousButton.setVisibility(View.VISIBLE);
            if (mApp.getService().getCurrentMediaPlayer().isPlaying()) {
                playPauseButton.setImageResource(R.drawable.pause_holo_light);
            } else {
                playPauseButton.setImageResource(R.drawable.play_holo_light);
            }
        } catch (Exception e) {
            /* The mediaPlayer hasn't been initialized yet, so let's just keep the controls 
        		 * hidden for now. Once the mediaPlayer is initialized and it starts playing, 
        		 * updateSongInfo() will be called, and we can show the controls/hide the progressbar 
        		 * there. For now though, we'll display the progressBar.
        		 */
            progressBar.setVisibility(View.VISIBLE);
            playPauseButton.setVisibility(View.GONE);
            nextButton.setVisibility(View.GONE);
            previousButton.setVisibility(View.GONE);
        }
        //Retrieve and set the current title/artist/artwork.
        mCursor.moveToPosition(mApp.getService().getPlaybackIndecesList().get(mApp.getService().getCurrentSongIndex()));
        String currentTitle = mCursor.getString(mCursor.getColumnIndex(DBAccessHelper.SONG_TITLE));
        String currentArtist = mCursor.getString(mCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST));
        nowPlayingSongTitle.setText(currentTitle);
        nowPlayingSongArtist.setText(currentArtist);
        File file = new File(mContext.getExternalCacheDir() + "/current_album_art.jpg");
        Bitmap bm = null;
        if (file.exists()) {
            bm = mApp.decodeSampledBitmapFromFile(file, screenWidth, screenHeight);
            nowPlayingAlbumArt.setScaleX(1.0f);
            nowPlayingAlbumArt.setScaleY(1.0f);
        } else {
            int defaultResource = UIElementsHelper.getIcon(mContext, "default_album_art");
            bm = mApp.decodeSampledBitmapFromResource(defaultResource, screenWidth, screenHeight);
            nowPlayingAlbumArt.setScaleX(0.5f);
            nowPlayingAlbumArt.setScaleY(0.5f);
        }
        nowPlayingAlbumArt.setImageBitmap(bm);
        noMusicPlaying.setPaintFlags(noMusicPlaying.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
        nowPlayingSongTitle.setPaintFlags(nowPlayingSongTitle.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
        nowPlayingSongArtist.setPaintFlags(nowPlayingSongArtist.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
        /* Set the adapter. We'll pass in playbackIndecesList as the adapter's data backend.
             * The array can then be manipulated (reordered, items removed, etc) with no restrictions. 
             * Each integer element in the array will be used as a pointer to a specific cursor row, 
             * so there's no need to fiddle around with the actual cursor itself. */
        nowPlayingQueueListViewAdapter = new NowPlayingQueueListViewAdapter(getActivity(), mApp.getService().getPlaybackIndecesList());
        nowPlayingQueueListView.setAdapter(nowPlayingQueueListViewAdapter);
        nowPlayingQueueListView.setFastScrollEnabled(true);
        nowPlayingQueueListView.setDropListener(onDrop);
        nowPlayingQueueListView.setRemoveListener(onRemove);
        SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(nowPlayingQueueListView);
        simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
        nowPlayingQueueListView.setFloatViewManager(simpleFloatViewManager);
        //Scroll down to the current song.
        nowPlayingQueueListView.setSelection(mApp.getService().getCurrentSongIndex());
        nowPlayingQueueListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) {
                mApp.getService().skipToTrack(index);
            }
        });
        playPauseButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mApp.getService().togglePlaybackState();
            }
        });
        nextButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mApp.getService().skipToNextTrack();
            }
        });
        previousButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mApp.getService().skipToPreviousTrack();
            }
        });
    }
    return rootView;
}
Also used : Context(android.content.Context) SimpleFloatViewManager(com.mobeta.android.dslv.SimpleFloatViewManager) LayoutParams(android.view.ViewGroup.LayoutParams) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) ImageView(android.widget.ImageView) DragSortListView(com.mobeta.android.dslv.DragSortListView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) File(java.io.File)

Example 10 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project JamsMusicPlayer by psaravan.

the class QueueDrawerFragment method onCreateView.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity();
    mApp = (Common) mContext.getApplicationContext();
    View rootView = inflater.inflate(R.layout.fragment_queue_drawer, null);
    if (mApp.getCurrentTheme() == Common.LIGHT_THEME) {
        rootView.setBackgroundColor(0xFFFFFFFF);
    } else {
        rootView.setBackgroundColor(0xFF191919);
    }
    mMiniPlayerLayout = (RelativeLayout) rootView.findViewById(R.id.queue_drawer_mini_player_layout);
    mMiniPlayerAlbumArt = (ImageView) rootView.findViewById(R.id.queue_drawer_album_art);
    mPlayPauseBackground = (RelativeLayout) rootView.findViewById(R.id.playPauseButtonBackground);
    mPlayPauseButton = (ImageButton) rootView.findViewById(R.id.playPauseButton);
    mNextButton = (ImageButton) rootView.findViewById(R.id.nextButton);
    mPreviousButton = (ImageButton) rootView.findViewById(R.id.previousButton);
    mTitleText = (TextView) rootView.findViewById(R.id.songName);
    mSubText = (TextView) rootView.findViewById(R.id.artistAlbumName);
    mListView = (DragSortListView) rootView.findViewById(R.id.queue_drawer_list_view);
    mEmptyInfoText = (TextView) rootView.findViewById(R.id.queue_drawer_empty_text);
    mPlayPauseBackground.setBackgroundResource(UIElementsHelper.getShadowedCircle(mContext));
    mPlayPauseButton.setId(R.drawable.pause_light);
    mTitleText.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    mSubText.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    mEmptyInfoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));
    //Set the click listeners.
    mMiniPlayerLayout.setOnClickListener(mOnClickMiniPlayer);
    mPlayPauseBackground.setOnClickListener(playPauseClickListener);
    mPlayPauseButton.setOnClickListener(playPauseClickListener);
    mNextButton.setOnClickListener(mOnClickNextListener);
    mPreviousButton.setOnClickListener(mOnClickPreviousListener);
    //Restrict all touch events to this fragment.
    rootView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    //KitKat translucent navigation/status bar.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int navBarHeight = Common.getNavigationBarHeight(mContext);
        if (mListView != null) {
            mListView.setPadding(0, 0, 0, navBarHeight);
            mListView.setClipToPadding(false);
        }
    }
    return rootView;
}
Also used : ImageView(android.widget.ImageView) DragSortListView(com.mobeta.android.dslv.DragSortListView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent) SuppressLint(android.annotation.SuppressLint)

Aggregations

DragSortListView (com.mobeta.android.dslv.DragSortListView)16 View (android.view.View)7 AdapterView (android.widget.AdapterView)5 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 ArrayList (java.util.ArrayList)4 Paint (android.graphics.Paint)3 DragSortController (com.mobeta.android.dslv.DragSortController)3 MotionEvent (android.view.MotionEvent)2 ViewGroup (android.view.ViewGroup)2 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Bitmap (android.graphics.Bitmap)1