Home | History | Annotate | Download | only in shadow
      1 /*
      2  * Copyright (C) 2017 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.settings.testutils.shadow;
     18 
     19 import android.content.res.Resources;
     20 import android.content.res.ResourcesImpl;
     21 import android.graphics.drawable.ColorDrawable;
     22 import android.graphics.drawable.Drawable;
     23 import android.util.TypedValue;
     24 
     25 import com.android.settings.R;
     26 
     27 import org.robolectric.annotation.Implementation;
     28 import org.robolectric.annotation.Implements;
     29 import org.robolectric.shadows.ShadowResourcesImpl;
     30 
     31 @Implements(
     32         value = ResourcesImpl.class,
     33         inheritImplementationMethods = true,
     34         isInAndroidSdk = false,
     35         minSdk = 26
     36 )
     37 public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
     38 
     39     @Implementation
     40     public Drawable loadDrawable(Resources wrapper, TypedValue value, int id, int density,
     41             Resources.Theme theme) {
     42         // The drawable item in switchbar_background.xml refers to a very recent color attribute
     43         // that Robolectric isn't yet aware of.
     44         // TODO: Remove this once Robolectric is updated.
     45         if (id == R.drawable.switchbar_background) {
     46             return new ColorDrawable();
     47         } else if (id == R.drawable.ic_launcher_settings) {
     48             // ic_launcher_settings uses adaptive-icon, which is not supported by robolectric,
     49             // change it to a normal drawable.
     50             id = R.drawable.ic_settings_wireless;
     51         } else if (id == R.drawable.app_filter_spinner_background) {
     52             id = R.drawable.ic_expand_more_inverse;
     53         } else if (id == R.drawable.color_bar_progress
     54                 || id == R.drawable.ring_progress) {
     55             // color_bar_progress and ring_progress use hidden resources, so just use the regular
     56             // progress_horizontal drawable
     57             id = android.R.drawable.progress_horizontal;
     58         }
     59         return super.loadDrawable(wrapper, value, id, density, theme);
     60     }
     61 }
     62