mirror of
https://github.com/cwinfo/envayasms.git
synced 2024-12-04 20:45:32 +00:00
improve ForwardInbox with help from http://www.marvinlabs.com/2010/10/custom-listview-ability-check-items/
This commit is contained in:
parent
41141fa5fd
commit
0071efd297
@ -9,7 +9,7 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:drawSelectorOnTop="false"/>
|
android:choiceMode="multipleChoice" />
|
||||||
<Button
|
<Button
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -1,31 +1,34 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:orientation="horizontal"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="6sp"
|
android:background="#cccccc">
|
||||||
android:background="#cccccc">
|
<org.envaya.kalsms.InertCheckBox android:id="@+id/inbox_checkbox"
|
||||||
<CheckBox android:id="@+id/inbox_checkbox"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
<LinearLayout
|
android:focusable="false"
|
||||||
android:orientation="vertical"
|
/>
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/inbox_address"
|
android:id="@+id/inbox_address"
|
||||||
android:layout_width="fill_parent"
|
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:textColor="#333333"
|
||||||
android:layout_marginTop="4sp"
|
android:layout_marginTop="4sp"
|
||||||
android:layout_marginLeft="6sp"
|
android:layout_marginLeft="6sp"
|
||||||
|
android:focusable="false"
|
||||||
android:textSize="14sp"></TextView>
|
android:textSize="14sp"></TextView>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/inbox_body"
|
android:id="@+id/inbox_body"
|
||||||
|
android:layout_below="@id/inbox_address"
|
||||||
|
android:layout_alignLeft="@id/inbox_address"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="#666666"
|
android:textColor="#666666"
|
||||||
android:layout_marginLeft="6sp"
|
android:layout_marginBottom="6sp"
|
||||||
|
android:focusable="false"
|
||||||
|
android:paddingBottom="6sp"
|
||||||
android:textSize="14sp"></TextView>
|
android:textSize="14sp"></TextView>
|
||||||
</LinearLayout>
|
</org.envaya.kalsms.CheckableRelativeLayout>
|
||||||
</LinearLayout>
|
|
105
src/org/envaya/kalsms/CheckableRelativeLayout.java
Executable file
105
src/org/envaya/kalsms/CheckableRelativeLayout.java
Executable 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,17 +5,18 @@ import android.app.ListActivity;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.SparseBooleanArray;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.SimpleCursorAdapter;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
|
|
||||||
public class ForwardInbox extends ListActivity {
|
public class ForwardInbox extends ListActivity {
|
||||||
|
|
||||||
private App app;
|
private App app;
|
||||||
|
|
||||||
|
private Cursor cur;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@ -30,7 +31,7 @@ public class ForwardInbox extends ListActivity {
|
|||||||
|
|
||||||
Uri inboxUri = Uri.parse("content://sms/inbox");
|
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,
|
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
|
||||||
R.layout.inbox_item,
|
R.layout.inbox_item,
|
||||||
@ -39,26 +40,38 @@ public class ForwardInbox extends ListActivity {
|
|||||||
new int[] {R.id.inbox_address, R.id.inbox_body});
|
new int[] {R.id.inbox_address, R.id.inbox_body});
|
||||||
|
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
|
|
||||||
|
ListView listView = getListView();
|
||||||
|
|
||||||
|
listView.setItemsCanFocus(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forwardSelected(View view) {
|
public void forwardSelected(View view) {
|
||||||
|
|
||||||
ListView listView = getListView();
|
ListView listView = getListView();
|
||||||
|
|
||||||
// there is probably a less hacky way to do this...
|
SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
|
||||||
int childCount = listView.getChildCount();
|
|
||||||
for (int i = 0; i < childCount; i++)
|
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);
|
int position = checkedItems.keyAt(i);
|
||||||
CheckBox checkbox = (CheckBox) entry.findViewById(R.id.inbox_checkbox);
|
boolean isChecked = checkedItems.valueAt(i);
|
||||||
|
|
||||||
if (checkbox.isChecked())
|
if (isChecked)
|
||||||
{
|
{
|
||||||
TextView addressView = (TextView) entry.findViewById(R.id.inbox_address);
|
cur.moveToPosition(position);
|
||||||
TextView bodyView = (TextView) entry.findViewById(R.id.inbox_body);
|
|
||||||
IncomingMessage sms = new IncomingMessage(app,
|
String address = cur.getString(addressIndex);
|
||||||
addressView.getText().toString(),
|
String body = cur.getString(bodyIndex);
|
||||||
bodyView.getText().toString());
|
long date = cur.getLong(dateIndex);
|
||||||
|
|
||||||
|
IncomingMessage sms = new IncomingMessage(app, address, body, date);
|
||||||
|
|
||||||
app.forwardToServer(sms);
|
app.forwardToServer(sms);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class IncomingMessage extends QueuedMessage {
|
|||||||
|
|
||||||
public String from;
|
public String from;
|
||||||
public String message;
|
public String message;
|
||||||
public long timestampMillis = 0;
|
public long timestampMillis;
|
||||||
|
|
||||||
public IncomingMessage(App app, SmsMessage sms) {
|
public IncomingMessage(App app, SmsMessage sms) {
|
||||||
super(app);
|
super(app);
|
||||||
@ -18,10 +18,11 @@ public class IncomingMessage extends QueuedMessage {
|
|||||||
this.timestampMillis = sms.getTimestampMillis();
|
this.timestampMillis = sms.getTimestampMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IncomingMessage(App app, String from, String message) {
|
public IncomingMessage(App app, String from, String message, long timestampMillis) {
|
||||||
super(app);
|
super(app);
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.timestampMillis = timestampMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessageBody()
|
public String getMessageBody()
|
||||||
|
72
src/org/envaya/kalsms/InertCheckBox.java
Executable file
72
src/org/envaya/kalsms/InertCheckBox.java
Executable 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user