If you think the Android project EBrowser 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
/*
* Zirco Browser for Android/*www.java2s.com*/
*
* Copyright (C) 2010 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* 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.
*/package org.zirco.ui.activities;
import com.mrpej.ebrowser.R;
import org.zirco.controllers.Controller;
import org.zirco.events.EventConstants;
import org.zirco.events.EventController;
import org.zirco.events.IDownloadEventsListener;
import org.zirco.model.adapters.DownloadListAdapter;
import org.zirco.model.items.DownloadItem;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
* Download list activity.
*/publicclass DownloadsListActivity extends ListActivity implements IDownloadEventsListener {
privatestaticfinalint MENU_CLEAR_DOWNLOADS = Menu.FIRST;
private DownloadListAdapter mAdapter;
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.downloads_list_activity);
setTitle(R.string.DownloadListActivity_Title);
EventController.getInstance().addDownloadListener(this);
fillData();
}
@Override
protectedvoid onDestroy() {
EventController.getInstance().removeDownloadListener(this);
super.onDestroy();
}
@Override
publicboolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem item = menu.add(0, MENU_CLEAR_DOWNLOADS, 0, R.string.DownloadListActivity_RemoveCompletedDownloads);
item.setIcon(R.drawable.ic_menu_delete);
return true;
}
@Override
publicboolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case MENU_CLEAR_DOWNLOADS:
Controller.getInstance().clearCompletedDownloads();
fillData();
return true;
default: return super.onMenuItemSelected(featureId, item);
}
}
/**
* Fill the download list.
*/privatevoid fillData() {
mAdapter = new DownloadListAdapter(this, Controller.getInstance().getDownloadList());
setListAdapter(mAdapter);
}
@Override
publicvoid onDownloadEvent(String event, Object data) {
if (event.equals(EventConstants.EVT_DOWNLOAD_ON_START)) {
fillData();
} elseif (event.equals(EventConstants.EVT_DOWNLOAD_ON_PROGRESS)) {
if (data != null) {
DownloadItem item = (DownloadItem) data;
ProgressBar bar = mAdapter.getBarMap().get(item);
if (bar != null) {
bar.setMax(100);
bar.setProgress(item.getProgress());
}
}
} elseif (event.equals(EventConstants.EVT_DOWNLOAD_ON_FINISHED)) {
if (data != null) {
DownloadItem item = (DownloadItem) data;
TextView title = mAdapter.getTitleMap().get(item);
if (title != null) {
if (item.isAborted()) {
title.setText(String.format(getResources().getString(R.string.DownloadListActivity_Aborted), item.getFileName()));
} else {
title.setText(String.format(getResources().getString(R.string.DownloadListActivity_Finished), item.getFileName()));
}
}
ProgressBar bar = mAdapter.getBarMap().get(item);
if (bar != null) {
bar.setProgress(bar.getMax());
}
ImageButton button = mAdapter.getButtonMap().get(item);
if (button != null) {
button.setEnabled(false);
}
}
}
}
}