Example usage for android.util SparseArray get

List of usage examples for android.util SparseArray get

Introduction

In this page you can find the example usage for android.util SparseArray get.

Prototype

public E get(int key) 

Source Link

Document

Gets the Object mapped from the specified key, or null if no such mapping has been made.

Usage

From source file:com.aware.plugin.polarhrm.Plugin.java

@Override
public void onCreate() {
    super.onCreate();
    TAG = "PolarHRM";

    CONTEXT_PRODUCER = new Aware_Plugin.ContextProducer() {
        @Override/*from w w  w. ja  v  a 2 s  . c  o m*/
        public void onContext() {
            Intent heartRate = new Intent(ACTION_AWARE_POLAR_HEARTRATE);
            sendBroadcast(heartRate);
        }
    };

    DATABASE_TABLES = PolarHRM_Provider.DATABASE_TABLES;
    TABLES_FIELDS = PolarHRM_Provider.TABLES_FIELDS;
    CONTEXT_URIS = new Uri[] { PolarHRM_Data.CONTENT_URI, PolarHRM_Profile.CONTENT_URI };

    notManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this);

    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(btStateListener, filter);

    prefs = getSharedPreferences(getPackageName(), MODE_MULTI_PROCESS);

    if (btAdapter != null && !btAdapter.isEnabled()) {
        Intent makeEnabled = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        makeEnabled.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivity(makeEnabled);
    }

    updater = new Timer();
    updater.scheduleAtFixedRate(updateHR, 0, 2000);

    if (!prefs.contains("age")) {
        Intent hrm_params = new Intent(getApplicationContext(), Settings.class);
        hrm_params.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(hrm_params);
    } else {
        algorithm = new Algorithm(prefs.getInt("age", 25), prefs.getInt("rhr", 70));
        SparseArray<double[]> hr_zones = algorithm.getZones();

        ContentValues rowData = new ContentValues();
        rowData.put(PolarHRM_Profile.TIMESTAMP, System.currentTimeMillis());
        rowData.put(PolarHRM_Profile.DEVICE_ID,
                Aware.getSetting(getContentResolver(), Aware_Preferences.DEVICE_ID));
        rowData.put(PolarHRM_Profile.AGE, prefs.getInt("age", 25));
        rowData.put(PolarHRM_Profile.RESTING_HR, prefs.getInt("rhr", 70));
        rowData.put(PolarHRM_Profile.RECOVERY_MIN, hr_zones.get(0)[0]);
        rowData.put(PolarHRM_Profile.RECOVERY_MAX, hr_zones.get(0)[1]);
        rowData.put(PolarHRM_Profile.AEROBIC_MIN, hr_zones.get(1)[0]);
        rowData.put(PolarHRM_Profile.AEROBIC_MAX, hr_zones.get(1)[1]);
        rowData.put(PolarHRM_Profile.ANAEROBIC_MIN, hr_zones.get(2)[0]);
        rowData.put(PolarHRM_Profile.ANAEROBIC_MAX, hr_zones.get(2)[1]);
        rowData.put(PolarHRM_Profile.RED_LINE_MIN, hr_zones.get(3)[0]);
        rowData.put(PolarHRM_Profile.RED_LINE_MAX, hr_zones.get(3)[1]);

        getContentResolver().insert(PolarHRM_Profile.CONTENT_URI, rowData);
    }

    showUI();
}

From source file:com.tmall.wireless.tangram3.dataparser.concrete.PojoGroupBasicAdapter.java

@Override
protected void diffGroup(SparseArray<Card> added, SparseArray<Card> removed) {
    for (int i = 0, size = removed.size(); i < size; i++) {
        int key = removed.keyAt(i);
        Card card = removed.get(key);
        if (card != null) {
            try {
                card.removed();/* ww  w.ja va  2s .com*/
            } catch (Exception e) {
                if (card.serviceManager != null) {
                    CellSupport cellSupport = card.serviceManager.getService(CellSupport.class);
                    if (card.extras != null) {
                        cellSupport.onException(card.extras.toString(), e);
                    } else {
                        cellSupport.onException(card.stringType, e);
                    }
                }
            }
        }
    }

    for (int i = 0, size = added.size(); i < size; i++) {
        int key = added.keyAt(i);
        Card card = added.get(key);
        if (card != null) {
            try {
                card.added();
            } catch (Exception e) {
                if (card.serviceManager != null) {
                    CellSupport cellSupport = card.serviceManager.getService(CellSupport.class);
                    if (card.extras != null) {
                        cellSupport.onException(card.extras.toString(), e);
                    } else {
                        cellSupport.onException(card.stringType, e);
                    }
                }
            }
        }
    }
}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java

/**
 * Groups the original values into a sparse array.
 * The outer sparse array is indexed by the group field.
 * The inner sparse array is indexed by the index field.
 * If groupField and indexField are the same, then the outer sparse array contains only 1 entry
 * index by 0 and the inner sparse array is indexed by indexField.
 * @param original the original value returned from the SQL query.
 * @param groupField the field used to group the outer sparse array.
 * @param indexField the field used to group the inner sparse array.
 * @return a bidimensional sparse array indexed by  groupField and indexField.
 *///from  w  ww.  ja v a 2s. co  m
private SparseArray<SparseArray<Double>> groupValues(final SparseArray<Pair<Date, Double>> original,
        final int groupField, final int indexField) {
    final Calendar calendar = Calendar.getInstance();
    final SparseArray<SparseArray<Double>> weeks = new SparseArray<>();

    for (int i = 0; i < original.size(); i++) {
        try {
            final int key = original.keyAt(i);

            calendar.setTime(original.get(key).first);
            final double value = original.get(key).second;

            final int indexValue = calendar.get(indexField);
            final int groupValue = groupField == indexField ? 0 : calendar.get(groupField);

            SparseArray<Double> currentWeek = weeks.get(groupValue);
            if (currentWeek == null) {
                currentWeek = new SparseArray<>();
                weeks.put(groupValue, currentWeek);
            }
            currentWeek.put(indexValue, value);
        } catch (Exception e) {
            Log.e(e.getMessage());
        }
    }

    // normalize the data
    // if the index field is DAY_OF_WEEK, then we'll add the remaining days to fill
    // the week from sunday until saturday
    if (indexField == Calendar.DAY_OF_WEEK) {
        for (int i = 0; i < weeks.size(); i++) {
            final int key = weeks.keyAt(i);
            SparseArray<Double> currentWeek = weeks.get(key);
            for (int j = Calendar.SUNDAY; j <= Calendar.SATURDAY; j++) {
                if (currentWeek.get(j) == null) {
                    currentWeek.put(j, 0.0);
                }
            }
        }
    }

    return weeks;
}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java

/**
 * Creates a line data set to plot the chart.
 * @param setPosition this dataset position.
 * @param label The label of the data set.
 * @param array The sparse array containing the data to plot.
 * @param startValue the value at which the x axis starts.
 * @return a dataset ready to plot.//from   w  w w  .j  a  va 2 s.  c om
 */
private LineDataSet getData(final int setPosition, final String label, final SparseArray<Double> array,
        final int startValue) {
    final List<Entry> values = new ArrayList<>();

    final int startIndex = startValue == 0 ? 0 : array.indexOfKey(startValue);

    for (int i = startIndex; i < array.size(); i++) {
        int key = array.keyAt(i);
        int xValue = startValue == 0 ? key : values.size() + startValue;
        values.add(new Entry(xValue, array.get(key).floatValue()));
    }
    for (int i = 0; i < startIndex; i++) {
        try {
            int key = array.keyAt(i);
            int xValue = startValue == 0 ? key : values.size() + startValue;
            values.add(new Entry(xValue, array.get(key).floatValue()));
        } catch (Exception e) {
            Log.e("Entry at index " + i + " does not exist");
        }
    }

    LineDataSet d = new LineDataSet(values, label);
    d.setLineWidth(2.5f);
    d.setCircleRadius(4f);
    d.setDrawValues(false);

    int color = CHART_COLORS[setPosition];
    d.setColor(color);
    d.setCircleColor(color);
    d.setDrawFilled(true);
    return d;
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

/**
 * ??//from  ww  w  .  j a v a 2 s .co m
 *
 * @param list             ?
 * @param appName          ??
 * @param becauseInstalled ??
 */
private void removePackFromListByAppName(SparseArray<Pack> list, String appName, boolean becauseInstalled) {
    for (int i = 0; i < list.size(); i++) {
        int key = list.keyAt(i);
        Pack pack = list.get(key);
        if (pack.getAppName().equals(appName)) {
            sInstallList.remove(key);
            if (becauseInstalled) {
                showInstalledNotification(pack);
            }
            break;
        }
    }
    if (sInstallList.size() == 0 && sUninstallList.size() == 0) {
        enable = false;
    }
}

From source file:com.smedic.tubtub.BackgroundAudioService.java

/**
 * Get the best available audio stream given connection type.
 * If the user is on wifi, then provide the best quality audio from video sources, if available.
 * Otherwise, use DASH audio streams to save on mobile data.
 *
 * @TODO make source configurable by the user.
 *
 * @param ytFiles Array of available streams
 * @return Audio stream with highest bitrate
 *///  ww  w  . j a va2  s .co  m
@Nullable
private YtFile findBestStream(SparseArray<YtFile> ytFiles) {
    final long start = System.nanoTime();

    final int[] mobileAllowed = { 251, 140, 171, 18, 250, 249, 36, 17 };
    final int[] wifiAllowed = { 22, 251, 140, 171, 43, 18, 250, 249, 36, 17 };

    final int[] allowedItags = network.networkType() == ConnectivityManager.TYPE_WIFI ? wifiAllowed
            : mobileAllowed;

    for (int itag : allowedItags) {
        final YtFile ytFile = ytFiles.get(itag);
        if (ytFile != null) {
            final long end = System.nanoTime();
            final long cost = end - start;
            Log.i(TAG, "Found best stream with itag " + ytFile.getFormat().getItag() + " in " + cost / 1000000.0
                    + "ms.");

            return ytFile;
        }
    }

    Log.e(TAG, "Unable to find audio stream from available candidates.");
    return null;
}

From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java

void onWeatherDataReady(WeatherData weatherData, SparseArray<WeatherUtils.ForecastInfo> forecastForDays) {

    if (weatherData == null) {
        Toast.makeText(this, "No weather info available", Toast.LENGTH_LONG).show();
        finish();//from  w  w w .j  a  v  a 2s  .c om
        return;
    }

    mWeatherData = weatherData;
    showDefaultImage(weatherData.nowConditionCode);

    int today = TimeUtils.getJulianDay();
    WeatherUtils.ForecastInfo todaysForecast = forecastForDays == null ? null : forecastForDays.get(today);

    mAdapter.setForecast(forecastForDays);

    mIsDay = mWeatherUtils.isDay(mTimezone, weatherData);

    int icon = mWeatherUtils.getConditionCodeIconResId(weatherData.nowConditionCode, mIsDay);
    mCurrentWeatherIcon.setImageResource(icon);

    mLocationView.setText(weatherData.location);
    String feelsLikeTemp = mWeatherUtils.formatTemperature(this, weatherData.windChill, weatherData.unit,
            mDisplayUnit, WeatherUtils.FLAG_TEMPERATURE_NO_UNIT);

    if (todaysForecast != null) {
        setTemperatureText(mMinTempView, todaysForecast.tempLow, todaysForecast.unit, mDisplayUnit);
        setTemperatureText(mMaxTempView, todaysForecast.tempHigh, todaysForecast.unit, mDisplayUnit);
    } else {
        mMinTempView.setText("-");
        mMaxTempView.setText("-");
    }

    String wind = mWeatherUtils.formatWindSpeed(this, weatherData.windSpeed, weatherData.unit, mDisplayUnit);

    mWindDrawable.mAngle = weatherData.windDirection;

    setTemperatureText(mTemperatureView, weatherData.nowTemperature, weatherData.unit, mDisplayUnit);
    setTemperatureText(mTemperatureView, weatherData.nowTemperature, weatherData.unit, mDisplayUnit);
    setTemperatureText(mTemperatureView, weatherData.nowTemperature, weatherData.unit, mDisplayUnit);

    String feelsLike = getString(R.string.feels_like, feelsLikeTemp);
    mFeelsLikeView.setText(feelsLike);

    mWindView.setText(wind);

    mConditionView.setText(mWeatherUtils.formatConditionCode(weatherData.nowConditionCode));
}

From source file:com.android.talkback.CollectionState.java

@Nullable
private static TableItemState getTableItemStateKitKat(AccessibilityNodeInfoCompat collectionRoot,
        AccessibilityNodeInfoCompat announcedNode, SparseArray<CharSequence> rowHeaders,
        SparseArray<CharSequence> columnHeaders, boolean computeHeaders, boolean computeNumbering) {
    if (collectionRoot == null || collectionRoot.getCollectionInfo() == null) {
        return null;
    }//w ww . j a v a  2s . co  m

    // Checking the ancestors should incur zero performance penalty in the typical case
    // where list items are direct descendants. Assuming list items are not deeply
    // nested, any performance penalty would be minimal.
    AccessibilityNodeInfoCompat collectionItem = AccessibilityNodeInfoUtils
            .getSelfOrMatchingAncestor(announcedNode, collectionRoot, FILTER_COLLECTION_ITEM);

    if (collectionItem == null) {
        return null;
    }

    CollectionInfoCompat collection = collectionRoot.getCollectionInfo();
    CollectionItemInfoCompat item = collectionItem.getCollectionItemInfo();

    int heading = computeHeaders ? getTableHeading(item, collection) : TYPE_NONE;
    int rowIndex = getRowIndex(item, collection);
    int columnIndex = getColumnIndex(item, collection);
    CharSequence rowName = rowIndex != -1 ? rowHeaders.get(rowIndex) : null;
    CharSequence columnName = columnIndex != -1 ? columnHeaders.get(columnIndex) : null;

    collectionItem.recycle();
    return new TableItemState(heading, rowName, columnName, rowIndex, columnIndex, computeNumbering);
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

/**
 * ?AccessibilityNodeInfo//from   w  ww  .j a  v a 2 s  .co m
 *
 * @param event
 * @param validPackageList 
 * @return
 */
private AccessibilityNodeInfo getValidAccessibilityNodeInfo(AccessibilityEvent event,
        SparseArray<Pack> validPackageList) {
    if (validPackageList != null && validPackageList.size() > 0) {
        for (int i = 0; i < validPackageList.size(); i++) {
            int key = validPackageList.keyAt(i);
            Pack pack = validPackageList.get(key);
            AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event, pack.getAppName());
            if (nodeInfo != null) {
                return nodeInfo;
            }
        }
    }
    return null;
}

From source file:com.tmall.wireless.tangram3.dataparser.concrete.Card.java

private void diffCells(@NonNull SparseArray<BaseCell> added, @NonNull SparseArray<BaseCell> removed) {
    if (!mIsActivated)
        return;//from w  w  w. ja  v  a2 s  .  c  om

    for (int i = 0, size = added.size(); i < size; i++) {
        int key = added.keyAt(i);
        BaseCell cell = added.get(key);
        if (cell != null) {
            cell.added();
        }
    }

    for (int i = 0, size = removed.size(); i < size; i++) {
        int key = removed.keyAt(i);
        BaseCell cell = removed.get(key);
        if (cell != null) {
            cell.removed();
        }
    }
}