Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2011 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.content.res.CompatibilityInfo;
     20 import android.content.res.Configuration;
     21 
     22 import java.util.Objects;
     23 
     24 /** @hide */
     25 public class DisplayAdjustments {
     26     public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
     27 
     28     private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
     29     private Configuration mConfiguration = Configuration.EMPTY;
     30 
     31     public DisplayAdjustments() {
     32     }
     33 
     34     public DisplayAdjustments(Configuration configuration) {
     35         mConfiguration = configuration;
     36     }
     37 
     38     public DisplayAdjustments(DisplayAdjustments daj) {
     39         setCompatibilityInfo(daj.mCompatInfo);
     40         mConfiguration = daj.mConfiguration;
     41     }
     42 
     43     public void setCompatibilityInfo(CompatibilityInfo compatInfo) {
     44         if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
     45             throw new IllegalArgumentException(
     46                     "setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
     47         }
     48         if (compatInfo != null && (compatInfo.isScalingRequired()
     49                 || !compatInfo.supportsScreen())) {
     50             mCompatInfo = compatInfo;
     51         } else {
     52             mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
     53         }
     54     }
     55 
     56     public CompatibilityInfo getCompatibilityInfo() {
     57         return mCompatInfo;
     58     }
     59 
     60     public void setConfiguration(Configuration configuration) {
     61         if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
     62             throw new IllegalArgumentException(
     63                     "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
     64         }
     65         mConfiguration = configuration != null ? configuration : Configuration.EMPTY;
     66     }
     67 
     68     public Configuration getConfiguration() {
     69         return mConfiguration;
     70     }
     71 
     72     @Override
     73     public int hashCode() {
     74         int hash = 17;
     75         hash = hash * 31 + Objects.hashCode(mCompatInfo);
     76         hash = hash * 31 + Objects.hashCode(mConfiguration);
     77         return hash;
     78     }
     79 
     80     @Override
     81     public boolean equals(Object o) {
     82         if (!(o instanceof DisplayAdjustments)) {
     83             return false;
     84         }
     85         DisplayAdjustments daj = (DisplayAdjustments)o;
     86         return Objects.equals(daj.mCompatInfo, mCompatInfo) &&
     87                 Objects.equals(daj.mConfiguration, mConfiguration);
     88     }
     89 }
     90