Android Open Source - SwipeRefreshLayout Demo Activity






From Project

Back to project page SwipeRefreshLayout.

License

The source code is released under:

GNU General Public License

If you think the Android project SwipeRefreshLayout listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
* Copyright 2013 The Android Open Source Project
*//  www. ja  v a2 s.  co  m
* 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.
*/


package reginald.swiperefresh.demo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import reginald.swiperefresh.view.CustomSwipeRefreshLayout;

/**
 * Created by tony.lxy on 2014/9/11.
 */

/**
 * One Sample activity that shows the features of CustomSwipeRefreshLayout
 */
public class DemoActivity extends Activity {

    public static final String TAG = "MainActivity";
    private CustomSwipeRefreshLayout mCustomSwipeRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "MainActivity.onCreate()");
        super.onCreate(savedInstanceState);
        CustomSwipeRefreshDemoView customSwipeRefreshDemoView = new CustomSwipeRefreshDemoView(getApplicationContext());
        mCustomSwipeRefreshLayout = customSwipeRefreshDemoView.getSwipeRefreshLayout();
        //show demo view
        setContentView(customSwipeRefreshDemoView);
    }


    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {

        menu.clear();
        menu.add(0, 1, 0, "swipe mode");
        menu.add(0, 2, 0, "pull mode");
        if (mCustomSwipeRefreshLayout.getRefreshMode() == CustomSwipeRefreshLayout.REFRESH_MODE_PULL) {
            menu.getItem(0).setEnabled(true);
            menu.getItem(1).setEnabled(false);
        } else {
            menu.getItem(0).setEnabled(false);
            menu.getItem(1).setEnabled(true);
        }

        if (mCustomSwipeRefreshLayout.getRefreshMode() == CustomSwipeRefreshLayout.REFRESH_MODE_PULL) {
            menu.add(1, 3, 0, "fixed refresh head");
            menu.add(1, 4, 0, "movable refresh head");
            if (mCustomSwipeRefreshLayout.isEnableTopRefreshingHead()) {
                menu.getItem(2).setEnabled(false);
                menu.getItem(3).setEnabled(true);
            } else {
                menu.getItem(2).setEnabled(true);
                menu.getItem(3).setEnabled(false);
            }
        }
        return true;
    }

    @Override
    /**
     * ??menu??????????????
     */
    public boolean onOptionsItemSelected(MenuItem item) {
        String text = "";
        switch (item.getItemId()) {
            case 1:
                mCustomSwipeRefreshLayout.setRefreshMode(CustomSwipeRefreshLayout.REFRESH_MODE_SWIPE);
                text = "swipe refresh mode";
                break;
            case 2:
                mCustomSwipeRefreshLayout.setRefreshMode(CustomSwipeRefreshLayout.REFRESH_MODE_PULL);
                text = "pull refresh mode";
                break;
            case 3:
                mCustomSwipeRefreshLayout.enableTopRefreshingHead(true);
                text = "fixed refreshing head";
                break;
            case 4:
                mCustomSwipeRefreshLayout.enableTopRefreshingHead(false);
                text = "movable refreshing head";
                break;
        }
        Toast.makeText(DemoActivity.this, text, Toast.LENGTH_SHORT).show();
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onStart() {
        Log.i(TAG, "MainActivity.onStart()");
        super.onStart();
    }

    @Override
    protected void onResume() {
        Log.i(TAG, "MainActivity.onResume()");
        super.onResume();
    }

    @Override
    protected void onPause() {
        Log.i(TAG, "MainActivity.onPause()");
        super.onPause();
    }

    @Override
    protected void onStop() {
        Log.i(TAG, "MainActivity.onStop()");
        super.onStop();
    }

}




Java Source Code List

reginald.swiperefresh.demo.CustomSwipeRefreshDemoView.java
reginald.swiperefresh.demo.DemoActivity.java
reginald.swiperefresh.demo.dummydata.Cheeses.java
reginald.swiperefresh.view.CustomInterpolator.java
reginald.swiperefresh.view.CustomSwipeProgressBar.java
reginald.swiperefresh.view.CustomSwipeRefreshHeadview.java
reginald.swiperefresh.view.CustomSwipeRefreshLayout.java
reginald.swiperefresh.view.DefaultCustomHeadViewLayout.java