Giter Site home page Giter Site logo

johnkil / android-progressfragment Goto Github PK

View Code? Open in Web Editor NEW
808.0 48.0 217.0 2.54 MB

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

Home Page: http://johnkil.github.io/Android-ProgressFragment/

License: Apache License 2.0

Java 100.00%
android fragment progress

android-progressfragment's Introduction

Android-ProgressFragment

Android Arsenal

Implementation of the fragment with the ability to display indeterminate progress indicator when you are waiting for the initial data. Based on ListFragment.

Sample

A sample application is available on Google Play:

Get it on Google Play

screenshot

Compatibility

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

Usage

To display the progress fragment you need the following code:

  • Create your implementation of progress fragment
public class MyProgressFragment extends ProgressFragment {
	// your code of fragment
}

or if you use ActionBarSherlock

public class MyProgressFragment extends SherlockProgressFragment {
	// your code of fragment
}
  • Setup content view and empty text (optional) in onActivityCreate() method.
@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);
    // ...
}
  • Display of indeterminate progress indicator
setContentShown(false);
  • When the data is loaded to set whether the content is empty and show content
setContentEmpty(/* true if content is empty else false */);
setContentShown(true);

Gradle

Android-ProgressFragment library is now pushed to Maven Central as a AAR, so you just need to add the following dependency to your build.gradle.

ProgressFragment (support-v4):

dependencies {
    compile 'com.github.johnkil.android-progressfragment:progressfragment:1.4.+'
}

ProgressFragment (native):

dependencies {
    compile 'com.github.johnkil.android-progressfragment:progressfragment-native:1.4.+'
}

SherlockProgressFragment:

dependencies {
    compile 'com.android.support:support-v4:19.0.0'
    compile('com.github.johnkil.android-progressfragment:sherlockprogressfragment:1.4.+') {
        exclude module: 'support-v4'
    }
}

Example Gradle project using Android-ProgressFragment:

Developed By

License

Copyright 2013 Evgeny Shishkin

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.

android-progressfragment's People

Contributors

hameno avatar johnkil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-progressfragment's Issues

java.lang.IllegalStateException

java.lang.IllegalStateException: Content view not yet created
at com.devspark.progressfragment.ProgressFragment.ensureContent(ProgressFragment.java:270)
at com.devspark.progressfragment.ProgressFragment.setContentShown(ProgressFragment.java:200)
at com.devspark.progressfragment.ProgressFragment.setContentShown(ProgressFragment.java:174)
at com.devspark.progressfragment.sample.DefaultProgressFragment$1.run(DefaultProgressFragment.java:36)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

Failed build for minSdkVersion=4

Thank you for this useful library.

But I have faced the issue when I try to build your sample application. It is impossible to build sample application with minSdkVersion set to "4". Could you please change sample application code to met Android-ProgressFragment library requirements (I mean minSdkVersion="4")? Thank you.

Obtain data process restarted on configuration changed

Obtain data process restarted on any configuration changed event, for example on device rotation.
Looks like this issue is very serious. It may prevent to use this library for Activities which starting time depends on network requests.

java.lang.NullPointerException

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.devspark.progressfragment.sample/com.devspark.progressfragment.sample.ProgressActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
at android.app.ActivityThread.access$1500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4028)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.devspark.progressfragment.sample.ProgressActivity$ActionBarHelper.setDisplayHomeAsUpEnabled(ProgressActivity.java:96)
at com.devspark.progressfragment.sample.ProgressActivity$ActionBarHelper.access$1(ProgressActivity.java:95)
at com.devspark.progressfragment.sample.ProgressActivity.onCreate(ProgressActivity.java:42)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
... 11 more

Tons of ProgressFragment.ensureContent errors

Sometimes i get tons of error feedbacks from my users about the lib.

java.lang.IllegalStateException: Content view not yet created
at com.devspark.progressfragment.ProgressFragment.ensureContent(ProgressFragment.java:273)
at com.devspark.progressfragment.ProgressFragment.setContentEmpty(ProgressFragment.java:250)

My fragments like;
public class BusListFragment extends ProgressFragment {
private Context context;
private CardRecyclerView cardRecyclerView;
private View rootView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    setRetainInstance(true);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_mycards, container, false);
    context = getActivity();
    cardRecyclerView = (CardRecyclerView) rootView.findViewById(R.id.cardRecyclerView);
    return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setContentView(rootView);
    if (stopId != null && location != null) {
        new getClosestBusListAsync(this).execute();
    }
}

}
and the task is like;
public class getClosestStopListAsync extends AsyncTask<Void, Void, String> {
ProgressFragment fragment;
Context context;
GoogleMap map;
LatLng location;

public getClosestStopListAsync(ProgressFragment fragment, LatLng location, GoogleMap map) {
    this.fragment = fragment;
    this.context = fragment.getActivity();
    this.location = location;
    this.map = map;
}

@Override
protected String doInBackground(Void... args0) {
    return new RequestHelper().getClosestStopList(PreferenceHelper.getCity(context), location.latitude, location.longitude);
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
    if (result != null) {
        map.clear();

        BusStop stopList = JsonHelper.getClosestStopList(result);
        if (stopList != null) {
            if (stopList.getResult().getCode().equals("0")) {
                if (stopList != null || stopList.getBusStopList().size() > 0) {
                    for (BusStop.BusStopItem busStop : stopList.getBusStopList()) {
                        map.addMarker(new MarkerOptions()
                                .position(new LatLng(Double.parseDouble(busStop.getLatitude()), Double.parseDouble(busStop.getLongitude())))
                                .title(busStop.getStopId() + " - " + busStop.getStopName() + " - " + busStop.getType())
                                .snippet(busStop.getRoutes())
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.stop)));
                    }
                    fragment.setContentEmpty(false);
                } else {
                    fragment.setContentEmpty(true);
                    fragment.setEmptyText(R.string.empty_list);
                }
            }
        }
        System.gc();
        fragment.setContentShown(true);
    }
}

}

how can it be possible that content view not yet created? OnActivityCreated is called after OnCreateView so that means views could be created?

How can i fix this issue? Thanks.

How to close the NavigationDrawerFragment on startup?

Hello first i will like to say that you have don a great job. second ii'm having an issue with the library. i have added it in my fragment but every time that i start the app it shows the mNavigationDrawerFragment open. how i can close it when the app it loads? thank you

java.lang.RuntimeException: Your content must have a ViewGroup whose id attribute is 'R.id.progress_container'

Dear johnkil,
firstly compliments for great work.
I'm try to use your library (SherlockProgressFragment). I've follow your guide, but when i click for show fragment i've the error as issue title:

java.lang.RuntimeException: Your content must have a ViewGroup whose id attribute is 'R.id.progress_container'

I've include your fragment_custom_progress into my layout...where are my errors?

Thanks and Best Regards

listview isn't showing with ProgressFragment

Hey, firstly nice work with the fragment! It is really helpful.

However, I want to ask why is my listview not showing up when extending ProgressFragment? I can't use a ListFragment as I have 2 listviews in that view, and it's rather a customised fragment..

Support for DialogFragments

It would be great to have base classes who's parents were either
DialogFragment
or
SherlockDialogFragment

It shouldn't require any real changes to how things work.

java.lang.NullPointerException on mHandler.removeCallbacks(mShowContentRunnable);

I have an issue when i'm moving from the portrait mode to landscape mode on mHandler.removeCallbacks(mShowContentRunnable);
the onDestroyView is under a class that extends ProgressFragment
How i can fix it?

@Override
public void onDestroyView() {
    super.onDestroyView();
    mHandler.removeCallbacks(mShowContentRunnable);
}

Here my error log
02-27 20:30:44.474: E/AndroidRuntime(19930): FATAL EXCEPTION: main
02-27 20:30:44.474: E/AndroidRuntime(19930): Process: com.georgiospanayi.cyprusshots, PID: 19930
02-27 20:30:44.474: E/AndroidRuntime(19930): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.georgiospanayi.cyprusshots/com.georgiospanayi.cyprusshots.HomeActivity}: java.lang.NullPointerException
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3738)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread.access$900(ActivityThread.java:135)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.os.Handler.dispatchMessage(Handler.java:102)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.os.Looper.loop(Looper.java:136)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-27 20:30:44.474: E/AndroidRuntime(19930): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 20:30:44.474: E/AndroidRuntime(19930): at java.lang.reflect.Method.invoke(Method.java:515)
02-27 20:30:44.474: E/AndroidRuntime(19930): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-27 20:30:44.474: E/AndroidRuntime(19930): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-27 20:30:44.474: E/AndroidRuntime(19930): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
02-27 20:30:44.474: E/AndroidRuntime(19930): at dalvik.system.NativeStart.main(Native Method)
02-27 20:30:44.474: E/AndroidRuntime(19930): Caused by: java.lang.NullPointerException
02-27 20:30:44.474: E/AndroidRuntime(19930): at com.georgiospanayi.fragments.PlaceholderFragment.onDestroyView(PlaceholderFragment.java:177)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.support.v4.app.Fragment.performDestroyView(Fragment.java:1705)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:996)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1201)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:639)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.Activity.performStart(Activity.java:5241)
02-27 20:30:44.474: E/AndroidRuntime(19930): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
02-27 20:30:44.474: E/AndroidRuntime(19930): ... 13 more

About the frameLayout

Why do you use the FrameLayout to contain the ImageView like this:

 <FrameLayout
        android:id="@+id/content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
                android:id="@android:id/empty"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceLarge"/>
</FrameLayout>

Is it necessary? Can I remove the FrameLayout ?

Support native fragments

This fragments use Fragment provided by support libraries.

Do you have a plan to provide classes with native Fragment?

Ability to not use setContentView

Since I was using this library, I was not happy with the setContentView method. It is because it is not similar to the methods you would use when you normalle use Fragments.

When I use ProgressListFragment it is like magic. Even when I use custom layout in the onCreateView it gets the ListView and does all the magic automatically.

Here is the solution in my mind. I hope I can tell it well.
If you have a FrameLayout in the content_container FrameLayout on top of the emptyView. You can use that id as a mContentView. When developer use custom layout in onCreateView and have a view with that id, you can use it right away. If the developer don't have a view with that id, you can expect usage of setContentView. If the developer doesn't do any of that, you can throw a IllegalStateException.

What do you think? Sorry if the English is not good.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.