12590c39739945451f80dcf8667709b93293fc8bcCraig Stout/*
22590c39739945451f80dcf8667709b93293fc8bcCraig Stout * Copyright (C) 2015 The Android Open Source Project
32590c39739945451f80dcf8667709b93293fc8bcCraig Stout *
42590c39739945451f80dcf8667709b93293fc8bcCraig Stout * Licensed under the Apache License, Version 2.0 (the "License");
52590c39739945451f80dcf8667709b93293fc8bcCraig Stout * you may not use this file except in compliance with the License.
62590c39739945451f80dcf8667709b93293fc8bcCraig Stout * You may obtain a copy of the License at
72590c39739945451f80dcf8667709b93293fc8bcCraig Stout *
82590c39739945451f80dcf8667709b93293fc8bcCraig Stout *      http://www.apache.org/licenses/LICENSE-2.0
92590c39739945451f80dcf8667709b93293fc8bcCraig Stout *
102590c39739945451f80dcf8667709b93293fc8bcCraig Stout * Unless required by applicable law or agreed to in writing, software
112590c39739945451f80dcf8667709b93293fc8bcCraig Stout * distributed under the License is distributed on an "AS IS" BASIS,
122590c39739945451f80dcf8667709b93293fc8bcCraig Stout * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132590c39739945451f80dcf8667709b93293fc8bcCraig Stout * See the License for the specific language governing permissions and
142590c39739945451f80dcf8667709b93293fc8bcCraig Stout * limitations under the License
152590c39739945451f80dcf8667709b93293fc8bcCraig Stout */
16ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.leanback.widget;
172590c39739945451f80dcf8667709b93293fc8bcCraig Stout
18ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
198e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas
202590c39739945451f80dcf8667709b93293fc8bcCraig Stoutimport android.graphics.drawable.Drawable;
212590c39739945451f80dcf8667709b93293fc8bcCraig Stoutimport android.os.Build;
222590c39739945451f80dcf8667709b93293fc8bcCraig Stoutimport android.view.View;
232590c39739945451f80dcf8667709b93293fc8bcCraig Stout
248619e0ef7062b6a714f22af993e4b440fae7ef08Aurimas Liutikasimport androidx.annotation.RestrictTo;
258619e0ef7062b6a714f22af993e4b440fae7ef08Aurimas Liutikas
262590c39739945451f80dcf8667709b93293fc8bcCraig Stout/**
272590c39739945451f80dcf8667709b93293fc8bcCraig Stout * Helper for view backgrounds.
282590c39739945451f80dcf8667709b93293fc8bcCraig Stout * @hide
292590c39739945451f80dcf8667709b93293fc8bcCraig Stout */
308e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas@RestrictTo(LIBRARY_GROUP)
312590c39739945451f80dcf8667709b93293fc8bcCraig Stoutpublic final class BackgroundHelper {
32e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas    public static void setBackgroundPreservingAlpha(View view, Drawable drawable) {
332590c39739945451f80dcf8667709b93293fc8bcCraig Stout        if (Build.VERSION.SDK_INT >= 19) {
34e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas            if (view.getBackground() != null) {
35e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas                drawable.setAlpha(view.getBackground().getAlpha());
36e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas            }
37e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas            view.setBackground(drawable);
382590c39739945451f80dcf8667709b93293fc8bcCraig Stout        } else {
39e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas            // Cannot query drawable alpha
40e32ee755efe98500d56ed3edf0ac91d262a48f1bAurimas Liutikas            view.setBackground(drawable);
412590c39739945451f80dcf8667709b93293fc8bcCraig Stout        }
422590c39739945451f80dcf8667709b93293fc8bcCraig Stout    }
430f4ca634bbc43ddff900c35f7d2a43b55d8c830dJake Wharton
440f4ca634bbc43ddff900c35f7d2a43b55d8c830dJake Wharton    private BackgroundHelper() {
450f4ca634bbc43ddff900c35f7d2a43b55d8c830dJake Wharton    }
462590c39739945451f80dcf8667709b93293fc8bcCraig Stout}
47