Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2007-2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.android.internal.view;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 import android.view.InputChannel;
     22 
     23 /**
     24  * Bundle of information returned by input method manager about a successful
     25  * binding to an input method.
     26  */
     27 public final class InputBindResult implements Parcelable {
     28     static final String TAG = "InputBindResult";
     29 
     30     /**
     31      * The input method service.
     32      */
     33     public final IInputMethodSession method;
     34 
     35     /**
     36      * The input channel used to send input events to this IME.
     37      */
     38     public final InputChannel channel;
     39 
     40     /**
     41      * The ID for this input method, as found in InputMethodInfo; null if
     42      * no input method will be bound.
     43      */
     44     public final String id;
     45 
     46     /**
     47      * Sequence number of this binding.
     48      */
     49     public final int sequence;
     50 
     51     public InputBindResult(IInputMethodSession _method, InputChannel _channel,
     52             String _id, int _sequence) {
     53         method = _method;
     54         channel = _channel;
     55         id = _id;
     56         sequence = _sequence;
     57     }
     58 
     59     InputBindResult(Parcel source) {
     60         method = IInputMethodSession.Stub.asInterface(source.readStrongBinder());
     61         if (source.readInt() != 0) {
     62             channel = InputChannel.CREATOR.createFromParcel(source);
     63         } else {
     64             channel = null;
     65         }
     66         id = source.readString();
     67         sequence = source.readInt();
     68     }
     69 
     70     @Override
     71     public String toString() {
     72         return "InputBindResult{" + method + " " + id
     73                 + " #" + sequence + "}";
     74     }
     75 
     76     /**
     77      * Used to package this object into a {@link Parcel}.
     78      *
     79      * @param dest The {@link Parcel} to be written.
     80      * @param flags The flags used for parceling.
     81      */
     82     @Override
     83     public void writeToParcel(Parcel dest, int flags) {
     84         dest.writeStrongInterface(method);
     85         if (channel != null) {
     86             dest.writeInt(1);
     87             channel.writeToParcel(dest, flags);
     88         } else {
     89             dest.writeInt(0);
     90         }
     91         dest.writeString(id);
     92         dest.writeInt(sequence);
     93     }
     94 
     95     /**
     96      * Used to make this class parcelable.
     97      */
     98     public static final Parcelable.Creator<InputBindResult> CREATOR =
     99             new Parcelable.Creator<InputBindResult>() {
    100         @Override
    101         public InputBindResult createFromParcel(Parcel source) {
    102             return new InputBindResult(source);
    103         }
    104 
    105         @Override
    106         public InputBindResult[] newArray(int size) {
    107             return new InputBindResult[size];
    108         }
    109     };
    110 
    111     @Override
    112     public int describeContents() {
    113         return channel != null ? channel.describeContents() : 0;
    114     }
    115 }
    116