180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb/*
280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * Copyright (C) 2011 The Android Open Source Project
380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb *
480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * Licensed under the Apache License, Version 2.0 (the "License");
580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * you may not use this file except in compliance with the License.
680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * You may obtain a copy of the License at
780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb *
880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb *      http://www.apache.org/licenses/LICENSE-2.0
980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb *
1080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * Unless required by applicable law or agreed to in writing, software
1180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * distributed under the License is distributed on an "AS IS" BASIS,
1280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * See the License for the specific language governing permissions and
1480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * limitations under the License.
1580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb */
1680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
1780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbpackage com.android.browser;
1880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
1980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.app.Activity;
2080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.content.Context;
2180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.graphics.Bitmap;
222bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Choimport android.os.Build;
2380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.view.LayoutInflater;
2480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.view.View;
2580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.view.View.OnClickListener;
2680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.view.ViewGroup;
2780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.view.ViewGroup.LayoutParams;
2880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.webkit.WebView;
2980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.widget.BaseAdapter;
3080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.widget.FrameLayout;
3180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.widget.ImageView;
3280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.widget.ImageView.ScaleType;
3380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.widget.TextView;
3480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
3580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport com.android.browser.UI.ComboViews;
3680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport com.android.browser.view.PieItem;
3780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport com.android.browser.view.PieMenu;
3880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport com.android.browser.view.PieMenu.PieView.OnLayoutListener;
3980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport com.android.browser.view.PieStackView;
4080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport com.android.browser.view.PieStackView.OnCurrentListener;
4180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
4280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport java.util.ArrayList;
4380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport java.util.List;
4480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
4580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb/**
4680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb * Controller for Quick Controls pie menu
4780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb */
4880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbpublic class PieControl implements PieMenu.PieController, OnClickListener {
4980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
5080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected Activity mActivity;
5180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected UiController mUiController;
5280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected PieMenu mPie;
5380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected int mItemSize;
5480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected TextView mTabsCount;
5580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private BaseUi mUi;
5680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mBack;
5780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mForward;
5880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mRefresh;
5980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mUrl;
6080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mOptions;
6180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mBookmarks;
6280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mHistory;
6380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mAddBookmark;
6480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mNewTab;
6580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mIncognito;
6680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mClose;
6780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mShowTabs;
6880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mInfo;
6980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mFind;
7080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mShare;
7180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private PieItem mRDS;
7280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private TabAdapter mTabAdapter;
7380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
7480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public PieControl(Activity activity, UiController controller, BaseUi ui) {
7580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mActivity = activity;
7680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUiController = controller;
7780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mItemSize = (int) activity.getResources().getDimension(R.dimen.qc_item_size);
7880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUi = ui;
7980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
8080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
8180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void stopEditingUrl() {
8280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUi.stopEditingUrl();
8380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
8480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
8580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected void attachToContainer(FrameLayout container) {
8680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mPie == null) {
8780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mPie = new PieMenu(mActivity);
8880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
8980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                    LayoutParams.MATCH_PARENT);
9080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mPie.setLayoutParams(lp);
9180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            populateMenu();
9280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mPie.setController(this);
9380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
9480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        container.addView(mPie);
9580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
9680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
9780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected void removeFromContainer(FrameLayout container) {
9880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        container.removeView(mPie);
9980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
10080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
10180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected void forceToTop(FrameLayout container) {
10280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mPie.getParent() != null) {
10380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            container.removeView(mPie);
10480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            container.addView(mPie);
10580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
10680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
10780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
10880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected void setClickListener(OnClickListener listener, PieItem... items) {
10980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        for (PieItem item : items) {
11080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            item.getView().setOnClickListener(listener);
11180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
11280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
11380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
11480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    @Override
11580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public boolean onOpen() {
11680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        int n = mUiController.getTabControl().getTabCount();
11780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mTabsCount.setText(Integer.toString(n));
11880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        Tab tab = mUiController.getCurrentTab();
1195fea4a202fd54c289b4316cbca9c19b256eb3cb3Michael Kolb        if (tab != null) {
1205fea4a202fd54c289b4316cbca9c19b256eb3cb3Michael Kolb            mForward.setEnabled(tab.canGoForward());
1215fea4a202fd54c289b4316cbca9c19b256eb3cb3Michael Kolb        }
122af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb        WebView view = mUiController.getCurrentWebView();
123af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb        if (view != null) {
124af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb            ImageView icon = (ImageView) mRDS.getView();
125af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb            if (mUiController.getSettings().hasDesktopUseragent(view)) {
126af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb                icon.setImageResource(R.drawable.ic_mobile);
127af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb            } else {
128af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb                icon.setImageResource(R.drawable.ic_desktop_holo_dark);
129af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb            }
130af63dbadb04a963f3513bff2f6ec5f34d31c24d6Michael Kolb        }
13180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return true;
13280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
13380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
13480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected void populateMenu() {
13580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBack = makeItem(R.drawable.ic_back_holo_dark, 1);
13680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUrl = makeItem(R.drawable.ic_web_holo_dark, 1);
13780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBookmarks = makeItem(R.drawable.ic_bookmarks_holo_dark, 1);
13880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mHistory = makeItem(R.drawable.ic_history_holo_dark, 1);
13980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mAddBookmark = makeItem(R.drawable.ic_bookmark_on_holo_dark, 1);
14080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mRefresh = makeItem(R.drawable.ic_refresh_holo_dark, 1);
14180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mForward = makeItem(R.drawable.ic_forward_holo_dark, 1);
14280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mNewTab = makeItem(R.drawable.ic_new_window_holo_dark, 1);
14380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mIncognito = makeItem(R.drawable.ic_new_incognito_holo_dark, 1);
14480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mClose = makeItem(R.drawable.ic_close_window_holo_dark, 1);
14580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mInfo = makeItem(android.R.drawable.ic_menu_info_details, 1);
14680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mFind = makeItem(R.drawable.ic_search_holo_dark, 1);
14780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mShare = makeItem(R.drawable.ic_share_holo_dark, 1);
14880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        View tabs = makeTabsView();
14980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mShowTabs = new PieItem(tabs, 1);
15080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mOptions = makeItem(R.drawable.ic_settings_holo_dark, 1);
15180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mRDS = makeItem(R.drawable.ic_desktop_holo_dark, 1);
15280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mTabAdapter = new TabAdapter(mActivity, mUiController);
15380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        PieStackView stack = new PieStackView(mActivity);
15480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        stack.setLayoutListener(new OnLayoutListener() {
15580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            @Override
15680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            public void onLayout(int ax, int ay, boolean left) {
15780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                buildTabs();
15880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            }
15980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        });
16080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        stack.setOnCurrentListener(mTabAdapter);
16180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        stack.setAdapter(mTabAdapter);
16280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mShowTabs.setPieView(stack);
16380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        setClickListener(this, mBack, mRefresh, mForward, mUrl, mFind, mInfo,
16480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                mShare, mBookmarks, mNewTab, mIncognito, mClose, mHistory,
16580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                mAddBookmark, mOptions, mRDS);
166a34ae509d18e6507757c337ed75ea629e05bec6dMichael Kolb        if (!BrowserActivity.isTablet(mActivity)) {
167a34ae509d18e6507757c337ed75ea629e05bec6dMichael Kolb            mShowTabs.getView().setOnClickListener(this);
168a34ae509d18e6507757c337ed75ea629e05bec6dMichael Kolb        }
16980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        // level 1
17080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mPie.addItem(mOptions);
17180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mOptions.addItem(mRDS);
17280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mOptions.addItem(makeFiller());
17380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mOptions.addItem(makeFiller());
17480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mOptions.addItem(makeFiller());
17580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mPie.addItem(mBack);
17680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBack.addItem(mRefresh);
17780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBack.addItem(mForward);
17880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBack.addItem(makeFiller());
17980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBack.addItem(makeFiller());
18080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mPie.addItem(mUrl);
18180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUrl.addItem(mFind);
18280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUrl.addItem(mShare);
18380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUrl.addItem(makeFiller());
18480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUrl.addItem(makeFiller());
18580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mPie.addItem(mShowTabs);
1862bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
1872bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho            mShowTabs.addItem(makeFiller());
1882bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho            mShowTabs.addItem(mClose);
1892bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho        } else {
1902bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho            mShowTabs.addItem(mClose);
1912bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho            mShowTabs.addItem(mIncognito);
1922bdd8d1d98f43cb3f861e16315f83eff6beed909Sungmann Cho        }
19380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mShowTabs.addItem(mNewTab);
19480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mShowTabs.addItem(makeFiller());
19580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mPie.addItem(mBookmarks);
19680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBookmarks.addItem(makeFiller());
19780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBookmarks.addItem(makeFiller());
19880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBookmarks.addItem(mAddBookmark);
19980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mBookmarks.addItem(mHistory);
20080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
20180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
20280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    @Override
20380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void onClick(View v) {
20480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        Tab tab = mUiController.getTabControl().getCurrentTab();
20580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        WebView web = tab.getWebView();
20680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mBack.getView() == v) {
20780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            tab.goBack();
20880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mForward.getView() == v) {
20980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            tab.goForward();
21080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mRefresh.getView() == v) {
21180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            if (tab.inPageLoad()) {
21280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                web.stopLoading();
21380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            } else {
21480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                web.reload();
21580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            }
21680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mUrl.getView() == v) {
2171f9b3565dbd1911dfe4d9bfd8b833a5ac5f2e0c4Michael Kolb            mUi.editUrl(false, true);
21880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mBookmarks.getView() == v) {
21980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.bookmarksOrHistoryPicker(ComboViews.Bookmarks);
22080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mHistory.getView() == v) {
22180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.bookmarksOrHistoryPicker(ComboViews.History);
22280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mAddBookmark.getView() == v) {
22380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.bookmarkCurrentPage();
22480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mNewTab.getView() == v) {
22580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.openTabToHomePage();
2261f9b3565dbd1911dfe4d9bfd8b833a5ac5f2e0c4Michael Kolb            mUi.editUrl(false, true);
22780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mIncognito.getView() == v) {
22880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.openIncognitoTab();
2291f9b3565dbd1911dfe4d9bfd8b833a5ac5f2e0c4Michael Kolb            mUi.editUrl(false, true);
23080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mClose.getView() == v) {
23180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.closeCurrentTab();
23280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mOptions.getView() == v) {
23380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.openPreferences();
23480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mShare.getView() == v) {
23580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.shareCurrentPage();
23680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mInfo.getView() == v) {
23780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.showPageInfo();
23880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mFind.getView() == v) {
23980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.findOnPage();
24080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        } else if (mRDS.getView() == v) {
24180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController.toggleUserAgent();
242a34ae509d18e6507757c337ed75ea629e05bec6dMichael Kolb        } else if (mShowTabs.getView() == v) {
243a34ae509d18e6507757c337ed75ea629e05bec6dMichael Kolb            ((PhoneUi) mUi).showNavScreen();
24480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
24580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
24680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
24780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private void buildTabs() {
24880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        final List<Tab> tabs = mUiController.getTabs();
24980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mUi.getActiveTab().capture();
25080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mTabAdapter.setTabs(tabs);
25180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        PieStackView sym = (PieStackView) mShowTabs.getPieView();
25280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        sym.setCurrent(mUiController.getTabControl().getCurrentPosition());
25380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
25480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
25580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected PieItem makeItem(int image, int l) {
25680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        ImageView view = new ImageView(mActivity);
25780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        view.setImageResource(image);
25880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        view.setMinimumWidth(mItemSize);
25980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        view.setMinimumHeight(mItemSize);
26080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        view.setScaleType(ScaleType.CENTER);
26180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        LayoutParams lp = new LayoutParams(mItemSize, mItemSize);
26280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        view.setLayoutParams(lp);
26380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return new PieItem(view, l);
26480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
26580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
26680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected PieItem makeFiller() {
26780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return new PieItem(null, 1);
26880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
26980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
27080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    protected View makeTabsView() {
27180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        View v = mActivity.getLayoutInflater().inflate(R.layout.qc_tabs_view, null);
27280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mTabsCount = (TextView) v.findViewById(R.id.label);
27380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mTabsCount.setText("1");
27480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        ImageView image = (ImageView) v.findViewById(R.id.icon);
27580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        image.setImageResource(R.drawable.ic_windows_holo_dark);
27680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        image.setScaleType(ScaleType.CENTER);
27780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        LayoutParams lp = new LayoutParams(mItemSize, mItemSize);
27880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        v.setLayoutParams(lp);
27980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return v;
28080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
28180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
28280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    static class TabAdapter extends BaseAdapter implements OnCurrentListener {
28380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
28480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        LayoutInflater mInflater;
28580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        UiController mUiController;
28680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        private List<Tab> mTabs;
28780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        private int mCurrent;
28880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
28980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public TabAdapter(Context ctx, UiController ctl) {
29080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mInflater = LayoutInflater.from(ctx);
29180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mUiController = ctl;
29280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mTabs = new ArrayList<Tab>();
29380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mCurrent = -1;
29480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
29580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
29680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public void setTabs(List<Tab> tabs) {
29780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mTabs = tabs;
29880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            notifyDataSetChanged();
29980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
30080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
30180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        @Override
30280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public int getCount() {
30380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            return mTabs.size();
30480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
30580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
30680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        @Override
30780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public Tab getItem(int position) {
30880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            return mTabs.get(position);
30980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
31080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
31180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        @Override
31280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public long getItemId(int position) {
31380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            return position;
31480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
31580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
31680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        @Override
31780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public View getView(int position, View convertView, ViewGroup parent) {
31880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            final Tab tab = mTabs.get(position);
31980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            View view = mInflater.inflate(R.layout.qc_tab,
32080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                    null);
32180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            ImageView thumb = (ImageView) view.findViewById(R.id.thumb);
32280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            TextView title1 = (TextView) view.findViewById(R.id.title1);
32380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            TextView title2 = (TextView) view.findViewById(R.id.title2);
32480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            Bitmap b = tab.getScreenshot();
32580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            if (b != null) {
32680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                thumb.setImageBitmap(b);
32780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            }
32880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            if (position > mCurrent) {
32980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                title1.setVisibility(View.GONE);
33080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                title2.setText(tab.getTitle());
33180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            } else {
33280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                title2.setVisibility(View.GONE);
33380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                title1.setText(tab.getTitle());
33480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            }
33580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            view.setOnClickListener(new OnClickListener() {
33680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                @Override
33780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                public void onClick(View v) {
33880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                    mUiController.switchToTab(tab);
33980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb                }
34080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            });
34180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            return view;
34280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
34380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
34480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        @Override
34580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        public void onSetCurrent(int index) {
34680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mCurrent = index;
34780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
34880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
34980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
35080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
35180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb}
352