Example usage for android.os Bundle getIntArray

List of usage examples for android.os Bundle getIntArray

Introduction

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

Prototype

@Nullable
public int[] getIntArray(@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:com.justplay1.shoppist.features.settings.SelectThemeColorDialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    size = ShoppistUtils.isTablet(getActivity()) ? SelectThemeColorDialogFragment.SIZE_LARGE
            : SelectThemeColorDialogFragment.SIZE_SMALL;
    colorsPrimary = getResources().getIntArray(R.array.color_theme);
    colorPrimaryDark = getResources().getIntArray(R.array.color_status_bar);

    if (getArguments() != null) {
        selectedColor = getArguments().getInt(Const.SELECTED_COLOR);
    }//from w w w  . j  a  va2 s  . c om

    if (savedInstanceState != null) {
        colorsPrimary = savedInstanceState.getIntArray(KEY_COLORS);
        selectedColor = savedInstanceState.getInt(KEY_SELECTED_COLOR);
    }
}

From source file:com.bt.download.android.gui.activities.MainActivity.java

private void restoreFragmentsStack(Bundle savedInstanceState) {
    try {/*from   www  . j a v  a2s.com*/
        int[] stack = savedInstanceState.getIntArray(FRAGMENTS_STACK_KEY);
        for (int id : stack) {
            fragmentsStack.push(id);
        }
    } catch (Throwable e) {
        // silent recovering, stack is't not really important
    }
}

From source file:androidx.navigation.NavController.java

/**
 * Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
 * This is called automatically for you the first time you set the graph if you've passed in an
 * {@link Activity} as the context when constructing this NavController, but should be manually
 * called if your Activity receives new Intents in {@link Activity#onNewIntent(Intent)}.
 * <p>//from w  w  w. j  a  va 2  s.c o m
 * The types of Intents that are supported include:
 * <ul>
 *     <ol>Intents created by {@link NavDeepLinkBuilder} or
 *     {@link #createDeepLink()}. This assumes that the current graph shares
 *     the same hierarchy to get to the deep linked destination as when the deep link was
 *     constructed.</ol>
 *     <ol>Intents that include a {@link Intent#getData() data Uri}. This Uri will be checked
 *     against the Uri patterns added via {@link NavDestination#addDeepLink(String)}.</ol>
 * </ul>
 * <p>The {@link #getGraph() navigation graph} should be set before calling this method.</p>
 * @param intent The Intent that may contain a valid deep link
 * @return True if the navigation controller found a valid deep link and navigated to it.
 * @see NavDestination#addDeepLink(String)
 */
public boolean onHandleDeepLink(@Nullable Intent intent) {
    if (intent == null) {
        return false;
    }
    Bundle extras = intent.getExtras();
    int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null;
    Bundle bundle = new Bundle();
    Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null;
    if (deepLinkExtras != null) {
        bundle.putAll(deepLinkExtras);
    }
    if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) {
        Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData());
        if (matchingDeepLink != null) {
            deepLink = matchingDeepLink.first.buildDeepLinkIds();
            bundle.putAll(matchingDeepLink.second);
        }
    }
    if (deepLink == null || deepLink.length == 0) {
        return false;
    }
    bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent);
    int flags = intent.getFlags();
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) {
        // Someone called us with NEW_TASK, but we don't know what state our whole
        // task stack is in, so we need to manually restart the whole stack to
        // ensure we're in a predictably good state.
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext)
                .addNextIntentWithParentStack(intent);
        taskStackBuilder.startActivities();
        if (mActivity != null) {
            mActivity.finish();
        }
        return true;
    }
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        // Start with a cleared task starting at our root when we're on our own task
        if (!mBackStack.isEmpty()) {
            navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder()
                    .setPopUpTo(mGraph.getId(), true).setEnterAnim(0).setExitAnim(0).build());
        }
        int index = 0;
        while (index < deepLink.length) {
            int destinationId = deepLink[index++];
            NavDestination node = findDestination(destinationId);
            if (node == null) {
                throw new IllegalStateException("unknown destination during deep link: "
                        + NavDestination.getDisplayName(mContext, destinationId));
            }
            node.navigate(bundle, new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build());
        }
        return true;
    }
    // Assume we're on another apps' task and only start the final destination
    NavGraph graph = mGraph;
    for (int i = 0; i < deepLink.length; i++) {
        int destinationId = deepLink[i];
        NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId);
        if (node == null) {
            throw new IllegalStateException("unknown destination during deep link: "
                    + NavDestination.getDisplayName(mContext, destinationId));
        }
        if (i != deepLink.length - 1) {
            // We're not at the final NavDestination yet, so keep going through the chain
            graph = (NavGraph) node;
        } else {
            // Navigate to the last NavDestination, clearing any existing destinations
            node.navigate(bundle, new NavOptions.Builder().setPopUpTo(mGraph.getId(), true).setEnterAnim(0)
                    .setExitAnim(0).build());
        }
    }
    return true;
}

From source file:com.example.android.snake.SnakeView.java

/**
 * Restore game state if our process is being relaunched
 *
 * @param icicle a Bundle containing the game state
 *//*  www .  j a  v a  2s.  com*/
public void restoreState(Bundle icicle) {
    setMode(PAUSE);

    mAppleList = coordArrayToArrayList(icicle.getIntArray("mAppleList"));
    mDirection = icicle.getInt("mDirection");
    mNextDirection = icicle.getInt("mNextDirection");
    mMoveDelay = icicle.getLong("mMoveDelay");
    mScore = icicle.getLong("mScore");
    mSnakeTrail = coordArrayToArrayList(icicle.getIntArray("mSnakeTrail"));
}

From source file:com.bilibili.lib.pageradapter.demo.MainActivity.java

private void setupViewPager(Bundle savedInstanceState, ViewPager pager) {
    List<Color> colors;
    if (savedInstanceState == null) {
        colors = new ArrayList<>(10);
        colors.add(new Color(1, 0xFFFF5722));
        colors.add(new Color(2, 0xFF8D6E63));
        colors.add(new Color(3, 0xFF9C27B0));
        colors.add(new Color(4, 0xFF757575));
        colors.add(new Color(5, 0xFF8BC34A));
        colors.add(new Color(6, 0xFF2196F3));
        colors.add(new Color(7, 0xFFE91E63));
        colors.add(new Color(8, 0xFFFFC107));
        colors.add(new Color(9, 0xFF795548));
        colors.add(new Color(0, 0xFF4CAF50));
    } else {//from   w  w w.j  a  v a  2 s.c  om
        // restore shuffled colors
        colors = fromArray(savedInstanceState.getIntArray("colors"));
    }
    Adapter adapter = new Adapter(getSupportFragmentManager(), colors);
    pager.setAdapter(adapter);
    this.adapter = adapter;
}

From source file:com.android.contacts.list.ContactEntryListAdapter.java

/**
 * Updates the indexer, which is used to produce section headers.
 *//*from   w  w  w. j av a 2  s  . c  o  m*/
//private void updateIndexer(Cursor cursor) {
public void updateIndexer(Cursor cursor) {
    if (cursor == null) {
        setIndexer(null);
        return;
    }

    Bundle bundle = cursor.getExtras();
    if (bundle.containsKey(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES)) {
        String sections[] = bundle.getStringArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES);
        int counts[] = bundle.getIntArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS);
        setIndexer(new ContactsSectionIndexer(sections, counts));
    } else {
        setIndexer(null);
    }
}

From source file:androidx.navigation.NavController.java

/**
 * Restores all navigation controller state from a bundle.
 *
 * <p>State may be saved to a bundle by calling {@link #saveState()}.
 * Restoring controller state is the responsibility of a {@link NavHost}.</p>
 *
 * @param navState state bundle to restore
 *//*  w w  w .  j ava  2s  .  c o m*/
public void restoreState(@Nullable Bundle navState) {
    if (navState == null) {
        return;
    }

    mGraphId = navState.getInt(KEY_GRAPH_ID);
    mNavigatorStateToRestore = navState.getBundle(KEY_NAVIGATOR_STATE);
    mBackStackToRestore = navState.getIntArray(KEY_BACK_STACK_IDS);
    if (mGraphId != 0) {
        // Set the graph right away, onGraphCreated will handle restoring the
        // rest of the saved state
        setGraph(mGraphId);
    }
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action.equals(REFRESH_ACTION)) {
        Log.d(TAG, "Widget Refresh button pressed");

        Intent i = new Intent(Constants.INTENT_START_SYNC_WITH_REMOTE);
        context.sendBroadcast(i);//from w w w . jav a  2 s .c  om
        Bundle extras = intent.getExtras();

        if (extras != null) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            RemoteViews rv = buildLayout(context, appWidgetId, true);
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, rv);
        }
    } else if (action.equals(Constants.INTENT_WIDGET_UPDATE)) {
        Log.d(TAG, "Update widget intent received ");

        int[] appWidgetIds = null;
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        Bundle extras = intent.getExtras();

        if (extras != null) {
            appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        }

        if (appWidgetIds == null) {
            appWidgetIds = appWidgetManager
                    .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class.getName()));
        }

        if (appWidgetIds != null && appWidgetIds.length > 0) {
            this.onUpdate(context, appWidgetManager, appWidgetIds);
        }
    }

    super.onReceive(context, intent);
}

From source file:com.pseudosudostudios.jdd.activities.GameActivity.java

private boolean loadFromBundle(Bundle state) {
    if (state == null)
        return false;
    Log.d("onCreateStuff", "Using bundle");
    Log.d("Loading", "Reading from bundle");
    // Reload the game after a screen rotation
    Tile.initPaints();/*  www  .ja v  a  2 s  .  com*/
    Tile[][] loadedTiles = new Tile[3][3];
    Tile[][] loadedSol = new Tile[3][3];
    for (int r = 0; r < bg.tiles.length; r++)
        for (int c = 0; c < bg.tiles[r].length; c++) {
            loadedTiles[r][c] = new Tile(this, state.getIntArray(onSaveBaseString + r + c));
            int[] arr = state.getIntArray(onSaveSolution + r + c);
            if (arr != null)
                loadedSol[r][c] = new Tile(this, arr);
        }
    int moves = state.getInt(onSaveMoves, 0);
    long time = state.getLong(onSaveTime, 0L);
    bg.setTileArray(loadedTiles, loadedSol, moves, time, state.getInt(jsonTileSize, 0));
    bg.setDifficulty(findDifficulty(state.getString(onSaveBaseString)));
    Grid.numberOfColors = state.getInt(bundleGameColors);
    bg.setCenterTile(new Tile(this, state.getIntArray(onSaveCeterTile)));
    Tile.initPaints();
    bg.invalidate();
    return true;
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void restoreFragmentsStack(Bundle savedInstanceState) {
    try {/*www  .j av a2s. c o  m*/
        int[] stack = savedInstanceState.getIntArray(FRAGMENTS_STACK_KEY);
        if (stack != null) {
            for (int id : stack) {
                fragmentsStack.push(id);
            }
        }
    } catch (Throwable ignored) {
    }
}