Add Group support

This commit is contained in:
Mathieu Maret 2011-01-10 11:39:18 +01:00
parent f51212fa08
commit 38f2fa1222
6 changed files with 57 additions and 41 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hectorone.multismssender" android:versionName="1.1" android:versionCode="1"> package="com.hectorone.multismssender" android:versionName="1.2" android:versionCode="2">
<application android:label="@string/app_name" android:icon="@drawable/multisms"> <application android:label="@string/app_name" android:icon="@drawable/multisms">
<activity android:name=".MultiSmsSender" android:label="@string/app_name"> <activity android:name=".MultiSmsSender" android:label="@string/app_name">
<intent-filter> <intent-filter>

View File

@ -20,7 +20,7 @@
<string name="delivery">Accusé de récéption</string> <string name="delivery">Accusé de récéption</string>
<string name="nodelivery">Aucun accusé de récéption</string> <string name="nodelivery">Aucun accusé de récéption</string>
<string name="enabledelivery">Accusé de récéption</string> <string name="enabledelivery">Accusé de récéption</string>
<string name="create_group">Créer un group</string> <string name="create_group">Créer un groupe</string>
<string name="remove_group">Supprimer ce groupe</string> <string name="remove_group">Supprimer ce groupe</string>
<string name="edit_group">Editer ce groupe</string> <string name="edit_group">Editer ce groupe</string>
<string name="noName">noName</string> <string name="noName">noName</string>

View File

@ -2,16 +2,18 @@ package com.hectorone.multismssender;
import java.util.HashSet; import java.util.HashSet;
import android.app.ListActivity; import android.app.ListActivity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Contacts.Phones; import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
@ -29,8 +31,12 @@ public class GroupEditActivity extends ListActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.edit_group_list); setContentView(R.layout.edit_group_list);
mGroupNameText = (EditText) findViewById(R.id.groupName); mGroupNameText = (EditText) findViewById(R.id.groupName);
Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, Phones.NAME); //Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, Phones.NAME);
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
null, Contacts.DISPLAY_NAME);
startManagingCursor(c); startManagingCursor(c);
String[] mSelected = {}; String[] mSelected = {};
@ -44,12 +50,13 @@ public class GroupEditActivity extends ListActivity {
if (groupId != null) { if (groupId != null) {
Cursor groupNameCursor = mDb.fetchGroup(groupId); Cursor groupNameCursor = mDb.fetchGroup(groupId);
startManagingCursor(groupNameCursor);
String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME)); String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME));
mGroupNameText.setText(groupName); mGroupNameText.setText(groupName);
Cursor numbers = mDb.fetchPhonesFromGroup(groupId); Cursor numbers = mDb.fetchPhonesFromGroup(groupId);
startManagingCursor(numbers); startManagingCursor(numbers);
numbers.moveToFirst(); numbers.moveToFirst();
int phoneNumIdx = numbers.getColumnIndex(Phones.NUMBER); int phoneNumIdx = numbers.getColumnIndex(Phone.NUMBER);
mSelected = new String[numbers.getCount()]; mSelected = new String[numbers.getCount()];
for(int i = 0; i < numbers.getCount(); i++) { for(int i = 0; i < numbers.getCount(); i++) {
mSelected[i] = numbers.getString(phoneNumIdx); mSelected[i] = numbers.getString(phoneNumIdx);
@ -61,7 +68,7 @@ public class GroupEditActivity extends ListActivity {
mAdpater = new GroupDataListAdapter(this, R.layout.number_row, c, new String[] { mAdpater = new GroupDataListAdapter(this, R.layout.number_row, c, new String[] {
Phones.NAME, Phones.NUMBER Contacts.DISPLAY_NAME, Phone.NUMBER
}, new int[] {R.id.name, R.id.phone}, mSelected); }, new int[] {R.id.name, R.id.phone}, mSelected);
setListAdapter(mAdpater); setListAdapter(mAdpater);
@ -78,10 +85,22 @@ public class GroupEditActivity extends ListActivity {
} }
}); });
} }
protected void onStart() {
Log.d("GroupEdit","---onStart");
mDb.open();
super.onStart();
}
protected void onResume() {
Log.d("GroupEdit","---onResume");
super.onResume();
}
protected void onDestroy() { protected void onStop() {
Log.d("GroupEdit","---OnStop");
mDb.close(); mDb.close();
super.onDestroy(); super.onStop();
} }
private void createGroup() { private void createGroup() {
@ -115,9 +134,9 @@ public class GroupEditActivity extends ListActivity {
public GroupDataListAdapter(Context context, int layout, Cursor c, public GroupDataListAdapter(Context context, int layout, Cursor c,
String[] from, int[] to, String[] rawSelected) { String[] from, int[] to, String[] rawSelected) {
super(context, layout, c, from, to); super(context, layout, c, from, to);
nameidx = c.getColumnIndex(Phones.NAME); nameidx = c.getColumnIndex(Contacts.DISPLAY_NAME);
numberidx = c.getColumnIndex(Phones.NUMBER); numberidx = c.getColumnIndex(Phone.NUMBER);
idIdx = c.getColumnIndex(Phones._ID); idIdx = c.getColumnIndex(Data._ID);
mContext = context; mContext = context;
selected = new HashSet<String>(); selected = new HashSet<String>();
for (int i = 0; i < rawSelected.length; i++) { for (int i = 0; i < rawSelected.length; i++) {
@ -127,6 +146,7 @@ public class GroupEditActivity extends ListActivity {
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
Cursor c = getCursor(); Cursor c = getCursor();
startManagingCursor(c);
c.moveToPosition(position); c.moveToPosition(position);
String name = c.getString(nameidx); String name = c.getString(nameidx);
String number = c.getString(numberidx); String number = c.getString(numberidx);

View File

@ -1,18 +1,3 @@
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.hectorone.multismssender; package com.hectorone.multismssender;
@ -22,7 +7,9 @@ import android.database.Cursor;
import android.database.SQLException; import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.provider.Contacts.Phones; import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.util.Log; import android.util.Log;
/** /**
@ -191,8 +178,12 @@ public class GroupsDbAdapter {
Cursor userCursor = null; Cursor userCursor = null;
int phoneIdIdx = mCursor.getColumnIndex(KEY_GROUP_TO_PHONE_PHONEID); int phoneIdIdx = mCursor.getColumnIndex(KEY_GROUP_TO_PHONE_PHONEID);
if(mCursor != null) { if(mCursor != null) {
userCursor = mCtx.getContentResolver().query(Phones.CONTENT_URI, null, "Phones."+ Phones._ID +" IN "+ cursorToStringList(mCursor, phoneIdIdx), null, Phones.NAME); userCursor = mCtx.getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
Data._ID +" IN "+ cursorToStringList(mCursor, phoneIdIdx),
null, Contacts.DISPLAY_NAME);
} }
mCursor.close();
return userCursor; return userCursor;
} }

View File

@ -422,7 +422,7 @@ public class MultiSmsSender extends Activity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
//menu.add(0, INSERT_ID, 0, R.string.add_group); menu.add(0, INSERT_ID, 0, R.string.add_group);
menu.add(0, INSERT_ID + 1, 0, R.string.delivery); menu.add(0, INSERT_ID + 1, 0, R.string.delivery);
return true; return true;
} }

View File

@ -7,8 +7,8 @@ import android.app.ListActivity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Contacts.Phones; import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Groups; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu; import android.view.Menu;
@ -32,6 +32,7 @@ public class SelectGroupActivity extends ListActivity{
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
Log.d("SelectGroup", "***Create");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.group_list); setContentView(R.layout.group_list);
mDbHelper = new GroupsDbAdapter(this); mDbHelper = new GroupsDbAdapter(this);
@ -40,20 +41,24 @@ public class SelectGroupActivity extends ListActivity{
registerForContextMenu(getListView()); registerForContextMenu(getListView());
} }
protected void onStart() {
Log.d("SelectGroup", "***onStart");
mDbHelper.open();
super.onStart();
}
protected void onDestroy() { protected void onStop() {
Log.d("SelectGroup", "***onStop");
mDbHelper.close(); mDbHelper.close();
super.onDestroy(); super.onStop();
} }
public void fillData() { public void fillData() {
Cursor groupsCursor = getContentResolver().query(Groups.CONTENT_URI, new String[]{Groups._ID, Groups.TITLE}, null, null, Groups.TITLE); Cursor groupsCursor = mDbHelper.fetchAllGroups();
startManagingCursor(groupsCursor); startManagingCursor(groupsCursor);
String[] from = new String[]{Groups.TITLE}; String[] from = new String[]{GroupsDbAdapter.KEY_GROUP_NAME};
int[] to = new int[]{R.id.groupNameTextView}; int[] to = new int[]{R.id.groupNameTextView};
@ -82,7 +87,7 @@ public class SelectGroupActivity extends ListActivity{
super.onListItemClick(l, v, position, id); super.onListItemClick(l, v, position, id);
Cursor phonesListCursor = mDbHelper.fetchPhonesFromGroup(id); Cursor phonesListCursor = mDbHelper.fetchPhonesFromGroup(id);
startManagingCursor(phonesListCursor); startManagingCursor(phonesListCursor);
int phoneNumberIdx = phonesListCursor.getColumnIndex(Phones.NUMBER); int phoneNumberIdx = phonesListCursor.getColumnIndex(Phone.NUMBER);
String[] res = new String[phonesListCursor.getCount()]; String[] res = new String[phonesListCursor.getCount()];
phonesListCursor.moveToFirst(); phonesListCursor.moveToFirst();
for (int i = 0; i < res.length; i++) { for (int i = 0; i < res.length; i++) {