/WebVox/src/com/marvin/webvox/BrowserBookmarksPage.java

http://eyes-free.googlecode.com/ · Java · 669 lines · 516 code · 57 blank · 96 comment · 103 complexity · 17e3130efdbb8e486d9cbaf9898f1b8d MD5 · raw file

  1. /*
  2. * Copyright (C) 2006 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. */
  16. package com.marvin.webvox;
  17. import com.marvin.webvox.R;
  18. import android.app.Activity;
  19. import android.app.AlertDialog;
  20. import android.content.DialogInterface;
  21. import android.content.Intent;
  22. import android.content.SharedPreferences;
  23. import android.content.SharedPreferences.Editor;
  24. import android.graphics.Bitmap;
  25. import android.graphics.BitmapFactory;
  26. import android.graphics.Canvas;
  27. import android.graphics.Color;
  28. import android.graphics.Paint;
  29. import android.graphics.Path;
  30. import android.graphics.PorterDuff;
  31. import android.graphics.PorterDuffXfermode;
  32. import android.graphics.RectF;
  33. import android.net.Uri;
  34. import android.os.Bundle;
  35. import android.os.Handler;
  36. import android.os.Message;
  37. //import android.os.ServiceManager;
  38. import android.provider.Browser;
  39. //import android.text.IClipboard;
  40. import android.util.Log;
  41. import android.view.ContextMenu;
  42. import android.view.KeyEvent;
  43. import android.view.LayoutInflater;
  44. import android.view.Menu;
  45. import android.view.MenuInflater;
  46. import android.view.MenuItem;
  47. import android.view.View;
  48. import android.view.ViewGroup;
  49. import android.view.ViewGroup.LayoutParams;
  50. import android.view.ViewStub;
  51. import android.view.ContextMenu.ContextMenuInfo;
  52. import android.widget.AdapterView;
  53. import android.widget.GridView;
  54. import android.widget.ListView;
  55. import android.widget.Toast;
  56. /*package*/ enum BookmarkViewMode { NONE, GRID, LIST }
  57. /**
  58. * View showing the user's bookmarks in the browser.
  59. */
  60. public class BrowserBookmarksPage extends Activity implements
  61. View.OnCreateContextMenuListener {
  62. private BookmarkViewMode mViewMode = BookmarkViewMode.NONE;
  63. private GridView mGridPage;
  64. private View mVerticalList;
  65. private BrowserBookmarksAdapter mBookmarksAdapter;
  66. private static final int BOOKMARKS_SAVE = 1;
  67. private boolean mDisableNewWindow;
  68. private BookmarkItem mContextHeader;
  69. private AddNewBookmark mAddHeader;
  70. private boolean mCanceled = false;
  71. private boolean mCreateShortcut;
  72. private boolean mMostVisited;
  73. private View mEmptyView;
  74. // XXX: There is no public string defining this intent so if Home changes
  75. // the value, we have to update this string.
  76. private static final String INSTALL_SHORTCUT =
  77. "com.android.launcher.action.INSTALL_SHORTCUT";
  78. private final static String LOGTAG = "browser";
  79. private final static String PREF_BOOKMARK_VIEW_MODE = "pref_bookmark_view_mode";
  80. private final static String PREF_MOST_VISITED_VIEW_MODE = "pref_most_visited_view_mode";
  81. @Override
  82. public boolean onContextItemSelected(MenuItem item) {
  83. // It is possible that the view has been canceled when we get to
  84. // this point as back has a higher priority
  85. if (mCanceled) {
  86. return true;
  87. }
  88. AdapterView.AdapterContextMenuInfo i =
  89. (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
  90. // If we have no menu info, we can't tell which item was selected.
  91. if (i == null) {
  92. return true;
  93. }
  94. switch (item.getItemId()) {
  95. case R.id.new_context_menu_id:
  96. saveCurrentPage();
  97. break;
  98. case R.id.open_context_menu_id:
  99. loadUrl(i.position);
  100. break;
  101. case R.id.edit_context_menu_id:
  102. editBookmark(i.position);
  103. break;
  104. case R.id.shortcut_context_menu_id:
  105. final Intent send = createShortcutIntent(i.position);
  106. send.setAction(INSTALL_SHORTCUT);
  107. sendBroadcast(send);
  108. break;
  109. case R.id.delete_context_menu_id:
  110. if (mMostVisited) {
  111. Browser.deleteFromHistory(getContentResolver(),
  112. getUrl(i.position));
  113. refreshList();
  114. } else {
  115. displayRemoveBookmarkDialog(i.position);
  116. }
  117. break;
  118. case R.id.new_window_context_menu_id:
  119. openInNewWindow(i.position);
  120. break;
  121. case R.id.share_link_context_menu_id:
  122. // Browser.sendString(BrowserBookmarksPage.this, getUrl(i.position),
  123. // getText(R.string.choosertitle_sharevia).toString());
  124. break;
  125. case R.id.copy_url_context_menu_id:
  126. copy(getUrl(i.position));
  127. break;
  128. case R.id.homepage_context_menu_id:
  129. BrowserSettings.getInstance().setHomePage(this,
  130. getUrl(i.position));
  131. Toast.makeText(this, R.string.homepage_set,
  132. Toast.LENGTH_LONG).show();
  133. break;
  134. // Only for the Most visited page
  135. case R.id.save_to_bookmarks_menu_id:
  136. boolean isBookmark;
  137. String name;
  138. String url;
  139. if (mViewMode == BookmarkViewMode.GRID) {
  140. isBookmark = mBookmarksAdapter.getIsBookmark(i.position);
  141. name = mBookmarksAdapter.getTitle(i.position);
  142. url = mBookmarksAdapter.getUrl(i.position);
  143. } else {
  144. HistoryItem historyItem = ((HistoryItem) i.targetView);
  145. isBookmark = historyItem.isBookmark();
  146. name = historyItem.getName();
  147. url = historyItem.getUrl();
  148. }
  149. // If the site is bookmarked, the item becomes remove from
  150. // bookmarks.
  151. if (isBookmark) {
  152. Bookmarks.removeFromBookmarks(this, getContentResolver(), url, name);
  153. } else {
  154. Browser.saveBookmark(this, name, url);
  155. }
  156. break;
  157. default:
  158. return super.onContextItemSelected(item);
  159. }
  160. return true;
  161. }
  162. @Override
  163. public void onCreateContextMenu(ContextMenu menu, View v,
  164. ContextMenuInfo menuInfo) {
  165. AdapterView.AdapterContextMenuInfo i =
  166. (AdapterView.AdapterContextMenuInfo) menuInfo;
  167. MenuInflater inflater = getMenuInflater();
  168. if (mMostVisited) {
  169. inflater.inflate(R.menu.historycontext, menu);
  170. } else {
  171. inflater.inflate(R.menu.bookmarkscontext, menu);
  172. }
  173. if (0 == i.position && !mMostVisited) {
  174. menu.setGroupVisible(R.id.CONTEXT_MENU, false);
  175. if (mAddHeader == null) {
  176. mAddHeader = new AddNewBookmark(BrowserBookmarksPage.this);
  177. } else if (mAddHeader.getParent() != null) {
  178. ((ViewGroup) mAddHeader.getParent()).
  179. removeView(mAddHeader);
  180. }
  181. mAddHeader.setUrl(getIntent().getStringExtra("url"));
  182. menu.setHeaderView(mAddHeader);
  183. return;
  184. }
  185. if (mMostVisited) {
  186. if ((mViewMode == BookmarkViewMode.LIST
  187. && ((HistoryItem) i.targetView).isBookmark())
  188. || mBookmarksAdapter.getIsBookmark(i.position)) {
  189. MenuItem item = menu.findItem(
  190. R.id.save_to_bookmarks_menu_id);
  191. item.setTitle(R.string.remove_from_bookmarks);
  192. }
  193. } else {
  194. // The historycontext menu has no ADD_MENU group.
  195. menu.setGroupVisible(R.id.ADD_MENU, false);
  196. }
  197. if (mDisableNewWindow) {
  198. menu.findItem(R.id.new_window_context_menu_id).setVisible(
  199. false);
  200. }
  201. if (mContextHeader == null) {
  202. mContextHeader = new BookmarkItem(BrowserBookmarksPage.this);
  203. } else if (mContextHeader.getParent() != null) {
  204. ((ViewGroup) mContextHeader.getParent()).
  205. removeView(mContextHeader);
  206. }
  207. if (mViewMode == BookmarkViewMode.GRID) {
  208. mBookmarksAdapter.populateBookmarkItem(mContextHeader,
  209. i.position);
  210. } else {
  211. BookmarkItem b = (BookmarkItem) i.targetView;
  212. b.copyTo(mContextHeader);
  213. }
  214. menu.setHeaderView(mContextHeader);
  215. }
  216. /**
  217. * Create a new BrowserBookmarksPage.
  218. */
  219. @Override
  220. protected void onCreate(Bundle icicle) {
  221. super.onCreate(icicle);
  222. if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
  223. mCreateShortcut = true;
  224. }
  225. mDisableNewWindow = getIntent().getBooleanExtra("disable_new_window",
  226. false);
  227. mMostVisited = getIntent().getBooleanExtra("mostVisited", false);
  228. if (mCreateShortcut) {
  229. setTitle(R.string.browser_bookmarks_page_bookmarks_text);
  230. }
  231. mBookmarksAdapter = new BrowserBookmarksAdapter(this,
  232. getIntent().getStringExtra("url"),
  233. getIntent().getStringExtra("title"),
  234. (Bitmap) getIntent().getParcelableExtra("thumbnail"),
  235. mCreateShortcut,
  236. mMostVisited);
  237. setContentView(R.layout.empty_history);
  238. mEmptyView = findViewById(R.id.empty_view);
  239. mEmptyView.setVisibility(View.GONE);
  240. SharedPreferences p = getPreferences(MODE_PRIVATE);
  241. // See if the user has set a preference for the view mode of their
  242. // bookmarks. Otherwise default to grid mode.
  243. BookmarkViewMode preference = BookmarkViewMode.NONE;
  244. if (mMostVisited) {
  245. // For the most visited page, only use list mode.
  246. preference = BookmarkViewMode.LIST;
  247. } else {
  248. preference = BookmarkViewMode.values()[p.getInt(
  249. PREF_BOOKMARK_VIEW_MODE, BookmarkViewMode.GRID.ordinal())];
  250. }
  251. switchViewMode(preference);
  252. }
  253. /**
  254. * Set the ContentView to be either the grid of thumbnails or the vertical
  255. * list.
  256. */
  257. private void switchViewMode(BookmarkViewMode gridMode) {
  258. if (mViewMode == gridMode) {
  259. return;
  260. }
  261. mViewMode = gridMode;
  262. // Update the preferences to make the new view mode sticky.
  263. Editor ed = getPreferences(MODE_PRIVATE).edit();
  264. if (mMostVisited) {
  265. ed.putInt(PREF_MOST_VISITED_VIEW_MODE, mViewMode.ordinal());
  266. } else {
  267. ed.putInt(PREF_BOOKMARK_VIEW_MODE, mViewMode.ordinal());
  268. }
  269. ed.commit();
  270. mBookmarksAdapter.switchViewMode(gridMode);
  271. if (mViewMode == BookmarkViewMode.GRID) {
  272. if (mGridPage == null) {
  273. mGridPage = new GridView(this);
  274. mGridPage.setAdapter(mBookmarksAdapter);
  275. mGridPage.setOnItemClickListener(mListener);
  276. mGridPage.setNumColumns(GridView.AUTO_FIT);
  277. mGridPage.setColumnWidth(
  278. BrowserActivity.getDesiredThumbnailWidth(this));
  279. mGridPage.setFocusable(true);
  280. mGridPage.setFocusableInTouchMode(true);
  281. mGridPage.setSelector(android.R.drawable.gallery_thumb);
  282. float density = getResources().getDisplayMetrics().density;
  283. mGridPage.setVerticalSpacing((int) (14 * density));
  284. mGridPage.setHorizontalSpacing((int) (8 * density));
  285. mGridPage.setStretchMode(GridView.STRETCH_SPACING);
  286. mGridPage.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
  287. mGridPage.setDrawSelectorOnTop(true);
  288. if (mMostVisited) {
  289. mGridPage.setEmptyView(mEmptyView);
  290. }
  291. if (!mCreateShortcut) {
  292. mGridPage.setOnCreateContextMenuListener(this);
  293. }
  294. }
  295. addContentView(mGridPage, FULL_SCREEN_PARAMS);
  296. if (mVerticalList != null) {
  297. ViewGroup parent = (ViewGroup) mVerticalList.getParent();
  298. if (parent != null) {
  299. parent.removeView(mVerticalList);
  300. }
  301. }
  302. } else {
  303. if (null == mVerticalList) {
  304. ListView listView = new ListView(this);
  305. listView.setAdapter(mBookmarksAdapter);
  306. listView.setDrawSelectorOnTop(false);
  307. listView.setVerticalScrollBarEnabled(true);
  308. listView.setOnItemClickListener(mListener);
  309. if (mMostVisited) {
  310. listView.setEmptyView(mEmptyView);
  311. }
  312. if (!mCreateShortcut) {
  313. listView.setOnCreateContextMenuListener(this);
  314. }
  315. mVerticalList = listView;
  316. }
  317. addContentView(mVerticalList, FULL_SCREEN_PARAMS);
  318. if (mGridPage != null) {
  319. ViewGroup parent = (ViewGroup) mGridPage.getParent();
  320. if (parent != null) {
  321. parent.removeView(mGridPage);
  322. }
  323. }
  324. }
  325. }
  326. private static final ViewGroup.LayoutParams FULL_SCREEN_PARAMS
  327. = new ViewGroup.LayoutParams(
  328. ViewGroup.LayoutParams.FILL_PARENT,
  329. ViewGroup.LayoutParams.FILL_PARENT);
  330. private static final int SAVE_CURRENT_PAGE = 1000;
  331. private final Handler mHandler = new Handler() {
  332. @Override
  333. public void handleMessage(Message msg) {
  334. if (msg.what == SAVE_CURRENT_PAGE) {
  335. saveCurrentPage();
  336. }
  337. }
  338. };
  339. private AdapterView.OnItemClickListener mListener = new AdapterView.OnItemClickListener() {
  340. public void onItemClick(AdapterView parent, View v, int position, long id) {
  341. // It is possible that the view has been canceled when we get to
  342. // this point as back has a higher priority
  343. if (mCanceled) {
  344. android.util.Log.e(LOGTAG, "item clicked when dismissing");
  345. return;
  346. }
  347. if (!mCreateShortcut) {
  348. if (0 == position && !mMostVisited) {
  349. // XXX: Work-around for a framework issue.
  350. mHandler.sendEmptyMessage(SAVE_CURRENT_PAGE);
  351. } else {
  352. loadUrl(position);
  353. }
  354. } else {
  355. final Intent intent = createShortcutIntent(position);
  356. setResultToParent(RESULT_OK, intent);
  357. finish();
  358. }
  359. }
  360. };
  361. private Intent createShortcutIntent(int position) {
  362. String url = getUrl(position);
  363. String title = getBookmarkTitle(position);
  364. Bitmap touchIcon = getTouchIcon(position);
  365. final Intent i = new Intent();
  366. final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW,
  367. Uri.parse(url));
  368. long urlHash = url.hashCode();
  369. long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
  370. shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID,
  371. Long.toString(uniqueId));
  372. i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  373. i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
  374. // Use the apple-touch-icon if available
  375. if (touchIcon != null) {
  376. // Make a copy so we can modify the pixels.
  377. Bitmap copy = touchIcon.copy(Bitmap.Config.ARGB_8888, true);
  378. Canvas canvas = new Canvas(copy);
  379. // Construct a path from a round rect. This will allow drawing with
  380. // an inverse fill so we can punch a hole using the round rect.
  381. Path path = new Path();
  382. path.setFillType(Path.FillType.INVERSE_WINDING);
  383. RectF rect = new RectF(0, 0, touchIcon.getWidth(),
  384. touchIcon.getHeight());
  385. rect.inset(1, 1);
  386. path.addRoundRect(rect, 8f, 8f, Path.Direction.CW);
  387. // Construct a paint that clears the outside of the rectangle and
  388. // draw.
  389. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  390. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
  391. canvas.drawPath(path, paint);
  392. i.putExtra(Intent.EXTRA_SHORTCUT_ICON, copy);
  393. } else {
  394. Bitmap favicon = getFavicon(position);
  395. if (favicon == null) {
  396. i.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
  397. Intent.ShortcutIconResource.fromContext(
  398. BrowserBookmarksPage.this,
  399. R.drawable.ic_launcher_shortcut_browser_bookmark));
  400. } else {
  401. Bitmap icon = BitmapFactory.decodeResource(getResources(),
  402. R.drawable.ic_launcher_shortcut_browser_bookmark);
  403. // Make a copy of the regular icon so we can modify the pixels.
  404. Bitmap copy = icon.copy(Bitmap.Config.ARGB_8888, true);
  405. Canvas canvas = new Canvas(copy);
  406. // Make a Paint for the white background rectangle and for
  407. // filtering the favicon.
  408. Paint p = new Paint(Paint.ANTI_ALIAS_FLAG
  409. | Paint.FILTER_BITMAP_FLAG);
  410. p.setStyle(Paint.Style.FILL_AND_STROKE);
  411. p.setColor(Color.WHITE);
  412. // Create a rectangle that is slightly wider than the favicon
  413. final float iconSize = 16; // 16x16 favicon
  414. final float padding = 2; // white padding around icon
  415. final float rectSize = iconSize + 2 * padding;
  416. final float y = icon.getHeight() - rectSize;
  417. RectF r = new RectF(0, y, rectSize, y + rectSize);
  418. // Draw a white rounded rectangle behind the favicon
  419. canvas.drawRoundRect(r, 2, 2, p);
  420. // Draw the favicon in the same rectangle as the rounded
  421. // rectangle but inset by the padding
  422. // (results in a 16x16 favicon).
  423. r.inset(padding, padding);
  424. canvas.drawBitmap(favicon, null, r, p);
  425. i.putExtra(Intent.EXTRA_SHORTCUT_ICON, copy);
  426. }
  427. }
  428. // Do not allow duplicate items
  429. i.putExtra("duplicate", false);
  430. return i;
  431. }
  432. private void saveCurrentPage() {
  433. Intent i = new Intent(BrowserBookmarksPage.this,
  434. AddBookmarkPage.class);
  435. i.putExtras(getIntent());
  436. startActivityForResult(i, BOOKMARKS_SAVE);
  437. }
  438. private void loadUrl(int position) {
  439. Intent intent = (new Intent()).setAction(getUrl(position));
  440. setResultToParent(RESULT_OK, intent);
  441. finish();
  442. }
  443. @Override
  444. public boolean onCreateOptionsMenu(Menu menu) {
  445. boolean result = super.onCreateOptionsMenu(menu);
  446. if (!mCreateShortcut && !mMostVisited) {
  447. MenuInflater inflater = getMenuInflater();
  448. inflater.inflate(R.menu.bookmarks, menu);
  449. return true;
  450. }
  451. return result;
  452. }
  453. @Override
  454. public boolean onPrepareOptionsMenu(Menu menu) {
  455. boolean result = super.onPrepareOptionsMenu(menu);
  456. if (mCreateShortcut || mMostVisited
  457. || mBookmarksAdapter.getCount() == 0) {
  458. // No need to show the menu if there are no items.
  459. return result;
  460. }
  461. MenuItem switchItem = menu.findItem(R.id.switch_mode_menu_id);
  462. int titleResId;
  463. int iconResId;
  464. if (mViewMode == BookmarkViewMode.GRID) {
  465. titleResId = R.string.switch_to_list;
  466. iconResId = R.drawable.ic_menu_list;
  467. } else {
  468. titleResId = R.string.switch_to_thumbnails;
  469. iconResId = R.drawable.ic_menu_thumbnail;
  470. }
  471. switchItem.setTitle(titleResId);
  472. switchItem.setIcon(iconResId);
  473. return true;
  474. }
  475. @Override
  476. public boolean onOptionsItemSelected(MenuItem item) {
  477. switch (item.getItemId()) {
  478. case R.id.new_context_menu_id:
  479. saveCurrentPage();
  480. break;
  481. case R.id.switch_mode_menu_id:
  482. if (mViewMode == BookmarkViewMode.GRID) {
  483. switchViewMode(BookmarkViewMode.LIST);
  484. } else {
  485. switchViewMode(BookmarkViewMode.GRID);
  486. }
  487. break;
  488. default:
  489. return super.onOptionsItemSelected(item);
  490. }
  491. return true;
  492. }
  493. private void openInNewWindow(int position) {
  494. Bundle b = new Bundle();
  495. b.putBoolean("new_window", true);
  496. setResultToParent(RESULT_OK,
  497. (new Intent()).setAction(getUrl(position)).putExtras(b));
  498. finish();
  499. }
  500. private void editBookmark(int position) {
  501. Intent intent = new Intent(BrowserBookmarksPage.this,
  502. AddBookmarkPage.class);
  503. intent.putExtra("bookmark", getRow(position));
  504. startActivityForResult(intent, BOOKMARKS_SAVE);
  505. }
  506. @Override
  507. protected void onActivityResult(int requestCode, int resultCode,
  508. Intent data) {
  509. switch(requestCode) {
  510. case BOOKMARKS_SAVE:
  511. if (resultCode == RESULT_OK) {
  512. Bundle extras;
  513. if (data != null && (extras = data.getExtras()) != null) {
  514. // If there are extras, then we need to save
  515. // the edited bookmark. This is done in updateRow()
  516. String title = extras.getString("title");
  517. String url = extras.getString("url");
  518. if (title != null && url != null) {
  519. mBookmarksAdapter.updateRow(extras);
  520. }
  521. } else {
  522. // extras == null then a new bookmark was added to
  523. // the database.
  524. refreshList();
  525. }
  526. }
  527. break;
  528. default:
  529. break;
  530. }
  531. }
  532. private void displayRemoveBookmarkDialog(int position) {
  533. // Put up a dialog asking if the user really wants to
  534. // delete the bookmark
  535. final int deletePos = position;
  536. new AlertDialog.Builder(this)
  537. .setTitle(R.string.delete_bookmark)
  538. .setIcon(android.R.drawable.ic_dialog_alert)
  539. .setMessage(getText(R.string.delete_bookmark_warning).toString().replace(
  540. "%s", getBookmarkTitle(deletePos)))
  541. .setPositiveButton(R.string.ok,
  542. new DialogInterface.OnClickListener() {
  543. public void onClick(DialogInterface dialog, int whichButton) {
  544. deleteBookmark(deletePos);
  545. }
  546. })
  547. .setNegativeButton(R.string.cancel, null)
  548. .show();
  549. }
  550. /**
  551. * Refresh the shown list after the database has changed.
  552. */
  553. private void refreshList() {
  554. mBookmarksAdapter.refreshList();
  555. }
  556. /**
  557. * Return a hashmap representing the currently highlighted row.
  558. */
  559. public Bundle getRow(int position) {
  560. return mBookmarksAdapter.getRow(position);
  561. }
  562. /**
  563. * Return the url of the currently highlighted row.
  564. */
  565. public String getUrl(int position) {
  566. return mBookmarksAdapter.getUrl(position);
  567. }
  568. /**
  569. * Return the favicon of the currently highlighted row.
  570. */
  571. public Bitmap getFavicon(int position) {
  572. return mBookmarksAdapter.getFavicon(position);
  573. }
  574. private Bitmap getTouchIcon(int position) {
  575. return mBookmarksAdapter.getTouchIcon(position);
  576. }
  577. private void copy(CharSequence text) {
  578. /*
  579. try {
  580. IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard"));
  581. if (clip != null) {
  582. clip.setClipboardText(text);
  583. }
  584. } catch (android.os.RemoteException e) {
  585. Log.e(LOGTAG, "Copy failed", e);
  586. }
  587. */
  588. }
  589. public String getBookmarkTitle(int position) {
  590. return mBookmarksAdapter.getTitle(position);
  591. }
  592. /**
  593. * Delete the currently highlighted row.
  594. */
  595. public void deleteBookmark(int position) {
  596. mBookmarksAdapter.deleteRow(position);
  597. }
  598. @Override
  599. public void onBackPressed() {
  600. setResultToParent(RESULT_CANCELED, null);
  601. mCanceled = true;
  602. super.onBackPressed();
  603. }
  604. // This Activity is generally a sub-Activity of CombinedHistoryActivity. In
  605. // that situation, we need to pass our result code up to our parent.
  606. // However, if someone calls this Activity directly, then this has no
  607. // parent, and it needs to set it on itself.
  608. private void setResultToParent(int resultCode, Intent data) {
  609. Activity a = getParent() == null ? this : getParent();
  610. a.setResult(resultCode, data);
  611. }
  612. }