android.os.Bundle#getLongArray ( )源码实例Demo

下面列出了android.os.Bundle#getLongArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FairEmail   文件: StorageStrategy.java
@Override
public @Nullable Selection<Long> asSelection(@NonNull Bundle state) {
    String keyType = state.getString(SELECTION_KEY_TYPE, null);
    if (keyType == null || !keyType.equals(getKeyTypeName())) {
        return null;
    }

    @Nullable long[] stored = state.getLongArray(SELECTION_ENTRIES);
    if (stored == null) {
        return null;
    }

    Selection<Long> selection = new Selection<>();
    for (long key : stored) {
        selection.mSelection.add(key);
    }
    return selection;
}
 
源代码2 项目: SimpleDialogFragments   文件: SimpleColorDialog.java
@Override
protected Bundle onResult(int which) {
    Bundle b = super.onResult(which);
    int color = (int) b.getLong(SELECTED_SINGLE_ID);
    if (color == PICKER){
        b.putInt(COLOR, mCustomColor);
    } else {
        b.putInt(COLOR, color);
    }

    long[] ids = b.getLongArray(SELECTED_IDS);
    if (ids != null) {
        int[] colors = new int[ids.length];
        for (int i = 0; i < ids.length; i++) {
            if (ids[i] == PICKER) {
                colors[i] = mCustomColor;
            } else {
                colors[i] = (int) ids[i];
            }
        }
        b.putIntArray(COLORS, colors);
    }
    return b;
}
 
源代码3 项目: SimpleDialogFragments   文件: SimpleColorDialog.java
@Override
protected Bundle onResult(int which) {
    Bundle b = super.onResult(which);
    int color = (int) b.getLong(SELECTED_SINGLE_ID);
    if (color == PICKER){
        b.putInt(COLOR, mCustomColor);
    } else {
        b.putInt(COLOR, color);
    }

    long[] ids = b.getLongArray(SELECTED_IDS);
    if (ids != null) {
        int[] colors = new int[ids.length];
        for (int i = 0; i < ids.length; i++) {
            if (ids[i] == PICKER) {
                colors[i] = mCustomColor;
            } else {
                colors[i] = (int) ids[i];
            }
        }
        b.putIntArray(COLORS, colors);
    }
    return b;
}
 
源代码4 项目: talkback   文件: KeyComboPreference.java
@Override
@SuppressWarnings("argument.type.incompatible")
protected void onRestoreInstanceState(Parcelable state) {
  Bundle bundle = (Bundle) state;
  if (bundle.containsKey(KEY_KEY_COMBOS)) {
    // Read keyCombos from the bundle and update the list adapter.
    if (keyCombos == null) {
      keyCombos = new HashSet<>();
    } else {
      keyCombos.clear();
    }
    long[] keyComboArray = bundle.getLongArray(KEY_KEY_COMBOS);
    if (keyComboArray != null) {
      for (long keyCombo : keyComboArray) {
        keyCombos.add(keyCombo);
      }
    }
    KeyAssignmentUtils.updateKeyListAdapter(keyListAdapter, keyCombos, getContext());
  }

  super.onRestoreInstanceState(bundle.getParcelable(KEY_SUPER_STATE));
}
 
源代码5 项目: mOrgAnd   文件: OutlineListView.java
public void loadState(Bundle savedInstanceState) {
    long[] state = savedInstanceState.getLongArray(OUTLINE_NODES);
    ArrayList<Integer> levels = savedInstanceState.getIntegerArrayList(OUTLINE_LEVELS);
    boolean[] expanded = savedInstanceState.getBooleanArray(OUTLINE_EXPANDED);

    if(state != null) {
        try {
            this.adapter.setState(state, levels, expanded);
        } catch (IllegalStateException ex) {
            this.adapter.init();
        }
    }

    int checkedPos= savedInstanceState.getInt(OUTLINE_CHECKED_POS, 0);
    setItemChecked(checkedPos, true);

    int scrollPos = savedInstanceState.getInt(OUTLINE_SCROLL_POS, 0);
    setSelection(scrollPos);
}
 
源代码6 项目: Dainty   文件: UpdatableFragmentPagerAdapter.java
@Override
public void restoreState(@Nullable Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        long[] fss = bundle.getLongArray("states");
        mSavedStates.clear();
        mFragments.clear();
        if (fss != null) {
            for (long fs : fss) {
                mSavedStates.put(fs, (Fragment.SavedState) bundle.getParcelable(Long.toString(fs)));
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    f.setMenuVisibility(false);
                    mFragments.put(Long.parseLong(key.substring(1)), f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
源代码7 项目: revolution-irc   文件: ChatPagerAdapter.java
public void onRestoreInstanceState(Bundle bundle) {
    String[] keys = bundle.getStringArray("channel_ids_keys");
    long[] values = bundle.getLongArray("channel_ids_values");
    if (keys != null && values != null && keys.length == values.length) {
        for (int i = keys.length - 1; i >= 0; --i) {
            channelIds.put(keys[i], values[i]);
            nextChannelId = Math.max(nextChannelId, values[i] + 1);
        }
    }
    updateChannelList();
}
 
源代码8 项目: FireFiles   文件: MultiSelectionUtil.java
/**
 * This method should be called from your {@link AppCompatActivity} or
 * {@link android.support.v4.app.Fragment Fragment} to allow the controller to restore any
 * instance state.
 *
 * @param savedInstanceState - The state passed to your Activity or Fragment.
 */
public void restoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        long[] checkedIds = savedInstanceState.getLongArray(getStateKey());
        if (checkedIds != null && checkedIds.length > 0) {
            HashSet<Long> idsToCheckOnRestore = new HashSet<Long>();
            for (long id : checkedIds) {
                idsToCheckOnRestore.add(id);
            }
            tryRestoreInstanceState(idsToCheckOnRestore);
        }
    }
}
 
源代码9 项目: FireFiles   文件: MultiSelectionUtil.java
/**
 * This method should be called from your {@link AppCompatActivity} or
 * {@link android.support.v4.app.Fragment Fragment} to allow the controller to restore any
 * instance state.
 *
 * @param savedInstanceState - The state passed to your Activity or Fragment.
 */
public void restoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        long[] checkedIds = savedInstanceState.getLongArray(getStateKey());
        if (checkedIds != null && checkedIds.length > 0) {
            HashSet<Long> idsToCheckOnRestore = new HashSet<Long>();
            for (long id : checkedIds) {
                idsToCheckOnRestore.add(id);
            }
            tryRestoreInstanceState(idsToCheckOnRestore);
        }
    }
}
 
源代码10 项目: FireFiles   文件: MultiSelectionUtil.java
/**
 * This method should be called from your {@link AppCompatActivity} or
 * {@link android.support.v4.app.Fragment Fragment} to allow the controller to restore any
 * instance state.
 *
 * @param savedInstanceState - The state passed to your Activity or Fragment.
 */
public void restoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        long[] checkedIds = savedInstanceState.getLongArray(getStateKey());
        if (checkedIds != null && checkedIds.length > 0) {
            HashSet<Long> idsToCheckOnRestore = new HashSet<Long>();
            for (long id : checkedIds) {
                idsToCheckOnRestore.add(id);
            }
            tryRestoreInstanceState(idsToCheckOnRestore);
        }
    }
}
 
@Override
public void restoreState(@Nullable Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        long[] fss = bundle.getLongArray("states");
        mSavedStates.clear();
        mFragments.clear();
        if (fss != null) {
            for (long fs : fss) {
                mSavedStates.put(fs, (Fragment.SavedState) bundle.getParcelable(Long.toString(fs)));
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    f.setMenuVisibility(false);
                    mFragments.put(Long.parseLong(key.substring(1)), f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
源代码12 项目: RecyclerViewExtensions   文件: Selector.java
public void onRestoreInstanceState(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        long[] selectedIds = savedInstanceState.getLongArray(KEY_SELECTOR_SELECTED_IDS);
        if (selectedIds != null) {
            mNotifyItemChanges = false;
            for (long selectedId : selectedIds) {
                setSelected(selectedId, true);
            }
            mNotifyItemChanges = true;
        }
    }
}
 
public void restoreSelectionFromSavedInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        return;
    }
    long[] array = savedInstanceState.getLongArray(BUNDLE_KEY);
    checkedItems.clear();
    if (array != null) {
        for (long id : array) {
            checkedItems.add(id);
        }
    }
}
 
源代码14 项目: android-state   文件: InjectionHelper.java
public long[] getLongArray(Bundle state, String key) {
    return state.getLongArray(key + mBaseKey);
}
 
源代码15 项目: mobile-manager-tool   文件: PlaylistDialog.java
@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(new LinearLayout(this));

    action = getIntent().getAction();

    mRenameId = icicle != null ? icicle.getLong(INTENT_KEY_RENAME) : getIntent().getLongExtra(
            INTENT_KEY_RENAME, -1);
    mList = icicle != null ? icicle.getLongArray(INTENT_PLAYLIST_LIST) : getIntent()
            .getLongArrayExtra(INTENT_PLAYLIST_LIST);
    if (INTENT_RENAME_PLAYLIST.equals(action)) {
        mOriginalName = nameForId(mRenameId);
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME)
                : mOriginalName;
    } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME)
                : makePlaylistName();
        mOriginalName = mDefaultName;
    }

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    mPlaylistDialog = new AlertDialog.Builder(this).create();
    mPlaylistDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (action != null && mRenameId >= 0 && mOriginalName != null || mDefaultName != null) {

        mPlaylist = new EditText(this);
        mPlaylist.setSingleLine(true);
        mPlaylist.setText(mDefaultName);
        mPlaylist.setSelection(mDefaultName.length());
        mPlaylist.addTextChangedListener(this);

        mPlaylistDialog.setIcon(android.R.drawable.ic_dialog_info);
        String promptformat;
        String prompt = "";
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.rename_playlist);
            prompt = String.format(promptformat, mOriginalName, mDefaultName);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.new_playlist);
            prompt = String.format(promptformat, mDefaultName);
        }

        mPlaylistDialog.setTitle(prompt);
        mPlaylistDialog.setView(mPlaylist, (int)(8 * dm.density), (int)(8 * dm.density),
                (int)(8 * dm.density), (int)(4 * dm.density));
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mRenamePlaylistListener);
            mPlaylistDialog.setOnShowListener(this);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mCreatePlaylistListener);
        }
        mPlaylistDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                    }
                });
        mPlaylistDialog.setOnCancelListener(this);
        mPlaylistDialog.show();
    } else {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
        finish();
    }

}
 
/**
 * OpenAPIParser#parse(String) に testEnum.json を渡して解析を行う。
 * 
 * parameter の type と異なる enum の宣言が存在する testEnum.json をよみこむ。
 * <pre>
 * 【期待する動作】
 * ・Swagger オブジェクトが取得できること。
 * ・parameter の enum が取得できること。
 * </pre>
 */
@Test
public void testEnum() throws JSONException {
    DevicePluginContext pluginContext = Mockito.mock(DevicePluginContext.class);

    String jsonString = FileLoader.readString("parser/testEnum.json");

    DConnectServiceSpec spec = new DConnectServiceSpec(pluginContext);
    spec.addProfileSpec("testEnum", jsonString);

    Bundle swagger = spec.findProfileSpec("testEnum").toBundle();
    assertThat(swagger, is(notNullValue()));

    Bundle paths = swagger.getBundle("paths");
    assertThat(paths, is(notNullValue()));
    assertThat(paths.size(), is(1));

    Bundle a0 = paths.getBundle("/a0");
    assertThat(a0, is(notNullValue()));

    Bundle a0Get = a0.getBundle("get");
    assertThat(a0Get, is(notNullValue()));

    Parcelable[] parameters = a0Get.getParcelableArray("parameters");
    assertThat(parameters, is(notNullValue()));
    assertThat(parameters.length, is(7));

    Bundle stringInt = (Bundle) parameters[1];
    assertThat(stringInt.getString("type"), is("string"));
    String[] stringIntEnum = stringInt.getStringArray("enum");
    assertThat(stringIntEnum, is(notNullValue()));
    assertThat(stringIntEnum[0], is("1"));
    assertThat(stringIntEnum[1], is("2"));
    assertThat(stringIntEnum[2], is("3"));
    assertThat(stringIntEnum[3], is("4"));

    Bundle stringNumber = (Bundle) parameters[2];
    assertThat(stringNumber.getString("type"), is("string"));
    String[] stringNumberEnum = stringNumber.getStringArray("enum");
    assertThat(stringNumberEnum, is(notNullValue()));
    assertThat(stringNumberEnum[0], is("1.1"));
    assertThat(stringNumberEnum[1], is("2.2"));
    assertThat(stringNumberEnum[2], is("3.3"));
    assertThat(stringNumberEnum[3], is("4.4"));

    Bundle intString = (Bundle) parameters[3];
    assertThat(intString.getString("type"), is("integer"));
    assertThat(intString.getString("format"), is("int32"));
    int[] intStringEnum = intString.getIntArray("enum");
    assertThat(intStringEnum, is(notNullValue()));
    assertThat(intStringEnum[0], is(1));
    assertThat(intStringEnum[1], is(2));
    assertThat(intStringEnum[2], is(3));
    assertThat(intStringEnum[3], is(4));

    Bundle longString = (Bundle) parameters[4];
    assertThat(longString.getString("type"), is("integer"));
    assertThat(longString.getString("format"), is("int64"));
    long[] longStringEnum = longString.getLongArray("enum");
    assertThat(longStringEnum, is(notNullValue()));
    assertThat(longStringEnum[0], is(1L));
    assertThat(longStringEnum[1], is(2L));
    assertThat(longStringEnum[2], is(3L));
    assertThat(longStringEnum[3], is(4L));

    Bundle floatString = (Bundle) parameters[5];
    assertThat(floatString.getString("type"), is("number"));
    assertThat(floatString.getString("format"), is("float"));
    float[] floatStringEnum = floatString.getFloatArray("enum");
    assertThat(floatStringEnum, is(notNullValue()));
    assertThat(floatStringEnum[0], is(1.1F));
    assertThat(floatStringEnum[1], is(2.2F));
    assertThat(floatStringEnum[2], is(3.3F));
    assertThat(floatStringEnum[3], is(4.4F));

    Bundle doubleString = (Bundle) parameters[6];
    assertThat(doubleString.getString("type"), is("number"));
    assertThat(doubleString.getString("format"), is("double"));
    double[] doubleStringEnum = doubleString.getDoubleArray("enum");
    assertThat(doubleStringEnum, is(notNullValue()));
    assertThat(doubleStringEnum[0], is(1.1D));
    assertThat(doubleStringEnum[1], is(2.2D));
    assertThat(doubleStringEnum[2], is(3.3D));
    assertThat(doubleStringEnum[3], is(4.4D));
}
 
源代码17 项目: cathode   文件: CommentsAdapter.java
public void restoreState(Bundle state) {
  long[] revealed = state.getLongArray(STATE_REVEALED_SPOILERS);
  for (long id : revealed) {
    revealedSpoilers.add(id);
  }
}