private Builder setSingleChoiceMode(Builder builder, String[] choices) { // 選択された選択肢を保存しておく配列を作成し,argumentsに入れておく // 生成時に受け取っている場合は不要 Bundle args = getArguments(); if (!args.containsKey(CHOSEN) || args.getBooleanArray(CHOSEN) == null) { boolean[] checked = new boolean[choices.length]; args.putBooleanArray(CHOSEN, checked); } boolean[] checked = args.getBooleanArray(CHOSEN); int chosenItem; for (chosenItem = 0; chosenItem < checked.length; chosenItem++) { if (checked[chosenItem]) break; } builder.setSingleChoiceItems( choices, chosenItem, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Bundle args = getArguments(); boolean[] checked = args.getBooleanArray(CHOSEN); for (int i = 0; i < checked.length; i++) { checked[i] = (i == which); // 選ばれたもの以外すべてfalseにする } args.putBooleanArray(CHOSEN, checked); } }); return builder; }
@Override public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.panes_layout); panesLayout = (PanesLayout) findViewById(R.id.panes); panesLayout.setOnIndexChangedListener(this); if (savedInstanceState != null) { int[] panesType = savedInstanceState.getIntArray("PanesLayout_panesType"); boolean[] panesFocused = savedInstanceState.getBooleanArray("PanesLayout_panesFocused"); int currentIndex = savedInstanceState.getInt("PanesLayout_currentIndex"); for (int i = 0; i < panesType.length; i++) { panesLayout.addPane(panesType[i], panesFocused[i]); } panesLayout.setIndex(currentIndex); } if (savedInstanceState != null) { FragmentManager fm = getSupportFragmentManager(); for (int index = 0; index < panesLayout.getNumPanes(); index++) { int id = panesLayout.getPane(index).getInnerId(); Fragment f = fm.findFragmentById(id); fragmentStack.add(f); updateFragment(f); } } }
private void saveMyPreferences() { // Log.e(TAG, "Save Preferences Fired"); Context context = getApplicationContext(); Bundle myBundle = ((AndroiDAQTCPAdapter) pager.getAdapter()).getUIStates(); boolean[] isOutputCh = myBundle.getBooleanArray("isInput"); boolean[] isDigCh = myBundle.getBooleanArray("isDig"); boolean[] outputState = myBundle.getBooleanArray("outputState"); String[] desiredFreq = myBundle.getStringArray("desiredFreqs"); String[] desiredDuty = myBundle.getStringArray("desiredDutys"); saveBooleanArray(isOutputCh, "isInput", context); saveBooleanArray(isDigCh, "isDig", context); saveBooleanArray(outputState, "outputState", context); saveStringArray(desiredFreq, "desiredFreqs", context); saveStringArray(desiredDuty, "desiredDutys", context); /*Example mEditor.putInt("setTime", countSecs); mEditor.putBoolean("timeSet", timeIsSet); mEditor.putString("project", project); mEditor.commit(); */ }
private Builder setMutlipleChoiceMode(Builder builder, String[] choices) { // 選択された選択肢を保存しておく配列を作成し,argumentsに入れておく // 生成時に受け取っている場合は不要 Bundle args = getArguments(); if (!args.containsKey(CHOSEN) || args.getBooleanArray(CHOSEN) == null) { boolean[] checked = new boolean[choices.length]; args.putBooleanArray(CHOSEN, checked); } builder.setMultiChoiceItems( choices, args.getBooleanArray(CHOSEN), new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { Bundle args = getArguments(); boolean[] checked = args.getBooleanArray(CHOSEN); checked[which] = isChecked; args.putBooleanArray(CHOSEN, checked); } }); return builder; }
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { // Restoration of title field if (savedInstanceState.containsKey(STATE_TITLE)) { String title = savedInstanceState.getString(STATE_TITLE); titleEditText.setText(title); } // Restoration of description field if (savedInstanceState.containsKey(STATE_DESCRIPTION)) { String description = savedInstanceState.getString(STATE_DESCRIPTION); descriptionEditText.setText(description); } // Restoration of time field if (savedInstanceState.containsKey(STATE_TIME_HOUR) && savedInstanceState.containsKey(STATE_TIME_MINUTES)) { int hour = savedInstanceState.getInt(STATE_TIME_HOUR); int minutes = savedInstanceState.getInt(STATE_TIME_MINUTES); time = new Pair(hour, minutes); setTime(hour, minutes); if (timePicker == null) { setTimePicker(hour, minutes); } else { timePicker.updateTime(hour, minutes); } } // Restoration of week days field if (savedInstanceState.containsKey(STATE_WEEK_DAYS)) { weekDays = savedInstanceState.getBooleanArray(STATE_WEEK_DAYS); if (weekDays != null) { for (int i = 0; i < weekDays.length; i++) { LinearLayout dayLayout = getDayLayout(i); if (weekDays[i]) { activateDay(i, dayLayout, false); } else { deactivateDay(i, dayLayout, false); } } } } // The call to super method must be at the end here super.onRestoreInstanceState(savedInstanceState); }
@Override protected void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; mBitmapAlpha = bundle.getFloatArray(STATUS_ALPHAS); mMessageNumber = bundle.getIntArray(STATUS_MESSAGENUMBER); mNews = bundle.getBooleanArray(STATUS_NEWS); for (int i = 0; i < mBitmapAlpha.length; i++) { mTabstrips.get(i).setBitmapAlpha(mBitmapAlpha[i]); mTabstrips.get(i).setNews(mNews[i]); mTabstrips.get(i).setMessageNumber(mMessageNumber[i]); } super.onRestoreInstanceState(bundle.getParcelable(INSTANCE_STATUS)); return; } super.onRestoreInstanceState(state); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); folders = extras.getStringArray("folders"); boolean[] checked = extras.getBooleanArray("checked"); setContentView(R.layout.folders); foldersView = (ListView) findViewById(R.id.foldersView); foldersView.setOnItemClickListener(onFoldersViewClick); foldersView.setItemsCanFocus(false); foldersView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); foldersView.setAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, folders)); for (int i = 0; i < checked.length; ++i) { foldersView.setItemChecked(i, checked[i]); } }
@SmallTest @MediumTest @LargeTest public void testAllTypes() { Bundle originalBundle = new Bundle(); putBoolean(BOOLEAN_KEY, originalBundle); putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle); putByte(BYTE_KEY, originalBundle); putByteArray(BYTE_ARRAY_KEY, originalBundle); putShort(SHORT_KEY, originalBundle); putShortArray(SHORT_ARRAY_KEY, originalBundle); putInt(INT_KEY, originalBundle); putIntArray(INT_ARRAY_KEY, originalBundle); putLong(LONG_KEY, originalBundle); putLongArray(LONG_ARRAY_KEY, originalBundle); putFloat(FLOAT_KEY, originalBundle); putFloatArray(FLOAT_ARRAY_KEY, originalBundle); putDouble(DOUBLE_KEY, originalBundle); putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle); putChar(CHAR_KEY, originalBundle); putCharArray(CHAR_ARRAY_KEY, originalBundle); putString(STRING_KEY, originalBundle); putStringList(STRING_LIST_KEY, originalBundle); originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB); ensureApplicationContext(); SharedPreferencesTokenCachingStrategy cache = new SharedPreferencesTokenCachingStrategy(getContext()); cache.save(originalBundle); SharedPreferencesTokenCachingStrategy cache2 = new SharedPreferencesTokenCachingStrategy(getContext()); Bundle cachedBundle = cache2.load(); Assert.assertEquals( originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY)); assertArrayEquals( originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY), cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY)); Assert.assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY)); assertArrayEquals( originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY)); Assert.assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY)); assertArrayEquals( originalBundle.getShortArray(SHORT_ARRAY_KEY), cachedBundle.getShortArray(SHORT_ARRAY_KEY)); Assert.assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY)); assertArrayEquals( originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY)); Assert.assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY)); assertArrayEquals( originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY)); Assert.assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY)); assertArrayEquals( originalBundle.getFloatArray(FLOAT_ARRAY_KEY), cachedBundle.getFloatArray(FLOAT_ARRAY_KEY)); Assert.assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY)); assertArrayEquals( originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY), cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY)); Assert.assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY)); assertArrayEquals( originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY)); Assert.assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY)); assertListEquals( originalBundle.getStringArrayList(STRING_LIST_KEY), cachedBundle.getStringArrayList(STRING_LIST_KEY)); Assert.assertEquals( originalBundle.getSerializable(SERIALIZABLE_KEY), cachedBundle.getSerializable(SERIALIZABLE_KEY)); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_day, container, false); // Retrieve Data Bundle getBundle = getArguments(); int dayCountMax = dayCount + 125; editableCells = Arrays.copyOfRange(getBundle.getBooleanArray("editableCells"), dayCount, dayCountMax); editableHours = Arrays.copyOfRange(getBundle.getBooleanArray("editableHours"), dayCount, dayCountMax); items = Arrays.copyOfRange(getBundle.getStringArray("items"), dayCount, dayCountMax); textColor = Arrays.copyOfRange(getBundle.getIntArray("textColor"), dayCount, dayCountMax); backgroundColor = Arrays.copyOfRange(getBundle.getIntArray("backgroundColor"), dayCount, dayCountMax); textBold = Arrays.copyOfRange(getBundle.getBooleanArray("textBold"), dayCount, dayCountMax); // Set GridView gridView = (GridView) rootView.findViewById(R.id.gridView); gridView.setAdapter( new gridView_adapter(getContext(), items, textColor, backgroundColor, textBold)); // Set on Item Click Listener for the GridView gridView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (editableCells[position] || editableHours[position]) { View editedView = new changeTextValues().getItemViewIfVisible(parent, position); int x = position + dayCount; new changeTextValues() .changeText( getContext(), parent, editedView, x, position, items, textColor, backgroundColor, textBold, editableHours); } } }); // Set on Drag gridView.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick( AdapterView<?> parent, View dragView, int dragPosition, long id) { if (editableCells[dragPosition]) { ClipData data = ClipData.newPlainText("", ""); View.DragShadowBuilder itemShadow = new View.DragShadowBuilder(dragView); dragView.startDrag(data, itemShadow, dragView, 0); for (int dropPosition = parent.getFirstVisiblePosition(); dropPosition <= parent.getLastVisiblePosition(); dropPosition++) { if (editableCells[dropPosition] || editableHours[dropPosition]) { dropView[dropPosition] = new changeTextValues().getItemViewIfVisible(parent, dropPosition); dropView[dropPosition].setOnDragListener( new myDragListener( parent, getContext(), items, textColor, backgroundColor, textBold, editableCells, editableHours, dragPosition, dropPosition, dayCount)); } } return true; } else return false; } }); return rootView; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** Restore from the previous state if exists */ if (savedInstanceState != null) { status = savedInstanceState.getBooleanArray("status"); } ListView lvCountries = (ListView) findViewById(R.id.lv_countries); OnItemClickListener itemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> lv, View item, int position, long id) { ListView lView = (ListView) lv; SimpleAdapter adapter = (SimpleAdapter) lView.getAdapter(); HashMap<String, Object> hm = (HashMap) adapter.getItem(position); /** The clicked Item in the ListView */ RelativeLayout rLayout = (RelativeLayout) item; /** Getting the toggle button corresponding to the clicked item */ ToggleButton tgl = (ToggleButton) rLayout.getChildAt(1); String strStatus = ""; if (tgl.isChecked()) { tgl.setChecked(false); strStatus = "Off"; status[position] = false; } else { tgl.setChecked(true); strStatus = "On"; status[position] = true; } Toast.makeText( getBaseContext(), (String) hm.get("txt") + " : " + strStatus, Toast.LENGTH_SHORT) .show(); } }; lvCountries.setOnItemClickListener(itemClickListener); // Each row in the list stores country name and its status List<HashMap<String, Object>> aList = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < 10; i++) { HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put("txt", countries[i]); hm.put("stat", status[i]); aList.add(hm); } // Keys used in Hashmap String[] from = {"txt", "stat"}; // Ids of views in listview_layout int[] to = {R.id.tv_item, R.id.tgl_status}; // Instantiating an adapter to store each items // R.layout.listview_layout defines the layout of each item SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.lv_layout, from, to); lvCountries.setAdapter(adapter); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate(Bundle) called"); setContentView(R.layout.activity_quiz); Log.d(TAG, "La versión del SDK actual es: " + Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar actionBar = getActionBar(); actionBar.setSubtitle("Bodies of Water"); } mTrueButton = (Button) findViewById(R.id.true_button); mTrueButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "Botón TRUE clickeado..."); checkAnswer(true); } }); mFalseButton = (Button) findViewById(R.id.false_button); mFalseButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "Botón FALSE clickeado..."); checkAnswer(false); } }); mQuestionTextView = (TextView) findViewById(R.id.question_text_view); mQuestionTextView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { updateQuestion(true); } }); mNextButton = (ImageButton) findViewById(R.id.next_button); mNextButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // mIsCheater = false; updateQuestion(true); } }); mPrevButton = (ImageButton) findViewById(R.id.prev_button); mPrevButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { updateQuestion(false); } }); mCheatButton = (Button) findViewById(R.id.cheat_button); mCheatButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { Log.d(TAG, "Presionando botón Cheat"); Intent i = new Intent(QuizActivity.this, CheatActivity.class); boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion(); i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, answerIsTrue); i.putExtra(CURRENT_INDEX, mCurrentIndex); startActivityForResult(i, 0); } }); if (savedInstanceState != null) { Log.d(TAG, "Ya había un valor guardado, recuperando"); mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0); // mIsCheater = savedInstanceState.getBoolean(KEY_IS_CHEATER, false); mCheatedQuestionsBank = savedInstanceState.getBooleanArray(CHEATED_VALUES); Log.d(TAG, "mCheatedQuestionsBank: " + mCheatedQuestionsBank); mCheatedQuestionsBank[mCurrentIndex] = false; // On Rotate, clears "I'm a cheater DATA" mNextButton.setEnabled(true); mPrevButton.setEnabled(true); } updateQuestion(null); }
/** * Retrieve extended data from the request. * * @param name The name of the desired item. * @return the value of an item that previously added with putExtra() or null if no boolean array * value was found. * @see #putExtra(String, boolean[]) */ public boolean[] getBooleanArrayExtra(String name) { return mExtras == null ? null : mExtras.getBooleanArray(name); }
@TargetApi(11) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate(Bundle) called"); setContentView(R.layout.activity_quiz); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { android.app.ActionBar actionBar = getActionBar(); actionBar.setSubtitle("Bodies of Water"); } if (savedInstanceState != null) { mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0); mIsCheater = savedInstanceState.getBooleanArray(KEY_CHEATER); } mQuestionTextView = (TextView) findViewById(R.id.question_text_view); mTrueButton = (Button) findViewById(R.id.true_button); mTrueButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { checkAnswer(true); } }); mFalseButton = (Button) findViewById(R.id.false_button); mFalseButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { checkAnswer(false); } }); mNextButton = (Button) findViewById(R.id.next_button); mNextButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length; updateQuestion(); } }); mPrevButton = (Button) findViewById(R.id.prev_button); mPrevButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mCurrentIndex = (mQuestionBank.length + mCurrentIndex - 1) % mQuestionBank.length; updateQuestion(); } }); mQuestionTextView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length; updateQuestion(); // TODO Auto-generated method stub } }); mCheateButton = (Button) findViewById(R.id.cheat_button); mCheateButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(QuizActivity.this, CheatActivity.class); boolean IsCheated = mIsCheater[mCurrentIndex]; System.out.println(IsCheated); boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion(); i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, new boolean[] {answerIsTrue, IsCheated}); // (CheatActivity.EXTRA_ANSWER_IS_TRUE, answerIsTrue); startActivityForResult(i, 0); // Intent j =new Intent(QuizActivity.this,CheatActivity.class); // boolean IsCheated = mIsCheater[mCurrentIndex]; // j.putExtra(name, value)(CheatActivity.EXTRA_HAS_CHEATED, IsCheated); // startActivityForResult(j, 0); // startActivity(i); // TODO Auto-generated method stub } }); updateQuestion(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupDrawer(); setDrawerIndicatorEnabled(false); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); boolean isLoggedIn = LoginHelper.getInstance(this).isLoggedIn(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment fragment = new MainFragmentWeb(); Bundle args = getIntent().getExtras(); Uri.Builder builder = Uri.parse(isLoggedIn ? Constant.BASE_URL_EX : Constant.BASE_URL).buildUpon(); boolean[] filter = args.getBooleanArray(EXTRA_FILTER); for (int i = 0; i < filter.length; i++) { String param = filter[i] ? "1" : "0"; switch (i) { case 0: builder.appendQueryParameter("f_doujinshi", param); break; case 1: builder.appendQueryParameter("f_manga", param); break; case 2: builder.appendQueryParameter("f_artistcg", param); break; case 3: builder.appendQueryParameter("f_gamecg", param); break; case 4: builder.appendQueryParameter("f_western", param); break; case 5: builder.appendQueryParameter("f_non-h", param); break; case 6: builder.appendQueryParameter("f_imageset", param); break; case 7: builder.appendQueryParameter("f_cosplay", param); break; case 8: builder.appendQueryParameter("f_asianporn", param); break; case 9: builder.appendQueryParameter("f_misc", param); break; } } builder.appendQueryParameter("f_apply", "Apply Filter"); args.putString(MainFragmentWeb.EXTRA_BASE, builder.build().toString()); fragment.setArguments(args); ft.replace(R.id.container, fragment); ft.commit(); setupAd(); }