Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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.app.servertransaction; |
| 18 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 19 | import android.app.ClientTransactionHandler; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
| 21 | import android.os.IBinder; |
| 22 | import android.os.Parcel; |
| 23 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 24 | import java.util.Objects; |
| 25 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Multi-window mode change message. |
| 28 | * @hide |
| 29 | */ |
| 30 | // TODO(lifecycler): Remove the use of this and just use the configuration change message to |
| 31 | // communicate multi-window mode change with WindowConfiguration. |
| 32 | public class MultiWindowModeChangeItem extends ClientTransactionItem { |
| 33 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 34 | private boolean mIsInMultiWindowMode; |
| 35 | private Configuration mOverrideConfig; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 36 | |
| 37 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 38 | public void execute(ClientTransactionHandler client, IBinder token, |
| 39 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 40 | client.handleMultiWindowModeChanged(token, mIsInMultiWindowMode, mOverrideConfig); |
| 41 | } |
| 42 | |
| 43 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 44 | // ObjectPoolItem implementation |
| 45 | |
| 46 | private MultiWindowModeChangeItem() {} |
| 47 | |
| 48 | /** Obtain an instance initialized with provided params. */ |
| 49 | public static MultiWindowModeChangeItem obtain(boolean isInMultiWindowMode, |
| 50 | Configuration overrideConfig) { |
| 51 | MultiWindowModeChangeItem instance = ObjectPool.obtain(MultiWindowModeChangeItem.class); |
| 52 | if (instance == null) { |
| 53 | instance = new MultiWindowModeChangeItem(); |
| 54 | } |
| 55 | instance.mIsInMultiWindowMode = isInMultiWindowMode; |
| 56 | instance.mOverrideConfig = overrideConfig; |
| 57 | |
| 58 | return instance; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void recycle() { |
| 63 | mIsInMultiWindowMode = false; |
| 64 | mOverrideConfig = null; |
| 65 | ObjectPool.recycle(this); |
| 66 | } |
| 67 | |
| 68 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 69 | // Parcelable implementation |
| 70 | |
| 71 | /** Write to Parcel. */ |
| 72 | @Override |
| 73 | public void writeToParcel(Parcel dest, int flags) { |
| 74 | dest.writeBoolean(mIsInMultiWindowMode); |
| 75 | dest.writeTypedObject(mOverrideConfig, flags); |
| 76 | } |
| 77 | |
| 78 | /** Read from Parcel. */ |
| 79 | private MultiWindowModeChangeItem(Parcel in) { |
| 80 | mIsInMultiWindowMode = in.readBoolean(); |
| 81 | mOverrideConfig = in.readTypedObject(Configuration.CREATOR); |
| 82 | } |
| 83 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 84 | public static final @android.annotation.NonNull Creator<MultiWindowModeChangeItem> CREATOR = |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 85 | new Creator<MultiWindowModeChangeItem>() { |
| 86 | public MultiWindowModeChangeItem createFromParcel(Parcel in) { |
| 87 | return new MultiWindowModeChangeItem(in); |
| 88 | } |
| 89 | |
| 90 | public MultiWindowModeChangeItem[] newArray(int size) { |
| 91 | return new MultiWindowModeChangeItem[size]; |
| 92 | } |
| 93 | }; |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 94 | |
| 95 | @Override |
| 96 | public boolean equals(Object o) { |
| 97 | if (this == o) { |
| 98 | return true; |
| 99 | } |
| 100 | if (o == null || getClass() != o.getClass()) { |
| 101 | return false; |
| 102 | } |
| 103 | final MultiWindowModeChangeItem other = (MultiWindowModeChangeItem) o; |
| 104 | return mIsInMultiWindowMode == other.mIsInMultiWindowMode |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 105 | && Objects.equals(mOverrideConfig, other.mOverrideConfig); |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public int hashCode() { |
| 110 | int result = 17; |
| 111 | result = 31 * result + (mIsInMultiWindowMode ? 1 : 0); |
| 112 | result = 31 * result + mOverrideConfig.hashCode(); |
| 113 | return result; |
| 114 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 115 | |
| 116 | @Override |
| 117 | public String toString() { |
| 118 | return "MultiWindowModeChangeItem{isInMultiWindowMode=" + mIsInMultiWindowMode |
| 119 | + ",overrideConfig=" + mOverrideConfig + "}"; |
| 120 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 121 | } |