The library is used to switch between content, progress, empty or error views. The main The progress is displayed during initial data loading. If data is empty then empty view is displayed. The same goes for error view. The work was based on Android-ProgressFragment project, but with a more declarative setup and state persistence.
The project now in Maven Central, so you can add dependency
dependencies{compile 'com.github.drnkn:progress-switcher:1.1.3@aar' }This library is compatible from API 4 (Android 1.6).
A sample can be found on Google Play:

The library consist of three main classes: ProgressWidget, ProgressSwitcher and ProgressFragment. All classes implement Switcher interface. The most important methods are:
For changing state:
publicvoidshowContent()publicvoidshowProgress()publicvoidshowEmpty()publicvoidshowError()For configure switcher:
publicvoidsetEmptyText(intresId)publicvoidsetErrorText(intresId)publicvoidsetOnEmptyViewClickListener(OnClickListeneronClickListener, intviewId)publicvoidsetOnErrorViewClickListener(OnClickListeneronClickListener, intviewId)- ProgressWidget
Declare widget in layout:
<ru.vang.progressswitcher.ProgressWidget xmlns:android="http://schemas.android.com/apk/res/android"xmlns:progress="http://schemas.android.com/apk/res-auto"android:id="@+id/progress_widget"android:layout_width="match_parent"android:layout_height="match_parent"progress:emptyViewLayout="@layout/custom_empty_view"progress:errorViewLayout="@layout/custom_error_view"progress:progressViewLayout="@layout/custom_progress_view"progress:animationIn="@anim/zoom_in"progress:animationOut="@anim/zoom_out"> <includelayout="@layout/view_content" /> </ru.vang.progressswitcher.ProgressWidget>... and that's it. Now you can get widget in your fragment and do what yout want.
- ProgressSwitcher
One way of using ProgressSwitcher is setup it with content view. Inflate your content view:
@OverridepublicViewonCreateView(finalLayoutInflaterinflater, finalViewGroupcontainer, finalBundlesavedInstanceState){mContentView = inflater.inflate(R.layout.view_content, container, false); returnmContentView}Setup switcher with fromContentView method:
@OverridepublicvoidonActivityCreated(finalBundlesavedInstanceState){super.onActivityCreated(savedInstanceState); mProgressSwitcher = ProgressSwitcher .fromContentView(getActivity(), mContentView)}The second way is provide complete layout:
<FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@id/content_container"> <includeandroid:id="@id/progress_view"layout="@layout/progress_view" /> <includeandroid:id="@id/empty_view"layout="@layout/empty_view" /> <includeandroid:id="@id/error_view"layout="@layout/error_view" /> </FrameLayout>And setup switcher with fromRootView method and add content view:
@OverridepublicvoidonActivityCreated(finalBundlesavedInstanceState){super.onActivityCreated(savedInstanceState); mProgressSwitcher = ProgressSwitcher .fromRootView(getActivity(), mContentView); mProgressSwitcher.addContentView(R.layout.view_content) }- ProgressFragment
Extend ProgressFragment:
publicclassCustomProgressFragmentextendsProgressFragment{}Setup content view:
@OverridepublicvoidonActivityCreated(BundlesavedInstanceState){super.onActivityCreated(savedInstanceState); setContentView(R.layout.view_content)}- Dmitry Zaitsev - [email protected]
Copyright 2014 Dmitry Zaitsev Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.