Add Group support
This commit is contained in:
parent
f51212fa08
commit
38f2fa1222
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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">
|
||||
<activity android:name=".MultiSmsSender" android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<string name="delivery">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="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="edit_group">Editer ce groupe</string>
|
||||
<string name="noName">noName</string>
|
||||
|
@ -2,16 +2,18 @@ package com.hectorone.multismssender;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
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.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
@ -29,8 +31,12 @@ public class GroupEditActivity extends ListActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.edit_group_list);
|
||||
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);
|
||||
|
||||
String[] mSelected = {};
|
||||
@ -44,12 +50,13 @@ public class GroupEditActivity extends ListActivity {
|
||||
|
||||
if (groupId != null) {
|
||||
Cursor groupNameCursor = mDb.fetchGroup(groupId);
|
||||
startManagingCursor(groupNameCursor);
|
||||
String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME));
|
||||
mGroupNameText.setText(groupName);
|
||||
Cursor numbers = mDb.fetchPhonesFromGroup(groupId);
|
||||
startManagingCursor(numbers);
|
||||
numbers.moveToFirst();
|
||||
int phoneNumIdx = numbers.getColumnIndex(Phones.NUMBER);
|
||||
int phoneNumIdx = numbers.getColumnIndex(Phone.NUMBER);
|
||||
mSelected = new String[numbers.getCount()];
|
||||
for(int i = 0; i < numbers.getCount(); i++) {
|
||||
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[] {
|
||||
Phones.NAME, Phones.NUMBER
|
||||
Contacts.DISPLAY_NAME, Phone.NUMBER
|
||||
}, new int[] {R.id.name, R.id.phone}, mSelected);
|
||||
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();
|
||||
super.onDestroy();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
private void createGroup() {
|
||||
@ -115,9 +134,9 @@ public class GroupEditActivity extends ListActivity {
|
||||
public GroupDataListAdapter(Context context, int layout, Cursor c,
|
||||
String[] from, int[] to, String[] rawSelected) {
|
||||
super(context, layout, c, from, to);
|
||||
nameidx = c.getColumnIndex(Phones.NAME);
|
||||
numberidx = c.getColumnIndex(Phones.NUMBER);
|
||||
idIdx = c.getColumnIndex(Phones._ID);
|
||||
nameidx = c.getColumnIndex(Contacts.DISPLAY_NAME);
|
||||
numberidx = c.getColumnIndex(Phone.NUMBER);
|
||||
idIdx = c.getColumnIndex(Data._ID);
|
||||
mContext = context;
|
||||
selected = new HashSet<String>();
|
||||
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) {
|
||||
Cursor c = getCursor();
|
||||
startManagingCursor(c);
|
||||
c.moveToPosition(position);
|
||||
String name = c.getString(nameidx);
|
||||
String number = c.getString(numberidx);
|
||||
|
@ -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;
|
||||
|
||||
@ -22,7 +7,9 @@ import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -191,8 +178,12 @@ public class GroupsDbAdapter {
|
||||
Cursor userCursor = null;
|
||||
int phoneIdIdx = mCursor.getColumnIndex(KEY_GROUP_TO_PHONE_PHONEID);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ public class MultiSmsSender extends Activity {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu 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);
|
||||
return true;
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Contacts.Phones;
|
||||
import android.provider.ContactsContract.Groups;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
@ -32,6 +32,7 @@ public class SelectGroupActivity extends ListActivity{
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.d("SelectGroup", "***Create");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.group_list);
|
||||
mDbHelper = new GroupsDbAdapter(this);
|
||||
@ -40,20 +41,24 @@ public class SelectGroupActivity extends ListActivity{
|
||||
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();
|
||||
super.onDestroy();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
String[] from = new String[]{Groups.TITLE};
|
||||
String[] from = new String[]{GroupsDbAdapter.KEY_GROUP_NAME};
|
||||
|
||||
int[] to = new int[]{R.id.groupNameTextView};
|
||||
|
||||
@ -82,7 +87,7 @@ public class SelectGroupActivity extends ListActivity{
|
||||
super.onListItemClick(l, v, position, id);
|
||||
Cursor phonesListCursor = mDbHelper.fetchPhonesFromGroup(id);
|
||||
startManagingCursor(phonesListCursor);
|
||||
int phoneNumberIdx = phonesListCursor.getColumnIndex(Phones.NUMBER);
|
||||
int phoneNumberIdx = phonesListCursor.getColumnIndex(Phone.NUMBER);
|
||||
String[] res = new String[phonesListCursor.getCount()];
|
||||
phonesListCursor.moveToFirst();
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user