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.fbartnitzek.tasteemall.addentry.AddLocationFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    Log.v(LOG_TAG, "onLoadFinished, hashCode=" + this.hashCode() + ", " + "loader = [" + loader + "], data = ["
            + data + "]");

    if (data != null && data.moveToFirst()) {
        // variables not really needed - optimize later...
        int location_Id = data.getInt(QueryColumns.LocationFragment.ShowQuery.COL__ID);
        String desc = data.getString(QueryColumns.LocationFragment.ShowQuery.COL_DESCRIPTION);
        mEditLocationDescription.setText(desc);

        //            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //                mEditProducerName.setTransitionName(
        //                        getString(R.string.shared_transition_producer_producer) + producer_Id);
        //            }

        mOriginalLocationInput = data.getString(QueryColumns.LocationFragment.ShowQuery.COL_INPUT);
        mOriginalLocationFormatted = data
                .getString(QueryColumns.LocationFragment.ShowQuery.COL_FORMATTED_ADDRESS);
        mLocationParcelable = new LocationParcelable(LocationParcelable.INVALID_ID, // ignored by update
                data.getString(QueryColumns.LocationFragment.ShowQuery.COL_COUNTRY), "", // ignored by update
                data.getDouble(QueryColumns.LocationFragment.ShowQuery.COL_LATITUDE),
                data.getDouble(QueryColumns.LocationFragment.ShowQuery.COL_LONGITUDE), mOriginalLocationInput,
                mOriginalLocationFormatted, null);

        Log.v(LOG_TAG, "onLoadFinished, hashCode=" + this.hashCode() + ", mLocationParcelable=["
                + mLocationParcelable + "]");

        if (!Utils.isNetworkUnavailable(getActivity())
                && DatabaseContract.LocationEntry.GEOCODE_ME.equals(mOriginalLocationFormatted)) {
            // geocode
            mEditLocation.setText(mOriginalLocationInput);
        } else {//from  w  ww  .  jav  a 2 s  .c  om
            updateLocationText();
        }

        if (Utils.isValidLocation(mLocationParcelable)) {
            showMap();
            updateAndMoveToMarker();
        } else {
            hideMap();
        }

        //            updateToolbar(name);
        //            resumeActivityEnterTransition();    // from edit

    }
}

From source file:com.example.calero.counters.app.UI.Fragments.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    if (cursor != null && cursor.moveToFirst()) {

        int columnIndexStart;
        int columnIndexStop;

        columnIndexStart = cursor.getColumnIndex(CountersContract.CountersEntry.COLUMN_COUNTED);
        if (columnIndexStart != -1)
            countedTextView.setText(cursor.getString(columnIndexStart));

        columnIndexStart = cursor.getColumnIndex(CountersContract.CountersEntry.COLUMN_TYPE);
        if (columnIndexStart != -1) {
            iconImageView.setImageResource(
                    UtilApplication.getArtResourceForCounterType(cursor.getInt(columnIndexStart)));
            typeTextView//w  w w .  ja  va  2 s  . c  o  m
                    .setText(UtilApplication.getTextResourceForCounterType(cursor.getInt(columnIndexStart)));
        }

        columnIndexStart = cursor.getColumnIndex(CountersContract.CountersEntry.COLUMN_STAR);
        columnIndexStop = cursor.getColumnIndex(CountersContract.CountersEntry.COLUMN_STOP);

        if (columnIndexStart != -1 && columnIndexStop != -1) {
            try {
                friendlyDateTextView.setText(UtilDate.getFormattedMonthDay(cursor.getString(columnIndexStart)));
                elapsedDateTextView.setText(UtilDate.getDateInLine(cursor.getString(columnIndexStart),
                        cursor.getString(columnIndexStop)));
                minutesTextView.setText(UtilDate.getMinutesAndSecondsDifference(
                        cursor.getString(columnIndexStart), cursor.getString(columnIndexStop)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        columnIndexStart = cursor.getColumnIndex(CountersContract.CountersEntry.COLUMN_LATITUDE);
        if (columnIndexStart != -1)
            latitudeValue = cursor.getDouble(columnIndexStart);
        latitudeTextView.setText(getActivity().getString(R.string.format_latitude, latitudeValue));

        columnIndexStart = cursor.getColumnIndex(CountersContract.CountersEntry.COLUMN_LONGITUDE);
        if (columnIndexStart != -1)
            longitudeValue = cursor.getDouble(columnIndexStart);
        longitudeTextView.setText(getActivity().getString(R.string.format_longitude, longitudeValue));

        // Shared information--------------------------------------------

        counters = String.format("%s - %s", typeTextView.getText(), countedTextView.getText());
        if (shareActionProvider != null) {
            shareActionProvider.setShareIntent(createShareCountedIntent());
        }
    }
}

From source file:com.ichi2.anki.SyncClient.java

private JSONArray cursorToJSONArray(Cursor cursor) {
    JSONArray jsonArray = new JSONArray();
    while (cursor.moveToNext()) {
        JSONArray element = new JSONArray();

        try {// w  w  w .j a v a 2s  . co  m
            element.put(cursor.getLong(0));
            element.put(cursor.getDouble(1));
        } catch (JSONException e) {
            Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage());
        }
        jsonArray.put(element);
    }

    cursor.close();

    return jsonArray;
}

From source file:com.google.android.apps.mytracks.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
    setContentView(R.layout.track_list);

    AnalyticsUtils.sendPageViews(this, this.getLocalClassName() + "/create");

    ApiAdapterFactory.getApiAdapter().hideActionBar(this);

    Display display = getWindowManager().getDefaultDisplay();
    boolean devicesZ = display.getWidth() > 720 || display.getHeight() > 720;
    if (devicesZ) {
        // Disable the Keyboard help link
        View v = findViewById(R.id.help_keyboard_q);
        if (v != null)
            v.setVisibility(View.GONE);
        v = findViewById(R.id.help_keyboard_a);
        if (v != null)
            v.setVisibility(View.GONE);
    }/*from   w w  w. j a v a2 s  .  c om*/
    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);

    SharedPreferences sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
    sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
    sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null);

    trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener,
            stopListener);

    // START MOD
    ImageButton helpButton = (ImageButton) findViewById(R.id.listBtnBarHelp);
    if (helpButton != null)
        helpButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = IntentUtils.newIntent(TrackListActivity.this, HelpActivity.class);
                startActivity(intent);
            }
        });
    /*
     * Record = Pause and Stop managed by track controller ImageButton
     * recordButton = (ImageButton) findViewById(R.id.listBtnBarRecord);
     * recordButton.setOnClickListener(recordListener); ImageButton stopButton =
     * (ImageButton) findViewById(R.id.listBtnBarStop);
     * stopButton.setOnClickListener(stopListener);
     */
    ImageButton searchButton = (ImageButton) findViewById(R.id.listBtnBarSearch);
    if (searchButton != null)
        searchButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                onSearchRequested();
            }
        });
    ImageButton settingsButton = (ImageButton) findViewById(R.id.listBtnBarSettings);
    if (settingsButton != null)
        settingsButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = IntentUtils.newIntent(TrackListActivity.this, SettingsActivity.class);
                startActivity(intent);
            }
        });

    // END MOD
    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty_view));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            startActivity(intent);
        }
    });
    resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);

            boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
            int iconId = TrackIconUtils.getIconDrawable(cursor.getString(iconIndex));
            String name = cursor.getString(nameIndex);
            String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = StringUtils.formatDistance(TrackListActivity.this,
                    cursor.getDouble(totalDistanceIndex), metricUnits);
            long startTime = cursor.getLong(startTimeIndex);
            String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null
                    : StringUtils.formatRelativeDateTime(context, startTime);

            ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId,
                    R.string.icon_track, name, cursor.getString(categoryIndex), totalTime, totalDistance,
                    startTimeDisplay, cursor.getString(descriptionIndex));
        }
    };
    listView.setAdapter(resourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
            return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null, null,
                    TracksColumns._ID + " DESC");
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            resourceCursorAdapter.swapCursor(cursor);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            resourceCursorAdapter.swapCursor(null);
        }
    });
    trackDataHub = TrackDataHub.newInstance(this);
    if (savedInstanceState != null) {
        startGps = savedInstanceState.getBoolean(START_GPS_KEY);
    } // Test repeated messaging
    if (!started)
        showStartupDialogs();
}

From source file:com.hangulo.powercontact.MainActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    Log.v(LOG_TAG, "LOADER:MainActivity/onLoaderFinished : cursor num " + cursor.getCount());

    mPowerContactArrayList.clear(); // first clear!

    if (cursor.moveToFirst()) {
        do {/*w  ww . j  av a  2  s  .c o m*/
            long contact_id = cursor.getLong(INDEX_COL_CONTACT_ID);
            long data_id = cursor.getLong(INDEX_COL_DATA_ID);
            String lookup_key = cursor.getString(INDEX_COL_LOOKUP_KEY);
            String name = cursor.getString(INDEX_COL_NAME);
            String addr = cursor.getString(INDEX_COL_ADDR);
            int type = cursor.getInt(INDEX_COL_TYPE);
            String label = cursor.getString(INDEX_COL_LABEL);
            double lat = cursor.getDouble(INDEX_COL_LAT);
            double lng = cursor.getDouble(INDEX_COL_LNG);
            double dist = cursor.getDouble(INDEX_COL_DISTANCE); // distance
            String photo = cursor.getString(INDEX_COL_PHOTO); // photo
            mPowerContactArrayList.add(new PowerContactAddress(contact_id, data_id, lookup_key, name, addr,
                    type, label, photo, lat, lng, dist));

        } while (cursor.moveToNext());
    }

    Log.v(LOG_TAG, "LOADER:MainActivity/onLoaderFinished : powercontact size " + mPowerContactArrayList.size());

    //  ? ?? .
    //  .
    if (mMapFragment != null) {

        Log.v(LOG_TAG, "LOADER:MainActivity/mMapFragment/setClusterManager :distance "
                + mPowerContactSettings.getDistance());
        mPreviousSearchKeyword = mSearchKeyword;
        mMapFragment.setClusterManager(mPowerContactArrayList, mPowerContactSettings.getMarkerType()); // ?? .
    }
    if (mListFragment != null) {
        //   mListFragment.setContactsList(mPowerContactArrayList, mPowerContactSettings.getDistance()); // ? .
        Log.v(LOG_TAG, "LOADER:MainActivity/mListFragment/restartLoader() : ");
        mListFragment.restartLoader();
    }
}

From source file:ru.arturvasilov.udacity.sunshinewatches.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        ViewParent vp = getView().getParent();
        if (vp instanceof CardView) {
            ((View) vp).setVisibility(View.VISIBLE);
        }// www .  j a va 2  s .c o m

        // 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);
        }

        // Read date from cursor and update views for day of week and date
        long date = data.getLong(COL_WEATHER_DATE);
        String dateText = Utility.getFullFriendlyDayString(getActivity(), date);
        mDateView.setText(dateText);

        // Get description from weather condition ID
        String description = Utility.getStringForWeatherCondition(getActivity(), weatherId);
        mDescriptionView.setText(description);
        mDescriptionView.setContentDescription(getString(R.string.a11y_forecast, description));

        // For accessibility, add a content description to the icon field. Because the ImageView
        // is independently focusable, it's better to have a description of the image. Using
        // null is appropriate when the image is purely decorative or when the image already
        // has text describing it in the same UI component.
        mIconView.setContentDescription(getString(R.string.a11y_forecast_icon, description));

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high);
        mHighTempView.setText(highString);
        mHighTempView.setContentDescription(getString(R.string.a11y_high_temp, highString));

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

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

        // 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));
        mWindView.setContentDescription(getString(R.string.a11y_wind, mWindView.getText()));
        mWindLabelView.setContentDescription(mWindView.getContentDescription());

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

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

    }
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar);

    // We need to start the enter transition after the data has loaded
    if (mTransitionAnimation) {
        activity.supportStartPostponedEnterTransition();

        if (null != toolbarView) {
            activity.setSupportActionBar(toolbarView);
            if (activity.getSupportActionBar() != null) {
                activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
                activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            }
        }
    } else {
        if (null != toolbarView) {
            Menu menu = toolbarView.getMenu();
            if (null != menu)
                menu.clear();
            toolbarView.inflateMenu(R.menu.detailfragment);
            finishCreatingMenu(toolbarView.getMenu());
        }
    }
}

From source file:com.ichi2.libanki.Stats.java

public boolean calculateDone(int type, boolean reps) {
    mHasColoredCumulative = true;//  w  w  w  .  ja v a 2  s  .  c  om
    mDynamicAxis = true;
    mType = type;
    mBackwards = true;
    if (reps) {
        mTitle = R.string.stats_review_count;
        mAxisTitles = new int[] { type, R.string.stats_answers, R.string.stats_cumulative_answers };
    } else {
        mTitle = R.string.stats_review_time;
    }
    mValueLabels = new int[] { R.string.statistics_learn, R.string.statistics_relearn,
            R.string.statistics_young, R.string.statistics_mature, R.string.statistics_cram };
    mColors = new int[] { R.color.stats_learn, R.color.stats_relearn, R.color.stats_young, R.color.stats_mature,
            R.color.stats_cram };
    int num = 0;
    int chunk = 0;
    switch (type) {
    case TYPE_MONTH:
        num = 31;
        chunk = 1;
        break;
    case TYPE_YEAR:
        num = 52;
        chunk = 7;
        break;
    case TYPE_LIFE:
        num = -1;
        chunk = 30;
        break;
    }
    ArrayList<String> lims = new ArrayList<String>();
    if (num != -1) {
        lims.add("id > " + ((mCol.getSched().getDayCutoff() - ((num + 1) * chunk * 86400)) * 1000));
    }
    String lim = _revlogLimit().replaceAll("[\\[\\]]", "");
    if (lim.length() > 0) {
        lims.add(lim);
    }
    if (lims.size() > 0) {
        lim = "WHERE ";
        while (lims.size() > 1) {
            lim += lims.remove(0) + " AND ";
        }
        lim += lims.remove(0);
    } else {
        lim = "";
    }
    String ti;
    String tf;
    if (!reps) {
        ti = "time/1000";
        if (mType == TYPE_MONTH) {
            tf = "/60.0"; // minutes
            mAxisTitles = new int[] { type, R.string.stats_minutes, R.string.stats_cumulative_time_minutes };
        } else {
            tf = "/3600.0"; // hours
            mAxisTitles = new int[] { type, R.string.stats_hours, R.string.stats_cumulative_time_hours };
        }
    } else {
        ti = "1";
        tf = "";
    }
    ArrayList<double[]> list = new ArrayList<double[]>();
    Cursor cur = null;
    String query = "SELECT (cast((id/1000 - " + mCol.getSched().getDayCutoff() + ") / 86400.0 AS INT))/" + chunk
            + " AS day, " + "sum(CASE WHEN type = 0 THEN " + ti + " ELSE 0 END)" + tf + ", " // lrn
            + "sum(CASE WHEN type = 1 AND lastIvl < 21 THEN " + ti + " ELSE 0 END)" + tf + ", " // yng
            + "sum(CASE WHEN type = 1 AND lastIvl >= 21 THEN " + ti + " ELSE 0 END)" + tf + ", " // mtr
            + "sum(CASE WHEN type = 2 THEN " + ti + " ELSE 0 END)" + tf + ", " // lapse
            + "sum(CASE WHEN type = 3 THEN " + ti + " ELSE 0 END)" + tf // cram
            + " FROM revlog " + lim + " GROUP BY day ORDER BY day";

    Timber.d("ReviewCount query: %s", query);

    try {
        cur = mCol.getDb().getDatabase().rawQuery(query, null);
        while (cur.moveToNext()) {
            list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(4), cur.getDouble(2),
                    cur.getDouble(3), cur.getDouble(5) });
        }
    } finally {
        if (cur != null && !cur.isClosed()) {
            cur.close();
        }
    }

    // small adjustment for a proper chartbuilding with achartengine
    if (type != TYPE_LIFE && (list.size() == 0 || list.get(0)[0] > -num)) {
        list.add(0, new double[] { -num, 0, 0, 0, 0, 0 });
    } else if (type == TYPE_LIFE && list.size() == 0) {
        list.add(0, new double[] { -12, 0, 0, 0, 0, 0 });
    }
    if (list.get(list.size() - 1)[0] < 0) {
        list.add(new double[] { 0, 0, 0, 0, 0, 0 });
    }

    mSeriesList = new double[6][list.size()];
    for (int i = 0; i < list.size(); i++) {
        double[] data = list.get(i);
        mSeriesList[0][i] = data[0]; // day
        mSeriesList[1][i] = data[1] + data[2] + data[3] + data[4] + data[5]; // lrn
        mSeriesList[2][i] = data[2] + data[3] + data[4] + data[5]; // relearn
        mSeriesList[3][i] = data[3] + data[4] + data[5]; // young
        mSeriesList[4][i] = data[4] + data[5]; // mature
        mSeriesList[5][i] = data[5]; // cram
        if (mSeriesList[1][i] > mMaxCards)
            mMaxCards = (int) Math.round(data[1] + data[2] + data[3] + data[4] + data[5]);

        if (data[5] >= 0.999)
            mFoundCramCards = true;

        if (data[1] >= 0.999)
            mFoundLearnCards = true;

        if (data[2] >= 0.999)
            mFoundRelearnCards = true;
        if (data[0] > mLastElement)
            mLastElement = data[0];
        if (data[0] < mFirstElement)
            mFirstElement = data[0];
        if (data[0] == 0) {
            mZeroIndex = i;
        }
    }
    mMaxElements = list.size() - 1;

    mCumulative = new double[6][];
    mCumulative[0] = mSeriesList[0];
    for (int i = 1; i < mSeriesList.length; i++) {
        mCumulative[i] = createCumulative(mSeriesList[i]);
        if (i > 1) {
            for (int j = 0; j < mCumulative[i - 1].length; j++) {
                mCumulative[i - 1][j] -= mCumulative[i][j];
            }
        }
    }

    switch (mType) {
    case TYPE_MONTH:
        mFirstElement = -31;
        break;
    case TYPE_YEAR:
        mFirstElement = -52;
        break;
    default:
    }

    mMcount = 0;
    // we could assume the last element to be the largest,
    // but on some collections that may not be true due some negative values
    //so we search for the largest element:
    for (int i = 1; i < mCumulative.length; i++) {
        for (int j = 0; j < mCumulative[i].length; j++) {
            if (mMcount < mCumulative[i][j])
                mMcount = mCumulative[i][j];
        }
    }

    //some adjustments to not crash the chartbuilding with emtpy data

    if (mMaxCards == 0)
        mMaxCards = 10;

    if (mMaxElements == 0) {
        mMaxElements = 10;
    }
    if (mMcount == 0) {
        mMcount = 10;
    }
    if (mFirstElement == mLastElement) {
        mFirstElement = -10;
        mLastElement = 0;
    }
    return list.size() > 0;
}

From source file:org.dicadeveloper.runnerapp.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (BuildConfig.DEBUG) {
        ApiAdapterFactory.getApiAdapter().enableStrictMode();
    }/*from  ww w  .ja  v  a2  s .  c om*/

    myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);

    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
    trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener,
            stopListener);

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    // Show trackController when search dialog is dismissed
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
        @Override
        public void onDismiss() {
            trackController.show();
        }
    });

    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty_view));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            startActivity(newIntent);
        }
    });
    sectionResourceCursorAdapter = new SectionResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int sharedOwnerIndex = cursor.getColumnIndex(TracksColumns.SHAREDOWNER);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);

            long trackId = cursor.getLong(idIndex);
            boolean isRecording = trackId == recordingTrackId;
            String icon = cursor.getString(iconIndex);
            int iconId = TrackIconUtils.getIconDrawable(icon);
            String name = cursor.getString(nameIndex);
            String sharedOwner = cursor.getString(sharedOwnerIndex);
            String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = StringUtils.formatDistance(TrackListActivity.this,
                    cursor.getDouble(totalDistanceIndex), metricUnits);
            int markerCount = myTracksProviderUtils.getWaypointCount(trackId);
            long startTime = cursor.getLong(startTimeIndex);
            String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
            String description = cursor.getString(descriptionIndex);

            ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId,
                    R.string.image_track, name, sharedOwner, totalTime, totalDistance, markerCount, startTime,
                    true, category, description, null);
        }
    };
    listView.setAdapter(sectionResourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
    showStartupDialogs();
}

From source file:br.com.bioscada.apps.biotracks.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (BuildConfig.DEBUG) {
        ApiAdapterFactory.getApiAdapter().enableStrictMode();
    }/*from w  w w .ja v  a 2  s . c  o m*/

    myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);

    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
    trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener,
            stopListener);

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    // Show trackController when search dialog is dismissed
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
        @Override
        public void onDismiss() {
            trackController.show();
        }
    });

    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty_view));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            startActivity(newIntent);
        }
    });
    sectionResourceCursorAdapter = new SectionResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int sharedOwnerIndex = cursor.getColumnIndex(TracksColumns.SHAREDOWNER);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);

            long trackId = cursor.getLong(idIndex);
            boolean isRecording = trackId == recordingTrackId;
            String icon = cursor.getString(iconIndex);
            int iconId = TrackIconUtils.getIconDrawable(icon);
            String name = cursor.getString(nameIndex);
            String sharedOwner = cursor.getString(sharedOwnerIndex);
            String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = StringUtils.formatDistance(TrackListActivity.this,
                    cursor.getDouble(totalDistanceIndex), metricUnits);
            int markerCount = 0;
            try {
                markerCount = myTracksProviderUtils.getWaypointCount(trackId);
            } catch (Exception e) {
                Log.d("BIOTRACKS", e.getMessage());
            }

            long startTime = cursor.getLong(startTimeIndex);
            String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
            String description = cursor.getString(descriptionIndex);

            ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId,
                    R.string.image_track, name, sharedOwner, totalTime, totalDistance, markerCount, startTime,
                    true, category, description, null);
        }
    };
    listView.setAdapter(sectionResourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
    showStartupDialogs();
}

From source file:com.ichi2.anki.SyncClient.java

/**
 * Anki Desktop -> libanki/anki/sync.py, SyncTools - bundleModel
 * // w  w  w .j  av  a 2  s.com
 * @param id
 * @return
 */
private JSONObject bundleModel(Long id)// , boolean updateModified
{
    JSONObject model = new JSONObject();
    Cursor cursor = AnkiDatabaseManager.getDatabase(mDeck.getDeckPath()).getDatabase()
            .rawQuery("SELECT * FROM models WHERE id = " + id, null);
    if (cursor.moveToFirst()) {
        try {
            model.put("id", cursor.getLong(0));
            model.put("deckId", cursor.getInt(1));
            model.put("created", cursor.getDouble(2));
            model.put("modified", cursor.getDouble(3));
            model.put("tags", cursor.getString(4));
            model.put("name", cursor.getString(5));
            model.put("description", cursor.getString(6));
            model.put("features", cursor.getDouble(7));
            model.put("spacing", cursor.getDouble(8));
            model.put("initialSpacing", cursor.getDouble(9));
            model.put("source", cursor.getInt(10));
            model.put("fieldModels", bundleFieldModels(id));
            model.put("cardModels", bundleCardModels(id));
        } catch (JSONException e) {
            Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage());
        }
    }
    cursor.close();

    Log.i(AnkiDroidApp.TAG, "Model = ");
    Utils.printJSONObject(model, false);

    return model;
}