• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 com.android.pump.util;
18 
19 import android.graphics.Bitmap;
20 import android.net.Uri;
21 
22 import androidx.annotation.AnyThread;
23 import androidx.annotation.NonNull;
24 import androidx.collection.ArrayMap;
25 
26 import java.util.Map;
27 
28 @AnyThread
29 class OrientationCache {
30     private final Map<Uri, Integer> mOrientationCache = new ArrayMap<>();
31 
put(@onNull Uri key, @NonNull Bitmap bitmap)32     void put(@NonNull Uri key, @NonNull Bitmap bitmap) {
33         int orientation = bitmap.getWidth() < bitmap.getHeight() ?
34                 Orientation.PORTRAIT : Orientation.LANDSCAPE;
35         mOrientationCache.put(key, orientation);
36     }
37 
38     @Orientation int get(@NonNull Uri key) {
39         Integer value = mOrientationCache.get(key);
40         if (value != null) {
41             return value;
42         }
43         return Orientation.UNKNOWN;
44     }
45 }
46