Beispiel #1
0
 public static void setTextColorFromTheme(int theme, Resources resources, TextView... textViews) {
   int color;
   if (Util.isLightTheme(theme))
     color = resources.getColor(R.color.reddit_light_dialog_text_color);
   else color = resources.getColor(R.color.reddit_dark_dialog_text_color);
   for (TextView textView : textViews) textView.setTextColor(color);
 }
Beispiel #2
0
 /** Set the Drawable for the list selector etc. based on the current theme. */
 public static void updateListDrawables(ListActivity la, int theme) {
   ListView lv = la.getListView();
   if (Util.isLightTheme(theme)) {
     lv.setBackgroundResource(android.R.color.background_light);
     lv.setSelector(R.drawable.list_selector_blue);
   } else /* if (Common.isDarkTheme(theme)) */ {
     lv.setSelector(android.R.drawable.list_selector_background);
   }
 }
  @Override
  public Boolean doInBackground(Void... voidz) {
    HttpEntity entity = null;
    BufferedReader in = null;
    try {
      HttpGet request = new HttpGet(_mCheckUrl);
      HttpResponse response = _mClient.execute(request);
      if (!Util.isHttpStatusOK(response)) {
        throw new HttpException("bad HTTP response: " + response);
      }
      entity = response.getEntity();
      in = new BufferedReader(new InputStreamReader(entity.getContent()));
      String line;

      while ((line = in.readLine()) != null) {
        Matcher idenMatcher = CAPTCHA_IDEN_PATTERN.matcher(line);
        Matcher urlMatcher = CAPTCHA_IMAGE_PATTERN.matcher(line);
        if (idenMatcher.find() && urlMatcher.find()) {
          _mCaptchaIden = idenMatcher.group(1);
          _mCaptchaUrl = urlMatcher.group(2);
          saveState();
          return true;
        }
      }

      _mCaptchaIden = null;
      _mCaptchaUrl = null;
      saveState();
      return false;

    } catch (Exception e) {
      if (Constants.LOGGING)
        Log.e(TAG, "Error accessing " + _mCheckUrl + " to check for CAPTCHA", e);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (Exception e2) {
          if (Constants.LOGGING) Log.e(TAG, "in.Close()", e2);
        }
      }
      if (entity != null) {
        try {
          entity.consumeContent();
        } catch (Exception e2) {
          if (Constants.LOGGING) Log.e(TAG, "entity.consumeContent()", e2);
        }
      }
    }
    // mCaptchaIden and mCaptchaUrl are null if not required
    // so on error, set them to some non-null dummy value
    _mCaptchaIden = "";
    _mCaptchaUrl = "";
    saveState();
    return null;
  }
 private void enableLoadingScreen() {
   if (Util.isLightTheme(mSettings.getTheme())) {
     setContentView(R.layout.loading_light);
   } else {
     setContentView(R.layout.loading_dark);
   }
   synchronized (ADAPTER_LOCK) {
     if (mSubredditsAdapter != null) mSubredditsAdapter.mLoading = true;
   }
   getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
 }
Beispiel #5
0
  /**
   * @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);
            Activity ac = (Activity) context;
            ac.startActivityForResult(intent, 0);
            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);
          Activity ac = (Activity) context;
          ac.startActivityForResult(intent, 0);
          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);
          Activity ac = (Activity) context;
          ac.startActivityForResult(intent, 0);
          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);
          Activity ac = (Activity) context;
          ac.startActivityForResult(intent, 0);
        } 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);
          Activity ac = (Activity) context;
          ac.startActivityForResult(intent, 0);
        }
        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);
      Activity ac = (Activity) context;
      ac.startActivityForResult(browser, 0);
    } 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);
      Activity ac = (Activity) context;
      ac.startActivityForResult(browser, 0);
    }
  }
Beispiel #6
0
  public static void updateNextPreviousButtons(
      ListActivity act,
      View nextPreviousView,
      String after,
      String before,
      int count,
      RedditSettings settings,
      OnClickListener downloadAfterOnClickListener,
      OnClickListener downloadBeforeOnClickListener) {
    boolean shouldShow = after != null || before != null;
    Button nextButton = null;
    Button previousButton = null;

    // If alwaysShowNextPrevious, use the navbar
    if (settings.isAlwaysShowNextPrevious()) {
      nextPreviousView = act.findViewById(R.id.next_previous_layout);
      if (nextPreviousView == null) return;
      View nextPreviousBorder = act.findViewById(R.id.next_previous_border_top);

      if (shouldShow) {
        if (nextPreviousView != null && nextPreviousBorder != null) {
          if (Util.isLightTheme(settings.getTheme())) {
            nextPreviousView.setBackgroundResource(android.R.color.background_light);
            nextPreviousBorder.setBackgroundResource(R.color.black);
          } else {
            nextPreviousBorder.setBackgroundResource(R.color.white);
          }
          nextPreviousView.setVisibility(View.VISIBLE);
        }
        // update the "next 25" and "prev 25" buttons
        nextButton = (Button) act.findViewById(R.id.next_button);
        previousButton = (Button) act.findViewById(R.id.previous_button);
      } else {
        nextPreviousView.setVisibility(View.GONE);
      }
    }
    // Otherwise we are using the ListView footer
    else {
      if (nextPreviousView == null) return;
      if (shouldShow && nextPreviousView.getVisibility() != View.VISIBLE) {
        nextPreviousView.setVisibility(View.VISIBLE);
      } else if (!shouldShow && nextPreviousView.getVisibility() == View.VISIBLE) {
        nextPreviousView.setVisibility(View.GONE);
      }
      // update the "next 25" and "prev 25" buttons
      nextButton = (Button) nextPreviousView.findViewById(R.id.next_button);
      previousButton = (Button) nextPreviousView.findViewById(R.id.previous_button);
    }
    if (nextButton != null) {
      if (after != null) {
        nextButton.setVisibility(View.VISIBLE);
        nextButton.setOnClickListener(downloadAfterOnClickListener);
      } else {
        nextButton.setVisibility(View.INVISIBLE);
      }
    }
    if (previousButton != null) {
      if (before != null && count != Constants.DEFAULT_THREAD_DOWNLOAD_LIMIT) {
        previousButton.setVisibility(View.VISIBLE);
        previousButton.setOnClickListener(downloadBeforeOnClickListener);
      } else {
        previousButton.setVisibility(View.INVISIBLE);
      }
    }
  }
 private void returnSubreddit(String subreddit) {
   Intent intent = new Intent();
   intent.setData(Util.createSubredditUri(subreddit));
   setResult(RESULT_OK, intent);
   finish();
 }