VoicemaiProviderDemoApp changed to use api from sdk.
Voicemail content provider APIs are now part of the SDK. This CL gets rid of the local copy of VoicemailContracts and instead uses the APIs from the SDK. Key differences between the old and latest APIs - voicemail permission renamed from READ_WRITE_OWN_VOICEMAILS to ADD_VOICEMAIL - voicemail state is a hidden field, so not part of the API. Demo app should not use it. - Use IS_READ field instead of NEW. Change-Id: Ib142eb02bb89eed32a7976b66132893a98aba466
This commit is contained in:
@@ -16,6 +16,16 @@
|
||||
|
||||
package com.example.android.voicemail;
|
||||
|
||||
import com.example.android.voicemail.common.core.Voicemail;
|
||||
import com.example.android.voicemail.common.core.VoicemailImpl;
|
||||
import com.example.android.voicemail.common.core.VoicemailProviderHelper;
|
||||
import com.example.android.voicemail.common.core.VoicemailProviderHelpers;
|
||||
import com.example.android.voicemail.common.inject.InjectView;
|
||||
import com.example.android.voicemail.common.inject.Injector;
|
||||
import com.example.android.voicemail.common.logging.Logger;
|
||||
import com.example.android.voicemail.common.ui.DialogHelperImpl;
|
||||
import com.example.android.voicemail.common.utils.CloseUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
@@ -28,16 +38,6 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.android.voicemail.common.core.Voicemail;
|
||||
import com.example.android.voicemail.common.core.VoicemailImpl;
|
||||
import com.example.android.voicemail.common.core.VoicemailProviderHelper;
|
||||
import com.example.android.voicemail.common.core.VoicemailProviderHelpers;
|
||||
import com.example.android.voicemail.common.inject.InjectView;
|
||||
import com.example.android.voicemail.common.inject.Injector;
|
||||
import com.example.android.voicemail.common.logging.Logger;
|
||||
import com.example.android.voicemail.common.ui.DialogHelperImpl;
|
||||
import com.example.android.voicemail.common.utils.CloseUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -131,7 +131,6 @@ public class AddVoicemailActivity extends Activity {
|
||||
return VoicemailImpl.createForInsertion(time, sender)
|
||||
.setDuration(duration)
|
||||
.setSourcePackage(sourcePackageName)
|
||||
.setMailbox(Voicemail.Mailbox.INBOX)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import com.example.android.provider.VoicemailContract;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
@@ -26,41 +24,6 @@ import android.net.Uri;
|
||||
* The presence of a field is indicated by a corresponding 'has' method.
|
||||
*/
|
||||
public interface Voicemail {
|
||||
/**
|
||||
* Which mailbox the message is sitting in.
|
||||
* <p>
|
||||
* Note that inbox and deleted are alone insufficient, because we may have a provider that is
|
||||
* not able to undelete (re-upload) a message. Thus we need a state to represent the (common)
|
||||
* case where the user has deleted a message (which results in the message being removed from
|
||||
* the server) and then restored the message (where we are unable to re-upload the message to
|
||||
* the server). That's what the undeleted state is for.
|
||||
* <p>
|
||||
* The presence of an undeleted mailbox prevents the voicemail source from having to keep a list
|
||||
* of all such deleted-then-restored message ids, without which it would be unable to tell the
|
||||
* difference between a message that has been deleted-then-restored by the user and a message
|
||||
* which has been deleted on the server and should now be removed (for example one removed via
|
||||
* an IVR).
|
||||
*/
|
||||
public enum Mailbox {
|
||||
/** After being fetched from the server, a message usually starts in the inbox. */
|
||||
INBOX(VoicemailContract.Voicemails.STATE_INBOX),
|
||||
/** Indicates that a message has been deleted. */
|
||||
DELETED(VoicemailContract.Voicemails.STATE_DELETED),
|
||||
/** Restored from having been deleted, distinct from being in the inbox. */
|
||||
UNDELETED(VoicemailContract.Voicemails.STATE_UNDELETED);
|
||||
|
||||
private final int mValue;
|
||||
|
||||
private Mailbox(int value) {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
/** Returns the DB value of this mailbox state. */
|
||||
public int getValue() {
|
||||
return mValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The identifier of the voicemail in the content provider.
|
||||
* <p>
|
||||
@@ -116,11 +79,6 @@ public interface Voicemail {
|
||||
|
||||
public boolean hasUri();
|
||||
|
||||
/** Tells us which mailbox the message is sitting in, returns null if this is not set. */
|
||||
public Voicemail.Mailbox getMailbox();
|
||||
|
||||
public boolean hasMailbox();
|
||||
|
||||
/**
|
||||
* Tells us if the voicemail message has been marked as read.
|
||||
* <p>
|
||||
|
||||
@@ -20,9 +20,7 @@ import static com.example.android.voicemail.common.utils.DbQueryUtils.concatenat
|
||||
import static com.example.android.voicemail.common.utils.DbQueryUtils.concatenateClausesWithOr;
|
||||
import static com.example.android.voicemail.common.utils.DbQueryUtils.getEqualityClause;
|
||||
|
||||
import com.example.android.voicemail.common.core.Voicemail.Mailbox;
|
||||
import com.example.android.provider.VoicemailContract.Voicemails;
|
||||
|
||||
import android.provider.VoicemailContract.Voicemails;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -31,8 +29,8 @@ import java.util.List;
|
||||
/**
|
||||
* Factory class to create {@link VoicemailFilter} objects for various filtering needs.
|
||||
* <p>
|
||||
* Factory methods like {@link #createWithMailbox(Mailbox)}, {@link #createWithReadStatus(boolean)}
|
||||
* and {@link #createWithMatchingFields(Voicemail)} can be used to create a voicemail filter that
|
||||
* Factory methods like {@link #createWithReadStatus(boolean)} and
|
||||
* {@link #createWithMatchingFields(Voicemail)} can be used to create a voicemail filter that
|
||||
* matches the value of the specific field.
|
||||
* <p>
|
||||
* It is possible to combine multiple filters with OR or AND operation using the methods
|
||||
@@ -44,13 +42,6 @@ import java.util.List;
|
||||
* content provider database and is therefore less recommended.
|
||||
*/
|
||||
public class VoicemailFilterFactory {
|
||||
/** Predefined filter for inbox only messages. */
|
||||
public static final VoicemailFilter INBOX_MESSAGES_FILTER = createWithOrOf(
|
||||
createWithMailbox(Mailbox.INBOX), createWithMailbox(Mailbox.UNDELETED));
|
||||
/** Predefined filter for trashed messages. */
|
||||
public static final VoicemailFilter TRASHED_MESSAGES_FILTER =
|
||||
createWithMailbox(Mailbox.DELETED);
|
||||
|
||||
/**
|
||||
* Creates a voicemail filter with the specified where clause. Use this method only if you know
|
||||
* and want to directly use the column names of the content provider. For most of the usages
|
||||
@@ -78,12 +69,6 @@ public class VoicemailFilterFactory {
|
||||
getWhereClauseForMatchingFields(fieldMatch));
|
||||
}
|
||||
|
||||
/** Creates a voicemail filter with the specified mailbox state. */
|
||||
public static VoicemailFilter createWithMailbox(Mailbox mailbox) {
|
||||
return createWithMatchingFields(
|
||||
VoicemailImpl.createEmptyBuilder().setMailbox(mailbox).build());
|
||||
}
|
||||
|
||||
/** Creates a voicemail filter with the specified read status. */
|
||||
public static VoicemailFilter createWithReadStatus(boolean isRead) {
|
||||
return createWithMatchingFields(
|
||||
@@ -111,11 +96,7 @@ public class VoicemailFilterFactory {
|
||||
private static String getWhereClauseForMatchingFields(Voicemail fieldMatch) {
|
||||
List<String> clauses = new ArrayList<String>();
|
||||
if (fieldMatch.hasRead()) {
|
||||
clauses.add(getEqualityClause(Voicemails.NEW, fieldMatch.isRead() ? "1" : "0"));
|
||||
}
|
||||
if (fieldMatch.hasMailbox()) {
|
||||
clauses.add(getEqualityClause(Voicemails.STATE,
|
||||
Integer.toString(fieldMatch.getMailbox().getValue())));
|
||||
clauses.add(getEqualityClause(Voicemails.IS_READ, fieldMatch.isRead() ? "1" : "0"));
|
||||
}
|
||||
if (fieldMatch.hasNumber()) {
|
||||
clauses.add(getEqualityClause(Voicemails.NUMBER, fieldMatch.getNumber()));
|
||||
|
||||
@@ -29,7 +29,6 @@ public final class VoicemailImpl implements Voicemail {
|
||||
private final String mSource;
|
||||
private final String mProviderData;
|
||||
private final Uri mUri;
|
||||
private final Voicemail.Mailbox mMailbox;
|
||||
private final Boolean mIsRead;
|
||||
private final boolean mHasContent;
|
||||
|
||||
@@ -44,7 +43,6 @@ public final class VoicemailImpl implements Voicemail {
|
||||
String source,
|
||||
String providerData,
|
||||
Uri uri,
|
||||
Voicemail.Mailbox mailbox,
|
||||
Boolean isRead,
|
||||
boolean hasContent) {
|
||||
mId = id;
|
||||
@@ -54,7 +52,6 @@ public final class VoicemailImpl implements Voicemail {
|
||||
mSource = source;
|
||||
mProviderData = providerData;
|
||||
mUri = uri;
|
||||
mMailbox = mailbox;
|
||||
mIsRead = isRead;
|
||||
mHasContent = hasContent;
|
||||
}
|
||||
@@ -100,7 +97,6 @@ public final class VoicemailImpl implements Voicemail {
|
||||
private String mBuilderSourcePackage;
|
||||
private String mBuilderSourceData;
|
||||
private Uri mBuilderUri;
|
||||
private Voicemail.Mailbox mBuilderMailbox;
|
||||
private Boolean mBuilderIsRead;
|
||||
private boolean mBuilderHasContent;
|
||||
|
||||
@@ -143,11 +139,6 @@ public final class VoicemailImpl implements Voicemail {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMailbox(Voicemail.Mailbox mailbox) {
|
||||
mBuilderMailbox = mailbox;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIsRead(boolean isRead) {
|
||||
mBuilderIsRead = isRead;
|
||||
return this;
|
||||
@@ -161,7 +152,7 @@ public final class VoicemailImpl implements Voicemail {
|
||||
public VoicemailImpl build() {
|
||||
return new VoicemailImpl(mBuilderTimestamp, mBuilderNumber, mBuilderId,
|
||||
mBuilderDuration,
|
||||
mBuilderSourcePackage, mBuilderSourceData, mBuilderUri, mBuilderMailbox,
|
||||
mBuilderSourcePackage, mBuilderSourceData, mBuilderUri,
|
||||
mBuilderIsRead,
|
||||
mBuilderHasContent);
|
||||
}
|
||||
@@ -237,16 +228,6 @@ public final class VoicemailImpl implements Voicemail {
|
||||
return mUri != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mailbox getMailbox() {
|
||||
return mMailbox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMailbox() {
|
||||
return mMailbox != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRead() {
|
||||
return hasRead() ? mIsRead : false;
|
||||
@@ -266,7 +247,7 @@ public final class VoicemailImpl implements Voicemail {
|
||||
public String toString() {
|
||||
return "VoicemailImpl [mTimestamp=" + mTimestamp + ", mNumber=" + mNumber + ", mId=" + mId
|
||||
+ ", mDuration=" + mDuration + ", mSource=" + mSource + ", mProviderData="
|
||||
+ mProviderData + ", mUri=" + mUri + ", mMailbox=" + mMailbox + ", mIsRead="
|
||||
+ mIsRead + ", mHasContent=" + mHasContent + "]";
|
||||
+ mProviderData + ", mUri=" + mUri + ", mIsRead=" + mIsRead + ", mHasContent="
|
||||
+ mHasContent + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import com.example.android.provider.VoicemailContract;
|
||||
import android.provider.VoicemailContract;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import com.example.android.provider.VoicemailContract.Voicemails;
|
||||
import com.example.android.voicemail.common.logging.Logger;
|
||||
import com.example.android.voicemail.common.utils.CloseUtils;
|
||||
import com.example.android.voicemail.common.utils.DbQueryUtils;
|
||||
@@ -27,6 +26,8 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.VoicemailContract;
|
||||
import android.provider.VoicemailContract.Voicemails;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -48,8 +49,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
Voicemails.DATE,
|
||||
Voicemails.SOURCE_PACKAGE,
|
||||
Voicemails.SOURCE_DATA,
|
||||
Voicemails.NEW,
|
||||
Voicemails.STATE
|
||||
Voicemails.IS_READ
|
||||
};
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
@@ -98,6 +98,10 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
check(voicemail.hasNumber(), "Inserted voicemails must have a number", voicemail);
|
||||
logger.d(String.format("Inserting new voicemail: %s", voicemail));
|
||||
ContentValues contentValues = getContentValues(voicemail);
|
||||
if (!voicemail.hasRead()) {
|
||||
// If is_read is not set then set it to false as default value.
|
||||
contentValues.put(Voicemails.IS_READ, 0);
|
||||
}
|
||||
return mContentResolver.insert(mBaseUri, contentValues);
|
||||
}
|
||||
|
||||
@@ -250,9 +254,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
.setUri(buildUriWithSourcePackage(id, sourcePackage))
|
||||
.setHasContent(cursor.getInt(
|
||||
cursor.getColumnIndexOrThrow(Voicemails.HAS_CONTENT)) == 1)
|
||||
.setIsRead(cursor.getInt(cursor.getColumnIndexOrThrow(Voicemails.NEW)) == 1)
|
||||
.setMailbox(mapValueToMailBoxEnum(cursor.getInt(
|
||||
cursor.getColumnIndexOrThrow(Voicemails.STATE))))
|
||||
.setIsRead(cursor.getInt(cursor.getColumnIndexOrThrow(Voicemails.IS_READ)) == 1)
|
||||
.build();
|
||||
return voicemail;
|
||||
}
|
||||
@@ -261,15 +263,6 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
return ContentUris.withAppendedId(Voicemails.buildSourceUri(sourcePackage), id);
|
||||
}
|
||||
|
||||
private Voicemail.Mailbox mapValueToMailBoxEnum(int value) {
|
||||
for (Voicemail.Mailbox mailbox : Voicemail.Mailbox.values()) {
|
||||
if (mailbox.getValue() == value) {
|
||||
return mailbox;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Value: " + value + " not valid for Voicemail.Mailbox.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps structured {@link Voicemail} to {@link ContentValues} understood by content provider.
|
||||
*/
|
||||
@@ -291,10 +284,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
contentValues.put(Voicemails.SOURCE_DATA, voicemail.getSourceData());
|
||||
}
|
||||
if (voicemail.hasRead()) {
|
||||
contentValues.put(Voicemails.NEW, voicemail.isRead() ? 1 : 0);
|
||||
}
|
||||
if (voicemail.hasMailbox()) {
|
||||
contentValues.put(Voicemails.STATE, voicemail.getMailbox().getValue());
|
||||
contentValues.put(Voicemails.IS_READ, voicemail.isRead() ? 1 : 0);
|
||||
}
|
||||
return contentValues;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user