• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.view;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.util.Pools.SynchronizedPool;
22 
23 /**
24  * This class represents spec for performing screen magnification.
25  *
26  * @hide
27  */
28 public class MagnificationSpec implements Parcelable {
29     private static final int MAX_POOL_SIZE = 20;
30     private static final SynchronizedPool<MagnificationSpec> sPool =
31             new SynchronizedPool<MagnificationSpec>(MAX_POOL_SIZE);
32 
33     public float scale = 1.0f;
34     public float offsetX;
35     public float offsetY;
36 
MagnificationSpec()37     private MagnificationSpec() {
38         /* do nothing - reducing visibility */
39     }
40 
initialize(float scale, float offsetX, float offsetY)41     public void initialize(float scale, float offsetX, float offsetY) {
42         if (scale < 1) {
43             throw new IllegalArgumentException("Scale must be greater than or equal to one!");
44         }
45         this.scale = scale;
46         this.offsetX = offsetX;
47         this.offsetY = offsetY;
48     }
49 
isNop()50     public boolean isNop() {
51         return scale == 1.0f && offsetX == 0 && offsetY == 0;
52     }
53 
obtain(MagnificationSpec other)54     public static MagnificationSpec obtain(MagnificationSpec other) {
55         MagnificationSpec info = obtain();
56         info.scale = other.scale;
57         info.offsetX = other.offsetX;
58         info.offsetY = other.offsetY;
59         return info;
60     }
61 
obtain()62     public static MagnificationSpec obtain() {
63         MagnificationSpec spec = sPool.acquire();
64         return (spec != null) ? spec : new MagnificationSpec();
65     }
66 
recycle()67     public void recycle() {
68         clear();
69         sPool.release(this);
70     }
71 
clear()72     public void clear() {
73        scale = 1.0f;
74        offsetX = 0.0f;
75        offsetY = 0.0f;
76     }
77 
78     @Override
describeContents()79     public int describeContents() {
80         return 0;
81     }
82 
83     @Override
writeToParcel(Parcel parcel, int flags)84     public void writeToParcel(Parcel parcel, int flags) {
85         parcel.writeFloat(scale);
86         parcel.writeFloat(offsetX);
87         parcel.writeFloat(offsetY);
88         recycle();
89     }
90 
91     @Override
toString()92     public String toString() {
93         StringBuilder builder = new StringBuilder();
94         builder.append("<scale:");
95         builder.append(scale);
96         builder.append(",offsetX:");
97         builder.append(offsetX);
98         builder.append(",offsetY:");
99         builder.append(offsetY);
100         builder.append(">");
101         return builder.toString();
102     }
103 
initFromParcel(Parcel parcel)104     private void initFromParcel(Parcel parcel) {
105         scale = parcel.readFloat();
106         offsetX = parcel.readFloat();
107         offsetY = parcel.readFloat();
108     }
109 
110     public static final Creator<MagnificationSpec> CREATOR = new Creator<MagnificationSpec>() {
111         @Override
112         public MagnificationSpec[] newArray(int size) {
113             return new MagnificationSpec[size];
114         }
115 
116         @Override
117         public MagnificationSpec createFromParcel(Parcel parcel) {
118             MagnificationSpec spec = MagnificationSpec.obtain();
119             spec.initFromParcel(parcel);
120             return spec;
121         }
122     };
123 }
124