summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBen Komalo <benkomalo@google.com>2010-10-26 14:26:34 -0700
committerBen Komalo <benkomalo@google.com>2010-10-26 15:39:55 -0700
commitad9a9c83630d87328c8439ac8b8b9a2c800dbd57 (patch)
tree71f8fa7938fce8a6a1e782e73fe5295a992c5ada /src
parent4761179c750ed341b4142c1cb5ce4ba077eb3187 (diff)
downloadandroid_packages_apps_Tag-ad9a9c83630d87328c8439ac8b8b9a2c800dbd57.tar.gz
android_packages_apps_Tag-ad9a9c83630d87328c8439ac8b8b9a2c800dbd57.tar.bz2
android_packages_apps_Tag-ad9a9c83630d87328c8439ac8b8b9a2c800dbd57.zip
Wire up delete icon for each record.
This introduces an explicit callbacks interface for the host activity. Change-Id: I381c59176daea4c97daa7f8d392eb30fc181e2a9
Diffstat (limited to 'src')
-rw-r--r--src/com/android/apps/tag/EditTagActivity.java24
-rw-r--r--src/com/android/apps/tag/MyTagActivity.java5
-rw-r--r--src/com/android/apps/tag/record/ImageRecord.java18
-rw-r--r--src/com/android/apps/tag/record/RecordEditInfo.java40
-rw-r--r--src/com/android/apps/tag/record/UriRecord.java7
-rw-r--r--src/com/android/apps/tag/record/VCardRecord.java19
6 files changed, 82 insertions, 31 deletions
diff --git a/src/com/android/apps/tag/EditTagActivity.java b/src/com/android/apps/tag/EditTagActivity.java
index 03df21a..c1683d2 100644
--- a/src/com/android/apps/tag/EditTagActivity.java
+++ b/src/com/android/apps/tag/EditTagActivity.java
@@ -19,6 +19,7 @@ package com.android.apps.tag;
import com.android.apps.tag.record.ImageRecord;
import com.android.apps.tag.record.ParsedNdefRecord;
import com.android.apps.tag.record.RecordEditInfo;
+import com.android.apps.tag.record.RecordEditInfo.EditCallbacks;
import com.android.apps.tag.record.UriRecord;
import com.android.apps.tag.record.VCardRecord;
import com.google.common.base.Preconditions;
@@ -46,7 +47,7 @@ import java.util.Set;
* {@link ParsedNdefRecord} types. Each type of {@link ParsedNdefRecord} can build views to
* pick/select a new piece of content, or edit an existing content for the {@link NdefMessage}.
*/
-public abstract class EditTagActivity extends Activity implements OnClickListener {
+public abstract class EditTagActivity extends Activity implements OnClickListener, EditCallbacks {
private static final String BUNDLE_KEY_OUTSTANDING_PICK = "outstanding-pick";
protected static final int DIALOG_ID_ADD_CONTENT = 0;
@@ -138,13 +139,9 @@ public abstract class EditTagActivity extends Activity implements OnClickListene
*/
public void addViewForRecord(RecordEditInfo editInfo) {
ViewGroup root = getContentRoot();
- View editView = editInfo.getEditView(this, mInflater, root);
+ View editView = editInfo.getEditView(this, mInflater, root, this);
root.addView(mInflater.inflate(R.layout.tag_divider, root, false));
root.addView(editView);
-
- if (editInfo.getPickIntent() != null) {
- editView.setOnClickListener(this);
- }
}
private void rebuildChildViews() {
@@ -177,9 +174,7 @@ public abstract class EditTagActivity extends Activity implements OnClickListene
showDialog(DIALOG_ID_ADD_CONTENT);
}
- /**
- * Fires an {@link Intent} to pick content for a record.
- */
+ @Override
public void startPickForRecord(RecordEditInfo editInfo, Intent intent) {
mRecordWithOutstandingPick = editInfo;
startActivityForResult(intent, 0);
@@ -205,12 +200,11 @@ public abstract class EditTagActivity extends Activity implements OnClickListene
}
@Override
- public void onClick(View target) {
- Object tag = target.getTag();
- if ((tag != null) && (tag instanceof RecordEditInfo)) {
- RecordEditInfo editInfo = (RecordEditInfo) tag;
- startPickForRecord(editInfo, Preconditions.checkNotNull(editInfo.getPickIntent()));
- }
+ public void deleteRecord(RecordEditInfo editInfo) {
+ mRecords.remove(editInfo);
+ ViewGroup root = getContentRoot();
+ root.removeAllViews();
+ rebuildChildViews();
}
@Override
diff --git a/src/com/android/apps/tag/MyTagActivity.java b/src/com/android/apps/tag/MyTagActivity.java
index 9a8a97f..38effaa 100644
--- a/src/com/android/apps/tag/MyTagActivity.java
+++ b/src/com/android/apps/tag/MyTagActivity.java
@@ -32,8 +32,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
-import android.widget.Toast;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -139,9 +137,6 @@ public class MyTagActivity extends EditTagActivity implements OnClickListener {
case R.id.add_content_target:
showAddContentDialog();
break;
-
- default:
- super.onClick(target);
}
}
diff --git a/src/com/android/apps/tag/record/ImageRecord.java b/src/com/android/apps/tag/record/ImageRecord.java
index 8f5879e..4361c9b 100644
--- a/src/com/android/apps/tag/record/ImageRecord.java
+++ b/src/com/android/apps/tag/record/ImageRecord.java
@@ -184,10 +184,13 @@ public class ImageRecord implements ParsedNdefRecord {
}
@Override
- public View getEditView(Activity activity, LayoutInflater inflater, ViewGroup parent) {
- View result = inflater.inflate(R.layout.tag_edit_image, parent, false);
+ public View getEditView(
+ Activity activity, LayoutInflater inflater,
+ ViewGroup parent, EditCallbacks callbacks) {
+ View result = buildEditView(
+ activity, inflater, R.layout.tag_edit_image, parent, callbacks);
((ImageView) result.findViewById(R.id.image)).setImageBitmap(getValueInternal());
- result.setTag(this);
+ result.setOnClickListener(this);
return result;
}
@@ -214,5 +217,14 @@ public class ImageRecord implements ParsedNdefRecord {
public int describeContents() {
return 0;
}
+
+ @Override
+ public void onClick(View target) {
+ if (this == target.getTag()) {
+ mCallbacks.startPickForRecord(this, mIntent);
+ } else {
+ super.onClick(target);
+ }
+ }
}
}
diff --git a/src/com/android/apps/tag/record/RecordEditInfo.java b/src/com/android/apps/tag/record/RecordEditInfo.java
index ea453e6..6b0bf6e 100644
--- a/src/com/android/apps/tag/record/RecordEditInfo.java
+++ b/src/com/android/apps/tag/record/RecordEditInfo.java
@@ -16,6 +16,8 @@
package com.android.apps.tag.record;
+import com.android.apps.tag.R;
+
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -29,13 +31,20 @@ import android.view.ViewGroup;
/**
* A simple holder for information required for editing a {@code ParsedNdefRecord}.
*/
-public abstract class RecordEditInfo implements Parcelable {
+public abstract class RecordEditInfo implements Parcelable, View.OnClickListener {
+
+ public interface EditCallbacks {
+ void startPickForRecord(RecordEditInfo info, Intent intent);
+ void deleteRecord(RecordEditInfo info);
+ }
/**
* The record type being edited.
*/
private final String mType;
+ protected EditCallbacks mCallbacks;
+
public RecordEditInfo(String type) {
mType = type;
}
@@ -71,10 +80,37 @@ public abstract class RecordEditInfo implements Parcelable {
* the value of the record.
* This {@code RecordEditInfo} will be set as the {@link View}'s tag.
*/
- public abstract View getEditView(Activity activity, LayoutInflater inflater, ViewGroup parent);
+ public abstract View getEditView(
+ Activity activity, LayoutInflater inflater, ViewGroup parent, EditCallbacks callbacks);
+
+ /**
+ * Does the work of building a {@link View} and binding common controls.
+ */
+ protected View buildEditView(
+ Activity activity, LayoutInflater inflater, int resourceId,
+ ViewGroup parent, EditCallbacks callbacks) {
+ View result = inflater.inflate(resourceId, parent, false);
+ result.setTag(this);
+
+ View deleteButton = result.findViewById(R.id.delete);
+ if (deleteButton == null) {
+ throw new IllegalArgumentException("All record edit layouts must have a delete button");
+ } else {
+ deleteButton.setOnClickListener(this);
+ }
+ mCallbacks = callbacks;
+ return result;
+ }
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(mType);
}
+
+ @Override
+ public void onClick(View target) {
+ if (target.getId() == R.id.delete) {
+ mCallbacks.deleteRecord(this);
+ }
+ }
}
diff --git a/src/com/android/apps/tag/record/UriRecord.java b/src/com/android/apps/tag/record/UriRecord.java
index 471068a..3777771 100644
--- a/src/com/android/apps/tag/record/UriRecord.java
+++ b/src/com/android/apps/tag/record/UriRecord.java
@@ -286,12 +286,13 @@ public class UriRecord implements ParsedNdefRecord, OnClickListener {
}
@Override
- public View getEditView(Activity activity, LayoutInflater inflater, ViewGroup parent) {
- View view = inflater.inflate(R.layout.tag_edit_url, parent, false);
+ public View getEditView(
+ Activity activity, LayoutInflater inflater,
+ ViewGroup parent, EditCallbacks callbacks) {
+ View view = buildEditView(activity, inflater, R.layout.tag_edit_url, parent, callbacks);
mEditText = (EditText) view.findViewById(R.id.value);
mEditText.setText(mCurrentValue);
mEditText.addTextChangedListener(this);
- view.setTag(this);
return view;
}
diff --git a/src/com/android/apps/tag/record/VCardRecord.java b/src/com/android/apps/tag/record/VCardRecord.java
index 75caac4..71d94a9 100644
--- a/src/com/android/apps/tag/record/VCardRecord.java
+++ b/src/com/android/apps/tag/record/VCardRecord.java
@@ -268,10 +268,14 @@ public class VCardRecord implements ParsedNdefRecord, OnClickListener {
}
@Override
- public View getEditView(Activity activity, LayoutInflater inflater, ViewGroup parent) {
- View result = inflater.inflate(R.layout.tag_edit_vcard, parent, false);
+ public View getEditView(
+ Activity activity, LayoutInflater inflater,
+ ViewGroup parent, EditCallbacks callbacks) {
+ View result = buildEditView(
+ activity, inflater, R.layout.tag_edit_vcard, parent, callbacks);
+
mActiveView = new WeakReference<View>(result);
- result.setTag(this);
+ result.setOnClickListener(this);
// Show default contact photo until the data loads.
((ImageView) result.findViewById(R.id.photo)).setImageDrawable(
@@ -304,5 +308,14 @@ public class VCardRecord implements ParsedNdefRecord, OnClickListener {
public int describeContents() {
return 0;
}
+
+ @Override
+ public void onClick(View target) {
+ if (this == target.getTag()) {
+ mCallbacks.startPickForRecord(this, mIntent);
+ } else {
+ super.onClick(target);
+ }
+ }
}
}