List of usage examples for android.provider Browser updateVisitedHistory
public static final void updateVisitedHistory(ContentResolver cr, String url, boolean real)
From source file:com.andrewshu.android.reddit.common.Common.java
/** * // w ww . j a v a 2 s.c o m * @param url * @param context * @param requireNewTask set this to true if context is not an Activity * @param bypassParser * @param useExternalBrowser */ public static void launchBrowser(Context context, String url, String threadUrl, boolean requireNewTask, boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) { try { if (saveHistory) { Browser.updateVisitedHistory(context.getContentResolver(), url, true); } } catch (Exception ex) { if (Constants.LOGGING) Log.i(TAG, "Browser.updateVisitedHistory error", ex); } Uri uri = Uri.parse(url); if (!bypassParser) { if (Util.isRedditUri(uri)) { String path = uri.getPath(); Matcher matcher = COMMENT_LINK.matcher(path); if (matcher.matches()) { if (matcher.group(3) != null || matcher.group(2) != null) { CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } matcher = REDDIT_LINK.matcher(path); if (matcher.matches()) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } matcher = USER_LINK.matcher(path); if (matcher.matches()) { Intent intent = new Intent(context, ProfileActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } else if (Util.isRedditShortenedUri(uri)) { String path = uri.getPath(); if (path.equals("") || path.equals("/")) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { // Assume it points to a thread aka CommentsList CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } return; } } uri = Util.optimizeMobileUri(uri); // Some URLs should always be opened externally, if BrowserActivity doesn't support their content. if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri)) useExternalBrowser = true; if (useExternalBrowser) { Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); if (requireNewTask) browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(browser); } else { Intent browser = new Intent(context, BrowserActivity.class); browser.setData(uri); if (threadUrl != null) browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl); if (requireNewTask) browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(browser); } }
From source file:in.shick.diode.common.Common.java
/** * * @param settings The {@link RedditSettings} object used to for preference-retrieving. * @param context The {@link Context} object to use, as necessary. * @param url The URL to launch in the browser. * @param threadUrl The (optional) URL of the comments thread for the 'View comments' menu option in the browser. * @param requireNewTask set this to true if context is not an Activity * @param bypassParser Should URI parsing be bypassed, usually true in the case an external browser is being launched. * @param useExternalBrowser Should the external browser app be launched instead of the internal one. * @param saveHistory Should the URL be entered into the browser history? *///w ww . j a v a 2 s .c o m public static void launchBrowser(RedditSettings settings, Context context, String url, String threadUrl, boolean requireNewTask, boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) { try { if (saveHistory) { Browser.updateVisitedHistory(context.getContentResolver(), url, true); } } catch (Exception ex) { if (Constants.LOGGING) Log.i(TAG, "Browser.updateVisitedHistory error", ex); } boolean forceDesktopUserAgent = false; if (!bypassParser && settings != null && settings.isLoadImgurImagesDirectly()) { Matcher m = m_imgurRegex.matcher(url); if (m.matches() && m.group(1) != null) { // We've determined it's an imgur link, no need to parse it further. bypassParser = true; url = "http://i.imgur.com/" + m.group(1); if (!StringUtils.isEmpty(m.group(2))) { String extension = m.group(2); if (".gifv".equalsIgnoreCase(extension)) { extension = ".mp4"; } url += extension; } else { // Need to give images an extension, or imgur will redirect to the mobile site. url += ".png"; } forceDesktopUserAgent = true; } } if (settings != null && settings.isLoadVredditLinksDirectly()) { if (url.contains("v.redd.it")) { url += "/DASH_600_K"; } } Uri uri = Uri.parse(url); if (!bypassParser) { if (Util.isRedditUri(uri)) { String path = uri.getPath(); Matcher matcher = COMMENT_LINK.matcher(path); if (matcher.matches()) { if (matcher.group(3) != null || matcher.group(2) != null) { CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } matcher = REDDIT_LINK.matcher(path); if (matcher.matches()) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } matcher = USER_LINK.matcher(path); if (matcher.matches()) { Intent intent = new Intent(context, ProfileActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } else if (Util.isRedditShortenedUri(uri)) { String path = uri.getPath(); if (path.equals("") || path.equals("/")) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { // Assume it points to a thread aka CommentsList CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } return; } } uri = Util.optimizeMobileUri(uri); // Some URLs should always be opened externally, if BrowserActivity doesn't support their content. if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri)) { useExternalBrowser = true; } if (useExternalBrowser) { Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); if (requireNewTask) { browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(browser); } else { Intent browser = new Intent(context, BrowserActivity.class); browser.setData(uri); if (forceDesktopUserAgent) { browser.putExtra(Constants.EXTRA_FORCE_UA_STRING, "desktop"); } if (threadUrl != null) { browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl); } if (requireNewTask) { browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(browser); } }
From source file:com.dish.browser.activity.BrowserActivity.java
public void addItemToHistory(final String title, final String url) { Runnable update = new Runnable() { @Override/*from ww w. jav a 2s. c om*/ public void run() { if (isSystemBrowserAvailable() && mPreferences.getSyncHistoryEnabled()) { try { Browser.updateVisitedHistory(getContentResolver(), url, true); } catch (NullPointerException ignored) { } } try { if (mHistoryDatabase == null) { mHistoryDatabase = HistoryDatabase.getInstance(mActivity); } mHistoryDatabase.visitHistoryItem(url, title); } catch (IllegalStateException e) { Log.e(Constants.TAG, "IllegalStateException in updateHistory"); } catch (NullPointerException e) { Log.e(Constants.TAG, "NullPointerException in updateHistory"); } catch (SQLiteException e) { Log.e(Constants.TAG, "SQLiteException in updateHistory"); } } }; if (url != null && !url.startsWith(Constants.FILE)) { new Thread(update).start(); } }