List of usage examples for android.widget ArrayAdapter setDropDownViewResource
public void setDropDownViewResource(@LayoutRes int resource)
Sets the layout resource to create the drop down views.
From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.OrgProfile.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); Intent i = this.getIntent(); Bundle b = i.getExtras();/* w ww . ja va 2 s . c o m*/ __keys = new CipherSuit[3]; __keys[KEY_IDX_ECDSA_BIG] = newCipherSuit(Cipher.ECDSA, Cipher.SHA384, ECDSA.P_521); __keys[KEY_IDX_ECDSA] = newCipherSuit(Cipher.ECDSA, Cipher.SHA1, ECDSA.P_256); __keys[KEY_IDX_RSA] = newCipherSuit(Cipher.RSA, Cipher.SHA512, 1024); // top panel setting organization_position = b.getInt(Orgs.O_ID); organization_LID = b.getString(Orgs.O_LID); organization_GIDH = b.getString(Orgs.O_GIDH); oLID = Util.lval(organization_LID, -1); if (oLID <= 0) return; this.org = D_Organization.getOrgByLID(oLID, true, false); if (org == null) return; try { Identity crt_identity = Identity.getCurrentConstituentIdentity(); if (crt_identity == null) { Log.d(TAG, "No identity"); } else constituent_LID = net.ddp2p.common.config.Identity.getDefaultConstituentIDForOrg(oLID); } catch (P2PDDSQLException e1) { e1.printStackTrace(); } if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, false); Log.d(TAG, "Got const: " + constituent); } setContentView(R.layout.org_profile); forename = (EditText) findViewById(R.id.profile_furname); surname = (EditText) findViewById(R.id.profile_surname); neiborhood = (Button) findViewById(R.id.profile_neiborhood); submit = (Button) findViewById(R.id.submit_profile); submit_new = (Button) findViewById(R.id.submit_profile_new); if (constituent == null) submit.setVisibility(Button.GONE); else submit.setVisibility(Button.VISIBLE); keys = (Spinner) findViewById(R.id.profile_keys); hasRightToVote = (CheckedTextView) findViewById(R.id.profile_hasRightToVote); email = (EditText) findViewById(R.id.profile_email); slogan = (EditText) findViewById(R.id.profile_slogan); slogan.setActivated(false); profilePic = (TextView) findViewById(R.id.profile_picture); profilePicImg = (ImageView) findViewById(R.id.profile_picture_img); // eligibility = (Spinner) findViewById(R.id.profile_eligibility); if (constituent != null) { forename.setText(constituent.getForename()); surname.setText(constituent.getSurname()); hasRightToVote.setChecked(Util.ival(constituent.getWeight(), 0) > 0); email.setText(constituent.getEmail()); slogan.setText(constituent.getSlogan()); } custom_fields = (LinearLayout) findViewById(R.id.profile_view); custom_index = 8; // custom_fields = (LinearLayout) findViewById(R.id.profile_custom); // custom_index = 0; custom_params = org.params.orgParam; if (custom_params == null || custom_params.length == 0) { custom_params = new D_OrgParam[0];// 3 /* * custom_params[0] = new D_OrgParam(); custom_params[0].label = * "School"; custom_params[0].entry_size = 5; custom_params[1] = new * D_OrgParam(); custom_params[1].label = "Street"; custom_params[2] * = new D_OrgParam(); custom_params[2].label = "Year"; * custom_params[2].list_of_values = new * String[]{"2010","2011","2012"}; */ } D_FieldValue[] field_values = null; if (constituent != null && constituent.address != null) field_values = constituent.address; for (int crt_field = 0; crt_field < custom_params.length; crt_field++) { D_OrgParam field = custom_params[crt_field]; LinearLayout custom_entry = new LinearLayout(this); custom_entry.setOrientation(LinearLayout.HORIZONTAL); custom_entry.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); TextView custom_label = new TextView(this); custom_label.setText(field.label); custom_entry.addView(custom_label); if (field.list_of_values != null && field.list_of_values.length > 0) { Log.d(TAG, "spinner:" + field); Spinner custom_spin = new Spinner(this); ArrayAdapter<String> custom_spin_Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, field.list_of_values); custom_spin_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); custom_spin.setAdapter(custom_spin_Adapter); custom_entry.addView(custom_spin); D_FieldValue fv = locateFV(field_values, field); if (fv != null) { int position = 0; for (int k = 0; k <= field.list_of_values.length; k++) { if (Util.equalStrings_null_or_not(field.list_of_values[k], fv.value)) { position = k; break; } } custom_spin.setSelection(position); } } else { Log.d(TAG, "edit: " + field); EditText edit_text = new EditText(this); edit_text.setText(field.default_value); edit_text.setInputType(InputType.TYPE_CLASS_TEXT); if (field.entry_size > 0) edit_text.setMinimumWidth(field.entry_size * 60); Log.d(TAG, "edit: size=" + field.entry_size); custom_entry.addView(edit_text); // Button child = new Button(this); // child.setText("Test"); D_FieldValue fv = locateFV(field_values, field); if (fv != null) edit_text.setText(fv.value); } custom_fields.addView(custom_entry, custom_index++); } ArrayAdapter<String> keysAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m); keysAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); keys.setAdapter(keysAdapter); keys.setOnItemSelectedListener(new KeysListener()); if (constituent != null) { SK sk = constituent.getSK(); if (sk != null) { Cipher cipher = Cipher.getCipher(sk, null); if (cipher instanceof net.ddp2p.ciphersuits.RSA) { keys.setSelection(KEY_IDX_RSA, true); } if (cipher instanceof net.ddp2p.ciphersuits.ECDSA) { ECDSA ecdsa = (ECDSA) cipher; CipherSuit e = ECDSA.getCipherSuite(ecdsa.getPK()); if (e.hash_alg == Cipher.SHA1) { keys.setSelection(KEY_IDX_ECDSA, true); } else { keys.setSelection(KEY_IDX_ECDSA_BIG, true); } } } } ArrayAdapter<String> eligibilityAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m); eligibilityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // eligibility.setAdapter(eligibilityAdapter); // eligibility.setOnItemSelectedListener(new EligibilityListener()); hasRightToVote.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hasRightToVote.setChecked(!hasRightToVote.isChecked()); } }); setProfilePhoto = (ImageView) findViewById(R.id.org_profile_set_profile_photo); /*TODO this part only make the whole stuff slow if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, true); Log.d(TAG, "Got const: " + constituent); } */ /* boolean gotIcon = false; if (constituent != null) { if (constituent.getPicture() != null) { byte[] icon = constituent.getPicture(); Bitmap bmp = BitmapFactory.decodeByteArray(icon, 0, icon.length - 1); setProfilePhoto.setImageBitmap(bmp); gotIcon = true; } if (!gotIcon) { int imgPath = R.drawable.constitutent_person_icon; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); setProfilePhoto.setImageBitmap(bmp); } } else { int imgPath = R.drawable.constitutent_person_icon; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); setProfilePhoto.setImageBitmap(bmp); } setProfilePhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, SELECT_PROFILE_PHOTO); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("image/*"); startActivityForResult(intent, SELECT_PPROFILE_PHOTO_KITKAT); } } });*/ submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String _forename = forename.getText().toString(); String _surname = surname.getText().toString(); int _keys = OrgProfile._selectedKey; boolean rightToVote = hasRightToVote.isChecked(); String _weight = rightToVote ? "1" : "0"; String _email = email.getText().toString(); String _slogan = slogan.getText().toString(); boolean external = false; if (constituent == null) { D_Constituent new_const = D_Constituent.createConstituent(_forename, _surname, _email, oLID, external, _weight, _slogan, OrgProfile.__keys[_keys].cipher, OrgProfile.__keys[_keys].hash_alg, OrgProfile.__keys[_keys].ciphersize, null, null); Log.d(TAG, "saved constituent=" + new_const.getNameFull()); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(new_const.getLID(), oLID); } catch (P2PDDSQLException e) { e.printStackTrace(); } Log.d(TAG, "saved new constituent=" + new_const); constituent = new_const; } else { constituent = D_Constituent.getConstByConst_Keep(constituent); constituent.setEmail(_email); constituent.setForename(_forename); constituent.setSurname(_surname); constituent.setWeight(rightToVote); constituent.setSlogan(_slogan); constituent.setExternal(false); constituent.setCreationDate(); constituent.sign(); if (constituent.dirty_any()) constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent=" + constituent); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(constituent.getLID(), oLID); } catch (P2PDDSQLException e) { e.printStackTrace(); } Log.d(TAG, "saved constituent=" + constituent.getLID() + " oLID=" + oLID); } if (constituent != null) { constituent = D_Constituent.getConstByConst_Keep(constituent); if (constituent != null) { if (constituent.getSK() != null) { constituent.setPicture(byteIcon); constituent.setCreationDate(); constituent.sign(); constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); } } } if (!org.getBroadcasted()) { D_Organization _org = D_Organization.getOrgByOrg_Keep(org); if (_org != null) { _org.setBroadcasting(true); if (_org.dirty_any()) _org.storeRequest(); _org.releaseReference(); org = _org; } } Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); Log.d(TAG, "saved constituent Done"); finish(); } }); submit_new.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String _forename = forename.getText().toString(); String _surname = surname.getText().toString(); int _keys = OrgProfile._selectedKey; boolean rightToVote = hasRightToVote.isChecked(); String _weight = rightToVote ? "1" : "0"; String _email = email.getText().toString(); String _slogan = slogan.getText().toString(); boolean external = false; D_Constituent new_const = D_Constituent.createConstituent(_forename, _surname, _email, oLID, external, _weight, _slogan, OrgProfile.__keys[_keys].cipher, OrgProfile.__keys[_keys].hash_alg, OrgProfile.__keys[_keys].ciphersize, null, null); Log.d(TAG, "saved constituent=" + new_const.getNameFull()); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(new_const.getLID(), oLID); Log.d("CONST", "No Set: oLID=" + oLID + " c=" + new_const.getLID()); } catch (P2PDDSQLException e) { e.printStackTrace(); } constituent = new_const; constituent_LID = new_const.getLID(); if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, true); Log.d(TAG, "Got const: " + constituent); } if (constituent != null) { if (constituent.getSK() != null) { constituent.setPicture(byteIcon); constituent.setCreationDate(); constituent.sign(); constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); } } if (!org.getBroadcasted()) { D_Organization _org = D_Organization.getOrgByOrg_Keep(org); if (_org != null) { _org.setBroadcasting(true); if (_org.dirty_any()) _org.storeRequest(); _org.releaseReference(); org = _org; } } Log.d(TAG, "saved constituent=" + new_const); finish(); } }); }
From source file:com.ezac.gliderlogs.FlightDetailActivity.java
public void addItemSpinner1() { Uri uri = FlightsContentProvider.CONTENT_URI_GLIDER; String[] projection = { GliderLogTables.G_REGISTRATION, GliderLogTables.G_CALLSIGN, GliderLogTables.G_SEATS, GliderLogTables.G_PRIVATE }; Cursor cursor = getContentResolver().query(uri, projection, null, null, "Registratie ASC"); if (cursor != null) { cursor.moveToFirst();//www . j a v a 2s . c o m // insert dummy item with no data as to avoid pre-selection GliderList.add(""); GliderCall.add(""); GliderSeatsList.add(""); GliderPrivateList.add(""); for (int i = 0; i < cursor.getCount(); i++) { GliderList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.G_REGISTRATION))); GliderCall.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.G_CALLSIGN))); GliderSeatsList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.G_SEATS))); GliderPrivateList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.G_PRIVATE))); cursor.moveToNext(); } cursor.close(); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(FlightDetailActivity.this, android.R.layout.simple_spinner_item, GliderList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mRegiSpin.setAdapter(dataAdapter); } }
From source file:com.forrestguice.suntimeswidget.LocationConfigView.java
/** * * @param context a context used to access resources *///from ww w .j a va 2s . com protected void initViews(Context context) { //Log.d("DEBUG", "LocationConfigView initViews"); WidgetSettings.initDisplayStrings(context); flipper = (ViewFlipper) findViewById(R.id.view_flip); flipper.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in)); flipper.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out)); flipper2 = (ViewFlipper) findViewById(R.id.view_flip2); flipper2.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in)); flipper2.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out)); ArrayAdapter<WidgetSettings.LocationMode> spinner_locationModeAdapter = new LocationModeAdapter(myParent, WidgetSettings.LocationMode.values()); spinner_locationModeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_locationMode = (Spinner) findViewById(R.id.appwidget_location_mode); spinner_locationMode.setAdapter(spinner_locationModeAdapter); spinner_locationMode.setOnItemSelectedListener(onLocationModeSelected); layout_locationName = (LinearLayout) findViewById(R.id.appwidget_location_name_layout); labl_locationName = (TextView) findViewById(R.id.appwidget_location_name_label); text_locationName = (EditText) findViewById(R.id.appwidget_location_name); String[] from = new String[] { "name" }; int[] to = new int[] { android.R.id.text1 }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) getFixAdapter = new SimpleCursorAdapter(myParent, R.layout.layout_listitem_locations, null, from, to, 0); else getFixAdapter = new SimpleCursorAdapter(myParent, R.layout.layout_listitem_locations, null, from, to); getFixAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spin_locationName = (Spinner) findViewById(R.id.appwidget_location_nameSelect); spin_locationName.setAdapter(getFixAdapter); spin_locationName.setOnItemSelectedListener(onCustomLocationSelected); labl_locationLat = (TextView) findViewById(R.id.appwidget_location_lat_label); text_locationLat = (EditText) findViewById(R.id.appwidget_location_lat); inputOverlay = findViewById(R.id.appwidget_location_latlon_overlay); inputOverlay.setVisibility(View.GONE); inputOverlay.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (mode == LocationViewMode.MODE_CUSTOM_SELECT) { setMode(LocationViewMode.MODE_CUSTOM_EDIT); } } }); labl_locationLon = (TextView) findViewById(R.id.appwidget_location_lon_label); text_locationLon = (EditText) findViewById(R.id.appwidget_location_lon); // custom mode: toggle edit mode button_edit = (ImageButton) findViewById(R.id.appwidget_location_edit); button_edit.setOnClickListener(onEditButtonClicked); // custom mode: save location button_save = (ImageButton) findViewById(R.id.appwidget_location_save); button_save.setOnClickListener(onSaveButtonClicked); // custom mode: get GPS fix progress_getfix = (ProgressBar) findViewById(R.id.appwidget_location_getfixprogress); progress_getfix.setVisibility(View.GONE); button_getfix = (ImageButton) findViewById(R.id.appwidget_location_getfix); getFixUI_editMode = new GetFixUI1(text_locationName, text_locationLat, text_locationLon, progress_getfix, button_getfix); button_getfix.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFixHelper.getFix(0); } }); // auto mode: get GPS fix progress_auto = (ProgressBar) findViewById(R.id.appwidget_location_auto_progress); progress_auto.setVisibility(View.GONE); button_auto = (ImageButton) findViewById(R.id.appwidget_location_auto); getFixUI_autoMode = new GetFixUI2(text_locationName, text_locationLat, text_locationLon, progress_auto, button_auto); button_auto.setOnClickListener(onAutoButtonClicked); getFixHelper = new GetFixHelper(myParent, getFixUI_editMode); // 0; getFixUI_editMode getFixHelper.addUI(getFixUI_autoMode); // 1; getFixUI_autoMode updateGPSButtonIcons(); }
From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java
public void updateCities(int id) { ArrayList<City> ca = new ArrayList<City>(); for (int i = 0; i < citiesArray.size(); i++) { if (citiesArray.get(i).getDepartment_id() == id) { ca.add(citiesArray.get(i));// w w w .j a v a 2 s. c o m } } ArrayAdapter saa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, ca); saa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view mCitiesSpinner.setAdapter(saa); }
From source file:com.ezac.gliderlogs.FlightDetailActivity.java
public void addItemSpinner2() { Uri uri = FlightsContentProvider.CONTENT_URI_MEMBER; String[] projection = { GliderLogTables.M_ID, GliderLogTables.M_2_NAME, GliderLogTables.M_3_NAME, GliderLogTables.M_1_NAME, GliderLogTables.M_INSTRUCTION }; Cursor cursor = getContentResolver().query(uri, projection, null, null, "Voornaam ASC"); if (cursor != null) { cursor.moveToFirst();/* ww w . j a v a 2s .c o m*/ // insert dummy item with no data as to avoid pre-selection MemberList.add(""); //MemberTrainList.add(""); MemberIndexList.add(""); MemberInstrList.add(""); for (int i = 0; i < cursor.getCount(); i++) { String tmp = cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_1_NAME)) + " " + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_2_NAME)) + " " + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_3_NAME)); MemberList.add(tmp.replaceAll("\\s+", " ")); MemberIndexList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_ID))); // MemberTrainList.add(cursor.getString(cursor // .getColumnIndexOrThrow(GliderLogTables.M_TRAIN))); MemberInstrList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_INSTRUCTION))); // some logic add as to deal with new members with dummy id if (Integer .parseInt(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_ID))) >= ini_id) { ini_id = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_ID))) + 1; Log.d(TAG, "key " + ini_id); } cursor.moveToNext(); } cursor.close(); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(FlightDetailActivity.this, android.R.layout.simple_spinner_item, MemberList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mPilotSpin.setAdapter(dataAdapter); mCoPilotSpin.setAdapter(dataAdapter); } }
From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java
public void updateDepartment(int id) { Log.v("UPDATE_DATA", "updateDepartment +"); ArrayList<Department> da = new ArrayList<Department>(); for (int i = 0; i < departmentsArray.size(); i++) { Log.v("UPDATE_DATA", " i=" + String.valueOf(i)); if (departmentsArray.get(i).getCountry_id() == id) { da.add(departmentsArray.get(i)); }/*from www .ja va2 s. com*/ } ArrayAdapter saa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, da); saa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view mDepartmentSpinner.setAdapter(saa); Log.v("UPDATE_DATE", "updateDepartment -"); }
From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext();/*from w w w. j ava 2s . co 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.pluscubed.velociraptor.SettingsActivity.java
@SuppressWarnings("ConstantConditions") @Override//w ww . j a v a 2s. com protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); ButterKnife.bind(this); setSupportActionBar(toolbar); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { View marshmallowPermissionsCard = findViewById(R.id.card_m_permissions); marshmallowPermissionsCard.setVisibility(View.GONE); } openStreetMapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShareCompat.IntentBuilder.from(SettingsActivity.this).setText("https://www.openstreetmap.org") .setType("text/plain").startChooser(); } }); checkCoverageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mGoogleApiClient = new GoogleApiClient.Builder(SettingsActivity.this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override @SuppressWarnings("MissingPermission") public void onConnected(@Nullable Bundle bundle) { String uriString = "http://product.itoworld.com/map/124"; if (isLocationPermissionGranted()) { Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleApiClient); if (lastLocation != null) { uriString += "?lon=" + lastLocation.getLongitude() + "&lat=" + lastLocation.getLatitude() + "&zoom=12"; } } Intent intent = new Intent(); intent.setData(Uri.parse(uriString)); intent.setAction(Intent.ACTION_VIEW); try { startActivity(intent); } catch (ActivityNotFoundException e) { Snackbar.make(enableFloatingButton, R.string.open_coverage_map_failed, Snackbar.LENGTH_LONG).show(); } mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int i) { } }).addApi(LocationServices.API).build(); mGoogleApiClient.connect(); } }); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); View notifControls = findViewById(R.id.switch_notif_controls); notifControls.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SettingsActivity.this, FloatingService.class); intent.putExtra(FloatingService.EXTRA_NOTIF_START, true); PendingIntent pending = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE, intent, PendingIntent.FLAG_CANCEL_CURRENT); Intent intentClose = new Intent(SettingsActivity.this, FloatingService.class); intentClose.putExtra(FloatingService.EXTRA_NOTIF_CLOSE, true); PendingIntent pendingClose = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE_CLOSE, intentClose, PendingIntent.FLAG_CANCEL_CURRENT); Intent settings = new Intent(SettingsActivity.this, SettingsActivity.class); PendingIntent settingsIntent = PendingIntent.getActivity(SettingsActivity.this, PENDING_SETTINGS, settings, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(SettingsActivity.this) .setSmallIcon(R.drawable.ic_speedometer) .setContentTitle(getString(R.string.controls_notif_title)) .setContentText(getString(R.string.controls_notif_desc)) .addAction(0, getString(R.string.show), pending) .addAction(0, getString(R.string.hide), pendingClose).setDeleteIntent(pendingClose) .setContentIntent(settingsIntent); Notification notification = builder.build(); notificationManager.notify(NOTIFICATION_CONTROLS, notification); } }); Button openAppSelection = (Button) findViewById(R.id.button_app_selection); openAppSelection.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(SettingsActivity.this, AppSelectionActivity.class)); } }); autoDisplaySwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this)); autoDisplaySwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean autoDisplayEnabled = autoDisplaySwitch.isChecked(); PrefUtils.setAutoDisplay(SettingsActivity.this, autoDisplayEnabled); updateAppDetectionEnabled(autoDisplayEnabled); } }); enableServiceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)); } catch (ActivityNotFoundException e) { Snackbar.make(enableServiceButton, R.string.open_settings_failed_accessibility, Snackbar.LENGTH_LONG).show(); } } }); enableFloatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { //Open the current default browswer App Info page openSettings(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, BuildConfig.APPLICATION_ID); } catch (ActivityNotFoundException ignored) { Snackbar.make(enableFloatingButton, R.string.open_settings_failed_overlay, Snackbar.LENGTH_LONG) .show(); } } }); enableLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(SettingsActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } }); ArrayAdapter<String> unitAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text, new String[] { "mph", "km/h" }); unitAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); unitSpinner.setAdapter(unitAdapter); unitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (PrefUtils.getUseMetric(SettingsActivity.this) != (position == 1)) { PrefUtils.setUseMetric(SettingsActivity.this, position == 1); unitSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this, unitSpinner.getSelectedItemPosition() * -48)); updateFloatingServicePrefs(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); unitSpinner.setSelection(PrefUtils.getUseMetric(this) ? 1 : 0); unitSpinner .setDropDownVerticalOffset(Utils.convertDpToPx(this, unitSpinner.getSelectedItemPosition() * -48)); ArrayAdapter<String> styleAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text, new String[] { getString(R.string.united_states), getString(R.string.international) }); styleAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); styleSpinner.setAdapter(styleAdapter); styleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != PrefUtils.getSignStyle(SettingsActivity.this)) { PrefUtils.setSignStyle(SettingsActivity.this, position); styleSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this, styleSpinner.getSelectedItemPosition() * -48)); updateFloatingServicePrefs(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); styleSpinner.setSelection(PrefUtils.getSignStyle(this)); styleSpinner .setDropDownVerticalOffset(Utils.convertDpToPx(this, styleSpinner.getSelectedItemPosition() * -48)); toleranceView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new ToleranceDialogFragment().show(getFragmentManager(), "dialog_tolerance"); } }); showSpeedometerSwitch.setChecked(PrefUtils.getShowSpeedometer(this)); ((View) showSpeedometerSwitch.getParent()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSpeedometerSwitch.setChecked(!showSpeedometerSwitch.isChecked()); PrefUtils.setShowSpeedometer(SettingsActivity.this, showSpeedometerSwitch.isChecked()); updateFloatingServicePrefs(); } }); debuggingSwitch.setChecked(PrefUtils.isDebuggingEnabled(this)); ((View) debuggingSwitch.getParent()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { debuggingSwitch.setChecked(!debuggingSwitch.isChecked()); PrefUtils.setDebugging(SettingsActivity.this, debuggingSwitch.isChecked()); updateFloatingServicePrefs(); } }); beepSwitch.setChecked(PrefUtils.isBeepAlertEnabled(this)); beepSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PrefUtils.setBeepAlertEnabled(SettingsActivity.this, beepSwitch.isChecked()); } }); testBeepButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Utils.playBeep(); } }); androidAutoSwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this)); androidAutoSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = androidAutoSwitch.isChecked(); if (checked) { new MaterialDialog.Builder(SettingsActivity.this) .content(R.string.android_auto_instruction_dialog).positiveText(android.R.string.ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, true); } }).show(); } else { PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, checked); } } }); invalidateStates(); if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this) && !PrefUtils.isFirstRun(this)) { showChangelog(); } billingProcessor = new BillingProcessor(this, getString(R.string.play_license_key), new BillingProcessor.IBillingHandler() { @Override public void onProductPurchased(String productId, TransactionDetails details) { PrefUtils.setSupported(SettingsActivity.this, true); if (Arrays.asList(PURCHASES).contains(productId)) billingProcessor.consumePurchase(productId); } @Override public void onPurchaseHistoryRestored() { } @Override public void onBillingError(int errorCode, Throwable error) { if (errorCode != 110) { Snackbar.make(findViewById(android.R.id.content), "Billing error: code = " + errorCode + ", error: " + (error != null ? error.getMessage() : "?"), Snackbar.LENGTH_LONG).show(); } } @Override public void onBillingInitialized() { billingProcessor.loadOwnedPurchasesFromGoogle(); } }); PrefUtils.setFirstRun(this, false); PrefUtils.setVersionCode(this, BuildConfig.VERSION_CODE); }
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
/** * Network Service Discovery???.//from w w w . ja v a2s .com * @param res ?JSON */ private void parseNetworkServieDiscovery(final String res) { try { JSONObject root = new JSONObject(res); JSONArray services = root.getJSONArray(NetworkServiceDiscoveryProfile.PARAM_SERVICES); if (services == null) { return; } String[] data = new String[services.length() + 1]; data[0] = " "; // ????????? for (int i = 1; i < services.length() + 1; i++) { data[i] = services.getJSONObject(i - 1).getString(NetworkServiceDiscoveryProfile.PARAM_ID); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, data); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDI.setAdapter(adapter); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mifos.mifosxdroid.online.LoanAccountFragment.java
private void inflateLoansProductSpinner() { showProgress(true);/* ww w . ja va2s .c o m*/ App.apiManager.getAllLoans(new Callback<List<ProductLoans>>() { @Override public void success(List<ProductLoans> loans, Response response) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return; final List<String> loansList = new ArrayList<String>(); for (ProductLoans loansname : loans) { loansList.add(loansname.getName()); loansNameIdHashMap.put(loansname.getName(), loansname.getId()); } ArrayAdapter<String> loansAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, loansList); loansAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_lproduct.setAdapter(loansAdapter); sp_lproduct.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { productId = loansNameIdHashMap.get(loansList.get(i)); Log.d("productId " + loansList.get(i), String.valueOf(productId)); if (productId != -1) { inflateLoanPurposeSpinner(); inflateFrequencyPeriodSpinner(); inflateAmortizationSpinner(); inflateInterestCalculationPeriodSpinner(); inflatetransactionProcessingStrategySpinner(); inflateLoanFundSpinner(); inflateLoanOfficerSpinner(); inflateInterestTypeMethodSpinner(); } else { Toast.makeText(getActivity(), getString(R.string.error_select_loan), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); showProgress(false); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); showProgress(false); } }); }