Example usage for android.os Bundle getDouble

List of usage examples for android.os Bundle getDouble

Introduction

In this page you can find the example usage for android.os Bundle getDouble.

Prototype

public double getDouble(String key) 

Source Link

Document

Returns the value associated with the given key, or 0.0 if no mapping of the desired type exists for the given key.

Usage

From source file:com.crcrch.chromatictuner.app.NotePickerFragment.java

@NonNull
@Override/*from ww w. j a  va2 s .co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());

    View dialogContent = LayoutInflater.from(dialogBuilder.getContext()).inflate(R.layout.fragment_note_picker,
            null);

    final NumberPicker notePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_note);
    notePicker.setMinValue(0);
    notePicker.setMaxValue(MiscMusic.CHROMATIC_SCALE.length - 1);
    notePicker.setDisplayedValues(MiscMusic.CHROMATIC_SCALE);
    notePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    final NumberPicker octavePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_octave);
    octavePicker.setMinValue(0);
    octavePicker.setMaxValue(MAX_OCTAVE);
    octavePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    octavePicker.setWrapSelectorWheel(false);

    final TextView frequencyView = (TextView) dialogContent.findViewById(R.id.frequency);
    notePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            frequencyView.setText(selectFrequency(newVal, octavePicker.getValue()));
        }
    });
    octavePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            frequencyView.setText(selectFrequency(notePicker.getValue(), newVal));
        }
    });

    double frequencyToDisplay;
    if (savedInstanceState == null) {
        frequencyToDisplay = initialFrequency;
    } else {
        frequencyToDisplay = savedInstanceState.getDouble(STATE_FREQUENCY);
    }
    frequencyView.setText(selectFrequency(frequencyToDisplay));
    int note = getNoteForFrequency(frequencyToDisplay);
    octavePicker.setValue(getOctaveForNote(note));
    octavePicker.invalidate();
    notePicker.setValue(getNoteIndexForNote(note));
    notePicker.invalidate();

    return dialogBuilder.setTitle(R.string.dialog_title_note_picker).setView(dialogContent)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    listener.onFrequencySelected(frequency);
                    dialog.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, null).create();
}

From source file:org.xbmc.kore.ui.TVShowOverviewFragment.java

@Override
@TargetApi(21)/*from  w w  w.  ja  va  2s.c  om*/
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    tvshowId = bundle.getInt(TVShowDetailsFragment.BUNDLE_KEY_TVSHOWID, -1);

    if (tvshowId == -1) {
        // There's nothing to show
        return null;
    }

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_tvshow_overview, container, false);
    ButterKnife.inject(this, root);

    //UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);

    // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
    Resources resources = getActivity().getResources();
    final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
    mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            float y = mediaPanel.getScrollY();
            float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
            mediaArt.setAlpha(newAlpha);
        }
    });

    tvshowTitle = bundle.getString(TVShowDetailsFragment.BUNDLE_KEY_TITLE);

    mediaTitle.setText(tvshowTitle);
    setMediaUndertitle(bundle.getInt(TVShowDetailsFragment.BUNDLE_KEY_EPISODE),
            bundle.getInt(TVShowDetailsFragment.BUNDLE_KEY_WATCHEDEPISODES));
    setMediaPremiered(bundle.getString(TVShowDetailsFragment.BUNDLE_KEY_PREMIERED),
            bundle.getString(TVShowDetailsFragment.BUNDLE_KEY_STUDIO));
    mediaGenres.setText(bundle.getString(TVShowDetailsFragment.BUNDLE_KEY_GENRES));
    setMediaRating(bundle.getDouble(TVShowDetailsFragment.BUNDLE_KEY_RATING));
    mediaDescription.setText(bundle.getString(TVShowDetailsFragment.BUNDLE_KEY_PLOT));

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(getArguments().getString(TVShowDetailsFragment.POSTER_TRANS_NAME));
    }
    // Pad main content view to overlap with bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
    //        mediaPanel.setClipToPadding(false);

    return root;
}

From source file:org.xbmc.kore.ui.sections.video.TVShowDetailsFragment.java

@Override
@TargetApi(21)//from   ww w. ja v  a2s. co  m
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    tvshowId = bundle.getInt(BUNDLE_KEY_TVSHOWID, -1);

    if (tvshowId == -1) {
        // There's nothing to show
        return null;
    }

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_tvshow_overview, container, false);
    ButterKnife.inject(this, root);

    //UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);

    // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
    Resources resources = getActivity().getResources();
    final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
    mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            float y = mediaPanel.getScrollY();
            float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
            mediaArt.setAlpha(newAlpha);
        }
    });

    tvshowTitle = bundle.getString(BUNDLE_KEY_TITLE);

    mediaTitle.setText(tvshowTitle);
    setMediaUndertitle(bundle.getInt(BUNDLE_KEY_EPISODE), bundle.getInt(BUNDLE_KEY_WATCHEDEPISODES));
    setMediaPremiered(bundle.getString(BUNDLE_KEY_PREMIERED), bundle.getString(BUNDLE_KEY_STUDIO));
    mediaGenres.setText(bundle.getString(BUNDLE_KEY_GENRES));
    setMediaRating(bundle.getDouble(BUNDLE_KEY_RATING));
    mediaDescription.setText(bundle.getString(BUNDLE_KEY_PLOT));

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(getArguments().getString(POSTER_TRANS_NAME));
    }
    // Pad main content view to overlap with bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
    //        mediaPanel.setClipToPadding(false);

    return root;
}

From source file:org.xbmc.kore.ui.MovieDetailsFragment.java

@TargetApi(21)
@Override//from  w w  w  . ja va 2  s  .c o m
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    movieId = bundle.getInt(BUNDLE_KEY_MOVIEID, -1);

    if (movieId == -1) {
        // There's nothing to show
        return null;
    }

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_movie_details, container, false);
    ButterKnife.inject(this, root);

    //UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);

    // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
    Resources resources = getActivity().getResources();
    final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
    mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            float y = mediaPanel.getScrollY();
            float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
            mediaArt.setAlpha(newAlpha);
        }
    });

    FloatingActionButton fab = (FloatingActionButton) fabButton;
    fab.attachToScrollView((ObservableScrollView) mediaPanel);

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(getArguments().getString(POSTER_TRANS_NAME));
    }

    mediaTitle.setText(bundle.getString(BUNDLE_KEY_MOVIETITLE));
    mediaUndertitle.setText(bundle.getString(BUNDLE_KEY_MOVIEPLOT));
    mediaGenres.setText(bundle.getString(BUNDLE_KEY_MOVIEGENRES));
    setMediaYear(bundle.getInt(BUNDLE_KEY_MOVIERUNTIME), bundle.getInt(BUNDLE_KEY_MOVIEYEAR));
    setMediaRating(bundle.getDouble(BUNDLE_KEY_MOVIERATING));

    // Pad main content view to overlap with bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
    //        mediaPanel.setClipToPadding(false);

    return root;
}

From source file:io.mapsquare.osmcontributor.ui.fragments.MapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_map, container, false);

    markersPoi = new HashMap<>();
    markersNotes = new HashMap<>();
    markersNodeRef = new HashMap<>();

    unbinder = ButterKnife.bind(this, rootView);
    setHasOptionsMenu(true);//  w ww  .ja  va2s.c  o m

    zoomVectorial = configManager.getZoomVectorial();

    if (savedInstanceState != null) {
        currentLevel = savedInstanceState.getDouble(LEVEL);
        selectedMarkerType = LocationMarkerView.MarkerType.values()[savedInstanceState.getInt(MARKER_TYPE)];
    }

    instantiateProgressBar();
    instantiateMapView(savedInstanceState);
    instantiateLevelBar();
    instantiatePoiTypePicker();
    instantiateCopyrightBar();

    eventBus.register(this);
    eventBus.register(presenter);
    return rootView;
}

From source file:qr.cloud.qrpedia.MessageViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_message_viewer);

    // set up tabs and collapse the action bar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);
    if (QRCloudUtils.actionBarIsSplit(MessageViewerActivity.this)) {
        actionBar.setDisplayShowHomeEnabled(false); // TODO: also need to show inverted/rearranged icons
    }/*from  ww  w . jav  a 2  s . c  om*/

    // load Google Play Services location client
    mWaitingForGooglePlayLocation = true;
    mGooglePlayLocationConnected = false;
    mLocationClient = new LocationClient(MessageViewerActivity.this, MessageViewerActivity.this,
            MessageViewerActivity.this);

    // refresh interval for location queries and load whether location has been updated, and product details
    mMinimumLocationRefreshWaitTime = getResources().getInteger(R.integer.minimum_location_refresh_time);
    if (savedInstanceState != null) {
        mLocationTabEnabled = savedInstanceState.getBoolean(getString(R.string.key_location_tab_visited));
        mProductDetails = savedInstanceState.getString(getString(R.string.key_product_details));
        double savedLat = savedInstanceState.getDouble(QRCloudUtils.DATABASE_PROP_LATITUDE);
        double savedLon = savedInstanceState.getDouble(QRCloudUtils.DATABASE_PROP_LONGITUDE);
        if (savedLat != 0.0d && savedLon != 0.0d) {
            mLocation = new Location(QRCloudUtils.DATABASE_PROP_GEOCELL); // just need any string to initialise
            mLocation.setLatitude(savedLat);
            mLocation.setLongitude(savedLon);
        }
        mManualLocationRequestTime = savedInstanceState.getLong(getString(R.string.key_location_request_time));
        long currentTime = System.currentTimeMillis();
        if (currentTime - mManualLocationRequestTime < LocationRetriever.LOCATION_WAIT_TIME) {
            // we've started but probably not finished getting the location (manual method) - try again
            requestManualLocationAndUpdateTab();
        }
    }

    // get the code hash and details (must be after getting mProductDetails to stop multiple queries)
    final Intent launchIntent = getIntent();
    // Bundle barcodeDetailsBundle = null;
    if (launchIntent != null) {
        final String codeContents = launchIntent.getStringExtra(QRCloudUtils.DATABASE_PROP_CONTENTS);
        if (codeContents != null) {
            // we need the hash for database lookups
            mCodeHash = QRCloudUtils.sha1Hash(codeContents);
            parseCodeDetailsAndUpdate(launchIntent, codeContents, savedInstanceState == null);
        }
    }
    if (mCodeHash == null) {
        finish();
    }

    // set up animation for the refresh button
    mRotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    mRotateAnimation.setDuration(600);
    mRotateAnimation.setRepeatCount(Animation.INFINITE);
    mRotateAnimation.setRepeatMode(Animation.RESTART);

    // set up tab paging
    mViewPager = (ViewPager) findViewById(R.id.message_sort_pager);
    mViewPager.setOffscreenPageLimit(3); // tried to save data, but 1 is the minimum - just pre-cache everything

    // load the tabs (see: http://stackoverflow.com/a/12090317/1993220)
    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(actionBar.newTab().setIcon(R.drawable.ic_action_clock_inverse),
            CloudEntityListFragment.class, getSortBundle(CloudEntity.PROP_CREATED_AT), false);
    mTabsAdapter.addTab(actionBar.newTab().setIcon(R.drawable.ic_action_location_inverse),
            CloudEntityListFragment.class, getSortBundle(QRCloudUtils.DATABASE_PROP_GEOCELL), true);
    mTabsAdapter.addTab(actionBar.newTab().setIcon(R.drawable.ic_action_star_10_inverse),
            CloudEntityListFragment.class, getSortBundle(QRCloudUtils.DATABASE_PROP_RATING), false);
    mTabsAdapter.addTab(actionBar.newTab().setIcon(R.drawable.ic_action_user_inverse),
            CloudEntityListFragment.class,
            getFilterBundle(F.Op.EQ.name(), CloudEntity.PROP_CREATED_BY, getCredentialAccountName()), false);
    // mTabsAdapter
    // .addTab(actionBar.newTab().setIcon(
    // mBarcodeFormat == BarcodeFormat.QR_CODE ? R.drawable.ic_action_qrcode_inverse
    // : R.drawable.ic_action_barcode_inverse), CodeViewerFragment.class, barcodeDetailsBundle);
}

From source file:gov.cdc.epiinfo.RecordList.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (intent != null) {
        if (intent.getAction() != null && intent.getAction().contains("zxing")) {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
            if (scanResult != null) {
                searchByQRCode(scanResult.getContents());
            }//from  w w  w  .j  a  v a 2  s .c o m
        } else {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                ContentValues initialValues = new ContentValues();
                for (int x = 0; x < formMetadata.DataFields.size(); x++) {
                    if (formMetadata.DataFields.get(x).getType().equals("11")
                            || formMetadata.DataFields.get(x).getType().equals("12")
                            || formMetadata.DataFields.get(x).getType().equals("18")
                            || formMetadata.DataFields.get(x).getType().equals("19")) {
                        initialValues.put(formMetadata.DataFields.get(x).getName(),
                                extras.getInt(formMetadata.DataFields.get(x).getName()));
                    } else if (formMetadata.DataFields.get(x).getType().equals("17")) {
                        if (formMetadata.DataFields.get(x).getListValues().size() > 100) {
                            initialValues.put(formMetadata.DataFields.get(x).getName(),
                                    extras.getString(formMetadata.DataFields.get(x).getName()));
                        } else {
                            initialValues.put(formMetadata.DataFields.get(x).getName(),
                                    extras.getInt(formMetadata.DataFields.get(x).getName()));
                        }
                    } else if (formMetadata.DataFields.get(x).getType().equals("5")) {
                        initialValues.put(formMetadata.DataFields.get(x).getName(),
                                extras.getDouble(formMetadata.DataFields.get(x).getName()));
                    } else if (formMetadata.DataFields.get(x).getType().equals("10")) {
                        if (extras.getInt(formMetadata.DataFields.get(x).getName()) == 1) {
                            initialValues.put(formMetadata.DataFields.get(x).getName(), true);
                        } else {
                            initialValues.put(formMetadata.DataFields.get(x).getName(), false);
                        }
                    } else {
                        initialValues.put(formMetadata.DataFields.get(x).getName(),
                                extras.getString(formMetadata.DataFields.get(x).getName()));
                    }
                }

                switch (requestCode) {
                case ACTIVITY_CREATE:
                    mDbHelper.createRecord(initialValues, true, newGuid, fkeyGuid);
                    fillData();
                    break;
                case ACTIVITY_EDIT:
                    Long mRowId = extras.getLong(EpiDbHelper.KEY_ROWID);
                    String mRowGuid = extras.getString(EpiDbHelper.GUID);
                    if (mRowId != null) {
                        mDbHelper.updateRecord(mRowId, initialValues, true);
                    }
                    fillData();
                    break;
                }
            }
        }
    }
}

From source file:io.jawg.osmcontributor.ui.fragments.MapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_map, container, false);

    markersPoi = new HashMap<>();
    markersNotes = new HashMap<>();
    markersNodeRef = new HashMap<>();
    markerIssues = new LinkedList<>();

    unbinder = ButterKnife.bind(this, rootView);
    setHasOptionsMenu(true);// w  ww  .  j  av a2s . co m

    zoomVectorial = configManager.getZoomVectorial();

    if (savedInstanceState != null) {
        currentLevel = savedInstanceState.getDouble(LEVEL);
        selectedMarkerType = LocationMarkerView.MarkerType.values()[savedInstanceState.getInt(MARKER_TYPE)];
    }

    instantiateProgressBar();
    instantiateMapView(savedInstanceState);
    instantiateLevelBar();
    instantiatePoiTypePicker();
    instantiateCopyrightBar();

    instantiateSelectedPois();

    eventBus.register(this);
    eventBus.register(presenter);
    return rootView;
}

From source file:com.facebook.LegacyTokenCacheTest.java

@Test
public void testAllTypes() {
    Bundle originalBundle = new Bundle();

    putBoolean(BOOLEAN_KEY, originalBundle);
    putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle);
    putByte(BYTE_KEY, originalBundle);//from  w w  w . java 2s .c o  m
    putByteArray(BYTE_ARRAY_KEY, originalBundle);
    putShort(SHORT_KEY, originalBundle);
    putShortArray(SHORT_ARRAY_KEY, originalBundle);
    putInt(INT_KEY, originalBundle);
    putIntArray(INT_ARRAY_KEY, originalBundle);
    putLong(LONG_KEY, originalBundle);
    putLongArray(LONG_ARRAY_KEY, originalBundle);
    putFloat(FLOAT_KEY, originalBundle);
    putFloatArray(FLOAT_ARRAY_KEY, originalBundle);
    putDouble(DOUBLE_KEY, originalBundle);
    putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle);
    putChar(CHAR_KEY, originalBundle);
    putCharArray(CHAR_ARRAY_KEY, originalBundle);
    putString(STRING_KEY, originalBundle);
    putStringList(STRING_LIST_KEY, originalBundle);
    originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    ensureApplicationContext();

    LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application);
    cache.save(originalBundle);

    LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application);
    Bundle cachedBundle = cache2.load();

    assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
    assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY),
            cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY));
    assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY));
    assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
    assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY));
    assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY),
            cachedBundle.getShortArray(SHORT_ARRAY_KEY));
    assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY));
    assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY));
    assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY));
    assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
    assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getFloatArray(FLOAT_ARRAY_KEY),
            cachedBundle.getFloatArray(FLOAT_ARRAY_KEY));
    assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY),
            cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY));
    assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY));
    assertArrayEquals(originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY));
    assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY));
    assertListEquals(originalBundle.getStringArrayList(STRING_LIST_KEY),
            cachedBundle.getStringArrayList(STRING_LIST_KEY));
    assertEquals(originalBundle.getSerializable(SERIALIZABLE_KEY),
            cachedBundle.getSerializable(SERIALIZABLE_KEY));
}

From source file:org.opendatakit.sensors.manager.WorkerThread.java

private void parseSensorDataAndInsertIntoTable(ODKSensor aSensor, String strTableDef, Bundle dataBundle) {
    JSONObject jsonTableDef = null;/*from w w  w . j a v  a2 s .c o  m*/
    ContentValues tablesValues = new ContentValues();

    SQLiteDatabase db = null;
    try {
        db = DatabaseFactory.get().getDatabase(serviceContext, aSensor.getAppNameForDatabase());

        jsonTableDef = new JSONObject(strTableDef);

        String tableId = jsonTableDef.getJSONObject(ODKJsonNames.jsonTableStr)
                .getString(ODKJsonNames.jsonTableIdStr);

        if (tableId == null) {
            return;
        }

        boolean success;

        success = false;
        try {
            success = ODKDatabaseUtils.get().hasTableId(db, tableId);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SQLException("Exception testing for tableId " + tableId);
        }
        if (!success) {
            sensorManager.parseDriverTableDefintionAndCreateTable(aSensor.getSensorID(),
                    aSensor.getAppNameForDatabase(), db);
        }

        success = false;
        try {
            success = ODKDatabaseUtils.get().hasTableId(db, tableId);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SQLException("Exception testing for tableId " + tableId);
        }
        if (!success) {
            throw new SQLException("Unable to create tableId " + tableId);
        }

        ArrayList<ColumnDefinition> orderedDefs = TableUtil.get().getColumnDefinitions(db,
                aSensor.getAppNameForDatabase(), tableId);

        // Create the columns for the driver table
        for (ColumnDefinition col : orderedDefs) {
            if (!col.isUnitOfRetention()) {
                continue;
            }

            String colName = col.getElementKey();
            ElementType type = col.getType();

            if (colName.equals(DataSeries.SENSOR_ID)) {

                // special treatment
                tablesValues.put(colName, aSensor.getSensorID());

            } else if (type.getDataType() == ElementDataType.bool) {

                Boolean boolColData = dataBundle.containsKey(colName) ? dataBundle.getBoolean(colName) : null;
                Integer colData = (boolColData == null) ? null : (boolColData ? 1 : 0);
                tablesValues.put(colName, colData);

            } else if (type.getDataType() == ElementDataType.integer) {

                Integer colData = dataBundle.containsKey(colName) ? dataBundle.getInt(colName) : null;
                tablesValues.put(colName, colData);

            } else if (type.getDataType() == ElementDataType.number) {

                Double colData = dataBundle.containsKey(colName) ? dataBundle.getDouble(colName) : null;
                tablesValues.put(colName, colData);

            } else {
                // everything else is a string value coming across the wire...
                String colData = dataBundle.containsKey(colName) ? dataBundle.getString(colName) : null;
                tablesValues.put(colName, colData);
            }
        }

        if (tablesValues.size() > 0) {
            Log.i(TAG, "Writing db values for sensor:" + aSensor.getSensorID());
            String rowId = tablesValues.containsKey(DataTableColumns.ID)
                    ? tablesValues.getAsString(DataTableColumns.ID)
                    : null;
            if (rowId == null) {
                rowId = ODKDataUtils.genUUID();
            }
            ODKDatabaseUtils.get().insertDataIntoExistingDBTableWithId(db, tableId, orderedDefs, tablesValues,
                    rowId);
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (db != null) {
            db.close();
        }
    }
}