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);
}
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;
}
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);
}
}
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;
}
Aggregations