Example usage for android.os Bundle getLong

List of usage examples for android.os Bundle getLong

Introduction

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

Prototype

public long getLong(String key) 

Source Link

Document

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

Usage

From source file:de.teunito.android.cyclelife.RennradNewsShare.java

/** Called when the activity is first created. */
@Override/*from   w  w  w  .j av a2s .c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share_rennradnews);

    Bundle data = new Bundle();
    data = getIntent().getExtras();
    trackId = data.getLong("trackId");

    mTrackDb = TrackDb.getInstance(getApplicationContext());

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    APIKey = prefs.getString(Preferences.RENNRADNEWS_API_KEY, "");
    bikeId = prefs.getString(Preferences.RENNRADNEWS_BIKE_ID, "");
    weight = prefs.getString(Preferences.WEIGHT, "");

    tv = (TextView) findViewById(R.id.rnsShareTitle);
    tv.setText("Share your track " + trackId + " to rennrad-news.de community!");
    bt = (Button) findViewById(R.id.rnsShareBtn);
    etTemp = (EditText) findViewById(R.id.rnsShareTemp);
    spSports = (Spinner) findViewById(R.id.rnsShareSports);
    spZone = (Spinner) findViewById(R.id.rnsShareZone);
    spWeather = (Spinner) findViewById(R.id.rnsShareWeather);
    spMood = (Spinner) findViewById(R.id.rnsShareMood);

    sportsAdapter = ArrayAdapter.createFromResource(this, R.array.sports, android.R.layout.simple_spinner_item);
    zoneAdapter = ArrayAdapter.createFromResource(this, R.array.zone, android.R.layout.simple_spinner_item);
    weatherAdapter = ArrayAdapter.createFromResource(this, R.array.weather,
            android.R.layout.simple_spinner_item);
    moodAdapter = ArrayAdapter.createFromResource(this, R.array.mood, android.R.layout.simple_spinner_item);

    sportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    zoneAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    weatherAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    moodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spSports.setAdapter(sportsAdapter);
    spZone.setAdapter(zoneAdapter);
    spWeather.setAdapter(weatherAdapter);
    spMood.setAdapter(moodAdapter);

    bt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog = ProgressDialog.show(RennradNewsShare.this, "", "Uploading. Please wait...", true);

            sportsID = String.valueOf(spSports.getSelectedItemPosition() + 1);
            zoneId = String.valueOf(spZone.getSelectedItemPosition() + 1);
            weatherId = String.valueOf(spWeather.getSelectedItemPosition() + 1);
            moodId = String.valueOf(spMood.getSelectedItemPosition() + 1);
            temperature = etTemp.getText().toString();

            // execute is a blocking call, it's best to call this code in a thread separate from the ui's
            uploadThread.start();
        }
    });

    handler = new Handler() {
        public void handleMessage(Message msg) {
            String result = msg.getData().getString("result");
            if (result.contains("success")) {
                Toast.makeText(getApplicationContext(), "Uploaded: " + result, Toast.LENGTH_LONG).show();
                finish();
            } else
                Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_LONG).show();
        }
    };

    if (APIKey.length() < 20) {
        AlertDialog.Builder builder = new AlertDialog.Builder(RennradNewsShare.this);
        builder.setMessage("Please enter first the rennrad-news.de API-key in the Settings!")
                .setCancelable(false).setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        RennradNewsShare.this.finish();
                        startActivity(new Intent(RennradNewsShare.this, Preferences.class));
                    }
                });
        builder.create().show();
    }
}

From source file:com.facebook.internal.BundleJSONConverterTest.java

@Test
public void testSimpleValues() throws JSONException {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1st");
    arrayList.add("2nd");
    arrayList.add("third");

    Bundle innerBundle1 = new Bundle();
    innerBundle1.putInt("inner", 1);

    Bundle innerBundle2 = new Bundle();
    innerBundle2.putString("inner", "2");
    innerBundle2.putStringArray("deep list", new String[] { "7", "8" });

    innerBundle1.putBundle("nested bundle", innerBundle2);

    Bundle b = new Bundle();
    b.putBoolean("boolValue", true);
    b.putInt("intValue", 7);
    b.putLong("longValue", 5000000000l);
    b.putDouble("doubleValue", 3.14);
    b.putString("stringValue", "hello world");
    b.putStringArray("stringArrayValue", new String[] { "first", "second" });
    b.putStringArrayList("stringArrayListValue", arrayList);
    b.putBundle("nested", innerBundle1);

    JSONObject json = BundleJSONConverter.convertToJSON(b);
    assertNotNull(json);/* w w  w . j av  a  2  s  . co  m*/

    assertEquals(true, json.getBoolean("boolValue"));
    assertEquals(7, json.getInt("intValue"));
    assertEquals(5000000000l, json.getLong("longValue"));
    assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", json.getString("stringValue"));

    JSONArray jsonArray = json.getJSONArray("stringArrayValue");
    assertEquals(2, jsonArray.length());
    assertEquals("first", jsonArray.getString(0));
    assertEquals("second", jsonArray.getString(1));

    jsonArray = json.getJSONArray("stringArrayListValue");
    assertEquals(3, jsonArray.length());
    assertEquals("1st", jsonArray.getString(0));
    assertEquals("2nd", jsonArray.getString(1));
    assertEquals("third", jsonArray.getString(2));

    JSONObject innerJson = json.getJSONObject("nested");
    assertEquals(1, innerJson.getInt("inner"));
    innerJson = innerJson.getJSONObject("nested bundle");
    assertEquals("2", innerJson.getString("inner"));

    jsonArray = innerJson.getJSONArray("deep list");
    assertEquals(2, jsonArray.length());
    assertEquals("7", jsonArray.getString(0));
    assertEquals("8", jsonArray.getString(1));

    Bundle finalBundle = BundleJSONConverter.convertToBundle(json);
    assertNotNull(finalBundle);

    assertEquals(true, finalBundle.getBoolean("boolValue"));
    assertEquals(7, finalBundle.getInt("intValue"));
    assertEquals(5000000000l, finalBundle.getLong("longValue"));
    assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", finalBundle.getString("stringValue"));

    List<String> stringList = finalBundle.getStringArrayList("stringArrayValue");
    assertEquals(2, stringList.size());
    assertEquals("first", stringList.get(0));
    assertEquals("second", stringList.get(1));

    stringList = finalBundle.getStringArrayList("stringArrayListValue");
    assertEquals(3, stringList.size());
    assertEquals("1st", stringList.get(0));
    assertEquals("2nd", stringList.get(1));
    assertEquals("third", stringList.get(2));

    Bundle finalInnerBundle = finalBundle.getBundle("nested");
    assertEquals(1, finalInnerBundle.getInt("inner"));
    finalBundle = finalInnerBundle.getBundle("nested bundle");
    assertEquals("2", finalBundle.getString("inner"));

    stringList = finalBundle.getStringArrayList("deep list");
    assertEquals(2, stringList.size());
    assertEquals("7", stringList.get(0));
    assertEquals("8", stringList.get(1));
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

private void handleConfiguration(Bundle bundle) {
    setForceStopTimeout(bundle.getLong(PreventIntent.KEY_FORCE_STOP_TIMEOUT));
    SystemHook.setDestroyProcesses(bundle.getBoolean(PreventIntent.KEY_DESTROY_PROCESSES));
    SystemHook.setLockSyncSettings(bundle.getBoolean(PreventIntent.KEY_LOCK_SYNC_SETTINGS));
    SystemHook.setUseAppStandby(bundle.getBoolean(PreventIntent.KEY_USE_APP_STANDBY));
    setAutoPrevent(bundle.getBoolean(PreventIntent.KEY_AUTO_PREVENT, true));
    if (bundle.containsKey(PreventIntent.KEY_STOP_SIGNATURE_APPS)) {
        // this is not an option can set from ui
        SystemHook.setStopSignatureApps(bundle.getBoolean(PreventIntent.KEY_STOP_SIGNATURE_APPS, true));
    }/*from  ww  w. j  a v  a 2  s. com*/
    if (bundle.containsKey(PreventIntent.KEY_PREVENT_LIST)) {
        updatePreventList(bundle.getStringArrayList(PreventIntent.KEY_PREVENT_LIST));
    }
    saveConfiguration(new Configuration(bundle), true);
}

From source file:com.rappsantiago.weighttracker.profile.setup.ProfileSetupSummaryFragment.java

public void refreshProfileData(Bundle profileData) {
    if (profileData.containsKey(NameBirthdayGenderFragment.KEY_NAME)) {
        mName.setText(profileData.getString(NameBirthdayGenderFragment.KEY_NAME));
    }/*from  ww  w  .  j  a v  a2  s.c  o  m*/

    if (profileData.containsKey(NameBirthdayGenderFragment.KEY_BIRTHDAY)) {
        long birthdayInMillis = profileData.getLong(NameBirthdayGenderFragment.KEY_BIRTHDAY);
        mBirthday.setText(DisplayUtil.getReadableDate(birthdayInMillis));
    }

    if (profileData.containsKey(NameBirthdayGenderFragment.KEY_GENDER)) {
        String gender = profileData.getString(NameBirthdayGenderFragment.KEY_GENDER);
        mGender.setText(DisplayUtil.getReadableGender(getContext(), gender));
    }

    if (profileData.containsKey(WeightHeightFragment.KEY_WEIGHT)
            && profileData.containsKey(WeightHeightFragment.KEY_WEIGHT_UNIT)) {

        String weightUnit = profileData.getString(WeightHeightFragment.KEY_WEIGHT_UNIT);
        double weight = profileData.getDouble(WeightHeightFragment.KEY_WEIGHT);
        mWeight.setText(DisplayUtil.getFormattedWeight(getContext(), weight, weightUnit));
    }

    if (profileData.containsKey(WeightHeightFragment.KEY_BODY_FAT_INDEX)) {
        double bodyFatIndex = profileData.getDouble(WeightHeightFragment.KEY_BODY_FAT_INDEX);
        mBodyFatIndex.setText(bodyFatIndex + "%");
    }

    if (profileData.containsKey(WeightHeightFragment.KEY_HEIGHT)
            && profileData.containsKey(WeightHeightFragment.KEY_HEIGHT_UNIT)) {

        double height = profileData.getDouble(WeightHeightFragment.KEY_HEIGHT);
        String heightUnit = profileData.getString(WeightHeightFragment.KEY_HEIGHT_UNIT);
        double heightInches = 0.0;

        if (profileData.containsKey(WeightHeightFragment.KEY_HEIGHT_INCHES)) {
            heightInches = profileData.getDouble(WeightHeightFragment.KEY_HEIGHT_INCHES);
        }

        mHeight.setText(DisplayUtil.getFormattedHeight(getContext(), height, heightInches, heightUnit));
    }

    if (profileData.containsKey(SetGoalsFragment.KEY_TARGET_WEIGHT)) {
        String weightUnit = profileData.getString(WeightHeightFragment.KEY_WEIGHT_UNIT);
        double targetWeight = profileData.getDouble(SetGoalsFragment.KEY_TARGET_WEIGHT);
        mTargetWeight.setText(DisplayUtil.getFormattedWeight(getContext(), targetWeight, weightUnit));
    }

    if (profileData.containsKey(SetGoalsFragment.KEY_TARGET_BODY_FAT_INDEX)) {
        double targetBodyFatIndex = profileData.getDouble(SetGoalsFragment.KEY_TARGET_BODY_FAT_INDEX);
        mTargetBodyFatIndex.setText(targetBodyFatIndex + "%");
    }

    if (profileData.containsKey(SetGoalsFragment.KEY_DUE_DATE)) {
        long dueDateInMillis = profileData.getLong(SetGoalsFragment.KEY_DUE_DATE);

        if (0 < dueDateInMillis) {
            mDueDate.setText(DisplayUtil.getReadableDate(dueDateInMillis));
        } else {
            mDueDate.setText(R.string.not_applicable);
        }
    }
}

From source file:com.LiteralWord.Bible.Notes.NoteEditFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);
    mDbHelper = new MyDbAdapter(myView.getContext());
    mDbHelper.open();/*from   w  w w.j  ava  2  s.c o m*/

    if (savedInstanceState != null) {

        if (savedInstanceState.containsKey(ID_TAG))
            mRowId = savedInstanceState.getLong(ID_TAG);
        mTitleText.setText(savedInstanceState.getString(TITLE_TAG));
        mBodyText.setText(savedInstanceState.getString(BODY_TAG));
        Log.d(LiteralWord.TAG, TAG + " Saved Activity Created, ID = " + mRowId);
        return;
    }

    if (mRowId == null) {
        Bundle extras = getActivity().getIntent().getExtras();
        mRowId = extras != null ? extras.getLong(MyDbAdapter.KEY_ROWID) : null;

    }
    Log.d(LiteralWord.TAG, TAG + " Activity Created, ID = " + mRowId);
    populateFields();
}

From source file:com.example.linhdq.test.documents.creation.crop.CropImageActivity.java

private void startCropping() {
    mImageView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override//from   w w w.  jav a  2 s.  co  m
        public void onGlobalLayout() {
            Bundle extras = getIntent().getExtras();
            final long nativePix = extras.getLong(DocumentGridActivity.EXTRA_NATIVE_PIX);
            final float margin = getResources().getDimension(R.dimen.crop_margin);
            final int width = (int) (mViewSwitcher.getWidth() - 2 * margin);
            final int height = (int) (mViewSwitcher.getHeight() - 2 * margin);
            mPix = new Pix(nativePix);
            mRotation = 0;
            mPrepareTask = Optional.of(new PreparePixForCropTask(mPix, width, height));
            mPrepareTask.get().execute();
            mImageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }

    });
}

From source file:com.google.android.demos.jamendo.widget.Loadable.java

/**
 * Appends query parameters to a {@link CursorLoader} {@link Uri}.
 * //w w w.  ja v  a 2 s  .co  m
 * @param loader the {@link CursorLoader} to modify.
 * @param args the arguments.
 * @return the modified {@link CursorLoader}.
 */
private CursorLoader appendQueryParameters(CursorLoader loader, Bundle args) {
    Uri.Builder builder = loader.getUri().buildUpon();
    if (args.containsKey(ARG_NUMBER)) {
        int n = args.getInt(ARG_NUMBER);
        builder.appendQueryParameter(JamendoContract.PARAM_NUMBER, Integer.toString(n));
    }
    if (args.containsKey(ARG_MAX_AGE)) {
        long maxAge = args.getLong(ARG_MAX_AGE);
        builder.appendQueryParameter(JamendoContract.PARAM_MAX_AGE, Long.toString(maxAge));
    }
    loader.setUri(builder.build());
    return loader;
}

From source file:com.wuman.androidimageloader.samples.ui.Loadable.java

/**
 * Appends query parameters to a {@link CursorLoader} {@link Uri}.
 * /*ww w .j  a  v a  2s .  c  o m*/
 * @param loader
 *            the {@link CursorLoader} to modify.
 * @param args
 *            the arguments.
 * @return the modified {@link CursorLoader}.
 */
private CursorLoader appendQueryParameters(CursorLoader loader, Bundle args) {
    Uri.Builder builder = loader.getUri().buildUpon();
    if (args.containsKey(ARG_NUMBER)) {
        int n = args.getInt(ARG_NUMBER);
        builder.appendQueryParameter(SamplesContract.PARAM_NUMBER, Integer.toString(n));
    }
    if (args.containsKey(ARG_MAX_AGE)) {
        long maxAge = args.getLong(ARG_MAX_AGE);
        builder.appendQueryParameter(SamplesContract.PARAM_MAX_AGE, Long.toString(maxAge));
    }
    loader.setUri(builder.build());
    return loader;
}

From source file:com.ultramegasoft.flavordex2.fragment.EditInfoFragment.java

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//from  ww  w. jav a2  s .  co m

    final Bundle args = getArguments();
    if (args != null) {
        mCatId = args.getLong(AddEntryFragment.ARG_CAT_ID);
        mEntryId = args.getLong(ARG_ENTRY_ID);
    }
}

From source file:com.gh4a.activities.ReleaseInfoActivity.java

@Override
protected void onInitExtras(Bundle extras) {
    super.onInitExtras(extras);
    mRepoOwner = extras.getString(Constants.Repository.OWNER);
    mRepoName = extras.getString(Constants.Repository.NAME);
    mRelease = (Release) extras.getSerializable(Constants.Release.RELEASE);
    mReleaseId = extras.getLong(Constants.Release.ID);
}