Example usage for android.os Bundle getBundle

List of usage examples for android.os Bundle getBundle

Introduction

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

Prototype

@Nullable
public Bundle getBundle(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:org.cobaltians.cobalt.fragments.CobaltFragment.java

protected void setBars(final JSONObject actionBar) {
    if (mContext != null) {
        Intent intent = ((CobaltActivity) mContext).getIntent();
        Bundle bundle = intent.getExtras();
        if (bundle == null) {
            bundle = new Bundle();
        }//from w ww  .ja v a 2 s.  co  m
        Bundle extras = bundle.getBundle(Cobalt.kExtras);
        if (extras == null) {
            extras = new Bundle();
            bundle.putBundle(Cobalt.kExtras, extras);
        }

        extras.putString(Cobalt.kBars, actionBar.toString());
        intent.putExtras(bundle);

        ((CobaltActivity) mContext).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ((CobaltActivity) mContext).setupBars(actionBar);
                ((CobaltActivity) mContext).supportInvalidateOptionsMenu();
            }
        });
    }
}

From source file:org.medcare.Dicom.DicomActivity.java

public void connectionSettings(Bundle locBundle) {
    Log.i("XMPPClient", "connectionSettings");
    Bundle accountBundle = locBundle.getBundle("settingsResults");
    String host = accountBundle.getString("host");
    String port = accountBundle.getString("port");
    String service = accountBundle.getString("service");
    String username = accountBundle.getString("username");
    String password = accountBundle.getString("password");
    this.xmppRemoteUser = accountBundle.getString("remoteuser");
    this.xmppUsername = username;

    // Create a connection
    ConnectionConfiguration connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service);
    StringBuffer buffer = new StringBuffer("system");
    buffer.append(File.separator).append("etc");
    buffer.append(File.separator).append("security");
    buffer.append(File.separator).append("cacerts.bks");
    connConfig.setTruststorePath(buffer.toString());
    connConfig.setTruststoreType("bks");
    connConfig.setTruststorePassword("changeit");
    Log.i("XMPPClient", "[SettingsDialog] ConnectionConfiguration created for " + host + " port " + port);
    XMPPConnection connection = new XMPPConnection(connConfig);
    Log.i("XMPPClient", "[SettingsDialog] Connection created for " + connection.getHost());
    try {//  ww w . j a v a2s  .c  om
        connection.connect();
        Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
    } catch (XMPPException ex) {
        Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
        Log.e("XMPPClient", ex.toString());
        alertMessage("Failed to connect to " + host);
        setConnection(null);
        return;
    }
    try {
        Log.i("XMPPClient", "[SettingsDialog] trying login as " + username + " password " + password);
        connection.login(username, password);
        Log.i("XMPPClient", "Logged in as " + connection.getUser());

        // Set the status to available
        Presence presence = new Presence(Presence.Type.available);
        connection.sendPacket(presence);
        setConnection(connection);
    } catch (XMPPException ex) {
        Log.e("XMPPClient", ex.toString());
        Log.e(TAG, "[SettingsDialog] Failed to log in as " + username);
        alertMessage("Failed to connect to " + username + " with pass " + password);
        setConnection(null);
        if (ex.getXMPPError() != null) {
            int err = ex.getXMPPError().getCode();
            // Responding to the various errors appropriately and allowing
            // signing in on the fly
            switch (err) {
            case 401:
            case 407:
                Log.e(TAG, "Failed to Login you must Create Account" + ex.getXMPPError().getMessage());
            default:
                Log.e(TAG, "Failed to Login" + ex.getXMPPError().getMessage());
            }
        }
        return;
    }
}

From source file:de.mrapp.android.dialog.example.PreferenceFragment.java

@Override
public final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initializeDialogs();// w  ww .  j  a  v a2  s .  c o m
    addPreferencesFromResource(R.xml.preferences);
    initializeThemePreference();
    initializeFullscreenPreference();
    initializeShowAlertDialogPreference();
    initializeShowListDialogPreference();
    initializeShowSingleChoiceListDialogPreference();
    initializeShowMultipleChoiceListDialogPreference();
    initializeShowCustomDialogPreference();
    initializeShowProgressDialogPreference();
    initializeShowWizardDialogPreference();

    if (savedInstanceState != null) {
        Bundle alertDialogState = savedInstanceState.getBundle(ALERT_DIALOG_STATE_EXTRA);
        Bundle listDialogState = savedInstanceState.getBundle(LIST_DIALOG_STATE_EXTRA);
        Bundle singleChoiceListDialogState = savedInstanceState
                .getBundle(SINGLE_CHOICE_LIST_DIALOG_STATE_EXTRA);
        Bundle multipleChoiceListDialogState = savedInstanceState
                .getBundle(MULTIPLE_CHOICE_LIST_DIALOG_STATE_EXTRA);
        Bundle customDialogState = savedInstanceState.getBundle(CUSTOM_DIALOG_STATE_EXTRA);
        Bundle progressDialogState = savedInstanceState.getBundle(PROGRESS_DIALOG_STATE_EXTRA);

        if (alertDialogState != null) {
            alertDialog.onRestoreInstanceState(alertDialogState);
        }

        if (listDialogState != null) {
            listDialog.onRestoreInstanceState(listDialogState);
        }

        if (singleChoiceListDialogState != null) {
            singleChoiceListDialog.onRestoreInstanceState(singleChoiceListDialogState);
        }

        if (multipleChoiceListDialogState != null) {
            multipleChoiceListDialog.onRestoreInstanceState(multipleChoiceListDialogState);
        }

        if (customDialogState != null) {
            customDialog.onRestoreInstanceState(customDialogState);
        }

        if (progressDialogState != null) {
            progressDialog.onRestoreInstanceState(progressDialogState);
        }
    }
}

From source file:org.mariotaku.twidere.activity.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    final Intent intent = getIntent();
    final String type = getTabType();
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();//from  w ww.j av  a  2s.  c om
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mEditTabName.setFloatingLabelText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean hasSecondaryField = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean accountIdNone = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(accountIdNone ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(ParcelableAccount.dummyCredentials());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        mAccountsAdapter.addAll(DataStoreUtils.getCredentialsList(this, false, officialKeyOnly));
        mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            TabExtras extras = CustomTabUtils.parseTabExtras(type, intent.getStringExtra(EXTRA_EXTRAS));
            if (extras != null) {
                extras.copyToBundle(mExtrasBundle);
            }
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:com.ovrhere.android.careerstack.ui.MainActivity.java

@SuppressWarnings("unchecked")
@Override/*from w ww .  java2  s.c om*/
protected void onCreate(Bundle savedInstanceState) {
    setThemeByIntent();
    super.onCreate(savedInstanceState);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    if (PreferenceUtils.isFirstRun(this)) {
        PreferenceUtils.setToDefault(this);
    }
    prefs = PreferenceUtils.getPreferences(this);
    //checks and, if necessary, restarts activity for theme
    checkThemePref();

    setContentView(R.layout.activity_main);

    tabletMessage = (TextView) findViewById(R.id.careerstack_main_text_job_description_message);

    if (savedInstanceState == null) {
        loadFragment(new MainFragment(), TAG_MAIN_FRAG, false);
        actionBarTitle = getString(R.string.app_name);

    } else {
        try {
            currSearchBarState = savedInstanceState.getBundle(KEY_CURRENT_SEARCH_BAR_STATE);

            if (savedInstanceState.getStringArrayList(KEY_FRAG_TAG_TACK) != null) {
                fragTagStack.addAll(savedInstanceState.getStringArrayList(KEY_FRAG_TAG_TACK));
            }

            if (savedInstanceState.getString(KEY_ACTIONBAR_TITLE) != null) {
                actionBarTitle = savedInstanceState.getString(KEY_ACTIONBAR_TITLE);
            }
            reattachLastFragment();

            if (savedInstanceState.getSerializable(KEY_FRAG_SAVED_STATES) != null) {
                try {
                    fragSavedStates.putAll((Map<? extends String, ? extends Bundle>) savedInstanceState
                            .getSerializable(KEY_FRAG_SAVED_STATES));
                } catch (ClassCastException e) {
                }
            }

        } catch (Exception e) {
            if (DEBUG) {
                Log.e(CLASS_NAME, "Should not be having an error here: " + e);
                e.printStackTrace();
            }
        }
    }

    getSupportActionBar().setTitle(actionBarTitle);

}

From source file:de.vanita5.twittnuker.activity.support.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mImageLoader = TwittnukerApplication.getInstance(this).getImageLoaderWrapper();
    final Intent intent = getIntent();
    final String type = mTabType = intent.getStringExtra(EXTRA_TYPE);
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();//from   w  w  w  .  j a v  a  2  s.  c  o m
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mTabTypeName.setText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean has_secondary_field = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean account_id_none = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(account_id_none ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(has_secondary_field ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(Account.dummyInstance());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        mAccountsAdapter.addAll(Account.getAccountsList(this, false, officialKeyOnly));
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS)));
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:org.getlantern.firetweet.activity.support.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mImageLoader = FiretweetApplication.getInstance(this).getMediaLoaderWrapper();
    final Intent intent = getIntent();
    final String type = mTabType = intent.getStringExtra(EXTRA_TYPE);
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();//  ww w .  j  a  va2 s .  c  o m
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mTabTypeName.setText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean hasSecondaryField = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean accountIdNone = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(accountIdNone ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(ParcelableAccount.dummyInstance());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        final boolean forcePrivateAPIs = intent.getBooleanExtra(KEY_FORCE_USING_PRIVATE_APIS, false);
        mAccountsAdapter
                .addAll(ParcelableAccount.getAccountsList(this, false, !forcePrivateAPIs && officialKeyOnly));
        mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS)));
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:org.hfoss.posit.android.api.fragment.FindFragment.java

/**
 * This may be invoked by a FindActivity subclass, which may or may not have
 * latitude and longitude fields.// w ww  .  j  ava2s. c o m
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    // Sets listeners for various UI elements
    initializeListeners();

    mAddFindMenuPlugins = FindPluginManager.getFunctionPlugins(FindPluginManager.ADD_FIND_MENU_EXTENSION);

    setHasOptionsMenu(true);

    // Initialize all UI elements for later uses
    mNameET = (EditText) getView().findViewById(R.id.nameEditText);
    mDescriptionET = (EditText) getView().findViewById(R.id.descriptionEditText);
    mGuidTV = (TextView) getView().findViewById(R.id.guidValueTextView);
    mGuidRealTV = (TextView) getView().findViewById(R.id.guidRealValueTextView);
    mTimeTV = (TextView) getView().findViewById(R.id.timeValueTextView);
    mLatTV = (TextView) getView().findViewById(R.id.latitudeTextView);
    mLatitudeTV = (TextView) getView().findViewById(R.id.latitudeValueTextView);
    mLongTV = (TextView) getView().findViewById(R.id.longitudeTextView);
    mLongitudeTV = (TextView) getView().findViewById(R.id.longitudeValueTextView);
    mAdhocTV = (TextView) getView().findViewById(R.id.isAdhocTextView);

    // Check if settings allow Geotagging
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mGeoTagEnabled = prefs.getBoolean("geotagKey", true);

    // If enabled, get location manager and provider
    if (mGeoTagEnabled) {
        mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    }

    // Set the content of UI elements, either auto-generated or retrieved
    // from a Find
    Bundle extras = getArguments();

    if (extras != null && !(extras.size() == 1 && extras.containsKey("ACTION"))) {
        // Existing Find
        if (getAction().equals(Intent.ACTION_EDIT)) {
            int id = extras.getInt(Find.ORM_ID);
            Log.i(TAG, "ORM_id = " + id);
            //            Find find = getHelper().getFindById(id);
            mFind = getHelper().getFindById(id);
            Log.i(TAG, "Updating: " + mFind);
            displayContentInView(mFind);
        } else

        // Bundled Find (from SMS)
        if (getAction().equals(Intent.ACTION_INSERT_OR_EDIT)) {
            // Pull a Bundle corresponding to a Find from the Intent and put
            // that in the view
            Bundle findBundle = extras.getBundle("findbundle");
            //Find find;
            try {
                FindPlugin plugin = FindPluginManager.mFindPlugin;
                if (plugin == null) {
                    Log.e(TAG, "Could not retrieve Find Plugin.");
                    Toast.makeText(getActivity(), "A fatal error occurred while trying to start FindActivity",
                            Toast.LENGTH_LONG).show();
                    getActivity().finish();
                    return;
                }
                mFind = plugin.getmFindClass().newInstance();
            } catch (IllegalAccessException e) {
                Toast.makeText(getActivity(), "A fatal error occurred while trying to start FindActivity",
                        Toast.LENGTH_LONG).show();
                getActivity().finish();
                return;
            } catch (java.lang.InstantiationException e) {
                Toast.makeText(getActivity(), "A fatal error occurred while trying to start FindActivity",
                        Toast.LENGTH_LONG).show();
                getActivity().finish();
                return;
            }
            mFind.updateObject(findBundle);
            displayContentInView(mFind);
        } else
        // CSV Find   
        if (getAction().equals(CsvListFindsFragment.ACTION_CSV_FINDS)) {

        }
        // New Find
    } else {
        Log.i("TAG", "new find");
        // Set real GUID
        if (mGuidRealTV != null)
            mGuidRealTV.setText(UUID.randomUUID().toString());
        // Set displayed GUID
        if (mGuidTV != null)
            mGuidTV.setText(mGuidRealTV.getText().toString().substring(0, 8) + "...");
        // Set Time
        if (mTimeTV != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            Date date = new Date();
            mTimeTV.setText(dateFormat.format(date));
        }

        if (mGeoTagEnabled) {
            // Set Longitude and Latitude
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 0, this);
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);

            Location netLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            if (gpsLocation != null) {
                mCurrentLocation = gpsLocation;
            } else {
                mCurrentLocation = netLocation;
            }

            if (mCurrentLocation == null) {
                Log.i(TAG, "Location issue, mCurrentLocation = " + mCurrentLocation);
                if (mLongitudeTV != null)
                    mLongitudeTV.setText("0.0");
                if (mLatitudeTV != null)
                    mLatitudeTV.setText("0.0");
                // Toast.makeText(this, "Unable to retrieve GPS info." +
                // " Please make sure your Data or Wi-Fi is enabled.",
                // Toast.LENGTH_SHORT).show();
                // Log.i(TAG,
                // "Cannot request location updates; Data or Wifi might not be enabled.");
            } else {
                if (mLongitudeTV != null)
                    mLongitudeTV.setText(String.valueOf(mCurrentLocation.getLongitude()));
                if (mLatitudeTV != null)
                    mLatitudeTV.setText(String.valueOf(mCurrentLocation.getLatitude()));
            }
        } else {
            if (mLongitudeTV != null && mLongTV != null) {
                mLongitudeTV.setVisibility(TextView.INVISIBLE);
                mLongTV.setVisibility(TextView.INVISIBLE);
            }
            if (mLatitudeTV != null && mLatTV != null) {
                mLatitudeTV.setVisibility(TextView.INVISIBLE);
                mLatTV.setVisibility(TextView.INVISIBLE);
            }
        }
    }
}

From source file:org.mariotaku.twidere.activity.support.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mImageLoader = TwidereApplication.getInstance(this).getMediaLoaderWrapper();
    final Intent intent = getIntent();
    final String type = mTabType = intent.getStringExtra(EXTRA_TYPE);
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();/*from   w ww .  j a  v a  2s.  co m*/
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mEditTabName.setFloatingLabelText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean hasSecondaryField = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean accountIdNone = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(accountIdNone ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(ParcelableAccount.dummyCredentials());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        final boolean forcePrivateAPIs = intent.getBooleanExtra(KEY_FORCE_USING_PRIVATE_APIS, false);
        mAccountsAdapter.addAll(
                ParcelableAccount.getCredentialsList(this, false, !forcePrivateAPIs && officialKeyOnly));
        mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS)));
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    // Restore dialog extras.
    mDialogExtras = savedInstanceState.getBundle(EXTRA_DIALOG_EXTRAS);
    // Restore list view position.
    int topPosition = savedInstanceState.getInt(EXTRA_TOP_POSITION);
    int top = savedInstanceState.getInt(EXTRA_TOP);
    getListView().setSelectionFromTop(topPosition, top);

    super.onRestoreInstanceState(savedInstanceState);
}