diff --git a/.gitignore b/.gitignore index af74b48..78cc783 100644 --- a/.gitignore +++ b/.gitignore @@ -3,21 +3,13 @@ bin gen lint.xml + #Eclipse .project .classpath .settings .checkstyle -#IntelliJ IDEA -.idea -*.iml -*.ipr -*.iws -out -classes -gen-external-apklibs - #Maven target release.properties @@ -31,4 +23,23 @@ proguard.cfg proguard-project.txt #Other -.DS_Store \ No newline at end of file +.DS_Store +#svn +.svn + +# Android Studio +.idea/ +.gradle +gradle +/*/local.properties +/*/out +/*/*/build +/*/*/production +*.iml +*.iws +*.ipr +*~ +*.swp +/gradlew.bat +/gradlew +build diff --git a/ProgressSwitcher-Sample.apk b/ProgressSwitcher-Sample.apk new file mode 100644 index 0000000..4b0b981 Binary files /dev/null and b/ProgressSwitcher-Sample.apk differ diff --git a/ProgressSwitcher.aar b/ProgressSwitcher.aar new file mode 100644 index 0000000..8aa174e Binary files /dev/null and b/ProgressSwitcher.aar differ diff --git a/README.md b/README.md index 478f6b4..e5fcdce 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,186 @@ -Android-ProgressFragment +Android-ProgressSwitcher ======================== -Implementation of the fragment with the ability to display indeterminate progress indicator when you are waiting for the initial data. Based on [ListFragment](http://developer.android.com/reference/android/app/ListFragment.html). +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](https://github.com/johnkil/Android-ProgressFragment) project, but with a more declarative setup and state persistence. +[Sample apk](https://github.com/Drnkn/Android-ProgressSwitcher/blob/master/ProgressSwitcher-Sample.apk) + +Dependencies +------------- + +[AAR](https://github.com/Drnkn/Android-ProgressSwitcher/blob/master/ProgressSwitcher.aar) + +The project now in Maven Central, so you can add dependency +``` xml +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 application is available on Google Play: +A sample can be found on Google Play: - + Get it on Google Play -![screenshot][1] +Usage +----- +The library consist of three main classes: ProgressWidget, ProgressSwitcher and ProgressFragment. All classes implement Switcher interface. The most important methods are: -Compatibility -------------- +For changing state: -This library is compatible from API 4 (Android 1.6). +```java +public void showContent() +``` +```java +public void showProgress() +``` +```java +public void showEmpty() +``` +```java +public void showError() +``` +For configure switcher: -Usage ------ +```java +public void setEmptyText(int resId) +``` +```java +public void setErrorText(int resId) +``` +```java +public void setOnEmptyViewClickListener(OnClickListener onClickListener, int viewId) +``` +```java +public void setOnErrorViewClickListener(OnClickListener onClickListener, int viewId) +``` -To display the progress fragment you need the following code: +* ProgressWidget -* Create your implementation of progress fragment +Declare widget in layout: +``` xml + -``` java -public class MyProgressFragment extends ProgressFragment { - // your code of fragment -} -``` + + + +``` -* Setup content view and empty text (optional) in `onActivityCreate()` method. +... 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: ``` java -@Override -public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - // Setup content view - setContentView(R.layout.content); - // Setup text for empty content - setEmptyText(R.string.empty); - // ... -} -``` + @Override + public View onCreateView(final LayoutInflater inflater, final ViewGroup container, + final Bundle savedInstanceState) { + mContentView = inflater.inflate(R.layout.view_content, container, false); + + return mContentView; + } +``` -* Display of indeterminate progress indicator +Setup switcher with fromContentView method: ``` java -setContentShown(false); -``` + @Override + public void onActivityCreated(final Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mProgressSwitcher = ProgressSwitcher + .fromContentView(getActivity(), mContentView); + } +``` + +The second way is provide complete layout: + +``` xml + + + + + + + + + +``` + +And setup switcher with fromRootView method and add content view: +``` java + @Override + public void onActivityCreated(final Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mProgressSwitcher = ProgressSwitcher + .fromRootView(getActivity(), mContentView); + mProgressSwitcher.addContentView(R.layout.view_content) + } +``` + +* ProgressFragment -* When the data is loaded to set whether the content is empty and show content +Extend ProgressFragment: ``` java -setContentEmpty(/* true if content is empty else false */); -setContentShown(true); -``` +public class CustomProgressFragment extends ProgressFragment { +} +``` + +Setup content view: +``` java +@Override +public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + setContentView(R.layout.view_content); +} +``` Developed By ------------ -* Evgeny Shishkin - +* Dmitry Zaitsev - License ------- - Copyright 2013 Evgeny Shishkin + 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. @@ -86,5 +193,3 @@ License 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. - -[1]: http://i50.tinypic.com/2b9jy9.png diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f351ae4 --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:0.12.+' + } +} + +allprojects { + version = VERSION_NAME + group = GROUP + + repositories { + mavenCentral() + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4eab181 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,13 @@ +VERSION_NAME = 1.1.3 +VERSION_CODE = 4 +GROUP = com.github.drnkn + +POM_DESCRIPTION = Set of tools with the ability to display indeterminate progress indicator when you are waiting for the initial data +POM_URL = https://github.com/Drnkn/Android-ProgressSwitcher +POM_SCM_URL = https://github.com/Drnkn/Android-ProgressSwitcher +POM_SCM_CONNECTION = scm:git@github.com:Drnkn/Android-ProgressSwitcher.git +POM_SCM_DEV_CONNECTION = scm:git@github.com:gabrielemariotti/changeloglib.git +POM_LICENCE_NAME = The Apache Software License, Version 2.0 +POM_LICENCE_URL = http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_DIST = repo +POM_DEVELOPER_NAME = Dmitry Zaytsev \ No newline at end of file diff --git a/library/AndroidManifest.xml b/library/AndroidManifest.xml index 51f7ac7..1a23bb3 100644 --- a/library/AndroidManifest.xml +++ b/library/AndroidManifest.xml @@ -1,10 +1,10 @@ + android:targetSdkVersion="19"/> diff --git a/library/build.gradle b/library/build.gradle new file mode 100644 index 0000000..7ecd2b6 --- /dev/null +++ b/library/build.gradle @@ -0,0 +1,44 @@ +apply plugin: 'com.android.library' +apply plugin: 'maven' + +dependencies { + compile 'com.android.support:support-v4:19.0.+' +} + +android { + compileSdkVersion 19 + buildToolsVersion '19.1.0' + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] + } + + // Move the tests to tests/java, tests/res, etc... + instrumentTest.setRoot('tests') + + // Move the build types to build-types/ + // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... + // This moves them out of them default location under src//... which would + // conflict with src/ being used by the main source set. + // Adding new build types or product flavors should be accompanied + // by a similar customization. + debug.setRoot('build-types/debug') + release.setRoot('build-types/release') + } + defaultConfig { + minSdkVersion 4 + targetSdkVersion 19 + versionName project.VERSION_NAME + versionCode Integer.parseInt(project.VERSION_CODE) + } + productFlavors { + } +} + +apply from: '../maven_push.gradle' diff --git a/library/gradle.properties b/library/gradle.properties new file mode 100644 index 0000000..0835d76 --- /dev/null +++ b/library/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Settings specified in this file will override any Gradle settings +# configured through the IDE. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +POM_NAME = Android-ProgressSwitcher +POM_ARTIFACT_ID = progress-switcher +POM_PACKAGING = aar \ No newline at end of file diff --git a/library/libs/android-support-v4.jar b/library/libs/android-support-v4.jar deleted file mode 100644 index 6080877..0000000 Binary files a/library/libs/android-support-v4.jar and /dev/null differ diff --git a/library/project.properties b/library/project.properties index 4a46b9d..61afc8f 100644 --- a/library/project.properties +++ b/library/project.properties @@ -12,4 +12,4 @@ android.library=true # Project target. -target=android-17 +target=android-19 diff --git a/library/res/layout/fragment_progress.xml b/library/res/layout/fragment_progress.xml deleted file mode 100644 index d6ab2d4..0000000 --- a/library/res/layout/fragment_progress.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/res/layout/ps_empty_view.xml b/library/res/layout/ps_empty_view.xml new file mode 100644 index 0000000..317658d --- /dev/null +++ b/library/res/layout/ps_empty_view.xml @@ -0,0 +1,9 @@ + + diff --git a/library/res/layout/ps_error_view.xml b/library/res/layout/ps_error_view.xml new file mode 100644 index 0000000..7031eb8 --- /dev/null +++ b/library/res/layout/ps_error_view.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/library/res/layout/ps_progress_view.xml b/library/res/layout/ps_progress_view.xml new file mode 100644 index 0000000..d3f23e6 --- /dev/null +++ b/library/res/layout/ps_progress_view.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/library/res/layout/retry_button.xml b/library/res/layout/retry_button.xml new file mode 100644 index 0000000..e847881 --- /dev/null +++ b/library/res/layout/retry_button.xml @@ -0,0 +1,10 @@ + +