Merge "VoicemaiProviderDemoApp changed to use api from sdk."
This commit is contained in:
committed by
Android (Google) Code Review
commit
a583cd15f7
@@ -26,7 +26,7 @@
|
|||||||
<uses-sdk android:minSdkVersion="13"
|
<uses-sdk android:minSdkVersion="13"
|
||||||
android:targetSdkVersion="13" />
|
android:targetSdkVersion="13" />
|
||||||
|
|
||||||
<uses-permission android:name="com.android.voicemail.permission.READ_WRITE_OWN_VOICEMAIL" />
|
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||||
|
|||||||
@@ -1,271 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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.example.android.provider;
|
|
||||||
|
|
||||||
// This is a COPY of the voicemail provider contract file checked in at
|
|
||||||
// framework/base/core/java/android/provider. The API is currently hidden so
|
|
||||||
// it is not available through the SDK and hence is not available to the sample
|
|
||||||
// code.
|
|
||||||
// TODO: get rid of this copy once the voicemail provider API is opened ups.
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.provider.BaseColumns;
|
|
||||||
import android.provider.CallLog.Calls;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The contract between the voicemail provider and applications. Contains
|
|
||||||
* definitions for the supported URIs and columns.
|
|
||||||
*
|
|
||||||
* <P>Voicemails are inserted by what is called as a "voicemail source"
|
|
||||||
* application, which is responsible for syncing voicemail data between a remote
|
|
||||||
* server and the local voicemail content provider. "voicemail source"
|
|
||||||
* application should use the source specific {@link #CONTENT_URI_SOURCE} URI
|
|
||||||
* to insert and retrieve voicemails.
|
|
||||||
*
|
|
||||||
* <P>In addition to the {@link ContentObserver} notifications the voicemail
|
|
||||||
* provider also generates broadcast intents to notify change for applications
|
|
||||||
* that are not active and therefore cannot listen to ContentObserver
|
|
||||||
* notifications. Broadcast intents with following actions are generated:
|
|
||||||
* <ul>
|
|
||||||
* <li> {@link #ACTION_NEW_VOICEMAIL} is generated for each new voicemail
|
|
||||||
* inserted.
|
|
||||||
* </li>
|
|
||||||
* <li> {@link Intent#ACTION_PROVIDER_CHANGED} is generated for any change
|
|
||||||
* made into the database, including new voicemail.
|
|
||||||
* </li>
|
|
||||||
* </ul>
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// TODO: unhide when the API is approved by android-api-council
|
|
||||||
public class VoicemailContract {
|
|
||||||
/** Not instantiable. */
|
|
||||||
private VoicemailContract() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The authority used by the voicemail provider. */
|
|
||||||
public static final String AUTHORITY = "com.android.voicemail";
|
|
||||||
/**
|
|
||||||
* URI to insert/retrieve all voicemails.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public static final Uri CONTENT_URI =
|
|
||||||
Uri.parse("content://" + AUTHORITY + "/voicemail");
|
|
||||||
/**
|
|
||||||
* URI to insert/retrieve voicemails by a given voicemail source.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public static final Uri CONTENT_URI_SOURCE =
|
|
||||||
Uri.parse("content://" + AUTHORITY + "/voicemail/source/");
|
|
||||||
/**
|
|
||||||
* Parameter key used in the URI to specify the voicemail source package name.
|
|
||||||
* <p> This field must be set in all requests that originate from a voicemail source.
|
|
||||||
*/
|
|
||||||
public static final String PARAM_KEY_SOURCE_PACKAGE = "source_package";
|
|
||||||
|
|
||||||
// TODO: Move ACTION_NEW_VOICEMAIL to the Intent class.
|
|
||||||
/** Broadcast intent when a new voicemail record is inserted. */
|
|
||||||
public static final String ACTION_NEW_VOICEMAIL = "android.intent.action.NEW_VOICEMAIL";
|
|
||||||
/**
|
|
||||||
* Extra included in {@value Intent#ACTION_PROVIDER_CHANGED} and
|
|
||||||
* {@value #ACTION_NEW_VOICEMAIL} broadcast intents to indicate if the receiving
|
|
||||||
* package made this change.
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_SELF_CHANGE = "com.android.voicemail.extra.SELF_CHANGE";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The mime type for a collection of voicemails.
|
|
||||||
* @deprecated */
|
|
||||||
public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemails";
|
|
||||||
|
|
||||||
/** Defines fields exposed through the /voicemail path of this content provider. */
|
|
||||||
public static final class Voicemails implements BaseColumns {
|
|
||||||
/** Not instantiable. */
|
|
||||||
private Voicemails() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** URI to insert/retrieve voicemails by a given voicemail source. */
|
|
||||||
public static final Uri CONTENT_URI =
|
|
||||||
Uri.parse("content://" + AUTHORITY + "/voicemail");
|
|
||||||
/** URI to insert/retrieve voicemails by a given voicemail source. */
|
|
||||||
public static final Uri CONTENT_URI_SOURCE =
|
|
||||||
Uri.parse("content://" + AUTHORITY + "/voicemail/source/");
|
|
||||||
|
|
||||||
/** The mime type for a collection of voicemails. */
|
|
||||||
public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemails";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phone number of the voicemail sender.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
*/
|
|
||||||
public static final String NUMBER = Calls.NUMBER;
|
|
||||||
/**
|
|
||||||
* The date the voicemail was sent, in milliseconds since the epoch
|
|
||||||
* <P>Type: INTEGER (long)</P>
|
|
||||||
*/
|
|
||||||
public static final String DATE = Calls.DATE;
|
|
||||||
/**
|
|
||||||
* The duration of the voicemail in seconds.
|
|
||||||
* <P>Type: INTEGER (long)</P>
|
|
||||||
*/
|
|
||||||
public static final String DURATION = Calls.DURATION;
|
|
||||||
/**
|
|
||||||
* Whether this is a new voicemail (i.e. has not been heard).
|
|
||||||
* <P>Type: INTEGER (boolean)</P>
|
|
||||||
*/
|
|
||||||
public static final String NEW = Calls.NEW;
|
|
||||||
/**
|
|
||||||
* The mail box state of the voicemail.
|
|
||||||
* <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
|
|
||||||
* {@link #STATE_UNDELETED}.
|
|
||||||
* <P>Type: INTEGER</P>
|
|
||||||
*/
|
|
||||||
public static final String STATE = "state";
|
|
||||||
/** Value of {@link #STATE} when the voicemail is in inbox. */
|
|
||||||
public static int STATE_INBOX = 0;
|
|
||||||
/** Value of {@link #STATE} when the voicemail has been marked as deleted. */
|
|
||||||
public static int STATE_DELETED = 1;
|
|
||||||
/** Value of {@link #STATE} when the voicemail has marked as undeleted. */
|
|
||||||
public static int STATE_UNDELETED = 2;
|
|
||||||
/**
|
|
||||||
* Package name of the source application that inserted the voicemail.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
*/
|
|
||||||
public static final String SOURCE_PACKAGE = "source_package";
|
|
||||||
/**
|
|
||||||
* Application-specific data available to the source application that
|
|
||||||
* inserted the voicemail. This is typically used to store the source
|
|
||||||
* specific message id to identify this voicemail on the remote
|
|
||||||
* voicemail server.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
* <P> Note that this is NOT the voicemail media content data.
|
|
||||||
*/
|
|
||||||
public static final String SOURCE_DATA = "source_data";
|
|
||||||
/**
|
|
||||||
* Whether the media content for this voicemail is available for
|
|
||||||
* consumption.
|
|
||||||
* <P>Type: INTEGER (boolean)</P>
|
|
||||||
*/
|
|
||||||
public static final String HAS_CONTENT = "has_content";
|
|
||||||
/**
|
|
||||||
* MIME type of the media content for the voicemail.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
*/
|
|
||||||
public static final String MIME_TYPE = "mime_type";
|
|
||||||
/**
|
|
||||||
* Path to the media content file. Internal only field.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final String _DATA = "_data";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience method to build voicemail URI specific to a source package by appending
|
|
||||||
* {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
|
|
||||||
*/
|
|
||||||
public static Uri buildSourceUri(String packageName) {
|
|
||||||
return Voicemails.CONTENT_URI.buildUpon()
|
|
||||||
.appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Defines fields exposed through the /status path of this content provider. */
|
|
||||||
public static final class Status implements BaseColumns {
|
|
||||||
/** URI to insert/retrieve status of voicemail source. */
|
|
||||||
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/status");
|
|
||||||
/** The mime type for a collection of voicemail source statuses. */
|
|
||||||
public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemail.source.status";
|
|
||||||
/** The mime type for a collection of voicemails. */
|
|
||||||
public static final String ITEM_TYPE = "vnd.android.cursor.item/voicemail.source.status";
|
|
||||||
|
|
||||||
/** Not instantiable. */
|
|
||||||
private Status() {
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* The package name of the voicemail source. There can only be a one entry per source.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
*/
|
|
||||||
public static final String SOURCE_PACKAGE = "source_package";
|
|
||||||
/**
|
|
||||||
* The URI to call to invoke source specific voicemail settings screen. On a user request
|
|
||||||
* to setup voicemail an intent with action VIEW with this URI will be fired by the system.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
*/
|
|
||||||
public static final String SETTINGS_URI = "settings_uri";
|
|
||||||
/**
|
|
||||||
* The URI to call when the user requests to directly access the voicemail from the remote
|
|
||||||
* server. In case of an IVR voicemail system this is typically set to the the voicemail
|
|
||||||
* number specified using a tel:/ URI.
|
|
||||||
* <P>Type: TEXT</P>
|
|
||||||
*/
|
|
||||||
public static final String VOICEMAIL_ACCESS_URI = "voicemail_access_uri";
|
|
||||||
/**
|
|
||||||
* The configuration state of the voicemail source.
|
|
||||||
* <P> Possible values:
|
|
||||||
* {@link #CONFIGURATION_STATE_OK},
|
|
||||||
* {@link #CONFIGURATION_STATE_NOT_CONFIGURED},
|
|
||||||
* {@link #CONFIGURATION_STATE_CAN_BE_CONFIGURED}
|
|
||||||
* <P>Type: INTEGER</P>
|
|
||||||
*/
|
|
||||||
public static final String CONFIGURATION_STATE = "configuration_state";
|
|
||||||
public static final int CONFIGURATION_STATE_OK = 0;
|
|
||||||
public static final int CONFIGURATION_STATE_NOT_CONFIGURED = 1;
|
|
||||||
/**
|
|
||||||
* This state must be used when the source has verified that the current user can be
|
|
||||||
* upgraded to visual voicemail and would like to show a set up invitation message.
|
|
||||||
*/
|
|
||||||
public static final int CONFIGURATION_STATE_CAN_BE_CONFIGURED = 2;
|
|
||||||
/**
|
|
||||||
* The data channel state of the voicemail source. This the channel through which the source
|
|
||||||
* pulls voicemail data from a remote server.
|
|
||||||
* <P> Possible values:
|
|
||||||
* {@link #DATA_CHANNEL_STATE_OK},
|
|
||||||
* {@link #DATA_CHANNEL_STATE_NO_CONNECTION}
|
|
||||||
* </P>
|
|
||||||
* <P>Type: INTEGER</P>
|
|
||||||
*/
|
|
||||||
public static final String DATA_CHANNEL_STATE = "data_channel_state";
|
|
||||||
public static final int DATA_CHANNEL_STATE_OK = 0;
|
|
||||||
public static final int DATA_CHANNEL_STATE_NO_CONNECTION = 1;
|
|
||||||
/**
|
|
||||||
* The notification channel state of the voicemail source. This is the channel through which
|
|
||||||
* the source gets notified of new voicemails on the remote server.
|
|
||||||
* <P> Possible values:
|
|
||||||
* {@link #NOTIFICATION_CHANNEL_STATE_OK},
|
|
||||||
* {@link #NOTIFICATION_CHANNEL_STATE_NO_CONNECTION},
|
|
||||||
* {@link #NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING}
|
|
||||||
* </P>
|
|
||||||
* <P>Type: INTEGER</P>
|
|
||||||
*/
|
|
||||||
public static final String NOTIFICATION_CHANNEL_STATE = "notification_channel_state";
|
|
||||||
public static final int NOTIFICATION_CHANNEL_STATE_OK = 0;
|
|
||||||
public static final int NOTIFICATION_CHANNEL_STATE_NO_CONNECTION = 1;
|
|
||||||
/**
|
|
||||||
* Use this state when the notification can only tell that there are pending messages on
|
|
||||||
* the server but no details of the sender/time etc are known.
|
|
||||||
*/
|
|
||||||
public static final int NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience method to build status URI specific to a source package by appending
|
|
||||||
* {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
|
|
||||||
*/
|
|
||||||
public static Uri buildSourceUri(String packageName) {
|
|
||||||
return Status.CONTENT_URI.buildUpon()
|
|
||||||
.appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,16 @@
|
|||||||
|
|
||||||
package com.example.android.voicemail;
|
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.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -28,16 +38,6 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -131,7 +131,6 @@ public class AddVoicemailActivity extends Activity {
|
|||||||
return VoicemailImpl.createForInsertion(time, sender)
|
return VoicemailImpl.createForInsertion(time, sender)
|
||||||
.setDuration(duration)
|
.setDuration(duration)
|
||||||
.setSourcePackage(sourcePackageName)
|
.setSourcePackage(sourcePackageName)
|
||||||
.setMailbox(Voicemail.Mailbox.INBOX)
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.voicemail.common.core;
|
package com.example.android.voicemail.common.core;
|
||||||
|
|
||||||
import com.example.android.provider.VoicemailContract;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,41 +24,6 @@ import android.net.Uri;
|
|||||||
* The presence of a field is indicated by a corresponding 'has' method.
|
* The presence of a field is indicated by a corresponding 'has' method.
|
||||||
*/
|
*/
|
||||||
public interface Voicemail {
|
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.
|
* The identifier of the voicemail in the content provider.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -116,11 +79,6 @@ public interface Voicemail {
|
|||||||
|
|
||||||
public boolean hasUri();
|
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.
|
* Tells us if the voicemail message has been marked as read.
|
||||||
* <p>
|
* <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.concatenateClausesWithOr;
|
||||||
import static com.example.android.voicemail.common.utils.DbQueryUtils.getEqualityClause;
|
import static com.example.android.voicemail.common.utils.DbQueryUtils.getEqualityClause;
|
||||||
|
|
||||||
import com.example.android.voicemail.common.core.Voicemail.Mailbox;
|
import android.provider.VoicemailContract.Voicemails;
|
||||||
import com.example.android.provider.VoicemailContract.Voicemails;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -31,8 +29,8 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Factory class to create {@link VoicemailFilter} objects for various filtering needs.
|
* Factory class to create {@link VoicemailFilter} objects for various filtering needs.
|
||||||
* <p>
|
* <p>
|
||||||
* Factory methods like {@link #createWithMailbox(Mailbox)}, {@link #createWithReadStatus(boolean)}
|
* Factory methods like {@link #createWithReadStatus(boolean)} and
|
||||||
* and {@link #createWithMatchingFields(Voicemail)} can be used to create a voicemail filter that
|
* {@link #createWithMatchingFields(Voicemail)} can be used to create a voicemail filter that
|
||||||
* matches the value of the specific field.
|
* matches the value of the specific field.
|
||||||
* <p>
|
* <p>
|
||||||
* It is possible to combine multiple filters with OR or AND operation using the methods
|
* 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.
|
* content provider database and is therefore less recommended.
|
||||||
*/
|
*/
|
||||||
public class VoicemailFilterFactory {
|
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
|
* 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
|
* 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));
|
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. */
|
/** Creates a voicemail filter with the specified read status. */
|
||||||
public static VoicemailFilter createWithReadStatus(boolean isRead) {
|
public static VoicemailFilter createWithReadStatus(boolean isRead) {
|
||||||
return createWithMatchingFields(
|
return createWithMatchingFields(
|
||||||
@@ -111,11 +96,7 @@ public class VoicemailFilterFactory {
|
|||||||
private static String getWhereClauseForMatchingFields(Voicemail fieldMatch) {
|
private static String getWhereClauseForMatchingFields(Voicemail fieldMatch) {
|
||||||
List<String> clauses = new ArrayList<String>();
|
List<String> clauses = new ArrayList<String>();
|
||||||
if (fieldMatch.hasRead()) {
|
if (fieldMatch.hasRead()) {
|
||||||
clauses.add(getEqualityClause(Voicemails.NEW, fieldMatch.isRead() ? "1" : "0"));
|
clauses.add(getEqualityClause(Voicemails.IS_READ, fieldMatch.isRead() ? "1" : "0"));
|
||||||
}
|
|
||||||
if (fieldMatch.hasMailbox()) {
|
|
||||||
clauses.add(getEqualityClause(Voicemails.STATE,
|
|
||||||
Integer.toString(fieldMatch.getMailbox().getValue())));
|
|
||||||
}
|
}
|
||||||
if (fieldMatch.hasNumber()) {
|
if (fieldMatch.hasNumber()) {
|
||||||
clauses.add(getEqualityClause(Voicemails.NUMBER, fieldMatch.getNumber()));
|
clauses.add(getEqualityClause(Voicemails.NUMBER, fieldMatch.getNumber()));
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
private final String mSource;
|
private final String mSource;
|
||||||
private final String mProviderData;
|
private final String mProviderData;
|
||||||
private final Uri mUri;
|
private final Uri mUri;
|
||||||
private final Voicemail.Mailbox mMailbox;
|
|
||||||
private final Boolean mIsRead;
|
private final Boolean mIsRead;
|
||||||
private final boolean mHasContent;
|
private final boolean mHasContent;
|
||||||
|
|
||||||
@@ -44,7 +43,6 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
String source,
|
String source,
|
||||||
String providerData,
|
String providerData,
|
||||||
Uri uri,
|
Uri uri,
|
||||||
Voicemail.Mailbox mailbox,
|
|
||||||
Boolean isRead,
|
Boolean isRead,
|
||||||
boolean hasContent) {
|
boolean hasContent) {
|
||||||
mId = id;
|
mId = id;
|
||||||
@@ -54,7 +52,6 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
mSource = source;
|
mSource = source;
|
||||||
mProviderData = providerData;
|
mProviderData = providerData;
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
mMailbox = mailbox;
|
|
||||||
mIsRead = isRead;
|
mIsRead = isRead;
|
||||||
mHasContent = hasContent;
|
mHasContent = hasContent;
|
||||||
}
|
}
|
||||||
@@ -100,7 +97,6 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
private String mBuilderSourcePackage;
|
private String mBuilderSourcePackage;
|
||||||
private String mBuilderSourceData;
|
private String mBuilderSourceData;
|
||||||
private Uri mBuilderUri;
|
private Uri mBuilderUri;
|
||||||
private Voicemail.Mailbox mBuilderMailbox;
|
|
||||||
private Boolean mBuilderIsRead;
|
private Boolean mBuilderIsRead;
|
||||||
private boolean mBuilderHasContent;
|
private boolean mBuilderHasContent;
|
||||||
|
|
||||||
@@ -143,11 +139,6 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setMailbox(Voicemail.Mailbox mailbox) {
|
|
||||||
mBuilderMailbox = mailbox;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setIsRead(boolean isRead) {
|
public Builder setIsRead(boolean isRead) {
|
||||||
mBuilderIsRead = isRead;
|
mBuilderIsRead = isRead;
|
||||||
return this;
|
return this;
|
||||||
@@ -161,7 +152,7 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
public VoicemailImpl build() {
|
public VoicemailImpl build() {
|
||||||
return new VoicemailImpl(mBuilderTimestamp, mBuilderNumber, mBuilderId,
|
return new VoicemailImpl(mBuilderTimestamp, mBuilderNumber, mBuilderId,
|
||||||
mBuilderDuration,
|
mBuilderDuration,
|
||||||
mBuilderSourcePackage, mBuilderSourceData, mBuilderUri, mBuilderMailbox,
|
mBuilderSourcePackage, mBuilderSourceData, mBuilderUri,
|
||||||
mBuilderIsRead,
|
mBuilderIsRead,
|
||||||
mBuilderHasContent);
|
mBuilderHasContent);
|
||||||
}
|
}
|
||||||
@@ -237,16 +228,6 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
return mUri != null;
|
return mUri != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mailbox getMailbox() {
|
|
||||||
return mMailbox;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasMailbox() {
|
|
||||||
return mMailbox != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRead() {
|
public boolean isRead() {
|
||||||
return hasRead() ? mIsRead : false;
|
return hasRead() ? mIsRead : false;
|
||||||
@@ -266,7 +247,7 @@ public final class VoicemailImpl implements Voicemail {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "VoicemailImpl [mTimestamp=" + mTimestamp + ", mNumber=" + mNumber + ", mId=" + mId
|
return "VoicemailImpl [mTimestamp=" + mTimestamp + ", mNumber=" + mNumber + ", mId=" + mId
|
||||||
+ ", mDuration=" + mDuration + ", mSource=" + mSource + ", mProviderData="
|
+ ", mDuration=" + mDuration + ", mSource=" + mSource + ", mProviderData="
|
||||||
+ mProviderData + ", mUri=" + mUri + ", mMailbox=" + mMailbox + ", mIsRead="
|
+ mProviderData + ", mUri=" + mUri + ", mIsRead=" + mIsRead + ", mHasContent="
|
||||||
+ mIsRead + ", mHasContent=" + mHasContent + "]";
|
+ mHasContent + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.example.android.voicemail.common.core;
|
package com.example.android.voicemail.common.core;
|
||||||
|
|
||||||
import com.example.android.provider.VoicemailContract;
|
import android.provider.VoicemailContract;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.voicemail.common.core;
|
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.logging.Logger;
|
||||||
import com.example.android.voicemail.common.utils.CloseUtils;
|
import com.example.android.voicemail.common.utils.CloseUtils;
|
||||||
import com.example.android.voicemail.common.utils.DbQueryUtils;
|
import com.example.android.voicemail.common.utils.DbQueryUtils;
|
||||||
@@ -27,6 +26,8 @@ import android.content.ContentValues;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.VoicemailContract;
|
||||||
|
import android.provider.VoicemailContract.Voicemails;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -48,8 +49,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
|||||||
Voicemails.DATE,
|
Voicemails.DATE,
|
||||||
Voicemails.SOURCE_PACKAGE,
|
Voicemails.SOURCE_PACKAGE,
|
||||||
Voicemails.SOURCE_DATA,
|
Voicemails.SOURCE_DATA,
|
||||||
Voicemails.NEW,
|
Voicemails.IS_READ
|
||||||
Voicemails.STATE
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
@@ -98,6 +98,10 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
|||||||
check(voicemail.hasNumber(), "Inserted voicemails must have a number", voicemail);
|
check(voicemail.hasNumber(), "Inserted voicemails must have a number", voicemail);
|
||||||
logger.d(String.format("Inserting new voicemail: %s", voicemail));
|
logger.d(String.format("Inserting new voicemail: %s", voicemail));
|
||||||
ContentValues contentValues = getContentValues(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);
|
return mContentResolver.insert(mBaseUri, contentValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,9 +254,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
|||||||
.setUri(buildUriWithSourcePackage(id, sourcePackage))
|
.setUri(buildUriWithSourcePackage(id, sourcePackage))
|
||||||
.setHasContent(cursor.getInt(
|
.setHasContent(cursor.getInt(
|
||||||
cursor.getColumnIndexOrThrow(Voicemails.HAS_CONTENT)) == 1)
|
cursor.getColumnIndexOrThrow(Voicemails.HAS_CONTENT)) == 1)
|
||||||
.setIsRead(cursor.getInt(cursor.getColumnIndexOrThrow(Voicemails.NEW)) == 1)
|
.setIsRead(cursor.getInt(cursor.getColumnIndexOrThrow(Voicemails.IS_READ)) == 1)
|
||||||
.setMailbox(mapValueToMailBoxEnum(cursor.getInt(
|
|
||||||
cursor.getColumnIndexOrThrow(Voicemails.STATE))))
|
|
||||||
.build();
|
.build();
|
||||||
return voicemail;
|
return voicemail;
|
||||||
}
|
}
|
||||||
@@ -261,15 +263,6 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
|||||||
return ContentUris.withAppendedId(Voicemails.buildSourceUri(sourcePackage), id);
|
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.
|
* 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());
|
contentValues.put(Voicemails.SOURCE_DATA, voicemail.getSourceData());
|
||||||
}
|
}
|
||||||
if (voicemail.hasRead()) {
|
if (voicemail.hasRead()) {
|
||||||
contentValues.put(Voicemails.NEW, voicemail.isRead() ? 1 : 0);
|
contentValues.put(Voicemails.IS_READ, voicemail.isRead() ? 1 : 0);
|
||||||
}
|
|
||||||
if (voicemail.hasMailbox()) {
|
|
||||||
contentValues.put(Voicemails.STATE, voicemail.getMailbox().getValue());
|
|
||||||
}
|
}
|
||||||
return contentValues;
|
return contentValues;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user