FileDocCategorySizeDatePackage
BrowserHistoryPage.javaAPI DocAndroid 1.5 API17139Wed May 06 22:42:42 BST 2009com.android.browser

BrowserHistoryPage

public class BrowserHistoryPage extends android.app.ExpandableListActivity
Activity for displaying the browser's history, divided into days of viewing.

Fields Summary
private HistoryAdapter
mAdapter
private android.webkit.DateSorter
mDateSorter
private boolean
mMaxTabsOpen
private static final String
LOGTAG
private final IconReceiver
mIconReceiver
Constructors Summary
Methods Summary
private voidcopy(java.lang.CharSequence text)

        try {
            IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard"));
            if (clip != null) {
                clip.setClipboardText(text);
            }
        } catch (android.os.RemoteException e) {
            Log.e(LOGTAG, "Copy failed", e);
        }
    
private voidloadUrl(java.lang.String url, boolean newWindow)
Report back to the calling activity to load a site.

param
url Site to load.
param
newWindow True if the URL should be loaded in a new window


                                       
          
        Intent intent = new Intent().setAction(url);
        if (newWindow) {
            Bundle b = new Bundle();
            b.putBoolean("new_window", true);
            intent.putExtras(b);
        }
        setResultToParent(RESULT_OK, intent);
        finish();
    
public booleanonChildClick(android.widget.ExpandableListView parent, android.view.View v, int groupPosition, int childPosition, long id)

        if (v instanceof HistoryItem) {
            loadUrl(((HistoryItem) v).getUrl(), false);
            return true;
        }
        return false;
    
public booleanonContextItemSelected(android.view.MenuItem item)

        ExpandableListContextMenuInfo i = 
            (ExpandableListContextMenuInfo) item.getMenuInfo();
        String url = ((HistoryItem)i.targetView).getUrl();
        String title = ((HistoryItem)i.targetView).getName();
        switch (item.getItemId()) {
            case R.id.open_context_menu_id:
                loadUrl(url, false);
                return true;
            case R.id.new_window_context_menu_id:
                loadUrl(url, true);
                return true;
            case R.id.save_to_bookmarks_menu_id:
                Browser.saveBookmark(this, title, url);
                return true;
            case R.id.share_link_context_menu_id:
                Browser.sendString(this, url);
                return true;
            case R.id.copy_context_menu_id:
                copy(url);
                return true;
            case R.id.delete_context_menu_id:
                Browser.deleteFromHistory(getContentResolver(), url);
                mAdapter.refreshData();
                return true;
            default:
                break;
        }
        return super.onContextItemSelected(item);
    
protected voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        setTitle(R.string.browser_history);
        
        mDateSorter = new DateSorter(this);

        mAdapter = new HistoryAdapter();
        setListAdapter(mAdapter);
        final ExpandableListView list = getExpandableListView();
        list.setOnCreateContextMenuListener(this);
        LayoutInflater factory = LayoutInflater.from(this);
        View v = factory.inflate(R.layout.empty_history, null);
        addContentView(v, new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT));
        list.setEmptyView(v);
        // Do not post the runnable if there is nothing in the list.
        if (list.getExpandableListAdapter().getGroupCount() > 0) {
            list.post(new Runnable() {
                public void run() {
                    // In case the history gets cleared before this event
                    // happens.
                    if (list.getExpandableListAdapter().getGroupCount() > 0) {
                        list.expandGroup(0);
                    }
                }
            });
        }
        mMaxTabsOpen = getIntent().getBooleanExtra("maxTabsOpen", false);
        CombinedBookmarkHistoryActivity.getIconListenerSet(getContentResolver())
                .addListener(mIconReceiver);
        
        // initialize the result to canceled, so that if the user just presses
        // back then it will have the correct result
        setResultToParent(RESULT_CANCELED, null);
    
public voidonCreateContextMenu(android.view.ContextMenu menu, android.view.View v, android.view.ContextMenu.ContextMenuInfo menuInfo)

        ExpandableListContextMenuInfo i = 
            (ExpandableListContextMenuInfo) menuInfo;
        // Do not allow a context menu to come up from the group views.
        if (!(i.targetView instanceof HistoryItem)) {
            return;
        }

        // Inflate the menu
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.historycontext, menu);

        // Setup the header
        menu.setHeaderTitle(((HistoryItem)i.targetView).getUrl());

        // Only show open in new tab if we have not maxed out available tabs
        menu.findItem(R.id.new_window_context_menu_id).setVisible(!mMaxTabsOpen);
        
        // decide whether to show the share link option
        PackageManager pm = getPackageManager();
        Intent send = new Intent(Intent.ACTION_SEND);
        send.setType("text/plain");
        ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY);
        menu.findItem(R.id.share_link_context_menu_id).setVisible(ri != null);
        
        super.onCreateContextMenu(menu, v, menuInfo);
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.history, menu);
        return true;
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        switch (item.getItemId()) {
            case R.id.clear_history_menu_id:
                // FIXME: Need to clear the tab control in browserActivity 
                // as well
                Browser.clearHistory(getContentResolver());
                mAdapter.refreshData();
                return true;
                
            default:
                break;
        }  
        return super.onOptionsItemSelected(item);
    
public booleanonPrepareOptionsMenu(android.view.Menu menu)

        menu.findItem(R.id.clear_history_menu_id).setVisible(Browser.canClearHistory(this.getContentResolver()));
        return true;
    
private voidsetResultToParent(int resultCode, android.content.Intent data)

        Activity a = getParent() == null ? this : getParent();
        a.setResult(resultCode, data);