Example #1
0
  public static Uri saveImage(Bitmap finalBitmap, String d, Context context) {
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/Talon");
    myDir.mkdirs();
    String fname = d + ".jpg";
    File file = new File(myDir, fname);
    if (file.exists()) file.delete();
    try {
      FileOutputStream out = new FileOutputStream(file);
      finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
      out.flush();
      out.close();

    } catch (Exception e) {
      Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
      e.printStackTrace();
    }

    // context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +
    // Environment.getExternalStorageDirectory())));
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    Toast.makeText(
            context, context.getResources().getString(R.string.save_image), Toast.LENGTH_SHORT)
        .show();

    return Uri.fromFile(file);
  }
Example #2
0
  public static String getPath(Uri uri, Context context) {
    String[] filePathColumn = {MediaStore.Images.Media.DATA};
    String filePath = null;

    try {
      Cursor cursor = context.getContentResolver().query(uri, filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      filePath = cursor.getString(columnIndex);
      cursor.close();
    } catch (Exception e) {
      e.printStackTrace();
      filePath = uri.getPath();
    }

    if (filePath == null) {
      filePath = uri.getPath();
      Log.v("talon_file_path", filePath);
    }

    return filePath;
  }
Example #3
0
  public static boolean trimDatabase(Context context, int account) {
    try {
      AppSettings settings = AppSettings.getInstance(context);
      SharedPreferences sharedPrefs =
          context.getSharedPreferences(
              "com.klinker.android.twitter_world_preferences",
              Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

      InteractionsDataSource interactions = InteractionsDataSource.getInstance(context);
      Cursor inters = interactions.getCursor(account);

      if (inters.getCount() > 50) {
        if (inters.moveToPosition(inters.getCount() - 50)) {
          do {
            interactions.deleteInteraction(
                inters.getLong(inters.getColumnIndex(InteractionsSQLiteHelper.COLUMN_ID)));
          } while (inters.moveToPrevious());
        }
      }

      inters.close();

      HomeDataSource home = HomeDataSource.getInstance(context);

      home.deleteDups(settings.currentAccount);

      Cursor timeline = home.getTrimmingCursor(account);

      Log.v("trimming", "timeline size: " + timeline.getCount());
      Log.v("trimming", "timeline settings size: " + settings.timelineSize);
      if (timeline.getCount() > settings.timelineSize) {

        if (timeline.moveToPosition(timeline.getCount() - settings.timelineSize)) {
          Log.v("trimming", "in the trim section");
          do {
            home.deleteTweet(
                timeline.getLong(timeline.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)));
          } while (timeline.moveToPrevious());
        }
      }

      timeline.close();

      // trimming the lists
      ListDataSource lists = ListDataSource.getInstance(context);

      int account1List1 = sharedPrefs.getInt("account_" + account + "_list_1", 0);
      int account1List2 = sharedPrefs.getInt("account_" + account + "_list_2", 0);

      lists.deleteDups(account1List1);
      lists.deleteDups(account1List2);

      Cursor list1 = lists.getTrimmingCursor(account1List1);

      Log.v("trimming", "lists size: " + list1.getCount());
      Log.v("trimming", "lists settings size: " + 400);
      if (list1.getCount() > 400) {

        if (list1.moveToPosition(list1.getCount() - 400)) {
          Log.v("trimming", "in the trim section");
          do {
            lists.deleteTweet(
                list1.getLong(list1.getColumnIndex(ListSQLiteHelper.COLUMN_TWEET_ID)));
          } while (list1.moveToPrevious());
        }
      }
      list1.close();

      Cursor list2 = lists.getTrimmingCursor(account1List2);

      Log.v("trimming", "lists size: " + list2.getCount());
      Log.v("trimming", "lists settings size: " + 400);
      if (list2.getCount() > 400) {

        if (list2.moveToPosition(list2.getCount() - 400)) {
          Log.v("trimming", "in the trim section");
          do {
            lists.deleteTweet(
                list2.getLong(list2.getColumnIndex(ListSQLiteHelper.COLUMN_TWEET_ID)));
          } while (list2.moveToPrevious());
        }
      }

      list2.close();

      MentionsDataSource mentions = MentionsDataSource.getInstance(context);

      mentions.deleteDups(settings.currentAccount);

      timeline = mentions.getTrimmingCursor(account);

      Log.v("trimming", "mentions size: " + timeline.getCount());
      Log.v("trimming", "mentions settings size: " + settings.mentionsSize);
      if (timeline.getCount() > settings.mentionsSize) {

        if (timeline.moveToPosition(timeline.getCount() - settings.mentionsSize)) {
          do {
            mentions.deleteTweet(
                timeline.getLong(timeline.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)));
          } while (timeline.moveToPrevious());
        }
      }

      timeline.close();

      DMDataSource dm = DMDataSource.getInstance(context);

      dm.deleteDups(settings.currentAccount);

      timeline = dm.getCursor(account);

      Log.v("trimming", "dm size: " + timeline.getCount());
      Log.v("trimming", "dm settings size: " + settings.dmSize);

      if (timeline.getCount() > settings.dmSize) {
        if (timeline.moveToPosition(timeline.getCount() - settings.dmSize)) {
          do {
            dm.deleteTweet(
                timeline.getLong(timeline.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)));
          } while (timeline.moveToPrevious());
        }
      }

      timeline.close();

      HashtagDataSource hashtag = HashtagDataSource.getInstance(context);

      timeline = hashtag.getCursor("");

      Log.v("trimming", "hashtag size: " + timeline.getCount());

      if (timeline.getCount() > 300) {
        if (timeline.moveToPosition(timeline.getCount() - 300)) {
          do {
            hashtag.deleteTag(
                timeline.getString(timeline.getColumnIndex(HashtagSQLiteHelper.COLUMN_TAG)));
          } while (timeline.moveToPrevious());
        }
      }

      timeline.close();

      ActivityDataSource activity = ActivityDataSource.getInstance(context);
      Cursor actCurs = activity.getCursor(account);

      Log.v("trimming", "activity size: " + actCurs.getCount());
      Log.v("trimming", "activity settings size: " + 200);
      if (actCurs.getCount() > 200) {
        int toDelete = actCurs.getCount() - 200;
        if (actCurs.moveToFirst()) {
          do {
            activity.deleteItem(
                actCurs.getLong(actCurs.getColumnIndex(ActivitySQLiteHelper.COLUMN_ID)));
            toDelete--;
          } while (timeline.moveToNext() && toDelete > 0);
        }
      }

      actCurs.close();
      FavoriteTweetsDataSource favtweets = FavoriteTweetsDataSource.getInstance(context);
      favtweets.deleteDups(settings.currentAccount);

      timeline = favtweets.getCursor(account);
      Log.v("trimming", "favtweets size: " + timeline.getCount());
      Log.v("trimming", "favtweets settings size: " + 200);
      if (timeline.getCount() > 200) {

        if (timeline.moveToPosition(timeline.getCount() - 200)) {
          do {
            favtweets.deleteTweet(
                timeline.getLong(
                    timeline.getColumnIndex(FavoriteTweetsSQLiteHelper.COLUMN_TWEET_ID)));
          } while (timeline.moveToPrevious());
        }
      }

      timeline.close();

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }