Example usage for android.database Cursor moveToFirst

List of usage examples for android.database Cursor moveToFirst

Introduction

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

Prototype

boolean moveToFirst();

Source Link

Document

Move the cursor to the first row.

Usage

From source file:curso.android.DAO.RespostaDAO.java

public static Resposta getPerguntaById(Resposta p) {
    Cursor cursor = null;
    try {/*ww w  .  j  a va2 s .  co m*/

        cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE asw_id = " + p.getAsw_id(), null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("asw_id");
            int askIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int respostaIndex = cursor.getColumnIndex("asw_resposta");
            int nameIndex = cursor.getColumnIndex("user_name");
            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long ask = Long.valueOf(cursor.getString(askIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String resposta = cursor.getString(respostaIndex);
                String user_name = cursor.getString(nameIndex);

                Resposta answer = new Resposta();
                answer.setAsw_id(id);
                answer.setAsk_id(ask);
                answer.setUser_id(user);
                answer.setAsw_resposta(resposta);
                answer.setUser_name(user_name);

                return answer;

            } while (!cursor.isAfterLast());
        }

        return null;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.fada.sellsteward.myweibo.sina.net.Utility.java

public static HttpClient getNewHttpClient(Context context) {
    try {//ww w.j a v  a2s  . c  o  m
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();

        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        // Set the default socket timeout (SO_TIMEOUT) // in
        // milliseconds which is the timeout for waiting for data.
        HttpConnectionParams.setConnectionTimeout(params, Utility.SET_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, Utility.SET_SOCKET_TIMEOUT);
        HttpClient client = new DefaultHttpClient(ccm, params);
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (!wifiManager.isWifiEnabled()) {
            // ??APN
            Uri uri = Uri.parse("content://telephony/carriers/preferapn");
            Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
            if (mCursor != null && mCursor.moveToFirst()) {
                // ???
                String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
                if (proxyStr != null && proxyStr.trim().length() > 0) {
                    HttpHost proxy = new HttpHost(proxyStr, 80);
                    client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
                }
                mCursor.close();
            }
        }
        return client;
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:foam.zizim.android.Util.java

public static List<IncidentsData> showIncidents(String by) {

    Cursor cursor;
    String title;// www .  ja v a2s. co  m
    String description;
    String location;
    String categories;
    String media;

    if (by.equals("All"))
        cursor = BoskoiApplication.mDb.fetchAllIncidents();
    else
        cursor = BoskoiApplication.mDb.fetchIncidentsByCategories(by);

    if (cursor.moveToFirst()) {
        int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_ID);
        int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_TITLE);
        int dateIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_DATE);
        int verifiedIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_VERIFIED);
        int locationIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_LOC_NAME);

        int descIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_DESC);

        int categoryIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_CATEGORIES);

        int mediaIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_MEDIA);

        int latitudeIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_LOC_LATITUDE);

        int longitudeIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.INCIDENT_LOC_LONGITUDE);

        do {

            IncidentsData incidentData = new IncidentsData();
            mOldIncidents.add(incidentData);

            int id = Util.toInt(cursor.getString(idIndex));
            incidentData.setIncidentId(id);

            title = Util.capitalizeString(cursor.getString(titleIndex));
            incidentData.setIncidentTitle(title);

            description = cursor.getString(descIndex);
            incidentData.setIncidentDesc(description);

            categories = cursor.getString(categoryIndex);
            incidentData.setIncidentCategories(categories);

            location = cursor.getString(locationIndex);
            incidentData.setIncidentLocLongitude(location);

            Util.joinString("Date: ", cursor.getString(dateIndex));
            incidentData.setIncidentDate(cursor.getString(dateIndex));

            media = cursor.getString(mediaIndex);
            incidentData.setIncidentMedia(media);

            incidentData.setIncidentVerified(Util.toInt(cursor.getString(verifiedIndex)));

            incidentData.setIncidentLocLatitude(cursor.getString(latitudeIndex));
            incidentData.setIncidentLocLongitude(cursor.getString(longitudeIndex));

        } while (cursor.moveToNext());
    }

    cursor.close();
    return mOldIncidents;

}

From source file:ro.weednet.contactssync.platform.ContactManager.java

public static int getStreamItemLimit(Context context) {
    Cursor c = context.getContentResolver().query(StreamItems.CONTENT_LIMIT_URI,
            new String[] { StreamItems.MAX_ITEMS }, null, null, null);

    try {//from  www. j  av a2s .co  m
        c.moveToFirst();
        return c.getInt(0);
    } catch (Exception e) {
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return 1;
}

From source file:curso.android.DAO.RespostaDAO.java

public static List<Resposta> readAll() {
    Cursor cursor = null;
    try {/*from  w w  w .j a v  a2 s  .  c o  m*/
        List<Resposta> all = new ArrayList<Resposta>();

        cursor = Const.db.rawQuery("SELECT * FROM resposta", null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("asw_id");
            int askIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int respostaIndex = cursor.getColumnIndex("asw_resposta");
            int nameIndex = cursor.getColumnIndex("user_name");
            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long ask = Long.valueOf(cursor.getString(askIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String pergunta = cursor.getString(respostaIndex);
                String user_name = cursor.getString(nameIndex);

                Resposta asw = new Resposta();
                asw.setAsw_id(id);
                asw.setAsk_id(ask);
                asw.setUser_id(user);
                asw.setAsw_resposta(pergunta);
                asw.setUser_name(user_name);

                all.add(asw);

                cursor.moveToNext();
            } while (!cursor.isAfterLast());
        }

        return all;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:ro.weednet.contactssync.platform.ContactManager.java

private static long lookupProfile(ContentResolver resolver, String userId) {
    long profileId = 0;
    final Cursor c = resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
            new String[] { userId }, null);
    try {//w w w .ja v a2 s . com
        if ((c != null) && c.moveToFirst()) {
            profileId = c.getLong(ProfileQuery.COLUMN_ID);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return profileId;
}

From source file:com.facebook.Settings.java

/**
 * Acquire the current attribution id from the facebook app.
 * @return returns null if the facebook app is not present on the phone.
 */// w w  w  . ja  va  2  s.c o  m
public static String getAttributionId(ContentResolver contentResolver) {
    Cursor c = null;
    try {
        String[] projection = { ATTRIBUTION_ID_COLUMN_NAME };
        c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null);
        if (c == null || !c.moveToFirst()) {
            return null;
        }
        String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME));
        return attributionId;
    } catch (Exception e) {
        Log.d(TAG, "Caught unexpected exception in getAttributionId(): " + e.toString());
        return null;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}

From source file:ro.weednet.contactssync.platform.ContactManager.java

public static int getPhotoPickSize(Context context) {
    Cursor c = context.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
            new String[] { DisplayPhoto.DISPLAY_MAX_DIM }, null, null, null);

    try {/*from w w w  . ja  v  a  2 s.  c om*/
        c.moveToFirst();
        return c.getInt(0);
    } catch (Exception e) {
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return ContactsSync.getInstance().getPictureSize();
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

public static String getRealPathFromURI(Context mContext, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = null;
    try {//from  w  w w. j a  v a  2s .  c o m
        mContext.getContentResolver().query(contentUri, proj, null, null, null);
    } catch (Exception e) {
    }
    if (cursor == null) {
        return null;
    }
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

From source file:com.dongfang.dicos.sina.UtilSina.java

/**
 * Get a HttpClient object which is setting correctly .
 * //from  w  w  w  .  j a  va  2  s. c o m
 * @param context
 *            : context of activity
 * @return HttpClient: HttpClient object
 */
public static HttpClient getHttpClient(Context context) {
    BasicHttpParams httpParameters = new BasicHttpParams();
    // Set the default socket timeout (SO_TIMEOUT) // in
    // milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setConnectionTimeout(httpParameters, UtilSina.SET_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParameters, UtilSina.SET_SOCKET_TIMEOUT);
    HttpClient client = new DefaultHttpClient(httpParameters);
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        // ??APN
        Uri uri = Uri.parse("content://telephony/carriers/preferapn");
        Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
        if (mCursor != null && mCursor.moveToFirst()) {
            // ???
            String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
            if (proxyStr != null && proxyStr.trim().length() > 0) {
                HttpHost proxy = new HttpHost(proxyStr, 80);
                client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
            }
            mCursor.close();
        }
    }
    return client;
}