• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  * Copyright (C) 2016 Mopria Alliance, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.bips.jni;
19 
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * Describes a width and height in arbitrary units.
25  */
26 public class SizeD implements Parcelable {
27     private final double mWidth;
28     private final double mHeight;
29 
SizeD(double width, double height)30     public SizeD(double width, double height) {
31         validate("width", width);
32         validate("height", height);
33         mWidth = width;
34         mHeight = height;
35     }
36 
37     /** Ensure the named value is finite and non-negative, or throw */
validate(String name, double value)38     private void validate(String name, double value) {
39         if (value < 0 || !Double.isFinite(value)) {
40             throw new IllegalArgumentException("invalid " + name + ": " + value);
41         }
42     }
43 
SizeD(Parcel in)44     public SizeD(Parcel in) {
45         this(in.readDouble(), in.readDouble());
46     }
47 
getWidth()48     public double getWidth() {
49         return mWidth;
50     }
51 
getHeight()52     public double getHeight() {
53         return mHeight;
54     }
55 
56     @Override
describeContents()57     public int describeContents() {
58         return 0;
59     }
60 
61     @Override
writeToParcel(Parcel out, int i)62     public void writeToParcel(Parcel out, int i) {
63         out.writeDouble(mWidth);
64         out.writeDouble(mHeight);
65     }
66 
67     public static final Parcelable.Creator<SizeD> CREATOR = new Parcelable.Creator<SizeD>() {
68         public SizeD createFromParcel(Parcel in) {
69             return new SizeD(in);
70         }
71 
72         public SizeD[] newArray(int size) {
73             return new SizeD[size];
74         }
75     };
76 }
77