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.nextgis.mobile.forms.DescriptionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.setRetainInstance(true); View view = inflater.inflate(R.layout.descriptfragment, container, false); final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item); final Map<String, ArrayList<String>> mlCategories = new HashMap<String, ArrayList<String>>(); //fill spinners from xml data XmlPullParser parser = Xml.newPullParser(); try {/*from w w w . j a v a 2s. co m*/ File file = new File(getActivity().getExternalFilesDir(null), "categories.xml"); if (file != null) { if (!file.exists()) { createExternalStoragePrivateFile(); file = new File(getActivity().getExternalFilesDir(null), "categories.xml"); } InputStream in = new BufferedInputStream(new FileInputStream(file)); InputStreamReader isr = new InputStreamReader(in); // auto-detect the encoding from the stream parser.setInput(isr); int eventType = parser.getEventType(); String sCatVal = null; while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: String name = parser.getName(); if (name.equalsIgnoreCase("category")) { sCatVal = parser.getAttributeValue(null, "name"); adapter.add(sCatVal); mlCategories.put(sCatVal, new ArrayList<String>()); } else if (name.equalsIgnoreCase("subcategory")) { if (sCatVal != null) { String sSubCatVal = parser.getAttributeValue(null, "name"); mlCategories.get(sCatVal).add(sSubCatVal); } } break; } eventType = parser.next(); } if (in != null) { in.close(); } } } catch (IOException e) { // TODO } catch (Exception e) { // TODO } Spinner spinner = (Spinner) view.findViewById(R.id.spinner_cat); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { final Spinner subspinner = (Spinner) getView().findViewById(R.id.spinner_subcat); //subspinner String sCat = adapter.getItem(arg2).toString(); TextView textview = (TextView) getView().findViewById(R.id.spinner_subcat_custom); if (sCat.equalsIgnoreCase("custom")) { //enable text item textview.setEnabled(true); } else { textview.setEnabled(false); } ArrayAdapter<String> subadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, mlCategories.get(sCat)); subadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); subspinner.setAdapter(subadapter); } public void onNothingSelected(AdapterView<?> arg0) { } }); onStoreValues(); return view; }
From source file:com.nextgis.maplibui.formcontrol.Combobox.java
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); setEnabled(ControlHelper.isEnabled(fields, mFieldName)); String lastValue = null;//from ww w . jav a2 s . co m if (ControlHelper.hasKey(savedState, mFieldName)) lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else if (null != featureCursor) { int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) lastValue = featureCursor.getString(column); } else if (mIsShowLast) lastValue = preferences.getString(mFieldName, null); int defaultPosition = 0; int lastValuePosition = -1; mAliasValueMap = new HashMap<>(); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.formtemplate_spinner); setAdapter(spinnerArrayAdapter); if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) { MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); if (null == map) throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited"); String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME); long id = attributes.getLong(JSON_NGW_ID_KEY); for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWLookupTable) { NGWLookupTable table = (NGWLookupTable) map.getLayer(i); if (table.getRemoteId() != id || !table.getAccountName().equals(account)) continue; int j = 0; for (Map.Entry<String, String> entry : table.getData().entrySet()) { mAliasValueMap.put(entry.getValue(), entry.getKey()); if (null != lastValue && lastValue.equals(entry.getKey())) lastValuePosition = j; spinnerArrayAdapter.add(entry.getValue()); j++; } break; } } } else { JSONArray values = attributes.optJSONArray(JSON_VALUES_KEY); if (values != null) { for (int j = 0; j < values.length(); j++) { JSONObject keyValue = values.getJSONObject(j); String value = keyValue.getString(JSON_VALUE_NAME_KEY); String value_alias = keyValue.getString(JSON_VALUE_ALIAS_KEY); if (keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY)) defaultPosition = j; if (null != lastValue && lastValue.equals(value)) lastValuePosition = j; mAliasValueMap.put(value_alias, value); spinnerArrayAdapter.add(value_alias); } } } setSelection(lastValuePosition >= 0 ? lastValuePosition : defaultPosition); // The drop down view spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); float minHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics()); setPadding(0, (int) minHeight, 0, (int) minHeight); }
From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Summons.NewSummon.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_summon); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar);/*w w w. j a v a 2s . c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); } createNetErrorDialog(); checkWriteExternalPermission(); checkReadExternalStoragePermission(); setupIds(); // // permission for Marshmallow // checkWriteExternalPermission(); // checkReadExternalStoragePermission(); // // getRespondentSignature.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // showSignatureDialog(); // } // }); // setup Spinner id spinnerSummonType = (Spinner) findViewById(R.id.spinnerNewSummon); SpinnerBaseSummon = (Spinner) findViewById(R.id.basesummoncar); SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.GONE); summondate.setVisibility(View.GONE); TlcLicenseHack.setVisibility(View.GONE); PlateNumber.setVisibility(View.GONE); ShlPermitHolder.setVisibility(View.GONE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.GONE); MedallionNo.setVisibility(View.GONE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.GONE); HearingLocation.setVisibility(View.GONE); takePictureNewSummonImageView.setVisibility(View.GONE); takePictureComplianceImageView.setVisibility(View.GONE); addcomment.setVisibility(View.GONE); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item, stringSummonType); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerSummonType.setAdapter(adapter); ArrayAdapter<String> adapterbasesummon = new ArrayAdapter<String>(this, R.layout.spinner_item, baseSummons); adapterbasesummon.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); SpinnerBaseSummon.setAdapter(adapterbasesummon); spinnerSummonType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { switch (arg2) { case 0: SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.GONE); summondate.setVisibility(View.GONE); TlcLicenseHack.setVisibility(View.GONE); PlateNumber.setVisibility(View.GONE); ShlPermitHolder.setVisibility(View.GONE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.GONE); MedallionNo.setVisibility(View.GONE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.GONE); HearingLocation.setVisibility(View.GONE); addcomment.setVisibility(View.GONE); break; case 1: SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.VISIBLE); summondate.setVisibility(View.VISIBLE); TlcLicenseHack.setVisibility(View.VISIBLE); PlateNumber.setVisibility(View.VISIBLE); ShlPermitHolder.setVisibility(View.GONE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.GONE); MedallionNo.setVisibility(View.GONE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.GONE); HearingLocation.setVisibility(View.VISIBLE); addcomment.setVisibility(View.VISIBLE); break; case 2: SpinnerBaseSummon.setVisibility(View.VISIBLE); summonno.setVisibility(View.VISIBLE); summondate.setVisibility(View.VISIBLE); TlcLicenseHack.setVisibility(View.VISIBLE); PlateNumber.setVisibility(View.VISIBLE); ShlPermitHolder.setVisibility(View.VISIBLE); BaseNumber.setVisibility(View.VISIBLE); DiamondNo.setVisibility(View.VISIBLE); MedallionNo.setVisibility(View.GONE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.GONE); HearingLocation.setVisibility(View.VISIBLE); addcomment.setVisibility(View.VISIBLE); break; case 3: SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.VISIBLE); summondate.setVisibility(View.VISIBLE); TlcLicenseHack.setVisibility(View.VISIBLE); PlateNumber.setVisibility(View.VISIBLE); ShlPermitHolder.setVisibility(View.VISIBLE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.VISIBLE); MedallionNo.setVisibility(View.GONE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.VISIBLE); HearingLocation.setVisibility(View.VISIBLE); addcomment.setVisibility(View.VISIBLE); break; case 4: SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.VISIBLE); summondate.setVisibility(View.VISIBLE); TlcLicenseHack.setVisibility(View.VISIBLE); PlateNumber.setVisibility(View.VISIBLE); ShlPermitHolder.setVisibility(View.GONE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.GONE); MedallionNo.setVisibility(View.GONE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.GONE); HearingLocation.setVisibility(View.VISIBLE); addcomment.setVisibility(View.VISIBLE); break; case 5: SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.VISIBLE); summondate.setVisibility(View.VISIBLE); TlcLicenseHack.setVisibility(View.VISIBLE); PlateNumber.setVisibility(View.GONE); ShlPermitHolder.setVisibility(View.GONE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.GONE); MedallionNo.setVisibility(View.VISIBLE); MedallionOwner.setVisibility(View.VISIBLE); FleetMedallion.setVisibility(View.VISIBLE); ShlPermit.setVisibility(View.GONE); HearingLocation.setVisibility(View.VISIBLE); addcomment.setVisibility(View.VISIBLE); break; case 6: SpinnerBaseSummon.setVisibility(View.GONE); summonno.setVisibility(View.VISIBLE); summondate.setVisibility(View.VISIBLE); TlcLicenseHack.setVisibility(View.VISIBLE); PlateNumber.setVisibility(View.VISIBLE); ShlPermitHolder.setVisibility(View.GONE); BaseNumber.setVisibility(View.GONE); DiamondNo.setVisibility(View.GONE); MedallionNo.setVisibility(View.VISIBLE); MedallionOwner.setVisibility(View.GONE); FleetMedallion.setVisibility(View.GONE); ShlPermit.setVisibility(View.VISIBLE); HearingLocation.setVisibility(View.VISIBLE); addcomment.setVisibility(View.VISIBLE); break; default: break; } } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub myCalendar.set(Calendar.YEAR, year); myCalendar.set(Calendar.MONTH, monthOfYear); myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); updateLabel(); } }; summondate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new DatePickerDialog(NewSummon.this, date, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } }); AppearanceRequired.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.apperanceradiogroupyes) { } else { } } }); seizedCarSelectionNewSummon.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.carSeizedYesNewSummon) { } else { } } }); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { strspinnerSummonType = spinnerSummonType.getSelectedItem().toString(); strSpinnerBaseSummon = SpinnerBaseSummon.getSelectedItem().toString(); strsummonno = summonno.getText().toString(); strsummondate = summondate.getText().toString(); strTlcLicenseHack = TlcLicenseHack.getText().toString(); strPlateNumber = PlateNumber.getText().toString(); strShlPermitHolder = ShlPermitHolder.getText().toString(); strBaseNumber = BaseNumber.getText().toString(); strDiamondNo = DiamondNo.getText().toString(); strMedallionNo = MedallionNo.getText().toString(); strMedallionOwner = MedallionOwner.getText().toString(); strFleetMedallion = FleetMedallion.getText().toString(); strShlPermit = ShlPermit.getText().toString(); strHearingLocation = HearingLocation.getText().toString(); straddcoment = addcomment.getText().toString(); intseizedCar = seizedCarSelectionNewSummon.getCheckedRadioButtonId(); intAppearance = AppearanceRequired.getCheckedRadioButtonId(); seizedRadioButton = (RadioButton) findViewById(intseizedCar); AppearanceButton = (RadioButton) findViewById(intAppearance); if (strspinnerSummonType.equals("Select Your Summon")) { Toast.makeText(NewSummon.this, "Please Select Your Summons", Toast.LENGTH_SHORT).show(); } else if (strspinnerSummonType.equals("Driver Summon")) { if (strsummonno.equals("")) { summonno.setError("Please Enter Summon Number"); } else if (strsummondate.equals("")) { summondate.setError("Please Enter Summon Date"); } else if (strTlcLicenseHack.equals("")) { TlcLicenseHack.setError("Please Enter TLC License Number "); } else if (strPlateNumber.equals("")) { PlateNumber.setError("Please Enter Plate Number"); } else if (strHearingLocation.equals("")) { HearingLocation.setError("Please Enter Hearing Location"); } else if (AppearanceRequired.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Appearance Required) Radio Button", Toast.LENGTH_SHORT).show(); } else if (seizedCarSelectionNewSummon.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Car Seized) Radio Button", Toast.LENGTH_SHORT).show(); } else if (takePictureNewSummonImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Summon Image", Toast.LENGTH_SHORT) .show(); } else if (takePictureComplianceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Compliance Image", Toast.LENGTH_SHORT).show(); } else { getTextSeized = seizedRadioButton.getText().toString(); getTextAppearance = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); sharedPreferences = getSharedPreferences("getuserid", 2); String email = sharedPreferences.getString(emailkey, null); String Userid = sharedPreferences.getString(userID, null); Log.d("", "email " + email); Log.d("", "userid " + Userid); message = "User Email: " + email + "\n \nSelected Summon: " + strspinnerSummonType + "\nSummon Number: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nPlate Number / Medallion: " + strPlateNumber + "\nCar Seized: " + getTextSeized; //new SendEmail().execute(); new driversummon().execute(); // UploadImage ui1 = new UploadImage(); // ui1.execute(bitmap1); Log.d("abc", "onClick: 1"); } } else if (strspinnerSummonType.equals("Base Summon")) { if (strSpinnerBaseSummon.equals("Select Your Base Car")) { Toast.makeText(NewSummon.this, "Please Select Your Base Car", Toast.LENGTH_SHORT).show(); } else if (strsummonno.equals("")) { summonno.setError("Please Enter Summon Number"); } else if (strsummondate.equals("")) { summondate.setError("Please Enter Summon Date"); } else if (strTlcLicenseHack.equals("")) { TlcLicenseHack.setError("Please Enter TLC License Number "); } else if (strPlateNumber.equals("")) { PlateNumber.setError("Please Enter Plate Number"); } else if (strShlPermitHolder.equals("")) { ShlPermitHolder.setError("Please Enter SHL Permit Holder"); } else if (strBaseNumber.equals("")) { BaseNumber.setError("Please Enter Base Number"); } else if (strDiamondNo.equals("")) { DiamondNo.setError("Please Enter Diamond Number"); } else if (strHearingLocation.equals("")) { HearingLocation.setError("Please Enter Hearing Location"); } else if (AppearanceRequired.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Appearance Required) Radio Button", Toast.LENGTH_SHORT).show(); } else if (seizedCarSelectionNewSummon.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Car Seized) Radio Button", Toast.LENGTH_SHORT).show(); } else if (takePictureNewSummonImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Summon Image", Toast.LENGTH_SHORT) .show(); } else if (takePictureComplianceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Compliance Image", Toast.LENGTH_SHORT).show(); } else { getTextSeized = seizedRadioButton.getText().toString(); getTextAppearance = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); String email = sharedPreferences.getString(emailkey, null); message = "User Email: " + email + "\n\nSelected Summon: " + strspinnerSummonType + "\nSelected Base Summon: " + strSpinnerBaseSummon + "\nSummon Number: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nPlate Number / Medallion: " + strPlateNumber + "\nSHL Permit Holder: " + strShlPermitHolder + "\nBase Number: " + strBaseNumber + "\nDiamond Number: " + strDiamondNo + "\nHearing Location: " + strHearingLocation + "\nCar Seized: " + getTextSeized; //new SendEmail().execute(); new basesummon().execute(); Log.d("abc", "onClick: 2"); } } else if (strspinnerSummonType.equals("SHL Summon")) { if (strsummonno.equals("")) { summonno.setError("Please Enter Summon Number"); } else if (strsummondate.equals("")) { summondate.setError("Please Enter Summon Date"); } else if (strTlcLicenseHack.equals("")) { TlcLicenseHack.setError("Please Enter TLC License Number "); } else if (strPlateNumber.equals("")) { PlateNumber.setError("Please Enter Plate Number"); } else if (strShlPermitHolder.equals("")) { ShlPermitHolder.setError("Please Enter SHL Permit Holder"); } else if (strDiamondNo.equals("")) { DiamondNo.setError("Please Enter Diamond Number"); } else if (strShlPermit.equals("")) { ShlPermit.setError("Please Enter SHL Permit"); } else if (strHearingLocation.equals("")) { HearingLocation.setError("Please Enter Hearing Location"); } else if (AppearanceRequired.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Appearance Required) Radio Button", Toast.LENGTH_SHORT).show(); } else if (seizedCarSelectionNewSummon.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Car Seized) Radio Button", Toast.LENGTH_SHORT).show(); } else if (takePictureNewSummonImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Summon Image", Toast.LENGTH_SHORT) .show(); } else if (takePictureComplianceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Compliance Image", Toast.LENGTH_SHORT).show(); } else { getTextSeized = seizedRadioButton.getText().toString(); getTextAppearance = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); String email = sharedPreferences.getString(emailkey, null); message = "User Email: " + email + "\n\nSelected Summon: " + strspinnerSummonType + "\nSelected Base Summon: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nPlate Number / Medallion: " + strPlateNumber + "\nSHL Permit Holder: " + strShlPermitHolder + "\nDiamond Number: " + strDiamondNo + "\nSHL Permit: " + strShlPermit + "\nHearing Location: " + strHearingLocation + "\nCar Seized: " + getTextSeized; //new SendEmail().execute(); new shlsummon().execute(); } } else if (strspinnerSummonType.equals("FHV Summon")) { if (strsummonno.equals("")) { summonno.setError("Please Enter Summon Number"); } else if (strsummondate.equals("")) { summondate.setError("Please Enter Summon Date"); } else if (strTlcLicenseHack.equals("")) { TlcLicenseHack.setError("Please Enter TLC License Number "); } else if (strPlateNumber.equals("")) { PlateNumber.setError("Please Enter Plate Number"); } else if (strHearingLocation.equals("")) { HearingLocation.setError("Please Enter Hearing Location"); } else if (AppearanceRequired.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Appearance Required) Radio Button", Toast.LENGTH_SHORT).show(); } else if (seizedCarSelectionNewSummon.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Car Seized) Radio Button", Toast.LENGTH_SHORT).show(); } else if (takePictureNewSummonImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Summon Image", Toast.LENGTH_SHORT) .show(); } else if (takePictureComplianceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Compliance Image", Toast.LENGTH_SHORT).show(); } else { getTextSeized = seizedRadioButton.getText().toString(); getTextAppearance = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); String email = sharedPreferences.getString(emailkey, null); message = "User Email: " + email + "\n\nSelected Summon: " + strspinnerSummonType + "\nSummon Number: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nPlate Number / Medallion: " + strPlateNumber + "\nHearing Location: " + strHearingLocation + "\nCar Seized: " + getTextSeized; //new SendEmail().execute(); new fhvsummon().execute(); } } else if (strspinnerSummonType.equals("Medallion/Yellow Cab")) { if (strsummonno.equals("")) { summonno.setError("Please Enter Summon Number"); } else if (strsummondate.equals("")) { summondate.setError("Please Enter Summon Date"); } else if (strTlcLicenseHack.equals("")) { TlcLicenseHack.setError("Please Enter TLC License Number "); } else if (strMedallionNo.equals("")) { MedallionNo.setError("Please Enter Medallion Number"); } else if (strMedallionOwner.equals("")) { MedallionOwner.setError("Please Enter Medallion Owner Name"); } else if (strFleetMedallion.equals("")) { FleetMedallion.setError("Please Enter Fleet / Medallion Name"); } else if (strHearingLocation.equals("")) { HearingLocation.setError("Please Enter Hearing Location"); } else if (AppearanceRequired.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Appearance Required) Radio Button", Toast.LENGTH_SHORT).show(); } else if (seizedCarSelectionNewSummon.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Car Seized) Radio Button", Toast.LENGTH_SHORT).show(); } else if (takePictureNewSummonImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Summon Image", Toast.LENGTH_SHORT) .show(); } else if (takePictureComplianceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Compliance Image", Toast.LENGTH_SHORT).show(); } else { getTextSeized = seizedRadioButton.getText().toString(); getTextAppearance = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); String email = sharedPreferences.getString(emailkey, null); message = "User Email: " + email + "\n\nSelected Summon: " + strspinnerSummonType + "\nSummon Number: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nMedallion Number: " + strMedallionNo + "\nMedallion Owner: " + strMedallionOwner + "\nFleet Medallion : " + strFleetMedallion + "\nHearing Location: " + strHearingLocation + "\nCar Seized: " + getTextSeized; //new SendEmail().execute(); new medallionyellowcab().execute(); Log.d("abc", "onClick: 5"); } } else if (strspinnerSummonType.equals("Corporation")) { if (strsummonno.equals("")) { summonno.setError("Please Enter Summon Number"); } else if (strsummondate.equals("")) { summondate.setError("Please Enter Summon Date"); } else if (strTlcLicenseHack.equals("")) { TlcLicenseHack.setError("Please Enter TLC License Number "); } else if (strPlateNumber.equals("")) { PlateNumber.setError("Please Enter Plate Number"); } else if (strMedallionNo.equals("")) { MedallionNo.setError("Please Enter Medallion Number"); } else if (strShlPermit.equals("")) { ShlPermit.setError("Please Enter SHL Permit"); } else if (strHearingLocation.equals("")) { HearingLocation.setError("Please Enter Hearing Location"); } else if (AppearanceRequired.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Appearance Required) Radio Button", Toast.LENGTH_SHORT).show(); } else if (seizedCarSelectionNewSummon.getCheckedRadioButtonId() == -1) { Toast.makeText(NewSummon.this, "Please Select (Car Seized) Radio Button", Toast.LENGTH_SHORT).show(); } else if (takePictureNewSummonImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Summon Image", Toast.LENGTH_SHORT) .show(); } else if (takePictureComplianceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Compliance Image", Toast.LENGTH_SHORT).show(); } else { getTextSeized = seizedRadioButton.getText().toString(); getTextAppearance = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); String email = sharedPreferences.getString(emailkey, null); message = "User Email: " + email + "\n\nSelected Summon: " + strspinnerSummonType + "\nSummon Number: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nPlate Number / Medallion: " + strPlateNumber + "\nMedallion Number: " + strMedallionNo + "\nSHL Permit: " + strShlPermit + "\nHearing Location: " + strHearingLocation + "\nCar Seized: " + getTextSeized; //new SendEmail().execute(); new corporation().execute(); Log.d("abc", "onClick: 6"); } } /*else { getTextSeized = seizedRadioButton.getText().toString(); sharedPreferences = getSharedPreferences("email" , 1); String email = sharedPreferences.getString(emailkey , null); if(!email.equals(null)) { message = "User Email: " +email + "\n\nSelected Summon: " + strspinnerSummonType+ "\nSelected Base Summon: " + strSpinnerBaseSummon + "\nSummon Number: " + strsummonno + "\nDate of Summon: " + strsummondate + "\nTLC License No: " + strTlcLicenseHack + "\nPlate Number / Medallion: " + strPlateNumber + "\nSHL Permit Holder: " + strShlPermitHolder + "Base Number: " + strBaseNumber+ "\nDiamond Number: " + strDiamondNo + "\nMedallion Number: " + strMedallionNo + "\nMedallion Owner: " + strMedallionOwner + "\nFleet Medallion : " + strFleetMedallion + "\nSHL Permit: " + strShlPermit + "\nHearing Location: " + strHearingLocation + "\nCar Seized: " + getTextSeized; new SendEmail().execute(); } //Toast.makeText(NewSummon.this, "" +message, Toast.LENGTH_SHORT).show(); // Intent intent = new Intent(NewSummon.this , ThankYouScreen.class); // startActivity(intent); }*/ } }); }
From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.TlcInsurance.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tlc_insurance); checkWriteExternalPermission();/* ww w. ja v a 2 s. c o m*/ checkReadExternalStoragePermission(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } createNetErrorDialog(); tlcDatabase = new TlcDatabase(this); showDialogForGettingUserDataFromSignUp(); setUpIds(); DriverLicenceImageView.setVisibility(View.GONE); SSCardImageView.setVisibility(View.GONE); BaseLetterImageView.setVisibility(View.GONE); UtilityBillsImageView.setVisibility(View.GONE); MVTitleImageView.setVisibility(View.GONE); SixhrDrivingClassImageView.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); IsPermitOwnedImageView.setVisibility(View.GONE); CertificateCorporationImageView.setVisibility(View.GONE); FillingReciptImageView.setVisibility(View.GONE); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item, carTypes); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); carType.setAdapter(adapter); //final int pos = carType.getSelectedItemPosition(); st = carType.getSelectedItemPosition(); carType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { switch (arg2) { case 0: einnum.setVisibility(View.GONE); ownername.setVisibility(View.GONE); SHlPermitCopy.setVisibility(View.GONE); SHLPermitReceipt.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); break; case 1: einnum.setVisibility(View.GONE); ownername.setVisibility(View.GONE); SHlPermitCopy.setVisibility(View.GONE); SHLPermitReceipt.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); break; case 2: einnum.setVisibility(View.GONE); ownername.setVisibility(View.GONE); SHlPermitCopy.setVisibility(View.GONE); SHLPermitReceipt.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); break; case 3: einnum.setVisibility(View.GONE); ownername.setVisibility(View.GONE); SHlPermitCopy.setVisibility(View.GONE); SHLPermitReceipt.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); break; case 4: einnum.setVisibility(View.GONE); ownername.setVisibility(View.GONE); SHlPermitCopy.setVisibility(View.GONE); SHLPermitReceipt.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); break; case 5: einnum.setVisibility(View.VISIBLE); ownername.setVisibility(View.VISIBLE); SHlPermitCopy.setVisibility(View.GONE); SHLPermitReceipt.setVisibility(View.GONE); SHlPermitCopyImageView.setVisibility(View.GONE); SHLPermitReceiptImageView.setVisibility(View.GONE); break; default: break; } } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); DriverLicence.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = licenseButton; } }); SSCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = ssCardButton; } }); BaseLetter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = baseLetterButton; } }); UtilityBills.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = utilityBillsbutton; } }); MVTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = mvTitlebutton; } }); SixhrDrivingClass.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = sixhrdrivingbutton; } }); SHlPermitCopy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = shlPermitbutton; } }); SHLPermitReceipt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = shlpermitreceiptbutton; } }); IsPermitOwned.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = ispermitownedbutton; } }); CertificateCorporation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = certificatebutton; } }); FillingRecipt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectImage(); btnClicked = fillingbutton; } }); final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub myCalendar.set(Calendar.YEAR, year); myCalendar.set(Calendar.MONTH, monthOfYear); myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); updateLabel(); } }; dob.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new DatePickerDialog(TlcInsurance.this, date, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } }); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // boolean result = tlcDatabase.insertDataInTlcInsurance(fullname.getText().toString(), address.getText().toString(), dob.getText().toString(), // driverLicense.getText().toString(), tlcLicense.getText().toString(), phoneNum.getText().toString(), // email.getText().toString(), vinnum.getText().toString(),socialSecurtiyNumber.getText().toString(),carMake.getText().toString(), // carModel.getText().toString(),carYear.getText().toString(),einnum.getText().toString(),ownername.getText().toString()); // if (result) // Toast.makeText(TlcInsurance.this, "Data Submited successfully", Toast.LENGTH_LONG).show(); // else // Toast.makeText(TlcInsurance.this, "Data not Submited successfully", Toast.LENGTH_LONG).show(); strfullname = fullname.getText().toString(); straddress = address.getText().toString(); strzipcode = Zipcode.getText().toString(); strdob = dob.getText().toString(); strdriverLicense = driverLicense.getText().toString(); strtlcLicense = tlcLicense.getText().toString(); strphoneNum = phoneNum.getText().toString(); stremail = email.getText().toString(); strvinnum = vinnum.getText().toString(); strsocialSecurtiyNumber = socialSecurtiyNumber.getText().toString(); strAddComment = AddComment.getText().toString(); strcarType = carType.getSelectedItem().toString(); streinnum = einnum.getText().toString(); strownername = ownername.getText().toString(); strcarMake = carMake.getText().toString(); strcarModel = carModel.getText().toString(); strcarYear = carYear.getText().toString(); intIsPermitRadioGroup = IsPermitRadioGroup.getCheckedRadioButtonId(); PermitRadioGroup = (RadioButton) findViewById(intIsPermitRadioGroup); intIsCabPolicyRadioGroup = IsCabPolicyRadioGroup.getCheckedRadioButtonId(); CabPolicyRadioGroup = (RadioButton) findViewById(intIsCabPolicyRadioGroup); intNeedFullCoverage = NeedFullCoverage.getCheckedRadioButtonId(); NeedFullCoverageis = (RadioButton) findViewById(intNeedFullCoverage); strTaxID = TaxID.getText().toString(); if (strfullname.equals("")) { fullname.setError("Please Enter Full Name"); } else if (straddress.equals("")) { address.setError("Please Enter Full Address"); } else if (strzipcode.equals("")) { Zipcode.setError("Please Enter Zip Code"); } else if (strdob.equals("")) { dob.setError("Please Enter Date of Birth"); } else if (strdriverLicense.equals("")) { driverLicense.setError("Please Enter DMV License"); } else if (strtlcLicense.equals("")) { tlcLicense.setError("Please Enter TLC License"); } else if (strphoneNum.equals("")) { phoneNum.setError("Please Enter Phone Number"); } else if (stremail.equals("")) { email.setError("Please Enter Email Address"); } else if (strsocialSecurtiyNumber.equals("")) { socialSecurtiyNumber.setError("Please Enter Social Security Number"); } else if (strvinnum.equals("")) { vinnum.setError("Please Enter VIN Number"); } else if (DriverLicenceImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Driver License Image", Toast.LENGTH_SHORT).show(); } else if (SSCardImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload SS Card Image", Toast.LENGTH_SHORT) .show(); } else if (BaseLetterImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Base Letter Image", Toast.LENGTH_SHORT) .show(); } else if (UtilityBillsImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Utility Bills Image", Toast.LENGTH_SHORT) .show(); } else if (MVTitleImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please MV50/Title Letter Image", Toast.LENGTH_SHORT) .show(); } else if (SixhrDrivingClassImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Six HR Driving Class Image", Toast.LENGTH_SHORT).show(); } else if (strcarType.equals("Type of Car")) { Toast.makeText(getApplicationContext(), "Please (Select Type of) Car Drop Down Menu", Toast.LENGTH_SHORT).show(); } else if (strcarType.equals("Corporation") && streinnum.length() == 0) { einnum.setError("Please Enter EIN Number"); } else if (strcarType.equals("Corporation") && strownername.length() == 0) { ownername.setError("Please Enter Owner Name"); } else if (IsPermitRadioGroup.getCheckedRadioButtonId() == -1) { Toast.makeText(getApplicationContext(), "Please Select Is Permit Owned Radio Button", Toast.LENGTH_SHORT).show(); } else if (PermitRadioGroup.getText().equals("No") && IsPermitOwnedImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Power Attorney Image", Toast.LENGTH_SHORT).show(); } else if (IsCabPolicyRadioGroup.getCheckedRadioButtonId() == -1) { Toast.makeText(getApplicationContext(), "Please Select Is Cab Policy Radio Button", Toast.LENGTH_SHORT).show(); } else if (CabPolicyRadioGroup.getText().equals("Yes") && CertificateCorporationImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Certificate of Incorporation Image", Toast.LENGTH_SHORT).show(); } else if (CabPolicyRadioGroup.getText().equals("Yes") && FillingReciptImageView.getDrawable() == null) { Toast.makeText(getApplicationContext(), "Please Upload Filling Receipt Image", Toast.LENGTH_SHORT).show(); } else if (CabPolicyRadioGroup.getText().equals("Yes") && strTaxID.equals("")) { TaxID.setError("Please Enter Tax ID/EIN number"); } else if (NeedFullCoverage.getCheckedRadioButtonId() == -1) { Toast.makeText(getApplicationContext(), "Please Select Need Full Coverage Radio Button", Toast.LENGTH_SHORT).show(); } else { getTExtPermitRadioGroup = PermitRadioGroup.getText().toString(); getTextCabPolicyRadioGroup = CabPolicyRadioGroup.getText().toString(); getTExtNeedFullCoverageis = NeedFullCoverageis.getText().toString(); sharedPreferences = getSharedPreferences("email", 1); String email = sharedPreferences.getString(emailkey, null); message = "User Email: " + email + "\n\nFull Name : " + strfullname + "\nAddress : " + straddress + "\nAddress Zip Code: " + strzipcode + "\nData of Birth : " + strdob + "\nDMV License : " + strdriverLicense + "\nTlc License : " + strtlcLicense + "\nPhone Number : " + strphoneNum + "Email : " + stremail + "\nVIN Number : " + strvinnum + "\nSocial Security Number : " + strsocialSecurtiyNumber + "\nSelected Car Type " + strcarType + "\nEIN Number : " + streinnum + "\nOwner Name : " + strownername + "\nCar Make :" + strcarMake + "\nCar Model :" + strcarModel + "\nCar Year :" + strcarYear + "Tax ID: " + strTaxID + "\nIs Permit Owned :" + getTExtPermitRadioGroup + "\nIs Cab Policy :" + getTextCabPolicyRadioGroup + "\nNeed Full Coverage :" + getTExtNeedFullCoverageis; //new SendEmail().execute(); new uploadData().execute(); } //Toast.makeText(TlcInsurance.this, "aslfkafa", Toast.LENGTH_SHORT).show(); // UploadImage ui1 = new UploadImage(); // ui1.execute(bitmap1); // } }); IsPermitOwned.setVisibility(View.GONE); //IsPermitOwnedImageView.setVisibility(View.GONE); IsPermitRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.ispermitownedno) { IsPermitOwned.setVisibility(View.VISIBLE); //IsPermitOwnedImageView.setVisibility(View.VISIBLE); } else { IsPermitOwned.setVisibility(View.GONE); IsPermitOwnedImageView.setVisibility(View.GONE); } } }); CertificateCorporation.setVisibility(View.GONE); // CertificateCorporationImageView.setVisibility(View.GONE); FillingRecipt.setVisibility(View.GONE); // FillingReciptImageView.setVisibility(View.GONE); TaxID.setVisibility(View.GONE); IsCabPolicyRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.cabpolicyyes) { CertificateCorporation.setVisibility(View.VISIBLE); // CertificateCorporationImageView.setVisibility(View.VISIBLE); FillingRecipt.setVisibility(View.VISIBLE); //FillingReciptImageView.setVisibility(View.VISIBLE); TaxID.setVisibility(View.VISIBLE); } else { CertificateCorporation.setVisibility(View.GONE); CertificateCorporationImageView.setVisibility(View.GONE); FillingRecipt.setVisibility(View.GONE); FillingReciptImageView.setVisibility(View.GONE); TaxID.setVisibility(View.GONE); } } }); }
From source file:foam.starwisp.StarwispBuilder.java
public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) { if (StarwispLinearLayout.m_DisplayMetrics == null) { StarwispLinearLayout.m_DisplayMetrics = ctx.getResources().getDisplayMetrics(); }//from w ww .jav a 2s . c o m try { String type = arr.getString(0); //Log.i("starwisp","building started "+type); if (type.equals("build-fragment")) { String name = arr.getString(1); int ID = arr.getInt(2); Fragment fragment = ActivityManager.GetFragment(name); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); inner.setId(ID); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, fragment); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("map")) { int ID = arr.getInt(1); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); inner.setId(ID); Fragment mapfrag = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, mapfrag); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("drawmap")) { final LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); DrawableMap dm = new DrawableMap(); dm.init(arr.getInt(1), inner, (StarwispActivity) ctx, this, arr.getString(3)); parent.addView(inner); m_DMaps.put(arr.getInt(1), dm); return; } if (type.equals("linear-layout")) { StarwispLinearLayout.Build(this, ctx, ctxname, arr, parent); return; } if (type.equals("relative-layout")) { StarwispRelativeLayout.Build(this, ctx, ctxname, arr, parent); return; } if (type.equals("draggable")) { final LinearLayout v = new LinearLayout(ctx); final int id = arr.getInt(1); final String behaviour_type = arr.getString(5); v.setPadding(20, 20, 20, 10); v.setId(id); v.setOrientation(StarwispLinearLayout.BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setClickable(true); v.setFocusable(true); JSONArray col = arr.getJSONArray(4); v.setBackgroundResource(R.drawable.draggable); GradientDrawable drawable = (GradientDrawable) v.getBackground(); final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)); drawable.setColor(colour); /*LayerDrawable bgDrawable = (LayerDrawable)v.getBackground(); GradientDrawable bgShape = (GradientDrawable)bgDrawable.findDrawableByLayerId(R.id.draggableshape); bgShape.setColor(colour);*/ /*v.getBackground().setColorFilter(colour, PorterDuff.Mode.MULTIPLY);*/ parent.addView(v); JSONArray children = arr.getJSONArray(6); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface if (!behaviour_type.equals("drop-only") && !behaviour_type.equals("drop-only-consume")) { v.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View vv) { if (id != 99) { ClipData dragData = new ClipData( new ClipDescription("" + id, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }), new ClipData.Item("" + id)); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp", "start drag id " + vv.getId() + " " + v); v.startDrag(dragData, myShadow, v, 0); v.setVisibility(View.GONE); return true; } return false; } }); } if (!behaviour_type.equals("drag-only")) { // ye gads - needed as drag/drop doesn't deal with nested targets final StarwispBuilder that = this; v.setOnDragListener(new View.OnDragListener() { public boolean onDrag(View vv, DragEvent event) { //Log.i("starwisp","on drag event happened"); final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: //Log.i("starwisp","Drag started"+v ); if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { // returns true to indicate that the View can accept the dragged data. return true; } else { // Returns false. During the current drag and drop operation, this View will // not receive events again until ACTION_DRAG_ENDED is sent. return false; } case DragEvent.ACTION_DRAG_ENTERED: { if (that.m_LastDragHighlighted != null) { that.m_LastDragHighlighted.getBackground().setColorFilter(null); } v.getBackground().setColorFilter(0x77777777, PorterDuff.Mode.MULTIPLY); that.m_LastDragHighlighted = v; //Log.i("starwisp","Drag entered"+v ); return true; } case DragEvent.ACTION_DRAG_LOCATION: { //View dragee = (View)event.getLocalState(); //dragee.setVisibility(View.VISIBLE); //Log.i("starwisp","Drag location"+v ); return true; } case DragEvent.ACTION_DRAG_EXITED: { //Log.i("starwisp","Drag exited "+v ); v.getBackground().setColorFilter(null); return true; } case DragEvent.ACTION_DROP: { v.getBackground().setColorFilter(null); //Log.i("starwisp","Drag dropped "+v ); View otherw = (View) event.getLocalState(); //Log.i("starwisp","removing from parent "+((View)otherw.getParent()).getId()); // check we are not adding to ourself if (id != otherw.getId()) { ((ViewManager) otherw.getParent()).removeView(otherw); //Log.i("starwisp","adding to " + id); if (!behaviour_type.equals("drop-only-consume")) { v.addView(otherw); } } otherw.setVisibility(View.VISIBLE); return true; } case DragEvent.ACTION_DRAG_ENDED: { //Log.i("starwisp","Drag ended "+v ); v.getBackground().setColorFilter(null); View dragee = (View) event.getLocalState(); dragee.setVisibility(View.VISIBLE); if (event.getResult()) { //Log.i("starwisp","sucess " ); } else { //Log.i("starwisp","fail " ); } ; return true; } // An unknown action type was received. default: //Log.e("starwisp","Unknown action type received by OnDragListener."); break; } ; return true; } }); return; } } if (type.equals("frame-layout")) { FrameLayout v = new FrameLayout(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } /* if (type.equals("grid-layout")) { GridLayout v = new GridLayout(ctx); v.setId(arr.getInt(1)); v.setRowCount(arr.getInt(2)); //v.setColumnCount(arr.getInt(2)); v.setOrientation(BuildOrientation(arr.getString(3))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } return; } */ if (type.equals("scroll-view")) { HorizontalScrollView v = new HorizontalScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("scroll-view-vert")) { ScrollView v = new ScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("view-pager")) { ViewPager v = new ViewPager(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.setOffscreenPageLimit(3); final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing fragment data " + e.toString()); } return null; } }); parent.addView(v); return; } if (type.equals("space")) { // Space v = new Space(ctx); (class not found runtime error??) TextView v = new TextView(ctx); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); } if (type.equals("image-view")) { ImageView v = new ImageView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setAdjustViewBounds(true); String image = arr.getString(2); if (image.startsWith("/")) { Bitmap b = BitmapCache.Load(image); if (b != null) { v.setImageBitmap(b); } } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } parent.addView(v); } if (type.equals("image-button")) { ImageButton v = new ImageButton(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); String image = arr.getString(2); if (image.startsWith("/")) { v.setImageBitmap(BitmapCache.Load(image)); } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } final String fn = arr.getString(4); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); v.setAdjustViewBounds(true); v.setScaleType(ImageView.ScaleType.CENTER_INSIDE); parent.addView(v); } if (type.equals("text-view")) { TextView v = new TextView(ctx); v.setId(arr.getInt(1)); v.setText(Html.fromHtml(arr.getString(2)), BufferType.SPANNABLE); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setLinkTextColor(0xff00aa00); // uncomment all this to get hyperlinks to work in text... // should make this an option of course //v.setClickable(true); // make links //v.setMovementMethod(LinkMovementMethod.getInstance()); //v.setEnabled(true); // go to browser /*v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { return false; } };*/ if (arr.length() > 5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.CENTER); } v.setTypeface(((StarwispActivity) ctx).m_Typeface); parent.addView(v); } if (type.equals("debug-text-view")) { TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null); // v.setBackgroundResource(R.color.black); v.setId(arr.getInt(1)); // v.setText(Html.fromHtml(arr.getString(2))); // v.setTextColor(R.color.white); // v.setTextSize(arr.getInt(3)); // v.setMovementMethod(LinkMovementMethod.getInstance()); // v.setMaxLines(10); // v.setVerticalScrollBarEnabled(true); // v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); //v.setMovementMethod(new ScrollingMovementMethod()); /* if (arr.length()>5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/ parent.addView(v); } if (type.equals("web-view")) { WebView v = new WebView(ctx); v.setId(arr.getInt(1)); v.setVerticalScrollBarEnabled(false); v.loadData(arr.getString(2), "text/html", "utf-8"); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); parent.addView(v); } if (type.equals("edit-text")) { final EditText v = new EditText(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setGravity(Gravity.LEFT | Gravity.TOP); String inputtype = arr.getString(4); if (inputtype.equals("text")) { //v.setInputType(InputType.TYPE_CLASS_TEXT); } else if (inputtype.equals("numeric")) { v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); } else if (inputtype.equals("email")) { v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS); } v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); //v.setSingleLine(true); v.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\""); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); parent.addView(v); } if (type.equals("button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("colour-button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); JSONArray col = arr.getJSONArray(6); v.getBackground().setColorFilter( Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)), PorterDuff.Mode.MULTIPLY); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("toggle-button")) { ToggleButton v = new ToggleButton(ctx); if (arr.getString(5).equals("fancy")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null); } if (arr.getString(5).equals("yes")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null); } if (arr.getString(5).equals("maybe")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null); } if (arr.getString(5).equals("no")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null); } v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, v.getId(), arg); } }); parent.addView(v); } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); v.setId(arr.getInt(1)); v.setMax(arr.getInt(2)); v.setProgress(arr.getInt(2) / 2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); final String fn = arr.getString(4); v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar v, int a, boolean s) { CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a)); } public void onStartTrackingTouch(SeekBar v) { } public void onStopTrackingTouch(SeekBar v) { } }); parent.addView(v); } if (type.equals("spinner")) { Spinner v = new Spinner(ctx); final int wid = arr.getInt(1); v.setId(wid); final JSONArray items = arr.getJSONArray(2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setMinimumWidth(100); // stops tiny buttons ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { CallbackArgs(ctx, ctxname, wid, "" + pos); } public void onNothingSelected(AdapterView<?> v) { } }); parent.addView(v); } if (type.equals("nomadic")) { final int wid = arr.getInt(1); NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); Log.e("starwisp", "built the thing"); parent.addView(v); Log.e("starwisp", "addit to the view"); } if (type.equals("canvas")) { StarwispCanvas v = new StarwispCanvas(ctx); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.SetDrawList(arr.getJSONArray(3)); parent.addView(v); } if (type.equals("camera-preview")) { PictureTaker pt = new PictureTaker(); CameraPreview v = new CameraPreview(ctx, pt); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); Log.i("starwisp", "in camera-preview..."); List<List<String>> info = v.mPictureTaker.GetInfo(); // can't find a way to do this via a callback yet String arg = "'("; for (List<String> e : info) { arg += "(" + e.get(0) + " " + e.get(1) + ")"; //Log.i("starwisp","converting prop "+arg); } arg += ")"; m_Scheme.eval("(set! camera-properties " + arg + ")"); } if (type.equals("button-grid")) { LinearLayout horiz = new LinearLayout(ctx); final int id = arr.getInt(1); final String buttontype = arr.getString(2); horiz.setId(id); horiz.setOrientation(LinearLayout.HORIZONTAL); parent.addView(horiz); int height = arr.getInt(3); int textsize = arr.getInt(4); LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5)); JSONArray buttons = arr.getJSONArray(6); int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } } } } catch (JSONException e) { Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString()); } //Log.i("starwisp","building ended"); }
From source file:dynamite.zafroshops.app.fragment.OpeningsDialogFragment.java
@NonNull @Override/*w ww . ja v a 2 s. c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { data = (ArrayList<MobileOpeningHourData>) getArguments().get(NEW_ZOP_OPENINGS); tempData = new ArrayList(); for (int i = 0; i < data.size(); i++) { tempData.add(data.get(i).Copy()); } // set spinners ArrayAdapter<String> openingsDayAdapter; ArrayAdapter<String> openingsHoursAdapter; ArrayAdapter<String> openingsMinutesAdapter; Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.openings_dialog, null); builder.setView(view).setTitle(R.string.openings_editing) .setPositiveButton(R.string.button_submit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { data.clear(); for (int i = 0; i < tempData.size(); i++) { data.add(tempData.get(i).Copy()); } Intent intent = new Intent(); intent.putExtra(NEW_ZOP_OPENINGS_COUNT_KEY, OpeningsDialogFragment.this.data.size()); getTargetFragment().onActivityResult(getTargetRequestCode(), NEW_ZOP_OPENINGS_RESULT_CODE, intent); } }).setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); final Spinner ohd = (Spinner) view.findViewById(R.id.openingsDay); final Spinner ohsh = (Spinner) view.findViewById(R.id.openingsStartHour); final Spinner ohsm = (Spinner) view.findViewById(R.id.openingsStartMinute); final Spinner oheh = (Spinner) view.findViewById(R.id.openingsEndHour); final Spinner ohem = (Spinner) view.findViewById(R.id.openingsEndMinute); if (days == null) { days = new ArrayList(); for (int i = 0; i < 7; i++) { try { days.add(getString(R.string.class.getField("day" + i).getInt(null))); } catch (IllegalAccessException ignored) { } catch (NoSuchFieldException e) { } } } if (hours == null) { hours = new ArrayList(); for (int i = 0; i < 24; i++) { hours.add(String.format("%02d", i)); } } if (minutes == null) { minutes = new ArrayList(); for (int i = 0; i < 4; i++) { minutes.add(String.format("%02d", i * 15)); } } openingsDayAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, days); openingsDayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ohd.setAdapter(openingsDayAdapter); openingsHoursAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, hours); openingsHoursAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ohsh.setAdapter(openingsHoursAdapter); oheh.setAdapter(openingsHoursAdapter); openingsMinutesAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, minutes); openingsMinutesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ohsm.setAdapter(openingsMinutesAdapter); ohem.setAdapter(openingsMinutesAdapter); // set current openings openingHoursContainer = (LinearLayout) view.findViewById(R.id.openingHours); openingHoursLabel = (TextView) view.findViewById(R.id.openingHoursLabel); openingHoursDeleteButton = (Button) view.findViewById(R.id.openingsHoursDelete); ZopItemFragment.setOpeningsList(tempData, openingHoursContainer, inflater, openingHoursLabel); // set buttons view.findViewById(R.id.openingsHoursAdd).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // get data final int position = ohd.getSelectedItemPosition(); MobileOpeningHourData item = null; try { item = Iterables.find(tempData, new Predicate<MobileOpeningHourData>() { @Override public boolean apply(MobileOpeningHourData input) { return input.Day == position; } }); } catch (NoSuchElementException ignored) { } // update data if (item == null) { item = new MobileOpeningHourData((byte) position); tempData.add(item); } final MobileOpeningHour moh = new MobileOpeningHour(); moh.StartTimeHour = (byte) ohsh.getSelectedItemPosition(); moh.StartTimeMinute = (byte) (ohsm.getSelectedItemPosition() * 15); moh.EndTimeHour = (byte) oheh.getSelectedItemPosition(); moh.EndTimeMinute = (byte) (ohem.getSelectedItemPosition() * 15); MobileOpeningHour temp = null; try { temp = Iterables.find(item.Hours, new Predicate<MobileOpeningHour>() { @Override public boolean apply(MobileOpeningHour input) { return input.compareTo(moh) == 0; } }); } catch (NoSuchElementException ignored) { } if (temp == null) { item.Hours.add(moh); } // sort data Collections.sort(item.Hours); Collections.sort(tempData); // update view ZopItemFragment.setOpeningsList(tempData, openingHoursContainer, inflater, openingHoursLabel); openingHoursDeleteButton.setEnabled(true); } }); openingHoursDeleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // get data final int position = ohd.getSelectedItemPosition(); MobileOpeningHourData item = null; try { item = Iterables.find(tempData, new Predicate<MobileOpeningHourData>() { @Override public boolean apply(MobileOpeningHourData input) { return input.Day == position; } }); } catch (NoSuchElementException ignored) { } // update data if (item != null) { tempData.remove(item); openingHoursDeleteButton.setEnabled(false); } // update view ZopItemFragment.setOpeningsList(tempData, openingHoursContainer, inflater, openingHoursLabel); } }); ohd.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, final int position, long id) { MobileOpeningHourData item = null; // get data try { item = Iterables.find(tempData, new Predicate<MobileOpeningHourData>() { @Override public boolean apply(MobileOpeningHourData input) { return input.Day == position; } }); } catch (NoSuchElementException ignored) { } // update view if (item != null) { openingHoursDeleteButton.setEnabled(true); } else { openingHoursDeleteButton.setEnabled(false); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); return builder.create(); }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
private void fillItinerariesSpinner(List<Itinerary> itineraryList) { String[] itinerarySummaryList = new String[itineraryList.size()]; for (int i = 0; i < itinerarySummaryList.length; i++) { boolean isTransitIsTagSet = false; Itinerary it = itineraryList.get(i); for (Leg leg : it.legs) { TraverseMode traverseMode = TraverseMode.valueOf(leg.mode); if (traverseMode.isTransit()) { itinerarySummaryList[i] = ConversionUtils.getTimeWithContext(mApplicationContext, leg.getAgencyTimeZoneOffset(), Long.parseLong(leg.getStartTime()), false); itinerarySummaryList[i] += ". " + getResources() + ConversionUtils.getRouteShortNameSafe( leg.getRouteShortName(), leg.getRouteLongName(), mApplicationContext); itinerarySummaryList[i] += " - " + ConversionUtils .getFormattedDurationTextNoSeconds(it.duration / 1000, mApplicationContext); if (leg.getHeadsign() != null) { itinerarySummaryList[i] += " - " + leg.getHeadsign(); }//from ww w. ja va 2 s . c o m isTransitIsTagSet = true; break; } } if (!isTransitIsTagSet) { itinerarySummaryList[i] = Integer.toString(i + 1) + ". ";//Shown index is i + 1, to use 1-based indexes for the UI instead of 0-based itinerarySummaryList[i] += ConversionUtils.getFormattedDistance(it.walkDistance, mApplicationContext) + " " + "-" + " " + ConversionUtils.getFormattedDurationTextNoSeconds(it.duration / 1000, mApplicationContext); } } ArrayAdapter<String> itineraryAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, itinerarySummaryList); itineraryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mItinerarySelectionSpinner.setAdapter(itineraryAdapter); }
From source file:cl.gisred.android.CatastroActivity.java
public void dialogBusqueda() { AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this); dialogBusqueda.setTitle("Busqueda"); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.dialog_busqueda, null); dialogBusqueda.setView(v);//from www . jav a 2 s .co m Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda); final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar); final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, R.layout.support_simple_spinner_dropdown_item, searchArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SpiBusqueda = position; if (position != 3) { if (llDireccion != null) llDireccion.setVisibility(View.GONE); if (llBuscar != null) llBuscar.setVisibility(View.VISIBLE); } else { if (llDireccion != null) llDireccion.setVisibility(View.VISIBLE); if (llBuscar != null) llBuscar.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show(); } }); final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar); final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle); final EditText eNumber = (EditText) v.findViewById(R.id.txtNum); dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (SpiBusqueda == 3) { txtBusqueda = new String(); if (!eStreet.getText().toString().isEmpty()) txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 " : eNumber.getText().toString().trim() + " "; txtBusqueda = txtBusqueda + eStreet.getText().toString(); } else { txtBusqueda = eSearch.getText().toString(); } if (txtBusqueda.trim().isEmpty()) { Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show(); } else { // Escala de calle para busquedas por default // TODO Asignar a res values o strings iBusqScale = 4000; switch (SpiBusqueda) { case 0: callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"), LyCLIENTES.getUrl().concat("/0")); if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0) iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale(); break; case 1: callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1")); if (LySED.getLayers() != null && LySED.getLayers().length > 1) iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale(); break; case 2: callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0")); if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0) iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale(); break; case 3: iBusqScale = 5000; String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() }; String[] sFields = { "nombre_calle", "numero" }; callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0")); break; } } } }); dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialogBusqueda.show(); }
From source file:foam.starwisp.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { String type = ""; Integer tid = 0;/*www . ja v a 2s .co m*/ String token = ""; try { type = arr.getString(0); tid = arr.getInt(1); token = arr.getString(2); } catch (JSONException e) { Log.e("starwisp", "Error parsing update arguments for " + ctxname + " " + arr.toString() + e.toString()); } final Integer id = tid; //Log.i("starwisp", "Update: "+type+" "+id+" "+token); try { // non widget commands if (token.equals("toast")) { Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT); LinearLayout linearLayout = (LinearLayout) msg.getView(); View child = linearLayout.getChildAt(0); TextView messageTextView = (TextView) child; messageTextView.setTextSize(arr.getInt(4)); msg.show(); return; } if (token.equals("play-sound")) { String name = arr.getString(3); if (name.equals("ping")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping); mp.start(); } if (name.equals("active")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active); mp.start(); } } if (token.equals("soundfile-start-recording")) { String filename = arr.getString(3); m_SoundManager.StartRecording(filename); } if (token.equals("soundfile-stop-recording")) { m_SoundManager.StopRecording(); } if (token.equals("soundfile-start-playback")) { String filename = arr.getString(3); m_SoundManager.StartPlaying(filename); } if (token.equals("soundfile-stop-playback")) { m_SoundManager.StopPlaying(); } if (token.equals("vibrate")) { Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(arr.getInt(3)); } if (type.equals("replace-fragment")) { int ID = arr.getInt(1); String name = arr.getString(2); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); //ft.setCustomAnimations( R.animator.fragment_slide_left_enter, // R.animator.fragment_slide_right_exit); //ft.setCustomAnimations( // R.animator.card_flip_right_in, R.animator.card_flip_right_out, // R.animator.card_flip_left_in, R.animator.card_flip_left_out); ft.replace(ID, fragment); ft.addToBackStack(null); ft.commit(); return; } if (token.equals("dialog-fragment")) { FragmentManager fm = ctx.getSupportFragmentManager(); final int ID = arr.getInt(3); final JSONArray lp = arr.getJSONArray(4); final String name = arr.getString(5); final Dialog dialog = new Dialog(ctx); dialog.setTitle("Title..."); LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); dialog.setContentView(inner); // Fragment fragment = ActivityManager.GetFragment(name); // FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); // fragmentTransaction.add(ID,fragment); // fragmentTransaction.commit(); dialog.show(); /* DialogFragment df = new DialogFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); return inner; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog ret = super.onCreateDialog(savedInstanceState); Log.i("starwisp","MAKINGDAMNFRAGMENT"); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(1,fragment); fragmentTransaction.commit(); return ret; } }; df.show(ctx.getFragmentManager(), "foo"); */ } if (token.equals("time-picker-dialog")) { final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true); d.show(); return; } ; if (token.equals("view")) { //ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse())); File f = new File(arr.getString(3)); Uri fileUri = Uri.fromFile(f); Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW); String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(arr.getString(3)); String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); myIntent.setDataAndType(fileUri, mimetype); ctx.startActivity(myIntent); return; } if (token.equals("make-directory")) { File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3)); file.mkdirs(); return; } if (token.equals("list-files")) { final String name = arr.getString(3); File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5)); // todo, should probably call callback with empty list if (file != null) { File list[] = file.listFiles(); if (list != null) { String code = "("; for (int i = 0; i < list.length; i++) { code += " \"" + list[i].getName() + "\""; } code += ")"; DialogCallback(ctx, ctxname, name, code); } } return; } if (token.equals("gps-start")) { final String name = arr.getString(3); if (m_LocationManager == null) { m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); m_GPS = new DorisLocationListener(m_LocationManager); } m_GPS.Start((StarwispActivity) ctx, name, this, arr.getInt(5), arr.getInt(6)); return; } if (token.equals("sensors-get")) { final String name = arr.getString(3); if (m_SensorHandler == null) { m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this); } m_SensorHandler.GetSensors((StarwispActivity) ctx, name, this); return; } if (token.equals("sensors-start")) { final String name = arr.getString(3); final JSONArray requested_json = arr.getJSONArray(5); ArrayList<Integer> requested = new ArrayList<Integer>(); try { for (int i = 0; i < requested_json.length(); i++) { requested.add(requested_json.getInt(i)); } } catch (JSONException e) { Log.e("starwisp", "Error parsing data in sensors start " + e.toString()); } // start it up... if (m_SensorHandler == null) { m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this); } m_SensorHandler.StartSensors((StarwispActivity) ctx, name, this, requested); return; } if (token.equals("sensors-stop")) { if (m_SensorHandler != null) { m_SensorHandler.StopSensors(); } return; } if (token.equals("walk-draggable")) { final String name = arr.getString(3); int iid = arr.getInt(5); DialogCallback(ctx, ctxname, name, WalkDraggable(ctx, name, ctxname, iid).replace("\\", "")); return; } if (token.equals("delayed")) { final String name = arr.getString(3); final int d = arr.getInt(5); Runnable timerThread = new Runnable() { public void run() { DialogCallback(ctx, ctxname, name, ""); } }; m_Handler.removeCallbacksAndMessages(null); m_Handler.postDelayed(timerThread, d); return; } if (token.equals("network-connect")) { final String name = arr.getString(3); final String ssid = arr.getString(5); m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this); return; } if (token.equals("http-request")) { Log.i("starwisp", "http-request called"); if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http request"); final String name = arr.getString(3); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "normal", "", name); } return; } if (token.equals("http-post")) { Log.i("starwisp", "http-post called"); if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http request"); final String name = arr.getString(3); final String url = arr.getString(5); final String data = arr.getString(6); m_NetworkManager.StartRequestThread(url, "post", data, name); } return; } if (token.equals("http-upload")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http ul request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "upload", "", filename); } return; } if (token.equals("http-download")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http dl request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "download", "", filename); } return; } if (token.equals("take-photo")) { photo(ctx, arr.getString(3), arr.getInt(4)); } if (token.equals("bluetooth")) { final String name = arr.getString(3); m_Bluetooth.Start((StarwispActivity) ctx, name, this); return; } if (token.equals("bluetooth-send")) { m_Bluetooth.Write(arr.getString(3)); } if (token.equals("process-image-in-place")) { BitmapCache.ProcessInPlace(arr.getString(3)); } if (token.equals("send-mail")) { final String to[] = new String[1]; to[0] = arr.getString(3); final String subject = arr.getString(4); final String body = arr.getString(5); JSONArray attach = arr.getJSONArray(6); ArrayList<String> paths = new ArrayList<String>(); for (int a = 0; a < attach.length(); a++) { Log.i("starwisp", attach.getString(a)); paths.add(attach.getString(a)); } email(ctx, to[0], "", subject, body, paths); } if (token.equals("date-picker-dialog")) { final Calendar c = Calendar.getInstance(); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); final String name = arr.getString(3); // Create a new instance of TimePickerDialog and return it DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int month, int day) { DialogCallback(ctx, ctxname, name, day + " " + month + " " + year); } }, year, month, day); d.show(); return; } ; if (token.equals("alert-dialog")) { final String name = arr.getString(3); final String msg = arr.getString(5); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int result = 0; if (which == DialogInterface.BUTTON_POSITIVE) result = 1; DialogCallback(ctx, ctxname, name, "" + result); } }; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return; } if (token.equals("ok-dialog")) { final String name = arr.getString(3); final String msg = arr.getString(5); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int result = 0; if (which == DialogInterface.BUTTON_POSITIVE) result = 1; DialogCallback(ctx, ctxname, name, "" + result); } }; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(msg).setPositiveButton("Ok", dialogClickListener).show(); return; } if (token.equals("start-activity")) { ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5)); return; } if (token.equals("start-activity-goto")) { ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4)); return; } if (token.equals("finish-activity")) { ctx.setResult(arr.getInt(3)); ctx.finish(); return; } /////////////////////////////////////////////////////////// if (id == 0) { Log.i("starwisp", "Zero ID, aborting..."); return; } // now try and find the widget final View vv = ctx.findViewById(id); if (vv == null) { Log.i("starwisp", "Can't find widget : " + id); return; } // tokens that work on everything if (token.equals("hide")) { vv.setVisibility(View.GONE); return; } if (token.equals("show")) { vv.setVisibility(View.VISIBLE); return; } // only tested on spinners if (token.equals("disabled")) { vv.setAlpha(0.3f); //vv.getSelectedView().setEnabled(false); vv.setEnabled(false); return; } if (token.equals("enabled")) { vv.setAlpha(1.0f); //vv.getSelectedView().setEnabled(true); vv.setEnabled(true); return; } if (token.equals("animate")) { JSONArray trans = arr.getJSONArray(3); final TranslateAnimation animation = new TranslateAnimation(getPixelsFromDp(ctx, trans.getInt(0)), getPixelsFromDp(ctx, trans.getInt(1)), getPixelsFromDp(ctx, trans.getInt(2)), getPixelsFromDp(ctx, trans.getInt(3))); animation.setDuration(1000); animation.setFillAfter(false); animation.setInterpolator(new AnticipateOvershootInterpolator(1.0f)); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { vv.clearAnimation(); Log.i("starwisp", "animation end"); ((ViewManager) vv.getParent()).removeView(vv); //LayoutParams lp = new LayoutParams(imageView.getWidth(), imageView.getHeight()); //lp.setMargins(50, 100, 0, 0); //imageView.setLayoutParams(lp); } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { Log.i("starwisp", "animation start"); } }); vv.startAnimation(animation); return; } // tokens that work on everything if (token.equals("set-enabled")) { Log.i("starwisp", "set-enabled called..."); vv.setEnabled(arr.getInt(3) == 1); vv.setClickable(arr.getInt(3) == 1); if (vv.getBackground() != null) { if (arr.getInt(3) == 0) { //vv.setBackgroundColor(0x00000000); vv.getBackground().setColorFilter(0x20000000, PorterDuff.Mode.MULTIPLY); } else { vv.getBackground().setColorFilter(null); } } return; } if (token.equals("background-colour")) { JSONArray col = arr.getJSONArray(3); if (type.equals("linear-layout")) { vv.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2))); } else { //vv.setBackgroundColor(); vv.getBackground().setColorFilter( Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)), PorterDuff.Mode.MULTIPLY); } vv.invalidate(); return; } // special cases if (type.equals("linear-layout")) { //Log.i("starwisp","linear-layout update id: "+id); StarwispLinearLayout.Update(this, (LinearLayout) vv, token, ctx, ctxname, arr); return; } if (type.equals("relative-layout")) { StarwispRelativeLayout.Update(this, (RelativeLayout) vv, token, ctx, ctxname, arr); return; } if (type.equals("draggable")) { LinearLayout v = (LinearLayout) vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } if (token.equals("contents-add")) { JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } } if (type.equals("button-grid")) { LinearLayout horiz = (LinearLayout) vv; if (token.equals("grid-buttons")) { horiz.removeAllViews(); JSONArray params = arr.getJSONArray(3); String buttontype = params.getString(0); int height = params.getInt(1); int textsize = params.getInt(2); LayoutParams lp = BuildLayoutParams(params.getJSONArray(3)); final JSONArray buttons = params.getJSONArray(4); final int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } else if (buttontype.equals("single")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); int bid = button.getInt(0); if (bid != v.getId()) { ToggleButton tb = (ToggleButton) ctx.findViewById(bid); tb.setChecked(false); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing on click data " + e.toString()); } CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } } } } /* if (type.equals("grid-layout")) { GridLayout v = (GridLayout)vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } } } */ if (type.equals("view-pager")) { ViewPager v = (ViewPager) vv; if (token.equals("switch")) { v.setCurrentItem(arr.getInt(3)); } if (token.equals("pages")) { final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing pages data " + e.toString()); } return null; } }); } } if (type.equals("image-view")) { ImageView v = (ImageView) vv; if (token.equals("image")) { int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName()); v.setImageResource(iid); } if (token.equals("external-image")) { v.setImageBitmap(BitmapCache.Load(arr.getString(3))); } return; } if (type.equals("text-view") || type.equals("debug-text-view")) { TextView v = (TextView) vv; if (token.equals("text")) { if (type.equals("debug-text-view")) { //v.setMovementMethod(new ScrollingMovementMethod()); } v.setText(Html.fromHtml(arr.getString(3)), BufferType.SPANNABLE); // v.invalidate(); } if (token.equals("file")) { v.setText(LoadData(arr.getString(3))); } return; } if (type.equals("edit-text")) { EditText v = (EditText) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("request-focus")) { v.requestFocus(); InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); } return; } if (type.equals("button")) { Button v = (Button) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("toggle-button")) { ToggleButton v = (ToggleButton) vv; if (token.equals("text")) { v.setText(arr.getString(3)); return; } if (token.equals("checked")) { if (arr.getInt(3) == 0) v.setChecked(false); else v.setChecked(true); return; } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("canvas")) { StarwispCanvas v = (StarwispCanvas) vv; if (token.equals("drawlist")) { v.SetDrawList(arr.getJSONArray(3)); } return; } if (type.equals("camera-preview")) { final CameraPreview v = (CameraPreview) vv; if (token.equals("take-picture")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] input, Camera camera) { Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length); Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true); ByteArrayOutputStream blob = new ByteArrayOutputStream(); resized.compress(Bitmap.CompressFormat.JPEG, 100, blob); String datetime = getDateTime(); String filename = path + datetime + ".jpg"; SaveData(filename, blob.toByteArray()); v.Shutdown(); ctx.finish(); } }); } // don't shut the activity down and use provided path if (token.equals("take-picture-cont")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); Log.i("starwisp", "take-picture-cont fired"); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] input, Camera camera) { Log.i("starwisp", "on picture taken..."); // the version used by the uav app Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length); //Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true); ByteArrayOutputStream blob = new ByteArrayOutputStream(); original.compress(Bitmap.CompressFormat.JPEG, 95, blob); original.recycle(); String filename = path; Log.i("starwisp", path); SaveData(filename, blob.toByteArray()); // burn gps into exif data if (m_GPS.currentLocation != null) { double latitude = m_GPS.currentLocation.getLatitude(); double longitude = m_GPS.currentLocation.getLongitude(); try { ExifInterface exif = new ExifInterface(filename); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, GPS.latitudeRef(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(longitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, GPS.longitudeRef(longitude)); exif.saveAttributes(); } catch (IOException e) { Log.i("starwisp", "Couldn't open " + filename + " to add exif data: ioexception caught."); } } v.TakenPicture(); } }); } if (token.equals("shutdown")) { v.Shutdown(); } return; } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); if (token.equals("max")) { // android seekbar bug workaround int p = v.getProgress(); v.setMax(0); v.setProgress(0); v.setMax(arr.getInt(3)); v.setProgress(1000); // not working.... :( } } if (type.equals("spinner")) { Spinner v = (Spinner) vv; if (token.equals("selection")) { v.setSelection(arr.getInt(3)); } if (token.equals("array")) { final JSONArray items = arr.getJSONArray(3); ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); final int wid = id; // need to update for new values v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { CallbackArgs(ctx, ctxname, wid, "" + pos); } public void onNothingSelected(AdapterView<?> v) { } }); } return; } if (type.equals("draw-map")) { DrawableMap v = m_DMaps.get(id); if (v != null) { if (token.equals("polygons")) { v.UpdateFromJSON(arr.getJSONArray(3)); } if (token.equals("centre")) { JSONArray tokens = arr.getJSONArray(3); v.Centre(tokens.getDouble(0), tokens.getDouble(1), tokens.getInt(2)); } if (token.equals("layout")) { v.m_parent.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); } } else { Log.e("starwisp", "Asked to update a drawmap which doesn't exist"); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing builder data " + e.toString()); Log.e("starwisp", "type:" + type + " id:" + id + " token:" + token); } }
From source file:cl.gisred.android.LectorActivity.java
public void dialogBusqueda() { AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this); dialogBusqueda.setTitle("Busqueda"); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.dialog_busqueda, null); dialogBusqueda.setView(v);//from w ww. j a v a2s. co m Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda); final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar); final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, R.layout.support_simple_spinner_dropdown_item, searchArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SpiBusqueda = position; if (position != 4) { if (llDireccion != null) llDireccion.setVisibility(View.GONE); if (llBuscar != null) llBuscar.setVisibility(View.VISIBLE); } else { if (llDireccion != null) llDireccion.setVisibility(View.VISIBLE); if (llBuscar != null) llBuscar.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show(); } }); final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar); final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle); final EditText eNumber = (EditText) v.findViewById(R.id.txtNum); dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (SpiBusqueda == 4) { txtBusqueda = new String(); if (!eStreet.getText().toString().isEmpty()) txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 " : eNumber.getText().toString().trim() + " "; txtBusqueda = txtBusqueda + eStreet.getText().toString(); } else { if (SpiBusqueda > 1) txtBusqueda = eSearch.getText().toString(); else txtBusqueda = Util.extraerNum(eSearch.getText().toString()); } if (txtBusqueda.trim().isEmpty()) { Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show(); } else { // Escala de calle para busquedas por default iBusqScale = 4000; switch (SpiBusqueda) { case 0: callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"), LyCLIENTES.getUrl().concat("/0")); if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0) iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale(); break; case 1: callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1")); if (LySED.getLayers() != null && LySED.getLayers().length > 1) iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale(); break; case 2: callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0")); if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0) iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale(); break; case 3: callQuery(txtBusqueda, "serie_medidor", LyMEDIDORES.getUrl().concat("/1")); if (LyMEDIDORES.getLayers() != null && LyMEDIDORES.getLayers().length > 1) iBusqScale = LyMEDIDORES.getLayers()[1].getLayerServiceInfo().getMinScale(); break; case 4: iBusqScale = 5000; String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() }; String[] sFields = { "nombre_calle", "numero" }; callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0")); break; case 5: callQuery(txtBusqueda, new String[] { "id_equipo", "nombre" }, LyEQUIPOSLINEA.getUrl().concat("/0")); if (LyEQUIPOSLINEA.getLayers() != null && LyEQUIPOSLINEA.getLayers().length > 0) iBusqScale = LyEQUIPOSLINEA.getLayers()[0].getLayerServiceInfo().getMinScale(); break; } } } }); dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialogBusqueda.show(); }