Android Open Source - EBrowser History List Activity






From Project

Back to project page EBrowser.

License

The source code is released under:

GNU General Public License

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/*from  w w w.j a  v a  2s . co m*/
 * 
 * Copyright (C) 2010 - 2011 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.model.adapters.HistoryExpandableListAdapter;
import org.zirco.model.items.HistoryItem;
import org.zirco.providers.BookmarksProviderWrapper;
import org.zirco.ui.components.CustomWebView;
import org.zirco.utils.ApplicationUtils;
import org.zirco.utils.Constants;

import android.app.ExpandableListActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Browser;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.CompoundButton;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;

/**
 * history list activity.
 */
public class HistoryListActivity extends ExpandableListActivity {
  
  private static final int MENU_CLEAR_HISTORY = Menu.FIRST;
  
  private static final int MENU_OPEN_IN_TAB = Menu.FIRST + 10;
  private static final int MENU_COPY_URL = Menu.FIRST + 11;
  private static final int MENU_SHARE = Menu.FIRST + 12;
  private static final int MENU_DELETE_FROM_HISTORY = Menu.FIRST + 13;
  
  private ExpandableListAdapter mAdapter;
  
  private ProgressDialog mProgressDialog;
  
  private OnCheckedChangeListener mBookmarkStarChangeListener;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setTitle(R.string.HistoryListActivity_Title);
        
        registerForContextMenu(getExpandableListView());
        
        mBookmarkStarChangeListener = new OnCheckedChangeListener() {      
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                
        long id = (Long) buttonView.getTag();
        BookmarksProviderWrapper.toggleBookmark(getContentResolver(), id, isChecked);
        
        if (isChecked) {
          Toast.makeText(HistoryListActivity.this, R.string.HistoryListActivity_BookmarkAdded, Toast.LENGTH_SHORT).show();
        } else {
          Toast.makeText(HistoryListActivity.this, R.string.HistoryListActivity_BookmarkRemoved, Toast.LENGTH_SHORT).show();
        }
      }
    };
        
        fillData();
  }

  /**
   * Fill the history list.
   */
  private void fillData() {
    Cursor c = BookmarksProviderWrapper.getStockHistory(getContentResolver());
    
    mAdapter = new HistoryExpandableListAdapter(
        this,
        mBookmarkStarChangeListener,
        c,
        c.getColumnIndex(Browser.BookmarkColumns.DATE),
        ApplicationUtils.getFaviconSizeForBookmarks(this));
    
        setListAdapter(mAdapter);
        
        if (getExpandableListAdapter().getGroupCount() > 0) {
          getExpandableListView().expandGroup(0);
        }
  }
  
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    
    ExpandableListView.ExpandableListContextMenuInfo info =
      (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int child =  ExpandableListView.getPackedPositionChild(info.packedPosition);
    
    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
      
      HistoryItem item = (HistoryItem) getExpandableListAdapter().getChild(group, child);
      menu.setHeaderTitle(item.getTitle());
      
      menu.add(0, MENU_OPEN_IN_TAB, 0, R.string.HistoryListActivity_MenuOpenInTab);
      menu.add(0, MENU_COPY_URL, 0, R.string.BookmarksHistoryActivity_MenuCopyLinkUrl);
      menu.add(0, MENU_SHARE, 0, R.string.Main_MenuShareLinkUrl);
      menu.add(0, MENU_DELETE_FROM_HISTORY, 0, R.string.HistoryListActivity_MenuDelete);
    }
  }
  
  @Override
  public boolean onContextItemSelected(MenuItem menuItem) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
    
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    
    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
      int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
      int child =  ExpandableListView.getPackedPositionChild(info.packedPosition);
      
      HistoryItem item = (HistoryItem) getExpandableListAdapter().getChild(group, child);
      
      switch (menuItem.getItemId()) {
      case MENU_OPEN_IN_TAB:
        doNavigateToUrl(item.getUrl(), true);
        break;
      case MENU_COPY_URL:
        ApplicationUtils.copyTextToClipboard(this, item.getUrl(), getString(R.string.Commons_UrlCopyToastMessage));
        break;
      case MENU_SHARE:
        ApplicationUtils.sharePage(this, item.getTitle(), item.getUrl());
        break;
      case MENU_DELETE_FROM_HISTORY:
        BookmarksProviderWrapper.deleteHistoryRecord(getContentResolver(), item.getId());
        fillData();
        break;
      default:
        break;
      }
    }
    
    return super.onContextItemSelected(menuItem);
  }
  
  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      super.onCreateOptionsMenu(menu);
      
      MenuItem item;
      item = menu.add(0, MENU_CLEAR_HISTORY, 0, R.string.Commons_ClearHistory);
        item.setIcon(R.drawable.ic_menu_delete);
        
        return true;
  }
  
  @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
    
    switch(item.getItemId()) {
    case MENU_CLEAR_HISTORY:
          clearHistory();
          return true;
        default: return super.onMenuItemSelected(featureId, item);
    }
  }
  
  @Override
  public boolean onChildClick(ExpandableListView parent, View v,  int groupPosition, int childPosition, long id) {
    HistoryItem item = (HistoryItem) getExpandableListAdapter().getChild(groupPosition, childPosition);
        doNavigateToUrl(item.getUrl(), false);
        
    return super.onChildClick(parent, v, groupPosition, childPosition, id);
  }
  
  /**
   * Load the given url.
   * @param url The url.
   * @param newTab If True, will open a new tab. If False, the current tab is used.
   */
  private void doNavigateToUrl(String url, boolean newTab) {
    Intent result = new Intent();
        result.putExtra(Constants.EXTRA_ID_NEW_TAB, newTab);
        result.putExtra(Constants.EXTRA_ID_URL,  url);
        
        if (getParent() != null) {
          getParent().setResult(RESULT_OK, result);
        } else {
          setResult(RESULT_OK, result);
        }
        finish();
  }

  /**
   * Clear history.
   */
  private void doClearHistory() {
      mProgressDialog = ProgressDialog.show(this,
          this.getResources().getString(R.string.Commons_PleaseWait),
          this.getResources().getString(R.string.Commons_ClearingHistory));
      
      new HistoryClearer();
    }
  
  /**
   * Display confirmation and clear history.
   */
  private void clearHistory() {
    ApplicationUtils.showYesNoDialog(this,
        android.R.drawable.ic_dialog_alert,
        R.string.Commons_ClearHistory,
        R.string.Commons_NoUndoMessage,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
              doClearHistory();
          }      
    });
    }
  
  /**
   * Runnable to clear history.
   */
  private class HistoryClearer implements Runnable {

    /**
     * Constructor.
     */
    public HistoryClearer() {
      new Thread(this).start();
    }

    @Override
    public void run() {
      BookmarksProviderWrapper.clearHistoryAndOrBookmarks(getContentResolver(), true, false);
      
      for (CustomWebView webView : Controller.getInstance().getWebViewList()) {
        webView.clearHistory();
      }
      
      handler.sendEmptyMessage(0);
    }

    private Handler handler = new Handler() {
      public void handleMessage(Message msg) {
        mProgressDialog.dismiss();
        fillData();
      }
    };
  }
  
}




Java Source Code List

org.emergent.android.weave.client.Base32.java
org.emergent.android.weave.client.Base64Encoder.java
org.emergent.android.weave.client.Base64.java
org.emergent.android.weave.client.BulkKeyCouplet.java
org.emergent.android.weave.client.Dbg.java
org.emergent.android.weave.client.HexEncoder.java
org.emergent.android.weave.client.Hex.java
org.emergent.android.weave.client.QueryParams.java
org.emergent.android.weave.client.QueryResult.java
org.emergent.android.weave.client.UserWeave.java
org.emergent.android.weave.client.WeaveAccountInfo.java
org.emergent.android.weave.client.WeaveBasicObject.java
org.emergent.android.weave.client.WeaveConstants.java
org.emergent.android.weave.client.WeaveCryptoUtil.java
org.emergent.android.weave.client.WeaveException.java
org.emergent.android.weave.client.WeaveFactory.java
org.emergent.android.weave.client.WeaveHeader.java
org.emergent.android.weave.client.WeaveResponse.java
org.emergent.android.weave.client.WeaveSSLSocketFactory.java
org.emergent.android.weave.client.WeaveTransport.java
org.emergent.android.weave.client.WeaveUtil.java
org.greendroid.QuickActionGrid.java
org.greendroid.QuickActionWidget.java
org.greendroid.QuickAction.java
org.zirco.controllers.Controller.java
org.zirco.events.EventConstants.java
org.zirco.events.EventController.java
org.zirco.events.IDownloadEventsListener.java
org.zirco.model.DbAdapter.java
org.zirco.model.UrlSuggestionItemComparator.java
org.zirco.model.adapters.BookmarksCursorAdapter.java
org.zirco.model.adapters.DownloadListAdapter.java
org.zirco.model.adapters.HistoryExpandableListAdapter.java
org.zirco.model.adapters.UrlSuggestionCursorAdapter.java
org.zirco.model.adapters.WeaveBookmarksCursorAdapter.java
org.zirco.model.items.BookmarkItem.java
org.zirco.model.items.DownloadItem.java
org.zirco.model.items.HistoryItem.java
org.zirco.model.items.UrlSuggestionItem.java
org.zirco.model.items.WeaveBookmarkItem.java
org.zirco.providers.BookmarksProviderWrapper.java
org.zirco.providers.WeaveColumns.java
org.zirco.providers.WeaveContentProvider.java
org.zirco.providers.ZircoBookmarksContentProvider.java
org.zirco.sync.ISyncListener.java
org.zirco.sync.WeaveSyncTask.java
org.zirco.ui.activities.AboutActivity.java
org.zirco.ui.activities.AdBlockerWhiteListActivity.java
org.zirco.ui.activities.BookmarksHistoryActivity.java
org.zirco.ui.activities.BookmarksListActivity.java
org.zirco.ui.activities.ChangelogActivity.java
org.zirco.ui.activities.DownloadsListActivity.java
org.zirco.ui.activities.EditBookmarkActivity.java
org.zirco.ui.activities.HistoryListActivity.java
org.zirco.ui.activities.IToolbarsContainer.java
org.zirco.ui.activities.MainActivity.java
org.zirco.ui.activities.MobileViewListActivity.java
org.zirco.ui.activities.WeaveBookmarksListActivity.java
org.zirco.ui.activities.preferences.BaseSpinnerCustomPreferenceActivity.java
org.zirco.ui.activities.preferences.HomepagePreferenceActivity.java
org.zirco.ui.activities.preferences.PreferencesActivity.java
org.zirco.ui.activities.preferences.SearchUrlPreferenceActivity.java
org.zirco.ui.activities.preferences.UserAgentPreferenceActivity.java
org.zirco.ui.activities.preferences.WeavePreferencesActivity.java
org.zirco.ui.activities.preferences.WeaveServerPreferenceActivity.java
org.zirco.ui.components.CustomWebViewClient.java
org.zirco.ui.components.CustomWebView.java
org.zirco.ui.runnables.DownloadRunnable.java
org.zirco.ui.runnables.FaviconUpdaterRunnable.java
org.zirco.ui.runnables.HideToolbarsRunnable.java
org.zirco.ui.runnables.HistoryUpdater.java
org.zirco.ui.runnables.XmlHistoryBookmarksExporter.java
org.zirco.ui.runnables.XmlHistoryBookmarksImporter.java
org.zirco.utils.AnimationManager.java
org.zirco.utils.ApplicationUtils.java
org.zirco.utils.Constants.java
org.zirco.utils.DateUtils.java
org.zirco.utils.IOUtils.java
org.zirco.utils.ProxyChangeReceiver.java
org.zirco.utils.ProxySettings.java
org.zirco.utils.UrlUtils.java