Search in sources :

Example 1 with StringResponse

use of com.foobnix.StringResponse in project LibreraReader by foobnix.

the class BrightnessHelper method showBlueLigthDialogAndBrightness.

public static void showBlueLigthDialogAndBrightness(final Activity a, View inflate, final Runnable onRefresh) {
    final CheckBox isEnableBlueFilter = (CheckBox) inflate.findViewById(R.id.isEnableBlueFilter);
    isEnableBlueFilter.setVisibility(Dips.isEInk(a) ? View.GONE : View.VISIBLE);
    isEnableBlueFilter.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            AppState.get().isEnableBlueFilter = isChecked;
            if (onRefresh != null) {
                onRefresh.run();
            }
        }
    });
    final TextView onBlueFilter = (TextView) inflate.findViewById(R.id.onBlueFilter);
    onBlueFilter.setVisibility(Dips.isEInk(a) ? View.GONE : View.VISIBLE);
    TxtUtils.underlineTextView(onBlueFilter);
    onBlueFilter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            builder.setTitle(R.string.bluelight_filter);
            final View inflate = LayoutInflater.from(a).inflate(R.layout.dialog_bluelight, null, false);
            final CustomColorView blueLightColor = (CustomColorView) inflate.findViewById(R.id.blueLightColor);
            TxtUtils.bold(blueLightColor.getText1());
            blueLightColor.withDefaultColors(AppState.BLUE_FILTER_DEFAULT_COLOR, Color.parseColor("#FFDD00"), Color.RED, Color.GREEN);
            blueLightColor.init(AppState.get().blueLightColor);
            blueLightColor.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    AppState.get().isEnableBlueFilter = true;
                    AppState.get().blueLightColor = Color.parseColor(string);
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    // Keyboards.hideNavigation(a);
                    return false;
                }
            });
            final CustomSeek blueLightAlpha = (CustomSeek) inflate.findViewById(R.id.blueLightAlpha);
            blueLightAlpha.init(0, 99, AppState.get().blueLightAlpha);
            blueLightAlpha.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    AppState.get().isEnableBlueFilter = true;
                    AppState.get().blueLightAlpha = result;
                    blueLightAlpha.setValueText("" + AppState.get().blueLightAlpha + "%");
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    return false;
                }
            });
            blueLightAlpha.setValueText("" + AppState.get().blueLightAlpha + "%");
            builder.setView(inflate);
            builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(final DialogInterface dialog, final int id) {
                    isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            AlertDialog dialog = builder.create();
            dialog.setOnDismissListener(new OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    Keyboards.hideNavigation(a);
                }
            });
            dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            dialog.show();
        }
    });
    // brightness
    final CheckBox autoSettings = (CheckBox) inflate.findViewById(R.id.autoSettings);
    final int systemBrigtnessInt = getSystemBrigtnessInt(a);
    final CustomSeek customBrightness = (CustomSeek) inflate.findViewById(R.id.customBrightness);
    int value = 0;
    if (AppState.get().appBrightness == AppState.AUTO_BRIGTNESS) {
        value = systemBrigtnessInt;
    } else {
        value = AppState.get().isEnableBlueFilter ? AppState.get().blueLightAlpha * -1 : AppState.get().appBrightness;
    }
    customBrightness.init(-100, 100, value);
    customBrightness.setOnSeekChanged(new IntegerResponse() {

        @Override
        public boolean onResultRecive(int result) {
            customBrightness.setValueText("" + result);
            EventBus.getDefault().post(new MessegeBrightness(result));
            isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
            return false;
        }
    });
    autoSettings.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (!buttonView.isPressed()) {
                return;
            }
            if (isChecked) {
                // auto
                customBrightness.setEnabled(false);
                customBrightness.reset(systemBrigtnessInt);
                EventBus.getDefault().post(new MessegeBrightness(AppState.AUTO_BRIGTNESS));
            } else {
                customBrightness.setEnabled(true);
                EventBus.getDefault().post(new MessegeBrightness(systemBrigtnessInt));
            }
            isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
        }
    });
    isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
    autoSettings.setChecked(AppState.get().appBrightness == AppState.AUTO_BRIGTNESS);
    customBrightness.setEnabled(AppState.get().appBrightness != AppState.AUTO_BRIGTNESS);
}
Also used : AlertDialog(android.app.AlertDialog) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) StringResponse(com.foobnix.StringResponse) MessegeBrightness(com.foobnix.pdf.search.activity.msg.MessegeBrightness) View(android.view.View) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 2 with StringResponse

use of com.foobnix.StringResponse in project LibreraReader by foobnix.

the class DragingDialogs method moreBookSettings.

public static DragingPopup moreBookSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
    final int initCssHash = BookCSS.get().toCssString().hashCode();
    DragingPopup dialog = new DragingPopup(R.string.reading_settings, anchor, PREF_WIDTH, PREF_HEIGHT) {

        @Override
        public void beforeCreate() {
            titleAction = controller.getString(R.string.preferences);
            titleRunnable = new Runnable() {

                @Override
                public void run() {
                    if (initCssHash != BookCSS.get().toCssString().hashCode()) {
                        AlertDialogs.showDialog(controller.getActivity(), controller.getString(R.string.you_neet_to_apply_the_new_settings), controller.getString(R.string.apply), new Runnable() {

                            @Override
                            public void run() {
                                closeDialog();
                            }
                        });
                    } else {
                        preferences(anchor, controller, onRefresh, updateUIRefresh);
                    }
                }
            };
        }

        @Override
        public View getContentView(final LayoutInflater inflater) {
            View inflate = inflater.inflate(R.layout.dialog_reading_pref, null, false);
            final CustomSeek fontWeight = (CustomSeek) inflate.findViewById(R.id.fontWeight);
            fontWeight.init(1, 9, BookCSS.get().fontWeight / 100);
            fontWeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    fontWeight.setValueText("" + (result * 100));
                    BookCSS.get().fontWeight = result * 100;
                    return false;
                }
            });
            fontWeight.setValueText("" + BookCSS.get().fontWeight);
            // begin styles
            final List<String> docStyles = // 
            Arrays.asList(// 
            controller.getString(R.string.document_styles) + " + " + controller.getString(R.string.user_styles), // 
            controller.getString(R.string.document_styles), controller.getString(R.string.user_styles));
            final TextView docStyle = (TextView) inflate.findViewById(R.id.documentStyle);
            docStyle.setText(docStyles.get(BookCSS.get().documentStyle));
            TxtUtils.underlineTextView(docStyle);
            inflate.findViewById(R.id.documentStyleLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            docStyle.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (int i = 0; i < docStyles.size(); i++) {
                        String type = docStyles.get(i);
                        final int j = i;
                        popupMenu.getMenu().add(type).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().documentStyle = j;
                                docStyle.setText(docStyles.get(BookCSS.get().documentStyle));
                                TxtUtils.underlineTextView(docStyle);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // end styles
            // hypens
            boolean isSupportHypens = controller.isTextFormat();
            CheckBox isAutoHypens = (CheckBox) inflate.findViewById(R.id.isAutoHypens);
            isAutoHypens.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
            isAutoHypens.setChecked(BookCSS.get().isAutoHypens);
            isAutoHypens.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    BookCSS.get().isAutoHypens = isChecked;
                }
            });
            final TextView hypenLangLabel = (TextView) inflate.findViewById(R.id.hypenLangLabel);
            final TextView hypenLang = (TextView) inflate.findViewById(R.id.hypenLang);
            hypenLang.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
            hypenLangLabel.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
            // hypenLang.setVisibility(View.GONE);
            // hypenLangLabel.setVisibility(View.GONE);
            hypenLang.setText(DialogTranslateFromTo.getLanuageByCode(BookCSS.get().hypenLang));
            TxtUtils.underlineTextView(hypenLang);
            hypenLang.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    HyphenPattern[] values = HyphenPattern.values();
                    List<String> all = new ArrayList<String>();
                    for (HyphenPattern p : values) {
                        String e = DialogTranslateFromTo.getLanuageByCode(p.lang) + ":" + p.lang;
                        all.add(e);
                    }
                    Collections.sort(all);
                    for (final String langFull : all) {
                        String[] split = langFull.split(":");
                        final String titleLang = split[0];
                        final String code = split[1];
                        popupMenu.getMenu().add(titleLang).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().hypenLang = code;
                                hypenLang.setText(titleLang);
                                TxtUtils.underlineTextView(hypenLang);
                                FileMeta load = AppDB.get().load(controller.getCurrentBook().getPath());
                                if (load != null) {
                                    load.setLang(code);
                                    AppDB.get().update(load);
                                }
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // - hypens
            View customCSS = inflate.findViewById(R.id.customCSS);
            // TxtUtils.underlineTextView(customCSS);
            customCSS.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
                    builder.setTitle(R.string.custom_css);
                    final EditText edit = new EditText(v.getContext());
                    edit.setMinWidth(Dips.dpToPx(1000));
                    edit.setLines(8);
                    edit.setGravity(Gravity.TOP);
                    edit.setText(BookCSS.get().customCSS1);
                    builder.setView(edit);
                    builder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(final DialogInterface dialog, final int id) {
                            BookCSS.get().customCSS1 = edit.getText().toString();
                            BookCSS.get().save(v.getContext());
                        }
                    });
                    builder.show();
                }
            });
            final CustomSeek lineHeight = (CustomSeek) inflate.findViewById(R.id.lineHeight);
            lineHeight.init(0, 30, BookCSS.get().lineHeight);
            lineHeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().lineHeight = result;
                    return false;
                }
            });
            final CustomSeek paragraphHeight = (CustomSeek) inflate.findViewById(R.id.paragraphHeight);
            paragraphHeight.init(0, 20, BookCSS.get().paragraphHeight);
            paragraphHeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().paragraphHeight = result;
                    return false;
                }
            });
            final CustomSeek fontParagraph = (CustomSeek) inflate.findViewById(R.id.fontParagraph);
            fontParagraph.init(0, 30, BookCSS.get().textIndent);
            fontParagraph.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().textIndent = result;
                    return false;
                }
            });
            final CustomSeek emptyLine = (CustomSeek) inflate.findViewById(R.id.emptyLine);
            // || //
            boolean isShow = BookType.FB2.is(controller.getCurrentBook().getPath());
            // BookType.HTML.is(controller.getCurrentBook().getPath()) || //
            // BookType.TXT.is(controller.getCurrentBook().getPath());//
            emptyLine.setVisibility(isShow ? View.VISIBLE : View.GONE);
            emptyLine.init(0, 30, BookCSS.get().emptyLine);
            emptyLine.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().emptyLine = result;
                    return false;
                }
            });
            // Margins
            final CustomSeek marginTop = (CustomSeek) inflate.findViewById(R.id.marginTop);
            marginTop.init(0, 30, BookCSS.get().marginTop);
            marginTop.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginTop = result;
                    return false;
                }
            });
            final CustomSeek marginBottom = (CustomSeek) inflate.findViewById(R.id.marginBottom);
            marginBottom.init(0, 30, BookCSS.get().marginBottom);
            marginBottom.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginBottom = result;
                    return false;
                }
            });
            final CustomSeek marginLeft = (CustomSeek) inflate.findViewById(R.id.marginLeft);
            marginLeft.init(0, 30, BookCSS.get().marginLeft);
            marginLeft.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginLeft = result;
                    return false;
                }
            });
            final CustomSeek marginRight = (CustomSeek) inflate.findViewById(R.id.marginRight);
            marginRight.init(0, 30, BookCSS.get().marginRight);
            marginRight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginRight = result;
                    return false;
                }
            });
            // font folder
            LOG.d("fontFolder2-2", BookCSS.get().fontFolder);
            final TextView fontsFolder = (TextView) inflate.findViewById(R.id.fontsFolder);
            TxtUtils.underline(fontsFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
            fontsFolder.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    ChooserDialogFragment.chooseFolder((FragmentActivity) controller.getActivity(), BookCSS.get().fontFolder).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                        @Override
                        public boolean onResultRecive(String nPath, Dialog dialog) {
                            File result = new File(nPath);
                            BookCSS.get().fontFolder = result.getPath();
                            TxtUtils.underline(fontsFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
                            BookCSS.get().save(controller.getActivity());
                            dialog.dismiss();
                            return false;
                        }
                    });
                }
            });
            final View downloadFonts = inflate.findViewById(R.id.downloadFonts);
            downloadFonts.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    FontExtractor.showDownloadFontsDialog(controller.getActivity(), downloadFonts, fontsFolder);
                }
            });
            // / aling
            final Map<Integer, String> alignConst = new LinkedHashMap<Integer, String>();
            alignConst.put(BookCSS.TEXT_ALIGN_JUSTIFY, controller.getString(R.string.width));
            alignConst.put(BookCSS.TEXT_ALIGN_LEFT, controller.getString(R.string.left));
            alignConst.put(BookCSS.TEXT_ALIGN_RIGHT, controller.getString(R.string.right));
            alignConst.put(BookCSS.TEXT_ALIGN_CENTER, controller.getString(R.string.center));
            // align
            final TextView textAlign = (TextView) inflate.findViewById(R.id.textAlign);
            textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
            textAlign.setOnClickListener(new OnClickListener() {

                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onClick(View v) {
                    if (Build.VERSION.SDK_INT <= 10) {
                        BookCSS.get().textAlign += 1;
                        if (BookCSS.get().textAlign == 4) {
                            BookCSS.get().textAlign = 0;
                        }
                        textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
                        return;
                    }
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (final int key : alignConst.keySet()) {
                        String name = alignConst.get(key);
                        popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().textAlign = key;
                                textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // link color
            final CustomColorView linkColorDay = (CustomColorView) inflate.findViewById(R.id.linkColorDay);
            linkColorDay.withDefaultColors(Color.parseColor(BookCSS.LINK_COLOR_DAY), Color.parseColor(BookCSS.LINK_COLOR_UNIVERSAL));
            linkColorDay.init(Color.parseColor(BookCSS.get().linkColorDay));
            linkColorDay.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    BookCSS.get().linkColorDay = string;
                    return false;
                }
            });
            final CustomColorView linkColorNight = (CustomColorView) inflate.findViewById(R.id.linkColorNight);
            linkColorNight.withDefaultColors(Color.parseColor(BookCSS.LINK_COLOR_NIGHT), Color.parseColor(BookCSS.LINK_COLOR_UNIVERSAL));
            linkColorNight.init(Color.parseColor(BookCSS.get().linkColorNight));
            linkColorNight.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    BookCSS.get().linkColorNight = string;
                    return false;
                }
            });
            linkColorDay.getText1().getLayoutParams().width = Dips.dpToPx(150);
            linkColorNight.getText1().getLayoutParams().width = Dips.dpToPx(150);
            TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onResetStyles)).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    AlertDialogs.showOkDialog(controller.getActivity(), controller.getString(R.string.restore_defaults_full), new Runnable() {

                        @Override
                        public void run() {
                            BookCSS.get().resetToDefault(controller.getActivity());
                            fontsFolder.setText(TxtUtils.underline(TxtUtils.lastTwoPath(BookCSS.get().fontFolder)));
                            textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
                            fontWeight.reset(BookCSS.get().fontWeight / 100);
                            fontWeight.setValueText("" + BookCSS.get().fontWeight);
                            lineHeight.reset(BookCSS.get().lineHeight);
                            paragraphHeight.reset(BookCSS.get().paragraphHeight);
                            fontParagraph.reset(BookCSS.get().textIndent);
                            // 
                            marginTop.reset(BookCSS.get().marginTop);
                            marginBottom.reset(BookCSS.get().marginBottom);
                            marginLeft.reset(BookCSS.get().marginLeft);
                            marginRight.reset(BookCSS.get().marginRight);
                            emptyLine.reset(BookCSS.get().emptyLine);
                            linkColorDay.init(Color.parseColor(BookCSS.get().linkColorDay));
                            linkColorNight.init(Color.parseColor(BookCSS.get().linkColorNight));
                        }
                    });
                }
            });
            return inflate;
        }
    };
    dialog.show(DragingPopup.PREF + "_moreBookSettings");
    dialog.setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            if (initCssHash != BookCSS.get().toCssString().hashCode()) {
                AppState.get().save(controller.getActivity());
                if (onRefresh != null) {
                    onRefresh.run();
                }
                controller.restartActivity();
            }
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) StringResponse(com.foobnix.StringResponse) LinkedHashMap(java.util.LinkedHashMap) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) ColorsDialog(com.foobnix.pdf.info.widget.ColorsDialog) AlertDialog(android.app.AlertDialog) FontDialog(com.foobnix.pdf.info.widget.FontDialog) TapZoneDialog(com.foobnix.pdf.info.widget.TapZoneDialog) HyphenPattern(com.foobnix.hypen.HyphenPattern) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) EditText(android.widget.EditText) ResultResponse2(com.foobnix.android.utils.ResultResponse2) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) MenuItem(android.view.MenuItem) 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) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) SuppressLint(android.annotation.SuppressLint) File(java.io.File) TargetApi(android.annotation.TargetApi) CompoundButton(android.widget.CompoundButton) FileMeta(com.foobnix.dao2.FileMeta) PopupMenu(android.widget.PopupMenu)

Example 3 with StringResponse

use of com.foobnix.StringResponse in project LibreraReader by foobnix.

the class DragingDialogs method statusBarSettings.

public static DragingPopup statusBarSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
    DragingPopup dialog = new DragingPopup(R.string.status_bar, anchor, PREF_WIDTH, PREF_HEIGHT) {

        @Override
        public void beforeCreate() {
            titleAction = controller.getString(R.string.preferences);
            titleRunnable = new Runnable() {

                @Override
                public void run() {
                    preferences(anchor, controller, onRefresh, updateUIRefresh);
                }
            };
        }

        @Override
        public View getContentView(final LayoutInflater inflater) {
            View inflate = inflater.inflate(R.layout.dialog_status_bar_settings, null, false);
            final CheckBox isShowReadingProgress = (CheckBox) inflate.findViewById(R.id.isShowReadingProgress);
            final CheckBox isShowChaptersOnProgress = (CheckBox) inflate.findViewById(R.id.isShowChaptersOnProgress);
            isShowReadingProgress.setChecked(AppState.get().isShowReadingProgress);
            isShowReadingProgress.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isShowReadingProgress = isChecked;
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    isShowChaptersOnProgress.setChecked(isChecked);
                    isShowChaptersOnProgress.setEnabled(isChecked);
                }
            });
            isShowChaptersOnProgress.setChecked(AppState.get().isShowChaptersOnProgress);
            isShowChaptersOnProgress.setEnabled(AppState.get().isShowReadingProgress);
            isShowChaptersOnProgress.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isShowChaptersOnProgress = isChecked;
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    if (isChecked) {
                        isShowReadingProgress.setChecked(true);
                    }
                }
            });
            final EditText musicText = (EditText) inflate.findViewById(R.id.musicText);
            musicText.setText(AppState.get().musicText);
            ((View) musicText.getParent()).setVisibility(AppState.get().isMusicianMode ? View.VISIBLE : View.GONE);
            inflate.findViewById(R.id.musicTextOk).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    AppState.get().musicText = musicText.getText().toString();
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                }
            });
            CheckBox isRewindEnable = (CheckBox) inflate.findViewById(R.id.isRewindEnable);
            isRewindEnable.setChecked(AppState.get().isRewindEnable);
            isRewindEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isRewindEnable = isChecked;
                }
            });
            // 
            final CheckBox isShowSatusBar = (CheckBox) inflate.findViewById(R.id.isShowSatusBar);
            isShowSatusBar.setChecked(AppState.get().isShowToolBar);
            isShowSatusBar.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isShowToolBar = isChecked;
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                }
            });
            final CheckBox isShowTime = (CheckBox) inflate.findViewById(R.id.isShowTime);
            isShowTime.setChecked(AppState.get().isShowTime);
            isShowTime.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isShowTime = isChecked;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    if (isChecked) {
                        isShowSatusBar.setChecked(true);
                    }
                }
            });
            final CheckBox isShowBattery = (CheckBox) inflate.findViewById(R.id.isShowBattery);
            isShowBattery.setChecked(AppState.get().isShowBattery);
            isShowBattery.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isShowBattery = isChecked;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    if (isChecked) {
                        isShowSatusBar.setChecked(true);
                    }
                }
            });
            // status bar
            final List<Integer> modeIds = // 
            Arrays.asList(// 
            AppState.READING_PROGRESS_NUMBERS, // 
            AppState.READING_PROGRESS_PERCENT, // 
            AppState.READING_PROGRESS_PERCENT_NUMBERS);
            // 
            final List<String> modeStrings = // 
            Arrays.asList(// 
            controller.getString(R.string.number), // 
            controller.getString(R.string.percent), // 
            controller.getString(R.string.percent_and_number));
            // 
            final TextView readingProgress = (TextView) inflate.findViewById(R.id.readingProgress);
            readingProgress.setText(modeStrings.get(modeIds.indexOf(AppState.get().readingProgress)));
            TxtUtils.underlineTextView(readingProgress);
            readingProgress.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final MyPopupMenu popupMenu = new MyPopupMenu(v.getContext(), v);
                    for (int i = 0; i < modeStrings.size(); i++) {
                        final int j = i;
                        popupMenu.getMenu().add(modeStrings.get(i)).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().readingProgress = modeIds.get(j);
                                readingProgress.setText(modeStrings.get(modeIds.indexOf(AppState.get().readingProgress)));
                                TxtUtils.underlineTextView(readingProgress);
                                if (onRefresh != null) {
                                    onRefresh.run();
                                }
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // / asd
            final CustomSeek statusBarTextSize = (CustomSeek) inflate.findViewById(R.id.statusBarTextSize);
            statusBarTextSize.setTitleTextWidth(Dips.dpToPx(100));
            statusBarTextSize.init(5, 30, controller.isEasyMode() ? AppState.get().statusBarTextSizeEasy : AppState.get().statusBarTextSizeAdv);
            statusBarTextSize.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    isShowSatusBar.setChecked(true);
                    if (controller.isEasyMode()) {
                        AppState.get().statusBarTextSizeEasy = result;
                    } else {
                        AppState.get().statusBarTextSizeAdv = result;
                    }
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    return false;
                }
            });
            final CustomSeek progressLineHeight = (CustomSeek) inflate.findViewById(R.id.progressLineHeight);
            progressLineHeight.setTitleTextWidth(Dips.dpToPx(100));
            progressLineHeight.init(1, 10, AppState.get().progressLineHeight);
            progressLineHeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    isShowReadingProgress.setChecked(true);
                    AppState.get().progressLineHeight = result;
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    return false;
                }
            });
            final CustomColorView statusBarColorDay = (CustomColorView) inflate.findViewById(R.id.statusBarColorDay);
            statusBarColorDay.withDefaultColors(AppState.TEXT_COLOR_DAY, AppState.get().tintColor);
            statusBarColorDay.init(AppState.get().statusBarColorDay);
            statusBarColorDay.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    isShowSatusBar.setChecked(true);
                    AppState.get().statusBarColorDay = Color.parseColor(string);
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    Keyboards.hideNavigation(controller.getActivity());
                    return false;
                }
            });
            final CustomColorView statusBarColorNight = (CustomColorView) inflate.findViewById(R.id.statusBarColorNight);
            statusBarColorNight.withDefaultColors(AppState.TEXT_COLOR_NIGHT, AppState.get().tintColor);
            statusBarColorNight.init(AppState.get().statusBarColorNight);
            statusBarColorNight.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    isShowSatusBar.setChecked(true);
                    AppState.get().statusBarColorNight = Color.parseColor(string);
                    AppState.get().isEditMode = false;
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                    Keyboards.hideNavigation(controller.getActivity());
                    return false;
                }
            });
            statusBarColorDay.getText1().getLayoutParams().width = Dips.dpToPx(150);
            statusBarColorNight.getText1().getLayoutParams().width = Dips.dpToPx(150);
            return inflate;
        }
    };
    dialog.show(DragingPopup.PREF + "_statusBarSettings");
    return dialog;
}
Also used : EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MenuItem(android.view.MenuItem) StringResponse(com.foobnix.StringResponse) 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) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Aggregations

View (android.view.View)3 OnClickListener (android.view.View.OnClickListener)3 CheckBox (android.widget.CheckBox)3 CompoundButton (android.widget.CompoundButton)3 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)3 TextView (android.widget.TextView)3 StringResponse (com.foobnix.StringResponse)3 IntegerResponse (com.foobnix.android.utils.IntegerResponse)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 RecyclerView (android.support.v7.widget.RecyclerView)2 LayoutInflater (android.view.LayoutInflater)2 MenuItem (android.view.MenuItem)2 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 EditText (android.widget.EditText)2 GridView (android.widget.GridView)2 ImageView (android.widget.ImageView)2