Search in sources :

Example 1 with BaseItemAdapter

use of com.foobnix.android.utils.BaseItemAdapter in project LibreraReader by foobnix.

the class DragingDialogs method editColorsPanel.

public static void editColorsPanel(final FrameLayout anchor, final DocumentController controller, final DrawView drawView, final boolean force) {
    drawView.setOnFinishDraw(new Runnable() {

        @Override
        public void run() {
            String annotationDrawColor = AppState.get().annotationDrawColor;
            if (TxtUtils.isEmpty(annotationDrawColor)) {
                annotationDrawColor = AppState.get().COLORS.get(0);
            }
            controller.saveChanges(drawView.getPoints(), Color.parseColor(annotationDrawColor));
            drawView.clear();
            controller.saveAnnotationsToFile();
        }
    });
    new DragingPopup(R.string.annotations_draw, anchor, 250, 150) {

        @Override
        public void closeDialog() {
            super.closeDialog();
            AppState.get().editWith = AppState.EDIT_NONE;
            AppState.get().annotationDrawColor = "";
            drawView.setVisibility(View.GONE);
            drawView.clear();
        }

        @Override
        public View getContentView(final LayoutInflater inflater) {
            View a = inflater.inflate(R.layout.edit_panel, null, false);
            final GridView grid = (GridView) a.findViewById(R.id.gridColors);
            if (AppState.get().editWith == AppState.EDIT_DELETE) {
                AppState.get().annotationDrawColor = AppState.get().COLORS.get(0);
            }
            final BaseItemAdapter<String> adapter = new BaseItemAdapter<String>(AppState.get().COLORS) {

                @Override
                public View getView(int pos, View arg1, ViewGroup arg2, String color) {
                    View view = null;
                    if (pos == 0) {
                        view = inflater.inflate(R.layout.item_color_cut, arg2, false);
                    } else if (pos == 1) {
                        view = inflater.inflate(R.layout.item_color_spinner, arg2, false);
                        final Spinner spinner = (Spinner) view.findViewById(R.id.spinner1);
                        final List<Float> values = Arrays.asList(0.5f, 0.75f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f);
                        spinner.setAdapter(new BaseItemLayoutAdapter<Float>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item, values) {

                            @Override
                            public void populateView(View inflate, int arg1, Float value) {
                                TextView text = Views.text(inflate, android.R.id.text1, "" + value + "");
                            }
                        });
                        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

                            @Override
                            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                spinner.setSelection(position);
                                AppState.get().editLineWidth = values.get(position);
                                int acolor = IMG.alphaColor(AppState.get().editAlphaColor, AppState.get().annotationDrawColor);
                                drawView.setColor(acolor, AppState.get().editLineWidth);
                                try {
                                    TextView textView = (TextView) spinner.getChildAt(0);
                                    textView.setTextAppearance(controller.getActivity(), R.style.textLinkStyle);
                                } catch (Exception e) {
                                }
                            }

                            @Override
                            public void onNothingSelected(AdapterView<?> parent) {
                            }
                        });
                        spinner.setSelection(values.indexOf(AppState.get().editLineWidth));
                    } else if (pos == 2121) {
                        view = inflater.inflate(R.layout.item_color_spinner, arg2, false);
                        final Spinner spinner = (Spinner) view.findViewById(R.id.spinner1);
                        final List<Integer> values = Arrays.asList(100, 90, 80, 70, 60, 50, 40, 30, 20, 10);
                        spinner.setAdapter(new BaseItemLayoutAdapter<Integer>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item, values) {

                            @Override
                            public void populateView(View inflate, int arg1, Integer value) {
                                TextView text = Views.text(inflate, android.R.id.text1, "" + value + "%");
                            }
                        });
                        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

                            @Override
                            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                spinner.setSelection(position);
                                AppState.get().editAlphaColor = values.get(position);
                                int acolor = IMG.alphaColor(AppState.get().editAlphaColor, AppState.get().annotationDrawColor);
                                drawView.setColor(acolor, AppState.get().editLineWidth);
                            // ((TextView)
                            // spinner.getChildAt(0)).setTextColor(anchor.getResources().getColor(R.color.grey_800));
                            }

                            @Override
                            public void onNothingSelected(AdapterView<?> parent) {
                            }
                        });
                        spinner.setSelection(values.indexOf(AppState.get().editAlphaColor));
                    } else {
                        view = inflater.inflate(R.layout.item_color, arg2, false);
                        int acolor = IMG.alphaColor(AppState.get().editAlphaColor, color);
                        view.findViewById(R.id.itColor).setBackgroundColor(acolor);
                    }
                    view.setTag(color);
                    if (color.equals(AppState.get().annotationDrawColor)) {
                        view.setBackgroundResource(R.drawable.bg_border_1_lines);
                    } else {
                        view.setBackgroundColor(Color.TRANSPARENT);
                    }
                    return view;
                }
            };
            grid.setAdapter(adapter);
            grid.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    AppState.get().editWith = AppState.EDIT_PEN;
                    if (view.getTag().equals(AppState.get().annotationDrawColor)) {
                        AppState.get().annotationDrawColor = "";
                        drawView.setVisibility(View.GONE);
                    } else {
                        AppState.get().annotationDrawColor = (String) view.getTag();
                        int acolor = IMG.alphaColor(AppState.get().editAlphaColor, AppState.get().annotationDrawColor);
                        drawView.setColor(acolor, AppState.get().editLineWidth);
                        drawView.setVisibility(View.VISIBLE);
                        if (position == 0) {
                            drawView.setVisibility(View.GONE);
                            AppState.get().editWith = AppState.EDIT_DELETE;
                        }
                    }
                    adapter.notifyDataSetChanged();
                }
            });
            return a;
        }
    }.show(EDIT_COLORS_PANEL, force);
}
Also used : Spinner(android.widget.Spinner) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) BaseItemAdapter(com.foobnix.android.utils.BaseItemAdapter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 BaseItemAdapter (com.foobnix.android.utils.BaseItemAdapter)1 BaseItemLayoutAdapter (com.foobnix.android.utils.BaseItemLayoutAdapter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1