• Home
  • 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.annotation.Nullable;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * This class represents spec for performing screen magnification.
25  *
26  * @hide
27  */
28 public class MagnificationSpec implements Parcelable {
29 
30     /** The magnification scaling factor. */
31     public float scale = 1.0f;
32 
33     /**
34      * The X coordinate, in unscaled screen-relative pixels, around which
35      * magnification is focused.
36      */
37     public float offsetX;
38 
39     /**
40      * The Y coordinate, in unscaled screen-relative pixels, around which
41      * magnification is focused.
42      */
43     public float offsetY;
44 
initialize(float scale, float offsetX, float offsetY)45     public void initialize(float scale, float offsetX, float offsetY) {
46         if (scale < 1) {
47             throw new IllegalArgumentException("Scale must be greater than or equal to one!");
48         }
49         this.scale = scale;
50         this.offsetX = offsetX;
51         this.offsetY = offsetY;
52     }
53 
isNop()54     public boolean isNop() {
55         return scale == 1.0f && offsetX == 0 && offsetY == 0;
56     }
57 
clear()58     public void clear() {
59        scale = 1.0f;
60        offsetX = 0.0f;
61        offsetY = 0.0f;
62     }
63 
setTo(MagnificationSpec other)64     public void setTo(MagnificationSpec other) {
65         scale = other.scale;
66         offsetX = other.offsetX;
67         offsetY = other.offsetY;
68     }
69 
70     @Override
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
75     @Override
writeToParcel(Parcel parcel, int flags)76     public void writeToParcel(Parcel parcel, int flags) {
77         parcel.writeFloat(scale);
78         parcel.writeFloat(offsetX);
79         parcel.writeFloat(offsetY);
80     }
81 
82     @Override
equals(@ullable Object other)83     public boolean equals(@Nullable Object other) {
84         if (this == other) {
85             return true;
86         }
87 
88         if (other == null || getClass() != other.getClass()) {
89             return false;
90         }
91 
92         final MagnificationSpec s = (MagnificationSpec) other;
93         return scale == s.scale && offsetX == s.offsetX && offsetY == s.offsetY;
94     }
95 
96     @Override
hashCode()97     public int hashCode() {
98         int result = (scale != +0.0f ? Float.floatToIntBits(scale) : 0);
99         result = 31 * result + (offsetX != +0.0f ? Float.floatToIntBits(offsetX) : 0);
100         result = 31 * result + (offsetY != +0.0f ? Float.floatToIntBits(offsetY) : 0);
101         return result;
102     }
103 
104     @Override
toString()105     public String toString() {
106         StringBuilder builder = new StringBuilder();
107         builder.append("<scale:");
108         builder.append(Float.toString(scale));
109         builder.append(",offsetX:");
110         builder.append(Float.toString(offsetX));
111         builder.append(",offsetY:");
112         builder.append(Float.toString(offsetY));
113         builder.append(">");
114         return builder.toString();
115     }
116 
initFromParcel(Parcel parcel)117     private void initFromParcel(Parcel parcel) {
118         scale = parcel.readFloat();
119         offsetX = parcel.readFloat();
120         offsetY = parcel.readFloat();
121     }
122 
123     public static final @android.annotation.NonNull Creator<MagnificationSpec> CREATOR = new Creator<MagnificationSpec>() {
124         @Override
125         public MagnificationSpec[] newArray(int size) {
126             return new MagnificationSpec[size];
127         }
128 
129         @Override
130         public MagnificationSpec createFromParcel(Parcel parcel) {
131             MagnificationSpec spec = new MagnificationSpec();
132             spec.initFromParcel(parcel);
133             return spec;
134         }
135     };
136 }
137