• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.support.v4.media;
18 
19 import android.os.Bundle;
20 
21 /**
22  * @hide
23  */
24 public class MediaBrowserCompatUtils {
areSameOptions(Bundle options1, Bundle options2)25     public static boolean areSameOptions(Bundle options1, Bundle options2) {
26         if (options1 == options2) {
27             return true;
28         } else if (options1 == null) {
29             return options2.getInt(MediaBrowserCompat.EXTRA_PAGE, -1) == -1
30                     && options2.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1) == -1;
31         } else if (options2 == null) {
32             return options1.getInt(MediaBrowserCompat.EXTRA_PAGE, -1) == -1
33                     && options1.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1) == -1;
34         } else {
35             return options1.getInt(MediaBrowserCompat.EXTRA_PAGE, -1)
36                     == options2.getInt(MediaBrowserCompat.EXTRA_PAGE, -1)
37                     && options1.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1)
38                     == options2.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1);
39         }
40     }
41 
hasDuplicatedItems(Bundle options1, Bundle options2)42     public static boolean hasDuplicatedItems(Bundle options1, Bundle options2) {
43         int page1 = options1 == null ? -1 : options1.getInt(MediaBrowserCompat.EXTRA_PAGE, -1);
44         int page2 = options2 == null ? -1 :options2.getInt(MediaBrowserCompat.EXTRA_PAGE, -1);
45         int pageSize1 = options1 == null
46                 ? -1 :options1.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1);
47         int pageSize2 = options2 == null
48                 ? -1 :options2.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1);
49 
50         int startIndex1, startIndex2, endIndex1, endIndex2;
51         if (page1 == -1 || pageSize1 == -1) {
52             startIndex1 = 0;
53             endIndex1 = Integer.MAX_VALUE;
54         } else {
55             startIndex1 = pageSize1 * page1;
56             endIndex1 = startIndex1 + pageSize1 - 1;
57         }
58 
59         if (page2 == -1 || pageSize2 == -1) {
60             startIndex2 = 0;
61             endIndex2 = Integer.MAX_VALUE;
62         } else {
63             startIndex2 = pageSize2 * page2;
64             endIndex2 = startIndex2 + pageSize2 - 1;
65         }
66 
67         if (startIndex1 <= startIndex2 && startIndex2 <= endIndex1) {
68             return true;
69         } else if (startIndex1 <= endIndex2 && endIndex2 <= endIndex1) {
70             return true;
71         }
72         return false;
73     }
74 }
75