1509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein/*
2509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * Copyright (C) 2012 Google Inc.
3509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * Licensed to The Android Open Source Project.
4509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein *
5509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * Licensed under the Apache License, Version 2.0 (the "License");
6509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * you may not use this file except in compliance with the License.
7509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * You may obtain a copy of the License at
8509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein *
9509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein *      http://www.apache.org/licenses/LICENSE-2.0
10509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein *
11509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * Unless required by applicable law or agreed to in writing, software
12509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * distributed under the License is distributed on an "AS IS" BASIS,
13509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * See the License for the specific language governing permissions and
15509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * limitations under the License.
16509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein */
17509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
18509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sappersteinpackage com.android.ex.photo.views;
19509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
20509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sappersteinimport android.view.View;
21509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sappersteinimport android.widget.ProgressBar;
22509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
23509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein/**
24509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * This class wraps around two progress bars and is solely designed to fix
25509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * a bug in the framework (b/6928449) that prevents a progress bar from
26509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * gracefully switching back and forth between indeterminate and determinate
27509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein * modes.
28509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein */
29509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sappersteinpublic class ProgressBarWrapper {
30459c618b574a3d3b6a544267a87c2093bacac20dPaul Westbrook    private final ProgressBar mDeterminate;
31459c618b574a3d3b6a544267a87c2093bacac20dPaul Westbrook    private final ProgressBar mIndeterminate;
32509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    private boolean mIsIndeterminate;
33509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
34509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    public ProgressBarWrapper(ProgressBar determinate,
35509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein            ProgressBar indeterminate, boolean isIndeterminate) {
36509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mDeterminate = determinate;
37509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mIndeterminate = indeterminate;
38509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        setIndeterminate(isIndeterminate);
39509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    }
40509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
41509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    public void setIndeterminate(boolean isIndeterminate) {
42509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mIsIndeterminate = isIndeterminate;
43509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
44509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        setVisibility(mIsIndeterminate);
45509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    }
46509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
47509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    public void setVisibility(int visibility) {
48509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        if (visibility == View.INVISIBLE || visibility == View.GONE) {
49509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein            mIndeterminate.setVisibility(visibility);
50509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein            mDeterminate.setVisibility(visibility);
51509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        } else {
52509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein            setVisibility(mIsIndeterminate);
53509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        }
54509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    }
55509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
56509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    private void setVisibility(boolean isIndeterminate) {
57509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mIndeterminate.setVisibility(isIndeterminate ? View.VISIBLE : View.GONE);
58509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mDeterminate.setVisibility(isIndeterminate ? View.GONE : View.VISIBLE);
59509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    }
60509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
61509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    public void setMax(int max) {
62509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mDeterminate.setMax(max);
63509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    }
64509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein
65509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    public void setProgress(int progress) {
66509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein        mDeterminate.setProgress(progress);
67509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein    }
68509bd03a2a783f804e9456767b52e0f8ef43479bAndrew Sapperstein}
69