{ editorToolsImpls[EditorTools.MARKER.ordinal()] = new MarkerToolsImpl(this); editorToolsImpls[EditorTools.DRAW.ordinal()] = new DrawToolsImpl(this); editorToolsImpls[EditorTools.TRASH.ordinal()] = new TrashToolsImpl(this); editorToolsImpls[EditorTools.SELECTOR.ordinal()] = new SelectorToolsImpl(this); editorToolsImpls[EditorTools.NONE.ordinal()] = new NoneToolsImpl(this); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (savedInstanceState != null) { // Retrieve the tool that was last selected before the fragment was destroyed. final String toolName = savedInstanceState.getString(STATE_SELECTED_TOOL, tool.name()); tool = EditorTools.valueOf(toolName); for (EditorToolsImpl toolImpl : editorToolsImpls) toolImpl.onRestoreInstanceState(savedInstanceState); } final Resources res = getResources(); popupLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()); final Context context = getContext(); final LayoutInflater inflater = getActivity().getLayoutInflater(); final int popupWidth = ViewGroup.LayoutParams.WRAP_CONTENT; final int popupHeight = ViewGroup.LayoutParams.WRAP_CONTENT; final Drawable popupBg = res.getDrawable(android.R.color.transparent); mEditorRadioGroup = (RadioGroup) view.findViewById(R.id.editor_tools_layout); final DrawToolsImpl drawToolImpl = (DrawToolsImpl) editorToolsImpls[EditorTools.DRAW.ordinal()]; final RadioButtonCenter buttonDraw = (RadioButtonCenter) view.findViewById(R.id.editor_tools_draw); final View drawPopupView = inflater.inflate(R.layout.popup_editor_tool_draw, (ViewGroup) view, false); final AdapterMissionItems drawItemsAdapter = new AdapterMissionItems( context, R.layout.spinner_drop_down_flight_mode, DrawToolsImpl.DRAW_ITEMS_TYPE); final Spinner drawItemsSpinner = (Spinner) drawPopupView.findViewById(R.id.draw_items_spinner); drawItemsSpinner.setAdapter(drawItemsAdapter); drawItemsSpinner.setSelection(drawItemsAdapter.getPosition(drawToolImpl.getSelected())); drawItemsSpinner.setOnItemSelectedListener(drawToolImpl); drawPopup = new PopupWindow(drawPopupView, popupWidth, popupHeight, true); drawPopup.setBackgroundDrawable(popupBg); final MarkerToolsImpl markerToolImpl = (MarkerToolsImpl) editorToolsImpls[EditorTools.MARKER.ordinal()]; final RadioButtonCenter buttonMarker = (RadioButtonCenter) view.findViewById(R.id.editor_tools_marker); final View markerPopupView = inflater.inflate(R.layout.popup_editor_tool_marker, (ViewGroup) view, false); final AdapterMissionItems markerItemsAdapter = new AdapterMissionItems( context, R.layout.spinner_drop_down_flight_mode, MarkerToolsImpl.MARKER_ITEMS_TYPE); final Spinner markerItemsSpinner = (Spinner) markerPopupView.findViewById(R.id.marker_items_spinner); markerItemsSpinner.setAdapter(markerItemsAdapter); markerItemsSpinner.setSelection(markerItemsAdapter.getPosition(markerToolImpl.getSelected())); markerItemsSpinner.setOnItemSelectedListener(markerToolImpl); markerPopup = new PopupWindow(markerPopupView, popupWidth, popupHeight, true); markerPopup.setBackgroundDrawable(popupBg); final RadioButtonCenter buttonTrash = (RadioButtonCenter) view.findViewById(R.id.editor_tools_trash); final View trashPopupView = inflater.inflate(R.layout.popup_editor_tool_trash, (ViewGroup) view, false); final TrashToolsImpl trashToolImpl = (TrashToolsImpl) editorToolsImpls[EditorTools.TRASH.ordinal()]; final TextView clearMission = (TextView) trashPopupView.findViewById(R.id.clear_mission_button); clearMission.setOnClickListener(trashToolImpl); trashPopup = new PopupWindow(trashPopupView, popupWidth, popupHeight, true); trashPopup.setBackgroundDrawable(popupBg); final RadioButtonCenter buttonSelector = (RadioButtonCenter) view.findViewById(R.id.editor_tools_selector); final View selectorPopupView = inflater.inflate(R.layout.popup_editor_tool_selector, (ViewGroup) view, false); final SelectorToolsImpl selectorToolImpl = (SelectorToolsImpl) editorToolsImpls[EditorTools.SELECTOR.ordinal()]; final TextView selectAll = (TextView) selectorPopupView.findViewById(R.id.select_all_button); selectAll.setOnClickListener(selectorToolImpl); selectorPopup = new PopupWindow(selectorPopupView, popupWidth, popupHeight, true); selectorPopup.setBackgroundDrawable(popupBg); for (View vv : new View[] {buttonDraw, buttonMarker, buttonTrash, buttonSelector}) { vv.setOnClickListener(this); } }