Search in sources :

Example 1 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project Klyph by jonathangerbaud.

the class MultiSelectDragListPreference method onPrepareDialogBuilder.

@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);
    if (mEntries == null || mEntryValues == null) {
        throw new IllegalStateException("MultiSelectListPreference requires an entries array and " + "an entryValues array.");
    }
    String[] entries = new String[mEntries.length];
    for (int i = 0; i < mEntries.length; i++) {
        entries[i] = mEntries[i].toString();
    }
    boolean[] selectedItems = getSelectedItems();
    ArrayList<String> orderedList = new ArrayList<String>();
    int n = selectedItems.length;
    for (String value : mValues) {
        int index = ArrayUtils.indexOf(mEntryValues, value);
        orderedList.add(mEntries[index].toString());
    }
    for (int i = 0; i < mEntries.length; i++) {
        if (!mValues.contains(mEntryValues[i]))
            orderedList.add(mEntries[i].toString());
    }
    adapter = new ArrayAdapter<String>(getContext(), R.layout.item_list_preference_multi_drag, R.id.text, orderedList);
    listView = new DragSortListView(getContext(), null);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    listView.setDragEnabled(true);
    listView.setFloatAlpha(0.8f);
    DragSortController controller = new DragSortController(listView);
    controller.setDragHandleId(R.id.drag_handle);
    controller.setRemoveEnabled(false);
    controller.setSortEnabled(true);
    controller.setBackgroundColor(0xFFFFFF);
    controller.setDragInitMode(DragSortController.ON_DOWN);
    listView.setFloatViewManager(controller);
    listView.setOnTouchListener(controller);
    builder.setView(listView);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mPreferenceChanged = true;
            refreshNewValues();
        }
    });
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    for (int i = 0; i < n; i++) {
        listView.setItemChecked(i, i < mValues.size());
    }
    /*
		 * boolean [] checkedItems = getSelectedItems();
		 * builder.setMultiChoiceItems(mEntries, checkedItems,
		 * new DialogInterface.OnMultiChoiceClickListener() {
		 * public void onClick(DialogInterface dialog, int which, boolean 
		 * isChecked) {
		 * if (isChecked) {
		 * mPreferenceChanged |= mNewValues.add(mEntryValues[which].toString());
		 * } else {
		 * mPreferenceChanged |=
		 * mNewValues.remove(mEntryValues[which].toString());
		 * }
		 * }
		 * });
		 */
    mNewValues.clear();
    mNewValues.addAll(mValues);
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ArrayList(java.util.ArrayList) DragSortListView(com.mobeta.android.dslv.DragSortListView) DragSortListView(com.mobeta.android.dslv.DragSortListView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) DragSortController(com.mobeta.android.dslv.DragSortController)

Example 2 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project WordPress-Android by wordpress-mobile.

the class MediaGalleryEditFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    mIds = new ArrayList<>();
    if (savedInstanceState != null) {
        mIds = ListUtils.fromLongArray(savedInstanceState.getLongArray(SAVED_MEDIA_IDS));
    }
    mGridAdapter = new MediaGalleryAdapter(getActivity(), R.layout.media_gallery_item, null, true, mImageLoader);
    View view = inflater.inflate(R.layout.media_gallery_edit_fragment, container, false);
    DragSortListView gridView = (DragSortListView) view.findViewById(R.id.edit_media_gallery_gridview);
    gridView.setAdapter(mGridAdapter);
    gridView.setOnCreateContextMenuListener(this);
    gridView.setDropListener(this);
    gridView.setRemoveListener(this);
    refreshGridView();
    return view;
}
Also used : DragSortListView(com.mobeta.android.dslv.DragSortListView) DragSortListView(com.mobeta.android.dslv.DragSortListView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 3 with DragSortListView

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

the class BlacklistManagerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mApp = (Common) getActivity().getApplicationContext();
    View rootView = (ViewGroup) inflater.inflate(R.layout.fragment_blacklist_manager, container, false);
    mContext = getActivity().getApplicationContext();
    ImageView blacklistImage = (ImageView) rootView.findViewById(R.id.blacklist_image);
    blacklistImage.setImageResource(UIElementsHelper.getIcon(mContext, "manage_blacklists"));
    MANAGER_TYPE = getArguments().getString("MANAGER_TYPE");
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    //Get a cursor with a list of blacklisted elements.
    if (MANAGER_TYPE.equals("ARTISTS")) {
        builder.setTitle(R.string.blacklisted_artists);
        cursor = mApp.getDBAccessHelper().getBlacklistedArtists();
        //Finish the activity if there are no blacklisted elements.
        if (cursor.getCount() == 0) {
            Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show();
            getActivity().finish();
        } else {
            //Load the cursor data into temporary ArrayLists.
            for (int i = 0; i < cursor.getCount(); i++) {
                cursor.moveToPosition(i);
                elementNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)));
            }
        }
    } else if (MANAGER_TYPE.equals("ALBUMS")) {
        builder.setTitle(R.string.blacklisted_albums);
        cursor = mApp.getDBAccessHelper().getBlacklistedAlbums();
        //Finish the activity if there are no blacklisted elements.
        if (cursor.getCount() == 0) {
            Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show();
            getActivity().finish();
        } else {
            //Load the cursor data into temporary ArrayLists.
            for (int i = 0; i < cursor.getCount(); i++) {
                cursor.moveToPosition(i);
                elementNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)));
                artistNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)));
            }
        }
    } else if (MANAGER_TYPE.equals("SONGS")) {
        builder.setTitle(R.string.blacklisted_songs);
        cursor = mApp.getDBAccessHelper().getAllBlacklistedSongs();
        //Finish the activity if there are no blacklisted elements.
        if (cursor.getCount() == 0) {
            Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show();
            getActivity().finish();
        } else {
            //Load the cursor data into temporary ArrayLists.
            for (int i = 0; i < cursor.getCount(); i++) {
                cursor.moveToPosition(i);
                elementNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_TITLE)));
                artistNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)));
                filePathList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)));
                songIdsList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ID)));
            }
        }
    } else if (MANAGER_TYPE.equals("PLAYLISTS")) {
    /*builder.setTitle(R.string.blacklisted_playlists);
        	DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity());
        	cursor = playlistsDBHelper.getAllBlacklistedPlaylists();
        	
        	//Finish the activity if there are no blacklisted elements.
            if (cursor.getCount()==0) {
            	Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show();
            	getActivity().finish();
            } else {
                //Load the cursor data into temporary ArrayLists.
            	for (int i=0; i < cursor.getCount(); i++) {
            		cursor.moveToPosition(i);
            		elementNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.PLAYLIST_NAME)));
            		artistNameList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.NUMBER_OF_SONGS)));
            		filePathList.add(cursor.getString(cursor.getColumnIndex(DBAccessHelper.PLAYLIST_FILE_PATH)));
            	}
            	
            }*/
    } else {
        Toast.makeText(getActivity(), R.string.error_occurred, Toast.LENGTH_LONG).show();
        getActivity().finish();
    }
    TextView blacklistManagerInfoText = (TextView) rootView.findViewById(R.id.blacklist_manager_info_text);
    DragSortListView blacklistManagerListView = (DragSortListView) rootView.findViewById(R.id.blacklist_manager_list);
    blacklistManagerListView.setRemoveListener(onRemove);
    blacklistManagerInfoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    blacklistManagerInfoText.setPaintFlags(blacklistManagerInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    blacklistManagerListView.setFastScrollEnabled(true);
    adapter = new BlacklistedElementsAdapter(getActivity(), elementNameList, artistNameList, MANAGER_TYPE);
    blacklistManagerListView.setAdapter(adapter);
    return rootView;
}
Also used : AlertDialog(android.app.AlertDialog) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) ImageView(android.widget.ImageView) DragSortListView(com.mobeta.android.dslv.DragSortListView) ImageView(android.widget.ImageView) DragSortListView(com.mobeta.android.dslv.DragSortListView) TextView(android.widget.TextView) View(android.view.View) Paint(android.graphics.Paint)

Example 4 with DragSortListView

use of com.mobeta.android.dslv.DragSortListView in project little-bear-dictionary by daimajia.

the class DictionaryManageFragment method onDestroyView.

@Override
public void onDestroyView() {
    super.onDestroyView();
    QueryProcessor.updateCacheDictionaryList(getActivity().getApplicationContext());
    if (mDictionaryManageFragment.mOfflineDictionaryManageView == null) {
        return;
    }
    DragSortListView dragSortListView = (DragSortListView) mDictionaryManageFragment.mOfflineDictionaryManageView.findViewById(android.R.id.list);
    OfflineListCursorAdapter dragSortCursorAdapter = (OfflineListCursorAdapter) dragSortListView.getInputAdapter();
    ArrayList<Integer> SortedResult = dragSortCursorAdapter.getCursorPositions();
    if (SortedResult == null || SortedResult.size() == 0) {
        return;
    }
    Cursor cursor = dragSortCursorAdapter.getCursor();
    cursor.moveToPosition(-1);
    int i = 0;
    DictionaryDB dictionaryDB = new DictionaryDB(getActivity(), DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = dictionaryDB.getWritableDatabase();
    while (cursor.moveToNext()) {
        String[] args = { SortedResult.get(i).toString(), cursor.getString(cursor.getColumnIndex("_id")) };
        sqLiteDatabase.execSQL("update `dictionary_list` set `dictionary_order`= ? where `_id`= ?", args);
        i++;
    }
}
Also used : DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) OfflineListCursorAdapter(com.zhan_dui.dictionary.cursoradapters.OfflineListCursorAdapter) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DragSortListView(com.mobeta.android.dslv.DragSortListView) Cursor(android.database.Cursor)

Example 5 with DragSortListView

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

the class MultipleChoiceListView 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_checkable, R.id.text, arrayList);
    setListAdapter(adapter);
    DragSortListView list = getListView();
    list.setDropListener(onDrop);
    list.setRemoveListener(onRemove);
}
Also used : ArrayList(java.util.ArrayList) DragSortListView(com.mobeta.android.dslv.DragSortListView)

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