Skip to content

Set of tools with the ability to display indeterminate progress indicator when you are waiting for the initial data.

License

Notifications You must be signed in to change notification settings

sirencode/Android-ProgressSwitcher

Repository files navigation

Android-ProgressSwitcher

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.

Sample apk

Dependencies

AAR

The project now in Maven Central, so you can add dependency

dependencies{compile 'com.github.drnkn:progress-switcher:1.1.3@aar' }

Compatibility

This library is compatible from API 4 (Android 1.6).

Sample

A sample can be found on Google Play:

Get it on Google Play

Usage

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)}

Developed By

License

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. 

About

Set of tools with the ability to display indeterminate progress indicator when you are waiting for the initial data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java100.0%