Search in sources :

Example 1 with DragSortController

use of com.mobeta.android.dslv.DragSortController 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 DragSortController

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

the class DSLVFragment method buildController.

/**
 * Called in onCreateView. Override this to provide a custom
 * DragSortController.
 */
public DragSortController buildController(DragSortListView dslv) {
    // defaults are
    // dragStartMode = onDown
    // removeMode = flingRight
    DragSortController controller = new DragSortController(dslv);
    controller.setDragHandleId(R.id.drag_handle);
    controller.setClickRemoveId(R.id.click_remove);
    controller.setRemoveEnabled(removeEnabled);
    controller.setSortEnabled(sortEnabled);
    controller.setDragInitMode(dragStartMode);
    controller.setRemoveMode(removeMode);
    return controller;
}
Also used : DragSortController(com.mobeta.android.dslv.DragSortController)

Example 3 with DragSortController

use of com.mobeta.android.dslv.DragSortController 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 4 with DragSortController

use of com.mobeta.android.dslv.DragSortController in project SeriesGuide by UweTrottmann.

the class ListsReorderDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.dialog_lists_reorder, container, false);
    unbinder = ButterKnife.bind(this, v);
    DragSortController controller = new DragSortController(dragSortListView, R.id.dragGripViewItemList, DragSortController.ON_DOWN, DragSortController.CLICK_REMOVE);
    controller.setRemoveEnabled(false);
    dragSortListView.setFloatViewManager(controller);
    dragSortListView.setOnTouchListener(controller);
    dragSortListView.setDropListener(new DragSortListView.DropListener() {

        @Override
        public void drop(int from, int to) {
            reorderList(from, to);
        }
    });
    buttonNegative.setText(R.string.discard);
    buttonNegative.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    buttonPositive.setText(android.R.string.ok);
    buttonPositive.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveListsOrder();
            dismiss();
        }
    });
    return v;
}
Also used : DragSortController(com.mobeta.android.dslv.DragSortController) DragSortListView(com.mobeta.android.dslv.DragSortListView) BindView(butterknife.BindView) DragSortListView(com.mobeta.android.dslv.DragSortListView) View(android.view.View)

Aggregations

DragSortController (com.mobeta.android.dslv.DragSortController)4 DragSortListView (com.mobeta.android.dslv.DragSortListView)3 View (android.view.View)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ListView (android.widget.ListView)1 BindView (butterknife.BindView)1 ArrayList (java.util.ArrayList)1