Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

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

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    BookmarkContextMenuInfo info = (BookmarkContextMenuInfo) menuInfo;
    BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition);
    Cursor cursor = adapter.getItem(info.childPosition);
    if (!canEdit(cursor)) {
        return;//from ww  w. ja  va  2 s . c  o  m
    }
    boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0;

    final Activity activity = this;
    MenuInflater inflater = activity.getMenuInflater();
    inflater.inflate(R.menu.bookmarkscontext, menu);
    if (isFolder) {
        menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true);
    } else {
        menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true);
        if (mDisableNewWindow) {
            menu.findItem(R.id.new_window_context_menu_id).setVisible(false);
        }
    }
    BookmarkItem header = new BookmarkItem(activity);
    header.setEnableScrolling(true);
    populateBookmarkItem(cursor, header, isFolder);
    menu.setHeaderView(header);

    int count = menu.size();
    for (int i = 0; i < count; i++) {
        menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener);
    }
}

From source file:com.mp3tunes.android.player.content.LockerDb.java

private Album cursorToAlbum(Cursor c) {
    if (c.getCount() > 1)
        Log.e("Mp3Tunes", "Got more than one album");
    if (c.moveToFirst()) {
        Album a = new Album(new LockerId(c.getInt(Music.ALBUM_MAPPING.ID)),
                c.getString(Music.ALBUM_MAPPING.ALBUM_NAME));
        c.close();//  w  ww.j  a v  a2  s.  co m
        return a;
    }
    c.close();
    return null;
}

From source file:se.kth.ssvl.tslab.bytewalla.androiddtn.servlib.storage.SQLiteImplementation.java

/**
 * Get the row count based on condition.
 * @param table Name of table in which record already exist
 * @param condition Get record where this condition matches
 * @param field Only get this field from resulted row
 * @return Total numbers rows//from  w ww .j  a v a2  s.c  om
 */

public int get_count(String table, String condition, String[] field) {

    int count = 0;
    try {
        Cursor cursor = db.query(table, field, condition, null, null, null, null, null);

        if (cursor != null) {
            if (cursor.moveToFirst()) {
                count = cursor.getInt(0);
                Log.d(TAG, "Records count @:" + cursor.getInt(0));
            }
        } else {
            Log.d(TAG, "Row not found!");
        }
        cursor.close();
    } catch (IndexOutOfBoundsException e) {
        Log.e(TAG, "Id Already deleted");
    } catch (SQLiteException e) {
        Log.e(TAG, "Coundn't run the query");
    } catch (Exception e) {
        Log.e(TAG, "General Exception");
    }
    return count;
}

From source file:com.polyvi.xface.extension.camera.XCameraExt.java

private void photoSucess(Intent intent) {
    //URI????URI?URI??
    //???try-catch???
    Uri uri = intent.getData();/*from  w  ww  . j a va 2s.  c  om*/
    if (null == uri) {
        uri = mImageUri;
    }
    ContentResolver resolver = getContext().getContentResolver();
    XPathResolver pathResolver = new XPathResolver(null == uri ? null : uri.toString(), "", getContext());
    Bitmap bitmap = null;
    try {
        if (!mAllowEdit) {
            String path = pathResolver.resolve();
            if (!XStringUtils.isEmptyString(path)) {
                bitmap = XUtils.decodeBitmap(path);
            }
        } else {
            //??????Android???
            bitmap = intent.getExtras().getParcelable("data");

            //?????URI
            if (bitmap == null) {
                bitmap = getCroppedBitmap(intent);
            }
        }
    } catch (OutOfMemoryError e) {
        mCallbackCtx.error("OutOfMemoryError when decode image.");
        return;
    }
    if (mDestType == DATA_URL) {
        int rotate = 0;
        String[] cols = { MediaStore.Images.Media.ORIENTATION };
        Cursor cursor = resolver.query(uri, cols, null, null, null);
        if (null != cursor) {
            cursor.moveToPosition(0);
            rotate = cursor.getInt(0);
            cursor.close();
        }
        if (0 != rotate) {
            Matrix matrix = new Matrix();
            matrix.setRotate(rotate);
            bitmap = bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        }
        bitmap = scaleBitmap(bitmap);
        processPicture(bitmap);
        bitmap.recycle();
        bitmap = null;
        System.gc();
    } else if (mTargetHeight > 0 && mTargetWidth > 0) {
        try {
            Bitmap scaleBitmap = scaleBitmap(bitmap);

            String fileName = XConfiguration.getInstance().getWorkDirectory() + RESIZED_PIC_NAME;
            OutputStream os = new FileOutputStream(fileName);
            scaleBitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, os);
            os.close();

            bitmap.recycle();
            bitmap = null;
            scaleBitmap.recycle();
            scaleBitmap = null;

            mCallbackCtx.success("file://" + fileName + "?" + System.currentTimeMillis());
            System.gc();
        } catch (Exception e) {
            mCallbackCtx.error("Error retrieving image.");
            return;
        }
    } else {
        mCallbackCtx.success(XConstant.FILE_SCHEME + pathResolver.resolve());
    }
}

From source file:com.samknows.measurement.storage.DBHelper.java

public synchronized boolean isEmpty() {
    synchronized (sync) {
        open();/*  w  w w.j a  v a  2  s  . c o m*/
        boolean ret = false;
        Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM " + SKSQLiteHelper.TABLE_TESTRESULT, null);
        cursor.moveToFirst();
        ret = cursor.getInt(0) == 0;
        cursor.close();
        close();
        return ret;
    }
}

From source file:com.flowzr.export.FlowzrIntegrationTest.java

public void test_push_category() throws Exception {

    if (dba.getAllCategories().getCount() == 2) { //only system categories
        Map<String, Category> categories = CategoryBuilder.createDefaultHierarchy(dba);
        FlowzrSyncEngine.fixCreatedEntities();
    }//from   w w  w . j  a v a 2  s.  c o m

    FlowzrSyncEngine.pushUpdate("attributes", Attribute.class);
    FlowzrSyncEngine.pushUpdate("category", Category.class);

    JSONObject json = getJsonResponse(
            FlowzrSyncEngine.FLOWZR_API_URL + "admin_example.com/category/?last_sync_ts=0");
    JSONArray result = json.getJSONArray("category");
    Cursor cursor = dba.getCategories(false);
    //minus two system categories
    assertEquals(valueOf(cursor.getCount()), valueOf(result.length()));

    if (cursor.moveToFirst()) {
        do {
            // the view doesn't contains remote_key, the test is unoptimized
            Category expect = em.load(Category.class, cursor.getInt(cursor.getColumnIndex("_id")));
            boolean gotIt = false;
            for (int i = 0; i < result.length(); i++) {
                if (expect.remoteKey.equals(result.getJSONObject(i).getString("key"))) {

                    assertEquals(expect.getTitle(), result.getJSONObject(i).getString("name"));
                    if (expect.getParentId() > 0) {
                        assertEquals(em.load(Category.class, expect.getParentId()).remoteKey,
                                result.getJSONObject(i).getString("parentCategory"));
                    }
                    assertEquals(expect.type, result.getJSONObject(i).getInt("type"));
                    gotIt = true;
                }
            }
            assertTrue(expect.title, gotIt);

        } while (cursor.moveToNext());

    }
    cursor.close();

}

From source file:com.example.xiaoma.myapplication.model.DoHttpPostJson.java

/**
 * Post????Json?// ww  w  .j av  a  2 s  .  c  o  m
 * 1
 */
@Override
public void carrealtime(final Context context, final String url) {
    new Thread() {
        @Override
        public void run() {
            final String Url = url;
            Context mContext = context;
            myDBHelper = new MyDBOpenHelper(mContext, "db_ebike", null, 1);
            db = myDBHelper.getWritableDatabase();
            /**
             * ??JsonJSONArray
             */
            String licensenumber = ""; // SN?
            int speed = 0; // 
            int drive_dis_today = 0; // 
            int drive_dis_total = 0; // 
            int drive_time_today = 0; // 
            int drive_time_total = 0; // 
            int ischarge = 0; // ?
            int islock = 0; // ??
            String gps = ""; // GPS??
            double air_quality = 0; // ?
            String uploadtime = "";
            JSONArray jsonArray = new JSONArray();
            Cursor cursor = db.query("tb_carrealtime", null, null, null, null, null, null);
            if (cursor.moveToFirst()) {
                do {
                    //int id = cursor.getInt(cursor.getColumnIndex("id"));
                    licensenumber = cursor.getString(cursor.getColumnIndex("licensenumber"));
                    speed = cursor.getInt(cursor.getColumnIndex("speed"));
                    drive_dis_today = cursor.getInt(cursor.getColumnIndex("drive_dis_today"));
                    drive_dis_total = cursor.getInt(cursor.getColumnIndex("drive_dis_total"));
                    drive_time_today = cursor.getInt(cursor.getColumnIndex("drive_time_today"));
                    drive_time_total = cursor.getInt(cursor.getColumnIndex("drive_time_total"));
                    ischarge = cursor.getInt(cursor.getColumnIndex("ischarge"));
                    islock = cursor.getInt(cursor.getColumnIndex("islock"));
                    gps = cursor.getString(cursor.getColumnIndex("gps"));
                    air_quality = cursor.getDouble(cursor.getColumnIndex("air_quality"));
                    try {
                        jsonArray.put(new JSONObject().put("licensenumber", licensenumber).put("speed", speed)
                                .put("drive_dis_today", drive_dis_today).put("drive_dis_total", drive_dis_total)
                                .put("drive_time_today", drive_time_today)
                                .put("drive_time_total", drive_time_total).put("ischarge", ischarge)
                                .put("islock", islock).put("gps", gps).put("air_quality", air_quality)
                                .put("uploadtime", uploadtime));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } while (cursor.moveToNext());
            }
            cursor.close();
            String jsonString = jsonArray.toString();

            // Post?
            List<NameValuePair> nameValuePairs = new ArrayList<>();
            nameValuePairs.add(new BasicNameValuePair("data", jsonString));

            try {
                //?HTTP
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(Url);
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                System.out.println("executing request " + httpPost.getURI());

                HttpResponse httpResponse = httpClient.execute(httpPost);
                try {
                    HttpEntity httpEntity = httpResponse.getEntity();
                    if (httpEntity != null) {
                        System.out.println("--------------------------------------");
                        System.out.println("Response content: " + EntityUtils.toString(httpEntity, "UTF-8"));
                        System.out.println("--------------------------------------");
                    }
                } finally {
                    System.out.println("--------------------------------------");
                }
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }.start();
}

From source file:com.zapto.park.ParkActivity.java

public void doPendingRequests() {
    EmployeeDB edb = new EmployeeDB(context);
    // Cursor of pending requests.
    Cursor cursor = edb.pendingClock();
    while (cursor.moveToNext()) {
        Log.i(LOG_TAG, "Sending pending request.");
        /*/*  ww  w.  j  av a  2s.  co  m*/
              cv.put("totable_license", Globals.LICENSE_KEY);
              cv.put("totable_id", idValue);
              cv.put("totable_date", timeStamp);
              cv.put("totable_inout", checkType == true ? "1" : "1");
           */
        int _id = cursor.getInt(cursor.getColumnIndex("_id"));
        String license = cursor.getString(cursor.getColumnIndex("license"));
        String employee_id = cursor.getString(cursor.getColumnIndex("employee_id"));
        String date = cursor.getString(cursor.getColumnIndex("date"));
        String inout = cursor.getString(cursor.getColumnIndex("inout"));
        int sent = cursor.getInt(cursor.getColumnIndex("sent"));

        ContentValues cv = new ContentValues();
        cv.put("totable_license", license);
        cv.put("totable_id", employee_id);
        cv.put("totable_date", date);
        cv.put("totable_inout", "1");
        Log.i(LOG_TAG, "=" + date + "=" + license + "=" + employee_id + "=");
        //cv.put("totable_inout", inout == 1 ? "1" : "1");

        try {
            Log.i(LOG_TAG, "TRY BLOCK of: doPendingRequest");
            String response = SendPost.sendPostRequest("app/clockuser.php", cv);
            Log.i(LOG_TAG, "TRY BLOCK 2 of: doPendingRequest");
            if (response.equals("1") || response.equals("0")) {
                edb.pendingSent(_id);
            }
        } catch (Exception e) {
            Log.i(LOG_TAG, "Pending resquest failed.");
        }
    }

    edb.close();
}

From source file:com.putlocker.upload.concurrency.PutlockerDownloadJob.java

@Override
public void parseResult(Cursor cursor) {
    int url_key = cursor.getColumnIndex(DOWNLOAD_URL_KEY);
    int status_column_key = cursor.getColumnIndex(DOWNLOAD_STATUS_KEY);
    int file_name_key = cursor.getColumnIndex(DOWNLOAD_FILENAME_KEY);
    int download_type_key = cursor.getColumnIndex(DOWNLOAD_TYPE_KEY);
    int file_size_index = cursor.getColumnIndex(DOWNLOAD_FILE_SIZE_KEY);
    int file_location_index = cursor.getColumnIndex(DOWNLOAD_FILE_LOCATION);
    int id_key = cursor.getColumnIndex(getIdKey());
    int original_file_location = cursor.getColumnIndex(DOWNLOAD_ORIGINAL_FILE_LOCATION);
    _id = cursor.getInt(id_key);
    url = cursor.getString(url_key);/*  w  ww . ja  v a  2  s .c  o m*/
    setStatus(DownloadStatus.statusForString(cursor.getString(status_column_key)));
    _fileLocation = cursor.getString(file_location_index);
    _fileName = cursor.getString(file_name_key);
    type = DownloadType.getTypeForInt(Integer.valueOf(cursor.getString(download_type_key)));
    _fileSize = Long.valueOf(cursor.getString(file_size_index));
    _originalFileLocation = cursor.getString(original_file_location);
}

From source file:com.cryart.sabbathschool.util.SSCore.java

public boolean quarterlyForLanguageExists() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(
            "SELECT COUNT(1) FROM ss_days, ss_lessons, ss_quarters "
                    + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial "
                    + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial "
                    + "   AND ss_quarters.quarter_lang = ?",
            new String[] { new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date()),
                    LANGUAGE });/*  www .j  ava 2  s .  c  o m*/

    c.moveToFirst();
    int count = c.getInt(0);
    c.close();

    return count > 0;
}