John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 16 | package com.android.browser; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 17 | |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 18 | import android.app.ActionBar; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
| 20 | import android.content.Intent; |
| 21 | import android.net.Uri; |
| 22 | import android.os.Bundle; |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 23 | import android.support.v4.view.ViewPager; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 24 | import android.view.Menu; |
| 25 | import android.view.MenuItem; |
| 26 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 27 | import com.android.browser.UI.ComboViews; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 28 | |
| 29 | public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks { |
| 30 | |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 31 | private static final String STATE_SELECTED_TAB = "tab"; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 32 | public static final String EXTRA_COMBO_ARGS = "combo_args"; |
| 33 | public static final String EXTRA_INITIAL_VIEW = "initial_view"; |
| 34 | |
| 35 | public static final String EXTRA_OPEN_SNAPSHOT = "snapshot_id"; |
| 36 | public static final String EXTRA_OPEN_ALL = "open_all"; |
| 37 | public static final String EXTRA_CURRENT_URL = "url"; |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 38 | private ViewPager mViewPager; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame^] | 39 | private ComboTabsAdapter mTabsAdapter; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 40 | |
| 41 | @Override |
| 42 | protected void onCreate(Bundle savedInstanceState) { |
| 43 | super.onCreate(savedInstanceState); |
| 44 | setResult(RESULT_CANCELED); |
| 45 | Bundle extras = getIntent().getExtras(); |
| 46 | Bundle args = extras.getBundle(EXTRA_COMBO_ARGS); |
| 47 | String svStr = extras.getString(EXTRA_INITIAL_VIEW, null); |
| 48 | ComboViews startingView = svStr != null |
| 49 | ? ComboViews.valueOf(svStr) |
| 50 | : ComboViews.Bookmarks; |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 51 | mViewPager = new ViewPager(this); |
| 52 | mViewPager.setId(R.id.tab_view); |
| 53 | setContentView(mViewPager); |
| 54 | |
| 55 | final ActionBar bar = getActionBar(); |
| 56 | bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 57 | if (BrowserActivity.isTablet(this)) { |
| 58 | bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
| 59 | | ActionBar.DISPLAY_USE_LOGO); |
John Reck | c0b64c8 | 2011-11-10 17:12:24 -0800 | [diff] [blame] | 60 | bar.setHomeButtonEnabled(true); |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 61 | } else { |
| 62 | bar.setDisplayOptions(0); |
| 63 | } |
| 64 | |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame^] | 65 | mTabsAdapter = new ComboTabsAdapter(this, mViewPager); |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 66 | mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks), |
| 67 | BrowserBookmarksPage.class, args); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 68 | mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history), |
| 69 | BrowserHistoryPage.class, args); |
| 70 | mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots), |
| 71 | BrowserSnapshotPage.class, args); |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 72 | |
| 73 | if (savedInstanceState != null) { |
| 74 | bar.setSelectedNavigationItem( |
| 75 | savedInstanceState.getInt(STATE_SELECTED_TAB, 0)); |
| 76 | } else { |
| 77 | switch (startingView) { |
| 78 | case Bookmarks: |
| 79 | mViewPager.setCurrentItem(0); |
| 80 | break; |
| 81 | case History: |
| 82 | mViewPager.setCurrentItem(1); |
| 83 | break; |
| 84 | case Snapshots: |
| 85 | mViewPager.setCurrentItem(2); |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | protected void onSaveInstanceState(Bundle outState) { |
| 93 | super.onSaveInstanceState(outState); |
| 94 | outState.putInt(STATE_SELECTED_TAB, |
| 95 | getActionBar().getSelectedNavigationIndex()); |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void openUrl(String url) { |
| 100 | Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
| 101 | setResult(RESULT_OK, i); |
| 102 | finish(); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void openInNewTab(String... urls) { |
| 107 | Intent i = new Intent(); |
| 108 | i.putExtra(EXTRA_OPEN_ALL, urls); |
| 109 | setResult(RESULT_OK, i); |
| 110 | finish(); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void close() { |
| 115 | finish(); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void openSnapshot(long id) { |
| 120 | Intent i = new Intent(); |
| 121 | i.putExtra(EXTRA_OPEN_SNAPSHOT, id); |
| 122 | setResult(RESULT_OK, i); |
| 123 | finish(); |
| 124 | } |
| 125 | |
| 126 | @Override |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 127 | public boolean onCreateOptionsMenu(Menu menu) { |
| 128 | getMenuInflater().inflate(R.menu.combined, menu); |
| 129 | return super.onCreateOptionsMenu(menu); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public boolean onOptionsItemSelected(MenuItem item) { |
| 134 | if (item.getItemId() == android.R.id.home) { |
| 135 | finish(); |
| 136 | return true; |
| 137 | } else if (item.getItemId() == R.id.preferences_menu_id) { |
| 138 | String url = getIntent().getStringExtra(EXTRA_CURRENT_URL); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 139 | BrowserPreferencesPage.startPreferencesForResult(this, url, Controller.PREFERENCES_PAGE); |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 140 | return true; |
| 141 | } |
| 142 | return super.onOptionsItemSelected(item); |
| 143 | } |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 144 | |
John Reck | 2d963a2 | 2011-08-10 15:53:07 -0700 | [diff] [blame] | 145 | private static String makeFragmentName(int viewId, int index) { |
| 146 | return "android:switcher:" + viewId + ":" + index; |
| 147 | } |
| 148 | |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 149 | } |