Fred Quintana | ce31b23 | 2009-05-04 16:01:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.content; |
| 18 | |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 19 | import android.content.ContentProvider; |
Fred Quintana | ce31b23 | 2009-05-04 16:01:15 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 21 | import android.os.Parcelable; |
| 22 | import android.os.Parcel; |
Fred Quintana | ce31b23 | 2009-05-04 16:01:15 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Contains the result of the application of a {@link ContentProviderOperation}. It is guaranteed |
| 26 | * to have exactly one of {@link #uri} or {@link #count} set. |
| 27 | */ |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 28 | public class ContentProviderResult implements Parcelable { |
Fred Quintana | ce31b23 | 2009-05-04 16:01:15 -0700 | [diff] [blame] | 29 | public final Uri uri; |
| 30 | public final Integer count; |
| 31 | |
| 32 | public ContentProviderResult(Uri uri) { |
| 33 | if (uri == null) throw new IllegalArgumentException("uri must not be null"); |
| 34 | this.uri = uri; |
| 35 | this.count = null; |
| 36 | } |
| 37 | |
| 38 | public ContentProviderResult(int count) { |
| 39 | this.count = count; |
| 40 | this.uri = null; |
| 41 | } |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 42 | |
| 43 | public ContentProviderResult(Parcel source) { |
| 44 | int type = source.readInt(); |
| 45 | if (type == 1) { |
| 46 | count = source.readInt(); |
| 47 | uri = null; |
| 48 | } else { |
| 49 | count = null; |
| 50 | uri = Uri.CREATOR.createFromParcel(source); |
| 51 | } |
| 52 | } |
| 53 | |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 54 | /** @hide */ |
| 55 | public ContentProviderResult(ContentProviderResult cpr, int userId) { |
| 56 | uri = ContentProvider.maybeAddUserId(cpr.uri, userId); |
| 57 | count = cpr.count; |
| 58 | } |
| 59 | |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 60 | public void writeToParcel(Parcel dest, int flags) { |
| 61 | if (uri == null) { |
| 62 | dest.writeInt(1); |
| 63 | dest.writeInt(count); |
| 64 | } else { |
| 65 | dest.writeInt(2); |
| 66 | uri.writeToParcel(dest, 0); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | public int describeContents() { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | public static final Creator<ContentProviderResult> CREATOR = |
| 75 | new Creator<ContentProviderResult>() { |
| 76 | public ContentProviderResult createFromParcel(Parcel source) { |
| 77 | return new ContentProviderResult(source); |
| 78 | } |
| 79 | |
| 80 | public ContentProviderResult[] newArray(int size) { |
| 81 | return new ContentProviderResult[size]; |
| 82 | } |
| 83 | }; |
Fred Quintana | 03d9490 | 2009-05-22 14:23:31 -0700 | [diff] [blame] | 84 | |
| 85 | public String toString() { |
| 86 | if (uri != null) { |
| 87 | return "ContentProviderResult(uri=" + uri.toString() + ")"; |
| 88 | } |
| 89 | return "ContentProviderResult(count=" + count + ")"; |
| 90 | } |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 91 | } |