Java Code Examples for android.database.Cursor.moveToPosition()

The following are Jave code examples for showing how to use moveToPosition() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Facebook-Video-Downloader   File: DBHelper.java   Source Code and License Vote up 6 votes
public RecordingItem getItemAt(int position) {
    SQLiteDatabase db = getReadableDatabase();
    String[] projection = {
            DBHelperItem._ID,
            DBHelperItem.COLUMN_NAME_RECORDING_NAME,
            DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH,
            DBHelperItem.COLUMN_NAME_RECORDING_LENGTH,
            DBHelperItem.COLUMN_NAME_TIME_ADDED,
            DBHelperItem.COLUMN_NAME_IMAGE_THUMB
    };
    Cursor c = db.query(DBHelperItem.TABLE_NAME, projection, null, null, null, null, null);
    if (c.moveToPosition(position)) {
        RecordingItem item = new RecordingItem();
        item.setId(c.getInt(c.getColumnIndex(DBHelperItem._ID)));
        item.setName(c.getString(c.getColumnIndex(DBHelperItem.COLUMN_NAME_RECORDING_NAME)));
        item.setFilePath(c.getString(c.getColumnIndex(DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH)));
        item.setLength(c.getInt(c.getColumnIndex(DBHelperItem.COLUMN_NAME_RECORDING_LENGTH)));
        item.setTime(c.getLong(c.getColumnIndex(DBHelperItem.COLUMN_NAME_TIME_ADDED)));
        byte[] bytes=c.getBlob(c.getColumnIndex(DBHelperItem.COLUMN_NAME_IMAGE_THUMB));
        item.setImageThumbnail(BitmapFactory.decodeByteArray(bytes, 0, bytes.length));
        c.close();
        return item;
    }
    return null;
}
 
Example 2
Project: BlackList   File: ContactsCursorAdapter.java   Source Code and License Vote up 6 votes
public List<Contact> extractCheckedContacts() {
    List<Contact> list = new LinkedList<>();
    Cursor cursor = getCursor();
    if (cursor != null) {
        int position = cursor.getPosition();
        cursor.moveToFirst();
        do {
            Contact contact = ((ContactSource) cursor).getContact();
            if (checkedItems.contains((int) contact.id)) {
                list.add(contact);
            }
        } while (cursor.moveToNext());
        cursor.moveToPosition(position);
    }
    return list;
}
 
Example 3
Project: Matisse-Image-and-Video-Selector   File: AlbumMediaAdapter.java   Source Code and License Vote up 6 votes
public void refreshSelection() {
    GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
    int first = layoutManager.findFirstVisibleItemPosition();
    int last = layoutManager.findLastVisibleItemPosition();
    if (first == -1 || last == -1) {
        return;
    }
    Cursor cursor = getCursor();
    for (int i = first; i <= last; i++) {
        RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(first);
        if (holder instanceof MediaViewHolder) {
            if (cursor.moveToPosition(i)) {
                setCheckStatus(Item.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid);
            }
        }
    }
}
 
Example 4
Project: microbit   File: AlertPlugin.java   Source Code and License Vote up 6 votes
private Uri searchAlarmUri(int alarmId) {
    Context context = MBApp.getApp();

    RingtoneManager ringtoneMgr = new RingtoneManager(context);
    ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
    Cursor alarms = ringtoneMgr.getCursor();
    Log.i(TAG, "playAlarm: total alarms = " + alarms.getCount());

    alarms.moveToPosition(alarmId - 4);
    Uri alarm = ringtoneMgr.getRingtoneUri(alarms.getPosition());

    if(alarm == null) {
        Log.i(TAG, "Cannot play nth Alarm. Playing default");
        alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    }

    return alarm;
}
 
Example 5
Project: zabbkit-android   File: HostActivity.java   Source Code and License Vote up 5 votes
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Cursor cursor = hostsAdapter.getCursor();
    cursor.moveToPosition(position);
    Intent outputIntent = new Intent();
    outputIntent.putExtra(Constants.HOST_BUNDLE_URL, cursor.getString(cursor.getColumnIndex(Host.COLUMN_URL)));
    outputIntent.putExtra(Constants.HOST_BUNDLE_LOGIN, cursor.getString(cursor.getColumnIndex(Host.COLUMN_LOGIN)));
    outputIntent.putExtra(Constants.HOST_BUNDLE_PASSWORD, cursor.getString(cursor.getColumnIndex(Host.COLUMN_PASSWORD)));
    setResult(RESULT_OK, outputIntent);
    finish();
}
 
Example 6
Project: TimeTrix   File: DatabaseAdapter.java   Source Code and License Vote up 5 votes
private int getUIDFromRowCount(long rowCount) {
    int UID = -1;
    int intRowCount = (int) rowCount;
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase ();
    Cursor cursor = db.query (DatabaseHelper.TABLE_NAME, null, null, null, null, null, null);
    Log.d (TAG, "getUIDFromRowCount: rowCount = "+rowCount);
    if (cursor.getCount () != 0) {
        cursor.moveToPosition (intRowCount - 1);
        UID = cursor.getInt (cursor.getColumnIndex (DatabaseHelper.KEY_ID));
    }
    cursor.close ();
    db.close ();
    return UID;
}
 
Example 7
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static void putPageInfo(Cursor photos, WritableMap response, int limit) {
  WritableMap pageInfo = new WritableNativeMap();
  pageInfo.putBoolean("has_next_page", limit < photos.getCount());
  if (limit < photos.getCount()) {
    photos.moveToPosition(limit - 1);
    pageInfo.putString(
        "end_cursor",
        photos.getString(photos.getColumnIndex(Images.Media.DATE_TAKEN)));
  }
  response.putMap("page_info", pageInfo);
}
 
Example 8
Project: filepicker   File: AudioPickerModel.java   Source Code and License Vote up 5 votes
private List<Folder> onLoadAudio(Cursor cursor) {
    if (cursor.getPosition() != -1) {
        cursor.moveToPosition(-1);
    }
    List<Folder> folders = new ArrayList<>();
    List<BaseFile> audioFiles = new ArrayList<>();
    while (cursor.moveToNext()) {
        //Create a File instance
        AudioFile audio = new AudioFile();
        audio.setId(cursor.getLong(cursor.getColumnIndexOrThrow(_ID)));
        audio.setName(cursor.getString(cursor.getColumnIndexOrThrow(TITLE)));
        audio.setPath(cursor.getString(cursor.getColumnIndexOrThrow(DATA)));
        audio.setSize(cursor.getLong(cursor.getColumnIndexOrThrow(SIZE)));
        audio.setDate(cursor.getLong(cursor.getColumnIndexOrThrow(DATE_ADDED)));

        audio.setDuration(cursor.getLong(cursor.getColumnIndexOrThrow(DURATION)));
        audioFiles.add(audio);
        //Create a Folder
        Folder folder = new Folder();
        folder.setName(Util.extractName(Util.extractDirectory(audio.getPath())));
        folder.setPath(Util.extractDirectory(audio.getPath()));

        if (!folders.contains(folder)) {
            folder.addFile(audio);
            folders.add(folder);
        } else {
            folders.get(folders.indexOf(folder)).addFile(audio);
        }
    }
    Folder all = new Folder();
    all.setName(mContext.getString(R.string.all));
    all.setFiles(audioFiles);
    all.setSelected(true);
    folders.add(0, all);
    return folders;
}
 
Example 9
Project: zabbkit-android   File: MainHostsFragment.java   Source Code and License Vote up 5 votes
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    String[] actions = getResources().getStringArray(R.array.list_hosts_actions);
    if (item.getTitle().equals(actions[0])) {
        AdapterView.AdapterContextMenuInfo contextMenuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        int position = contextMenuInfo.position;
        Cursor cursor = getHostsAdapter().getCursor();
        cursor.moveToPosition(position);
        removeHost(cursor.getString(cursor.getColumnIndex(Host.COLUMN_URL)));
    }
    return super.onContextItemSelected(item);
}
 
Example 10
Project: zabbkit-android   File: BookmarksFragment.java   Source Code and License Vote up 5 votes
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
                        int position, long id) {
    Cursor cursor = mCursorAdapter.getCursor();
    cursor.moveToPosition(position);
    Intent intent = new Intent(getActivity(), GraphActivity.class);
    intent.putExtra(Constants.GRAPH_ID, cursor.getString(cursor.getColumnIndex(Bookmark.COLUMN_GRAPH_ID)));
    intent.putExtra(Constants.HOST_ID, cursor.getString(cursor.getColumnIndex(Bookmark.COLUMN_SERVER_ID)));
    intent.putExtra(Constants.HOST_NAME, cursor.getString(cursor.getColumnIndex(Bookmark.COLUMN_SERVER_NAME)));
    intent.putExtra(Constants.PARAM_NAME, cursor.getString(cursor.getColumnIndex(Bookmark.COLUMN_PARAM_NAME)));
    intent.putExtra(Constants.PERIOD, cursor.getString(cursor.getColumnIndex(Bookmark.COLUMN_PERIOD)));
    startActivity(intent);
}
 
Example 11
Project: letv   File: WorldCupTraceHandler.java   Source Code and License Vote up 5 votes
public DownloadDBListBean getLoadingDownloadInfo() {
    DownloadDBListBean list = new DownloadDBListBean();
    boolean flag = false;
    Cursor cursor = null;
    try {
        cursor = this.context.getContentResolver().query(LetvContentProvider.URI_WORLDCUPTRACE, null, "finish<>?", new String[]{"4"}, "timestamp ASC");
        if (!PreferencesManager.getInstance().hasUpdateMulti()) {
            if (cursor != null && cursor.getCount() > 0) {
                while (cursor.moveToNext()) {
                    int episodeId = cursor.getInt(cursor.getColumnIndex("episodeid"));
                    if (!DownloadManager.getInstance(this.context).isDownloadExist(episodeId + "")) {
                        delete(episodeId);
                        flag = true;
                    }
                }
            }
            PreferencesManager.getInstance().updateMulti();
        }
        if (flag) {
            cursor = this.context.getContentResolver().query(LetvContentProvider.URI_WORLDCUPTRACE, null, "finish<>?", new String[]{"4"}, "timestamp ASC");
        } else {
            cursor.moveToPosition(-1);
        }
        while (cursor.moveToNext()) {
            list.add(createDownloadDBBean(cursor));
        }
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return list;
    } finally {
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
    }
    return list;
}
 
Example 12
Project: androidbeginners-Lesson3   File: MainActivity.java   Source Code and License Vote up 4 votes
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    Cursor cursor = ((SimpleCursorAdapter) parent.getAdapter()).getCursor();

    cursor.moveToPosition(position);

    String contactName = cursor.getString(LOOKUP_KEY_INDEX);

    Uri mContactUri = ContactsContract.Contacts.getLookupUri(
            cursor.getLong(CONTACT_ID_INDEX),
            contactName
    );

    String email = getEmail(mContactUri);

    if(!email.equals(""))
        sendEmail(email, contactName);

}
 
Example 13
Project: Mp3Player   File: songDetailloader.java   Source Code and License Vote up 4 votes
public ArrayList<Songs> getSongs(String withWhat,String content)
{   Cursor c;
    ArrayList<Songs> s= new ArrayList<>();
    String  orderby = MediaStore.Audio.Media.TITLE;;
    boolean condition;
    String[]  col = {MediaStore.Audio.Albums._ID ,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.ALBUM,MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.COMPOSER, MediaStore.Audio.Media.DURATION};
    final String where= "is_music AND duration > 10000";

    c= context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,col ,where ,null,orderby) ;
    for(int i=0 ;i< c.getCount() ; i++)
    { Songs songs = new Songs();
        c.moveToPosition(i);
        switch(withWhat)
        {
            case "album" : if(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)).equals(content))
                               {
                                   songs.settitle(c.getString(c.getColumnIndex(MediaStore.Audio.Media.TITLE)));
                                   songs.setSonguri(Uri.parse(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DATA))));
                                   songs.setartist(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
                                   songs.setalbum(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
                                   songs.setDuration(Long.decode(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DURATION))));
                                   songs.setPosition(i);
                                   songs.setAlbumart(albumartwithalbum(content));
                                   s.add(songs);
                               }
                break;

            case "artist" : if(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST)).equals(content))
            {
                songs.settitle(c.getString(c.getColumnIndex(MediaStore.Audio.Media.TITLE)));
                songs.setSonguri(Uri.parse(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DATA))));
                songs.setartist(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
                songs.setalbum(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
                songs.setDuration(Long.decode(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DURATION))));
                songs.setPosition(i);
                songs.setAlbumart(albumartwithalbum(songs.getalbum()));
                s.add(songs);
            }
                break ;

            case "geners" :
                if(c.getString(c.getColumnIndex(MediaStore.Audio.Media.COMPOSER)).equals(content))
                {
                    songs.settitle(c.getString(c.getColumnIndex(MediaStore.Audio.Media.TITLE)));
                    songs.setSonguri(Uri.parse(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DATA))));
                    songs.setartist(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
                    songs.setalbum(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
                    songs.setDuration(Long.decode(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DURATION))));
                    songs.setPosition(i);
                    songs.setAlbumart(albumartwithalbum(songs.getalbum()));
                    s.add(songs);
                }
                break;
            default:  return null ;
        }

    }
    for(int j=0 ;j< s.size();j++)
    {
        Log.d("positions--->",""+s.get(j).getPosition());
    }
    c.close();
    return s;
}
 
Example 14
Project: letv   File: DownloadTraceHandler.java   Source Code and License Vote up 4 votes
public DownloadDBListBean getLoadingDownloadInfo() {
    DownloadDBListBean list = new DownloadDBListBean();
    Cursor cursor = this.mContext.getContentResolver().query(LetvContentProvider.URI_DOWNLOADTRACE, null, "finish<>?", new String[]{"4"}, "timestamp ASC");
    if (cursor != null) {
        if (!PreferencesManager.getInstance().hasUpdateMulti()) {
            if (cursor != null && cursor.getCount() > 0) {
                while (cursor.moveToNext()) {
                    cursor.getInt(cursor.getColumnIndex("episodeid"));
                }
            }
            PreferencesManager.getInstance().updateMulti();
        }
        if (false) {
            cursor = this.mContext.getContentResolver().query(LetvContentProvider.URI_DOWNLOADTRACE, null, "finish<>?", new String[]{"4"}, "timestamp ASC");
        } else {
            cursor.moveToPosition(-1);
        }
        while (cursor.moveToNext()) {
            DownloadDBBean mDownloadDBBean = new DownloadDBBean();
            mDownloadDBBean.vid = cursor.getInt(cursor.getColumnIndex("episodeid"));
            mDownloadDBBean.aid = cursor.getInt(cursor.getColumnIndex(PageJumpUtil.IN_TO_ALBUM_PID));
            mDownloadDBBean.icon = cursor.getString(cursor.getColumnIndex(SettingsJsonConstants.APP_ICON_KEY));
            mDownloadDBBean.type = cursor.getInt(cursor.getColumnIndex("type"));
            mDownloadDBBean.ord = (float) cursor.getInt(cursor.getColumnIndex("ord"));
            mDownloadDBBean.cid = cursor.getInt(cursor.getColumnIndex("cid"));
            mDownloadDBBean.episodetitle = cursor.getString(cursor.getColumnIndex("episodetitle"));
            mDownloadDBBean.episodeIcon = cursor.getString(cursor.getColumnIndex("episodeicon"));
            mDownloadDBBean.albumtitle = cursor.getString(cursor.getColumnIndex(DownloadAlbumTable.COLUMN_ALBUMTITLE));
            mDownloadDBBean.totalsize = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_TOTALSIZE));
            mDownloadDBBean.finish = cursor.getInt(cursor.getColumnIndex("finish"));
            mDownloadDBBean.timestamp = cursor.getLong(cursor.getColumnIndex("timestamp"));
            mDownloadDBBean.length = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_LENGTH));
            mDownloadDBBean.isHd = cursor.getInt(cursor.getColumnIndex("isHd"));
            mDownloadDBBean.isNew = cursor.getInt(cursor.getColumnIndex(DownloadVideoTable.COLUMN_ISNEW));
            mDownloadDBBean.btime = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_BTIME));
            mDownloadDBBean.etime = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_ETIME));
            mDownloadDBBean.duration = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_DURATION));
            list.add(mDownloadDBBean);
        }
        cursor.close();
    }
    return list;
}
 
Example 15
Project: easyfilemanager   File: SortingCursorWrapper.java   Source Code and License Vote up 4 votes
public SortingCursorWrapper(Cursor cursor, int sortOrder) {
    mCursor = cursor;

    final int count = cursor.getCount();
    mPosition = new int[count];
    switch (sortOrder) {
        case SORT_ORDER_DISPLAY_NAME:
            mValueString = new String[count];
            mValueLong = null;
            break;
        case SORT_ORDER_LAST_MODIFIED:
        case SORT_ORDER_SIZE:
            mValueString = null;
            mValueLong = new long[count];
            break;
        default:
            throw new IllegalArgumentException();
    }

    cursor.moveToPosition(-1);
    for (int i = 0; i < count; i++) {
        cursor.moveToNext();
        mPosition[i] = i;

        switch (sortOrder) {
            case SORT_ORDER_DISPLAY_NAME:
                final String mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
                final String displayName = getCursorString(
                        cursor, Document.COLUMN_DISPLAY_NAME);
                if (Utils.isDir(mimeType)) {
                    mValueString[i] = DocumentInfo.DIR_PREFIX + displayName;
                } else {
                    mValueString[i] = displayName;
                }
                break;
            case SORT_ORDER_LAST_MODIFIED:
                mValueLong[i] = getCursorLong(cursor, Document.COLUMN_LAST_MODIFIED);
                break;
            case SORT_ORDER_SIZE:
                mValueLong[i] = getCursorLong(cursor, Document.COLUMN_SIZE);
                break;
        }
    }

    switch (sortOrder) {
        case SORT_ORDER_DISPLAY_NAME:
            synchronized (SortingCursorWrapper.class) {

                binarySort(mPosition, mValueString);
            }
            break;
        case SORT_ORDER_LAST_MODIFIED:
        case SORT_ORDER_SIZE:
            binarySort(mPosition, mValueLong);
            break;
    }
}
 
Example 16
Project: Hello-Music-droid   File: SearchHistory.java   Source Code and License Vote up 4 votes
public void addSearchString(final String searchString) {
    if (searchString == null) {
        return;
    }

    String trimmedString = searchString.trim();

    if (trimmedString.isEmpty()) {
        return;
    }

    final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
    database.beginTransaction();

    try {

        database.delete(SearchHistoryColumns.NAME,
                SearchHistoryColumns.SEARCHSTRING + " = ? COLLATE NOCASE",
                new String[]{trimmedString});

        final ContentValues values = new ContentValues(2);
        values.put(SearchHistoryColumns.SEARCHSTRING, trimmedString);
        values.put(SearchHistoryColumns.TIMESEARCHED, System.currentTimeMillis());
        database.insert(SearchHistoryColumns.NAME, null, values);

        Cursor oldest = null;
        try {
            database.query(SearchHistoryColumns.NAME,
                    new String[]{SearchHistoryColumns.TIMESEARCHED}, null, null, null, null,
                    SearchHistoryColumns.TIMESEARCHED + " ASC");

            if (oldest != null && oldest.getCount() > MAX_ITEMS_IN_DB) {
                oldest.moveToPosition(oldest.getCount() - MAX_ITEMS_IN_DB);
                long timeOfRecordToKeep = oldest.getLong(0);

                database.delete(SearchHistoryColumns.NAME,
                        SearchHistoryColumns.TIMESEARCHED + " < ?",
                        new String[]{String.valueOf(timeOfRecordToKeep)});

            }
        } finally {
            if (oldest != null) {
                oldest.close();
                oldest = null;
            }
        }
    } finally {
        database.setTransactionSuccessful();
        database.endTransaction();
    }
}
 
Example 17
Project: aos-Video   File: AllTVShowsProvider.java   Source Code and License Vote up 4 votes
protected Collection<Cover> convertCursorToCovers(Cursor c, boolean update) {
    if(DBG) Log.d(TAG, "convertCursorToCovers()");
    final int mIdidx = c.getColumnIndexOrThrow(BaseColumns._ID);
    final int mNameIdx = c.getColumnIndexOrThrow(VideoStore.Video.VideoColumns.SCRAPER_TITLE);
    final int mPosterIdx = c.getColumnIndexOrThrow(VideoStore.Video.VideoColumns.SCRAPER_S_COVER);
    final int seasonNumberIdx = c.getColumnIndexOrThrow(VideoStore.Video.VideoColumns.SCRAPER_E_SEASON);
    final int anyEpisodeFilePathIdx = c.getColumnIndexOrThrow(VideoStore.Video.VideoColumns.DATA);
    final int epCountIdx = c.getColumnIndexOrThrow(AllTvshowsLoader.COLUMN_EPISODE_COUNT);
    final int seasCountIdx = c.getColumnIndexOrThrow(AllTvshowsLoader.COLUMN_SEASON_COUNT);

    //keep a reference to the previous Cover Map, to keep track of covers that are not in the new cursor anymore, to recycle them
    HashMap<String, Cover> newCoverIdMap = new HashMap<String, Cover>();

    // Allocate new array (we don't have to keep the previous one, update is handled using the old CoverMap instead
    mCoverArray = new ArrayList<Cover>(c.getCount());
    c.moveToPosition(-1); // make sure position is before first
    while (c.moveToNext()) {
        final long id = c.getLong(mIdidx);
        final int numberOfEpisodes = c.getInt(epCountIdx);
        final String name = c.getString(mNameIdx);
        final String poster = c.getString(mPosterIdx);
        final int seasonCount = c.getInt(seasCountIdx);
        final int seasonNumber = c.getInt(seasonNumberIdx);
        final String anyEpisodeFilePath = c.getString(anyEpisodeFilePathIdx);
        Cover cover = null;
        // Update case
        if (update) {
            // For the TVShow covers there is a special method to compute the CoverID. It integrates the number of episodes,
            // so that the cover is updated in case it is changed (only the description texture should be updated tough...)
            final String coverID = TvShowCover.computeCoverIDwithNumberOfEpisode(id, numberOfEpisodes);
            if (DBG) Log.d(TAG, "convertCursorToCovers update: coverID="+coverID);
            // Is it in the previous cover collection already?
            cover = mCoverIdMap.get(coverID);
            if (cover!=null) {
                if (DBG) Log.d(TAG, "convertCursorToCovers update: found "+coverID+" in previous covers");
                // remove in the old cover map. Will allow to keep track of the non-recycled covers remaining at the end
                mCoverIdMap.remove(coverID);
            } else {
                if (DBG) Log.d(TAG, "convertCursorToCovers update: "+coverID+" not found in previous covers");
            }
        }
        if (cover==null) {
            // Create a new one
            cover = new TvShowCover(id, name, numberOfEpisodes, poster, seasonCount, seasonNumber, anyEpisodeFilePath);
        }
        mCoverArray.add(cover);
        if (DBG) Log.d(TAG, "convertCursorToCovers: put coverID="+cover.getCoverID());
        newCoverIdMap.put(cover.getCoverID(), cover);
    }

    // Must not close the cursor here. It is handled at CoverProvider level.

    // Return the collection of covers to recycle
    Collection<Cover> coversToRecycle = null;
    if (update) {
        coversToRecycle = mCoverIdMap.values();
    }

    // Update the CoverMap: old = new, now
    mCoverIdMap = newCoverIdMap;

    // Sanity check
    if (mCoverArray.size() == 0) {
        mErrorMessage = mContext.getResources().getString(R.string.you_have_no_tv_shows);
        mErrorMessage += "\n\n" + mContext.getResources().getString(R.string.scraper_suggest_message);
        Log.e(TAG,"Error: " + mErrorMessage);
    }
    return coversToRecycle;
}
 
Example 18
Project: TaBeTa   File: InternalDB.java   Source Code and License Vote up 4 votes
public int GetPointsCount(int level){
	
	int n=0 ;

	Cursor cu = mydb.query("Pointsx", null, "ID="+level, null, null, null, null);
	cu.moveToPosition(0);
	
	for(int i=1;i<=24;i++){
		
		if(cu.getFloat(i) != 8){
			n +=1;
		}else if(cu.getFloat(i) == 8)break;
		
	}
	
	return n;
	
}
 
Example 19
Project: TaBeTa   File: InternalDB.java   Source Code and License Vote up 3 votes
public double GetCurPosX(int level, int n){

		Cursor cu = mydb.query("CurlPosx", null, "ID="+level, null, null, null, null);
		cu.moveToPosition(0);
		double point = cu.getDouble(n+1);
		
		return point;
		
	}
 
Example 20
Project: TaBeTa   File: InternalDB.java   Source Code and License Vote up 3 votes
public double GetCurlDirX(int level, int n){

		Cursor cu = mydb.query("CurlDirx", null, "ID="+level, null, null, null, null);
		cu.moveToPosition(0);
		double point = cu.getDouble(n+1);
		
		return point;
		
	}