1 /* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.ex.photo.views; 19 20 import android.view.View; 21 import android.widget.ProgressBar; 22 23 /** 24 * This class wraps around two progress bars and is solely designed to fix 25 * a bug in the framework (b/6928449) that prevents a progress bar from 26 * gracefully switching back and forth between indeterminate and determinate 27 * modes. 28 */ 29 public class ProgressBarWrapper { 30 private final ProgressBar mDeterminate; 31 private final ProgressBar mIndeterminate; 32 private boolean mIsIndeterminate; 33 34 public ProgressBarWrapper(ProgressBar determinate, 35 ProgressBar indeterminate, boolean isIndeterminate) { 36 mDeterminate = determinate; 37 mIndeterminate = indeterminate; 38 setIndeterminate(isIndeterminate); 39 } 40 41 public void setIndeterminate(boolean isIndeterminate) { 42 mIsIndeterminate = isIndeterminate; 43 44 setVisibility(mIsIndeterminate); 45 } 46 47 public void setVisibility(int visibility) { 48 if (visibility == View.INVISIBLE || visibility == View.GONE) { 49 mIndeterminate.setVisibility(visibility); 50 mDeterminate.setVisibility(visibility); 51 } else { 52 setVisibility(mIsIndeterminate); 53 } 54 } 55 56 private void setVisibility(boolean isIndeterminate) { 57 mIndeterminate.setVisibility(isIndeterminate ? View.VISIBLE : View.GONE); 58 mDeterminate.setVisibility(isIndeterminate ? View.GONE : View.VISIBLE); 59 } 60 61 public void setMax(int max) { 62 mDeterminate.setMax(max); 63 } 64 65 public void setProgress(int progress) { 66 mDeterminate.setProgress(progress); 67 } 68 } 69