blob: 5c6df08d62e9287f8f559cd038a4c7b748f156fa [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;
Vivek Sekharb7b51df2016-02-06 20:55:00 +010020import android.content.Context;
John Reckd3e4d5b2011-07-13 15:48:43 -070021import android.content.Intent;
22import android.net.Uri;
23import android.os.Bundle;
John Reck2d963a22011-08-10 15:53:07 -070024import android.support.v4.view.ViewPager;
John Reckd3e4d5b2011-07-13 15:48:43 -070025import android.view.Menu;
26import android.view.MenuItem;
Vivek Sekharb7b51df2016-02-06 20:55:00 +010027import android.util.Log;
John Reckd3e4d5b2011-07-13 15:48:43 -070028
Bijan Amirzada41242f22014-03-21 12:12:18 -070029import com.android.browser.UI.ComboViews;
John Reckd3e4d5b2011-07-13 15:48:43 -070030
31public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks {
32
Vivek Sekharb7b51df2016-02-06 20:55:00 +010033 private static final String LOGTAG = "ComboViewActivity";
John Reck2d963a22011-08-10 15:53:07 -070034 private static final String STATE_SELECTED_TAB = "tab";
John Reckd3e4d5b2011-07-13 15:48:43 -070035 public static final String EXTRA_COMBO_ARGS = "combo_args";
36 public static final String EXTRA_INITIAL_VIEW = "initial_view";
37
38 public static final String EXTRA_OPEN_SNAPSHOT = "snapshot_id";
39 public static final String EXTRA_OPEN_ALL = "open_all";
40 public static final String EXTRA_CURRENT_URL = "url";
John Reck2d963a22011-08-10 15:53:07 -070041 private ViewPager mViewPager;
Tarun Nainani87a86682015-02-05 11:47:35 -080042 private ComboTabsAdapter mTabsAdapter;
John Reckd3e4d5b2011-07-13 15:48:43 -070043
44 @Override
45 protected void onCreate(Bundle savedInstanceState) {
Vivek Sekharb7b51df2016-02-06 20:55:00 +010046 if (!EngineInitializer.isInitialized()) {
47 Log.e(LOGTAG, "Engine not Initialized");
48 EngineInitializer.initializeSync((Context) getApplicationContext());
49 }
John Reckd3e4d5b2011-07-13 15:48:43 -070050 super.onCreate(savedInstanceState);
51 setResult(RESULT_CANCELED);
52 Bundle extras = getIntent().getExtras();
53 Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
54 String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
55 ComboViews startingView = svStr != null
56 ? ComboViews.valueOf(svStr)
57 : ComboViews.Bookmarks;
John Reck2d963a22011-08-10 15:53:07 -070058 mViewPager = new ViewPager(this);
59 mViewPager.setId(R.id.tab_view);
60 setContentView(mViewPager);
61
62 final ActionBar bar = getActionBar();
63 bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
64 if (BrowserActivity.isTablet(this)) {
65 bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
66 | ActionBar.DISPLAY_USE_LOGO);
John Reckc0b64c82011-11-10 17:12:24 -080067 bar.setHomeButtonEnabled(true);
John Reck2d963a22011-08-10 15:53:07 -070068 } else {
69 bar.setDisplayOptions(0);
70 }
71
Tarun Nainani87a86682015-02-05 11:47:35 -080072 mTabsAdapter = new ComboTabsAdapter(this, mViewPager);
Sagar Dhawan53b2ba72015-08-05 15:58:20 -070073 mTabsAdapter.addTab(bar.newTab().setText(R.string.bookmarks),
John Reck2d963a22011-08-10 15:53:07 -070074 BrowserBookmarksPage.class, args);
Sagar Dhawan53b2ba72015-08-05 15:58:20 -070075 mTabsAdapter.addTab(bar.newTab().setText(R.string.history),
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080076 BrowserHistoryPage.class, args);
77 mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots),
78 BrowserSnapshotPage.class, args);
John Reck2d963a22011-08-10 15:53:07 -070079
80 if (savedInstanceState != null) {
81 bar.setSelectedNavigationItem(
82 savedInstanceState.getInt(STATE_SELECTED_TAB, 0));
83 } else {
84 switch (startingView) {
85 case Bookmarks:
86 mViewPager.setCurrentItem(0);
87 break;
88 case History:
89 mViewPager.setCurrentItem(1);
90 break;
91 case Snapshots:
92 mViewPager.setCurrentItem(2);
93 break;
94 }
95 }
96 }
97
98 @Override
99 protected void onSaveInstanceState(Bundle outState) {
100 super.onSaveInstanceState(outState);
101 outState.putInt(STATE_SELECTED_TAB,
102 getActionBar().getSelectedNavigationIndex());
John Reckd3e4d5b2011-07-13 15:48:43 -0700103 }
104
105 @Override
106 public void openUrl(String url) {
107 Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
108 setResult(RESULT_OK, i);
109 finish();
110 }
111
112 @Override
113 public void openInNewTab(String... urls) {
114 Intent i = new Intent();
115 i.putExtra(EXTRA_OPEN_ALL, urls);
116 setResult(RESULT_OK, i);
117 finish();
118 }
119
120 @Override
121 public void close() {
122 finish();
123 }
124
125 @Override
126 public void openSnapshot(long id) {
127 Intent i = new Intent();
128 i.putExtra(EXTRA_OPEN_SNAPSHOT, id);
129 setResult(RESULT_OK, i);
130 finish();
131 }
132
133 @Override
John Reckd3e4d5b2011-07-13 15:48:43 -0700134 public boolean onCreateOptionsMenu(Menu menu) {
135 getMenuInflater().inflate(R.menu.combined, menu);
136 return super.onCreateOptionsMenu(menu);
137 }
138
139 @Override
140 public boolean onOptionsItemSelected(MenuItem item) {
141 if (item.getItemId() == android.R.id.home) {
142 finish();
143 return true;
144 } else if (item.getItemId() == R.id.preferences_menu_id) {
145 String url = getIntent().getStringExtra(EXTRA_CURRENT_URL);
Enrico Rosd6efa972014-12-02 19:49:59 -0800146 BrowserPreferencesPage.startPreferencesForResult(this, url, Controller.PREFERENCES_PAGE);
John Reckd3e4d5b2011-07-13 15:48:43 -0700147 return true;
148 }
149 return super.onOptionsItemSelected(item);
150 }
John Reck2d963a22011-08-10 15:53:07 -0700151
John Reck2d963a22011-08-10 15:53:07 -0700152 private static String makeFragmentName(int viewId, int index) {
153 return "android:switcher:" + viewId + ":" + index;
154 }
155
John Reckd3e4d5b2011-07-13 15:48:43 -0700156}