@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.detect_start_localize_button: ConnectivityManager cm = (ConnectivityManager) this.getApplicationContext().getSystemService(CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected()) { myHandler.post(new FailConnectInternet()); return; } if (((String) listTypeSpinner.getSelectedItem()).equals("GPS")) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show(); return; } } startLocalizeButton.setEnabled(false); startLocalizeButton.setFocusable(false); stopLocalizeButton.setEnabled(true); stopLocalizeButton.setFocusable(true); listTypeSpinner.setEnabled(false); listTypeSpinner.setFocusable(false); countInt = 0; if (((String) listTypeSpinner.getSelectedItem()).equals("WIFI")) { wifiDetector.setConvert(convertCheckbox.isChecked()); wifiDetector.startDetectLocation(); } else { gpsDetector.startDetectLocation(); } break; case R.id.detect_stop_localize_button: startLocalizeButton.setEnabled(true); startLocalizeButton.setFocusable(true); stopLocalizeButton.setEnabled(false); stopLocalizeButton.setFocusable(false); listTypeSpinner.setEnabled(true); listTypeSpinner.setFocusable(true); if (((String) listTypeSpinner.getSelectedItem()).equals("WIFI")) { wifiDetector.stopDectectLocation(); } else { gpsDetector.stopDectectLocation(); } break; default: break; } }
@Override public View getPrototypeView(Context context) { prototypeView = View.inflate(context, R.layout.brick_phiro_rgb_light, null); TextView textValueRed = (TextView) prototypeView.findViewById(R.id.brick_phiro_rgb_led_red_prototype_text_view); textValueRed.setText(String.valueOf(BrickValues.PHIRO_VALUE_RED)); TextView textValueGreen = (TextView) prototypeView.findViewById(R.id.brick_phiro_rgb_led_green_prototype_text_view); textValueGreen.setText(String.valueOf(BrickValues.PHIRO_VALUE_GREEN)); TextView textValueBlue = (TextView) prototypeView.findViewById(R.id.brick_phiro_rgb_led_blue_prototype_text_view); textValueBlue.setText(String.valueOf(BrickValues.PHIRO_VALUE_BLUE)); Spinner eyeSpinner = (Spinner) prototypeView.findViewById(R.id.brick_phiro_rgb_light_spinner); eyeSpinner.setFocusableInTouchMode(false); eyeSpinner.setFocusable(false); eyeSpinner.setEnabled(false); ArrayAdapter<CharSequence> eyeAdapter = ArrayAdapter.createFromResource( context, R.array.brick_phiro_select_light_spinner, android.R.layout.simple_spinner_item); eyeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); eyeSpinner.setAdapter(eyeAdapter); eyeSpinner.setSelection(eyeEnum.ordinal()); return prototypeView; }
@Override public View getPrototypeView(Context context) { View prototypeView = View.inflate(context, R.layout.brick_change_variable_by, null); Spinner variableSpinner = (Spinner) prototypeView.findViewById(R.id.change_variable_spinner); variableSpinner.setFocusableInTouchMode(false); variableSpinner.setFocusable(false); UserBrick currentBrick = ProjectManager.getInstance().getCurrentUserBrick(); int userBrickId = (currentBrick == null ? -1 : currentBrick.getDefinitionBrick().getUserBrickId()); DataAdapter dataAdapter = ProjectManager.getInstance() .getCurrentProject() .getDataContainer() .createDataAdapter( context, userBrickId, ProjectManager.getInstance().getCurrentSprite(), inUserBrick); UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context, dataAdapter); userVariableAdapterWrapper.setItemLayout( android.R.layout.simple_spinner_item, android.R.id.text1); variableSpinner.setAdapter(userVariableAdapterWrapper); setSpinnerSelection(variableSpinner, null); TextView textChangeVariable = (TextView) prototypeView.findViewById(R.id.brick_change_variable_prototype_view); textChangeVariable.setText(String.valueOf(BrickValues.CHANGE_VARIABLE)); return prototypeView; }
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String date = Integer.toString(hourOfDay) + ":" + Integer.toString(minute); etTime.setText(date); dHour = hourOfDay; dMin = minute; spCategory.setFocusable(true); }
@Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { int month = monthOfYear + 1; String date = "" + dayOfMonth + AppConfig.DATE_SEPARATOR + month + AppConfig.DATE_SEPARATOR + year; date = Utilities.setDayAsTwoNumbers(date); etDate.setText(date); dYear = year; dMonth = monthOfYear; dDay = dayOfMonth; spCategory.setFocusable(true); }
@Override public View getPrototypeView(Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.brick_point_to, null); Spinner pointToSpinner = (Spinner) view.findViewById(R.id.brick_point_to_spinner); pointToSpinner.setFocusableInTouchMode(false); pointToSpinner.setFocusable(false); pointToSpinner.setEnabled(false); SpinnerAdapter pointToSpinnerAdapter = getArrayAdapterFromSpriteList(context); pointToSpinner.setAdapter(pointToSpinnerAdapter); setSpinnerSelection(pointToSpinner); return view; }
@Override public View getPrototypeView(Context context) { View prototypeView = View.inflate(context, R.layout.brick_phiro_motor_stop, null); Spinner phiroProSpinner = (Spinner) prototypeView.findViewById(R.id.brick_phiro_stop_motor_spinner); phiroProSpinner.setFocusableInTouchMode(false); phiroProSpinner.setFocusable(false); ArrayAdapter<CharSequence> motorAdapter = ArrayAdapter.createFromResource( context, R.array.brick_phiro_stop_motor_spinner, android.R.layout.simple_spinner_item); motorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); phiroProSpinner.setAdapter(motorAdapter); phiroProSpinner.setSelection(motorEnum.ordinal()); return prototypeView; }
@Override public View getView(final Context context, int brickId, BaseAdapter adapter) { View view = View.inflate(context, R.layout.brick_play_sound, null); Spinner soundbrickSpinner = (Spinner) view.findViewById(R.id.playsound_spinner); soundbrickSpinner.setAdapter(createSoundAdapter(context)); soundbrickSpinner.setClickable(true); soundbrickSpinner.setFocusable(true); soundbrickSpinner.setOnItemSelectedListener(this); if (sprite.getSoundList().contains(sound)) { soundbrickSpinner.setSelection(sprite.getSoundList().indexOf(sound) + 1, true); } else { soundbrickSpinner.setSelection(0); } return view; }
@Override public View getPrototypeView(Context context) { prototypeView = View.inflate(context, R.layout.brick_nxt_motor_action, null); TextView textSpeed = (TextView) prototypeView.findViewById(R.id.motor_action_speed_text_view); textSpeed.setText(String.valueOf(speed.interpretInteger(sprite))); Spinner legoSpinner = (Spinner) prototypeView.findViewById(R.id.lego_motor_action_spinner); legoSpinner.setFocusableInTouchMode(false); legoSpinner.setFocusable(false); ArrayAdapter<CharSequence> motorAdapter = ArrayAdapter.createFromResource( context, R.array.nxt_motor_chooser, android.R.layout.simple_spinner_item); motorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); legoSpinner.setAdapter(motorAdapter); legoSpinner.setSelection(motorEnum.ordinal()); return prototypeView; }
@Override public View getView(final Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; } LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.brick_point_to, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_point_to_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); final Spinner spinner = (Spinner) view.findViewById(R.id.brick_point_to_spinner); spinner.setFocusableInTouchMode(false); spinner.setFocusable(false); if (!(checkbox.getVisibility() == View.VISIBLE)) { spinner.setClickable(true); spinner.setEnabled(true); } else { spinner.setClickable(false); spinner.setEnabled(false); } final ArrayAdapter<String> spinnerAdapter = getArrayAdapterFromSpriteList(context); spinnerAdapterWrapper = new SpinnerAdapterWrapper(context, spinner, spinnerAdapter); spinner.setAdapter(spinnerAdapterWrapper); spinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String itemSelected = parent.getSelectedItem().toString(); if (itemSelected.equals(context.getString(R.string.new_broadcast_message))) { pointedObject = null; } else { final ArrayList<Sprite> spriteList = (ArrayList<Sprite>) ProjectManager.getInstance().getCurrentProject().getSpriteList(); for (Sprite sprite : spriteList) { String spriteName = sprite.getName(); if (spriteName.equals(itemSelected)) { pointedObject = sprite; break; } } } adapterView = parent; } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); setSpinnerSelection(spinner); return view; }
@Override public View getView(final Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; } view = View.inflate(context, R.layout.brick_change_variable_by, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_change_variable_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); TextView prototypeText = (TextView) view.findViewById(R.id.brick_change_variable_prototype_view); TextView textField = (TextView) view.findViewById(R.id.brick_change_variable_edit_text); prototypeText.setVisibility(View.GONE); getFormulaWithBrickField(BrickField.VARIABLE_CHANGE) .setTextFieldId(R.id.brick_change_variable_edit_text); getFormulaWithBrickField(BrickField.VARIABLE_CHANGE).refreshTextField(view); textField.setVisibility(View.VISIBLE); textField.setOnClickListener(this); Spinner variableSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner); UserBrick currentBrick = ProjectManager.getInstance().getCurrentUserBrick(); int userBrickId = (currentBrick == null ? -1 : currentBrick.getUserBrickId()); DataAdapter dataAdapter = ProjectManager.getInstance() .getCurrentProject() .getDataContainer() .createDataAdapter( context, userBrickId, ProjectManager.getInstance().getCurrentSprite(), inUserBrick); UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context, dataAdapter); userVariableAdapterWrapper.setItemLayout( android.R.layout.simple_spinner_item, android.R.id.text1); variableSpinner.setAdapter(userVariableAdapterWrapper); if (!(checkbox.getVisibility() == View.VISIBLE)) { variableSpinner.setClickable(true); variableSpinner.setEnabled(true); } else { variableSpinner.setClickable(false); variableSpinner.setFocusable(false); } setSpinnerSelection(variableSpinner, null); variableSpinner.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && ((Spinner) view).getSelectedItemPosition() == 0 && ((Spinner) view).getAdapter().getCount() == 1) { NewDataDialog dialog = new NewDataDialog((Spinner) view, NewDataDialog.DialogType.USER_VARIABLE); dialog.addVariableDialogListener(ChangeVariableBrick.this); dialog.show( ((SherlockFragmentActivity) view.getContext()).getSupportFragmentManager(), NewDataDialog.DIALOG_FRAGMENT_TAG); return true; } return false; } }); variableSpinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) { NewDataDialog dialog = new NewDataDialog((Spinner) parent, NewDataDialog.DialogType.USER_VARIABLE); dialog.addVariableDialogListener(ChangeVariableBrick.this); dialog.show( ((SherlockFragmentActivity) view.getContext()).getSupportFragmentManager(), NewDataDialog.DIALOG_FRAGMENT_TAG); } ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView(); userVariable = (UserVariable) parent.getItemAtPosition(position); adapterView = parent; } @Override public void onNothingSelected(AdapterView<?> arg0) { userVariable = null; } }); return view; }