blob: 4e672ca6eeedd755d87b19c3b39328009590eae2 [file] [log] [blame]
John Reckd3e4d5b2011-07-13 15:48:43 -07001/*
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 Amirzada41242f22014-03-21 12:12:18 -070016package com.android.browser;
John Reckd3e4d5b2011-07-13 15:48:43 -070017
John Reck2d963a22011-08-10 15:53:07 -070018import android.app.ActionBar;
John Reckd3e4d5b2011-07-13 15:48:43 -070019import android.app.Activity;
20import android.content.Intent;
21import android.net.Uri;
22import android.os.Bundle;
John Reck2d963a22011-08-10 15:53:07 -070023import android.support.v4.view.ViewPager;
John Reckd3e4d5b2011-07-13 15:48:43 -070024import android.view.Menu;
25import android.view.MenuItem;
26
Bijan Amirzada41242f22014-03-21 12:12:18 -070027import com.android.browser.UI.ComboViews;
John Reckd3e4d5b2011-07-13 15:48:43 -070028
29public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks {
30
John Reck2d963a22011-08-10 15:53:07 -070031 private static final String STATE_SELECTED_TAB = "tab";
John Reckd3e4d5b2011-07-13 15:48:43 -070032 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 Reck2d963a22011-08-10 15:53:07 -070038 private ViewPager mViewPager;
Tarun Nainani87a86682015-02-05 11:47:35 -080039 private ComboTabsAdapter mTabsAdapter;
John Reckd3e4d5b2011-07-13 15:48:43 -070040
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 Reck2d963a22011-08-10 15:53:07 -070051 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 Reckc0b64c82011-11-10 17:12:24 -080060 bar.setHomeButtonEnabled(true);
John Reck2d963a22011-08-10 15:53:07 -070061 } else {
62 bar.setDisplayOptions(0);
63 }
64
Tarun Nainani87a86682015-02-05 11:47:35 -080065 mTabsAdapter = new ComboTabsAdapter(this, mViewPager);
John Reck2d963a22011-08-10 15:53:07 -070066 mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks),
67 BrowserBookmarksPage.class, args);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080068 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 Reck2d963a22011-08-10 15:53:07 -070072
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 Reckd3e4d5b2011-07-13 15:48:43 -070096 }
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 Reckd3e4d5b2011-07-13 15:48:43 -0700127 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 Rosd6efa972014-12-02 19:49:59 -0800139 BrowserPreferencesPage.startPreferencesForResult(this, url, Controller.PREFERENCES_PAGE);
John Reckd3e4d5b2011-07-13 15:48:43 -0700140 return true;
141 }
142 return super.onOptionsItemSelected(item);
143 }
John Reck2d963a22011-08-10 15:53:07 -0700144
John Reck2d963a22011-08-10 15:53:07 -0700145 private static String makeFragmentName(int viewId, int index) {
146 return "android:switcher:" + viewId + ":" + index;
147 }
148
John Reckd3e4d5b2011-07-13 15:48:43 -0700149}