Permalink
Browse files

Rotate refresh icon in Action Bar while loading things.

This implementation contributed by Eddie Ringle

#13

This reverts commit 6081dfb.
  • Loading branch information...
1 parent 6081dfb commit 1bd4883307c6cdaa7fdfe40d4405894688112956 @rtyley rtyley committed Mar 5, 2012
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright 2012 GitHub Inc.
+ ~
+ ~ 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.
+ -->
+
+<rotate xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fromDegrees="0"
+ android:toDegrees="360"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:duration="1000"
+ android:interpolator="@android:anim/linear_interpolator" />
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright 2012 GitHub Inc.
+ ~
+ ~ 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.
+ -->
+
+<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ic_action_refresh"
+ style="@style/Widget.Sherlock.ActionButton" />
@@ -16,17 +16,23 @@
package com.github.mobile.gauges.ui;
+import static android.view.animation.Animation.INFINITE;
import static com.github.mobile.gauges.ui.ToastUtil.toastOnUiThread;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
+import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
+import com.github.mobile.gauges.R.anim;
import com.github.mobile.gauges.R.id;
+import com.github.mobile.gauges.R.layout;
import com.github.mobile.gauges.R.menu;
import com.madgag.android.listviews.ViewHoldingListAdapter;
@@ -41,6 +47,8 @@
*/
public abstract class ListLoadingFragment<E> extends RoboListFragment implements LoaderCallbacks<List<E>> {
+ private MenuItem refreshItem;
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -63,6 +71,7 @@ public void onCreateOptionsMenu(Menu optionsMenu, MenuInflater inflater) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case id.refresh:
+ refreshItem = item;
refresh();
return true;
default:
@@ -74,8 +83,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
* Refresh the fragment's list
*/
public void refresh() {
- if (getActivity() != null)
- getLoaderManager().restartLoader(0, null, this);
+ final Activity activity = getActivity();
+ if(activity == null)
+ return;
+
+ /* Attach a rotating ImageView to the refresh item as an ActionView */
+ View iv = activity.getLayoutInflater().inflate(layout.refresh_action_view, null);
+
+ Animation rotation = AnimationUtils.loadAnimation(activity, anim.clockwise_refresh);
+ rotation.setRepeatCount(INFINITE);
+ iv.startAnimation(rotation);
+
+ refreshItem.setActionView(iv);
+
+ getLoaderManager().restartLoader(0, null, this);
}
public void onLoadFinished(Loader<List<E>> loader, List<E> items) {
@@ -85,6 +106,11 @@ public void onLoadFinished(Loader<List<E>> loader, List<E> items) {
setListShown(true);
else
setListShownNoAnimation(true);
+
+ if (refreshItem != null && refreshItem.getActionView() != null) {
+ refreshItem.getActionView().clearAnimation();
+ refreshItem.setActionView(null);
+ }
}
/**

0 comments on commit 1bd4883

Please sign in to comment.