com.mobeta.android.dslv.DragSortController Java Examples

The following examples show how to use com.mobeta.android.dslv.DragSortController. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourcesActivity.java    From blade-player with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    //set theme
    setTheme(ThemesActivity.currentAppTheme);

    setContentView(R.layout.activity_sources);
    android.support.v7.widget.Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    DragSortListView sourcesListView = findViewById(R.id.sources_listview);
    adapter = new SourceAdapter(this);
    sourcesListView.setAdapter(adapter);
    DragSortController controller = new DragSortController(sourcesListView);
    controller.setDragHandleId(R.id.element_more);
    sourcesListView.setFloatViewManager(controller);
    sourcesListView.setOnTouchListener(controller);
    sourcesListView.setDropListener(dropListener);
    sourcesListView.setOnItemClickListener(onItemClickListener);

    //set theme
    sourcesListView.setBackgroundColor(ContextCompat.getColor(this, ThemesActivity.currentColorBackground));
}
 
Example #2
Source File: AuthenticatorActivity.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
public DragItemController(
    EmptySpaceClickableDragSortListView dragSortListView, Activity activity) {
  super(dragSortListView, R.id.user_row_drag_handle, DragSortController.ON_DOWN, 0);
  this.dragSortListView = dragSortListView;
  this.activity = activity;
  setRemoveEnabled(false);
}
 
Example #3
Source File: AuthenticatorActivity.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
@Override
public int startDragPosition(MotionEvent ev) {
  ListAdapter adapter = dragSortListView.getAdapter();
  // We lock the dragging when the number of account is 0 or 1.
  if (adapter == null || adapter.getCount() <= 1) {
    return DragSortController.MISS;
  }

  // We only allow dragging on selected item.
  int position = super.startDragPosition(ev);
  boolean allowDragging = false;

  try {
    if (getMultiSelectListSingleCheckedItemPosition(dragSortListView) == position) {
      allowDragging = true;
    }
  } catch (IllegalStateException ignored) {
    // No pin code is selected.
  }

  if (!allowDragging) {
    position = DragSortController.MISS;
  }

  if (position != DragSortController.MISS && startDraggingListener != null) {
    startDraggingListener.startDragging();
  }
  return position;
}
 
Example #4
Source File: CustomRecoveryCommandFragment.java    From android-kernel-tweaker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	super.onCreateView(inflater, container, savedInstanceState);
	View v = inflater.inflate(R.layout.dragsort_list, container,false);
	mList = (DragSortListView) v.findViewById(R.id.dslist);
	mReboot = (Button) v.findViewById(R.id.reboot);
	mCancel = (Button) v.findViewById(R.id.cancel);
	mReboot.setOnClickListener(this);
	mCancel.setOnClickListener(this);
	mList.setEmptyView(v.findViewById(R.id.empty));
	list = new ArrayList<String>();
	names = new ArrayList<String>();
	values = new ArrayList<String>();
	backupString = new ArrayList<String>();

	for(int i=0; i<10; i++) {
		list.add("TEST "+i);
	}

	mAdapter = new RecoveryBaseAdapter(mContext, names, values);

	mList.setAdapter(mAdapter);
	mList.setDropListener(onDrop);
	mList.setRemoveListener(onRemove);

	DragSortController controller = new DragSortController(mList);
	controller.setDragHandleId(R.id.image);
	//controller.setClickRemoveId(R.id.);
	controller.setRemoveEnabled(true);
	controller.setSortEnabled(true);
	controller.setDragInitMode(1);
	controller.setFlingHandleId(R.id.item_container);
	//controller.setRemoveMode(removeMode);

	mList.setFloatViewManager(controller);
	mList.setOnTouchListener(controller);
	mList.setDragEnabled(true);
	checkEmptyList();
	return v;
}
 
Example #5
Source File: RouteEdit.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called in onCreateView. Override this to provide a custom
 * DragSortController.
 */
protected DragSortController buildController(DragSortListView dslv)
{
	DragSortController controller = new DragSortController(dslv);
	controller.setDragHandleId(R.id.drag_handle);
	// controller.setClickRemoveId(R.id.click_remove);
	controller.setRemoveEnabled(true);
	controller.setSortEnabled(true);
	controller.setDragInitMode(DragSortController.ON_DOWN);
	controller.setRemoveMode(DragSortController.FLING_REMOVE);
	return controller;
}
 
Example #6
Source File: MultiSelectDragListPreference.javaMultiSelectDragListPreference.java    From Klyph with MIT License 4 votes vote down vote up
@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);
}