Example usage for android.os Bundle keySet

List of usage examples for android.os Bundle keySet

Introduction

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

Prototype

public Set<String> keySet() 

Source Link

Document

Returns a Set containing the Strings used as keys in this Bundle.

Usage

From source file:de.andacaydin.bidirectionalviewpagerlibrary.googlecode.FragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//from  www  .j  a  v  a2  s .  c  o m
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                BiDirectionalFragment f = (BiDirectionalFragment) mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.leychina.widget.tabindicator.view.indicator.FragmentListPageAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//from ww w . java  2s  .co  m
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                }
            }
        }
    }
}

From source file:com.google.android.gms.location.sample.locationaddress.LocationMainActivity.java

/**
 * Updates fields based on data stored in the bundle.
 *///from  www.  ja  va 2 s.  co  m
private void updateValuesFromBundle(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        // Check savedInstanceState to see if the address was previously requested.
        if (savedInstanceState.keySet().contains(ADDRESS_REQUESTED_KEY)) {
            mAddressRequested = savedInstanceState.getBoolean(ADDRESS_REQUESTED_KEY);
        }
        // Check savedInstanceState to see if the location address string was previously found
        // and stored in the Bundle. If it was found, display the address string in the UI.
        if (savedInstanceState.keySet().contains(LOCATION_ADDRESS_KEY)) {
            mAddressOutput = savedInstanceState.getString(LOCATION_ADDRESS_KEY);

            displayAddressOutput();
        }
    }
}

From source file:com.hongsec.frame.tab.view.indicator.FragmentListPageAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*w  w w. ja  v  a 2  s .  c om*/
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    //                  Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.nononsenseapps.support.app.FragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//from  w ww  .j a  va  2 s .  co  m
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    setMenuVisibility(f, false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.tapchatapp.android.app.ui.TapchatFragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//from   w  ww. j  a  v  a2  s.co  m
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                    f.onResume();
                } else {
                    if (DEBUG)
                        Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.york.cs.services.SyncAdapter.SyncAdapterCB.java

/**
 * Called by the Android system in response to a request to run the sync
 * adapter. The work required to read data from the network, parse it, and
 * store it done here. Extending AbstractThreadedSyncAdapter ensures that
 * all methods within SyncAdapter run on a background thread. For this
 * reason, blocking I/O and other long-running tasks can be run
 * <em>in situ</em>, and you don't have to set up a separate thread for
 * them. .//from   w  w  w .j a v  a 2  s  .  com
 * 
 * <p>
 * This is where we actually perform any work required to perform a sync.
 * {@link AbstractThreadedSyncAdapter} guarantees that this will be called
 * on a non-UI thread, so it is safe to peform blocking I/O here.
 * 
 * <p>
 * The syncResult argument allows you to pass information back to the method
 * that triggered the sync.
 */
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {
    Log.d(TAG, "onPerformSync for account");

    // Building a print of the extras we got
    StringBuilder sb = new StringBuilder();
    if (extras != null) {
        for (String key : extras.keySet()) {
            sb.append(key + "[" + extras.get(key) + "] ");
        }
    }

    Log.d(TAG, "onPerformSync for account[" + account.name + "]. Extras: " + sb.toString());

    try {
        // Get the auth token for the current account and
        // the userObjectId, needed for creating items on Parse.com account
        String authToken = mAccountManager.blockingGetAuthToken(account,
                AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, true);
        String userObjectId = mAccountManager.getUserData(account, AccountGeneral.USERDATA_USER_OBJ_ID);

        Log.d(TAG, "start sunc" + authToken + "-" + userObjectId);

        Application application = (Application) getContext();

        Database database = application.getDatabase();
        initObservable();
        startSyncWithCustomCookie(database, authToken);

    } catch (OperationCanceledException e) {
        e.printStackTrace();
    } catch (IOException e) {
        syncResult.stats.numIoExceptions++;
        e.printStackTrace();
    } catch (AuthenticatorException e) {
        syncResult.stats.numAuthExceptions++;
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.karura.framework.PluginManager.java

/**
 * Called when the webview attached with the plugin manager is being restored with instance data
 * /*from w  w w  .  j a  v a2 s  .c om*/
 * Lets try to recreate all plugins with instance data
 * 
 * @param savedInstance
 *            the memory block which contains information about each of the plugins which were persisted in call to onSaveInstanceState
 */
public void onRestoreInstanceState(Bundle savedInstance) {
    // See if there is a valid instance to restore state from
    if (savedInstance == null || !savedInstance.containsKey(PLUGIN_MGR_INSTANCE_DATA_KEY))
        return;

    Bundle pluginMgrInstanceData = savedInstance.getBundle(PLUGIN_MGR_INSTANCE_DATA_KEY);
    _nextPluginId = 0;
    for (String pluginDataKey : pluginMgrInstanceData.keySet()) {

        // only process those data keys which were created by us
        if (!pluginDataKey.startsWith(PLUGIN_INSTANCE_DATA_KEY_PREFIX)) {
            continue;
        }

        // try and retrieve plugin specific instance data
        Bundle pluginInstanceData = pluginMgrInstanceData.getBundle(pluginDataKey);

        if (pluginInstanceData == null)
            continue;

        String clazz = pluginInstanceData.getString(PLUGIN_CLASS_NAME_KEY);
        pluginInstanceData.remove(PLUGIN_CLASS_NAME_KEY);
        Integer pluginId = Integer.valueOf(pluginInstanceData.getString(PLUGIN_ID_KEY));

        // manage the plugin id counter for subsequent allocation of plugins
        if (_nextPluginId < pluginId) {
            _nextPluginId = pluginId;
        }
        pluginInstanceData.remove(PLUGIN_ID_KEY);

        // Since we are passing the instance data for the plugin in this call, we are hoping it
        // will be able to restore its state
        allocateAndCachePlugin(clazz, pluginId, pluginInstanceData);

    }
    // safe increment
    _nextPluginId++;

    // TODO create a list of pluginIds and pass them back to the javascript layer just in case

}

From source file:org.akvo.caddisfly.sensor.ec.SensorActivity.java

@SuppressWarnings("SameParameterValue")
private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {

    if (!UsbService.SERVICE_CONNECTED) {
        Intent startService = new Intent(this, service);
        if (extras != null && !extras.isEmpty()) {
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                String extra = extras.getString(key);
                startService.putExtra(key, extra);
            }/*w ww.ja  v a  2s. co m*/
        }
        startService(startService);
    }
    Intent bindingIntent = new Intent(this, service);
    bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);

    alertDialog.dismiss();

    handler.postDelayed(validateDeviceRunnable, IDENTIFY_DELAY_MILLIS * 2);
}

From source file:com.bilibili.lib.pageradapter.IDFragmentStatePagerAdapter.java

@Override
@CallSuper/*ww w  .j  a va  2s .  co  m*/
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        mSavedState.clear();
        mFragments.clear();
        SparseArray<Fragment.SavedState> fss = bundle.getSparseParcelableArray(KEY_SAVED_STATES);
        if (fss != null) {
            for (int i = 0; i < fss.size(); i++) {
                mSavedState.put(fss.keyAt(i), fss.valueAt(i));
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith(KEY_PREFIX)) {
                Fragment f = mFragmentManager.getFragment(bundle, key);
                int id;
                try {
                    id = Integer.parseInt(key.substring(KEY_PREFIX.length()));
                } catch (NumberFormatException e) {
                    // should not happen!
                    throw new IllegalStateException("Can't find id at key " + key);
                }
                if (f != null) {
                    f.setMenuVisibility(false);
                    mFragments.put(id, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}