1d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam/*
2d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * Copyright (C) 2015 The Android Open Source Project
3d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam *
4d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
5d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * you may not use this file except in compliance with the License.
6d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * You may obtain a copy of the License at
7d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam *
8d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
9d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam *
10d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * Unless required by applicable law or agreed to in writing, software
11d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
12d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * See the License for the specific language governing permissions and
14d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam * limitations under the License.
15d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam */
16d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam
17d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lampackage com.android.setupwizardlib;
18d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam
1995af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.annotation.SuppressLint;
209f9367672191190f903955d09a4314d40869acc6Maurice Lamimport android.annotation.TargetApi;
2195af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.content.Context;
22bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lamimport android.content.res.ColorStateList;
2395af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.content.res.TypedArray;
2495af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.graphics.Shader.TileMode;
2595af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.graphics.drawable.BitmapDrawable;
2695af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.graphics.drawable.Drawable;
2795af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.graphics.drawable.LayerDrawable;
28b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lamimport android.os.Build.VERSION;
29b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lamimport android.os.Build.VERSION_CODES;
30d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lamimport android.os.Parcel;
31d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lamimport android.os.Parcelable;
3295af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.util.AttributeSet;
332d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lamimport android.util.Log;
347114577a094593dbf55b625146b3809800697030Jorim Jaggiimport android.util.TypedValue;
3595af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.view.Gravity;
3699586481628659cd2982a0248bc0d09a6ec4590eMaurice Lamimport android.view.InflateException;
3795af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.view.LayoutInflater;
3895af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.view.View;
3995af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.view.ViewGroup;
40d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lamimport android.view.ViewStub;
41bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lamimport android.widget.ProgressBar;
4295abb283deb209532bbbae4ade3f5cc149a548a6Maurice Lamimport android.widget.ScrollView;
4395af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.widget.TextView;
4495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
452d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lamimport com.android.setupwizardlib.util.RequireScrollHelper;
462d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lamimport com.android.setupwizardlib.view.BottomScrollView;
4795af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport com.android.setupwizardlib.view.Illustration;
487e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lamimport com.android.setupwizardlib.view.NavigationBar;
4995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
50bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lampublic class SetupWizardLayout extends TemplateLayout {
5195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
5295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private static final String TAG = "SetupWizardLayout";
5395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
54bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam    private ColorStateList mProgressBarColor;
55bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam
5695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardLayout(Context context) {
57bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        super(context, 0, 0);
58bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        init(null, R.attr.suwLayoutTheme);
5995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
6095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
6195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardLayout(Context context, int template) {
62bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        this(context, template, 0);
63bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    }
64bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam
65bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    public SetupWizardLayout(Context context, int template, int containerId) {
66bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        super(context, template, containerId);
67bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        init(null, R.attr.suwLayoutTheme);
6895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
6995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
7095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardLayout(Context context, AttributeSet attrs) {
719f9367672191190f903955d09a4314d40869acc6Maurice Lam        super(context, attrs);
72bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        init(attrs, R.attr.suwLayoutTheme);
7395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
7495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
759f9367672191190f903955d09a4314d40869acc6Maurice Lam    @TargetApi(VERSION_CODES.HONEYCOMB)
7695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardLayout(Context context, AttributeSet attrs, int defStyleAttr) {
779f9367672191190f903955d09a4314d40869acc6Maurice Lam        super(context, attrs, defStyleAttr);
78bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        init(attrs, defStyleAttr);
799f9367672191190f903955d09a4314d40869acc6Maurice Lam    }
809f9367672191190f903955d09a4314d40869acc6Maurice Lam
819f9367672191190f903955d09a4314d40869acc6Maurice Lam    // All the constructors delegate to this init method. The 3-argument constructor is not
829f9367672191190f903955d09a4314d40869acc6Maurice Lam    // available in LinearLayout before v11, so call super with the exact same arguments.
83bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    private void init(AttributeSet attrs, int defStyleAttr) {
849f9367672191190f903955d09a4314d40869acc6Maurice Lam        final TypedArray a = getContext().obtainStyledAttributes(attrs,
8595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                R.styleable.SuwSetupWizardLayout, defStyleAttr, 0);
8695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
8795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        // Set the background from XML, either directly or built from a bitmap tile
8895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final Drawable background =
8995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                a.getDrawable(R.styleable.SuwSetupWizardLayout_suwBackground);
9095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (background != null) {
91b73a15f71e63dd46bf4dab94ca13caa861ac948fMaurice Lam            setLayoutBackground(background);
9295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        } else {
9395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Drawable backgroundTile =
9495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                    a.getDrawable(R.styleable.SuwSetupWizardLayout_suwBackgroundTile);
9595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            if (backgroundTile != null) {
9695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                setBackgroundTile(backgroundTile);
9795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            }
9895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
9995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
10095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        // Set the illustration from XML, either directly or built from image + horizontal tile
10195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final Drawable illustration =
10295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                a.getDrawable(R.styleable.SuwSetupWizardLayout_suwIllustration);
10395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (illustration != null) {
10495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            setIllustration(illustration);
10595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        } else {
10695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Drawable illustrationImage =
10795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                    a.getDrawable(R.styleable.SuwSetupWizardLayout_suwIllustrationImage);
10895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Drawable horizontalTile = a.getDrawable(
10995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                    R.styleable.SuwSetupWizardLayout_suwIllustrationHorizontalTile);
11095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            if (illustrationImage != null && horizontalTile != null) {
11195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                setIllustration(illustrationImage, horizontalTile);
11295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            }
11395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
11495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
1157114577a094593dbf55b625146b3809800697030Jorim Jaggi        // Set the top padding of the illustration
1167114577a094593dbf55b625146b3809800697030Jorim Jaggi        int decorPaddingTop = a.getDimensionPixelSize(
1177114577a094593dbf55b625146b3809800697030Jorim Jaggi                R.styleable.SuwSetupWizardLayout_suwDecorPaddingTop, -1);
1187114577a094593dbf55b625146b3809800697030Jorim Jaggi        if (decorPaddingTop == -1) {
1197114577a094593dbf55b625146b3809800697030Jorim Jaggi            decorPaddingTop = getResources().getDimensionPixelSize(R.dimen.suw_decor_padding_top);
1207114577a094593dbf55b625146b3809800697030Jorim Jaggi        }
1217114577a094593dbf55b625146b3809800697030Jorim Jaggi        setDecorPaddingTop(decorPaddingTop);
1227114577a094593dbf55b625146b3809800697030Jorim Jaggi
1237114577a094593dbf55b625146b3809800697030Jorim Jaggi
1247114577a094593dbf55b625146b3809800697030Jorim Jaggi        // Set the illustration aspect ratio. See Illustration.setAspectRatio(float). This will
1257114577a094593dbf55b625146b3809800697030Jorim Jaggi        // override suwIllustrationPaddingTop if its value is not 0.
1267114577a094593dbf55b625146b3809800697030Jorim Jaggi        float illustrationAspectRatio = a.getFloat(
1277114577a094593dbf55b625146b3809800697030Jorim Jaggi                R.styleable.SuwSetupWizardLayout_suwIllustrationAspectRatio, -1f);
1287114577a094593dbf55b625146b3809800697030Jorim Jaggi        if (illustrationAspectRatio == -1f) {
1297114577a094593dbf55b625146b3809800697030Jorim Jaggi            final TypedValue out = new TypedValue();
1307114577a094593dbf55b625146b3809800697030Jorim Jaggi            getResources().getValue(R.dimen.suw_illustration_aspect_ratio, out, true);
1317114577a094593dbf55b625146b3809800697030Jorim Jaggi            illustrationAspectRatio = out.getFloat();
1327114577a094593dbf55b625146b3809800697030Jorim Jaggi        }
1337114577a094593dbf55b625146b3809800697030Jorim Jaggi        setIllustrationAspectRatio(illustrationAspectRatio);
1347114577a094593dbf55b625146b3809800697030Jorim Jaggi
13595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        // Set the header text
13695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final CharSequence headerText =
13795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                a.getText(R.styleable.SuwSetupWizardLayout_suwHeaderText);
13895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (headerText != null) {
13995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            setHeaderText(headerText);
14095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
14195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
14295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        a.recycle();
14395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
14495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
14595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    @Override
146d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    protected Parcelable onSaveInstanceState() {
147d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        final Parcelable parcelable = super.onSaveInstanceState();
148d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        final SavedState ss = new SavedState(parcelable);
1490e9b312956dd28cef21473337800919eb0a54b2dMaurice Lam        ss.mIsProgressBarShown = isProgressBarShown();
150d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        return ss;
151d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    }
152d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
153d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    @Override
154d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    protected void onRestoreInstanceState(Parcelable state) {
1557f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam        if (!(state instanceof SavedState)) {
1567f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam            Log.w(TAG, "Ignoring restore instance state " + state);
1577f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam            super.onRestoreInstanceState(state);
1587f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam            return;
1597f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam        }
1607f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam
161d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        final SavedState ss = (SavedState) state;
162d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        super.onRestoreInstanceState(ss.getSuperState());
1630e9b312956dd28cef21473337800919eb0a54b2dMaurice Lam        final boolean isProgressBarShown = ss.mIsProgressBarShown;
164d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        if (isProgressBarShown) {
165d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            showProgressBar();
166d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        } else {
167d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            hideProgressBar();
168d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        }
169d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    }
170d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
171d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    @Override
17295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    protected View onInflateTemplate(LayoutInflater inflater, int template) {
17395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (template == 0) {
17495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            template = R.layout.suw_template;
17595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
17699586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam        try {
17799586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam            return super.onInflateTemplate(inflater, template);
1783aee7b9de403e669e24ce68da1b390ab74288364Maurice Lam        } catch (RuntimeException e) {
1793aee7b9de403e669e24ce68da1b390ab74288364Maurice Lam            // Versions before M throws RuntimeException for unsuccessful attribute resolution
1803aee7b9de403e669e24ce68da1b390ab74288364Maurice Lam            // Versions M+ will throw an InflateException (which extends from RuntimeException)
18199586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam            throw new InflateException("Unable to inflate layout. Are you using "
18299586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam                    + "@style/SuwThemeMaterial (or its descendant) as your theme?", e);
18399586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam        }
18495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
18595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
186bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    @Override
187bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    protected ViewGroup findContainer(int containerId) {
188bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        if (containerId == 0) {
189bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam            containerId = R.id.suw_layout_content;
190bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        }
191bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        return super.findContainer(containerId);
19295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
19395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
1947e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam    public NavigationBar getNavigationBar() {
195ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_navigation_bar);
1967e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam        return view instanceof NavigationBar ? (NavigationBar) view : null;
1977e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam    }
1987e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam
19995abb283deb209532bbbae4ade3f5cc149a548a6Maurice Lam    public ScrollView getScrollView() {
200ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_bottom_scroll_view);
20195abb283deb209532bbbae4ade3f5cc149a548a6Maurice Lam        return view instanceof ScrollView ? (ScrollView) view : null;
2022d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam    }
2032d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam
2042d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam    public void requireScrollToBottom() {
2052d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam        final NavigationBar navigationBar = getNavigationBar();
20695abb283deb209532bbbae4ade3f5cc149a548a6Maurice Lam        final ScrollView scrollView = getScrollView();
20795abb283deb209532bbbae4ade3f5cc149a548a6Maurice Lam        if (navigationBar != null && (scrollView instanceof BottomScrollView)) {
20895abb283deb209532bbbae4ade3f5cc149a548a6Maurice Lam            RequireScrollHelper.requireScroll(navigationBar, (BottomScrollView) scrollView);
2092d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam        } else {
2102d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam            Log.e(TAG, "Both suw_layout_navigation_bar and suw_bottom_scroll_view must exist in"
2112d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam                    + " the template to require scrolling.");
2122d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam        }
2132d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam    }
2142d77e072fed129b34e473c7f77246a2b064fab7dMaurice Lam
21595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public void setHeaderText(int title) {
2166cd984308b537924865bde77c2ee13d072cd9a48Udam Saini        final TextView titleView = getHeaderTextView();
21795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (titleView != null) {
21895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            titleView.setText(title);
21995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
22095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
22195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
22295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public void setHeaderText(CharSequence title) {
2236cd984308b537924865bde77c2ee13d072cd9a48Udam Saini        final TextView titleView = getHeaderTextView();
22495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (titleView != null) {
22595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            titleView.setText(title);
22695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
22795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
22895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
229caf3ce9f8da61e59a7b7dacbce2e1f8e23d3231eRussell Brenner    public CharSequence getHeaderText() {
2306cd984308b537924865bde77c2ee13d072cd9a48Udam Saini        final TextView titleView = getHeaderTextView();
231caf3ce9f8da61e59a7b7dacbce2e1f8e23d3231eRussell Brenner        return titleView != null ? titleView.getText() : null;
232caf3ce9f8da61e59a7b7dacbce2e1f8e23d3231eRussell Brenner    }
233caf3ce9f8da61e59a7b7dacbce2e1f8e23d3231eRussell Brenner
2346cd984308b537924865bde77c2ee13d072cd9a48Udam Saini    public TextView getHeaderTextView() {
2356cd984308b537924865bde77c2ee13d072cd9a48Udam Saini        return (TextView) findManagedViewById(R.id.suw_layout_title);
2366cd984308b537924865bde77c2ee13d072cd9a48Udam Saini    }
2376cd984308b537924865bde77c2ee13d072cd9a48Udam Saini
23895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    /**
23995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * Set the illustration of the layout. The drawable will be applied as is, and the bounds will
24095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * be set as implemented in {@link com.android.setupwizardlib.view.Illustration}. To create
24195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * a suitable drawable from an asset and a horizontal repeating tile, use
24295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * {@link #setIllustration(int, int)} instead.
24395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     *
24495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * @param drawable The drawable specifying the illustration.
24595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     */
24695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public void setIllustration(Drawable drawable) {
247ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_decor);
24895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (view instanceof Illustration) {
24995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Illustration illustration = (Illustration) view;
25095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            illustration.setIllustration(drawable);
25195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
25295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
25395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
25495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    /**
25595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * Set the illustration of the layout, which will be created asset and the horizontal tile as
25695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * suitable. On phone layouts (not sw600dp), the asset will be scaled, maintaining aspect ratio.
25795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * On tablets (sw600dp), the assets will always have 256dp height and the rest of the
25895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * illustration area that the asset doesn't fill will be covered by the horizontalTile.
25995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     *
26095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * @param asset Resource ID of the illustration asset.
26195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * @param horizontalTile Resource ID of the horizontally repeating tile for tablet layout.
26295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     */
26395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public void setIllustration(int asset, int horizontalTile) {
264ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_decor);
26595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (view instanceof Illustration) {
26695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Illustration illustration = (Illustration) view;
26795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Drawable illustrationDrawable = getIllustration(asset, horizontalTile);
26895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            illustration.setIllustration(illustrationDrawable);
26995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
27095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
27195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
27295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private void setIllustration(Drawable asset, Drawable horizontalTile) {
273ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_decor);
27495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (view instanceof Illustration) {
27595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Illustration illustration = (Illustration) view;
27695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final Drawable illustrationDrawable = getIllustration(asset, horizontalTile);
27795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            illustration.setIllustration(illustrationDrawable);
27895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
27995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
28095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
28195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    /**
2827114577a094593dbf55b625146b3809800697030Jorim Jaggi     * Sets the aspect ratio of the illustration. This will be the space (padding top) reserved
2837114577a094593dbf55b625146b3809800697030Jorim Jaggi     * above the header text. This will override the padding top of the illustration.
2847114577a094593dbf55b625146b3809800697030Jorim Jaggi     *
2857114577a094593dbf55b625146b3809800697030Jorim Jaggi     * @param aspectRatio The aspect ratio
2867114577a094593dbf55b625146b3809800697030Jorim Jaggi     * @see com.android.setupwizardlib.view.Illustration#setAspectRatio(float)
2877114577a094593dbf55b625146b3809800697030Jorim Jaggi     */
2887114577a094593dbf55b625146b3809800697030Jorim Jaggi    public void setIllustrationAspectRatio(float aspectRatio) {
289ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_decor);
2907114577a094593dbf55b625146b3809800697030Jorim Jaggi        if (view instanceof Illustration) {
2917114577a094593dbf55b625146b3809800697030Jorim Jaggi            final Illustration illustration = (Illustration) view;
2927114577a094593dbf55b625146b3809800697030Jorim Jaggi            illustration.setAspectRatio(aspectRatio);
2937114577a094593dbf55b625146b3809800697030Jorim Jaggi        }
2947114577a094593dbf55b625146b3809800697030Jorim Jaggi    }
2957114577a094593dbf55b625146b3809800697030Jorim Jaggi
2967114577a094593dbf55b625146b3809800697030Jorim Jaggi    /**
2977114577a094593dbf55b625146b3809800697030Jorim Jaggi     * Set the top padding of the decor view. If the decor is an Illustration and the aspect ratio
2987114577a094593dbf55b625146b3809800697030Jorim Jaggi     * is set, this value will be overridden.
2997114577a094593dbf55b625146b3809800697030Jorim Jaggi     *
300b38561602db3fc1b31c7ee907da41ec2c53e4764Maurice Lam     * <p>Note: Currently the default top padding for tablet landscape is 128dp, which is the offset
3017114577a094593dbf55b625146b3809800697030Jorim Jaggi     * of the card from the top. This is likely to change in future versions so this value aligns
3027114577a094593dbf55b625146b3809800697030Jorim Jaggi     * with the height of the illustration instead.
3037114577a094593dbf55b625146b3809800697030Jorim Jaggi     *
3047114577a094593dbf55b625146b3809800697030Jorim Jaggi     * @param paddingTop The top padding in pixels.
3057114577a094593dbf55b625146b3809800697030Jorim Jaggi     */
3067114577a094593dbf55b625146b3809800697030Jorim Jaggi    public void setDecorPaddingTop(int paddingTop) {
307ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_decor);
3087114577a094593dbf55b625146b3809800697030Jorim Jaggi        if (view != null) {
3097114577a094593dbf55b625146b3809800697030Jorim Jaggi            view.setPadding(view.getPaddingLeft(), paddingTop, view.getPaddingRight(),
3107114577a094593dbf55b625146b3809800697030Jorim Jaggi                    view.getPaddingBottom());
3117114577a094593dbf55b625146b3809800697030Jorim Jaggi        }
3127114577a094593dbf55b625146b3809800697030Jorim Jaggi    }
3137114577a094593dbf55b625146b3809800697030Jorim Jaggi
3147114577a094593dbf55b625146b3809800697030Jorim Jaggi    /**
31595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * Set the background of the layout, which is expected to be able to extend infinitely. If it is
31695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * a bitmap tile and you want it to repeat, use {@link #setBackgroundTile(int)} instead.
31795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     */
318b73a15f71e63dd46bf4dab94ca13caa861ac948fMaurice Lam    public void setLayoutBackground(Drawable background) {
319ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View view = findManagedViewById(R.id.suw_layout_decor);
32095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (view != null) {
321b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            //noinspection deprecation
322b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            view.setBackgroundDrawable(background);
32395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
32495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
32595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
32695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    /**
32795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     * Set the background of the layout to a repeating bitmap tile. To use a different kind of
328b73a15f71e63dd46bf4dab94ca13caa861ac948fMaurice Lam     * drawable, use {@link #setLayoutBackground(android.graphics.drawable.Drawable)} instead.
32995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam     */
33095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public void setBackgroundTile(int backgroundTile) {
331b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam        final Drawable backgroundTileDrawable =
332b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam                getContext().getResources().getDrawable(backgroundTile);
33395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        setBackgroundTile(backgroundTileDrawable);
33495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
33595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
33695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private void setBackgroundTile(Drawable backgroundTile) {
33795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (backgroundTile instanceof BitmapDrawable) {
33895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            ((BitmapDrawable) backgroundTile).setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
33995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
340b73a15f71e63dd46bf4dab94ca13caa861ac948fMaurice Lam        setLayoutBackground(backgroundTile);
34195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
34295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
34395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private Drawable getIllustration(int asset, int horizontalTile) {
34495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final Context context = getContext();
34595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final Drawable assetDrawable = context.getResources().getDrawable(asset);
34695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final Drawable tile = context.getResources().getDrawable(horizontalTile);
34795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        return getIllustration(assetDrawable, tile);
34895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
34995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
35095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    @SuppressLint("RtlHardcoded")
35195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private Drawable getIllustration(Drawable asset, Drawable horizontalTile) {
35295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        final Context context = getContext();
35395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (context.getResources().getBoolean(R.bool.suwUseTabletLayout)) {
35495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            // If it is a "tablet" (sw600dp), create a LayerDrawable with the horizontal tile.
35595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            if (horizontalTile instanceof BitmapDrawable) {
35695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                ((BitmapDrawable) horizontalTile).setTileModeX(TileMode.REPEAT);
35795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                ((BitmapDrawable) horizontalTile).setGravity(Gravity.TOP);
35895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            }
35995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            if (asset instanceof BitmapDrawable) {
36095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                // Always specify TOP | LEFT, Illustration will flip the entire LayerDrawable.
36195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                ((BitmapDrawable) asset).setGravity(Gravity.TOP | Gravity.LEFT);
36295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            }
36395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            final LayerDrawable layers =
36495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam                    new LayerDrawable(new Drawable[] { horizontalTile, asset });
365b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
366b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam                layers.setAutoMirrored(true);
367b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            }
36895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            return layers;
36995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        } else {
37095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            // If it is a "phone" (not sw600dp), simply return the illustration
371b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
372b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam                asset.setAutoMirrored(true);
373b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            }
37495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            return asset;
37595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
37695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
377d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
378ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    /**
379ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * Same as {@link android.view.View#findViewById(int)}, but may include views that are managed
380ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * by this view but not currently added to the view hierarchy. e.g. recycler view or list view
381ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * headers that are not currently shown.
382ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     */
383ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    protected View findManagedViewById(int id) {
384ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        return findViewById(id);
385ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    }
386ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam
387d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    public boolean isProgressBarShown() {
388ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View progressBar = findManagedViewById(R.id.suw_layout_progress);
389d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        return progressBar != null && progressBar.getVisibility() == View.VISIBLE;
390d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    }
391d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
392ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    /**
393ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * Sets whether the progress bar below the header text is shown or not. The progress bar is
394ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * a lazily inflated ViewStub, which means the progress bar will not actually be part of the
395ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * view hierarchy until the first time this is set to {@code true}.
396ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     */
397ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    public void setProgressBarShown(boolean shown) {
398ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        final View progressBar = findManagedViewById(R.id.suw_layout_progress);
399d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        if (progressBar != null) {
400ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam            progressBar.setVisibility(shown ? View.VISIBLE : View.GONE);
401ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        } else if (shown) {
402ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam            final ViewStub progressBarStub =
403ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam                    (ViewStub) findManagedViewById(R.id.suw_layout_progress_stub);
404d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            if (progressBarStub != null) {
405d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                progressBarStub.inflate();
406d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            }
407bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            if (mProgressBarColor != null) {
408bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam                setProgressBarColor(mProgressBarColor);
409bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            }
410d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        }
411d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    }
412d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
413ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    /**
414ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * @deprecated Use {@link #setProgressBarShown(boolean)}
415ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     */
416ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    @Deprecated
417ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    public void showProgressBar() {
418ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        setProgressBarShown(true);
419ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    }
420ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam
421ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    /**
422ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     * @deprecated Use {@link #setProgressBarShown(boolean)}
423ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam     */
424ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam    @Deprecated
425d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    public void hideProgressBar() {
426ec9d8c8aa8fdeb6640fb0037b062bf10ca1c016bMaurice Lam        setProgressBarShown(false);
427d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    }
428d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
429bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam    public void setProgressBarColor(ColorStateList color) {
430bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam        mProgressBarColor = color;
431bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
432bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            // Suppress lint error caused by
433bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            // https://code.google.com/p/android/issues/detail?id=183136
434bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            // noinspection AndroidLintWrongViewCast
435bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            final ProgressBar bar = (ProgressBar) findViewById(R.id.suw_layout_progress);
436bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            if (bar != null) {
437bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam                bar.setIndeterminateTintList(color);
438bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam            }
439bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam        }
440bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam    }
441bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam
442bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam    public ColorStateList getProgressBarColor() {
443bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam        return mProgressBarColor;
444bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam    }
445bf4afac02228e42af171bbb5f3db11977be487b1Maurice Lam
4468c10c403c063aff3f17c4949b0fe9a88536ae580Maurice Lam    /* Misc */
4478c10c403c063aff3f17c4949b0fe9a88536ae580Maurice Lam
448d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    protected static class SavedState extends BaseSavedState {
449d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
4500e9b312956dd28cef21473337800919eb0a54b2dMaurice Lam        boolean mIsProgressBarShown = false;
451d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
452d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        public SavedState(Parcelable parcelable) {
453d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            super(parcelable);
454d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        }
455d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
456d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        public SavedState(Parcel source) {
457d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            super(source);
4580e9b312956dd28cef21473337800919eb0a54b2dMaurice Lam            mIsProgressBarShown = source.readInt() != 0;
459d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        }
460d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
461d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        @Override
462d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        public void writeToParcel(Parcel dest, int flags) {
463d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam            super.writeToParcel(dest, flags);
4640e9b312956dd28cef21473337800919eb0a54b2dMaurice Lam            dest.writeInt(mIsProgressBarShown ? 1 : 0);
465d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        }
466d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
467d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam        public static final Parcelable.Creator<SavedState> CREATOR =
468d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                new Parcelable.Creator<SavedState>() {
469d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
470d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                    @Override
471d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                    public SavedState createFromParcel(Parcel parcel) {
472d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                        return new SavedState(parcel);
473d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                    }
474d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam
475d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                    @Override
476d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                    public SavedState[] newArray(int size) {
477d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                        return new SavedState[size];
478d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                    }
479d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam                };
480d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam    }
481d4c6ef70612f48c4612ec827bd89964d0955cd6fMaurice Lam}
482