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 /** 52 * Sequence number of user action notification. 53 */ 54 public final int userActionNotificationSequenceNumber; 55 InputBindResult(IInputMethodSession _method, InputChannel _channel, String _id, int _sequence, int _userActionNotificationSequenceNumber)56 public InputBindResult(IInputMethodSession _method, InputChannel _channel, 57 String _id, int _sequence, int _userActionNotificationSequenceNumber) { 58 method = _method; 59 channel = _channel; 60 id = _id; 61 sequence = _sequence; 62 userActionNotificationSequenceNumber = _userActionNotificationSequenceNumber; 63 } 64 InputBindResult(Parcel source)65 InputBindResult(Parcel source) { 66 method = IInputMethodSession.Stub.asInterface(source.readStrongBinder()); 67 if (source.readInt() != 0) { 68 channel = InputChannel.CREATOR.createFromParcel(source); 69 } else { 70 channel = null; 71 } 72 id = source.readString(); 73 sequence = source.readInt(); 74 userActionNotificationSequenceNumber = source.readInt(); 75 } 76 77 @Override toString()78 public String toString() { 79 return "InputBindResult{" + method + " " + id 80 + " sequence:" + sequence 81 + " userActionNotificationSequenceNumber:" + userActionNotificationSequenceNumber 82 + "}"; 83 } 84 85 /** 86 * Used to package this object into a {@link Parcel}. 87 * 88 * @param dest The {@link Parcel} to be written. 89 * @param flags The flags used for parceling. 90 */ 91 @Override writeToParcel(Parcel dest, int flags)92 public void writeToParcel(Parcel dest, int flags) { 93 dest.writeStrongInterface(method); 94 if (channel != null) { 95 dest.writeInt(1); 96 channel.writeToParcel(dest, flags); 97 } else { 98 dest.writeInt(0); 99 } 100 dest.writeString(id); 101 dest.writeInt(sequence); 102 dest.writeInt(userActionNotificationSequenceNumber); 103 } 104 105 /** 106 * Used to make this class parcelable. 107 */ 108 public static final Parcelable.Creator<InputBindResult> CREATOR = 109 new Parcelable.Creator<InputBindResult>() { 110 @Override 111 public InputBindResult createFromParcel(Parcel source) { 112 return new InputBindResult(source); 113 } 114 115 @Override 116 public InputBindResult[] newArray(int size) { 117 return new InputBindResult[size]; 118 } 119 }; 120 121 @Override describeContents()122 public int describeContents() { 123 return channel != null ? channel.describeContents() : 0; 124 } 125 } 126