Ejemplo n.º 1
0
  public void onCreate(final Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();

    final String html = intent.getStringExtra("html");
    final String title = intent.getStringExtra("title");
    setTitle(title);

    if (html == null) {
      BugReportActivity.handleGlobalError(this, "No HTML");
    }

    webView = WebViewFragment.newInstanceHtml(html);

    setContentView(View.inflate(this, R.layout.main_single, null));

    getSupportFragmentManager().beginTransaction().add(R.id.main_single_frame, webView).commit();
  }
Ejemplo n.º 2
0
  public synchronized void pruneCache() {

    try {

      final HashSet<Long> currentFiles = new HashSet<Long>(128);

      final File externalCacheDir = context.getExternalCacheDir();
      final File internalCacheDir = context.getCacheDir();

      if (externalCacheDir != null) {
        getCacheFileList(externalCacheDir, currentFiles);
      }

      if (internalCacheDir != null) {
        getCacheFileList(internalCacheDir, currentFiles);
      }

      final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
      final HashMap<Integer, Long> maxAge = PrefsUtility.pref_cache_maxage(context, prefs);

      final LinkedList<Long> filesToDelete = dbManager.getFilesToPrune(currentFiles, maxAge, 72);
      for (final long id : filesToDelete) {
        fileDeletionQueue.enqueue(id);
      }

    } catch (Throwable t) {
      BugReportActivity.handleGlobalError(context, t);
    }
  }
Ejemplo n.º 3
0
  public static synchronized void handleGlobalError(Context context, Throwable t) {

    if (t != null) {
      Log.e("BugReportActivity", "Handling exception", t);
    }

    handleGlobalError(context, new RRError(null, null, t));
  }
Ejemplo n.º 4
0
    public ReadableCacheFile getReadableCacheFile() throws IOException {

      if (readableCacheFile == null) {

        if (!request.isJson) {
          BugReportActivity.handleGlobalError(context, "Attempt to read cache file before closing");
        }

        try {
          os.flush();
          os.close();
        } catch (IOException e) {
          Log.e("RR DEBUG getReadableCacheFile", "Error closing " + cacheFileId);
          throw e;
        }
      }

      return readableCacheFile;
    }
Ejemplo n.º 5
0
  private synchronized void reloadAccounts(final SQLiteDatabase db) {

    final String[] fields = new String[] {FIELD_USERNAME, FIELD_REFRESH_TOKEN, FIELD_PRIORITY};

    final Cursor cursor = db.query(TABLE, fields, null, null, null, null, FIELD_PRIORITY + " ASC");

    accountsCache = new LinkedList<>();
    defaultAccountCache = null;

    // TODO handle null? can this even happen?
    if (cursor != null) {

      while (cursor.moveToNext()) {

        final String username = cursor.getString(0);

        final RedditOAuth.RefreshToken refreshToken;
        if (cursor.isNull(1)) {
          refreshToken = null;
        } else {
          refreshToken = new RedditOAuth.RefreshToken(cursor.getString(1));
        }

        final long priority = cursor.getLong(2);

        final RedditAccount account = new RedditAccount(username, refreshToken, priority);
        accountsCache.add(account);

        if (defaultAccountCache == null || account.priority < defaultAccountCache.priority) {
          defaultAccountCache = account;
        }
      }

      cursor.close();

    } else {
      BugReportActivity.handleGlobalError(context, "Cursor was null after query");
    }
  }
Ejemplo n.º 6
0
 public static synchronized void handleGlobalError(Context context, String text) {
   handleGlobalError(context, new RRError(text, null, new RuntimeException()));
 }