Example usage for android.database Cursor moveToPrevious

List of usage examples for android.database Cursor moveToPrevious

Introduction

In this page you can find the example usage for android.database Cursor moveToPrevious.

Prototype

boolean moveToPrevious();

Source Link

Document

Move the cursor to the previous row.

Usage

From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java

/**
 * Retrieves the day group of the previous call in the call log.  Used to determine if the day
 * group has changed and to trigger display of the day group text.
 *
 * @param cursor The call log cursor.//from ww  w  . j  ava  2 s .co  m
 * @return The previous day group, or DAY_GROUP_NONE if this is the first call.
 */
private int getPreviousDayGroup(Cursor cursor) {
    // We want to restore the position in the cursor at the end.
    int startingPosition = cursor.getPosition();
    int dayGroup = CallLogGroupBuilder.DAY_GROUP_NONE;
    if (cursor.moveToPrevious()) {
        long previousRowId = cursor.getLong(CallLogQuery.ID);
        dayGroup = getDayGroupForCall(previousRowId);
    }
    cursor.moveToPosition(startingPosition);
    return dayGroup;
}

From source file:br.liveo.ndrawer.ui.fragment.FragmentNotificationsfacebook.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());

    callbackManager = CallbackManager.Factory.create();

    View rootView = inflater.inflate(R.layout.fragment_fragment_note_detail, container, false);

    Log.i("methods", "oncreateview");

    button = (LoginButton) rootView.findViewById(R.id.fb_login_button);
    View vv = getView();/*from  w  ww  . j  a v a  2 s. c o m*/

    registerForContextMenu(container);

    button.setReadPermissions(Arrays.asList("user_posts"));
    final Activity a = getActivity();

    button.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            Log.i("facebooklog", AccessToken.getCurrentAccessToken().getToken());

            Toast.makeText(a, Profile.getCurrentProfile().getName(), Toast.LENGTH_LONG).show();

            //access token - CAALwq7ecy1kBABr2zkaYuKdtUZBREujKrmSeNpWbFqdZAp6jGZC6MfWKjSbQaL7Fq6aX6phXk4rbB4r1GZCk6S14A1yTiPFAU2jwjfDVOO1XQzZAijqXZC3GCoMakHQZCnH7YPRdHisi5mcdZBOujC16TRkKZB40EcoeYKAMlDnkRMd4sXlxJW51PcuZAhwo3E7KnSZCcb3llWDXdbcVAK1QcDG

        }

        @Override
        public void onCancel() {
            // Toast.makeText(a, "Cancelled" , Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(FacebookException e) {
            //  Toast.makeText(a, e.toString(), Toast.LENGTH_LONG).show();
        }
    });

    //  TextView mTxtTitle = (TextView) rootView.findViewById(R.id.txtTitle);
    //    mTxtTitle.setText(getArguments().getString(TEXT_FRAGMENT));
    data2 = new ArrayList<Notification>();

    lv = (ListView) rootView.findViewById(R.id.listview);

    LayoutInflater l = getActivity().getLayoutInflater();
    adapter2 = new NotificationAdapter(getActivity(), 0, data2, l);

    lv.setAdapter(adapter2);

    lv.setOnItemClickListener(this);
    lv.setOnItemLongClickListener(this);

    activity = getActivity();

    this.registerForContextMenu(lv);

    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    //brefresh=(Button)rootView.findViewById(R.id.buttonrefresh);
    //  brefresh.setOnClickListener(this);

    // lv.setAdapter(adapter);

    //data base work

    helper = new NotificationSquliteOpenHelper(getActivity());
    db = helper.getReadableDatabase();

    String[] col = new String[3];
    col[0] = NotificationSquliteOpenHelper.NOTIFICATION;
    col[1] = NotificationSquliteOpenHelper.NOTIFICATION_DATE;
    col[2] = NotificationSquliteOpenHelper.NOTIFICATION_TIME;

    String text = null;

    Cursor c = db.query(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, col, null, null, null, null, null);
    while (c.moveToNext()) {
        //            text=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION));
        //           String datee=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_DATE));
        //           String timeee=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_TIME));
        //
        //
        //            String compare=datee+timeee;
        //
        //
        //
        //
        //
        //            Notification n1=new Notification(text, datee, timeee);
        //            // Log.i("text get", text);
        //           // postcount++;
        //          //  Note nn1=new Note(text);
        //            data2.add(n1);
        //            adapter2.notifyDataSetChanged();
    }

    while (c.moveToPrevious()) {

        text = c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION));
        String datee = c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_DATE));
        String timeee = c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_TIME));

        Notification n1 = new Notification(text, datee, timeee);
        // Log.i("text get", text);
        // postcount++;
        //  Note nn1=new Note(text);
        data2.add(n1);
        adapter2.notifyDataSetChanged();

    }

    //        String[] col2=new String[1];
    //        col2[0]=NotificationSquliteOpenHelper.NOTIFICATION_DATE;
    //
    //        String datee=null;
    //
    //        Cursor c2=db.query(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, col2, null, null, null, null, null);
    //        while(c2!=null&&c2.moveToNext())
    //        {
    //
    //            // String text=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION));
    //            datee = c2.getString(c2.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_DATE));
    //            //  String timeee=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_TIME));
    //
    //
    //           // Notification n1 = new Notification("text", datee, "time");
    //            //  Log.i("noti date", datee);
    //            // postcount++;
    //            //  Note nn1=new Note(text);
    //           // data2.add(n1);
    //
    //        }
    //
    //
    //
    //        String[] col3=new String[1];
    //        col3[0]=NotificationSquliteOpenHelper.NOTIFICATION_TIME;
    //
    //        String timeee=null;
    //
    //        Cursor c3=db.query(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, col3, null, null, null, null, null);
    //        while(c3!=null&&c3.moveToNext())
    //        {
    //
    //            // String text=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION));
    //           // datee = c3.getString(c3.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_DATE));
    //              timeee=c3.getString(c3.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_TIME));
    //
    //
    //          //  Notification n1 = new Notification("text", datee, "time");
    //            //  Log.i("noti date", datee);
    //            // postcount++;
    //            //  Note nn1=new Note(text);
    //          //  data2.add(n1);
    //
    //        }

    //  Notification n11=new Notification(text, datee, timeee);
    // data2.add(n11);
    // adapter2.notifyDataSetChanged();

    String postcountstring = String.valueOf(postcount);
    // Log.i("postcount", postcountstring);

    return rootView;
}

From source file:com.nogago.android.tracks.services.TrackRecordingService.java

private void restoreStats(Track track) {
    Log.d(TAG, "Restoring stats of track with ID: " + track.getId());

    TripStatistics stats = track.getTripStatistics();
    statsBuilder = new TripStatisticsBuilder(stats.getStartTime());
    statsBuilder.setMinRecordingDistance(minRecordingDistance);

    length = 0;/*from  w  w  w  .ja  va2s  .  co m*/
    lastValidLocation = null;

    Waypoint waypoint = providerUtils.getFirstWaypoint(recordingTrackId);
    if (waypoint != null && waypoint.getTripStatistics() != null) {
        currentWaypointId = waypoint.getId();
        waypointStatsBuilder = new TripStatisticsBuilder(waypoint.getTripStatistics());
    } else {
        // This should never happen, but we got to do something so life goes on:
        waypointStatsBuilder = new TripStatisticsBuilder(stats.getStartTime());
        currentWaypointId = -1;
    }
    waypointStatsBuilder.setMinRecordingDistance(minRecordingDistance);

    Cursor cursor = null;
    try {
        cursor = providerUtils.getLocationsCursor(recordingTrackId, -1, Constants.MAX_LOADED_TRACK_POINTS,
                true);
        if (cursor != null) {
            if (cursor.moveToLast()) {
                do {
                    Location location = providerUtils.createLocation(cursor);
                    if (LocationUtils.isValidLocation(location)) {
                        statsBuilder.addLocation(location, location.getTime());
                        if (lastValidLocation != null) {
                            length += location.distanceTo(lastValidLocation);
                        }
                        lastValidLocation = location;
                    }
                } while (cursor.moveToPrevious());
            }
            statsBuilder.getStatistics().setMovingTime(stats.getMovingTime());
            statsBuilder.pauseAt(stats.getStopTime());
            statsBuilder.resumeAt(System.currentTimeMillis());
        } else {
            Log.e(TAG, "Could not get track points cursor.");
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Error while restoring track.", e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    announcementExecutor.restore();
    splitExecutor.restore();
}

From source file:com.google.android.apps.mytracks.services.TrackRecordingService.java

/**
 * Restart a track.//w w w .ja  v a2  s . c  o  m
 * 
 * @param track the track
 */
private void restartTrack(Track track) {
    Log.d(TAG, "Restarting track: " + track.getId());

    TripStatistics tripStatistics = track.getTripStatistics();
    trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());

    long markerStartTime;
    Waypoint waypoint = myTracksProviderUtils.getLastStatisticsWaypoint(recordingTrackId);
    if (waypoint != null && waypoint.getTripStatistics() != null) {
        markerStartTime = waypoint.getTripStatistics().getStopTime();
    } else {
        markerStartTime = tripStatistics.getStartTime();
    }
    markerTripStatisticsUpdater = new TripStatisticsUpdater(markerStartTime);

    Cursor cursor = null;
    try {
        // TODO: how to handle very long track.
        cursor = myTracksProviderUtils.getTrackPointCursor(recordingTrackId, -1,
                Constants.MAX_LOADED_TRACK_POINTS, true);
        if (cursor == null) {
            Log.e(TAG, "Cursor is null.");
        } else {
            if (cursor.moveToLast()) {
                do {
                    Location location = myTracksProviderUtils.createTrackPoint(cursor);
                    trackTripStatisticsUpdater.addLocation(location, minRecordingDistance);
                    if (location.getTime() > markerStartTime) {
                        markerTripStatisticsUpdater.addLocation(location, minRecordingDistance);
                    }
                } while (cursor.moveToPrevious());
            }
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "RuntimeException", e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    startRecording(true);
}

From source file:com.mobicage.rogerthat.plugins.messaging.MessagingPlugin.java

public Intent getPreviousMessageThreadActivityIntent(Context context, String messageKey, String memberFilter) {
    T.UI();/*from  w w  w.jav a  2  s .  c  om*/
    Cursor cursor = mStore.getThreadListCursor(memberFilter);
    try {
        if (cursor.moveToFirst()) {
            do {
                String key = cursor.getString(0); // parent_key
                if (key == null)
                    key = cursor.getString(1); // message key

                if (key.equals(messageKey)) {
                    while (cursor.moveToPrevious()) {
                        String prevKey = cursor.getString(0); // parent_key
                        if (prevKey == null)
                            prevKey = cursor.getString(1); // message key

                        if (isTmpKey(prevKey)) {
                            continue;
                        }
                        String prevSender = cursor.getString(2);
                        long prevFlags = cursor.getLong(3);
                        Intent intent = getThreadActivityIntent(context, prevKey, prevSender, prevFlags,
                                memberFilter);
                        if (intent != null)
                            return intent;
                    }
                    return null;
                }
            } while (cursor.moveToNext());
        }
        return null;
    } finally {
        cursor.close();
    }
}

From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment2.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    ArrayList<WeekViewEvent> events = mWeekViewLoader.getEvents(loader.getId());
    events.clear();/*  w  w w.  j  a  v  a2s  .  c  om*/

    Account mAccount = AppUtils.getAccount(getContext());
    if (mAccount != null) {
        // fetch calendar colors
        final SparseIntArray mColors = new SparseIntArray();
        ContentResolver cr = getContext().getContentResolver();
        Cursor cursor = cr.query(CalendarContractWrapper.Calendars.CONTENT_URI(), new String[] {
                CalendarContractWrapper.Calendars._ID(), CalendarContractWrapper.Calendars.CALENDAR_COLOR() },
                null, null, null);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                int color = cursor.getInt(1);

                double lastContrast = ColorUtils.calculateContrast(color, mWeekView.getEventTextColor());
                //Log.d(TAG, String.format("color=%d %d %d, contrast=%f", Color.red(color), Color.green(color), Color.blue(color), lastContrast));

                while (lastContrast < 1.6) {
                    float[] hsv = new float[3];

                    Color.colorToHSV(color, hsv);
                    hsv[2] = Math.max(0f, hsv[2] - 0.033f); // darken
                    color = Color.HSVToColor(hsv);

                    lastContrast = ColorUtils.calculateContrast(color, mWeekView.getEventTextColor());
                    //Log.d(TAG, String.format("new color=%d %d %d, contrast=%f", Color.red(color), Color.green(color), Color.blue(color), lastContrast));

                    if (hsv[2] == 0)
                        break;
                }

                mColors.put(cursor.getInt(0), color);
            }
            cursor.close();
        }

        if (data != null) {
            data.moveToFirst();
            data.moveToPrevious();
            while (data.moveToNext()) {

                boolean allDay = data.getInt(CalendarUtils.COLUMN_EVENT_ALL_DAY) == 1;

                Calendar startTime = Calendar.getInstance();
                if (allDay) {
                    startTime.setTimeZone(TimeZone.getTimeZone("UTC"));
                }
                startTime.setTimeInMillis(data.getLong(CalendarUtils.COLUMN_EVENT_DTSTART));

                Calendar endTime = Calendar.getInstance();
                if (allDay) {
                    endTime.setTimeZone(TimeZone.getTimeZone("UTC"));
                }
                endTime.setTimeInMillis(data.getLong(CalendarUtils.COLUMN_EVENT_DTEND));
                if (allDay && endTime.getTimeInMillis() % DateUtils.DAY_IN_MILLIS == 0) {
                    endTime.add(Calendar.MILLISECOND, -1);
                }

                WeekViewEvent event = new WeekViewEvent(data.getLong(CalendarUtils.COLUMN_EVENT_ID),
                        data.getString(CalendarUtils.COLUMN_EVENT_TITLE),
                        data.getString(CalendarUtils.COLUMN_EVENT_LOCATION), startTime, endTime, allDay);

                event.setColor(mColors.get(data.getInt(CalendarUtils.COLUMN_EVENT_CAL_ID)));

                events.add(event);
            }
        }
    }

    mWeekView.notifyDatasetChanged();
}