Example usage for android.os Bundle getStringArray

List of usage examples for android.os Bundle getStringArray

Introduction

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

Prototype

@Nullable
public String[] getStringArray(@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:edu.umich.oasis.sandbox.SandboxService.java

@Override
public IBinder onBind(Intent i) {
    if (localLOGD) {
        Log.d(TAG, "Bound");
    }/*from  ww  w . j a va2 s .  c  o  m*/
    Bundle extras = i.getExtras();
    if (extras == null) {
        throw new IllegalArgumentException("No extras");
    }
    IBinder api = extras.getBinder(EXTRA_TRUSTED_API);
    if (api == null) {
        throw new IllegalArgumentException("Trusted API not found in extras");
    }
    IBinder root = extras.getBinder(EXTRA_ROOT_SERVICE);
    if (root == null) {
        throw new IllegalArgumentException("OASISService not found in extras");
    }
    mTrustedAPI = ITrustedAPI.Stub.asInterface(api);
    mRootService = IOASISService.Stub.asInterface(root);
    mID = extras.getInt(EXTRA_SANDBOX_ID, -1);

    if (localLOGV) {
        ClassLoader cl = getClassLoader();
        Log.v(TAG, "ClassLoader chain:");
        while (cl != null) {
            Log.v(TAG, cl.toString());
            cl = cl.getParent();
        }
        Log.v(TAG, "<end of chain>");
    }

    final String[] packagesToLoad = extras.getStringArray(EXTRA_KNOWN_PACKAGES);
    getBackgroundHandler().post(new Runnable() {
        @Override
        public void run() {
            if (localLOGD) {
                Log.d(TAG, "Preloading resolve code");
            }

            // Run through a fake transaction, to preload the appropriate classes.
            SodaDescriptor preloadDesc = SodaDescriptor.forStatic(SandboxService.this, SandboxService.class,
                    "resolveStub");

            Binder testBinder = new Binder() {
                @Override
                protected boolean onTransact(int code, Parcel data, Parcel reply, int flags)
                        throws RemoteException {
                    return mBinder.onTransact(code, data, reply, flags);
                }
            };
            testBinder.attachInterface(null, "");

            ISandboxService proxy = ISandboxService.Stub.asInterface(testBinder);
            try {
                proxy.resolveSoda(preloadDesc, false, null);
            } catch (Exception e) {
                Log.w(TAG, "Couldn't preload resolve", e);
            }

            if (localLOGD) {
                Log.d(TAG, "Preloading packages");
            }

            // Load up packages the trusted service tells us we might need.
            for (String packageName : ArrayUtils.nullToEmpty(packagesToLoad)) {
                try {
                    if (localLOGD) {
                        Log.d(TAG, "Preloading " + packageName);
                    }
                    getContextForPackage(packageName);
                } catch (PackageManager.NameNotFoundException e) {
                    Log.w(TAG, "Can't preload package", e);
                }
            }

            Log.i(TAG, "Sandbox #" + mID + ": preload complete");
        }
    });
    return mBinder;
}

From source file:edu.umich.flowfence.sandbox.SandboxService.java

@Override
public IBinder onBind(Intent i) {
    if (localLOGD) {
        Log.d(TAG, "Bound");
    }// w ww .  ja  v  a  2 s . co  m
    Bundle extras = i.getExtras();
    if (extras == null) {
        throw new IllegalArgumentException("No extras");
    }
    IBinder api = extras.getBinder(EXTRA_TRUSTED_API);
    if (api == null) {
        throw new IllegalArgumentException("Trusted API not found in extras");
    }
    IBinder root = extras.getBinder(EXTRA_ROOT_SERVICE);
    if (root == null) {
        throw new IllegalArgumentException("FlowfenceService not found in extras");
    }
    mTrustedAPI = ITrustedAPI.Stub.asInterface(api);
    mRootService = IFlowfenceService.Stub.asInterface(root);
    mID = extras.getInt(EXTRA_SANDBOX_ID, -1);

    if (localLOGV) {
        ClassLoader cl = getClassLoader();
        Log.v(TAG, "ClassLoader chain:");
        while (cl != null) {
            Log.v(TAG, cl.toString());
            cl = cl.getParent();
        }
        Log.v(TAG, "<end of chain>");
    }

    final String[] packagesToLoad = extras.getStringArray(EXTRA_KNOWN_PACKAGES);
    getBackgroundHandler().post(new Runnable() {
        @Override
        public void run() {
            if (localLOGD) {
                Log.d(TAG, "Preloading resolve code");
            }

            // Run through a fake transaction, to preload the appropriate classes.
            QMDescriptor preloadDesc = QMDescriptor.forStatic(SandboxService.this, SandboxService.class,
                    "resolveStub");

            Binder testBinder = new Binder() {
                @Override
                protected boolean onTransact(int code, Parcel data, Parcel reply, int flags)
                        throws RemoteException {
                    return mBinder.onTransact(code, data, reply, flags);
                }
            };
            testBinder.attachInterface(null, "");

            ISandboxService proxy = ISandboxService.Stub.asInterface(testBinder);
            try {
                proxy.resolveQM(preloadDesc, false, null);
            } catch (Exception e) {
                Log.w(TAG, "Couldn't preload resolve", e);
            }

            if (localLOGD) {
                Log.d(TAG, "Preloading packages");
            }

            // Load up packages the trusted service tells us we might need.
            for (String packageName : ArrayUtils.nullToEmpty(packagesToLoad)) {
                try {
                    if (localLOGD) {
                        Log.d(TAG, "Preloading " + packageName);
                    }
                    getContextForPackage(packageName);
                } catch (PackageManager.NameNotFoundException e) {
                    Log.w(TAG, "Can't preload package", e);
                }
            }

            Log.i(TAG, "Sandbox #" + mID + ": preload complete");
        }
    });
    return mBinder;
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java

/**
 * {@inheritDoc}//from w ww  .  j  a v a  2 s . c o m
 */
@Override
public Loader onCreateLoader(final int i, final Bundle bundle) {
    switch (i) {
    case LOADER_ID_BUS_STOPS:
        if (bundle.containsKey(LOADER_ARG_FILTERED_SERVICES)) {
            return new BusStopMarkerLoader(getActivity(), bundle.getDouble(LOADER_ARG_MIN_X),
                    bundle.getDouble(LOADER_ARG_MIN_Y), bundle.getDouble(LOADER_ARG_MAX_X),
                    bundle.getDouble(LOADER_ARG_MAX_Y), bundle.getFloat(LOADER_ARG_ZOOM),
                    bundle.getStringArray(LOADER_ARG_FILTERED_SERVICES));
        } else {
            return new BusStopMarkerLoader(getActivity(), bundle.getDouble(LOADER_ARG_MIN_X),
                    bundle.getDouble(LOADER_ARG_MIN_Y), bundle.getDouble(LOADER_ARG_MAX_X),
                    bundle.getDouble(LOADER_ARG_MAX_Y), bundle.getFloat(LOADER_ARG_ZOOM));
        }
    case LOADER_ID_GEO_SEARCH:
        String query = bundle.getString(LOADER_ARG_QUERY);
        // Make sure the query arg is not null.
        if (query == null) {
            query = "";
        }

        return new GeoSearchLoader(getActivity(), query);
    case LOADER_ID_ROUTE_LINES:
        return new RouteLineLoader(getActivity(), bundle.getStringArray(LOADER_ARG_FILTERED_SERVICES));
    default:
        return null;
    }
}

From source file:com.pileproject.drive.util.fragment.AlertDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override/*from   w ww. j a  v  a2  s  . c om*/
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
            mListener.onDialogEventHandled(getRequestCode(), dialog, which,
                    getArguments().getBundle(KEY_PARAMS));
        }
    };

    Bundle args = getArguments();

    setCancelable(args.getBoolean(KEY_CANCELABLE));

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

    String title = args.getString(KEY_TITLE);
    String message = args.getString(KEY_MESSAGE);
    String positiveLabel = args.getString(KEY_POSITIVE_LABEL);
    String negativeLabel = args.getString(KEY_NEGATIVE_LABEL);

    // set strings if not empty
    if (!TextUtils.isEmpty(title)) {
        builder.setTitle(title);
    }
    if (!TextUtils.isEmpty(message)) {
        builder.setMessage(message);
    }
    if (!TextUtils.isEmpty(positiveLabel)) {
        builder.setPositiveButton(positiveLabel, listener);
    }
    if (!TextUtils.isEmpty(negativeLabel)) {
        builder.setNegativeButton(negativeLabel, listener);
    }

    // if there is a list, set it as list view
    String[] items = args.getStringArray(KEY_ITEMS);

    if (items != null && items.length > 0) {
        builder.setItems(items, listener);
    }

    AlertDialog dialog = builder.create();

    dialog.getWindow().setGravity(args.getInt(KEY_GRAVITY));

    return dialog;
}

From source file:github.daneren2005.dsub.activity.SubsonicActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
    String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
    FragmentManager fm = getSupportFragmentManager();
    currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]);
    currentFragment.setPrimaryFragment(true);
    currentFragment.setSupportTag(ids[0]);
    supportInvalidateOptionsMenu();/*w w  w  . j a  va 2  s. co  m*/
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    for (int i = 1; i < size; i++) {
        SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]);
        frag.setSupportTag(ids[i]);
        if (secondaryContainer != null) {
            frag.setPrimaryFragment(false, true);
        }
        trans.hide(frag);
        backStack.add(frag);
    }
    trans.commit();

    // Current fragment is hidden in secondaryContainer
    if (secondaryContainer == null && !currentFragment.isVisible()) {
        trans = getSupportFragmentManager().beginTransaction();
        trans.remove(currentFragment);
        trans.commit();
        getSupportFragmentManager().executePendingTransactions();

        trans = getSupportFragmentManager().beginTransaction();
        trans.add(R.id.fragment_container, currentFragment, ids[0]);
        trans.commit();
    }
    // Current fragment needs to be moved over to secondaryContainer
    else if (secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null
            && backStack.size() > 0) {
        trans = getSupportFragmentManager().beginTransaction();
        trans.remove(currentFragment);
        trans.show(backStack.get(backStack.size() - 1));
        trans.commit();
        getSupportFragmentManager().executePendingTransactions();

        trans = getSupportFragmentManager().beginTransaction();
        trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
        trans.commit();

        secondaryContainer.setVisibility(View.VISIBLE);
    }

    lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
    if (lastSelectedPosition != 0) {
        MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
        if (item != null) {
            item.setChecked(true);
        }
    }
    recreateSpinner();
}

From source file:net.xisberto.phonetodesktop.SendTasksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Utils.log("onCreate " + this.toString());

    prefs = new Preferences(this);
    if (prefs.loadShowPreview()) {
        // If we will show the activity, change the theme
        setTheme(R.style.Theme_PhoneToDesktop_ActivityOrDialog);
    }//  www. j av a  2  s  .  co  m
    // ActionbarSherlock adds views to the Activity during onCreate, so we
    // must call super.onCreate after we reset the theme
    super.onCreate(savedInstanceState);

    UpdateChecker checker = new UpdateChecker(this);
    checker.setNotice(Notice.NOTIFICATION);
    checker.setDebug(BuildConfig.DEBUG);
    checker.start();

    if (getIntent().getAction().equals(Intent.ACTION_SEND) && getIntent().hasExtra(Intent.EXTRA_TEXT)) {
        text_from_extra = getIntent().getStringExtra(Intent.EXTRA_TEXT);

        databaseHelper = DatabaseHelper.getInstance(getApplicationContext());

        if (savedInstanceState != null) {
            cache_unshorten = savedInstanceState.getStringArray(SAVE_CACHE_UNSHORTEN);
            cache_titles = savedInstanceState.getStringArray(SAVE_CACHE_TITLES);
            long local_id = savedInstanceState.getLong(SAVE_LOCAL_TASK_ID);
            localTask = databaseHelper.getTask(local_id);
            isWaiting = savedInstanceState.getBoolean(SAVE_IS_WAITING);
            restoreFromPreferences = false;
        } else {
            localTask = new LocalTask(this);
            localTask.setTitle(text_from_extra);
            if (!prefs.loadShowPreview()) {
                // User has chosen to not see the preview, so we process and
                // send the task without showing the activity.
                // processPreferences calls sentText on localTask's persist
                // callback
                processPreferences();
                finish();
                return;
            }
            restoreFromPreferences = true;
        }

        send_fragment = (SendFragment) getSupportFragmentManager().findFragmentByTag("send_fragment");
        if (send_fragment == null) {
            send_fragment = SendFragment.newInstance(text_from_extra);
        }
        if (!send_fragment.isAdded()) {
            if (getResources().getBoolean(R.bool.is_tablet)) {
                send_fragment.show(getSupportFragmentManager(), "send_fragment");
            } else {
                getSupportFragmentManager().beginTransaction()
                        .replace(android.R.id.content, send_fragment, "send_fragment").commit();
            }
        }
    } else {
        finish();
        return;
    }

}

From source file:org.lyricue.android.Lyricue.java

/**
 * Called when the activity is first created.
 *///from w  w w  .  ja  va2  s  .  co  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate()");
    activity = this;
    setContentView(R.layout.main);
    FragmentManager fragman = getSupportFragmentManager();
    vib = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);

    if (savedInstanceState != null) {
        for (Fragment frag : fragman.getFragments()) {
            if (frag != null) {
                Log.d(TAG, frag.toString());
                Log.d(TAG, frag.getClass().getName());
                fragments.put(frag.getClass().getName(), frag);
            }
        }
        hosts = (HostItem[]) savedInstanceState.getParcelableArray("hosts");
        profile = savedInstanceState.getString("profile");
        playlistid = savedInstanceState.getLong("playlistid");
        playlists_text = savedInstanceState.getStringArray("playlists_text");
        playlists_id = savedInstanceState.getLongArray("playlists_id");
        bibles_text = savedInstanceState.getStringArray("bibles_text");
        bibles_id = savedInstanceState.getStringArray("bibles_id");
        bibles_type = savedInstanceState.getStringArray("bibles_type");
        ld = new LyricueDisplay(hosts);
    }

    LyricuePagerAdapter adapter = new LyricuePagerAdapter(fragman, activity, activity);
    pager = (ViewPager) findViewById(R.id.viewpager);
    pager.setAdapter(adapter);

    actionBar = getSupportActionBar();
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // When the tab is selected, switch to the
            // corresponding page in the ViewPager.
            pager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
        }

        @Override
        public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
        }
    };

    Tab controlTab = actionBar.newTab().setText("Control").setTabListener(tabListener);
    actionBar.addTab(actionBar.newTab().setText(R.string.playlist).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.available).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.bible).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.display).setTabListener(tabListener));
    actionBar.addTab(controlTab);

    pager.setOffscreenPageLimit(actionBar.getTabCount());

    Resources res = getResources();
    Configuration conf = res.getConfiguration();
    boolean isLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE);
    boolean isLarge = (conf.screenLayout & 0x4) == 0x4;
    Log.d(TAG, "Status:" + isLarge + ":" + isLandscape);
    if (isLarge && isLandscape) {
        activity.setQuickBar(false);
        actionBar.removeTab(controlTab);
        pager.setCurrentItem(0);
    } else {
        pager.setCurrentItem(4);
    }
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getSupportActionBar().setSelectedNavigationItem(position);
        }
    });

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.RED);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    thumbnail_width = Math.min(displaymetrics.widthPixels, displaymetrics.heightPixels) / 2;
    if (profile.equals("")) {
        getPrefs();
    }
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java

/**
 * {@inheritDoc}//w w  w  .ja  va 2s. c  o  m
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Retain the instance to this Fragment.
    setRetainInstance(true);

    final Context context = getActivity();
    bsd = BusStopDatabase.getInstance(context.getApplicationContext());
    sp = context.getSharedPreferences(PreferencesActivity.PREF_FILE, 0);
    searchMan = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);

    services = bsd.getBusServiceList();

    if (savedInstanceState != null) {
        chosenServices = savedInstanceState.getStringArray(ARG_CHOSEN_SERVICES);
    }

    // Get the height of the ActionBar from the assigned attribute in the
    // appcompat project theme.
    final TypedValue value = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, value, true);
    actionBarHeight = getResources().getDimensionPixelSize(value.resourceId);

    // This Fragment shows an options menu.
    setHasOptionsMenu(true);
}

From source file:net.xisberto.phonetodesktop.ui.SendTasksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Utils.log("onCreate " + this.toString());

    prefs = Preferences.getInstance(this);
    if (prefs.loadShowPreview()) {
        // If we will show the activity, change the theme
        setTheme(R.style.Theme_PhoneToDesktop_Dialog);
    }/* w  w  w.java 2 s.co  m*/
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    UpdateChecker checker = new UpdateChecker(this);
    checker.setNotice(Notice.NOTIFICATION);
    checker.start();

    if (getIntent().getAction().equals(Intent.ACTION_SEND) && getIntent().hasExtra(Intent.EXTRA_TEXT)) {
        text_from_extra = getIntent().getStringExtra(Intent.EXTRA_TEXT);

        DatabaseHelper databaseHelper = DatabaseHelper.getInstance(getApplicationContext());

        if (savedInstanceState != null) {
            long local_id = savedInstanceState.getLong(SAVE_LOCAL_TASK_ID);
            localTask = databaseHelper.getTask(local_id);
            //The caches aren't saved to the databse
            localTask.cache_titles = savedInstanceState.getStringArray(SAVE_CACHE_TITLES);
            localTask.cache_unshorten = savedInstanceState.getStringArray(SAVE_CACHE_UNSHORTEN);
            isWaiting = savedInstanceState.getBoolean(SAVE_IS_WAITING);
            restoreFromPreferences = false;
        } else {
            localTask = new LocalTask(this);
            localTask.setTitle(text_from_extra);
            if (!prefs.loadShowPreview()) {
                // User has chosen to not see the preview, so we process and
                // send the task without showing the activity.
                // processPreferences calls sentText on localTask's persist
                // callback
                spiceManager.start(this);
                processPreferences();
                finish();
                return;
            }
            restoreFromPreferences = true;
        }

        send_fragment = (SendFragment) getSupportFragmentManager().findFragmentByTag("send_fragment");
        if (send_fragment == null) {
            send_fragment = SendFragment.newInstance(text_from_extra);
        }
        if (!send_fragment.isAdded()) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.main_frame, send_fragment, "send_fragment").commit();
        }
    } else {
        finish();
    }

}