List of usage examples for android.widget ArrayAdapter add
public void add(@Nullable T object)
From source file:org.cvasilak.jboss.mobile.app.fragments.RuntimeViewFragment.java
public void showDomainHostChooser() { ProgressDialogFragment.showDialog(getActivity(), R.string.queryingServer); application.getOperationsManager().fetchDomainHostInfoInformation(new Callback() { @Override/*from ww w . j ava2 s . c o m*/ public void onSuccess(JsonElement reply) { JsonArray jsonArr = reply.getAsJsonArray(); // if only one host exists in the domain, // no need to display the host chooser dialog // immediately show the servers dialog for this host if (jsonArr.size() == 1) { showDomainServersDialog(jsonArr.get(0).getAsString(), false); return; } ProgressDialogFragment.dismissDialog(getActivity()); final ArrayAdapter<String> hosts = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice); // will hold the default selection host position // when the list is displayed int selPos = -1; String activeHost = application.getOperationsManager().getDomainHost(); for (int i = 0; i < jsonArr.size(); i++) { String host = jsonArr.get(i).getAsString(); if (host.equals(activeHost)) selPos = i; hosts.add(host); } AlertDialog.Builder hostsDialog = new AlertDialog.Builder(getActivity()); hostsDialog.setTitle(R.string.select_host); hostsDialog.setSingleChoiceItems(hosts, selPos, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showDomainServersDialog(hosts.getItem(which), true); } }); hostsDialog.setPositiveButton(R.string.next, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { int selectedPosition = ((AlertDialog) dialogInterface).getListView() .getCheckedItemPosition(); showDomainServersDialog(hosts.getItem(selectedPosition), true); } }); hostsDialog.setCancelable(false); ParameterizedDialogFragment dialog = new ParameterizedDialogFragment(hostsDialog); dialog.show(getActivity().getSupportFragmentManager(), null); } @Override public void onFailure(Exception e) { ProgressDialogFragment.dismissDialog(getActivity()); ErrorDialogFragment.showDialog(getActivity(), e.getMessage()); } }); }
From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
private void handleGovernors() { String currentGovernor = ""; if (Helpers.doesFileExist(GOVERNOR)) currentGovernor = CPUHelper.readOneLineNotRoot(GOVERNOR); String currentGovernor2 = ""; if (Helpers.doesFileExist(GOVERNOR2)) currentGovernor2 = CPUHelper.readOneLineNotRoot(GOVERNOR2); else/*from w w w . j a v a 2 s . c o m*/ currentGovernor2 = bootPrefs.getString("CORE1_GOVERNOR", "NaN"); String currentGovernor3 = ""; if (Helpers.doesFileExist(GOVERNOR3)) currentGovernor3 = CPUHelper.readOneLineNotRoot(GOVERNOR3); else currentGovernor3 = bootPrefs.getString("CORE2_GOVERNOR", "NaN"); String currentGovernor4 = ""; if (Helpers.doesFileExist(GOVERNOR4)) currentGovernor4 = CPUHelper.readOneLineNotRoot(GOVERNOR4); else currentGovernor4 = bootPrefs.getString("CORE3_GOVERNOR", "NaN"); /** CPU Governor for all cores */ String[] availableGovernorsGeneral = CPUHelper.readOneLineNotRoot(GOVERNORS_LIST).split(" "); ArrayAdapter<CharSequence> governorAdapterGeneral = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapterGeneral.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String availableGovernor : availableGovernorsGeneral) { governorAdapterGeneral.add(availableGovernor); } mGeneralGovernor.setAdapter(governorAdapterGeneral); mGeneralGovernor.setSelection(Arrays.asList(availableGovernorsGeneral).indexOf(currentGovernor)); mGeneralGovernor.setOnItemSelectedListener(new GeneralGovListener()); /** CPU Governor for core 0 */ String[] availableGovernors = CPUHelper.readOneLineNotRoot(GOVERNORS_LIST).split(" "); ArrayAdapter<CharSequence> governorAdapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String availableGovernor : availableGovernors) { governorAdapter.add(availableGovernor); } mGovernor.setAdapter(governorAdapter); mGovernor.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor)); mGovernor.setOnItemSelectedListener(new GovListener()); /** CPU Governor for core 1 */ ArrayAdapter<CharSequence> governorAdapter2 = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String anAvailableGovernors2 : availableGovernors) { governorAdapter2.add(anAvailableGovernors2); } mGovernor2.setAdapter(governorAdapter2); mGovernor2.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor2)); mGovernor2.setOnItemSelectedListener(new GovListener2()); /** CPU Governor for core 2 */ ArrayAdapter<CharSequence> governorAdapter3 = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String anAvailableGovernors3 : availableGovernors) { governorAdapter3.add(anAvailableGovernors3); } mGovernor3.setAdapter(governorAdapter3); mGovernor3.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor3)); mGovernor3.setOnItemSelectedListener(new GovListener3()); /** CPU Governor for core 3 */ ArrayAdapter<CharSequence> governorAdapter4 = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String anAvailableGovernors4 : availableGovernors) { governorAdapter4.add(anAvailableGovernors4); } mGovernor4.setAdapter(governorAdapter4); mGovernor4.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor4)); mGovernor4.setOnItemSelectedListener(new GovListener4()); /** CPU Boost */ if (Helpers.doesFileExist(KRAIT_BOOST)) { Switch cpuBoostSwitch = (Switch) findViewById(R.id.krait_boost_switch); String cpuBoostState = CPUHelper.readOneLineNotRoot(KRAIT_BOOST); if (cpuBoostState.equals("Y")) cpuBoostSwitch.setChecked(true); else cpuBoostSwitch.setChecked(false); cpuBoostSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo Y > " + KRAIT_BOOST); else Helpers.CMDProcessorWrapper.runSuCommand("busybox echo N > " + KRAIT_BOOST); } }); } else { findViewById(R.id.card_krait_boost).setVisibility(View.GONE); } /** CPU Informations */ String pvs = "NaN"; String table = "NaN"; TextView pvsBinning = (TextView) findViewById(R.id.pvs_bin); TextView pvsSpeed = (TextView) findViewById(R.id.pvs_speed); if (Helpers.doesFileExist(PVS_BINNING)) { String rawTableName = CPUHelper.readOneLineNotRoot(PVS_BINNING); rawTableName = rawTableName.replaceAll("[\\D]", ""); table = rawTableName; String[] params = rawTableName.split(""); if (rawTableName.length() == 3) pvs = params[2]; } pvsBinning.setText(getString(R.string.pvs_binning) + " " + pvs); pvsSpeed.setText(getString(R.string.freq_table) + " " + table); }
From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java
private ActionBarDrawerToggle initializeDrawerToggle() { final int drawerImageRes; // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); //actionBar.setCustomView(mTextView); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowCustomEnabled(false); actionBar.setIcon(R.drawable.icon);//from w ww . jav a 2 s. co m actionBar.setTitle("");//ZV //actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(197, 197, 197))); //ZV final ArrayAdapter<CharSequence> actionBarAdapter = new ArrayAdapter<>(actionBar.getThemedContext(), android.R.layout.simple_spinner_item); for (final String tab : TAB_LIST) { actionBarAdapter.add(getText(LibraryTabsUtil.getTabTitleResId(tab))); } actionBarAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); actionBar.setListNavigationCallbacks(actionBarAdapter, this); /** * @param Activity activity * @param DrawerLayout * @param drawerImageRes nav drawer icon to replace 'Up' caret * @param openDrawerContentDescRes "open drawer" description * @param closeDrawerContentDescRes "close drawer" description */ return new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { /** * Called when a drawer has settled in a completely closed * state. */ @Override public void onDrawerClosed(final View drawerView) { refreshActionBarTitle(); } /** * Called when a drawer has settled in a completely open * state. */ @Override public void onDrawerOpened(final View drawerView) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayShowCustomEnabled(true); actionBar.setTitle(R.string.app_name);//ZV //mTextView.setText(R.string.app_name); ZV } }; }
From source file:com.googlecode.CallerLookup.Main.java
@SuppressWarnings("unchecked") public void updateLookupEntries() { parseLookupEntries();/* w ww . j ava 2 s. com*/ ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter(); if (adapter == null) { adapter = new ArrayAdapter<CharSequence>(getApplicationContext(), android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLookup.setAdapter(adapter); } else { adapter.clear(); } adapter.add("Custom"); for (String lookupEntryName : mLookupEntries.keySet()) { adapter.add(lookupEntryName); } for (String lookupEntryName : mUserLookupEntries.keySet()) { assert (!mLookupEntries.containsKey(lookupEntryName)); mLookupEntries.put(lookupEntryName, mUserLookupEntries.get(lookupEntryName)); adapter.add(lookupEntryName); } String name = mPrefs.getString(PREFS_LOOKUP, "Custom"); if ((name.length() > 0) && !name.equals("Custom")) { int count = mLookup.getCount(); for (int i = 1; i < count; i++) { if (mLookup.getItemAtPosition(i).toString().equals(name)) { mLookup.setSelection(i); break; } } } else { if (mLookup.getSelectedItemPosition() != 0) { mIgnoreItemSelection = true; mLookup.setSelection(0); } } }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpMerchandiseStation.java
private void setLister() { timePicker = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { }/*from ww w .ja v a 2s. com*/ }; timerPicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new TimePickerDialog(getActivity(), timePicker, 24, 59, true).show(); } }); departure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DEPARTURE_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DEPARTURE_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.STOP_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.STOP_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); destination.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DESTINATION_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DESTINATION_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); getDataFromDB(); listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); } }); spinner_dork_location_destination.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); destination_detail = new LocationAddress(); destination_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); destination_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); destination_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); destination_detail.setLocation(currentLocation.getLocation()); destination_detail.setZipCode(currentLocation.getStreetAddress().substring(0, 3)); destination_detail.setCountryName("Taiwan"); destination_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); spinner_dork_location_departure.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); departure_detail = new LocationAddress(); departure_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); departure_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); departure_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); departure_detail.setLocation(currentLocation.getLocation()); departure_detail.setZipCode(currentLocation.getStreetAddress().substring(0, 3)); departure_detail.setCountryName("Taiwan"); departure_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); }
From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int menuItemIndex = item.getItemId(); contextListPosition = info.position; AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()).setTitle("Move Meal To:"); final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1); mAdapterMoveMeal.add("Snack"); mAdapterMoveMeal.add("Breakfast"); mAdapterMoveMeal.add("Lunch"); mAdapterMoveMeal.add("Dinner"); builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override//from ww w .j av a 2 s . co m public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = mAdapterMoveMeal.getItem(which); if (contextListChoice == 1) { LogMeal logMeals = mLogSnackAdapter.getItem(contextListPosition); logMeals.setMealChoice(strName); logMeals.edit(); initializeAdapters(mDate); } if (contextListChoice == 2) { LogMeal logMeals = mLogBreakfastAdapter.getItem(contextListPosition); logMeals.setMealChoice(strName); logMeals.edit(); initializeAdapters(mDate); } if (contextListChoice == 3) { LogMeal logMeals = mLogLunchAdapter.getItem(contextListPosition); logMeals.setMealChoice(strName); logMeals.edit(); initializeAdapters(mDate); } if (contextListChoice == 4) { LogMeal logMeals = mLogDinnerAdapter.getItem(contextListPosition); logMeals.setMealChoice(strName); logMeals.edit(); initializeAdapters(mDate); } updateListViews(); } }); switch (contextListChoice) { case 1: switch (menuItemIndex) { case 0: LogMeal logMeals = mLogSnackAdapter.getItem(contextListPosition); logMeals.delete(); mLogSnackAdapter.remove(logMeals); mLogSnackAdapter.notifyDataSetChanged(); testing(); initializeAdapters(new Date()); refreshOnDelete(); updateListViews(); equations(); break; case 1: builderSingle.show(); break; } break; case 2: switch (menuItemIndex) { case 0: LogMeal logMeals = mLogBreakfastAdapter.getItem(contextListPosition); logMeals.delete(); mLogBreakfastAdapter.remove(logMeals); mLogBreakfastAdapter.notifyDataSetChanged(); testing(); initializeAdapters(new Date()); refreshOnDelete(); updateListViews(); equations(); break; case 1: builderSingle.show(); break; } break; case 3: switch (menuItemIndex) { case 0: LogMeal logMeals = mLogLunchAdapter.getItem(contextListPosition); logMeals.delete(); mLogLunchAdapter.remove(logMeals); mLogLunchAdapter.notifyDataSetChanged(); testing(); initializeAdapters(new Date()); refreshOnDelete(); updateListViews(); equations(); break; case 1: builderSingle.show(); break; } break; case 4: switch (menuItemIndex) { case 0: LogMeal logMeals = mLogDinnerAdapter.getItem(contextListPosition); logMeals.delete(); mLogDinnerAdapter.remove(logMeals); mLogDinnerAdapter.notifyDataSetChanged(); testing(); initializeAdapters(new Date()); refreshOnDelete(); updateListViews(); equations(); break; case 1: builderSingle.show(); break; } break; default: break; } return true; }
From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext();//from w ww .jav a 2s . c o m PropertyHolder.init(context); storeMyData = PropertyHolder.getStoreMyData(); setContentView(R.layout.settings); // views mServiceButton = (ToggleButton) findViewById(R.id.service_button); mServiceMessage = (TextView) findViewById(R.id.service_message); mIntervalSpinner = (Spinner) findViewById(R.id.spinner_interval); mStorageHeading = (TextView) findViewById(R.id.storageHeading); mStorageText = (TextView) findViewById(R.id.storageText); mIntervalHeading = (TextView) findViewById(R.id.intervalHeading); mIntervalText = (TextView) findViewById(R.id.intervalText); participationLabel = (TextView) findViewById(R.id.participationHeading); pendingUploadsLabel = (TextView) findViewById(R.id.pendingUploadsHeading); mStorageSizePendingUploadsText = (TextView) findViewById(R.id.storageSizePendingUploadsText); mStorageSizeUserDbText = (TextView) findViewById(R.id.storageSizeUserDbText); participationTimeText = (Chronometer) findViewById(R.id.participationTimeText); nUploadsText = (TextView) findViewById(R.id.nUploadsText); mStorageSpinner = (Spinner) findViewById(R.id.spinner_mydata); ArrayAdapter<CharSequence> sAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item); sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (int i = MIN_STORAGE; i <= MAX_STORAGE; i++) { sAdapter.add(" " + Integer.toString(i)); } mStorageSpinner.setAdapter(sAdapter); mShareDataRadioGroup = (RadioGroup) findViewById(R.id.sharedataRadioGroup); deletePendingUploadsButton = (ImageButton) findViewById(R.id.deletePendingUploadsButton); uploadButton = (ImageButton) findViewById(R.id.uploadButton); oldColors = mStorageText.getTextColors(); }
From source file:com.mobicage.rogerthat.AddFriendsActivity.java
private void configureMailView() { T.UI();// w w w .ja v a 2 s.co m final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_email_text_field); emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>())); emailText.setThreshold(1); if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) { mService.postAtFrontOfBIZZHandler(new SafeRunnable() { @SuppressWarnings("unchecked") @Override protected void safeRun() throws Exception { L.d("AddFriendsActivity getEmailAddresses"); List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.this); ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter(); for (int i = 0; i < emailList.size(); i++) { a.add(emailList.get(i)); } a.notifyDataSetChanged(); L.d("AddFriendsActivity gotEmailAddresses"); } }); } final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String email = emailText.getText().toString().trim(); if (RegexPatterns.EMAIL.matcher(email).matches()) { if (mFriendsPlugin.inviteFriend(email, null, null, true)) { emailText.setText(null); UIUtils.hideKeyboard(AddFriendsActivity.this, emailText); } else { UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed)); } } else { AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } } }; ((Button) findViewById(R.id.add_via_email_button)).setOnClickListener(onClickListener); emailText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { onClickListener.onClick(view); return true; } return false; } }); }
From source file:org.uguess.android.sysinfo.NetStateManager.java
void refresh() { ArrayList<ConnectionItem> data = new ArrayList<ConnectionItem>(); data.add(dummyInfo);//w w w . j a v a 2s . co m ArrayList<ConnectionItem> items = readStatesRaw(); if (items != null) { final int type = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_ORDER_TYPE, ORDER_TYPE_PROTO); final int direction = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_DIRECTION, ORDER_ASC); final Collator clt = Collator.getInstance(); switch (type) { case ORDER_TYPE_PROTO: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.proto, obj2.proto) * direction; } }); break; case ORDER_TYPE_LOCAL: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.local, obj2.local) * direction; } }); break; case ORDER_TYPE_REMOTE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.remoteName == null ? obj1.remote : obj1.remoteName, obj2.remoteName == null ? obj2.remote : obj2.remoteName) * direction; } }); break; case ORDER_TYPE_STATE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.state == null ? "" //$NON-NLS-1$ : obj1.state, obj2.state == null ? "" //$NON-NLS-1$ : obj2.state) * direction; } }); break; } data.addAll(items); } ArrayAdapter<ConnectionItem> adapter = (ArrayAdapter<ConnectionItem>) getListView().getAdapter(); adapter.setNotifyOnChange(false); adapter.clear(); for (int i = 0, size = data.size(); i < size; i++) { adapter.add(data.get(i)); } adapter.notifyDataSetChanged(); if (adapter.getCount() == 1) { Log.d(NetStateManager.class.getName(), "No network traffic detected"); //$NON-NLS-1$ } }
From source file:br.ufsc.das.gtscted.shibbauth.ShibAuthenticationActivity.java
/** Called when the activity is first created. */ @Override//from w w w.j a v a 2s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.idp_selection); loginButton = (Button) findViewById(R.id.loginButton); backButton = (Button) findViewById(R.id.backButton); usernameTxt = (EditText) findViewById(R.id.usernameTxt); passwordTxt = (EditText) findViewById(R.id.passwordTxt); idpSpinner = (Spinner) findViewById(R.id.idpSpinner); //Configura o ArrayAdapter do spinner. ArrayAdapter<CharSequence> spinnerArrayAdapter; spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); idpSpinner.setAdapter(spinnerArrayAdapter); // Obtm os parmetros passados pela Activity anterior // (no caso, a pgina do WAYF como uma String e o // nico cookie da Connection usada anteriormente) Bundle bundle = this.getIntent().getExtras(); String wayfHtml = bundle.getString("html_source"); final String wayfLocation = bundle.getString("wayf_location"); final SerializableCookie receivedCookie = (SerializableCookie) bundle.getSerializable("cookie"); //Obtm todos os tags de nome "option", que correspondem // aos IdPs, da pgina do WAYF. Document wayfDocument = Jsoup.parse(wayfHtml); idpElements = wayfDocument.select("option"); //Popula o spinner com os nomes dos IdPs encontrados. for (Element idpElement : idpElements) { String idpName = idpElement.text(); spinnerArrayAdapter.add(idpName); } // Obtm o caminho para o qual deve ser passado o IdP do usurio. formElements = wayfDocument.select("form"); for (Element formElement : formElements) { if (formElement.attr("id").equals("IdPList")) { wayfActionPath = formElement.attr("action"); } } loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Obtm a URL correspondente ao idP selecionado no spinner. int selectedIdpPosition = idpSpinner.getSelectedItemPosition(); Element selectedIdp = idpElements.get(selectedIdpPosition); selectedIdpUrl = selectedIdp.attr("value"); try { // Obtm os campos "username" e "password" fornecidos // pelo usurio e necessrios para a autenticao. String username = usernameTxt.getText().toString(); String password = passwordTxt.getText().toString(); // Cria um novo objeto Connection, e adiciona o // cookie passado pela Activity anterior. Connection connection = new Connection(); BasicClientCookie newCookie = new BasicClientCookie(receivedCookie.getName(), receivedCookie.getValue()); newCookie.setDomain(receivedCookie.getDomain()); connection.addCookie(newCookie); // Tenta realizar a autenticao no IdP selecionado. O resultado corresponde // pgina para a qual o cliente redirecionado em caso de autenticao // bem-sucedida. String authResult = connection.authenticate(wayfLocation, wayfActionPath, selectedIdpUrl, username, password); // Apenas mostra o recurso que o usurio queria acessar (neste caso, mostra a pg. de // "Homologao de atributos"). Intent newIntent = new Intent(ShibAuthenticationActivity.this.getApplicationContext(), TestActivity.class); Bundle bundle = new Bundle(); bundle.putString("arg", authResult); newIntent.putExtras(bundle); startActivity(newIntent); } catch (IOException e) { String message = "IOException - problema na conexo"; Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG); toast.show(); } catch (Exception e) { String message = "Exception - problema na autenticao"; Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG); toast.show(); } } }); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); }