List of usage examples for android.widget Spinner setSelection
@Override public void setSelection(int position)
From source file:org.openhab.habdroid.ui.OpenHABWidgetAdapter.java
@SuppressWarnings("deprecation") @Override// w w w. j av a2 s . c om public View getView(int position, View convertView, ViewGroup parent) { /* TODO: This definitely needs some huge refactoring */ final RelativeLayout widgetView; TextView labelTextView; TextView valueTextView; int widgetLayout; String[] splitString; OpenHABWidget openHABWidget = getItem(position); int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getWidth(); switch (this.getItemViewType(position)) { case TYPE_FRAME: widgetLayout = R.layout.openhabwidgetlist_frameitem; break; case TYPE_GROUP: widgetLayout = R.layout.openhabwidgetlist_groupitem; break; case TYPE_SECTIONSWITCH: widgetLayout = R.layout.openhabwidgetlist_sectionswitchitem; break; case TYPE_SWITCH: widgetLayout = R.layout.openhabwidgetlist_switchitem; break; case TYPE_ROLLERSHUTTER: widgetLayout = R.layout.openhabwidgetlist_rollershutteritem; break; case TYPE_TEXT: widgetLayout = R.layout.openhabwidgetlist_textitem; break; case TYPE_SLIDER: widgetLayout = R.layout.openhabwidgetlist_slideritem; break; case TYPE_IMAGE: widgetLayout = R.layout.openhabwidgetlist_imageitem; break; case TYPE_SELECTION: widgetLayout = R.layout.openhabwidgetlist_selectionitem; break; case TYPE_SETPOINT: widgetLayout = R.layout.openhabwidgetlist_setpointitem; break; case TYPE_CHART: widgetLayout = R.layout.openhabwidgetlist_chartitem; break; case TYPE_VIDEO: widgetLayout = R.layout.openhabwidgetlist_videoitem; break; case TYPE_VIDEO_MJPEG: widgetLayout = R.layout.openhabwidgetlist_videomjpegitem; break; case TYPE_WEB: widgetLayout = R.layout.openhabwidgetlist_webitem; break; case TYPE_COLOR: widgetLayout = R.layout.openhabwidgetlist_coloritem; break; default: widgetLayout = R.layout.openhabwidgetlist_genericitem; break; } if (convertView == null) { widgetView = new RelativeLayout(getContext()); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi = (LayoutInflater) getContext().getSystemService(inflater); vi.inflate(widgetLayout, widgetView, true); } else { widgetView = (RelativeLayout) convertView; } // Process the colour attributes Integer iconColor = openHABWidget.getIconColor(); Integer labelColor = openHABWidget.getLabelColor(); Integer valueColor = openHABWidget.getValueColor(); // Process widgets icon image MySmartImageView widgetImage = (MySmartImageView) widgetView.findViewById(R.id.widgetimage); // Some of widgets, for example Frame doesnt' have an icon, so... if (widgetImage != null) { if (openHABWidget.getIcon() != null) { // This is needed to escape possible spaces and everything according to rfc2396 String iconUrl = openHABBaseUrl + "images/" + Uri.encode(openHABWidget.getIcon() + ".png"); // Log.d(TAG, "Will try to load icon from " + iconUrl); // Now set image URL widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword); if (iconColor != null) widgetImage.setColorFilter(iconColor); else widgetImage.clearColorFilter(); } } TextView defaultTextView = new TextView(widgetView.getContext()); // Get TextView for widget label and set it's color labelTextView = (TextView) widgetView.findViewById(R.id.widgetlabel); // Change label color only for non-frame widgets if (labelColor != null && labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) { Log.d(TAG, String.format("Setting label color to %d", labelColor)); labelTextView.setTextColor(labelColor); } else if (labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); // Get TextView for widget value and set it's color valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue); if (valueColor != null && valueTextView != null) { Log.d(TAG, String.format("Setting value color to %d", valueColor)); valueTextView.setTextColor(valueColor); } else if (valueTextView != null) valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); defaultTextView = null; switch (getItemViewType(position)) { case TYPE_FRAME: if (labelTextView != null) { labelTextView.setText(openHABWidget.getLabel()); if (valueColor != null) labelTextView.setTextColor(valueColor); } widgetView.setClickable(false); if (openHABWidget.getLabel().length() > 0) { // hide empty frames widgetView.setVisibility(View.VISIBLE); labelTextView.setVisibility(View.VISIBLE); } else { widgetView.setVisibility(View.GONE); labelTextView.setVisibility(View.GONE); } break; case TYPE_GROUP: if (labelTextView != null && valueTextView != null) { splitString = openHABWidget.getLabel().split("\\[|\\]"); labelTextView.setText(splitString[0]); if (splitString.length > 1) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } } break; case TYPE_SECTIONSWITCH: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (splitString.length > 1 && valueTextView != null) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } RadioGroup sectionSwitchRadioGroup = (RadioGroup) widgetView.findViewById(R.id.sectionswitchradiogroup); // As we create buttons in this radio in runtime, we need to remove all // exiting buttons first sectionSwitchRadioGroup.removeAllViews(); sectionSwitchRadioGroup.setTag(openHABWidget); Iterator<OpenHABWidgetMapping> sectionMappingIterator = openHABWidget.getMappings().iterator(); while (sectionMappingIterator.hasNext()) { OpenHABWidgetMapping widgetMapping = sectionMappingIterator.next(); SegmentedControlButton segmentedControlButton = (SegmentedControlButton) LayoutInflater .from(sectionSwitchRadioGroup.getContext()) .inflate(R.layout.openhabwidgetlist_sectionswitchitem_button, sectionSwitchRadioGroup, false); segmentedControlButton.setText(widgetMapping.getLabel()); segmentedControlButton.setTag(widgetMapping.getCommand()); if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) { if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { segmentedControlButton.setChecked(true); } else { segmentedControlButton.setChecked(false); } } else { segmentedControlButton.setChecked(false); } segmentedControlButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Log.i(TAG, "Button clicked"); RadioGroup group = (RadioGroup) view.getParent(); if (group.getTag() != null) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) view; if (selectedButton.getTag() != null) { sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } } }); sectionSwitchRadioGroup.addView(segmentedControlButton); } sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) group.findViewById(checkedId); if (selectedButton != null) { Log.d(TAG, "Selected " + selectedButton.getText()); Log.d(TAG, "Command = " + (String) selectedButton.getTag()); // radioWidget.getItem().sendCommand((String)selectedButton.getTag()); sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } }); break; case TYPE_SWITCH: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); SwitchCompat switchSwitch = (SwitchCompat) widgetView.findViewById(R.id.switchswitch); if (openHABWidget.hasItem()) { if (openHABWidget.getItem().getStateAsBoolean()) { switchSwitch.setChecked(true); } else { switchSwitch.setChecked(false); } } switchSwitch.setTag(openHABWidget.getItem()); switchSwitch.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { SwitchCompat switchSwitch = (SwitchCompat) v; OpenHABItem linkedItem = (OpenHABItem) switchSwitch.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) if (!switchSwitch.isChecked()) { sendItemCommand(linkedItem, "ON"); } else { sendItemCommand(linkedItem, "OFF"); } return false; } }); break; case TYPE_COLOR: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton colorUpButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_up); ImageButton colorDownButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_down); ImageButton colorColorButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_color); colorUpButton.setTag(openHABWidget.getItem()); colorDownButton.setTag(openHABWidget.getItem()); colorColorButton.setTag(openHABWidget.getItem()); colorUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "ON"); return false; } }); colorDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "OFF"); return false; } }); colorColorButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (colorItem != null) { if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { Log.d(TAG, "Time to launch color picker!"); ColorPickerDialog colorDialog = new ColorPickerDialog(widgetView.getContext(), new OnColorChangedListener() { public void colorChanged(float[] hsv, View v) { Log.d(TAG, "New color HSV = " + hsv[0] + ", " + hsv[1] + ", " + hsv[2]); String newColor = String.valueOf(hsv[0]) + "," + String.valueOf(hsv[1] * 100) + "," + String.valueOf(hsv[2] * 100); OpenHABItem colorItem = (OpenHABItem) v.getTag(); sendItemCommand(colorItem, newColor); } }, colorItem.getStateAsHSV()); colorDialog.setTag(colorItem); colorDialog.show(); } } return false; } }); break; case TYPE_ROLLERSHUTTER: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton rollershutterUpButton = (ImageButton) widgetView.findViewById(R.id.rollershutterbutton_up); ImageButton rollershutterStopButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_stop); ImageButton rollershutterDownButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_down); rollershutterUpButton.setTag(openHABWidget.getItem()); rollershutterStopButton.setTag(openHABWidget.getItem()); rollershutterDownButton.setTag(openHABWidget.getItem()); rollershutterUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "UP"); return false; } }); rollershutterStopButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "STOP"); return false; } }); rollershutterDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "DOWN"); return false; } }); break; case TYPE_TEXT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) if (splitString.length > 0) { labelTextView.setText(splitString[0]); } else { labelTextView.setText(openHABWidget.getLabel()); } if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } else { // If value is empty, hide TextView to fix vertical alignment of label valueTextView.setVisibility(View.GONE); valueTextView.setText(""); } break; case TYPE_SLIDER: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); SeekBar sliderSeekBar = (SeekBar) widgetView.findViewById(R.id.sliderseekbar); if (openHABWidget.hasItem()) { sliderSeekBar.setTag(openHABWidget.getItem()); sliderSeekBar.setProgress(openHABWidget.getItem().getStateAsFloat().intValue()); sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } public void onStartTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStartTrackingTouch position = " + seekBar.getProgress()); } public void onStopTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStopTrackingTouch position = " + seekBar.getProgress()); OpenHABItem sliderItem = (OpenHABItem) seekBar.getTag(); // sliderItem.sendCommand(String.valueOf(seekBar.getProgress())); if (sliderItem != null && seekBar != null) sendItemCommand(sliderItem, String.valueOf(seekBar.getProgress())); } }); if (volumeUpWidget == null) { volumeUpWidget = sliderSeekBar; volumeDownWidget = sliderSeekBar; } } break; case TYPE_IMAGE: MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage); imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false, openHABUsername, openHABPassword); // ViewGroup.LayoutParams imageLayoutParams = imageImage.getLayoutParams(); // float imageRatio = imageImage.getDrawable().getIntrinsicWidth()/imageImage.getDrawable().getIntrinsicHeight(); // imageLayoutParams.height = (int) (screenWidth/imageRatio); // imageImage.setLayoutParams(imageLayoutParams); if (openHABWidget.getRefresh() > 0) { imageImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(imageImage); } break; case TYPE_CHART: MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage); //Always clear the drawable so no images from recycled views appear chartImage.setImageDrawable(null); OpenHABItem chartItem = openHABWidget.getItem(); Random random = new Random(); String chartUrl = ""; if (chartItem != null) { if (chartItem.getType().equals("GroupItem")) { chartUrl = openHABBaseUrl + "chart?groups=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } else { chartUrl = openHABBaseUrl + "chart?items=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) { chartUrl += "&service=" + openHABWidget.getService(); } } Log.d(TAG, "Chart url = " + chartUrl); if (chartImage == null) Log.e(TAG, "chartImage == null !!!"); ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams(); chartLayoutParams.height = (int) (screenWidth / 2); chartImage.setLayoutParams(chartLayoutParams); chartUrl += "&w=" + String.valueOf(screenWidth); chartUrl += "&h=" + String.valueOf(screenWidth / 2); chartImage.setImageUrl(chartUrl, false, openHABUsername, openHABPassword); // TODO: This is quite dirty fix to make charts look full screen width on all displays if (openHABWidget.getRefresh() > 0) { chartImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(chartImage); } Log.d(TAG, "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height); break; case TYPE_VIDEO: VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo); Log.d(TAG, "Opening video at " + openHABWidget.getUrl()); // TODO: This is quite dirty fix to make video look maximum available size on all screens WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams(); videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77); videoVideo.setLayoutParams(videoLayoutParams); // We don't have any event handler to know if the VideoView is on the screen // so we manage an array of all videos to stop them when user leaves the page if (!videoWidgetList.contains(videoVideo)) videoWidgetList.add(videoVideo); // Start video if (!videoVideo.isPlaying()) { videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl())); videoVideo.start(); } Log.d(TAG, "Video height is " + videoVideo.getHeight()); break; case TYPE_VIDEO_MJPEG: Log.d(TAG, "Video is mjpeg"); ImageView mjpegImage = (ImageView) widgetView.findViewById(R.id.mjpegimage); MjpegStreamer mjpegStreamer = new MjpegStreamer(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword, this.getContext()); mjpegStreamer.setTargetImageView(mjpegImage); mjpegStreamer.start(); if (!mjpegWidgetList.contains(mjpegStreamer)) mjpegWidgetList.add(mjpegStreamer); break; case TYPE_WEB: WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb); if (openHABWidget.getHeight() > 0) { ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams(); webLayoutParams.height = openHABWidget.getHeight() * 80; webWeb.setLayoutParams(webLayoutParams); } webWeb.setWebViewClient( new AnchorWebViewClient(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword)); webWeb.getSettings().setJavaScriptEnabled(true); webWeb.loadUrl(openHABWidget.getUrl()); break; case TYPE_SELECTION: int spinnerSelectedIndex = -1; if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); final Spinner selectionSpinner = (Spinner) widgetView.findViewById(R.id.selectionspinner); selectionSpinner.setOnItemSelectedListener(null); ArrayList<String> spinnerArray = new ArrayList<String>(); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings().iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); spinnerArray.add(openHABWidgetMapping.getLabel()); if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null) if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { spinnerSelectedIndex = spinnerArray.size() - 1; } } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_spinner_item, spinnerArray); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); selectionSpinner.setAdapter(spinnerAdapter); selectionSpinner.setTag(openHABWidget); if (spinnerSelectedIndex >= 0) { Log.d(TAG, "Setting spinner selected index to " + String.valueOf(spinnerSelectedIndex)); selectionSpinner.setSelection(spinnerSelectedIndex); } else { Log.d(TAG, "Not setting spinner selected index"); } selectionSpinner.post(new Runnable() { @Override public void run() { selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int index, long id) { Log.d(TAG, "Spinner item click on index " + index); Spinner spinner = (Spinner) parent; String selectedLabel = (String) spinner.getAdapter().getItem(index); Log.d(TAG, "Spinner onItemSelected selected label = " + selectedLabel); OpenHABWidget openHABWidget = (OpenHABWidget) parent.getTag(); if (openHABWidget != null) { Log.d(TAG, "Label selected = " + openHABWidget.getMapping(index).getLabel()); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings() .iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); if (openHABWidgetMapping.getLabel().equals(selectedLabel)) { Log.d(TAG, "Spinner onItemSelected found match with " + openHABWidgetMapping.getCommand()); if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() != null) { // Only send the command for selection of selected command will change the state if (!openHABWidget.getItem().getState() .equals(openHABWidgetMapping.getCommand())) { Log.d(TAG, "Spinner onItemSelected selected label command != current item state"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } else if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() == null) { Log.d(TAG, "Spinner onItemSelected selected label command and state == null"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } } } // if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand())) // sendItemCommand(openHABWidget.getItem(), // openHABWidget.getMapping(index).getCommand()); } public void onNothingSelected(AdapterView<?> arg0) { } }); } }); break; case TYPE_SETPOINT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } Button setPointMinusButton = (Button) widgetView.findViewById(R.id.setpointbutton_minus); Button setPointPlusButton = (Button) widgetView.findViewById(R.id.setpointbutton_plus); setPointMinusButton.setTag(openHABWidget); setPointPlusButton.setTag(openHABWidget); setPointMinusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Minus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue - setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); setPointPlusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Plus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue + setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); if (volumeUpWidget == null) { volumeUpWidget = setPointPlusButton; volumeDownWidget = setPointMinusButton; } break; default: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); break; } LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider); if (dividerLayout != null) { if (position < this.getCount() - 1) { if (this.getItemViewType(position + 1) == TYPE_FRAME) { dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets } else { dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others } } else { // last widget in the list, hide divider dividerLayout.setVisibility(View.GONE); } } return widgetView; }
From source file:org.onebusaway.android.ui.TripPlanFragment.java
private void advancedSettings() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); final TypedArray transitModeResource = getContext().getResources() .obtainTypedArray(R.array.transit_mode_array); final boolean unitsAreImperial = !PreferenceUtils.getUnitsAreMetricFromPreferences(getContext()); dialogBuilder.setTitle(R.string.trip_plan_advanced_settings) .setView(R.layout.trip_plan_advanced_settings_dialog); dialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override/* w w w.j a va 2 s .co m*/ public void onClick(DialogInterface dialogInterface, int which) { Dialog dialog = (Dialog) dialogInterface; boolean optimizeTransfers = ((CheckBox) dialog.findViewById(R.id.checkbox_minimize_transfers)) .isChecked(); Spinner spinnerTravelBy = (Spinner) dialog.findViewById(R.id.spinner_travel_by); int modeId = transitModeResource.getResourceId(spinnerTravelBy.getSelectedItemPosition(), 0); boolean wheelchair = ((CheckBox) dialog.findViewById(R.id.checkbox_wheelchair_acccesible)) .isChecked(); String maxWalkString = ((EditText) dialog.findViewById(R.id.number_maximum_walk_distance)).getText() .toString(); double maxWalkDistance; if (TextUtils.isEmpty(maxWalkString)) { maxWalkDistance = Double.MAX_VALUE; } else { double d = Double.parseDouble(maxWalkString); maxWalkDistance = unitsAreImperial ? ConversionUtils.feetToMeters(d) : d; } mBuilder.setOptimizeTransfers(optimizeTransfers).setModeSetById(modeId) .setWheelchairAccessible(wheelchair).setMaxWalkDistance(maxWalkDistance); checkRequestAndSubmit(); } }); final AlertDialog dialog = dialogBuilder.create(); dialog.show(); CheckBox minimizeTransfersCheckbox = (CheckBox) dialog.findViewById(R.id.checkbox_minimize_transfers); Spinner spinnerTravelBy = (Spinner) dialog.findViewById(R.id.spinner_travel_by); CheckBox wheelchairCheckbox = (CheckBox) dialog.findViewById(R.id.checkbox_wheelchair_acccesible); EditText maxWalkEditText = (EditText) dialog.findViewById(R.id.number_maximum_walk_distance); minimizeTransfersCheckbox.setChecked(mBuilder.getOptimizeTransfers()); wheelchairCheckbox.setChecked(mBuilder.getWheelchairAccessible()); ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.transit_mode_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerTravelBy.setAdapter(adapter); int modeSetId = mBuilder.getModeSetId(); if (modeSetId != -1) { for (int i = 0; i < transitModeResource.length(); i++) { if (transitModeResource.getResourceId(i, -1) == modeSetId) { spinnerTravelBy.setSelection(i); break; } } } Double maxWalk = mBuilder.getMaxWalkDistance(); if (maxWalk != null && Double.MAX_VALUE != maxWalk) { if (unitsAreImperial) { maxWalk = ConversionUtils.metersToFeet(maxWalk); } maxWalkEditText.setText(String.format("%d", maxWalk.longValue())); } if (unitsAreImperial) { TextView label = (TextView) dialog.findViewById(R.id.label_minimum_walk_distance); label.setText(getString(R.string.feet_abbreviation)); } }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void showMultiEditDialog(final String multiPath) { JSONObject multiObj = global.getSubredditManager().getMultiData(multiPath); @SuppressLint("InflateParams") LinearLayout dialogView = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_multi_edit, null); // passing null okay for dialog final Button saveButton = (Button) dialogView.findViewById(R.id.multi_save_button); final Button renameButton = (Button) dialogView.findViewById(R.id.multi_rename_button); multiName = (TextView) dialogView.findViewById(R.id.multi_pname); final EditText displayName = (EditText) dialogView.findViewById(R.id.multi_name); final EditText description = (EditText) dialogView.findViewById(R.id.multi_description); final EditText color = (EditText) dialogView.findViewById(R.id.multi_color); final Spinner icon = (Spinner) dialogView.findViewById(R.id.multi_icon); final Spinner visibility = (Spinner) dialogView.findViewById(R.id.multi_visibility); final Spinner weighting = (Spinner) dialogView.findViewById(R.id.multi_weighting); ArrayAdapter<CharSequence> iconAdapter = ArrayAdapter.createFromResource(SubredditSelectActivity.this, R.array.multi_icons, android.R.layout.simple_spinner_item); iconAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); icon.setAdapter(iconAdapter);/* w w w. j ava2s .c om*/ ArrayAdapter<CharSequence> visibilityAdapter = ArrayAdapter.createFromResource(SubredditSelectActivity.this, R.array.multi_visibility, android.R.layout.simple_spinner_item); visibilityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); visibility.setAdapter(visibilityAdapter); ArrayAdapter<CharSequence> weightsAdapter = ArrayAdapter.createFromResource(SubredditSelectActivity.this, R.array.multi_weights, android.R.layout.simple_spinner_item); weightsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); weighting.setAdapter(weightsAdapter); try { multiName.setText(multiObj.getString("name")); displayName.setText(multiObj.getString("display_name")); description.setText(multiObj.getString("description_md")); color.setText(multiObj.getString("key_color")); String iconName = multiObj.getString("icon_name"); icon.setSelection(iconAdapter.getPosition(iconName.equals("") ? "none" : iconName)); visibility.setSelection(iconAdapter.getPosition(multiObj.getString("visibility"))); weighting.setSelection(iconAdapter.getPosition(multiObj.getString("weighting_scheme"))); } catch (JSONException e) { e.printStackTrace(); } ViewPager pager = (ViewPager) dialogView.findViewById(R.id.multi_pager); LinearLayout tabsWidget = (LinearLayout) dialogView.findViewById(R.id.multi_tab_widget); pager.setAdapter(new SimpleTabsAdapter(new String[] { "Subreddits", "Settings" }, new int[] { R.id.multi_subreddits, R.id.multi_settings }, SubredditSelectActivity.this, dialogView)); SimpleTabsWidget simpleTabsWidget = new SimpleTabsWidget(SubredditSelectActivity.this, tabsWidget); simpleTabsWidget.setViewPager(pager); ThemeManager.Theme theme = global.mThemeManager.getActiveTheme("appthemepref"); int headerColor = Color.parseColor(theme.getValue("header_color")); int headerText = Color.parseColor(theme.getValue("header_text")); simpleTabsWidget.setBackgroundColor(headerColor); simpleTabsWidget.setTextColor(headerText); simpleTabsWidget.setInidicatorColor(Color.parseColor(theme.getValue("tab_indicator"))); ListView subList = (ListView) dialogView.findViewById(R.id.multi_subredditList); multiSubsAdapter = new SubsListAdapter(SubredditSelectActivity.this, multiPath); subList.setAdapter(multiSubsAdapter); renameButton.getBackground().setColorFilter(headerColor, PorterDuff.Mode.MULTIPLY); renameButton.setTextColor(headerText); renameButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showMultiRenameDialog(multiPath); } }); saveButton.getBackground().setColorFilter(headerColor, PorterDuff.Mode.MULTIPLY); saveButton.setTextColor(headerText); saveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { System.out.println("Save multi"); JSONObject multiObj = new JSONObject(); try { multiObj.put("decription_md", description.getText().toString()); multiObj.put("display_name", displayName.getText().toString()); multiObj.put("icon_name", icon.getSelectedItem().toString().equals("none") ? "" : icon.getSelectedItem().toString()); multiObj.put("key_color", color.getText().toString()); multiObj.put("subreddits", global.getSubredditManager().getMultiData(multiPath).getJSONArray("subreddits")); multiObj.put("visibility", visibility.getSelectedItem().toString()); multiObj.put("weighting_scheme", weighting.getSelectedItem().toString()); new SubscriptionEditTask(SubscriptionEditTask.ACTION_MULTI_EDIT).execute(multiPath, multiObj); } catch (JSONException e) { e.printStackTrace(); } } }); AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this); multiDialog = builder.setView(dialogView).show(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTaskProfile.java
private void restoreViewContents(final SavedViewContents sv) { final EditText dlg_prof_name_et = (EditText) mDialog.findViewById(R.id.edit_profile_task_profile_et_name); final CheckBox cb_active = (CheckBox) mDialog.findViewById(R.id.edit_profile_task_enabled); final CheckBox cb_notification = (CheckBox) mDialog.findViewById(R.id.edit_profile_task_error_notification); final Spinner spinnerTriggerCat = (Spinner) mDialog .findViewById(R.id.edit_profile_task_exec_trigger_category); final Spinner spinnerEvent = (Spinner) mDialog.findViewById(R.id.edit_profile_task_exec_trigger_event); final CheckBox cb_enable_env_parms = (CheckBox) mDialog .findViewById(R.id.edit_profile_task_enable_env_parms); final Spinner spinnerActionProfile = (Spinner) mDialog.findViewById(R.id.edit_profile_task_user_actionlist); final Spinner spinnerBuiltinPrimitiveAction = (Spinner) mDialog .findViewById(R.id.edit_profile_task_builtin_primitive_actionlist); final Spinner spinnerBuiltinConditionalAction = (Spinner) mDialog .findViewById(R.id.edit_profile_task_builtin_conditional_actionlist); final Spinner spinnerBuiltinCancelAction = (Spinner) mDialog .findViewById(R.id.edit_profile_task_builtin_cancel_actionlist); final Spinner spinnerBuiltinBlockAction = (Spinner) mDialog .findViewById(R.id.edit_profile_task_builtin_block_actionlist); final ListView lv_act_list = (ListView) mDialog.findViewById(android.R.id.list); final Spinner spinnerSelectAction = (Spinner) mDialog.findViewById(R.id.edit_profile_task_select_action); Handler hndl1 = new Handler(); hndl1.postDelayed(new Runnable() { @Override/*w w w.j a v a 2 s . c o m*/ public void run() { dlg_prof_name_et.setText(sv.dlg_prof_name_et); dlg_prof_name_et.setSelection(sv.dlg_prof_name_et_spos, sv.dlg_prof_name_et_epos); cb_active.setChecked(sv.cb_active); cb_notification.setChecked(sv.cb_notification); if (spinnerTriggerCat.getSelectedItemPosition() != sv.spinnerTriggerCat) { spinnerTriggerCat.setSelection(sv.spinnerTriggerCat); } Handler hndl2 = new Handler(); hndl2.postDelayed(new Runnable() { @Override public void run() { spinnerEvent.setSelection(sv.spinnerEvent); lv_act_list.setSelectionFromTop(sv.lv_act_list[0], sv.lv_act_list[1]); for (int i = 0; i < mGlblParms.taskActionListAdapter.getCount(); i++) mGlblParms.taskActionListAdapter.remove(0); for (int i = 0; i < sv.action_adapter_list.size(); i++) mGlblParms.taskActionListAdapter.add(sv.action_adapter_list.get(i)); mGlblParms.taskActionListAdapter.notifyDataSetChanged(); } }, 50); cb_enable_env_parms.setChecked(sv.cb_enable_env_parms); spinnerActionProfile.setSelection(sv.spinnerActionProfile); spinnerBuiltinPrimitiveAction.setSelection(sv.spinnerBuiltinPrimitiveAction); spinnerBuiltinConditionalAction.setSelection(sv.spinnerBuiltinConditionalAction); spinnerBuiltinCancelAction.setSelection(sv.spinnerBuiltinCancelAction); spinnerBuiltinBlockAction.setSelection(sv.spinnerBuiltinBlockAction); spinnerSelectAction.setSelection(sv.spinnerSelectAction); } }, 50); }
From source file:com.google.android.apps.muzei.settings.SettingsActivity.java
private void setupAppBar() { mAppBar = (Toolbar) findViewById(R.id.app_bar); mAppBar.setNavigationOnClickListener(new View.OnClickListener() { @Override//from ww w.ja v a 2s . c o m public void onClick(View view) { onNavigateUp(); } }); final LayoutInflater inflater = LayoutInflater.from(this); Spinner sectionSpinner = (Spinner) findViewById(R.id.section_spinner); sectionSpinner.setAdapter(new BaseAdapter() { @Override public int getCount() { return SECTION_LABELS.length; } @Override public Object getItem(int position) { return SECTION_LABELS[position]; } @Override public long getItemId(int position) { return position + 1; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.settings_ab_spinner_list_item, parent, false); } ((TextView) convertView.findViewById(android.R.id.text1)) .setText(getString(SECTION_LABELS[position])); return convertView; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.settings_ab_spinner_list_item_dropdown, parent, false); } ((TextView) convertView.findViewById(android.R.id.text1)) .setText(getString(SECTION_LABELS[position])); return convertView; } }); sectionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> spinner, View view, int position, long id) { Class<? extends Fragment> fragmentClass = SECTION_FRAGMENTS[position]; Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_container); if (currentFragment != null && fragmentClass.equals(currentFragment.getClass())) { return; } inflateMenuFromFragment(0); try { Fragment newFragment = fragmentClass.newInstance(); getSupportFragmentManager().beginTransaction() .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .setTransitionStyle(R.style.Muzei_SimpleFadeFragmentAnimation) .replace(R.id.content_container, newFragment).commitAllowingStateLoss(); } catch (Exception e) { throw new RuntimeException(e); } } @Override public void onNothingSelected(AdapterView<?> spinner) { } }); sectionSpinner.setSelection(mStartSection); inflateMenuFromFragment(0); mAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_get_more_sources: try { Intent playStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/search?q=Muzei&c=apps")) .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); preferPackageForIntent(SettingsActivity.this, playStoreIntent, PLAY_STORE_PACKAGE_NAME); startActivity(playStoreIntent); } catch (ActivityNotFoundException activityNotFoundException1) { Toast.makeText(SettingsActivity.this, R.string.play_store_not_found, Toast.LENGTH_LONG) .show(); } return true; case R.id.action_about: startActivity(new Intent(SettingsActivity.this, AboutActivity.class)); return true; } Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_container); if (currentFragment != null && currentFragment instanceof SettingsActivityMenuListener) { ((SettingsActivityMenuListener) currentFragment).onSettingsActivityMenuItemClick(item); } return false; } }); }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
/** * Will pop up a dialog to let the user input a new frequency. * Note: A frequency can be entered either in Hz or in MHz. If the input value * is a number smaller than the maximum frequency of the source in MHz, then it * is interpreted as a frequency in MHz. Otherwise it will be handled as frequency * in Hz./*from www . j a va2 s. co m*/ */ private void tuneToFrequency() { if (source == null) return; // calculate max frequency of the source in MHz: final double maxFreqMHz = source.getMaxFrequency() / 1000000f; final LinearLayout ll_view = (LinearLayout) this.getLayoutInflater().inflate(R.layout.tune_to_frequency, null); final EditText et_frequency = (EditText) ll_view.findViewById(R.id.et_tune_to_frequency); final Spinner sp_unit = (Spinner) ll_view.findViewById(R.id.sp_tune_to_frequency_unit); final CheckBox cb_bandwidth = (CheckBox) ll_view.findViewById(R.id.cb_tune_to_frequency_bandwidth); final EditText et_bandwidth = (EditText) ll_view.findViewById(R.id.et_tune_to_frequency_bandwidth); final Spinner sp_bandwidthUnit = (Spinner) ll_view.findViewById(R.id.sp_tune_to_frequency_bandwidth_unit); final TextView tv_warning = (TextView) ll_view.findViewById(R.id.tv_tune_to_frequency_warning); // Show warning if we are currently recording to file: if (recordingFile != null) tv_warning.setVisibility(View.VISIBLE); cb_bandwidth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { et_bandwidth.setEnabled(isChecked); sp_bandwidthUnit.setEnabled(isChecked); } }); cb_bandwidth.toggle(); // to trigger the onCheckedChangeListener at least once to set inital state cb_bandwidth .setChecked(preferences.getBoolean(getString(R.string.pref_tune_to_frequency_setBandwidth), false)); et_bandwidth.setText(preferences.getString(getString(R.string.pref_tune_to_frequency_bandwidth), "1")); sp_unit.setSelection(preferences.getInt(getString(R.string.pref_tune_to_frequency_unit), 0)); sp_bandwidthUnit .setSelection(preferences.getInt(getString(R.string.pref_tune_to_frequency_bandwidthUnit), 0)); new AlertDialog.Builder(this).setTitle("Tune to Frequency") .setMessage(String.format("Frequency is %f MHz. Type a new Frequency: ", source.getFrequency() / 1000000f)) .setView(ll_view).setPositiveButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { double newFreq = source.getFrequency(); if (et_frequency.getText().length() != 0) newFreq = Double.valueOf(et_frequency.getText().toString()); if (sp_unit.getSelectedItemPosition() == 0) //MHz newFreq *= 1000000; else if (sp_unit.getSelectedItemPosition() == 1) //KHz newFreq *= 1000; if (newFreq <= source.getMaxFrequency() && newFreq >= source.getMinFrequency()) { source.setFrequency((long) newFreq); analyzerSurface.setVirtualFrequency((long) newFreq); if (demodulationMode != Demodulator.DEMODULATION_OFF) analyzerSurface.setDemodulationEnabled(true); // This will re-adjust the channel freq correctly // Set bandwidth (virtual sample rate): if (cb_bandwidth.isChecked() && et_bandwidth.getText().length() != 0) { float bandwidth = Float.valueOf(et_bandwidth.getText().toString()); if (sp_bandwidthUnit.getSelectedItemPosition() == 0) //MHz bandwidth *= 1000000; else if (sp_bandwidthUnit.getSelectedItemPosition() == 1) //KHz bandwidth *= 1000; if (bandwidth > source.getMaxSampleRate()) bandwidth = source.getMaxFrequency(); source.setSampleRate(source.getNextHigherOptimalSampleRate((int) bandwidth)); analyzerSurface.setVirtualSampleRate((int) bandwidth); } // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_tune_to_frequency_unit), sp_unit.getSelectedItemPosition()); edit.putBoolean(getString(R.string.pref_tune_to_frequency_setBandwidth), cb_bandwidth.isChecked()); edit.putString(getString(R.string.pref_tune_to_frequency_bandwidth), et_bandwidth.getText().toString()); edit.putInt(getString(R.string.pref_tune_to_frequency_bandwidthUnit), sp_bandwidthUnit.getSelectedItemPosition()); edit.apply(); } else { Toast.makeText(MainActivity.this, "Frequency is out of the valid range: " + (long) newFreq + " Hz", Toast.LENGTH_LONG).show(); } } catch (NumberFormatException e) { Log.e(LOGTAG, "tuneToFrequency: Error while setting frequency: " + e.getMessage()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).show(); }
From source file:com.code.android.vibevault.SearchScreen.java
private void launchSettingsDialog() { final SeekBar seek; final Spinner sortSpin; final Spinner searchSpin; final TextView seekValue; // Make the settings dialog. AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Search Settings"); View v = LayoutInflater.from(this).inflate(R.layout.scrollable_settings_dialog, null); ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { }//from w w w. j a v a2 s. co m }); // Grab all the GUI widgets. seek = (SeekBar) v.findViewById(R.id.NumResultsSeekBar); seek.setProgress(Integer.valueOf(VibeVault.db.getPref("numResults")) - 10); sortSpin = (Spinner) v.findViewById(R.id.SortSpinner); searchSpin = (Spinner) v.findViewById(R.id.SearchSpinner); seekValue = (TextView) v.findViewById(R.id.SeekBarValue); seekValue.setText(VibeVault.db.getPref("numResults")); // Set the seek bar to its current value, and set up a Listener. seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { seekValue.setText(String.valueOf(progress + 10)); VibeVault.db.updatePref("numResults", String.valueOf(progress + 10)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // Set up the spinner, and set up it's OnItemSelectedListener. ArrayAdapter<String> sortAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.sortChoices); sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sortSpin.setAdapter(sortAdapter); int sortPos = 1; String sortOrder = VibeVault.db.getPref("sortOrder"); for (int i = 0; i < VibeVault.sortChoices.length; i++) { if (VibeVault.sortChoices[i].equals(sortOrder)) sortPos = i; } sortSpin.setSelection(sortPos); sortSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.db.updatePref("sortOrder", VibeVault.sortChoices[selected]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.searchChoices); searchAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); searchSpin.setAdapter(searchAdapter); int searchPos = 1; String searchOrder = VibeVault.searchPref; for (int i = 0; i < VibeVault.searchChoices.length; i++) { if (VibeVault.searchChoices[i].equals(searchOrder)) searchPos = i; } searchSpin.setSelection(searchPos); searchSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.searchPref = VibeVault.searchChoices[selected]; if (VibeVault.searchPref.equals("Artist") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Artists..."); } else if (VibeVault.searchPref.equals("Show/Artist Description") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Descriptions..."); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Show the settings screen. ad.setView(v); ad.show(); }
From source file:com.sunmeng.educationaladministration.animateview.GoogleCardsActivity.java
/** * Item??/*from w w w. java 2 s .c om*/ */ public void getDetails() { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Map<String, Object> map; map = (Map<String, Object>) parent.getItemAtPosition(position); LayoutInflater inflater1 = getLayoutInflater(); View view1 = inflater1.inflate(R.layout.activity_extra_detailsinfo, (ViewGroup) findViewById(R.id.toast_layout)); final Spinner spn_extraclassName = (Spinner) view1.findViewById(R.id.spn_uextraclassName); final TextView tv_date = (TextView) view1.findViewById(R.id.ued_date_reply); final EditText et_teacher = (EditText) view1.findViewById(R.id.et_uextrateacher); final EditText et_jointeacher = (EditText) view1.findViewById(R.id.et_uextrajoin); final EditText et_address = (EditText) view1.findViewById(R.id.et_uaddress); final TextView tv_update_reply = (TextView) view1.findViewById(R.id.tvUpdate); final EditText et_uatime = (EditText) view1.findViewById(R.id.et_uatime); img_back = (ImageView) view1.findViewById(R.id.ivBack); img_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); /** * ??? */ httpUtils.send(HttpRequest.HttpMethod.GET, HttpClientUtil.HTTP_URL + "ClassAllServlet", new RequestCallBack() { @Override public void onSuccess(final ResponseInfo responseInfo) { //Toast.makeText(mContext, responseInfo.toString(), Toast.LENGTH_LONG).show(); final List<String> list = new ArrayList<String>(); list.add("cnname"); list.add("cnid"); new AsyncTask<String, String, Map<String, String>>() { @Override protected Map<String, String> doInBackground(String... params) { classNameArr = JsonUtil .getJsonToSpinnerListMap(responseInfo.result.toString(), list); return classNameArr; } @Override protected void onPostExecute(Map<String, String> s) { //android.R.layout.simple_spinner_dropdown_item// //R.layout.myspinner spn_extraclassName.setAdapter( new android.widget.ArrayAdapter<String>(GoogleCardsActivity.this, android.R.layout.simple_spinner_dropdown_item, Utils.getMapListToListString(s))); if (map.get("cnname").toString() != "") { spn_extraclassName.setSelection( Utils.getMapListId(s, map.get("cnname").toString())); spn_extraclassName.setEnabled(false); } else { } // et_classname_reply.setSelection(2, true); } }.execute(""); } @Override public void onFailure(HttpException e, String s) { } }); et_teacher.setText(map.get("ateacher").toString()); et_jointeacher.setText(map.get("ajointeacher").toString()); et_address.setText(map.get("aaddress").toString()); tv_date.setText(map.get("adate").toString()); et_uatime.setText(map.get("atime").toString()); tv_update_reply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (tv_update_reply.getText().equals("")) { setClickble(true); tv_update_reply.setText("?"); } else if (tv_update_reply.getText().equals("?")) { setClickble(false); tv_update_reply.setText(""); // TODO ?? updateReply(); } } /** * ?? */ private void setClickble(boolean flag) { et_teacher.setEnabled(flag); et_jointeacher.setEnabled(flag); et_address.setEnabled(flag); spn_extraclassName.setEnabled(flag); et_uatime.setEnabled(flag); } public void updateReply() { String etteacher = et_teacher.getText().toString().trim(); String etjointeacher = et_jointeacher.getText().toString().trim(); String ettime = et_uatime.getText().toString().trim(); String etaddress = et_address.getText().toString().trim(); String tvdate = tv_date.getText().toString().trim(); String classnumid = classNameArr .get(spn_extraclassName.getSelectedItem().toString().trim());//?id String id = map.get("aid").toString(); //Toast.makeText(GoogleCardsActivity.this, "="+etteacher+etjointeacher+ettime+etaddress, Toast.LENGTH_SHORT).show(); if ("".equals(etteacher) && "".equals(etjointeacher) && "".equals(etaddress)) { Toast.makeText(GoogleCardsActivity.this, "???", Toast.LENGTH_SHORT) .show(); return; } else { RequestParams params = new RequestParams(); params.addBodyParameter("activitiesupcdate", tvdate); params.addBodyParameter("activitiesuptime", ettime); params.addBodyParameter("activitiesupclassnumid", classnumid); params.addBodyParameter("activitiesupteacher", etteacher); params.addBodyParameter("activitiesupjointeacher", etjointeacher); params.addBodyParameter("activitiesupaddress", etaddress); params.addBodyParameter("activitiesuprid", id); Toast.makeText(GoogleCardsActivity.this, "id==" + id, Toast.LENGTH_SHORT).show(); httpUtils.send(HttpRequest.HttpMethod.POST, HttpClientUtil.HTTP_URL + "ActivitiesUpdateServlet", params, new RequestCallBack() { @Override public void onSuccess(ResponseInfo responseInfo) { Toast.makeText(GoogleCardsActivity.this, "?", Toast.LENGTH_SHORT).show(); getData(); dialog.cancel(); } @Override public void onFailure(HttpException e, String s) { Toast.makeText(GoogleCardsActivity.this, "", Toast.LENGTH_SHORT).show(); } }); } } }); builder = new AlertDialog.Builder(parent.getContext()); builder.setView(view1); dialog = builder.create(); dialog.show(); } }); }
From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java
private void initCamera(final View rootView) { mCameraExposureFormat = getString(R.string.trace_camera_exposure); mCameraSaturationFormat = getString(R.string.trace_camera_saturation); mCameraPanFormat = getString(R.string.trace_camera_pan); mCameraTiltFormat = getString(R.string.trace_camera_tilt); SeekBar sb;//from w w w . j a v a2s. c o m // ? mCameraAutoWhiteBlance = getInt(mPref, KEY_CAMERA_WHITE_BLANCE, DEFAULT_CAMERA_WHITE_BLANCE); final Spinner spinner = (Spinner) rootView.findViewById(R.id.camera_white_blance_spinner); spinner.setAdapter(new WhiteBlanceAdapter(getActivity())); spinner.setSelection(mCameraAutoWhiteBlance + 1); spinner.setOnItemSelectedListener(mOnItemSelectedListener); // mCameraExposure = mPref.getFloat(KEY_CAMERA_EXPOSURE, DEFAULT_CAMERA_EXPOSURE); mCameraExposureLabel = (TextView) rootView.findViewById(R.id.camera_exposure_textview); sb = (SeekBar) rootView.findViewById(R.id.camera_exposure_seekbar); sb.setMax(3000); sb.setProgress(cameraExposureToProgress(mCameraExposure)); // [-1.5,+ 1.5] => [0, 3000] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateCameraExposure(mCameraExposure); // mCameraSaturation = mPref.getFloat(KEY_CAMERA_SATURATION, DEFAULT_CAMERA_SATURATION); mCameraSaturationLabel = (TextView) rootView.findViewById(R.id.camera_saturation_textview); sb = (SeekBar) rootView.findViewById(R.id.camera_saturation_seekbar); sb.setMax(2000); sb.setProgress((int) (mCameraSaturation * 10.0f) + 1000); // [-100.0f, +100.0f] => [0, 2000] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateCameraSaturation(mCameraSaturation); // mCameraPan = getInt(mPref, KEY_CAMERA_PAN, DEFAULT_CAMERA_PAN); mCameraPanLabel = (TextView) rootView.findViewById(R.id.camera_pan_textview); sb = (SeekBar) rootView.findViewById(R.id.camera_pan_seekbar); sb.setMax(40); sb.setProgress(cameraPanTiltToProgress(mCameraPan)); // [-100,+100] => [0, 40] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateCameraPan(mCameraPan); // ? mCameraTilt = getInt(mPref, KEY_CAMERA_TILT, DEFAULT_CAMERA_TILT); mCameraTiltLabel = (TextView) rootView.findViewById(R.id.camera_tilt_textview); sb = (SeekBar) rootView.findViewById(R.id.camera_tilt_seekbar); sb.setMax(40); sb.setProgress(cameraPanTiltToProgress(mCameraTilt)); // [-100,+100] => [0, 40] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateCameraTilt(mCameraTilt); }
From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java
/** * @param fieldTable//from w w w.jav a 2 s . co m * @param nameOfField * @param field */ private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal, final String fieldRemote) { if (mCurrentLocal == null || mCurrentSugar == null) return; // String fieldLocal = mCurrentLocal.get(nameOfField); // String fieldRemote = mCurrentSugar.get(nameOfField); TableRow row = new TableRow(this); final Spinner sourceSelect = new Spinner(this); sourceSelect.setBackgroundResource(R.drawable.black_underline); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources)); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sourceSelect.setAdapter(spinnerArrayAdapter); // Open the spinner when pressing any of the text fields OnClickListener spinnerOpener = new OnClickListener() { @Override public void onClick(View v) { sourceSelect.performClick(); } }; row.addView(sourceSelect); fieldTable.addView(row); row = new TableRow(this); TextView fieldName = new TextView(this); int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName()); fieldName.setText(this.getString(stringId)); fieldName.setTextSize(16); fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(), fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom()); fieldName.setOnClickListener(spinnerOpener); row.addView(fieldName); final TextView fieldValueLocal = new TextView(this); fieldValueLocal.setText(fieldLocal); fieldValueLocal.setTextSize(16); row.addView(fieldValueLocal); fieldValueLocal.setOnClickListener(spinnerOpener); fieldTable.addView(row); row = new TableRow(this); row.addView(new TextView(this));// add dummy control final TextView fieldValueRemote = new TextView(this); fieldValueRemote.setText(fieldRemote); fieldValueRemote.setTextSize(16); fieldValueRemote.setOnClickListener(spinnerOpener); row.addView(fieldValueRemote); sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); resolvedContacts[mPosResolved].set(nameOfField, fieldLocal); } else { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); resolvedContacts[mPosResolved].set(nameOfField, fieldRemote); } } @Override public void onNothingSelected(AdapterView<?> view) { } }); row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10); // Restore appropiate selections according to resolved contact if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) { sourceSelect.setSelection(0); } else { sourceSelect.setSelection(1); } fieldTable.addView(row); }