5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-11-08 09:50:26 +00:00
This commit is contained in:
Jesse Young 2011-09-14 12:26:14 -07:00
parent 41141fa5fd
commit 0071efd297
6 changed files with 225 additions and 31 deletions

View File

@ -9,7 +9,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
android:choiceMode="multipleChoice" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"

View File

@ -1,31 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.envaya.kalsms.CheckableRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6sp"
android:background="#cccccc">
<CheckBox android:id="@+id/inbox_checkbox"
android:background="#cccccc">
<org.envaya.kalsms.InertCheckBox android:id="@+id/inbox_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:focusable="false"
/>
<TextView
android:id="@+id/inbox_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/inbox_checkbox"
android:layout_alignTop="@id/inbox_checkbox"
android:textColor="#333333"
android:layout_marginTop="4sp"
android:layout_marginLeft="6sp"
android:focusable="false"
android:textSize="14sp"></TextView>
<TextView
android:id="@+id/inbox_body"
android:layout_below="@id/inbox_address"
android:layout_alignLeft="@id/inbox_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#666666"
android:layout_marginLeft="6sp"
android:layout_marginBottom="6sp"
android:focusable="false"
android:paddingBottom="6sp"
android:textSize="14sp"></TextView>
</LinearLayout>
</LinearLayout>
</org.envaya.kalsms.CheckableRelativeLayout>

View File

@ -0,0 +1,105 @@
package org.envaya.kalsms;
// from http://www.marvinlabs.com/2010/10/custom-listview-ability-check-items/
// package fr.marvinlabs.widget;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Checkable;
import android.widget.RelativeLayout;
/**
* Extension of a relative layout to provide a checkable behavior
*
* @author marvinlabs
*/
public class CheckableRelativeLayout extends RelativeLayout implements
Checkable {
private boolean isChecked;
private List<Checkable> checkableViews;
public CheckableRelativeLayout(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
initialise(attrs);
}
public CheckableRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initialise(attrs);
}
public CheckableRelativeLayout(Context context, int checkableId) {
super(context);
initialise(null);
}
/*
* @see android.widget.Checkable#isChecked()
*/
public boolean isChecked() {
return isChecked;
}
/*
* @see android.widget.Checkable#setChecked(boolean)
*/
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
for (Checkable c : checkableViews) {
c.setChecked(isChecked);
}
}
/*
* @see android.widget.Checkable#toggle()
*/
public void toggle() {
this.isChecked = !this.isChecked;
for (Checkable c : checkableViews) {
c.toggle();
}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
final int childCount = this.getChildCount();
for (int i = 0; i < childCount; ++i) {
findCheckableChildren(this.getChildAt(i));
}
}
/**
* Read the custom XML attributes
*/
private void initialise(AttributeSet attrs) {
this.isChecked = false;
this.checkableViews = new ArrayList<Checkable>(5);
}
/**
* Add to our checkable list all the children of the view that implement the
* interface Checkable
*/
private void findCheckableChildren(View v) {
if (v instanceof Checkable) {
this.checkableViews.add((Checkable) v);
}
if (v instanceof ViewGroup) {
final ViewGroup vg = (ViewGroup) v;
final int childCount = vg.getChildCount();
for (int i = 0; i < childCount; ++i) {
findCheckableChildren(vg.getChildAt(i));
}
}
}
}

View File

@ -5,17 +5,18 @@ import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class ForwardInbox extends ListActivity {
private App app;
private Cursor cur;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
@ -30,7 +31,7 @@ public class ForwardInbox extends ListActivity {
Uri inboxUri = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(inboxUri, null, null, null, null);
cur = getContentResolver().query(inboxUri, null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.inbox_item,
@ -39,26 +40,38 @@ public class ForwardInbox extends ListActivity {
new int[] {R.id.inbox_address, R.id.inbox_body});
setListAdapter(adapter);
ListView listView = getListView();
listView.setItemsCanFocus(false);
}
public void forwardSelected(View view) {
ListView listView = getListView();
// there is probably a less hacky way to do this...
int childCount = listView.getChildCount();
for (int i = 0; i < childCount; i++)
SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
int checkedItemsCount = checkedItems.size();
int addressIndex = cur.getColumnIndex("address");
int bodyIndex = cur.getColumnIndex("body");
int dateIndex = cur.getColumnIndex("date");
for (int i = 0; i < checkedItemsCount; ++i)
{
View entry = listView.getChildAt(i);
CheckBox checkbox = (CheckBox) entry.findViewById(R.id.inbox_checkbox);
int position = checkedItems.keyAt(i);
boolean isChecked = checkedItems.valueAt(i);
if (checkbox.isChecked())
{
TextView addressView = (TextView) entry.findViewById(R.id.inbox_address);
TextView bodyView = (TextView) entry.findViewById(R.id.inbox_body);
IncomingMessage sms = new IncomingMessage(app,
addressView.getText().toString(),
bodyView.getText().toString());
if (isChecked)
{
cur.moveToPosition(position);
String address = cur.getString(addressIndex);
String body = cur.getString(bodyIndex);
long date = cur.getLong(dateIndex);
IncomingMessage sms = new IncomingMessage(app, address, body, date);
app.forwardToServer(sms);
}

View File

@ -9,7 +9,7 @@ public class IncomingMessage extends QueuedMessage {
public String from;
public String message;
public long timestampMillis = 0;
public long timestampMillis;
public IncomingMessage(App app, SmsMessage sms) {
super(app);
@ -18,10 +18,11 @@ public class IncomingMessage extends QueuedMessage {
this.timestampMillis = sms.getTimestampMillis();
}
public IncomingMessage(App app, String from, String message) {
public IncomingMessage(App app, String from, String message, long timestampMillis) {
super(app);
this.from = from;
this.message = message;
this.timestampMillis = timestampMillis;
}
public String getMessageBody()

View File

@ -0,0 +1,72 @@
package org.envaya.kalsms;
// from http://www.marvinlabs.com/2010/10/custom-listview-ability-check-items/
// package fr.marvinlabs.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.CheckBox;
/**
* CheckBox that does not react to any user event in order to let the container handle them.
*/
public class InertCheckBox extends CheckBox {
// Provide the same constructors as the superclass
public InertCheckBox(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
// Provide the same constructors as the superclass
public InertCheckBox(Context context, AttributeSet attrs) {
super(context, attrs);
}
// Provide the same constructors as the superclass
public InertCheckBox(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// Make the checkbox not respond to any user event
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Make the checkbox not respond to any user event
return false;
}
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
// Make the checkbox not respond to any user event
return false;
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
// Make the checkbox not respond to any user event
return false;
}
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
// Make the checkbox not respond to any user event
return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// Make the checkbox not respond to any user event
return false;
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
// Make the checkbox not respond to any user event
return false;
}
}