/**
   * *********************************************************************************************
   * VOD시청
   */
  public void addWatchVod(Date watchDate, String assetId, String title) {
    // Realm Database **********************************************************************
    // Obtain a Realm instance
    Realm realm = Realm.getInstance(mContext);
    RealmResults<WatchVodObject> results = realm.where(WatchVodObject.class).findAll();
    long iSeq = 0;
    if (results == null) {
      //
    } else {
      if (results.size() == 0) {
        iSeq = 0;
      } else {
        iSeq = realm.where(WatchVodObject.class).maximumInt("iSeq") + 1;
      }
    }

    WatchVodObject obj = new WatchVodObject();
    obj.setiSeq((int) iSeq);
    obj.setdDate(watchDate);
    obj.setsAssetId(assetId);
    obj.setsTitle(title);
    realm.beginTransaction();
    WatchVodObject obj2 = realm.copyToRealm(obj);
    realm.commitTransaction();
    // Realm Database **********************************************************************
  }
  @Override
  protected void doOneByOneCrudRun(int count) throws Exception {
    final List<SimpleEntityNotNull> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
      list.add(SimpleEntityNotNullHelper.createEntity((long) i));
    }

    startClock();
    for (int i = 0; i < count; i++) {
      realm.beginTransaction();
      realm.copyToRealm(list.get(i));
      realm.commitTransaction();
    }
    stopClock(Benchmark.Type.ONE_BY_ONE_CREATE);

    startClock();
    for (int i = 0; i < count; i++) {
      realm.beginTransaction();
      realm.copyToRealmOrUpdate(list.get(i));
      realm.commitTransaction();
    }
    stopClock(Benchmark.Type.ONE_BY_ONE_UPDATE);

    deleteAll();
  }
Пример #3
0
  private void savePhotos() {
    try {
      saveMemo(1);

      realm.beginTransaction();
      Photo photo = new Photo();
      photo.setId(getPhotoId());
      photo.setSource("memo");
      photo.setCreateTime(new Date());
      photo.setCreateUser(ConstUtils.USER_NAME);
      photo.setMyPosition(ConstUtils.MY_POSITION);
      photo.setRelationId(addMemo.getId());
      Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
      Log.d("AddMemoActivity", "width: " + bitmap.getWidth());
      Log.d("AddMemoActivity", "height: " + bitmap.getHeight());
      if (bitmap.getWidth() < bitmap.getHeight()) {
        bitmap = ThumbnailUtils.extractThumbnail(bitmap, 660, 1173);
      } else {
        bitmap = ThumbnailUtils.extractThumbnail(bitmap, 1173, 660);
      }

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.JPEG, 95, bos); // 参数100表示不压缩
      byte[] photoBytes = bos.toByteArray();
      photo.setPhoto(photoBytes);
      realm.copyToRealm(photo);
      realm.commitTransaction();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
  public void loadData() {
    SimpleDateFormat formatIn = new SimpleDateFormat("MMMM d, yyyy");
    SimpleDateFormat formatOut = new SimpleDateFormat("MM/d/yy");
    ObjectMapper objectMapper = new ObjectMapper();
    JsonFactory jsonFactory = new JsonFactory();
    Random random = new Random();
    try {
      JsonParser jsonParserBlog =
          jsonFactory.createParser(getResources().openRawResource(R.raw.blog));
      List<Blog> entries =
          objectMapper.readValue(jsonParserBlog, new TypeReference<List<Blog>>() {});
      JsonParser jsonParserEmoji =
          jsonFactory.createParser(getResources().openRawResource(R.raw.emoji));
      List<String> emojies =
          objectMapper.readValue(jsonParserEmoji, new TypeReference<List<String>>() {});

      int numEmoji = emojies.size();
      for (Blog blog : entries) {
        blog.setEmoji(emojies.get(random.nextInt(numEmoji)));
        try {
          blog.setDate(formatOut.format(formatIn.parse(blog.getDate())));
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }
      Realm realm = Realm.getInstance(this);
      realm.beginTransaction();
      realm.copyToRealm(entries);
      realm.commitTransaction();
      realm.close();

    } catch (Exception e) {
      throw new IllegalStateException("Could not load blog data.");
    }
  }
Пример #5
0
  private void createTrackStats(String local_id, int type) {
    TrackStats stats = new TrackStats(local_id, type, android_id);

    realm.beginTransaction();
    realm.copyToRealm(stats);
    realm.commitTransaction();
  }
Пример #6
0
 /**
  * Create a new {@link RBookList} as a smart list.
  *
  * @param realm Instance of Realm to use.
  * @param listName Name to use for new smart list. Assumed to not already be in use.
  * @param realmUserQuery RealmUserQuery to use to get a RealmUserQuery string to store in the
  *     list. Can be null.
  * @return The newly created and persisted smart list.
  */
 public static RBookList createNewSmartList(
     Realm realm, String listName, RealmUserQuery realmUserQuery) {
   if (listName == null || listName.isEmpty())
     throw new IllegalArgumentException("listName must be non-null and non-empty.");
   realm.beginTransaction();
   RBookList newSmartList = realm.copyToRealm(new RBookList(listName, realmUserQuery));
   realm.commitTransaction();
   return newSmartList;
 }
Пример #7
0
 private void update(int type, String contents, Date reminderDate) {
   realm.beginTransaction();
   addMemo.setContents(contents);
   addMemo.setReminderDate(reminderDate);
   if (type == 1) {
     addMemo.setHasPhoto(true);
   } else if (type == 2) {
     addMemo.setHasVoice(true);
   }
   realm.copyToRealm(addMemo);
   realm.commitTransaction();
 }
Пример #8
0
 private void save(int type, String contents, Date reminderDate) {
   realm.beginTransaction();
   addMemo = new Memo();
   addMemo.setId(getMemoId());
   addMemo.setContents(contents);
   addMemo.setReminderDate(reminderDate);
   addMemo.setRepeat(((SpinnerItem) repeat.getSelectedItem()).getKey());
   addMemo.setCreateTime(new Date());
   addMemo.setCreateUser(ConstUtils.USER_NAME);
   if (type == 1) {
     addMemo.setHasPhoto(true);
   } else if (type == 2) {
     addMemo.setHasVoice(true);
   }
   realm.copyToRealm(addMemo);
   realm.commitTransaction();
 }
 private void populateCacheData(LocalCacheData realmCacheData, LocalCacheDataPOJO newCacheData) {
   realmCacheData.setCreationDate(generateCreationDate());
   if (newCacheData.getPersonIdsToPrayFor() != null) {
     List<String> personIdsToPrayFor = newCacheData.getPersonIdsToPrayFor();
     RealmList<RealmString> managedPersonIdsToPrayFor = new RealmList<>();
     for (String personIdToPrayFor : personIdsToPrayFor) {
       managedPersonIdsToPrayFor.add(realm.copyToRealm(new RealmString(personIdToPrayFor)));
     }
     realmCacheData.setPersonIdsToPrayFor(managedPersonIdsToPrayFor);
   }
   if (newCacheData.getScriptureCitation() != null)
     realmCacheData.setScriptureCitation(newCacheData.getScriptureCitation());
   if (newCacheData.getScriptureText() != null)
     realmCacheData.setScriptureText(newCacheData.getScriptureText());
   if (newCacheData.getScriptureJson() != null)
     realmCacheData.setScriptureJson(newCacheData.getScriptureJson());
   if (newCacheData.getVerseImageURL() != null)
     realmCacheData.setVerseImageURL(newCacheData.getVerseImageURL());
 }
  private void indexedStringEntityQueriesRun(int count) {
    // create entities
    List<IndexedStringEntity> entities = new ArrayList<>(count);
    String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(count);
    for (int i = 0; i < count; i++) {
      IndexedStringEntity entity = new IndexedStringEntity();
      entity.setId((long) i);
      entity.setIndexedString(fixedRandomStrings[i]);
      entities.add(entity);
    }
    log("Built entities.");

    // insert entities
    realm.beginTransaction();
    realm.copyToRealm(entities);
    realm.commitTransaction();
    log("Inserted entities.");

    // query for entities by indexed string at random
    int[] randomIndices = StringGenerator.getFixedRandomIndices(getQueryCount(), count - 1);

    startClock();
    for (int i = 0; i < getQueryCount(); i++) {
      int nextIndex = randomIndices[i];
      RealmQuery<IndexedStringEntity> query = realm.where(IndexedStringEntity.class);
      query.equalTo("indexedString", fixedRandomStrings[nextIndex]);
      RealmResults<IndexedStringEntity> result = query.findAll();
      for (int j = 0, resultSize = result.size(); j < resultSize; j++) {
        // actually get each entity so its object is reconstructed, same with properties
        IndexedStringEntity entity = result.get(j);
        entity.getId();
        entity.getIndexedString();
      }
    }
    stopClock(Benchmark.Type.QUERY_INDEXED);

    // delete all entities
    realm.beginTransaction();
    realm.delete(IndexedStringEntity.class);
    realm.commitTransaction();
    log("Deleted all entities.");
  }
Пример #11
0
  public static void updateLibrary(Context context, boolean rebuildStats) {
    Log.d(TAG, "updateLibrary() start");

    Realm realm = Realm.getInstance(Migration.getConfig(context));

    realm.beginTransaction();
    RealmResults<Track> res = realm.where(Track.class).findAll();
    for (int x = 0; x < res.size(); x++) {
      res.get(x).setIsAvailable(false);
    }
    realm.commitTransaction();

    String where = MediaStore.Audio.Media.IS_MUSIC + " = 1";
    String[] selectionArgs = null;
    String orderBy = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;

    ContentResolver contentResolver = context.getContentResolver();

    Cursor[] cursors = new Cursor[2];
    cursors[0] =
        contentResolver.query(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            TRACK_COLUMNS,
            where,
            selectionArgs,
            orderBy);

    cursors[1] =
        contentResolver.query(
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI,
            TRACK_COLUMNS,
            where,
            selectionArgs,
            orderBy);

    Cursor cursor = new MergeCursor(cursors);

    int idColumn = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
    int displayNameColumn = cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME);
    int titleColumn = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
    int titleKeyColumn = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE_KEY);
    int durationColumn = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
    int trackColumn = cursor.getColumnIndex(MediaStore.Audio.Media.TRACK);
    int artistColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
    // int dateAddedColumn 	= cursor.getColumnIndex(MediaStore.Audio.Media.DATE_ADDED);
    int dataColumn = cursor.getColumnIndex(MediaStore.Audio.Media.DATA);
    int albumColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
    int albumIdColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
    int albumKeyColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_KEY);

    realm.beginTransaction();

    while (cursor.moveToNext()) {
      int minimumDurationToConsiderAsSong = 61500;

      Track track = null;

      String local_id =
          Track.getLocalId(
              cursor.getString(titleColumn),
              cursor.getString(artistColumn),
              cursor.getString(albumColumn));

      Track res2 = realm.where(Track.class).equalTo("local_id", local_id).findFirst();

      if (res2 != null) {
        if (cursor.getInt(durationColumn) < minimumDurationToConsiderAsSong) {
          res2.removeFromRealm();
        } else {
          track = res2;
          track.setIsAvailable(true);

          if (!track.isHidden()) {
            if (rebuildStats) {
              rebuildStats(context, track.getLocal_id());
            }
          }
        }
      } else {
        if (cursor.getInt(durationColumn) > minimumDurationToConsiderAsSong) {
          //                    Log.d(TAG, "hi6 - means its a new record");
          //                    Log.d(TAG, "cursor.getString(titleColumn): " +
          // cursor.getString(titleColumn));
          //                    Log.d(TAG, "cursor.getString(artistColumn): " +
          // cursor.getString(artistColumn));
          //                    Log.d(TAG, "cursor.getString(albumColumn): " +
          // cursor.getString(albumColumn));

          track =
              new Track(
                  cursor.getString(titleColumn),
                  cursor.getString(artistColumn),
                  cursor.getString(albumColumn),
                  cursor.getString(dataColumn));

          track.setId(cursor.getLong(idColumn));
          track.setDisplayName(cursor.getString(displayNameColumn));
          track.setTitleKey(cursor.getString(titleKeyColumn));
          track.setDuration(cursor.getInt(durationColumn));
          track.setTrackNo(cursor.getInt(trackColumn));
          track.setAlbumId(cursor.getString(albumIdColumn));
          track.setAlbumKey(cursor.getString(albumKeyColumn));

          track = realm.copyToRealm(track);
        }
      }

      if (track != null) {
        track.setPath(cursor.getString(dataColumn));
      }
    }
    realm.commitTransaction();

    cursor.close();
    Log.d(TAG, "updateLibrary() end");
  }
Пример #12
0
 public void save(DoctorLocation location) {
   realm.beginTransaction();
   realm.copyToRealm(location);
   realm.commitTransaction();
 }