@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.codecs_list, container, false); DragnDropListView listView = (DragnDropListView) v.findViewById(android.R.id.list); listView.setOnDropListener( new DropListener() { @Override public void drop(int from, int to) { @SuppressWarnings("unchecked") HashMap<String, Object> item = (HashMap<String, Object>) getListAdapter().getItem(from); Log.d(THIS_FILE, "Dropped " + item.get(CODEC_NAME) + " -> " + to); // Prevent disabled codecsList to be reordered if ((Short) item.get(CODEC_PRIORITY) <= 0) { return; } codecsList.remove(from); codecsList.add(to, item); // Update priorities short currentPriority = 130; for (Map<String, Object> codec : codecsList) { if ((Short) codec.get(CODEC_PRIORITY) > 0) { if (currentPriority != (Short) codec.get(CODEC_PRIORITY)) { setCodecPriority((String) codec.get(CODEC_ID), currentPriority); codec.put(CODEC_PRIORITY, currentPriority); } // Log.d(THIS_FILE, "Reorder : "+codec.toString()); currentPriority--; } } // Log.d(THIS_FILE, "Data set "+codecsList.toString()); mAdapter.notifyDataSetChanged(); } }); listView.setOnCreateContextMenuListener(this); return v; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view View v = inflater.inflate(R.layout.accounts_edit_list, container, false); DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber); // Setup the drop listener lv.setOnDropListener( new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } }); return v; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); if (extras != null) { accountId = extras.getLong(SipProfile.FIELD_ID, -1); } if (accountId == -1) { Log.e(THIS_FILE, "You provide an empty account id...."); finish(); } // Custom title listing the account name for filters // final boolean customTitleOk = // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.filters_list); /* * if(customTitleOk) { * getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, * R.layout.account_filters_title); final TextView titleText = * (TextView) findViewById(R.id.account_filters_title); if (titleText != * null) { SipProfile acct = SipProfile.getProfileFromDbId(this, * accountId, new String[] {SipProfile.FIELD_ID, * SipProfile.FIELD_DISPLAY_NAME}); * titleText.setText(R.string.filters_for); titleText.append(" " + * acct.display_name); } } */ database = new DBAdapter(this); database.open(); // Add add row TextView add_row = (TextView) findViewById(R.id.add_filter); add_row.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { editFilterActivity(-1); } }); cursor = database.getFiltersForAccount(accountId); if (cursor != null) { startManagingCursor(cursor); } CursorAdapter adapter = new FiltersCursorAdapter(this, cursor); setListAdapter(adapter); DragnDropListView listView = (DragnDropListView) getListView(); listView.setOnDropListener( new DropListener() { @Override public void drop(int from, int to) { // Update priorities CursorAdapter ad = (CursorAdapter) getListAdapter(); int numRows = ad.getCount(); for (int i = 0; i < numRows; i++) { // Log.d(THIS_FILE, "i= "+i+" from ="+from+" to="+to); if (i != from) { if (from > i && i >= to) { updateFilterPriority(ad.getItemId(i), i + 1); } else if (from < i && i <= to) { updateFilterPriority(ad.getItemId(i), i - 1); } else { updateFilterPriority(ad.getItemId(i), i); } } else { updateFilterPriority(ad.getItemId(from), to); } } cursor.requery(); } }); listView.setOnCreateContextMenuListener(this); }