Android Open Source - RefreshActionItem Indeterminate Progress Activity






From Project

Back to project page RefreshActionItem.

License

The source code is released under:

Apache License

If you think the Android project RefreshActionItem 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 (C) 2013 Manuel Peinado// ww w .  j ava 2s.c  om
 *
 * 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 com.manuelpeinado.refreshactionitem.demo;

import java.util.Random;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;

import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.manuelpeinado.refreshactionitem.ProgressIndicatorType;
import com.manuelpeinado.refreshactionitem.RefreshActionItem;
import com.manuelpeinado.refreshactionitem.RefreshActionItem.RefreshActionListener;

public class IndeterminateProgressActivity extends SherlockListActivity implements RefreshActionListener {
    private RefreshActionItem mRefreshActionItem;
    private Random r = new Random();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indeterminate_progress);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.refresh, menu);
        MenuItem item = menu.findItem(R.id.refresh_button);
        mRefreshActionItem = (RefreshActionItem)item.getActionView();
        mRefreshActionItem.setMenuItem(item);
        mRefreshActionItem.setProgressIndicatorType(ProgressIndicatorType.INDETERMINATE);
        mRefreshActionItem.setRefreshActionListener(this);
        loadData();
        return true;
    }

    private void loadData() {
        mRefreshActionItem.showProgress(true);
        new Thread(new Runnable() {
            @Override public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                }
                runOnUiThread(new Runnable() {
                    @Override public void run() {
                        mRefreshActionItem.showProgress(false);
                        String[] items = generateRandomItemList();
                        setListAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1, items ));
                    }
                });
            }
            
        }).start();
    }

    private String[] generateRandomItemList() {
        String[] result = new String[100];
        for (int i = 0; i < result.length; ++i) {
            result[i] = Integer.toString(r.nextInt(1000)); 
        }
        return result;
    }

    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            Intent parentActivityIntent = new Intent(this, HomeActivity.class);
            parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(parentActivityIntent);
            finish();
            return true;
        }
        return false;
    }
    
    @Override
    public void onRefreshButtonClick(RefreshActionItem sender) {
        loadData();
    }
}




Java Source Code List

com.manuelpeinado.refreshactionitem.ProgressIndicatorType.java
com.manuelpeinado.refreshactionitem.ProgressIndicator.java
com.manuelpeinado.refreshactionitem.RefreshActionItem.java
com.manuelpeinado.refreshactionitem.demo.ActivityInfo.java
com.manuelpeinado.refreshactionitem.demo.BadgeActivity.java
com.manuelpeinado.refreshactionitem.demo.BasicUsageActivity.java
com.manuelpeinado.refreshactionitem.demo.HomeActivity.java
com.manuelpeinado.refreshactionitem.demo.IndeterminateProgressActivity.java
com.manuelpeinado.refreshactionitem.demo.StyledActivity.java
com.readystatesoftware.viewbadger.BadgeView.java
com.readystatesoftware.viewbadger.BadgeView.java