Example usage for android.database Cursor getDouble

List of usage examples for android.database Cursor getDouble

Introduction

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

Prototype

double getDouble(int columnIndex);

Source Link

Document

Returns the value of the requested column as a double.

Usage

From source file:com.aware.utils.WebserviceHelper.java

@Override
protected void onHandleIntent(Intent intent) {

    WEBSERVER = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER);
    DEVICE_ID = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID);
    DEBUG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true");
    DATABASE_TABLE = intent.getStringExtra(EXTRA_TABLE);
    TABLES_FIELDS = intent.getStringExtra(EXTRA_FIELDS);
    CONTENT_URI = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI));

    //Fixed: not using webservices
    if (WEBSERVER.length() == 0)
        return;/*from w w w.j  a va  2  s  .  c  o m*/

    if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_SYNC_TABLE)) {

        //Check if we should do this only over Wi-Fi
        boolean wifi_only = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY)
                .equals("true");
        if (wifi_only) {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo active_network = cm.getActiveNetworkInfo();
            if (active_network != null && active_network.getType() != ConnectivityManager.TYPE_WIFI) {
                if (DEBUG) {
                    Log.i("AWARE", "User not connected to Wi-Fi, skipping data sync.");
                }
                return;
            }
        }

        //Check first if we have database table remotely, otherwise create it!
        ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>();
        fields.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
        fields.add(new BasicNameValuePair(EXTRA_FIELDS, TABLES_FIELDS));

        //Create table if doesn't exist on the remote webservice server
        HttpResponse response = new Https(getApplicationContext())
                .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/create_table", fields);
        if (response != null && response.getStatusLine().getStatusCode() == 200) {
            if (DEBUG) {
                HttpResponse copy = response;
                try {
                    if (DEBUG)
                        Log.d(Aware.TAG, EntityUtils.toString(copy.getEntity()));
                } catch (ParseException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            String[] columnsStr = new String[] {};
            Cursor columnsDB = getContentResolver().query(CONTENT_URI, null, null, null, null);
            if (columnsDB != null && columnsDB.moveToFirst()) {
                columnsStr = columnsDB.getColumnNames();
                if (DEBUG)
                    Log.d(Aware.TAG, "Total records on " + DATABASE_TABLE + ": " + columnsDB.getCount());
            }
            if (columnsDB != null && !columnsDB.isClosed())
                columnsDB.close();

            try {
                ArrayList<NameValuePair> request = new ArrayList<NameValuePair>();
                request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));

                //check the latest entry in remote database
                HttpResponse latest = new Https(getApplicationContext())
                        .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/latest", request);
                if (latest == null)
                    return;

                String data = "[]";
                try {
                    data = EntityUtils.toString(latest.getEntity());
                } catch (IllegalStateException e) {
                    Log.d(Aware.TAG, "Unable to connect to webservices...");
                }

                if (DEBUG) {
                    Log.d(Aware.TAG, "Webservice response: " + data);
                }

                //If in a study, get from joined date onwards
                String study_condition = "";
                if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0
                        && Aware.getSetting(getApplicationContext(), "study_start").length() > 0) {
                    String study_start = Aware.getSetting(getApplicationContext(), "study_start");
                    study_condition = " AND timestamp > " + Long.parseLong(study_start);
                }
                if (DATABASE_TABLE.equalsIgnoreCase("aware_device"))
                    study_condition = "";

                JSONArray remoteData = new JSONArray(data);

                Cursor context_data;
                if (remoteData.length() == 0) {
                    if (exists(columnsStr, "double_end_timestamp")) {
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "double_end_timestamp != 0" + study_condition, null, "timestamp ASC");
                    } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) {
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "double_esm_user_answer_timestamp != 0" + study_condition, null,
                                "timestamp ASC");
                    } else {
                        context_data = getContentResolver().query(CONTENT_URI, null, "1" + study_condition,
                                null, "timestamp ASC");
                    }
                } else {
                    long last = 0;
                    if (exists(columnsStr, "double_end_timestamp")) {
                        last = remoteData.getJSONObject(0).getLong("double_end_timestamp");
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition,
                                null, "timestamp ASC");
                    } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) {
                        last = remoteData.getJSONObject(0).getLong("double_esm_user_answer_timestamp");
                        context_data = getContentResolver().query(
                                CONTENT_URI, null, "timestamp > " + last
                                        + " AND double_esm_user_answer_timestamp != 0" + study_condition,
                                null, "timestamp ASC");
                    } else {
                        last = remoteData.getJSONObject(0).getLong("timestamp");
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "timestamp > " + last + study_condition, null, "timestamp ASC");
                    }
                }

                JSONArray context_data_entries = new JSONArray();
                if (context_data != null && context_data.moveToFirst()) {
                    if (DEBUG)
                        Log.d(Aware.TAG, "Uploading " + context_data.getCount() + " from " + DATABASE_TABLE);

                    do {
                        JSONObject entry = new JSONObject();

                        String[] columns = context_data.getColumnNames();
                        for (String c_name : columns) {

                            //Skip local database ID
                            if (c_name.equals("_id"))
                                continue;

                            if (c_name.equals("timestamp") || c_name.contains("double")) {
                                entry.put(c_name, context_data.getDouble(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("float")) {
                                entry.put(c_name, context_data.getFloat(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("long")) {
                                entry.put(c_name, context_data.getLong(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("blob")) {
                                entry.put(c_name, context_data.getBlob(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("integer")) {
                                entry.put(c_name, context_data.getInt(context_data.getColumnIndex(c_name)));
                            } else {
                                entry.put(c_name, context_data.getString(context_data.getColumnIndex(c_name)));
                            }
                        }
                        context_data_entries.put(entry);

                        if (context_data_entries.length() == 1000) {
                            request = new ArrayList<NameValuePair>();
                            request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
                            request.add(new BasicNameValuePair("data", context_data_entries.toString()));
                            new Https(getApplicationContext())
                                    .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request);

                            context_data_entries = new JSONArray();
                        }
                    } while (context_data.moveToNext());

                    if (context_data_entries.length() > 0) {
                        request = new ArrayList<NameValuePair>();
                        request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
                        request.add(new BasicNameValuePair("data", context_data_entries.toString()));
                        new Https(getApplicationContext())
                                .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request);
                    }
                } else {
                    if (DEBUG)
                        Log.d(Aware.TAG,
                                "Nothing new in " + DATABASE_TABLE + "!" + " URI=" + CONTENT_URI.toString());
                }

                if (context_data != null && !context_data.isClosed())
                    context_data.close();

            } catch (ParseException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //Clear database table remotely
    if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_CLEAR_TABLE)) {
        ArrayList<NameValuePair> request = new ArrayList<NameValuePair>();
        request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
        new Https(getApplicationContext()).dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/clear_table", request);
    }
}

From source file:com.example.rartonne.appftur.HomeActivity.java

public void syncDwh() {
    String[] tables = { "pda_sec_id_data",
            //"batch_nr_checking",
            //"customer_incident",
            //"PROCESS_LOG",
            "\"SCAN_LOG\"", "ordernr_sites" };

    for (String table : tables) {
        try {/*from   w  ww .  ja v  a2  s .  c  o  m*/
            String fields = "";
            String values = "";
            String urlPost = "http://admin.qr-ut.com/webservice/pdaws.php?action=syncDwh";
            List<NameValuePair> data = new ArrayList<>();
            String param = "";
            String updateScanlog = "";
            String updatePdaSecIdData = "";
            //on initalise la connexion  la base
            SQLiteDatabase bdd;
            DataBaseHelper myDbHelper = new DataBaseHelper(getApplicationContext());
            String format = "yyyy/MM/dd HH:mm:ss";
            SimpleDateFormat formater = new SimpleDateFormat(format);
            String date = formater.format(new Date());

            try {
                myDbHelper.createDataBase();
            } catch (IOException e) {
                e.printStackTrace();
            }

            myDbHelper.openDataBase();

            bdd = myDbHelper.getWritableDatabase();

            Cursor cursor;

            if (table == "\"SCAN_LOG\"") {
                cursor = bdd.rawQuery("SELECT * FROM " + table, null);
            } else if (table == "ordernr_sites") {
                cursor = bdd
                        .rawQuery(
                                "SELECT ordernr, status_code, modified_by, modified_on, installer_id FROM "
                                        + table + " WHERE modified_on > '" + GlobalClass.getLastUpdate() + "'",
                                null);
            } else {
                cursor = bdd.rawQuery("SELECT * FROM " + table + " WHERE createdon > " + "'"
                        + GlobalClass.getLastUpdate() + "'", null);
            }

            while (cursor.moveToNext()) {
                switch (table) {
                case "pda_sec_id_data":
                    fields = "type, value, createdon, modifiedon, gf_sec_id";
                    values = "'" + cursor.getString(1) + "', '" + cursor.getString(2) + "', '"
                            + cursor.getString(3) + "', '" + cursor.getString(4) + "', '" + cursor.getString(5)
                            + "'";
                    updatePdaSecIdData = "UPDATE pda_sec_id_data SET value = '" + cursor.getString(2)
                            + "', modifiedon = '" + cursor.getString(4) + "' WHERE gf_sec_id = '"
                            + cursor.getString(5) + "' AND type = '" + cursor.getString(1) + "';";
                    break;

                case "batch_nr_checking":
                    fields = "createdon, modifiedon, gps_lat, gps_long, createdby, modifiedby, status_code, isonline, checking_source, last_update_batch, last_synchro_blacklist, gf_sec_id, batch_nr_checking_id, batch_nr, article_id";
                    values = "";
                    break;

                case "customer_incident":
                    fields = "";
                    values = "";
                    break;

                case "PROCESS_LOG":
                    fields = "process_type, process_date, comment, object_name, status_code, interface_type, action";
                    values = "'" + cursor.getString(0) + "', '" + cursor.getString(1) + "', '"
                            + cursor.getString(2) + "', '" + cursor.getString(3) + "', " + cursor.getInt(4)
                            + ", '" + cursor.getString(5) + "', '" + cursor.getString(6) + "'";
                    break;

                case "\"SCAN_LOG\"":
                    fields = "gf_sec_id, gps_lat, gps_long, scan_date, user_id, status_code, art_id, customer_order_nr, welding_sketch_nr, serial_wm_nr, fusion_nr, source";
                    values = "'" + cursor.getString(0) + "', " + cursor.getDouble(1) + ", "
                            + cursor.getDouble(2) + ", '" + cursor.getString(3) + "', " + cursor.getInt(4)
                            + ", " + cursor.getInt(5) + ", '" + cursor.getString(6) + "', '"
                            + cursor.getString(7) + "', '" + cursor.getString(8) + "', '" + cursor.getString(9)
                            + "', " + cursor.getInt(10) + ", '" + cursor.getString(11) + "'";
                    updateScanlog += "UPDATE \"SCAN_LOG\" SET gps_lat = " + cursor.getDouble(1)
                            + ", gps_long = " + cursor.getDouble(2) + ", scan_date = '" + cursor.getString(3)
                            + "'" + ", user_id = " + cursor.getInt(4) + ", status_code = " + cursor.getInt(5)
                            + ", art_id = '" + cursor.getString(6) + "', customer_order_nr = '"
                            + cursor.getString(7) + "'" + ", welding_sketch_nr = '" + cursor.getString(8)
                            + "', serial_wm_nr = '" + cursor.getString(9) + "', fusion_nr = "
                            + cursor.getInt(10) + " WHERE gf_sec_id = '" + cursor.getString(0)
                            + "' AND source = 'PDA';";
                    break;

                case "ordernr_sites":
                    fields = "ordernr, status_code, modified_by, modified_on, installer_id";
                    values = "'" + cursor.getString(0) + "', " + cursor.getInt(1) + ", " + cursor.getInt(2)
                            + ", '" + cursor.getString(3) + "', " + cursor.getInt(4);
                    break;
                }
                param += "INSERT INTO " + table + " (" + fields + ") VALUES (" + values + ");";
                //break;
            }

            param += updatePdaSecIdData;
            param += updateScanlog;
            param += "UPDATE pda_settings SET last_update = '" + GlobalClass.getLastUpdate()
                    + "' WHERE pda_id = '" + GlobalClass.getSerialNumber() + "'";
            data.add(new BasicNameValuePair("data", param));

            //on envoie les INSERT
            new HttpAsyncTaskPost(this, data).execute(urlPost);

            cursor.close();

            bdd.close();

            GlobalClass.setLastUpdate(date);
            startActivity(new Intent(this, HomeActivity.class)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java

private Program convertCursorToProgram(Cursor cursor, final String table) {
    //      Log.v( TAG, "convertCursorToProgram : enter" );

    DateTime startTime = null, endTime = null, lastModified = null, airDate = null;
    String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "",
            hostname = "", filename = "", description = "", inetref = "";
    int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1,
            episode = -1;/*from  ww w. j a va 2 s. co m*/
    long fileSize = -1;
    double stars = 0.0f;

    ChannelInfo channelInfo = null;
    RecordingInfo recording = null;

    if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) {
        startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) {
        endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) {
        title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) {
        subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) {
        category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) {
        categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) {
        repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) {
        videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) {
        audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) {
        subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) {
        seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) {
        programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) {
        stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) {
        fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) {
        lastModified = new DateTime(
                cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) {
        programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) {
        hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) {
        filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) {
        try {
            airDate = DateUtils.dateFormatter
                    .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE)));
        } catch (Exception e) {
            Log.w(TAG, "AirDate could not be parsed");
        }
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) {
        description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) {
        inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) {
        season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) {
        episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE));
    }

    Program program = new Program();
    program.setStartTime(startTime);
    program.setEndTime(endTime);
    program.setTitle(title);
    program.setSubTitle(subTitle);
    program.setCategory(category);
    program.setCatType(categoryType);
    program.setRepeat(repeat == 1 ? true : false);
    program.setVideoProps(videoProps);
    program.setAudioProps(audioProps);
    program.setSubProps(subProps);
    program.setSeriesId(seriesId);
    program.setProgramId(programId);
    program.setStars(stars);
    program.setFileSize(fileSize);
    program.setLastModified(lastModified);
    program.setProgramFlags(programFlags);
    program.setHostName(hostname);
    program.setFileName(filename);
    program.setAirdate(null != airDate ? airDate.toLocalDate() : null);
    program.setDescription(description);
    program.setInetref(inetref);
    program.setSeason(season);
    program.setEpisode(episode);
    program.setChannel(channelInfo);
    program.setRecording(recording);

    //      Log.v( TAG, "convertCursorToProgram : exit" );
    return program;
}

From source file:org.mythtv.service.dvr.v25.ProgramHelperV25.java

private Program convertCursorToProgram(Cursor cursor, final String table) {
    //      Log.v( TAG, "convertCursorToProgram : enter" );

    DateTime startTime = null, endTime = null, lastModified = null, airDate = null;
    String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "",
            hostname = "", filename = "", description = "", inetref = "";
    int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1,
            episode = -1;//from   w ww.j a  va 2 s .  com
    long fileSize = -1;
    double stars = 0.0f;

    ChannelInfo channelInfo = null;
    RecordingInfo recording = null;

    if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) {
        startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) {
        endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) {
        title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) {
        subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) {
        category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) {
        categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) {
        repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) {
        videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) {
        audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) {
        subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) {
        seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) {
        programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) {
        stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) {
        fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) {
        lastModified = new DateTime(
                cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) {
        programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) {
        hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) {
        filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) {
        try {
            airDate = DateUtils.dateFormatter
                    .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE)));
        } catch (Exception e) {
            Log.w(TAG, "AirDate could not be parsed");
        }
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) {
        description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) {
        inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) {
        season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) {
        episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID) != -1) {
        channelInfo = ChannelHelperV25.getInstance().convertCursorToChannelInfo(cursor);
    }

    if (cursor.getColumnIndex(RecordingConstants.ContentDetails.getValueFromParent(table).getTableName() + "_"
            + RecordingConstants.FIELD_RECORD_ID) != -1) {
        recording = RecordingHelperV25.getInstance().convertCursorToRecording(cursor, table);
    }

    Program program = new Program();
    program.setStartTime(startTime);
    program.setEndTime(endTime);
    program.setTitle(title);
    program.setSubTitle(subTitle);
    program.setCategory(category);
    program.setCatType(categoryType);
    program.setRepeat(repeat == 1 ? true : false);
    program.setVideoProps(videoProps);
    program.setAudioProps(audioProps);
    program.setSubProps(subProps);
    program.setSeriesId(seriesId);
    program.setProgramId(programId);
    program.setStars(stars);
    program.setFileSize(fileSize);
    program.setLastModified(lastModified);
    program.setProgramFlags(programFlags);
    program.setHostName(hostname);
    program.setFileName(filename);
    program.setAirdate(null != airDate ? airDate.toLocalDate() : null);
    program.setDescription(description);
    program.setInetref(inetref);
    program.setSeason(season);
    program.setEpisode(episode);
    program.setChannel(channelInfo);
    program.setRecording(recording);

    //      Log.v( TAG, "convertCursorToProgram : exit" );
    return program;
}

From source file:org.mythtv.service.dvr.v26.ProgramHelperV26.java

private Program convertCursorToProgram(Cursor cursor, final String table) {
    //      Log.v( TAG, "convertCursorToProgram : enter" );

    DateTime startTime = null, endTime = null, lastModified = null, airDate = null;
    String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "",
            hostname = "", filename = "", description = "", inetref = "";
    int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1,
            episode = -1;/*from  w  ww . j  av  a  2  s.  co  m*/
    long fileSize = -1;
    double stars = 0.0f;

    ChannelInfo channelInfo = null;
    RecordingInfo recording = null;

    if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) {
        startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) {
        endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) {
        title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) {
        subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) {
        category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) {
        categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) {
        repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) {
        videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) {
        audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) {
        subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) {
        seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) {
        programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) {
        stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) {
        fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) {
        lastModified = new DateTime(
                cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) {
        programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) {
        hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) {
        filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) {
        try {
            airDate = DateUtils.dateFormatter
                    .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE)));
        } catch (Exception e) {
            Log.w(TAG, "AirDate could not be parsed");
        }
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) {
        description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) {
        inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) {
        season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) {
        episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID) != -1) {
        channelInfo = ChannelHelperV26.getInstance().convertCursorToChannelInfo(cursor);
    }

    if (cursor.getColumnIndex(RecordingConstants.ContentDetails.getValueFromParent(table).getTableName() + "_"
            + RecordingConstants.FIELD_RECORD_ID) != -1) {
        recording = RecordingHelperV26.getInstance().convertCursorToRecording(cursor, table);
    }

    Program program = new Program();
    program.setStartTime(startTime);
    program.setEndTime(endTime);
    program.setTitle(title);
    program.setSubTitle(subTitle);
    program.setCategory(category);
    program.setCatType(categoryType);
    program.setRepeat(repeat == 1 ? true : false);
    program.setVideoProps(videoProps);
    program.setAudioProps(audioProps);
    program.setSubProps(subProps);
    program.setSeriesId(seriesId);
    program.setProgramId(programId);
    program.setStars(stars);
    program.setFileSize(fileSize);
    program.setLastModified(lastModified);
    program.setProgramFlags(programFlags);
    program.setHostName(hostname);
    program.setFileName(filename);
    program.setAirdate(null != airDate ? airDate.toLocalDate() : null);
    program.setDescription(description);
    program.setInetref(inetref);
    program.setSeason(season);
    program.setEpisode(episode);
    program.setChannel(channelInfo);
    program.setRecording(recording);

    //      Log.v( TAG, "convertCursorToProgram : exit" );
    return program;
}

From source file:org.mythtv.service.dvr.v27.ProgramHelperV27.java

private Program convertCursorToProgram(Cursor cursor, final String table) {
    //      Log.v( TAG, "convertCursorToProgram : enter" );

    DateTime startTime = null, endTime = null, lastModified = null, airDate = null;
    String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "",
            hostname = "", filename = "", description = "", inetref = "";
    int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1,
            episode = -1;/*ww w. j  a va2 s.  c  o  m*/
    long fileSize = -1;
    double stars = 0.0f;

    ChannelInfo channelInfo = null;
    RecordingInfo recording = null;

    if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) {
        startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) {
        endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) {
        title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) {
        subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) {
        category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) {
        categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) {
        repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) {
        videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) {
        audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) {
        subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) {
        seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) {
        programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) {
        stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) {
        fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) {
        lastModified = new DateTime(
                cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED)));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) {
        programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) {
        hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) {
        filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) {
        try {
            airDate = DateUtils.dateFormatter
                    .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE)));
        } catch (Exception e) {
            Log.w(TAG, "AirDate could not be parsed");
        }
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) {
        description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) {
        inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) {
        season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) {
        episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE));
    }

    if (cursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID) != -1) {
        channelInfo = ChannelHelperV27.getInstance().convertCursorToChannelInfo(cursor);
    }

    if (cursor.getColumnIndex(RecordingConstants.ContentDetails.getValueFromParent(table).getTableName() + "_"
            + RecordingConstants.FIELD_RECORD_ID) != -1) {
        recording = RecordingHelperV27.getInstance().convertCursorToRecording(cursor, table);
    }

    Program program = new Program();
    program.setStartTime(startTime);
    program.setEndTime(endTime);
    program.setTitle(title);
    program.setSubTitle(subTitle);
    program.setCategory(category);
    program.setCatType(categoryType);
    program.setRepeat(repeat == 1 ? true : false);
    program.setVideoProps(videoProps);
    program.setAudioProps(audioProps);
    program.setSubProps(subProps);
    program.setSeriesId(seriesId);
    program.setProgramId(programId);
    program.setStars(stars);
    program.setFileSize(fileSize);
    program.setLastModified(lastModified);
    program.setProgramFlags(programFlags);
    program.setHostName(hostname);
    program.setFileName(filename);
    program.setAirdate(null != airDate ? airDate.toLocalDate() : null);
    program.setDescription(description);
    program.setInetref(inetref);
    program.setSeason(season);
    program.setEpisode(episode);
    program.setChannel(channelInfo);
    program.setRecording(recording);

    //      Log.v( TAG, "convertCursorToProgram : exit" );
    return program;
}

From source file:info.wncwaterfalls.app.ResultsMapFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    int count = cursor.getCount();
    if (count == 0) {
        Context context = getActivity();
        CharSequence text = "No results found for your search.";
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();//  w  ww  . j  ava2  s. c  o  m
    } else {
        // Put the results on a map!
        GoogleMap googleMap = mMapView.getMap();
        double searchLocationDistanceM = 0;
        LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
        if (cursor.moveToFirst()) {
            // First, add the "searched for" location, if it was a location search.
            Location originLocation = new Location("");
            Address originAddress = sLocationQueryListener.getOriginAddress();
            if (originAddress != null) {
                // Get searched-for distance and convert to meters.
                short searchLocationDistance = sLocationQueryListener.getSearchLocationDistance();
                searchLocationDistanceM = searchLocationDistance * 1609.34;

                // Build up a list of Address1, Address2, Address3, if present.
                ArrayList<String> addressList = new ArrayList<String>();
                for (int i = 0; i <= 3; i++) {
                    String line = originAddress.getAddressLine(i);
                    if (line != null && line.length() > 0) {
                        addressList.add(line);
                    }
                }

                String addressDesc = TextUtils.join("\n", addressList);
                if (addressDesc == "") {
                    addressDesc = originAddress.getFeatureName();
                }
                if (addressDesc == "") {
                    addressDesc = "Searched Location";
                }

                // Create the LatLng and the map marker.
                LatLng originLatLng = new LatLng(originAddress.getLatitude(), originAddress.getLongitude());
                googleMap.addMarker(new MarkerOptions().position(originLatLng)
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
                        .title(addressDesc));

                boundsBuilder.include(originLatLng); // In case only one result :)

                // Translate into a Location for distance comparison.
                originLocation.setLatitude(originAddress.getLatitude());
                originLocation.setLongitude(originAddress.getLongitude());
            } else {
                // Not a location search; don't add point for searched-for location
                // and don't check radius from that point.
                //Log.d(TAG, "Skipped adding origin address to map.");
            }

            // Next, add the results waterfalls.
            // Use do...while since we're already at the first result.
            do {
                // Get some data from the db
                Long waterfallId = cursor.getLong(AttrDatabase.COLUMNS.indexOf("_id"));
                double lat = cursor.getDouble(AttrDatabase.COLUMNS.indexOf("geo_lat"));
                double lon = cursor.getDouble(AttrDatabase.COLUMNS.indexOf("geo_lon"));

                // Make sure this one's actually within our search radius. SQL only checked
                // the bounding box.
                Location waterfallLocation = new Location("");
                waterfallLocation.setLatitude(lat);
                waterfallLocation.setLongitude(lon);

                if (originAddress == null
                        || (originLocation.distanceTo(waterfallLocation) <= searchLocationDistanceM)) {
                    // Not a location search (originAddress is null: show all) or within radius.
                    // Display on map.
                    String name = cursor.getString(AttrDatabase.COLUMNS.indexOf("name"));

                    LatLng waterfallLatLng = new LatLng(lat, lon);
                    Marker waterfallMarker = googleMap.addMarker(new MarkerOptions().position(waterfallLatLng)
                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
                            .title(name));

                    // Save the id so we can retrieve it when clicked
                    mMarkersToIds.put(waterfallMarker, waterfallId);
                    boundsBuilder.include(waterfallLatLng);
                }

            } while (cursor.moveToNext());

            // Zoom and center the map to bounds
            mResultBounds = boundsBuilder.build();
            zoomToBounds();
        }
    }
}

From source file:com.jackie.movies.ui.MovieActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data == null || data.getCount() <= 0) {
        Log.d(TAG, "onLoadFinished: data is empty");
        recyclerView.removeMoreListener();
        recyclerView.hideMoreProgress();
        recyclerView.setLoadingMore(false);
        recyclerView.setRefreshing(false);
        currentPage = 1;/*  ww w  .  java  2  s  .c  o  m*/
        return;
    }

    entity = new MovieEntity();
    List<MovieItem> details = new LinkedList<>();
    final int columnTotalResults = data.getColumnIndex(Page.TOTAL_RESULTS);
    final int columnPosterPath = data.getColumnIndex(Movie.POSTER_PATH);
    final int columnAdult = data.getColumnIndex(Movie.ADULT);
    final int columnOverview = data.getColumnIndex(Movie.OVERVIEW);
    final int columnReleaseDate = data.getColumnIndex(Movie.RELEASE_DATE);
    final int columnId = data.getColumnIndex(Movie.MOVIE_ID);
    final int columnOriginalTitle = data.getColumnIndex(Movie.ORIGINAL_TITLE);
    final int columnOriginalLanguage = data.getColumnIndex(Movie.ORIGINAL_LANGUAGE);
    final int columnTitle = data.getColumnIndex(Movie.TITLE);
    final int columnBackdropPath = data.getColumnIndex(Movie.BACKDROP_PATH);
    final int columnPopularity = data.getColumnIndex(Movie.POPULARITY);
    final int columnVoteCount = data.getColumnIndex(Movie.VOTE_COUNT);
    final int columnVideo = data.getColumnIndex(Movie.VIDEO);
    final int columnVoteAverage = data.getColumnIndex(Movie.VOTE_AVERAGE);
    final int columnGenreIds = data.getColumnIndex(Movie.GENRE_IDS);
    final int columnFavour = data.getColumnIndex(Movie.FAVOUR);

    boolean hasPage = columnTotalResults > -1;
    Log.d(TAG, "onLoadFinished: hasPage is " + hasPage);
    while (data.moveToNext()) {
        if (hasPage && entity.getTotal_pages() == -1) {
            int columnPageType = data.getColumnIndex(Page.PAGE_TYPE);
            int columnTotalPages = data.getColumnIndex(Page.TOTAL_PAGES);

            entity.setPage(data.getInt(columnPageType) >> 2);
            entity.setTotal_pages(data.getInt(columnTotalPages));
            entity.setTotal_results(data.getInt(columnTotalResults));
        }
        MovieItem detail = new MovieItem();
        //        String poster_path;
        detail.setPoster_path(data.getString(columnPosterPath));
        //        boolean adult;
        detail.setAdult(data.getInt(columnAdult) == 1);
        //        String overview;
        detail.setOverview(data.getString(columnOverview));
        //        String release_date;
        detail.setRelease_date(data.getString(columnReleaseDate));
        //        long id;
        detail.setId(data.getLong(columnId));
        //        String original_title;
        detail.setOriginal_title(data.getString(columnOriginalTitle));
        //        String original_language;
        detail.setOriginal_language(data.getString(columnOriginalLanguage));
        //        String title;
        detail.setTitle(data.getString(columnTitle));
        //        String backdrop_path;
        detail.setBackdrop_path(data.getString(columnBackdropPath));
        //        double popularity;
        detail.setPopularity(data.getDouble(columnPopularity));
        //        int vote_count;
        detail.setVote_count(data.getInt(columnVoteCount));
        //        boolean video;
        detail.setVideo(data.getInt(columnVideo) == 1);
        //        double vote_average;
        detail.setVote_average(data.getDouble(columnVoteAverage));
        //        List<Integer> genre_ids;
        String[] split = data.getString(columnGenreIds).split(",");
        List<Integer> ids = new LinkedList<>();
        for (String s : split) {
            if (TextUtils.isEmpty(s)) {
                continue;
            }
            ids.add(Integer.valueOf(s));
        }
        detail.setGenre_ids(ids);
        detail.setFavour(data.getInt(columnFavour) == 1);
        details.add(detail);
    }
    entity.setResults(details);
    onSuccess(entity);
}

From source file:de.sindzinski.wetter.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

        //            if ( Utility.usingLocalGraphics(getActivity()) ) {
        //                mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));
        //            } else {
        //                // Use weather art image
        //                Glide.with(this)
        //                        .load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId))
        //                        .error(Utility.getArtResourceForWeatherCondition(weatherId))
        //                        .crossFade()
        //                        .into(mIconView);
        //            }

        if (Utility.getProvider(getActivity()).equals(this.getString(R.string.pref_provider_wug))) {
            String icon = data.getString(COL_WEATHER_ICON);
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            String artPack = prefs.getString(this.getString(R.string.pref_art_pack_wug_key),
                    this.getString(R.string.pref_art_pack_wug_alt_black));
            Glide.with(this).load(String.format(Locale.US, artPack, icon))
                    //.error(defaultImage)
                    .crossFade().into(mIconView);
        } else {/*from ww w.java 2  s.co m*/
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            String artPack = prefs.getString(this.getString(R.string.pref_art_pack_key),
                    this.getString(R.string.pref_art_pack_sunshine));

            if (artPack.equals(this.getString(R.string.pref_art_pack_owm))) {
                String icon = data.getString(COL_WEATHER_ICON);
                Glide.with(this).load(String.format(Locale.US, artPack, icon))
                        //                            .error(defaultImage)
                        .crossFade().into(mIconView);
            } else if (artPack.equals(this.getString(R.string.pref_art_pack_cute_dogs))) {
                Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId))
                        //                            .error(defaultImage)
                        .crossFade().into(mIconView);
            } else {
                // local images
                mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));
            }
        }

        // Read date from cursor and update views for day of week and date
        long date = data.getLong(COL_WEATHER_DATE);
        String timeZoneName = data.getString(COL_TIME_ZONE);
        String friendlyDateText = Utility.getDailyDayString(getActivity(), date, timeZoneName);
        String dateText = Utility.getFormattedMonthDay(getActivity(), date, timeZoneName);
        mFriendlyDateView.setText(friendlyDateText);
        mDateView.setText(dateText);

        // Read description from cursor and update view
        String description = data.getString(COL_WEATHER_DESC);
        mDescriptionView.setText(description);

        // For accessibility, add a content description to the icon field
        mIconView.setContentDescription(description);

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high, isMetric);
        mHighTempView.setText(highString);

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
        mLowTempView.setText(lowString);

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));

        // Read wind speed and direction from cursor and update view
        float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
        float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

        // Read pressure from cursor and update view
        float pressure = data.getFloat(COL_WEATHER_PRESSURE);
        mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure));

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

        // If onCreateOptionsMenu has already happened, we need to update the share intent now.
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareForecastIntent());
        }
    }
}