Java tutorial
/** * technoXist * * Copyright (c) 2014 Suyash Bhatt * * Copyright (c) 2012-2013 Frederic Julian * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.technoxist.fragment; import android.app.Fragment; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public abstract class SwipeRefreshFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout mRefreshLayout; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRefreshLayout = new SwipeRefreshLayout(inflater.getContext()); inflateView(inflater, mRefreshLayout, savedInstanceState); return mRefreshLayout; } abstract public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRefreshLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_blue_dark, android.R.color.holo_blue_bright, android.R.color.holo_blue_dark); mRefreshLayout.setOnRefreshListener(this); } /** * It shows the SwipeRefreshLayout progress */ public void showSwipeProgress() { mRefreshLayout.setRefreshing(true); } /** * It shows the SwipeRefreshLayout progress */ public void hideSwipeProgress() { mRefreshLayout.setRefreshing(false); } /** * Enables swipe gesture */ public void enableSwipe() { mRefreshLayout.setEnabled(true); } /** * Disables swipe gesture. It prevents manual gestures but keeps the option tu show * refreshing programatically. */ public void disableSwipe() { mRefreshLayout.setEnabled(false); } /** * Get the refreshing status */ public boolean isRefreshing() { return mRefreshLayout.isRefreshing(); } }