Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

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

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Get double property for activity./*from w  ww  . j  ava 2  s . c om*/
 *
 * @param name
 * @param defaultValue
 * @return
 */
public double getDoubleProperty(String name, double defaultValue) {
    Bundle bundle = this.getIntent().getExtras();
    if (bundle == null) {
        return defaultValue;
    }
    Double p;
    try {
        p = (Double) bundle.get(name);
    } catch (ClassCastException e) {
        p = Double.parseDouble(bundle.get(name).toString());
    }
    if (p == null) {
        return defaultValue;
    }
    return p.doubleValue();
}

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Get int property for activity./*from  w  w  w.j a v a2 s.c  o m*/
 *
 * @param name
 * @param defaultValue
 * @return
 */
public int getIntegerProperty(String name, int defaultValue) {
    Bundle bundle = this.getIntent().getExtras();
    if (bundle == null) {
        return defaultValue;
    }
    Integer p;
    try {
        p = (Integer) bundle.get(name);
    } catch (ClassCastException e) {
        p = Integer.parseInt(bundle.get(name).toString());
    }
    if (p == null) {
        return defaultValue;
    }
    return p.intValue();
}

From source file:edu.mit.mobile.android.locast.data.Sync.java

/**
 * Sync the given URI to the server. Will compare dates and do a two-way sync.
 * Does not yet handle the case where both server and and local are modified
 * (collisions)//w ww.ja  v a2  s  .  co  m
 *
 * @param toSync URI of the object to sync. Generally, this should be the dir URI
 * @param sync A new object that extends JsonSyncableItem. This is needed for the JSON
 * serialization routine in it, as well as the sync map.
 * @throws IOException
 */
private void sync(Uri toSync, JsonSyncableItem sync, SyncProgressNotifier syncProgress, Bundle extras)
        throws SyncException, IOException {
    String netPath;
    boolean haveItemPubUri = false;

    if ("http".equals(toSync.getScheme()) || "https".equals(toSync.getScheme())) {
        netPath = toSync.getPath();
        toSync = (Uri) extras.get(EXTRA_DESTINATION_URI);
        haveItemPubUri = true;
    } else {
        netPath = null;
    }
    final String contentType = getContentResolver().getType(toSync);

    final Cursor c = cr.query(toSync, sync.getFullProjection(), null, null, null);
    try {
        syncProgress.addPendingTasks(c.getCount());

        // Handle a list of items.
        if (contentType.startsWith(CONTENT_TYPE_PREFIX_DIR)) {
            // load from the network first...
            if (netPath == null) {
                netPath = MediaProvider.getPublicPath(this, toSync);
            }
            syncNetworkList(toSync, netPath, sync, syncProgress);
        } else if (haveItemPubUri) {
            syncNetworkItem(toSync, netPath, sync, syncProgress);
        }

        // then load locally.

        if (DEBUG) {
            Log.d(TAG, "have " + c.getCount() + " local items to sync");
        }
        for (c.moveToFirst(); (currentSyncTask != null && !currentSyncTask.isCancelled()) && !c.isAfterLast(); c
                .moveToNext()) {
            try {
                syncItem(toSync, c, null, sync, syncProgress, netPath);
                syncProgress.completeTask();

            } catch (final SyncItemDeletedException side) {
                if (DEBUG) {
                    Log.d(TAG, side.getLocalizedMessage() + " Deleting...");
                }
                cr.delete(side.getItem(), null, null);
                //side.printStackTrace();
                syncProgress.completeTask();
                continue;
            }
        }
    } catch (final NoPublicPath npp) {
        // XXX this should be a hard error
        Log.e(TAG, "Sync Error: " + npp.getLocalizedMessage());
        return;
    } finally {
        c.close();
    }
}

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Get boolean property for activity.//from   w  w  w .j  a v  a2 s  . c  o  m
 *
 * @param name
 * @param defaultValue
 * @return
 */
public boolean getBooleanProperty(String name, boolean defaultValue) {
    Bundle bundle = this.getIntent().getExtras();
    if (bundle == null) {
        return defaultValue;
    }
    Boolean p;
    try {
        p = (Boolean) bundle.get(name);
    } catch (ClassCastException e) {
        String s = bundle.get(name).toString();
        if ("true".equals(s)) {
            p = true;
        } else {
            p = false;
        }
    }
    if (p == null) {
        return defaultValue;
    }
    return p.booleanValue();
}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Bundle arguments = getArguments();
    sourcePosition = (Integer) arguments.get("position");
    int colorFilterInt = AppSettings.getColorFilterInt(appContext);

    View view = inflater.inflate(R.layout.source_info_fragment, container, false);
    headerView = inflater.inflate(R.layout.source_info_header, null, false);

    settingsContainer = (RelativeLayout) headerView.findViewById(R.id.source_settings_container);

    sourceImage = (ImageView) headerView.findViewById(R.id.source_image);
    sourceTitle = (EditText) headerView.findViewById(R.id.source_title);
    sourcePrefix = (EditText) headerView.findViewById(R.id.source_data_prefix);
    sourceData = (EditText) headerView.findViewById(R.id.source_data);
    sourceSuffix = (EditText) headerView.findViewById(R.id.source_data_suffix);
    sourceNum = (EditText) headerView.findViewById(R.id.source_num);

    ViewGroup.LayoutParams params = sourceImage.getLayoutParams();
    params.height = (int) ((container.getWidth()
            - 2f * getResources().getDimensionPixelSize(R.dimen.side_margin)) / 16f * 9);
    sourceImage.setLayoutParams(params);

    cancelButton = (Button) view.findViewById(R.id.cancel_button);
    saveButton = (Button) view.findViewById(R.id.save_button);

    sourcePrefix.setTextColor(colorFilterInt);
    sourceSuffix.setTextColor(colorFilterInt);
    cancelButton.setTextColor(colorFilterInt);
    saveButton.setTextColor(colorFilterInt);

    // Adjust alpha to get faded hint color from regular text color
    int hintColor = Color.argb(0x88, Color.red(colorFilterInt), Color.green(colorFilterInt),
            Color.blue(colorFilterInt));

    sourceTitle.setHintTextColor(hintColor);
    sourceData.setHintTextColor(hintColor);
    sourceNum.setHintTextColor(hintColor);

    sourceData.setOnClickListener(new View.OnClickListener() {
        @Override/*from w w  w  . j av  a  2  s  .c  om*/
        public void onClick(View v) {
            switch (type) {

            case AppSettings.FOLDER:
                selectSource(getPositionOfType(AppSettings.FOLDER));
                break;
            case AppSettings.GOOGLE_ALBUM:
                selectSource(getPositionOfType(AppSettings.GOOGLE_ALBUM));
                break;

            }
            Log.i(TAG, "Data launched folder fragment");
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    saveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveSource();
        }
    });

    sourceSpinnerText = (TextView) headerView.findViewById(R.id.source_spinner_text);
    sourceSpinner = (Spinner) headerView.findViewById(R.id.source_spinner);

    timePref = (CustomSwitchPreference) findPreference("source_time");
    timePref.setChecked(arguments.getBoolean("use_time"));
    timePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {

            if (!(Boolean) newValue) {
                return true;
            }

            DialogFactory.TimeDialogListener startTimeListener = new DialogFactory.TimeDialogListener() {

                @Override
                public void onTimeSet(TimePicker view, int hour, int minute) {
                    startHour = hour;
                    startMinute = minute;

                    DialogFactory.TimeDialogListener endTimeListener = new DialogFactory.TimeDialogListener() {
                        @Override
                        public void onTimeSet(TimePicker view, int hour, int minute) {
                            endHour = hour;
                            endMinute = minute;

                            timePref.setSummary(String.format("Time active: %02d:%02d - %02d:%02d", startHour,
                                    startMinute, endHour, endMinute));

                        }
                    };

                    DialogFactory.showTimeDialog(appContext, "End time?", endTimeListener, startHour,
                            startMinute);

                }
            };

            DialogFactory.showTimeDialog(appContext, "Start time?", startTimeListener, startHour, startMinute);

            return true;
        }
    });

    if (savedInstanceState != null) {

        if (sourcePosition == -1) {
            sourceSpinner
                    .setSelection(getPositionOfType(savedInstanceState.getString("type", AppSettings.WEBSITE)));
        }

    }

    if (sourcePosition == -1) {
        sourceImage.setVisibility(View.GONE);
        sourceSpinnerText.setVisibility(View.VISIBLE);
        sourceSpinner.setVisibility(View.VISIBLE);

        SourceSpinnerAdapter adapter = new SourceSpinnerAdapter(appContext, R.layout.spinner_row,
                Arrays.asList(getResources().getStringArray(R.array.source_menu)));
        sourceSpinner.setAdapter(adapter);
        sourceSpinner.setSelection(0);
        sourceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                selectSource(position);
                Log.i(TAG, "Spinner launched folder fragment");
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        type = AppSettings.WEBSITE;
        hint = "URL";
        prefix = "";
        suffix = "";

        startHour = 0;
        startMinute = 0;
        endHour = 0;
        endMinute = 0;
    } else {
        sourceImage.setVisibility(View.VISIBLE);
        sourceSpinnerText.setVisibility(View.GONE);
        sourceSpinner.setVisibility(View.GONE);

        type = arguments.getString("type");

        folderData = arguments.getString("data");
        String data = folderData;

        hint = AppSettings.getSourceDataHint(type);
        prefix = AppSettings.getSourceDataPrefix(type);
        suffix = "";

        switch (type) {
        case AppSettings.GOOGLE_ALBUM:
            sourceTitle.setFocusable(false);
            sourceData.setFocusable(false);
            sourceNum.setFocusable(false);
        case AppSettings.FOLDER:
            data = Arrays.toString(folderData.split(AppSettings.DATA_SPLITTER));
            break;
        case AppSettings.TUMBLR_BLOG:
            suffix = ".tumblr.com";
            break;

        }

        sourceTitle.setText(arguments.getString("title"));
        sourceNum.setText("" + arguments.getInt("num"));
        sourceData.setText(data);

        if (imageDrawable != null) {
            sourceImage.setImageDrawable(imageDrawable);
        }

        boolean showPreview = arguments.getBoolean("preview");
        if (showPreview) {
            sourceImage.setVisibility(View.VISIBLE);
        }

        ((CustomSwitchPreference) findPreference("source_show_preview")).setChecked(showPreview);

        String[] timeArray = arguments.getString("time").split(":|[ -]+");

        try {
            startHour = Integer.parseInt(timeArray[0]);
            startMinute = Integer.parseInt(timeArray[1]);
            endHour = Integer.parseInt(timeArray[2]);
            endMinute = Integer.parseInt(timeArray[3]);
            timePref.setSummary(String.format("Time active: %02d:%02d - %02d:%02d", startHour, startMinute,
                    endHour, endMinute));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            startHour = 0;
            startMinute = 0;
            endHour = 0;
            endMinute = 0;
        }

    }

    setDataWrappers();

    sourceUse = (Switch) headerView.findViewById(R.id.source_use_switch);
    sourceUse.setChecked(arguments.getBoolean("use"));

    if (AppSettings.getTheme().equals(AppSettings.APP_LIGHT_THEME)) {
        view.setBackgroundColor(getResources().getColor(R.color.LIGHT_THEME_BACKGROUND));
    } else {
        view.setBackgroundColor(getResources().getColor(R.color.DARK_THEME_BACKGROUND));
    }

    ListView listView = (ListView) view.findViewById(android.R.id.list);
    listView.addHeaderView(headerView);

    if (savedInstanceState != null) {
        sourceTitle.setText(savedInstanceState.getString("title", ""));
        sourceData.setText(savedInstanceState.getString("data", ""));
        sourceNum.setText(savedInstanceState.getString("num", ""));
    }

    return view;
}

From source file:com.tealeaf.TeaLeaf.java

private String findAppID() {
    String appid = getIntent().getStringExtra("appid");
    if (appid != null) {
        return appid;
    }/*w  w w. ja v a  2 s  .  c o  m*/
    // FIXME HACK: find a better way to determine the appID
    try {
        Bundle metaData = getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA).metaData;
        return metaData.containsKey("appID") ? metaData.get("appID").toString() : "tealeaf";
    } catch (NameNotFoundException e) {
        logger.log(e);
        return "tealeaf";
    }
}

From source file:org.apache.cordova.AndroidWebView.java

/**
 * Get string property for activity.//  www  . ja  v  a 2 s .com
 *
 * @param name
 * @param defaultValue
 * @return the String value for the named property
 */
public String getProperty(String name, String defaultValue) {
    Bundle bundle = this.cordova.getActivity().getIntent().getExtras();
    if (bundle == null) {
        return defaultValue;
    }
    name = name.toLowerCase(Locale.getDefault());
    Object p = bundle.get(name);
    if (p == null) {
        return defaultValue;
    }
    return p.toString();
}

From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

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

    // Load intent
    Parcelable[] uncastedIntentFilters = null;
    if (savedInstanceState != null) {
        // Saved instance state
        mEditedIntent = savedInstanceState.getParcelable("intent");
        mComponentType = savedInstanceState.getInt("componentType");
        mMethodId = savedInstanceState.getInt("methodId");
        uncastedIntentFilters = savedInstanceState.getParcelableArray("intentFilters");
        Object uncastedLocalState = savedInstanceState.get("localIEState");
        if (uncastedLocalState instanceof LocalIntentEditorState) {
            mLocalState = (LocalIntentEditorState) uncastedLocalState;
        }/*ww w.  jav a 2  s .c om*/
    } else if (isInterceptedIntent()) {
        // Intercept
        mEditedIntent = new Intent(getIntent());
        mEditedIntent.setComponent(null);
        mComponentType = IntentEditorConstants.ACTIVITY;
        mMethodId = getCallingPackage() != null ? IntentEditorConstants.ACTIVITY_METHOD_STARTACTIVITYFORRESULT
                : IntentEditorConstants.ACTIVITY_METHOD_STARTACTIVITY;
    } else if (getIntent().hasExtra(Editor.EXTRA_VALUE)) {
        mEditedIntent = getIntent().getParcelableExtra(Editor.EXTRA_VALUE);
        mGenericEditorMode = true;
    } else {
        // Start of editor
        mEditedIntent = getIntent().getParcelableExtra(EXTRA_INTENT);
        mComponentType = getIntent().getIntExtra(EXTRA_COMPONENT_TYPE, IntentEditorConstants.ACTIVITY);
        mMethodId = getIntent().getIntExtra(EXTRA_METHOD_ID, 0);
        uncastedIntentFilters = getIntent().getParcelableArrayExtra(EXTRA_INTENT_FILTERS);
        if (mEditedIntent == null) {
            mEditedIntent = new Intent();
        }

        // Restore instance state
        if (getIntent().getExtras() != null) {
            Object localState = getIntent().getExtras().get(EXTRA_LOCAL_STATE);
            if (localState instanceof LocalIntentEditorState) {
                mLocalState = (LocalIntentEditorState) localState;
            }
        }
    }

    // Manually cast array of intent filters
    if (uncastedIntentFilters != null) {
        try {
            mAttachedIntentFilters = new IntentFilter[uncastedIntentFilters.length];
            for (int i = 0; i < uncastedIntentFilters.length; i++) {
                mAttachedIntentFilters[i] = (IntentFilter) uncastedIntentFilters[i];
            }
        } catch (ClassCastException e) {
            Log.w(TAG, "Invalid intent filters");
            mAttachedIntentFilters = null;
        }
    }

    // Setup tabs
    if (getResources().getBoolean(R.bool.use_master_detail)) {
        //if (getResources().getConfiguration().orientation == 2) {
        mergeFollowingTabs(getString(R.string.general), R.layout.intent_editor_general_with_extras,
                R.id.general, R.id.extras);
    }
    addTab(getString(R.string.general), new IntentGeneralFragment());
    addTab(getString(R.string.intent_extras), new IntentExtrasFragment());
    addTab(getString(R.string.flags), new IntentFlagsFragment());
    allTabsAdded();

}

From source file:com.intel.xdk.facebook.IntelXDKFacebook.java

private JSONObject BundleToJSON(Bundle bundleObj) {
    JSONObject jsonObj = new JSONObject();

    Object[] keys = bundleObj.keySet().toArray();

    for (int i = 0; i < keys.length; i++) {
        String key = (String) keys[i];
        try {/*from  w w w .j av  a  2s  .c  o m*/
            jsonObj.put(key, bundleObj.get(key));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return jsonObj;
}

From source file:com.neusou.artsy.Flickr.java

public String createRequestSignature(String secret, Bundle data) throws NoSuchAlgorithmException {
    Set<String> keys = data.keySet();
    String[] keysArray = new String[keys.size()];
    keys.toArray(keysArray);//  ww  w. j  ava  2 s .c o m
    Arrays.sort(keysArray);

    StringBuffer sb = new StringBuffer();
    sb.append(secret);
    for (String key : keysArray) {
        sb.append(key);
        sb.append(data.get(key));
    }

    MessageDigest md = MessageDigest.getInstance(SIGNATURE_DIGEST_ALGORITHM);
    md.update(sb.toString().getBytes());
    byte[] digested = md.digest();
    BigInteger bi = new BigInteger(1, digested);
    String signature = bi.toString(16);
    return signature;
}