Example #1
0
  @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);
  }
Example #2
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   database.close();
 }