Search in sources :

Example 1 with CoordinateInputAdapter

use of net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter in project Osmand by osmandapp.

the class CoordinateInputDialogFragment method registerMainView.

private void registerMainView() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    final Context ctx = getContext();
    if (orientationPortrait) {
        View.OnClickListener backspaceOnClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.lat_backspace_btn) {
                    clearInputs(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_third_input_et);
                } else {
                    clearInputs(R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_third_input_et);
                }
            }
        };
        ImageView latBackspaceBtn = (ImageView) mainView.findViewById(R.id.lat_backspace_btn);
        latBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_clear_all_fields));
        latBackspaceBtn.setOnClickListener(backspaceOnClickListener);
        ImageView lonBackspaceBtn = (ImageView) mainView.findViewById(R.id.lon_backspace_btn);
        lonBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_clear_all_fields));
        lonBackspaceBtn.setOnClickListener(backspaceOnClickListener);
        showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon);
    } else {
        boolean rightHand = getMyApplication().getSettings().COORDS_INPUT_USE_RIGHT_SIDE.get();
        LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container);
        View dataAreaView = View.inflate(ctx, R.layout.coordinate_input_land_data_area, null);
        View keyboardAndListView = View.inflate(ctx, R.layout.coordinate_input_land_keyboard_and_list, null);
        setBackgroundColor(dataAreaView, lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark);
        setBackgroundColor(keyboardAndListView, lightTheme ? R.color.ctx_menu_info_view_bg_light : R.color.coordinate_input_markers_list_bg_dark);
        ((FrameLayout) handContainer.findViewById(R.id.left_container)).addView(rightHand ? dataAreaView : keyboardAndListView, 0);
        ((FrameLayout) handContainer.findViewById(R.id.right_container)).addView(rightHand ? keyboardAndListView : dataAreaView, 0);
        showHideKeyboardIcon = (ImageView) dataAreaView.findViewById(rightHand ? R.id.show_hide_keyboard_icon_right : R.id.show_hide_keyboard_icon_left);
        showHideKeyboardIcon.setVisibility(View.VISIBLE);
        dataAreaView.findViewById(rightHand ? R.id.show_hide_keyboard_icon_left : R.id.show_hide_keyboard_icon_right).setVisibility(View.GONE);
        handContainer.findViewById(R.id.input_area_top_padding).setVisibility(View.VISIBLE);
        handContainer.findViewById(R.id.point_name_top_space).setVisibility(View.VISIBLE);
        handContainer.findViewById(R.id.right_shadow).setVisibility(rightHand ? View.VISIBLE : View.GONE);
        handContainer.findViewById(R.id.left_shadow).setVisibility(rightHand ? View.GONE : View.VISIBLE);
        handContainer.findViewById(R.id.lat_backspace_btn).setVisibility(View.GONE);
        handContainer.findViewById(R.id.lon_backspace_btn).setVisibility(View.GONE);
        handContainer.findViewById(R.id.lat_end_padding).setVisibility(View.VISIBLE);
        handContainer.findViewById(R.id.lon_end_padding).setVisibility(View.VISIBLE);
    }
    registerInputs();
    setupSideOfTheWorldBtns(R.id.lat_side_of_the_world_btn, R.id.lon_side_of_the_world_btn);
    setBackgroundColor(R.id.point_name_divider, lightTheme ? R.color.route_info_divider_light : R.color.route_info_divider_dark);
    setBackgroundColor(R.id.point_name_et_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.route_info_bottom_view_bg_dark);
    ImageView pointNameKeyboardBtn = (ImageView) mainView.findViewById(R.id.point_name_keyboard_btn);
    pointNameKeyboardBtn.setImageDrawable(getColoredIcon(R.drawable.ic_action_keyboard, R.color.icon_color));
    pointNameKeyboardBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (isOsmandKeyboardCurrentlyVisible()) {
                changeOsmandKeyboardVisibility(false);
            }
            for (EditText et : editTexts) {
                if (et.getId() == R.id.point_name_et) {
                    et.requestFocus();
                }
            }
            final View focusedView = getDialog().getCurrentFocus();
            if (focusedView != null) {
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        isSoftKeyboardShown = true;
                        AndroidUtils.showSoftKeyboard(focusedView);
                        showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide));
                    }
                }, 200);
            }
        }
    });
    adapter = new CoordinateInputAdapter(mapActivity, mapMarkers);
    RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
        }
    });
    setBackgroundColor(R.id.bottom_controls_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.keyboard_item_control_dark_bg);
    TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
    addButton.setBackgroundResource(lightTheme ? R.drawable.route_info_go_btn_bg_light : R.drawable.route_info_go_btn_bg_dark);
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            addMapMarker();
        }
    });
    mainView.findViewById(R.id.keyboard_layout).setBackgroundResource(lightTheme ? R.drawable.bg_bottom_menu_light : R.drawable.bg_coordinate_input_keyboard_dark);
    View keyboardView = mainView.findViewById(R.id.keyboard_view);
    int dividersColorResId = lightTheme ? R.color.keyboard_divider_light : R.color.keyboard_divider_dark;
    setBackgroundColor(keyboardView, dividersColorResId);
    setBackgroundColor(R.id.keyboard_divider, dividersColorResId);
    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isOsmandKeyboardOn()) {
                View focusedView = getDialog().getCurrentFocus();
                if (focusedView != null && focusedView instanceof EditText) {
                    EditText focusedEditText = (EditText) focusedView;
                    int id = v.getId();
                    switch(id) {
                        case R.id.keyboard_item_clear:
                            focusedEditText.setText("");
                            break;
                        case R.id.keyboard_item_backspace:
                            String str = focusedEditText.getText().toString();
                            if (str.length() > 0) {
                                str = str.substring(0, str.length() - 1);
                                focusedEditText.setText(str);
                                focusedEditText.setSelection(str.length());
                            } else {
                                switchEditText(focusedEditText.getId(), false);
                            }
                            break;
                        case R.id.keyboard_item_next_field:
                            switchEditText(focusedEditText.getId(), true);
                            break;
                        default:
                            focusedEditText.setText(focusedEditText.getText().toString() + getItemObjectById(id));
                            focusedEditText.setSelection(focusedEditText.getText().length());
                    }
                }
            }
        }
    };
    setupKeyboardItems(keyboardView, onClickListener, R.id.keyboard_item_0, R.id.keyboard_item_1, R.id.keyboard_item_2, R.id.keyboard_item_3, R.id.keyboard_item_4, R.id.keyboard_item_5, R.id.keyboard_item_6, R.id.keyboard_item_7, R.id.keyboard_item_8, R.id.keyboard_item_9, R.id.keyboard_item_clear, R.id.keyboard_item_next_field, R.id.keyboard_item_backspace);
    if (!isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) {
        changeOsmandKeyboardVisibility(false);
    }
    showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide));
    showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible();
            if (isOsmandKeyboardOn() && !isSoftKeyboardShown) {
                changeOsmandKeyboardVisibility(!isCurrentlyVisible);
            } else {
                final View focusedView = getDialog().getCurrentFocus();
                if (focusedView != null) {
                    if (isSoftKeyboardShown) {
                        isSoftKeyboardShown = false;
                        AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
                        showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_show));
                    } else {
                        new Handler().postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                isSoftKeyboardShown = true;
                                AndroidUtils.showSoftKeyboard(focusedView);
                                showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide));
                            }
                        }, 200);
                    }
                    changeEditTextSelections();
                }
            }
        }
    });
    mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            mainView.getWindowVisibleDisplayFrame(r);
            int screenHeight = mainView.getRootView().getHeight();
            int keypadHeight = screenHeight - r.bottom;
            if (keypadHeight > screenHeight * 0.15) {
                isSoftKeyboardShown = true;
                showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide));
            } else {
                isSoftKeyboardShown = false;
            }
        }
    });
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) Rect(android.graphics.Rect) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) FrameLayout(android.widget.FrameLayout) CoordinateInputAdapter(net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

Context (android.content.Context)1 Rect (android.graphics.Rect)1 Handler (android.os.Handler)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 MapActivity (net.osmand.plus.activities.MapActivity)1 CoordinateInputAdapter (net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter)1