private void loadLanguages() { mLocaleAdapter = com.android.internal.app.LocalePicker.constructAdapter( getActivity(), R.layout.locale_picker_item, R.id.locale); mInitialLocale = Locale.getDefault(); mCurrentLocale = mInitialLocale; mAdapterIndices = new int[mLocaleAdapter.getCount()]; int currentLocaleIndex = 0; String[] labels = new String[mLocaleAdapter.getCount()]; for (int i = 0; i < mAdapterIndices.length; i++) { com.android.internal.app.LocalePicker.LocaleInfo localLocaleInfo = mLocaleAdapter.getItem(i); Locale localLocale = localLocaleInfo.getLocale(); if (localLocale.equals(mCurrentLocale)) { currentLocaleIndex = i; } mAdapterIndices[i] = i; labels[i] = localLocaleInfo.getLabel(); } mLanguagePicker.setDisplayedValues(labels); mLanguagePicker.setMaxValue(labels.length - 1); mLanguagePicker.setValue(currentLocaleIndex); mLanguagePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mLanguagePicker.setOnValueChangedListener( new LocalePicker.OnValueChangeListener() { public void onValueChange(LocalePicker picker, int oldVal, int newVal) { setLocaleFromPicker(); } }); }
public void handleMessage(android.os.Message msg) { switch (msg.what) { case MSG_INIT_OK: ArrayAdapter<LogItem> adapter = (ArrayAdapter<LogItem>) getListView().getAdapter(); adapter.setNotifyOnChange(false); adapter.clear(); ArrayList<LogItem> data = (ArrayList<LogItem>) msg.obj; if (data != null) { for (int i = 0, size = data.size(); i < size; i++) { adapter.add(data.get(i)); } } adapter.notifyDataSetChanged(); sendEmptyMessage(MSG_DISMISS_PROGRESS); if (adapter.getCount() == 0) { Util.shortToast(LogViewer.this, R.string.no_log_info); } else { getListView().setSelection(adapter.getCount() - 1); } break; case MSG_CONTENT_READY: sendEmptyMessage(MSG_DISMISS_PROGRESS); Util.handleMsgSendContentReady( (String) msg.obj, "Android Device Log - ", //$NON-NLS-1$ LogViewer.this, msg.arg2 == 1); break; case MSG_CHECK_FORCE_COMPRESSION: sendEmptyMessage(MSG_DISMISS_PROGRESS); Util.checkForceCompression( this, LogViewer.this, (String) msg.obj, msg.arg1, "android_log"); // $NON-NLS-1$ break; case MSG_DISMISS_PROGRESS: if (progress != null) { progress.dismiss(); progress = null; } break; case MSG_TOAST: Util.shortToast(LogViewer.this, (String) msg.obj); break; } };
@Override public Object[] getSections() { String[] sectionHeaders = new String[headers.getCount()]; for (int i = 0; i < headers.getCount(); i++) { sectionHeaders[i] = headers.getItem(i); } return sectionHeaders; }
/** * Parses the result from JSON and then displays the list of results * * @param results A list containing the results title * @param results2 Beans of the items */ private void parseAndDisplayResult(ArrayAdapter<String> results, final List<MapItem> results2) { if (results != null && results.getCount() == 1 && results2 != null && results2.size() > 0) { startMapActivity(results2.get(0)); finish(); } ListView lv = getListView(); lv.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (results2 != null && results2.size() > 0) { try { MapItem meb = results2.get(position); startMapActivity(meb); } catch (Exception e) { } } } }); mLayout.hideText(); setListAdapter(results); }
@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Utils.Log("MessageFragment onCreateView called"); View view = inflater.inflate(R.layout.fragment_messages, container, false); messageList = (ListView) view.findViewById(R.id.messages_list); messages = dbManager.getMessages(conversation.getUsername()); adapter = new MessagesAdapter( getActivity(), messages, dbManager.getUsername(), conversation.getUsername(), conversationPass); messageList.setAdapter(adapter); messageList.setOnItemLongClickListener(messageLongClicked); if (savedInstanceState == null) { messageList.setSelection(adapter.getCount() - 6); } sendMessage = (Button) view.findViewById(R.id.btn_message_send); sendMessage.setOnClickListener(sendClicked); messageText = (MaterialEditText) view.findViewById(R.id.user_message_text); return view; }
@UiThreadTest public void testMakeTweet() { LonelyTwitterActivity lta = (LonelyTwitterActivity) getActivity(); int oldLength = lta.getAdapter().getCount(); makeTweet("test string"); ArrayAdapter<Tweet> arrayAdapter = lta.getAdapter(); assertEquals(oldLength + 1, arrayAdapter.getCount()); assertTrue( "Did you add a Tweet object?", arrayAdapter.getItem(arrayAdapter.getCount() - 1) instanceof Tweet); Tweet tweet = arrayAdapter.getItem(arrayAdapter.getCount() - 1); assertEquals("This is not the text we expected!", tweet.getMessage(), "test string"); }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // 查找到设备action if (BluetoothDevice.ACTION_FOUND.equals(action)) { // 得到蓝牙设备 BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // 如果是已配对的则略过,已得到显示,其余的在添加到列表中进行显示 if (device.getBondState() != BluetoothDevice.BOND_BONDED) { mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } else { // 添加到已配对设备列表 mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); // mPairedDevicesArrayAdapter.add(mBtAdapter.getRemoteDevice(device.getAddress()).getName() + "\n" + device.getAddress()); } // 搜索完成action } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { setProgressBarIndeterminateVisibility(false); setTitle(getResources().getString(R.string.select)); if (mNewDevicesArrayAdapter.getCount() == 0) { String noDevices = getResources().getString(R.string.nonewdevice); mNewDevicesArrayAdapter.add(noDevices); } } }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position; if (position >= adapter.getCount() || adapter.getItem(position).getResult() != null) { menu.add(Menu.NONE, position, position, RHelper.getString("history_clear_one_history_text")); } // else it's just that dummy "Empty" message }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); Short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE); mNewDevicesArrayAdapter.add( device.getName() + "\n" + "RSSI = " + rssi + "\n" + device.getAddress()); // log for test if (device.getName().equals("Zhenan")) { DataLogger dl = new DataLogger(device.getName(), device.getAddress(), rssi.intValue()); } // When discovery is finished, change the Activity title } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { setProgressBarIndeterminateVisibility(false); setTitle(R.string.scan_finish); if (mNewDevicesArrayAdapter.getCount() == 0) { String noDevices = getResources().getText(R.string.none_found).toString(); mNewDevicesArrayAdapter.add(noDevices); } } }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // If it's already paired, skip it, because it's been listed // already if (device.getBondState() != BluetoothDevice.BOND_BONDED) { mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); // if (lastAdress.compareTo(device.getAddress())==0) // { setAndReturn(device.getAddress()); // } } // When discovery is finished, change the Activity title } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { setProgressBarIndeterminateVisibility(false); setTitle(R.string.select_device); if (mNewDevicesArrayAdapter.getCount() == 0) { String noDevices = getResources().getText(R.string.none_found).toString(); mNewDevicesArrayAdapter.add(noDevices); } } }
@Override public void onClick(View v) { View rootView = v.getRootView(); EditText textToAdd = (EditText) rootView.findViewById(R.id.text_to_add); ListView groceryList = (ListView) rootView.findViewById(R.id.grocery_list); ArrayAdapter<String> groceryAdapter = (ArrayAdapter<String>) groceryList.getAdapter(); String groceryItem = textToAdd.getText().toString(); if (groceryItem.length() != 0) { groceryAdapter.add(groceryItem); dbService.writeToDatabase(groceryItem, groceryAdapter.getCount()); groceryAdapter.notifyDataSetChanged(); textToAdd.setText(""); } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder .setTitle("Groceries must not be blank") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ; AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }
private void createSubAssunto(int idAssunto) { SubAssunto subAssunto = new SubAssunto(idAssunto); ArrayAdapter<Assunto> adapter = getAssuntosAdapterByAssuntoPai(idAssunto); if (adapter.getCount() == 0) { Toast.makeText( this, R.string.acompanhamento_estudos_assunto_doesnt_contains_subassuntos, Toast.LENGTH_LONG) .show(); return; } LinearLayout rootLinearLayout = (LinearLayout) findViewById(R.id.acompanhamento_estudos_linlyt_subassuntos); subAssunto.layoutContainer = new LinearLayout(this); subAssunto.layoutContainer.setOrientation(LinearLayout.HORIZONTAL); rootLinearLayout.addView(subAssunto.layoutContainer); subAssunto.spnSubAssuntos = new Spinner(this); subAssunto.spnSubAssuntos.setId(View.generateViewId()); subAssunto.spnSubAssuntos.setAdapter(adapter); subAssunto.spnSubAssuntos.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { int startingIndexKey = calcularIndiceParaLimparSubAssuntos((Assunto) adapterView.getSelectedItem()); clearSubAssuntos(startingIndexKey); } @Override public void onNothingSelected(AdapterView<?> adapterView) {} }); subAssunto.spnSubAssuntos.setLayoutParams( new LinearLayout.LayoutParams(390, LinearLayout.LayoutParams.WRAP_CONTENT)); subAssunto.layoutContainer.addView(subAssunto.spnSubAssuntos); subAssunto.btnExpandirSubAssuntos = new ImageButton(this); subAssunto.btnExpandirSubAssuntos.setImageResource(R.drawable.arrow_combo); subAssunto.btnExpandirSubAssuntos.setBackgroundColor(Color.TRANSPARENT); final int dicPosAssuntoToExpand = dicIdxAndIdSubAssuntos.size(); subAssunto.btnExpandirSubAssuntos.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { SubAssunto correspondingSubAssunto = (SubAssunto) dicIdxAndIdSubAssuntos.get(dicPosAssuntoToExpand); int selectedId = ((Assunto) correspondingSubAssunto.spnSubAssuntos.getSelectedItem()).getId(); createSubAssunto(selectedId); } }); subAssunto.btnExpandirSubAssuntos.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); subAssunto.layoutContainer.addView(subAssunto.btnExpandirSubAssuntos); dicIdxAndIdSubAssuntos.put(dicIdxAndIdSubAssuntos.size(), subAssunto); }
protected void b(String s, int i) { boolean flag = true; nz.b( "ToolboxListActivity", (new StringBuilder()).append("package changed: ").append(s).toString()); int j = b.getCount(); int k = 0; do { ou ou1; label0: { if (k < j) { ou1 = (ou) b.getItem(k); if (ou1 != null) { break label0; } } return; } if (s.equals(ou1.f)) { if (i != flag) { flag = false; } ou1.t = flag; b.notifyDataSetChanged(); return; } k++; } while (true); }
/** UPDATE GRAPH WITH SELECTED when results are returned */ private void updateGraphWithSelected(String results) { ndb = new NutritionDatabaseHelper(this); if (selectedItems != null || quantities != null) { selectedItems.clear(); quantities.clear(); } else { selectedItems = new ArrayList<Item>(); quantities = new ArrayList<Integer>(); } int position = -1; for (int i = 0; i < ccartList.getCount(); i++) { String tempItemName = ccartList.getItem(i); int pos = tempItemName.indexOf(" "); String compare = tempItemName.substring(pos + 1); if (compare.equals(results)) { position = i; break; } else { continue; } } Item selectedItem = ndb.getItem(results); ndb.close(); selectedItems.add(selectedItem); String itemOne; if (selectedItems.get(0).getItemName().length() > 20) { itemOne = selectedItems.get(0).getItemName().substring(0, 20) + "..."; } else { itemOne = selectedItems.get(0).getItemName(); } String one = "<font color='#7EAD1A'>" + itemOne + "</font> SELECTED"; added.setText(Html.fromHtml(one)); for (GroceryItem gItem : ccart) { if (gItem.getItemName().equals(results)) { quantities.add(gItem.getQuantity()); Log.d("CartActivity: ", "Name: " + gItem.getItemName() + quantities.get(0)); } } Log.d("CartActivity", "Position: " + position); sd_list.setItemChecked(position, true); graph.passSelectedItems(selectedItems); graph.passSelectedQuantities(quantities); graph.postInvalidate(); graphLabels.setDays(days); graphLabels.postInvalidate(); }
private String waypointsToString(ArrayAdapter<RouteEditorActivity.Waypoint> waypoints) { StringBuilder builder = new StringBuilder(); for (int i = 1; i < waypoints.getCount() - 1; i++) { builder.append(positionToString(waypoints.getItem(i).getMarkerOptions().getPosition())); builder.append("|"); } return builder.toString(); }
/** @return Actual selected groups from adapter. */ public ArrayList<String> getSelected() { ArrayList<String> groups = new ArrayList<>(); for (int position = 0; position < arrayAdapter.getCount(); position++) if (listView.isItemChecked(position + listView.getHeaderViewsCount())) { groups.add(arrayAdapter.getItem(position)); } return groups; }
private int findPosition(String key) { if (key.equals("latest")) key = "CONUS"; for (int i = 0; i < dataAdapter.getCount(); i++) if (key.equals(dataAdapter.getItem(i))) return i; return 0; }
/** * @param context: the context where the blocks are shown * @description this function binds the data in already defined block pattern, */ private void show(Context context) { this.removeAllViews(); do { setPadding(1, 1, 1, 0); display(context); } while (postion < mAdapter.getCount()); this.addView(frameLayout); }
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int top = spinnerAdapter.getCount() - 1; if (position < top) { for (int i = top; i > position; i--) { removeCurrent(); } } }
// saved DATA when it is stop @Override protected void onPause() { String s = ""; if (mAdapter.getCount() == 0) s = "addedItem"; else if (mAdapter.getCount() != 0) { for (int i = 0; i < mAdapter.getCount() - 1; i++) { s = s + mAdapter.getItem(i) + ","; } s = s + mAdapter.getItem(mAdapter.getCount() - 1); } SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE); Editor editor = settings.edit(); editor.putString("savedData", s); editor.putBoolean("first", !isitFirst); editor.commit(); super.onPause(); }
@Override public float getSpeed(float w, long t) { if (w > 0.8f) { // Traverse all views in a millisecond return ((float) adapter.getCount()) / 0.001f; } else { return 10.0f * w; } }
public void sendMessage(View view) { EditText editText = (EditText) findViewById(R.id.message_edit_text); String message = editText.getText().toString(); editText.setText(""); messages.add("Me: " + message); adapter.notifyDataSetChanged(); listView.setSelection(adapter.getCount() - 1); new SendMessageTask().execute(message); }
@Override protected void appendCachedData() { if (getWrappedAdapter().getCount() < 75) { @SuppressWarnings("unchecked") ArrayAdapter<Integer> a = (ArrayAdapter<Integer>) getWrappedAdapter(); for (int i = 0; i < 25; i++) { a.add(a.getCount()); } } }
@Override public void finish() { StringBuilder newSetting = new StringBuilder(30); for (int i = 0; i < adapter.getCount(); i++) { newSetting.append(adapter.getItem(i)); newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR); } Preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString()); super.finish(); }
private void display(Context cx) { ArrayList<Block> blocks = new ArrayList<Block>(); counter = coorX = coorY = 0; calculateAllCells(cx); pattern = getDisplayPattern(); for (int i = 0; i < pattern.size(); i++) { ArrayList<Cell> boxCells = new ArrayList<Cell>(); for (int j = 0; j < pattern.get(i).size(); j++) { Cell c = cells.get(pattern.get(i).get(j)); boxCells.add(c); } Block block = mBlockPattern.getBlock(boxCells); block.cells = boxCells; blocks.add(block); } double maxHeightsLocal[] = {0, 0, 0, 0}; for (int i = 0; i < blocks.size(); i++) { CellView cv = new CellView(cx); View view = mAdapter.getView(postion, null, frameLayout); cv.addView(view); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams((int) blocks.get(i).width, (int) blocks.get(i).height); params.setMargins( (int) blocks.get(i).x1, (int) blocks.get(i).y1 + (int) blocks.get(i).getHeightShift(maxHeights), 0, 0); frameLayout.addView(cv, params); cells.get(i).setCellView(cv); postion++; view.setTag(postion); setViewListeners(view); if (postion >= mAdapter.getCount()) return; // Get the max height that the cells of the box occupy for (int j = 0; j < blocks.get(i).cells.size(); j++) { maxHeightsLocal[blocks.get(i).cells.get(j).coorX] += blocks.get(i).cells.get(j).getHeight(); } } for (int i = 0; i < 4; i++) maxHeights[i] += maxHeightsLocal[i]; cells.clear(); }
private void selectType() { String typeName = bundle.getString("typeName"); if (typeName != null && "".equals(typeName) && "null".equals(typeName)) { for (int i = 0; i < typeAdapter.getCount(); i++) { String tempTypeName = typeAdapter.getItem(i); if (typeName.equals(tempTypeName)) { typeSpinner.setSelection(i); } } } }
private void reloadHistoryItems() { Iterable<HistoryItem> items = historyManager.buildHistoryItems(); adapter.clear(); for (HistoryItem item : items) { adapter.add(item); } setTitle(originalTitle + " (" + adapter.getCount() + ')'); if (adapter.isEmpty()) { adapter.add(new HistoryItem(null, null, null)); } }
@Override public int getSectionForPosition(int position) { int sectionCount = 0; for (int i = 0; i < headers.getCount() - 1; i++) { sectionCount += sections.get(headers.getItem(i)).getCount(); if (sectionCount > position) return i; } return 0; }
public void addSection(String section, Adapter adapter) { this.headers.add(section); this.sections.put(section, adapter); int sectionCount = 0; for (int i = 0; i < headers.getCount() - 1; i++) { sectionCount += sections.get(headers.getItem(i)).getCount(); } _alphaIndexer.put(section, sectionCount); }
private void setSelection(Spinner spinner, String value) { if (value != null) { @SuppressWarnings("unchecked") ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter(); for (int i = adapter.getCount() - 1; i >= 0; --i) { if (value.equals(adapter.getItem(i))) { spinner.setSelection(i); break; } } } }