package com.marshalchen.common.usefulModule;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.marshalchen.common.R;
/**
* Created by cym on 14-9-11.
*/
public abstract class AbstractSwipeRefreshLoadMoreActivity extends ActionBarActivity implements SwipeRefreshLayout.OnRefreshListener {
protected SwipeRefreshLayout refreshLayout;
protected RelativeLayout swipeReaLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.swipe_refresh_list_more_layout);
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeReaLayout = (RelativeLayout) findViewById(R.id.swipeReaLayout);
}
@Override
public void setContentView(int layoutResID) {
View v = getLayoutInflater().inflate(layoutResID, refreshLayout, false);
setContentView(v);
}
@Override
public void setContentView(View view) {
setContentView(view, view.getLayoutParams());
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
swipeReaLayout.addView(view, params);
initSwipeOptions();
}
private void initSwipeOptions() {
refreshLayout.setOnRefreshListener(this);
setAppearance();
disableSwipe();
}
private void setAppearance() {
refreshLayout.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}
/**
* It shows the SwipeRefreshLayout progress
*/
public void showSwipeProgress() {
refreshLayout.setRefreshing(true);
}
/**
* It shows the SwipeRefreshLayout progress
*/
public void hideSwipeProgress() {
refreshLayout.setRefreshing(false);
}
/**
* Enables swipe gesture
*/
public void enableSwipe() {
refreshLayout.setEnabled(true);
}
/**
* Disables swipe gesture. It prevents manual gestures but keeps the option tu show
* refreshing programatically.
*/
public void disableSwipe() {
refreshLayout.setEnabled(false);
}
/**
* It must be overriden by parent classes if manual swipe is enabled.
*/
@Override
public void onRefresh() {
// Empty implementation
}
}