Home | History | Annotate | Download | only in content
      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 
     19 import android.net.Uri;
     20 import android.os.Parcelable;
     21 import android.os.Parcel;
     22 
     23 /**
     24  * Contains the result of the application of a {@link ContentProviderOperation}. It is guaranteed
     25  * to have exactly one of {@link #uri} or {@link #count} set.
     26  */
     27 public class ContentProviderResult implements Parcelable {
     28     public final Uri uri;
     29     public final Integer count;
     30 
     31     public ContentProviderResult(Uri uri) {
     32         if (uri == null) throw new IllegalArgumentException("uri must not be null");
     33         this.uri = uri;
     34         this.count = null;
     35     }
     36 
     37     public ContentProviderResult(int count) {
     38         this.count = count;
     39         this.uri = null;
     40     }
     41 
     42     public ContentProviderResult(Parcel source) {
     43         int type = source.readInt();
     44         if (type == 1) {
     45             count = source.readInt();
     46             uri = null;
     47         } else {
     48             count = null;
     49             uri = Uri.CREATOR.createFromParcel(source);
     50         }
     51     }
     52 
     53     public void writeToParcel(Parcel dest, int flags) {
     54         if (uri == null) {
     55             dest.writeInt(1);
     56             dest.writeInt(count);
     57         } else {
     58             dest.writeInt(2);
     59             uri.writeToParcel(dest, 0);
     60         }
     61     }
     62 
     63     public int describeContents() {
     64         return 0;
     65     }
     66 
     67     public static final Creator<ContentProviderResult> CREATOR =
     68             new Creator<ContentProviderResult>() {
     69         public ContentProviderResult createFromParcel(Parcel source) {
     70             return new ContentProviderResult(source);
     71         }
     72 
     73         public ContentProviderResult[] newArray(int size) {
     74             return new ContentProviderResult[size];
     75         }
     76     };
     77 
     78     public String toString() {
     79         if (uri != null) {
     80             return "ContentProviderResult(uri=" + uri.toString() + ")";
     81         }
     82         return "ContentProviderResult(count=" + count + ")";
     83     }
     84 }