Commit 0d5a8fdb authored by Roger Barton's avatar Roger Barton
Browse files

Added amiv theme to swipe refresh UI, animation not clean yet

animation needs to repeat, end anim is skipped
parent b56f5315
package ch.amiv.android_app.checkin;
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
......@@ -8,6 +9,10 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import com.google.zxing.BarcodeFormat;
......@@ -47,23 +52,43 @@ public class BarcodeIdActivity extends AppCompatActivity {
}
});
//Setup swipe down to refresh
InitSwipeRefreshUI();
}
//Setup swipe down to refresh, adds the amiv logo and rotate animation
private void InitSwipeRefreshUI()
{
swipeRefreshLayout = findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setRefreshing(true);
//swipeRefreshLayout.setRefreshing(true);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { //This sets what function is called when we swipe down to refresh
@Override
public void onRefresh() {
GenerateBarcode();
try {
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
f.setAccessible(true);
ImageView img = (ImageView)f.get(swipeRefreshLayout);
RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setRepeatMode(Animation.INFINITE);
rotate.setDuration(1000);
rotate.setInterpolator(new LinearInterpolator());
img.startAnimation(rotate);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
//Change the image on the swipe to refresh icon. Unfortunately have not found a way to make the icon rotate, may have to create overriden class
try {
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
f.setAccessible(true);
ImageView img = (ImageView)f.get(swipeRefreshLayout);
img.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_amiv_logo_icon_scaled, null));
swipeRefreshLayout.setColorSchemeResources(R.color.refresh_progress_1, R.color.refresh_progress_2, R.color.refresh_progress_3);
img.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_amiv_logo_icon_scaled, null));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
......
......@@ -7,6 +7,7 @@ import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
......@@ -14,7 +15,13 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import java.lang.reflect.Field;
import ch.amiv.android_app.R;
import ch.amiv.android_app.events.EventsListAdapter;
......@@ -95,30 +102,10 @@ public class ListFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
swipeRefreshLayout = getView().findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if(pagePosition == PageType.EVENTS)
Requests.FetchEventList(MainActivity.instance, onEventsListUpdatedCallback, cancelRefreshCallback, "");
else if (pagePosition == PageType.JOBS)
Requests.FetchJobList(MainActivity.instance, onJobsListUpdatedCallback, cancelRefreshCallback, "");
}
});
//refresh on activity start
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
if(pagePosition == PageType.EVENTS) {
SetRefreshUI(true);
Requests.FetchEventList(MainActivity.instance, onEventsListUpdatedCallback, cancelRefreshCallback, "");
}
else if(pagePosition == PageType.JOBS){
SetRefreshUI(true);
Requests.FetchJobList(MainActivity.instance, onJobsListUpdatedCallback, cancelRefreshCallback, "");
}
}
});
InitSwipeRefreshUI();
//refresh on activity start
SetRefreshUI(true);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
......@@ -156,6 +143,55 @@ public class ListFragment extends Fragment {
RefreshList(true);
}
//Setup swipe down to refresh, adds the amiv logo and rotate animation
private void InitSwipeRefreshUI()
{
//Set on resfresh functionality
swipeRefreshLayout = getView().findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { //This sets what function is called when we swipe down to refresh
@Override
public void onRefresh() {
OnSwipeRefreshed();
try {
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
f.setAccessible(true);
ImageView img = (ImageView)f.get(swipeRefreshLayout);
RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setRepeatMode(Animation.INFINITE);
rotate.setDuration(1000);
rotate.setRepeatCount(5);
rotate.setInterpolator(new LinearInterpolator());
img.startAnimation(rotate);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
//Set Image of swipe refresh
try {
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
f.setAccessible(true);
ImageView img = (ImageView)f.get(swipeRefreshLayout);
img.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_amiv_logo_icon_scaled, null));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private void OnSwipeRefreshed(){
if(pagePosition == PageType.EVENTS)
Requests.FetchEventList(MainActivity.instance, onEventsListUpdatedCallback, cancelRefreshCallback, "");
else if (pagePosition == PageType.JOBS)
Requests.FetchJobList(MainActivity.instance, onJobsListUpdatedCallback, cancelRefreshCallback, "");
}
public void RefreshList(boolean animate)
{
if(recyclerAdapter == null)
......
......@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
......@@ -13,6 +14,9 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
......@@ -32,6 +36,7 @@ import com.google.gson.JsonObject;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
......@@ -185,17 +190,56 @@ public class EventDetailActivity extends AppCompatActivity {
posterBg = findViewById(R.id.posterBg);
registerButton = findViewById(R.id.registerButton);
InitSwipeRefreshUI();
SetUIDirty(false, false);
}
//Setup swipe down to refresh, adds the amiv logo and rotate animation
private void InitSwipeRefreshUI()
{
//Set on resfresh functionality
swipeRefreshLayout = findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { //This sets what function is called when we swipe down to refresh
@Override
public void onRefresh() {
if(!hasEvent())
return;
Requests.FetchEventList(getApplicationContext(), onEventsListUpdatedCallback, cancelRefreshCallback, event()._id);
OnSwipeRefreshed();
try {
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
f.setAccessible(true);
ImageView img = (ImageView)f.get(swipeRefreshLayout);
RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setRepeatMode(Animation.INFINITE);
rotate.setDuration(1000);
rotate.setInterpolator(new LinearInterpolator());
img.startAnimation(rotate);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
SetUIDirty(false, false);
//Set Image of swipe refresh
try {
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
f.setAccessible(true);
ImageView img = (ImageView)f.get(swipeRefreshLayout);
img.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_amiv_logo_icon_scaled, null));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private void OnSwipeRefreshed(){
if(!hasEvent())
return;
Requests.FetchEventList(getApplicationContext(), onEventsListUpdatedCallback, cancelRefreshCallback, event()._id);
}
public void SetUIDirty(boolean isRefreshing, boolean signupUpdated)
......
......@@ -36,7 +36,8 @@ import ch.amiv.android_app.jobs.Jobs;
import static android.content.Context.MODE_PRIVATE;
/**
*
* Use this class to save data between sessions, data is saved in the private sharedpreferences in a json form as a string
* You can see what is stored by opening the device file explorer, navigate to data/data/ch.amiv.android_app/shared_prefs/ch.amiv.android_app.xml
*/
public final class PersistentStorage {
private static SharedPreferences prefs;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment