blob: cea1884967e53b9e19511b063d45384977c48336 [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 */
16package com.android.browser;
17
18import android.app.Activity;
19import android.content.Intent;
20import android.net.Uri;
21import android.os.Bundle;
22import android.view.Menu;
23import android.view.MenuItem;
24
25import com.android.browser.CombinedBookmarkHistoryView.CombinedBookmarksCallbacks;
26import com.android.browser.UI.ComboViews;
27
28public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks {
29
30 public static final String EXTRA_COMBO_ARGS = "combo_args";
31 public static final String EXTRA_INITIAL_VIEW = "initial_view";
32
33 public static final String EXTRA_OPEN_SNAPSHOT = "snapshot_id";
34 public static final String EXTRA_OPEN_ALL = "open_all";
35 public static final String EXTRA_CURRENT_URL = "url";
36 public static final String EXTRA_BOOKMARK_PAGE = "create_bookmark";
37
38 private CombinedBookmarkHistoryView mComboView;
39
40 @Override
41 protected void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
43 setResult(RESULT_CANCELED);
44 Bundle extras = getIntent().getExtras();
45 Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
46 String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
47 ComboViews startingView = svStr != null
48 ? ComboViews.valueOf(svStr)
49 : ComboViews.Bookmarks;
50 mComboView = new CombinedBookmarkHistoryView(this, this,
51 startingView, args);
52 setContentView(mComboView);
53 }
54
55 @Override
56 public void openUrl(String url) {
57 Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
58 setResult(RESULT_OK, i);
59 finish();
60 }
61
62 @Override
63 public void openInNewTab(String... urls) {
64 Intent i = new Intent();
65 i.putExtra(EXTRA_OPEN_ALL, urls);
66 setResult(RESULT_OK, i);
67 finish();
68 }
69
70 @Override
71 public void close() {
72 finish();
73 }
74
75 @Override
76 public void openSnapshot(long id) {
77 Intent i = new Intent();
78 i.putExtra(EXTRA_OPEN_SNAPSHOT, id);
79 setResult(RESULT_OK, i);
80 finish();
81 }
82
83 @Override
84 public void onBackPressed() {
85 if (!mComboView.onBackPressed()) {
86 super.onBackPressed();
87 }
88 }
89
90 @Override
91 public boolean onCreateOptionsMenu(Menu menu) {
92 getMenuInflater().inflate(R.menu.combined, menu);
93 return super.onCreateOptionsMenu(menu);
94 }
95
96 @Override
97 public boolean onOptionsItemSelected(MenuItem item) {
98 if (item.getItemId() == android.R.id.home) {
99 finish();
100 return true;
101 } else if (item.getItemId() == R.id.preferences_menu_id) {
102 String url = getIntent().getStringExtra(EXTRA_CURRENT_URL);
103 Intent intent = new Intent(this, BrowserPreferencesPage.class);
104 intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE, url);
105 startActivityForResult(intent, Controller.PREFERENCES_PAGE);
106 return true;
107 }
108 return super.onOptionsItemSelected(item);
109 }
110}