Search in sources :

Example 6 with IntegerResponse

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

the class PrefFragment2 method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    inflate = inflater.inflate(R.layout.preferences, container, false);
    // tabs position
    final DragLinearLayout dragLinearLayout = (DragLinearLayout) inflate.findViewById(R.id.dragLinearLayout);
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2));
    final Runnable dragLinear = new Runnable() {

        @Override
        public void run() {
            dragLinearLayout.removeAllViews();
            for (UITab tab : UITab.getOrdered(AppState.get().tabsOrder)) {
                View library = LayoutInflater.from(getActivity()).inflate(R.layout.item_tab_line, null, false);
                ((TextView) library.findViewById(R.id.text1)).setText(tab.getName());
                ((CheckBox) library.findViewById(R.id.isVisible)).setChecked(tab.isVisible());
                ((ImageView) library.findViewById(R.id.image1)).setImageResource(tab.getIcon());
                TintUtil.setTintImageWithAlpha(((ImageView) library.findViewById(R.id.image1)), TintUtil.COLOR_TINT_GRAY);
                library.setTag(tab.getIndex());
                dragLinearLayout.addView(library, layoutParams);
            }
            for (int i = 0; i < dragLinearLayout.getChildCount(); i++) {
                View child = dragLinearLayout.getChildAt(i);
                View handle = child.findViewById(R.id.imageDrag);
                dragLinearLayout.setViewDraggable(child, handle);
            }
        }
    };
    dragLinear.run();
    TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.tabsApply)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AppState.get().tabsOrder = "";
            for (int i = 0; i < dragLinearLayout.getChildCount(); i++) {
                View child = dragLinearLayout.getChildAt(i);
                boolean isVisible = ((CheckBox) child.findViewById(R.id.isVisible)).isChecked();
                AppState.get().tabsOrder += child.getTag() + "#" + (isVisible ? "1" : "0") + ",";
            }
            AppState.get().tabsOrder = TxtUtils.replaceLast(AppState.get().tabsOrder, ",", "");
            LOG.d("tabsApply", AppState.get().tabsOrder);
            AppState.get().save(getActivity());
            onTheme();
        }
    });
    final CheckBox isshowPrefAsMenu = (CheckBox) inflate.findViewById(R.id.isshowPrefAsMenu);
    isshowPrefAsMenu.setChecked(AppState.get().tabsOrder.contains(UITab.PrefFragment.index + "#0"));
    isshowPrefAsMenu.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                AppState.get().tabsOrder = AppState.get().tabsOrder.replace(UITab.PrefFragment.index + "#1", UITab.PrefFragment.index + "#0");
            } else {
                AppState.get().tabsOrder = AppState.get().tabsOrder.replace(UITab.PrefFragment.index + "#0", UITab.PrefFragment.index + "#1");
            }
            dragLinear.run();
        }
    });
    TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.tabsDefaul)).setOnClickListener(new OnClickListener() {

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

                @Override
                public void run() {
                    AppState.get().tabsOrder = AppState.DEFAULTS_TABS_ORDER;
                    isshowPrefAsMenu.setChecked(false);
                    dragLinear.run();
                }
            });
        }
    });
    // tabs position
    section1 = inflate.findViewById(R.id.section1);
    section2 = inflate.findViewById(R.id.section2);
    section3 = inflate.findViewById(R.id.section3);
    section4 = inflate.findViewById(R.id.section4);
    section5 = inflate.findViewById(R.id.section5);
    section6 = inflate.findViewById(R.id.section6);
    section7 = inflate.findViewById(R.id.section7);
    onTintChanged();
    final int max = Dips.pxToDp(Dips.screenMinWH() / 2) - 2 * 4;
    final CustomSeek coverSmallSize = (CustomSeek) inflate.findViewById(R.id.coverSmallSize);
    coverSmallSize.init(40, max, AppState.get().coverSmallSize);
    coverSmallSize.setOnSeekChanged(new IntegerResponse() {

        @Override
        public boolean onResultRecive(int result) {
            TempHolder.listHash++;
            AppState.get().coverSmallSize = result;
            return false;
        }
    });
    final CustomSeek coverBigSize = (CustomSeek) inflate.findViewById(R.id.coverBigSize);
    coverBigSize.init(40, Math.max(max, AppState.get().coverBigSize), AppState.get().coverBigSize);
    coverBigSize.setOnSeekChanged(new IntegerResponse() {

        @Override
        public boolean onResultRecive(int result) {
            TempHolder.listHash++;
            AppState.get().coverBigSize = result;
            return false;
        }
    });
    final TextView columsCount = (TextView) inflate.findViewById(R.id.columsCount);
    columsCount.setText("" + Dips.screenWidthDP() / AppState.get().coverBigSize);
    TxtUtils.underlineTextView(columsCount);
    columsCount.setOnClickListener(new OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            PopupMenu p = new PopupMenu(getContext(), columsCount);
            for (int i = 1; i <= 8; i++) {
                final int k = i;
                p.getMenu().add("" + k).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        int result = Dips.screenWidthDP() / k - 8;
                        TempHolder.listHash++;
                        AppState.get().coverBigSize = result;
                        columsCount.setText("" + k);
                        TxtUtils.underlineTextView(columsCount);
                        coverBigSize.init(40, Math.max(max, AppState.get().coverBigSize), AppState.get().coverBigSize);
                        return false;
                    }
                });
            }
            p.show();
        }
    });
    final TextView columsDefaul = (TextView) inflate.findViewById(R.id.columsDefaul);
    TxtUtils.underlineTextView(columsDefaul);
    columsDefaul.setOnClickListener(new OnClickListener() {

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

                @Override
                public void run() {
                    IMG.clearDiscCache();
                    IMG.clearMemoryCache();
                    AppState.get().coverBigSize = (int) (((Dips.screenWidthDP() / (Dips.screenWidthDP() / 120)) - 8) * (Dips.isXLargeScreen() ? 1.5f : 1));
                    AppState.get().coverSmallSize = 80;
                    TempHolder.listHash++;
                    columsCount.setText("" + Dips.screenWidthDP() / AppState.get().coverBigSize);
                    TxtUtils.underlineTextView(columsCount);
                    coverSmallSize.init(40, max, AppState.get().coverSmallSize);
                    coverBigSize.init(40, Math.max(max, AppState.get().coverBigSize), AppState.get().coverBigSize);
                }
            });
        }
    });
    final ScrollView scrollView = (ScrollView) inflate.findViewById(R.id.scroll);
    scrollView.setVerticalScrollBarEnabled(false);
    ((TextView) inflate.findViewById(R.id.section6)).setText(String.format("%s: %s", getString(R.string.product), AppsConfig.TXT_APP_NAME));
    try {
        PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        final String version = packageInfo.versionName;
        ((TextView) inflate.findViewById(R.id.pVersion)).setText(String.format("%s: %s (%s)", getString(R.string.version), version, AppsConfig.MUPDF_VERSION));
    } catch (final NameNotFoundException e) {
    }
    TextView onCloseApp = (TextView) inflate.findViewById(R.id.onCloseApp);
    TxtUtils.underlineTextView(onCloseApp);
    onCloseApp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((MainTabs2) getActivity()).showInterstial();
        }
    });
    final TextView onFullScreen = (TextView) inflate.findViewById(R.id.fullscreen);
    onFullScreen.setText(AppState.get().isFullScreenMain ? R.string.yes : R.string.no);
    TxtUtils.underlineTextView(onFullScreen);
    onFullScreen.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            MyPopupMenu popup = new MyPopupMenu(getActivity(), v);
            popup.getMenu().add(R.string.yes).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AppState.get().isFullScreenMain = true;
                    onFullScreen.setText(R.string.yes);
                    TxtUtils.underlineTextView(onFullScreen);
                    DocumentController.chooseFullScreen(getActivity(), AppState.get().isFullScreenMain);
                    return false;
                }
            });
            popup.getMenu().add(R.string.no).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AppState.get().isFullScreenMain = false;
                    onFullScreen.setText(R.string.no);
                    TxtUtils.underlineTextView(onFullScreen);
                    DocumentController.chooseFullScreen(getActivity(), AppState.get().isFullScreenMain);
                    return false;
                }
            });
            popup.show();
        }
    });
    screenOrientation = (TextView) inflate.findViewById(R.id.screenOrientation);
    screenOrientation.setText(DocumentController.getRotationText());
    TxtUtils.underlineTextView(screenOrientation);
    screenOrientation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu menu = new PopupMenu(v.getContext(), v);
            for (int i = 0; i < DocumentController.orientationIds.size(); i++) {
                final int j = i;
                final int name = DocumentController.orientationTexts.get(i);
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().orientation = DocumentController.orientationIds.get(j);
                        screenOrientation.setText(DocumentController.orientationTexts.get(j));
                        TxtUtils.underlineTextView(screenOrientation);
                        DocumentController.doRotation(getActivity());
                        return false;
                    }
                });
            }
            menu.show();
        }
    });
    // inflate.findViewById(R.id.onHelpTranslate).setOnClickListener(new
    // OnClickListener() {
    // 
    // @Override
    // public void onClick(final View v) {
    // Urls.open(getActivity(),
    // "https://www.dropbox.com/sh/8el7kon2sbx46w8/xm3qoHYT7n");
    // }
    // });
    inflate.findViewById(R.id.onKeyCode).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            new KeyCodeDialog(getActivity(), onCloseDialog);
        }
    });
    themeColor = (TextView) inflate.findViewById(R.id.themeColor);
    themeColor.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            PopupMenu p = new PopupMenu(getContext(), themeColor);
            p.getMenu().add(R.string.light).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AppState.get().isWhiteTheme = true;
                    AppState.get().isInkMode = false;
                    AppState.get().contrastImage = 0;
                    AppState.get().brigtnessImage = 0;
                    AppState.get().bolderTextOnImage = false;
                    AppState.get().isEnableBC = false;
                    AppState.get().save(getActivity());
                    IMG.clearDiscCache();
                    IMG.clearMemoryCache();
                    onTheme();
                    return false;
                }
            });
            p.getMenu().add(R.string.black).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AppState.get().isWhiteTheme = false;
                    AppState.get().isInkMode = false;
                    AppState.get().contrastImage = 0;
                    AppState.get().brigtnessImage = 0;
                    AppState.get().bolderTextOnImage = false;
                    AppState.get().isEnableBC = false;
                    AppState.get().save(getActivity());
                    IMG.clearDiscCache();
                    IMG.clearMemoryCache();
                    onTheme();
                    return false;
                }
            });
            p.getMenu().add("Ink").setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    IMG.clearDiscCache();
                    IMG.clearMemoryCache();
                    onEink();
                    return false;
                }
            });
            p.show();
        }
    });
    final TextView hypenLang = (TextView) inflate.findViewById(R.id.appLang);
    hypenLang.setText(DialogTranslateFromTo.getLanuageByCode(AppState.get().appLang));
    TxtUtils.underlineTextView(hypenLang);
    hypenLang.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            final List<String> codes = // 
            Arrays.asList(// 
            "en", // 
            "ar", // 
            "de", // 
            "es", // 
            "fa", // 
            "fi", // 
            "fr", // 
            "he", // 
            "hi", // 
            "hu", // 
            "id", // 
            "it", // 
            "ja", // 
            "ko", // 
            "la", // 
            "lt", // 
            "nl", // 
            "no", // 
            "pl", // 
            "pt", // 
            "ro", // 
            "ru", // 
            "sk", // 
            "sv", "sw", "th", "tr", "uk", "vi", "zh");
            List<String> langs = new ArrayList<String>();
            for (String code : codes) {
                langs.add(DialogTranslateFromTo.getLanuageByCode(code) + ":" + code);
            }
            Collections.sort(langs);
            popupMenu.getMenu().add(R.string.system_language).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    TxtUtils.underlineTextView(hypenLang);
                    AppState.get().appLang = AppState.MY_SYSTEM_LANG;
                    TempHolder.get().forseAppLang = true;
                    MyContextWrapper.wrap(getContext());
                    AppState.get().save(getActivity());
                    onTheme();
                    return false;
                }
            });
            for (int i = 0; i < langs.size(); i++) {
                String[] all = langs.get(i).split(":");
                final String name = all[0];
                final String code = all[1];
                popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().appLang = code;
                        TxtUtils.underlineTextView(hypenLang);
                        AppState.get().save(getActivity());
                        onTheme();
                        return false;
                    }
                });
            }
            popupMenu.show();
        }
    });
    final TextView appFontScale = (TextView) inflate.findViewById(R.id.appFontScale);
    appFontScale.setText(getFontName(AppState.get().appFontScale));
    TxtUtils.underlineTextView(appFontScale);
    appFontScale.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            for (float i = 0.7f; i < 2.1f; i += 0.1) {
                final float number = i;
                popupMenu.getMenu().add(getFontName(number)).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().appFontScale = number;
                        AppState.get().save(getActivity());
                        onTheme();
                        return false;
                    }
                });
            }
            popupMenu.show();
        }
    });
    final TextView onMail = (TextView) inflate.findViewById(R.id.onMailSupport);
    onMail.setText(TxtUtils.underline(getString(R.string.my_email)));
    onMail.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            onEmail();
        }
    });
    rememberMode = (CheckBox) inflate.findViewById(R.id.isRememberMode);
    rememberMode.setChecked(AppState.get().isRememberMode);
    rememberMode.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isRememberMode = isChecked;
        }
    });
    selectedOpenMode = (TextView) inflate.findViewById(R.id.selectedOpenMode);
    selectedOpenMode.setOnClickListener(new OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT <= 10) {
                Toast.makeText(selectedOpenMode.getContext(), R.string.this_function_will_works_in_modern_android, Toast.LENGTH_SHORT).show();
                return;
            }
            final PopupMenu popupMenu = new PopupMenu(selectedOpenMode.getContext(), selectedOpenMode);
            final MenuItem advanced_mode = popupMenu.getMenu().add(AppState.get().nameVerticalMode);
            advanced_mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().isAlwaysOpenAsMagazine = false;
                    AppState.get().isMusicianMode = false;
                    checkOpenWithSpinner();
                    return false;
                }
            });
            final MenuItem easy_mode = popupMenu.getMenu().add(AppState.get().nameHorizontalMode);
            easy_mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().isAlwaysOpenAsMagazine = true;
                    AppState.get().isMusicianMode = false;
                    checkOpenWithSpinner();
                    return false;
                }
            });
            final MenuItem music_mode = popupMenu.getMenu().add(AppState.get().nameMusicianMode);
            music_mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().isAlwaysOpenAsMagazine = false;
                    AppState.get().isMusicianMode = true;
                    checkOpenWithSpinner();
                    return false;
                }
            });
            popupMenu.show();
        }
    });
    checkOpenWithSpinner();
    final CheckBox isCropBookCovers = (CheckBox) inflate.findViewById(R.id.isCropBookCovers);
    isCropBookCovers.setOnCheckedChangeListener(null);
    isCropBookCovers.setChecked(AppState.get().isCropBookCovers);
    isCropBookCovers.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isCropBookCovers = isChecked;
            TempHolder.listHash++;
        }
    });
    final CheckBox isBookCoverEffect = (CheckBox) inflate.findViewById(R.id.isBookCoverEffect);
    isBookCoverEffect.setOnCheckedChangeListener(null);
    isBookCoverEffect.setChecked(AppState.get().isBookCoverEffect);
    isBookCoverEffect.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isBookCoverEffect = isChecked;
            ImageLoader.getInstance().clearMemoryCache();
            ImageLoader.getInstance().clearDiskCache();
            TempHolder.listHash++;
            if (isChecked) {
                isCropBookCovers.setEnabled(false);
                isCropBookCovers.setChecked(true);
            } else {
                isCropBookCovers.setEnabled(true);
            }
        }
    });
    final CheckBox isBorderAndShadow = (CheckBox) inflate.findViewById(R.id.isBorderAndShadow);
    isBorderAndShadow.setOnCheckedChangeListener(null);
    isBorderAndShadow.setChecked(AppState.get().isBorderAndShadow);
    isBorderAndShadow.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isBorderAndShadow = isChecked;
            TempHolder.listHash++;
        }
    });
    final CheckBox isShowImages = (CheckBox) inflate.findViewById(R.id.isShowImages);
    isShowImages.setOnCheckedChangeListener(null);
    isShowImages.setChecked(AppState.get().isShowImages);
    isShowImages.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isShowImages = isChecked;
            TempHolder.listHash++;
            isCropBookCovers.setEnabled(AppState.get().isShowImages);
            isBookCoverEffect.setEnabled(AppState.get().isShowImages);
            isBorderAndShadow.setEnabled(AppState.get().isShowImages);
        }
    });
    isCropBookCovers.setEnabled(AppState.get().isShowImages);
    isBookCoverEffect.setEnabled(AppState.get().isShowImages);
    isBorderAndShadow.setEnabled(AppState.get().isShowImages);
    CheckBox isLoopAutoplay = (CheckBox) inflate.findViewById(R.id.isLoopAutoplay);
    isLoopAutoplay.setChecked(AppState.get().isLoopAutoplay);
    isLoopAutoplay.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

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

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isShowCloseAppDialog = isChecked;
        }
    });
    final Handler handler = new Handler();
    final Runnable ask = new Runnable() {

        @Override
        public void run() {
            AlertDialogs.showDialog(getActivity(), getActivity().getString(R.string.you_need_to_update_the_library), getString(R.string.ok), new Runnable() {

                @Override
                public void run() {
                    onScan();
                }
            }, null);
        }
    };
    final int timeout = 1500;
    final CheckBox isFirstSurname = (CheckBox) inflate.findViewById(R.id.isFirstSurname);
    isFirstSurname.setChecked(AppState.get().isFirstSurname);
    isFirstSurname.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isFirstSurname = isChecked;
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    final CheckBox isAddKeywordsToGenres = (CheckBox) inflate.findViewById(R.id.isAddKeywordsToGenres);
    isAddKeywordsToGenres.setChecked(AppState.get().isAddKeywordsToGenres);
    isAddKeywordsToGenres.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isAddKeywordsToGenres = isChecked;
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    // //
    ((CheckBox) inflate.findViewById(R.id.supportPDF)).setChecked(AppState.get().supportPDF);
    ((CheckBox) inflate.findViewById(R.id.supportPDF)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportPDF = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportXPS)).setChecked(AppState.get().supportXPS);
    ((CheckBox) inflate.findViewById(R.id.supportXPS)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportXPS = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportDJVU)).setChecked(AppState.get().supportDJVU);
    ((CheckBox) inflate.findViewById(R.id.supportDJVU)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportDJVU = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportEPUB)).setChecked(AppState.get().supportEPUB);
    ((CheckBox) inflate.findViewById(R.id.supportEPUB)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportEPUB = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportFB2)).setChecked(AppState.get().supportFB2);
    ((CheckBox) inflate.findViewById(R.id.supportFB2)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportFB2 = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
            isAddKeywordsToGenres.setVisibility(AppState.get().supportFB2 ? View.VISIBLE : View.GONE);
        }
    });
    isAddKeywordsToGenres.setVisibility(AppState.get().supportFB2 ? View.VISIBLE : View.GONE);
    ((CheckBox) inflate.findViewById(R.id.supportTXT)).setChecked(AppState.get().supportTXT);
    ((CheckBox) inflate.findViewById(R.id.supportTXT)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportTXT = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportMOBI)).setChecked(AppState.get().supportMOBI);
    ((CheckBox) inflate.findViewById(R.id.supportMOBI)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportMOBI = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportRTF)).setChecked(AppState.get().supportRTF);
    ((CheckBox) inflate.findViewById(R.id.supportRTF)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportRTF = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    ((CheckBox) inflate.findViewById(R.id.supportCBZ)).setChecked(AppState.get().supportCBZ);
    ((CheckBox) inflate.findViewById(R.id.supportCBZ)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportCBZ = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    CheckBox supportZIP = (CheckBox) inflate.findViewById(R.id.supportZIP);
    supportZIP.setChecked(AppState.get().supportZIP);
    supportZIP.setText(getString(R.string.archives) + " (ZIP/RAR/...)");
    supportZIP.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportZIP = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    CheckBox supportOther = (CheckBox) inflate.findViewById(R.id.supportOther);
    supportOther.setChecked(AppState.get().supportOther);
    supportOther.setText(getString(R.string.other) + " (DOC/CHM/...)");
    supportOther.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().supportOther = isChecked;
            ExtUtils.updateSearchExts();
            handler.removeCallbacks(ask);
            handler.postDelayed(ask, timeout);
        }
    });
    CheckBox isDisplayAllFilesInFolder = (CheckBox) inflate.findViewById(R.id.isDisplayAllFilesInFolder);
    isDisplayAllFilesInFolder.setChecked(AppState.get().isDisplayAllFilesInFolder);
    isDisplayAllFilesInFolder.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isDisplayAllFilesInFolder = isChecked;
            TempHolder.listHash++;
        }
    });
    // app password
    final CheckBox isAppPassword = (CheckBox) inflate.findViewById(R.id.isAppPassword);
    isAppPassword.setChecked(PasswordState.get().isAppPassword);
    isAppPassword.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            PasswordState.get().isAppPassword = isChecked;
            if (isChecked && TxtUtils.isEmpty(PasswordState.get().appPassword)) {
                PasswordDialog.showDialog(getActivity(), true, new Runnable() {

                    @Override
                    public void run() {
                        if (TxtUtils.isEmpty(PasswordState.get().appPassword)) {
                            isAppPassword.setChecked(false);
                        }
                    }
                });
            }
        }
    });
    TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.appPassword)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PasswordDialog.showDialog(getActivity(), true, new Runnable() {

                @Override
                public void run() {
                    if (TxtUtils.isEmpty(PasswordState.get().appPassword)) {
                        isAppPassword.setChecked(false);
                    }
                }
            });
        }
    });
    // What is new
    CheckBox showWhatIsNew = (CheckBox) inflate.findViewById(R.id.isShowWhatIsNewDialog);
    showWhatIsNew.setChecked(AppState.get().isShowWhatIsNewDialog);
    showWhatIsNew.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isShowWhatIsNewDialog = isChecked;
        }
    });
    final TextView whatIsNew = (TextView) inflate.findViewById(R.id.whatIsNew);
    whatIsNew.setText(getActivity().getString(R.string.what_is_new_in) + " " + Apps.getApplicationName(getActivity()) + " " + Apps.getVersionName(getActivity()));
    TxtUtils.underlineTextView(whatIsNew);
    whatIsNew.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AndroidWhatsNew.show(getActivity());
        }
    });
    // /
    // BrightnessHelper.controlsWrapper(inflate, getActivity());
    nextKeys = (TextView) inflate.findViewById(R.id.textNextKeys);
    prevKeys = (TextView) inflate.findViewById(R.id.textPrevKeys);
    ch = (CheckBox) inflate.findViewById(R.id.onReverse);
    ch.setOnCheckedChangeListener(null);
    ch.setChecked(AppState.get().isReverseKeys);
    ch.setOnCheckedChangeListener(reverseListener);
    inflate.findViewById(R.id.onColorChoser).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
        }
    });
    initKeys();
    searchPaths = (TextView) inflate.findViewById(R.id.searchPaths);
    searchPaths.setText(TxtUtils.underline(AppState.get().searchPaths.replace(",", "<br>")));
    searchPaths.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onFolderConfigDialog();
        }
    });
    TextView addFolder = (TextView) inflate.findViewById(R.id.onConfigPath);
    TxtUtils.underlineTextView(addFolder);
    addFolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            onFolderConfigDialog();
        }
    });
    TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.importButton)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            PrefDialogs.importDialog(getActivity());
        }
    });
    TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.exportButton)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            PrefDialogs.exportDialog(getActivity());
        }
    });
    final CheckBox isAutomaticExport = (CheckBox) inflate.findViewById(R.id.isAutomaticExport);
    isAutomaticExport.setChecked(AppState.get().isAutomaticExport);
    isAutomaticExport.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            AppState.get().isAutomaticExport = isChecked;
        }
    });
    // folders
    final TextView fontFolder = (TextView) inflate.findViewById(R.id.fontFolder);
    TxtUtils.underline(fontFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
    fontFolder.setOnClickListener(new OnClickListener() {

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

                @Override
                public boolean onResultRecive(String nPath, Dialog dialog) {
                    BookCSS.get().fontFolder = nPath;
                    TxtUtils.underline(fontFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
                    dialog.dismiss();
                    return false;
                }
            });
        }
    });
    final TextView downloadFolder = (TextView) inflate.findViewById(R.id.downloadFolder);
    TxtUtils.underline(downloadFolder, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
    downloadFolder.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().downlodsPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                @Override
                public boolean onResultRecive(String nPath, Dialog dialog) {
                    AppState.get().downlodsPath = nPath;
                    TxtUtils.underline(downloadFolder, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
                    dialog.dismiss();
                    return false;
                }
            });
        }
    });
    final TextView ttsFolder = (TextView) inflate.findViewById(R.id.ttsFolder);
    TxtUtils.underline(ttsFolder, TxtUtils.lastTwoPath(AppState.get().ttsSpeakPath));
    ttsFolder.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().ttsSpeakPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                @Override
                public boolean onResultRecive(String nPath, Dialog dialog) {
                    AppState.get().ttsSpeakPath = nPath;
                    TxtUtils.underline(ttsFolder, TxtUtils.lastTwoPath(AppState.get().ttsSpeakPath));
                    dialog.dismiss();
                    return false;
                }
            });
        }
    });
    final TextView backupPath = (TextView) inflate.findViewById(R.id.backupFolder);
    TxtUtils.underline(backupPath, TxtUtils.lastTwoPath(AppState.get().backupPath));
    backupPath.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().backupPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                @Override
                public boolean onResultRecive(String nPath, Dialog dialog) {
                    AppState.get().backupPath = nPath;
                    TxtUtils.underline(backupPath, TxtUtils.lastTwoPath(AppState.get().backupPath));
                    dialog.dismiss();
                    return false;
                }
            });
        }
    });
    // Widget Configuration
    final TextView widgetLayout = (TextView) inflate.findViewById(R.id.widgetLayout);
    widgetLayout.setText(AppState.get().widgetType == AppState.WIDGET_LIST ? R.string.list : R.string.grid);
    TxtUtils.underlineTextView(widgetLayout);
    widgetLayout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            final MenuItem recent = popupMenu.getMenu().add(R.string.list);
            recent.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().widgetType = AppState.WIDGET_LIST;
                    widgetLayout.setText(R.string.list);
                    TxtUtils.underlineTextView(widgetLayout);
                    return false;
                }
            });
            final MenuItem starred = popupMenu.getMenu().add(R.string.grid);
            starred.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().widgetType = AppState.WIDGET_GRID;
                    widgetLayout.setText(R.string.grid);
                    TxtUtils.underlineTextView(widgetLayout);
                    return false;
                }
            });
            popupMenu.show();
        }
    });
    final TextView widgetForRecent = (TextView) inflate.findViewById(R.id.widgetForRecent);
    widgetForRecent.setText(AppState.get().isStarsInWidget ? R.string.starred : R.string.recent);
    TxtUtils.underlineTextView(widgetForRecent);
    widgetForRecent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu popupMenu = new PopupMenu(widgetForRecent.getContext(), widgetForRecent);
            final MenuItem recent = popupMenu.getMenu().add(R.string.recent);
            recent.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().isStarsInWidget = false;
                    widgetForRecent.setText(AppState.get().isStarsInWidget ? R.string.starred : R.string.recent);
                    TxtUtils.underlineTextView(widgetForRecent);
                    return false;
                }
            });
            final MenuItem starred = popupMenu.getMenu().add(R.string.starred);
            starred.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(final MenuItem item) {
                    AppState.get().isStarsInWidget = true;
                    widgetForRecent.setText(AppState.get().isStarsInWidget ? R.string.starred : R.string.recent);
                    TxtUtils.underlineTextView(widgetForRecent);
                    return false;
                }
            });
            popupMenu.show();
        }
    });
    final TextView widgetItemsCount = (TextView) inflate.findViewById(R.id.widgetItemsCount);
    widgetItemsCount.setText("" + AppState.get().widgetItemsCount);
    TxtUtils.underlineTextView(widgetItemsCount);
    widgetItemsCount.setOnClickListener(new OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            PopupMenu p = new PopupMenu(getContext(), columsCount);
            for (int i = 1; i <= 50; i++) {
                final int k = i;
                p.getMenu().add("" + k).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().widgetItemsCount = k;
                        widgetItemsCount.setText("" + k);
                        TxtUtils.underlineTextView(widgetItemsCount);
                        return false;
                    }
                });
            }
            p.show();
        }
    });
    // dictionary
    isRememberDictionary = (CheckBox) inflate.findViewById(R.id.isRememberDictionary);
    isRememberDictionary.setChecked(AppState.get().isRememberDictionary);
    isRememberDictionary.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isRememberDictionary = isChecked;
        }
    });
    selectedDictionaly = (TextView) inflate.findViewById(R.id.selectedDictionaly);
    selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
    selectedDictionaly.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogTranslateFromTo.show(getActivity(), new Runnable() {

                @Override
                public void run() {
                    selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
                }
            });
        }
    });
    textDayColor = (TextView) inflate.findViewById(R.id.onDayColor);
    textDayColor.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new ColorsDialog(getActivity(), true, AppState.get().colorDayText, AppState.get().colorDayBg, false, true, new ColorsDialogResult() {

                @Override
                public void onChooseColor(int colorText, int colorBg) {
                    textDayColor.setTextColor(colorText);
                    textDayColor.setBackgroundColor(colorBg);
                    AppState.get().colorDayText = colorText;
                    AppState.get().colorDayBg = colorBg;
                    ImageLoader.getInstance().clearDiskCache();
                    ImageLoader.getInstance().clearMemoryCache();
                }
            });
        }
    });
    textNigthColor = (TextView) inflate.findViewById(R.id.onNigthColor);
    textNigthColor.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new ColorsDialog(getActivity(), false, AppState.get().colorNigthText, AppState.get().colorNigthBg, false, true, new ColorsDialogResult() {

                @Override
                public void onChooseColor(int colorText, int colorBg) {
                    textNigthColor.setTextColor(colorText);
                    textNigthColor.setBackgroundColor(colorBg);
                    AppState.get().colorNigthText = colorText;
                    AppState.get().colorNigthBg = colorBg;
                }
            });
        }
    });
    TextView onDefalt = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDefaultColor));
    onDefalt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AppState.get().colorDayText = AppState.COLOR_BLACK;
            AppState.get().colorDayBg = AppState.COLOR_WHITE;
            textDayColor.setTextColor(AppState.COLOR_BLACK);
            textDayColor.setBackgroundColor(AppState.COLOR_WHITE);
            AppState.get().colorNigthText = AppState.COLOR_WHITE;
            AppState.get().colorNigthBg = AppState.COLOR_BLACK;
            textNigthColor.setTextColor(AppState.COLOR_WHITE);
            textNigthColor.setBackgroundColor(AppState.COLOR_BLACK);
        }
    });
    LinearLayout colorsLine = (LinearLayout) inflate.findViewById(R.id.colorsLine);
    colorsLine.removeAllViews();
    for (String color : AppState.STYLE_COLORS) {
        View view = inflater.inflate(R.layout.item_color, (ViewGroup) inflate, false);
        view.setBackgroundColor(Color.TRANSPARENT);
        final int intColor = Color.parseColor(color);
        final View img = view.findViewById(R.id.itColor);
        img.setBackgroundColor(intColor);
        colorsLine.addView(view, new LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30)));
        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                TintUtil.color = intColor;
                AppState.get().tintColor = intColor;
                TempHolder.listHash++;
                onTintChanged();
                sendNotifyTintChanged();
                AppState.get().save(getActivity());
            }
        });
    }
    View view = inflater.inflate(R.layout.item_color, (ViewGroup) inflate, false);
    view.setBackgroundColor(Color.TRANSPARENT);
    final ImageView img = (ImageView) view.findViewById(R.id.itColor);
    img.setColorFilter(getResources().getColor(R.color.tint_gray));
    img.setImageResource(R.drawable.glyphicons_433_plus);
    img.setBackgroundColor(AppState.get().userColor);
    colorsLine.addView(view, new LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30)));
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new HSVColorPickerDialog(getContext(), AppState.get().userColor, new OnColorSelectedListener() {

                @Override
                public void colorSelected(Integer color) {
                    AppState.get().userColor = color;
                    AppState.get().tintColor = color;
                    TintUtil.color = color;
                    img.setBackgroundColor(color);
                    onTintChanged();
                    sendNotifyTintChanged();
                    AppState.get().save(getActivity());
                    TempHolder.listHash++;
                }
            }).show();
        }
    });
    underline(inflate.findViewById(R.id.linksColor)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            closeLeftMenu();
            Dialogs.showLinksColorDialog(getActivity(), new Runnable() {

                @Override
                public void run() {
                    TempHolder.listHash++;
                    onTintChanged();
                    sendNotifyTintChanged();
                    ((MainTabs2) getActivity()).updateCurrentFragment();
                }
            });
        }
    });
    underline(inflate.findViewById(R.id.onContrast)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            Dialogs.showContrastDialogByUrl(getActivity(), new Runnable() {

                @Override
                public void run() {
                    ImageLoader.getInstance().clearDiskCache();
                    ImageLoader.getInstance().clearMemoryCache();
                    TempHolder.listHash++;
                    notifyFragment();
                }
            });
        }
    });
    underline(inflate.findViewById(R.id.onRateIt)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            rateIT();
        }
    });
    underline(inflate.findViewById(R.id.openWeb)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            Urls.open(getActivity(), WWW_SITE);
        }
    });
    underline(inflate.findViewById(R.id.openBeta)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            Urls.open(getActivity(), WWW_BETA_SITE);
        }
    });
    underline(inflate.findViewById(R.id.openArchive)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            Urls.open(getActivity(), WWW_ARCHIVE_SITE);
        }
    });
    underline(inflate.findViewById(R.id.onTelegram)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            Urls.open(getActivity(), "https://t.me/LibreraReader");
        }
    });
    TextView proText = (TextView) inflate.findViewById(R.id.downloadPRO);
    TxtUtils.underlineTextView(proText);
    ((View) proText.getParent()).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            Urls.openPdfPro(getActivity());
        }
    });
    // if (AppsConfig.checkIsProInstalled(getActivity())) {
    // ((View) proText.getParent()).setVisibility(View.GONE);
    // }
    inflate.findViewById(R.id.cleanRecent).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setMessage(getString(R.string.clear_all_recent) + "?");
            builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AppSharedPreferences.get().cleanRecent();
                }
            });
            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                }
            });
            builder.show();
        }
    });
    inflate.findViewById(R.id.cleanBookmarks).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setMessage(getString(R.string.clear_all_bookmars) + "?");
            builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AppSharedPreferences.get().cleanBookmarks();
                }
            });
            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                }
            });
            builder.show();
        }
    });
    // tutorials
    TextView tutorialLink = (TextView) inflate.findViewById(R.id.tutorialLink);
    TxtUtils.underlineTextView(tutorialLink);
    tutorialLink.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Urls.open(getActivity(), AndroidWhatsNew.DETAIL_URL_RU);
        }
    });
    // licences link
    underline(inflate.findViewById(R.id.libraryLicenses)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle(R.string.licenses_for_libraries);
            WebView wv = new WebView(getActivity());
            wv.loadUrl("file:///android_asset/licenses.html");
            wv.setWebViewClient(new WebViewClient() {

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }
            });
            alert.setView(wv);
            alert.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
            AlertDialog create = alert.create();
            create.setOnDismissListener(new OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    Keyboards.hideNavigation(getActivity());
                }
            });
            create.show();
        }
    });
    TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.docSearch)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            MultyDocSearchDialog.show(getActivity());
        }
    });
    // convert
    final TextView docConverter = (TextView) inflate.findViewById(R.id.docConverter);
    TxtUtils.underlineTextView(docConverter);
    docConverter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu p = new PopupMenu(getContext(), v);
            for (final String id : AppState.CONVERTERS.keySet()) {
                p.getMenu().add("" + getActivity().getString(R.string.convert_to) + " " + id).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        ShareDialog.showsItemsDialog(getActivity(), getActivity().getString(R.string.convert_to) + " " + id, AppState.CONVERTERS.get(id));
                        return false;
                    }
                });
            }
            p.show();
        }
    });
    overlay = getActivity().findViewById(R.id.overlay);
    return inflate;
}
Also used : AlertDialog(android.app.AlertDialog) MainTabs2(com.foobnix.ui2.MainTabs2) DragLinearLayout(com.jmedeisis.draglinearlayout.DragLinearLayout) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) OnColorSelectedListener(com.buzzingandroid.ui.HSVColorPickerDialog.OnColorSelectedListener) MultyDocSearchDialog(com.foobnix.pdf.info.view.MultyDocSearchDialog) ShareDialog(com.foobnix.pdf.info.widget.ShareDialog) PasswordDialog(com.foobnix.pdf.info.PasswordDialog) KeyCodeDialog(com.foobnix.pdf.info.view.KeyCodeDialog) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) HSVColorPickerDialog(com.buzzingandroid.ui.HSVColorPickerDialog) ColorsDialog(com.foobnix.pdf.info.widget.ColorsDialog) TextView(android.widget.TextView) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) ResultResponse2(com.foobnix.android.utils.ResultResponse2) LayoutParams(android.view.ViewGroup.LayoutParams) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CustomSeek(com.foobnix.pdf.info.view.CustomSeek) IntegerResponse(com.foobnix.android.utils.IntegerResponse) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) OnDismissListener(android.content.DialogInterface.OnDismissListener) Handler(android.os.Handler) MenuItem(android.view.MenuItem) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) UITab(com.foobnix.pdf.info.wrapper.UITab) ScrollView(android.widget.ScrollView) KeyCodeDialog(com.foobnix.pdf.info.view.KeyCodeDialog) HSVColorPickerDialog(com.buzzingandroid.ui.HSVColorPickerDialog) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) SuppressLint(android.annotation.SuppressLint) ColorsDialog(com.foobnix.pdf.info.widget.ColorsDialog) ColorsDialogResult(com.foobnix.pdf.info.widget.ColorsDialog.ColorsDialogResult) LinearLayout(android.widget.LinearLayout) DragLinearLayout(com.jmedeisis.draglinearlayout.DragLinearLayout) CompoundButton(android.widget.CompoundButton) PopupMenu(android.widget.PopupMenu) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu)

Example 7 with IntegerResponse

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

the class DragingDialogs method performanceSettings.

public static DragingPopup performanceSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
    AppState.get().saveIn(controller.getActivity());
    final int cssHash = BookCSS.get().toCssString().hashCode();
    final int appHash = Objects.hashCode(AppState.get());
    DragingPopup dialog = new DragingPopup(R.string.advanced_settings, anchor, PREF_WIDTH, PREF_HEIGHT) {

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

                @Override
                public void run() {
                    if (appHash != Objects.hashCode(AppState.get())) {
                        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_adv_preferences, null, false);
            CheckBox isLoopAutoplay = (CheckBox) inflate.findViewById(R.id.isLoopAutoplay);
            isLoopAutoplay.setChecked(AppState.get().isLoopAutoplay);
            isLoopAutoplay.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isLoopAutoplay = isChecked;
                }
            });
            CheckBox isScrollSpeedByVolumeKeys = (CheckBox) inflate.findViewById(R.id.isScrollSpeedByVolumeKeys);
            isScrollSpeedByVolumeKeys.setChecked(AppState.get().isScrollSpeedByVolumeKeys);
            isScrollSpeedByVolumeKeys.setVisibility(View.GONE);
            isScrollSpeedByVolumeKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

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

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

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isAllowTextSelection = isChecked;
                    if (isChecked) {
                        TempHolder.get().isAllowTextSelectionFirstTime = true;
                    }
                }
            });
            CheckBox isZoomInOutWithVolueKeys = (CheckBox) inflate.findViewById(R.id.isZoomInOutWithVolueKeys);
            isZoomInOutWithVolueKeys.setChecked(AppState.get().isZoomInOutWithVolueKeys);
            isZoomInOutWithVolueKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isZoomInOutWithVolueKeys = isChecked;
                }
            });
            final CustomSeek mouseWheelSpeed = (CustomSeek) inflate.findViewById(R.id.seekWheelSpeed);
            mouseWheelSpeed.getTitleText().setSingleLine(false);
            mouseWheelSpeed.init(1, 200, AppState.get().mouseWheelSpeed);
            mouseWheelSpeed.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    AppState.get().mouseWheelSpeed = result;
                    return false;
                }
            });
            CheckBox isScrollAnimation = (CheckBox) inflate.findViewById(R.id.isScrollAnimation);
            isScrollAnimation.setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
            isScrollAnimation.setChecked(AppState.get().isScrollAnimation);
            isScrollAnimation.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isScrollAnimation = isChecked;
                }
            });
            CheckBox isDisableSwipe = (CheckBox) inflate.findViewById(R.id.isDisableSwipe);
            isDisableSwipe.setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
            isDisableSwipe.setChecked(AppState.get().isDisableSwipe);
            isDisableSwipe.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

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

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isOLED = isChecked;
                }
            });
            CheckBox isLockPDF = (CheckBox) inflate.findViewById(R.id.isLockPDF);
            isLockPDF.setChecked(AppState.get().isLockPDF);
            isLockPDF.setVisibility(controller.isTextFormat() ? View.GONE : View.VISIBLE);
            isLockPDF.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isLockPDF = isChecked;
                }
            });
            CheckBox isCropPDF = (CheckBox) inflate.findViewById(R.id.isCropPDF);
            isCropPDF.setChecked(AppState.get().isCropPDF);
            isCropPDF.setVisibility(controller.isTextFormat() ? View.GONE : View.VISIBLE);
            isCropPDF.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isCropPDF = isChecked;
                }
            });
            CheckBox isCustomizeBgAndColors = (CheckBox) inflate.findViewById(R.id.isCustomizeBgAndColors);
            isCustomizeBgAndColors.setVisibility(controller.isTextFormat() ? View.GONE : View.VISIBLE);
            isCustomizeBgAndColors.setChecked(AppState.get().isCustomizeBgAndColors);
            isCustomizeBgAndColors.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isCustomizeBgAndColors = isChecked;
                }
            });
            final CheckBox isReplaceWhite = (CheckBox) inflate.findViewById(R.id.isReplaceWhite);
            isReplaceWhite.setChecked(AppState.get().isReplaceWhite);
            isReplaceWhite.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
            isReplaceWhite.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isIgnoreAnnotatations = isChecked;
                }
            });
            isIgnoreAnnotatations.setVisibility(!AppState.get().isAlwaysOpenAsMagazine && BookType.PDF.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            CheckBox isSaveAnnotatationsAutomatically = (CheckBox) inflate.findViewById(R.id.isSaveAnnotatationsAutomatically);
            isSaveAnnotatationsAutomatically.setChecked(AppState.get().isSaveAnnotatationsAutomatically);
            isSaveAnnotatationsAutomatically.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isSaveAnnotatationsAutomatically = isChecked;
                }
            });
            isSaveAnnotatationsAutomatically.setVisibility(!AppState.get().isAlwaysOpenAsMagazine && BookType.PDF.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            CheckBox highlightByLetters = (CheckBox) inflate.findViewById(R.id.highlightByLetters);
            highlightByLetters.setChecked(AppState.get().selectingByLetters);
            highlightByLetters.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isCutRTL = isChecked;
                }
            });
            final TextView pageQuality = (TextView) inflate.findViewById(R.id.pageQuality);
            ((ViewGroup) pageQuality.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine && !ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            pageQuality.setText((int) (AppState.get().pageQuality * 100) + "%");
            TxtUtils.underlineTextView(pageQuality);
            pageQuality.setOnClickListener(new OnClickListener() {

                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (float i = 0.5f; i < 2.1f; i += 0.1f) {
                        final float quality = i;
                        popupMenu.getMenu().add((int) (i * 100) + "%").setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().pageQuality = quality;
                                pageQuality.setText((int) (AppState.get().pageQuality * 100) + "%");
                                TxtUtils.underlineTextView(pageQuality);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            final TextView pagesInMemory = (TextView) inflate.findViewById(R.id.pagesInMemory);
            ((ViewGroup) pagesInMemory.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
            pagesInMemory.setText("" + AppState.get().pagesInMemory);
            TxtUtils.underlineTextView(pagesInMemory);
            pagesInMemory.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    popupMenu.getMenu().add("" + 1).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().pagesInMemory = 1;
                            pagesInMemory.setText("" + AppState.get().pagesInMemory);
                            TxtUtils.underlineTextView(pagesInMemory);
                            return false;
                        }
                    });
                    popupMenu.getMenu().add("" + 3).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().pagesInMemory = 3;
                            pagesInMemory.setText("" + AppState.get().pagesInMemory);
                            TxtUtils.underlineTextView(pagesInMemory);
                            return false;
                        }
                    });
                    popupMenu.getMenu().add("" + 5).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().pagesInMemory = 5;
                            pagesInMemory.setText("" + AppState.get().pagesInMemory);
                            TxtUtils.underlineTextView(pagesInMemory);
                            return false;
                        }
                    });
                    popupMenu.show();
                }
            });
            // /
            final TextView inactivityTime = (TextView) inflate.findViewById(R.id.inactivityTime);
            inactivityTime.setText("" + AppState.get().inactivityTime);
            TxtUtils.underlineTextView(inactivityTime);
            inactivityTime.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (int i = 1; i <= 10; i++) {
                        final int number = i;
                        popupMenu.getMenu().add("" + i).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().inactivityTime = number;
                                inactivityTime.setText("" + AppState.get().inactivityTime);
                                TxtUtils.underlineTextView(inactivityTime);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // /
            final TextView rotate = (TextView) inflate.findViewById(R.id.rotate);
            ((ViewGroup) rotate.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
            rotate.setText("" + AppState.get().rotate + "°");
            TxtUtils.underlineTextView(rotate);
            rotate.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    MenuBuilderM.addRotateMenu(rotate, null, new Runnable() {

                        @Override
                        public void run() {
                            rotate.setText("" + AppState.get().rotate + "°");
                            TxtUtils.underlineTextView(rotate);
                        }
                    }).show();
                }
            });
            final TextView tapzoneSize = (TextView) inflate.findViewById(R.id.tapzoneSize);
            tapzoneSize.setText("" + AppState.get().tapzoneSize + "%");
            TxtUtils.underlineTextView(tapzoneSize);
            tapzoneSize.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (int i = 0; i <= 45f; i += 5) {
                        final int number = i;
                        popupMenu.getMenu().add("" + i + "%").setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().tapzoneSize = number;
                                tapzoneSize.setText("" + AppState.get().tapzoneSize + "%");
                                TxtUtils.underlineTextView(tapzoneSize);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // double tap
            final List<String> doubleTapNames = // 
            Arrays.asList(// 
            controller.getString(R.string.db_auto_scroll), // 
            controller.getString(R.string.db_auto_alignemnt), // 
            controller.getString(R.string.db_auto_center_horizontally), // 
            controller.getString(R.string.zoom_in_zoom_out), // 
            controller.getString(R.string.close_book), // 
            controller.getString(R.string.close_book_and_application), // 
            controller.getString(R.string.hide_app), // 
            controller.getString(R.string.db_do_nothing));
            final List<Integer> doubleTapIDS = // 
            Arrays.asList(// 
            AppState.DOUBLE_CLICK_AUTOSCROLL, // 
            AppState.DOUBLE_CLICK_ADJUST_PAGE, // 
            AppState.DOUBLE_CLICK_CENTER_HORIZONTAL, // 
            AppState.DOUBLE_CLICK_ZOOM_IN_OUT, // 
            AppState.DOUBLE_CLICK_CLOSE_BOOK, // 
            AppState.DOUBLE_CLICK_CLOSE_BOOK_AND_APP, // 
            AppState.DOUBLE_CLICK_CLOSE_HIDE_APP, // 
            AppState.DOUBLE_CLICK_NOTHING);
            // 
            final TextView doubleClickAction1 = (TextView) inflate.findViewById(R.id.doubleTapValue);
            doubleClickAction1.setText(doubleTapNames.get(doubleTapIDS.indexOf(AppState.get().doubleClickAction1)));
            TxtUtils.underlineTextView(doubleClickAction1);
            doubleClickAction1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    MyPopupMenu popup = new MyPopupMenu(controller.getActivity(), v);
                    for (int i = 0; i < doubleTapNames.size(); i++) {
                        final int j = i;
                        final String fontName = doubleTapNames.get(i);
                        popup.getMenu().add(fontName).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().doubleClickAction1 = doubleTapIDS.get(j);
                                doubleClickAction1.setText(doubleTapNames.get(doubleTapIDS.indexOf(AppState.get().doubleClickAction1)));
                                TxtUtils.underlineTextView(doubleClickAction1);
                                return false;
                            }
                        });
                    }
                    popup.show();
                }
            });
            final TextView tapzoneCustomize = (TextView) inflate.findViewById(R.id.tapzoneCustomize);
            TxtUtils.underlineTextView(tapzoneCustomize);
            tapzoneCustomize.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    TapZoneDialog.show(controller.getActivity());
                }
            });
            final TextView allocatedMemorySize = (TextView) inflate.findViewById(R.id.allocatedMemorySize);
            allocatedMemorySize.setText("" + AppState.get().allocatedMemorySize + "Mb");
            TxtUtils.underlineTextView(allocatedMemorySize);
            allocatedMemorySize.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (int i = 16; i <= 512 && i < MemoryUtils.MAX_MEMORY_SIZE; i += i) {
                        final int number = i;
                        popupMenu.getMenu().add("" + i + "Mb").setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().allocatedMemorySize = number;
                                allocatedMemorySize.setText("" + AppState.get().allocatedMemorySize + "Mb");
                                TxtUtils.underlineTextView(allocatedMemorySize);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // image format
            final TextView imageFormat = (TextView) inflate.findViewById(R.id.imageFormat);
            // ((ViewGroup)
            // imageFormat.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine
            // ? View.VISIBLE : View.GONE);
            ((ViewGroup) imageFormat.getParent()).setVisibility(View.GONE);
            imageFormat.setText(AppState.get().imageFormat);
            TxtUtils.underlineTextView(imageFormat);
            imageFormat.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    popupMenu.getMenu().add(AppState.PNG).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().imageFormat = AppState.PNG;
                            imageFormat.setText(AppState.get().imageFormat);
                            TxtUtils.underlineTextView(imageFormat);
                            return false;
                        }
                    });
                    popupMenu.getMenu().add(AppState.JPG).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().imageFormat = AppState.JPG;
                            imageFormat.setText(AppState.get().imageFormat);
                            TxtUtils.underlineTextView(imageFormat);
                            return false;
                        }
                    });
                    popupMenu.show();
                }
            });
            // remind rest time
            final TextView remindRestTime = (TextView) inflate.findViewById(R.id.remindRestTime);
            final String minutesString = controller.getString(R.string.minutes).toLowerCase(Locale.US);
            if (AppState.get().remindRestTime == -1) {
                remindRestTime.setText(R.string.no);
            } else {
                remindRestTime.setText(AppState.get().remindRestTime + " " + minutesString);
            }
            TxtUtils.underlineTextView(remindRestTime);
            remindRestTime.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    popupMenu.getMenu().add(R.string.no).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().remindRestTime = -1;
                            remindRestTime.setText(R.string.no);
                            TxtUtils.underlineTextView(remindRestTime);
                            return false;
                        }
                    });
                    for (int i = 10; i <= 240; i += 10) {
                        final int j = i;
                        popupMenu.getMenu().add(i + " " + minutesString).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().remindRestTime = j;
                                remindRestTime.setText(AppState.get().remindRestTime + " " + minutesString);
                                TxtUtils.underlineTextView(remindRestTime);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // rotate
            final TextView rotateViewPager = (TextView) inflate.findViewById(R.id.rotateViewPager);
            ((ViewGroup) rotateViewPager.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
            rotateViewPager.setText(AppState.get().rotateViewPager == 0 ? R.string.horizontal : R.string.vertical);
            TxtUtils.underlineTextView(rotateViewPager);
            rotateViewPager.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    popupMenu.getMenu().add(R.string.horizontal).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().rotateViewPager = 0;
                            rotateViewPager.setText(AppState.get().rotateViewPager == 0 ? R.string.horizontal : R.string.vertical);
                            TxtUtils.underlineTextView(rotateViewPager);
                            return false;
                        }
                    });
                    popupMenu.getMenu().add(R.string.vertical).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().rotateViewPager = 90;
                            rotateViewPager.setText(AppState.get().rotateViewPager == 0 ? R.string.horizontal : R.string.vertical);
                            TxtUtils.underlineTextView(rotateViewPager);
                            return false;
                        }
                    });
                    popupMenu.show();
                }
            });
            // rtl
            final TextView rtlText = (TextView) inflate.findViewById(R.id.rtlText);
            ((ViewGroup) rtlText.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
            if (AppState.get().isRTL) {
                rtlText.setText(R.string.right_to_left);
            } else {
                rtlText.setText(R.string.left_to_rigth);
            }
            TxtUtils.underlineTextView(rtlText);
            rtlText.setOnClickListener(new OnClickListener() {

                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    popupMenu.getMenu().add(R.string.left_to_rigth).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().isRTL = false;
                            rtlText.setText(R.string.left_to_rigth);
                            TxtUtils.underlineTextView(rtlText);
                            AppState.get().tapZoneTop = AppState.TAP_PREV_PAGE;
                            AppState.get().tapZoneBottom = AppState.TAP_NEXT_PAGE;
                            AppState.get().tapZoneLeft = AppState.TAP_PREV_PAGE;
                            AppState.get().tapZoneRight = AppState.TAP_NEXT_PAGE;
                            return false;
                        }
                    });
                    popupMenu.getMenu().add(R.string.right_to_left).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().isRTL = true;
                            rtlText.setText(R.string.right_to_left);
                            TxtUtils.underlineTextView(rtlText);
                            AppState.get().tapZoneTop = AppState.TAP_PREV_PAGE;
                            AppState.get().tapZoneBottom = AppState.TAP_NEXT_PAGE;
                            AppState.get().tapZoneLeft = AppState.TAP_NEXT_PAGE;
                            AppState.get().tapZoneRight = AppState.TAP_PREV_PAGE;
                            return false;
                        }
                    });
                    popupMenu.show();
                }
            });
            return inflate;
        }
    };
    dialog.show(DragingPopup.PREF + "_performanceSettings");
    dialog.setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            boolean one = appHash != Objects.hashCode(AppState.get());
            boolean two = controller.isTextFormat() && cssHash != BookCSS.get().toCssString().hashCode();
            if (one || two) {
                if (onRefresh != null) {
                    onRefresh.run();
                }
                controller.restartActivity();
            }
        }
    });
    return dialog;
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) TextView(android.widget.TextView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) ViewGroup(android.view.ViewGroup) 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) TargetApi(android.annotation.TargetApi) CompoundButton(android.widget.CompoundButton) PopupMenu(android.widget.PopupMenu)

Example 8 with IntegerResponse

use of com.foobnix.android.utils.IntegerResponse 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)

Example 9 with IntegerResponse

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

the class Dialogs method getBCView.

public static LinearLayout getBCView(final Activity c, final Runnable action) {
    LinearLayout l = new LinearLayout(c);
    l.setPadding(Dips.dpToPx(5), Dips.dpToPx(5), Dips.dpToPx(5), Dips.dpToPx(5));
    l.setOrientation(LinearLayout.VERTICAL);
    final Handler handler = new Handler();
    final Runnable actionWrapper = new Runnable() {

        @Override
        public void run() {
            handler.removeCallbacks(action);
            handler.postDelayed(action, 100);
        }
    };
    final CheckBox isEnableBC = new CheckBox(c);
    isEnableBC.setText(R.string.enable_contrast_and_brightness);
    isEnableBC.setChecked(AppState.get().isEnableBC);
    isEnableBC.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().isEnableBC = isChecked;
            actionWrapper.run();
        }
    });
    final CustomSeek contrastSeek = new CustomSeek(c);
    contrastSeek.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0));
    contrastSeek.init(0, 200, AppState.get().contrastImage);
    contrastSeek.setOnSeekChanged(new IntegerResponse() {

        @Override
        public boolean onResultRecive(int result) {
            AppState.get().contrastImage = result;
            isEnableBC.setChecked(true);
            actionWrapper.run();
            return false;
        }
    });
    final CustomSeek brightnesSeek = new CustomSeek(c);
    brightnesSeek.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0));
    brightnesSeek.init(-100, 100, AppState.get().brigtnessImage);
    brightnesSeek.setOnSeekChanged(new IntegerResponse() {

        @Override
        public boolean onResultRecive(int result) {
            AppState.get().brigtnessImage = result;
            isEnableBC.setChecked(true);
            actionWrapper.run();
            return false;
        }
    });
    final CheckBox bolderText = new CheckBox(c);
    bolderText.setText(R.string.make_text_bold);
    bolderText.setChecked(AppState.get().bolderTextOnImage);
    bolderText.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            AppState.get().bolderTextOnImage = isChecked;
            if (isChecked) {
                isEnableBC.setChecked(true);
            }
            actionWrapper.run();
        }
    });
    TextView contrastText = new TextView(c);
    contrastText.setText(R.string.contrast);
    TextView brightnessText = new TextView(c);
    brightnessText.setText(R.string.brightness);
    l.addView(isEnableBC);
    l.addView(contrastText);
    l.addView(contrastSeek);
    l.addView(brightnessText);
    l.addView(brightnesSeek);
    l.addView(bolderText);
    TextView defaults = new TextView(c);
    defaults.setTextAppearance(c, R.style.textLinkStyle);
    defaults.setText(R.string.restore_defaults_short);
    TxtUtils.underlineTextView(defaults);
    defaults.setOnClickListener(new View.OnClickListener() {

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

                @Override
                public void run() {
                    AppState.get().brigtnessImage = 0;
                    AppState.get().contrastImage = 0;
                    AppState.get().bolderTextOnImage = false;
                    isEnableBC.setChecked(AppState.get().bolderTextOnImage);
                    brightnesSeek.reset(AppState.get().brigtnessImage);
                    contrastSeek.reset(AppState.get().contrastImage);
                    actionWrapper.run();
                }
            });
        }
    });
    l.addView(defaults);
    return l;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) Handler(android.os.Handler) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Aggregations

IntegerResponse (com.foobnix.android.utils.IntegerResponse)9 View (android.view.View)8 OnClickListener (android.view.View.OnClickListener)8 CheckBox (android.widget.CheckBox)8 CompoundButton (android.widget.CompoundButton)8 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)8 TextView (android.widget.TextView)8 ImageView (android.widget.ImageView)7 SuppressLint (android.annotation.SuppressLint)6 MenuItem (android.view.MenuItem)6 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)6 ListView (android.widget.ListView)6 AlertDialog (android.app.AlertDialog)5 DialogInterface (android.content.DialogInterface)5 RecyclerView (android.support.v7.widget.RecyclerView)5 LayoutInflater (android.view.LayoutInflater)5 AbsListView (android.widget.AbsListView)5 AdapterView (android.widget.AdapterView)5 GridView (android.widget.GridView)5 PopupMenu (android.widget.PopupMenu)4