Search in sources :

Example 1 with ResultResponse

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

the class DragingDialogs method preferences.

public static DragingPopup preferences(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
    final int cssHash = BookCSS.get().toCssString().hashCode();
    final int appHash = Objects.hashCode(AppState.get());
    if (ExtUtils.isNotValidFile(controller.getCurrentBook())) {
        DragingPopup dialog = new DragingPopup(R.string.preferences, anchor, PREF_WIDTH, PREF_HEIGHT) {

            @Override
            public View getContentView(final LayoutInflater inflater) {
                TextView txt = new TextView(anchor.getContext());
                txt.setText(R.string.file_not_found);
                return txt;
            }
        };
        return dialog;
    }
    DragingPopup dialog = new DragingPopup(R.string.preferences, anchor, PREF_WIDTH, PREF_HEIGHT) {

        @Override
        public View getContentView(final LayoutInflater inflater) {
            View inflate = inflater.inflate(R.layout.dialog_prefs, null, false);
            // TOP panel start
            View topPanelLine = inflate.findViewById(R.id.topPanelLine);
            View topPanelLineDiv = inflate.findViewById(R.id.topPanelLineDiv);
            // topPanelLine.setVisibility(controller instanceof
            // DocumentControllerHorizontalView ? View.VISIBLE : View.GONE);
            topPanelLine.setVisibility(View.GONE);
            topPanelLineDiv.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
            inflate.findViewById(R.id.allBGConfig).setVisibility(Dips.isEInk(inflate.getContext()) ? View.GONE : View.VISIBLE);
            View onRecent = inflate.findViewById(R.id.onRecent);
            onRecent.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    DragingDialogs.recentBooks(anchor, controller);
                }
            });
            final View onRotate = inflate.findViewById(R.id.onRotate);
            onRotate.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    if (Build.VERSION.SDK_INT <= 10) {
                        Toast.makeText(anchor.getContext(), R.string.this_function_will_works_in_modern_android, Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // closeDialog();
                    MenuBuilderM.addRotateMenu(onRotate, null, updateUIRefresh).show();
                }
            });
            inflate.findViewById(R.id.onPageFlip).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    closeDialog();
                    DragingDialogs.pageFlippingDialog(anchor, controller, onRefresh);
                }
            });
            ImageView brightness = (ImageView) inflate.findViewById(R.id.onBrightness);
            brightness.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    AppState.get().isDayNotInvert = !AppState.get().isDayNotInvert;
                    controller.restartActivity();
                }
            });
            brightness.setImageResource(!AppState.get().isDayNotInvert ? R.drawable.glyphicons_232_sun : R.drawable.glyphicons_2_moon);
            final ImageView isCrop = (ImageView) inflate.findViewById(R.id.onCrop);
            // isCrop.setVisibility(controller.isTextFormat() ||
            // AppState.get().isCut ? View.GONE : View.VISIBLE);
            isCrop.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    AppState.get().isCrop = !AppState.get().isCrop;
                    SettingsManager.getBookSettings().updateFromAppState();
                    TintUtil.setTintImageWithAlpha(isCrop, !AppState.get().isCrop ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
                    updateUIRefresh.run();
                }
            });
            TintUtil.setTintImageWithAlpha(isCrop, !AppState.get().isCrop ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
            final ImageView bookCut = (ImageView) inflate.findViewById(R.id.bookCut);
            // bookCut.setVisibility(controller.isTextFormat() ? View.GONE :
            // View.VISIBLE);
            bookCut.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    closeDialog();
                    DragingDialogs.sliceDialog(anchor, controller, updateUIRefresh, new ResultResponse<Integer>() {

                        @Override
                        public boolean onResultRecive(Integer result) {
                            TintUtil.setTintImageWithAlpha(bookCut, !AppState.get().isCut ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
                            SettingsManager.getBookSettings().updateFromAppState();
                            EventBus.getDefault().post(new InvalidateMessage());
                            return false;
                        }
                    });
                }
            });
            TintUtil.setTintImageWithAlpha(bookCut, !AppState.get().isCut ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
            inflate.findViewById(R.id.onFullScreen).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    AppState.get().isFullScreen = !AppState.get().isFullScreen;
                    DocumentController.chooseFullScreen(controller.getActivity(), AppState.get().isFullScreen);
                    if (controller.isTextFormat()) {
                        if (onRefresh != null) {
                            onRefresh.run();
                        }
                        controller.restartActivity();
                    }
                }
            });
            View tts = inflate.findViewById(R.id.onTTS);
            tts.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    closeDialog();
                    DragingDialogs.textToSpeachDialog(anchor, controller);
                }
            });
            final ImageView pin = (ImageView) inflate.findViewById(R.id.onPin);
            pin.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    AppState.get().isShowToolBar = !AppState.get().isShowToolBar;
                    pin.setImageResource(AppState.get().isShowToolBar ? R.drawable.glyphicons_336_pushpin : R.drawable.glyphicons_200_ban);
                    if (onRefresh != null) {
                        onRefresh.run();
                    }
                }
            });
            pin.setImageResource(AppState.get().isShowToolBar ? R.drawable.glyphicons_336_pushpin : R.drawable.glyphicons_200_ban);
            // TOP panel end
            CheckBox isPreText = (CheckBox) inflate.findViewById(R.id.isPreText);
            isPreText.setChecked(AppState.get().isPreText);
            isPreText.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isLineBreaksText = isChecked;
                }
            });
            isLineBreaksText.setVisibility(BookType.TXT.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            // 
            TextView moreSettings = (TextView) inflate.findViewById(R.id.moreSettings);
            moreSettings.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
            inflate.findViewById(R.id.moreSettingsDiv).setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
            // View moreSettingsImage =
            // inflate.findViewById(R.id.moreSettingsImage);
            // moreSettingsImage.setVisibility(controller.isTextFormat() ?
            // View.VISIBLE : View.GONE);
            TxtUtils.underlineTextView(moreSettings).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    moreBookSettings(anchor, controller, onRefresh, updateUIRefresh);
                }
            });
            TextView performanceSettings = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.performanceSettigns));
            performanceSettings.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    performanceSettings(anchor, controller, onRefresh, updateUIRefresh);
                }
            });
            TextView statusBarSettings = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.statusBarSettings));
            statusBarSettings.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    statusBarSettings(anchor, controller, onRefresh, updateUIRefresh);
                }
            });
            final CustomSeek fontSizeSp = (CustomSeek) inflate.findViewById(R.id.fontSizeSp);
            fontSizeSp.init(10, 70, AppState.get().fontSizeSp);
            fontSizeSp.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    AppState.get().fontSizeSp = result;
                    return false;
                }
            });
            fontSizeSp.setValueText("" + AppState.get().fontSizeSp);
            inflate.findViewById(R.id.fontSizeLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            inflate.findViewById(R.id.fontNameSelectionLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            final TextView textFontName = (TextView) inflate.findViewById(R.id.textFontName);
            textFontName.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final List<FontPack> fontPacks = BookCSS.get().getAllFontsPacks();
                    MyPopupMenu popup = new MyPopupMenu(controller.getActivity(), v);
                    for (final FontPack pack : fontPacks) {
                        LOG.d("pack.normalFont", pack.normalFont);
                        popup.getMenu().add(pack.dispalyName, pack.normalFont).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().resetAll(pack);
                                TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
                                return false;
                            }
                        });
                    }
                    popup.show();
                }
            });
            TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
            final View moreFontSettings = inflate.findViewById(R.id.moreFontSettings);
            moreFontSettings.setOnClickListener(new OnClickListener() {

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

                        @Override
                        public void run() {
                            TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
                        }
                    });
                }
            });
            final View downloadFonts = inflate.findViewById(R.id.downloadFonts);
            downloadFonts.setVisibility(FontExtractor.hasZipFonts() ? View.GONE : View.VISIBLE);
            downloadFonts.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    FontExtractor.showDownloadFontsDialog(controller.getActivity(), downloadFonts, textFontName);
                }
            });
            // crop
            CheckBox isCropBorders = (CheckBox) inflate.findViewById(R.id.isCropBorders);
            isCropBorders.setChecked(controller.isCropCurrentBook());
            isCropBorders.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    controller.onCrop();
                }
            });
            // volume
            final CheckBox isReverseKyes = (CheckBox) inflate.findViewById(R.id.isReverseKyes);
            isReverseKyes.setChecked(AppState.get().isReverseKeys);
            isReverseKyes.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isReverseKeys = isChecked;
                }
            });
            isReverseKyes.setEnabled(AppState.get().isUseVolumeKeys ? true : false);
            CheckBox isUseVolumeKeys = (CheckBox) inflate.findViewById(R.id.isUseVolumeKeys);
            isUseVolumeKeys.setChecked(AppState.get().isUseVolumeKeys);
            isUseVolumeKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().isUseVolumeKeys = isChecked;
                    isReverseKyes.setEnabled(AppState.get().isUseVolumeKeys ? true : false);
                }
            });
            // orientation begin
            final TextView 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(controller.getActivity());
                                return false;
                            }
                        });
                    }
                    menu.show();
                }
            });
            // orientation end
            BrightnessHelper.showBlueLigthDialogAndBrightness(controller.getActivity(), inflate, onRefresh);
            // brightness end
            // dicts
            final TextView selectedDictionaly = (TextView) inflate.findViewById(R.id.selectedDictionaly);
            selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
            selectedDictionaly.setOnClickListener(new OnClickListener() {

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

                        @Override
                        public void run() {
                            selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
                        }
                    });
                }
            });
            ((CheckBox) inflate.findViewById(R.id.isRememberDictionary)).setChecked(AppState.get().isRememberDictionary);
            ((CheckBox) inflate.findViewById(R.id.isRememberDictionary)).setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().isRememberDictionary = isChecked;
                }
            });
            // Colors
            TextView textCustomizeFontBGColor = (TextView) inflate.findViewById(R.id.textCustomizeFontBGColor);
            if (AppState.get().isCustomizeBgAndColors || controller.isTextFormat()) {
                textCustomizeFontBGColor.setText(R.string.customize_font_background_colors);
            } else {
                textCustomizeFontBGColor.setText(R.string.customize_background_color);
            }
            final ImageView onDayColorImage = (ImageView) inflate.findViewById(R.id.onDayColorImage);
            final TextView textDayColor = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDayColor));
            textDayColor.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    boolean isSolid = !AppState.get().isUseBGImageDay;
                    new ColorsDialog((FragmentActivity) controller.getActivity(), true, AppState.get().colorDayText, AppState.get().colorDayBg, false, isSolid, new ColorsDialogResult() {

                        @Override
                        public void onChooseColor(int colorText, int colorBg) {
                            textDayColor.setTextColor(colorText);
                            textDayColor.setBackgroundColor(colorBg);
                            TintUtil.setTintImageWithAlpha(onDayColorImage, colorText);
                            AppState.get().colorDayText = colorText;
                            AppState.get().colorDayBg = colorBg;
                            ImageLoader.getInstance().clearDiskCache();
                            ImageLoader.getInstance().clearMemoryCache();
                            if (AppState.get().isUseBGImageDay) {
                                textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(true));
                            }
                        }
                    });
                }
            });
            final ImageView onNigthColorImage = (ImageView) inflate.findViewById(R.id.onNigthColorImage);
            final TextView textNigthColor = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onNigthColor));
            textNigthColor.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    boolean isSolid = !AppState.get().isUseBGImageNight;
                    new ColorsDialog((FragmentActivity) controller.getActivity(), false, AppState.get().colorNigthText, AppState.get().colorNigthBg, false, isSolid, new ColorsDialogResult() {

                        @Override
                        public void onChooseColor(int colorText, int colorBg) {
                            textNigthColor.setTextColor(colorText);
                            textNigthColor.setBackgroundColor(colorBg);
                            TintUtil.setTintImageWithAlpha(onNigthColorImage, colorText);
                            AppState.get().colorNigthText = colorText;
                            AppState.get().colorNigthBg = colorBg;
                            if (AppState.get().isUseBGImageNight) {
                                textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(true));
                            }
                        }
                    });
                }
            });
            final LinearLayout lc = (LinearLayout) inflate.findViewById(R.id.preColors);
            TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
            TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
            textNigthColor.setTextColor(AppState.get().colorNigthText);
            textNigthColor.setBackgroundColor(AppState.get().colorNigthBg);
            textDayColor.setTextColor(AppState.get().colorDayText);
            textDayColor.setBackgroundColor(AppState.get().colorDayBg);
            if (AppState.get().isUseBGImageDay) {
                textDayColor.setTextColor(Color.BLACK);
                textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(true));
            }
            if (AppState.get().isUseBGImageNight) {
                textNigthColor.setTextColor(Color.WHITE);
                textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(true));
            }
            // lc.setVisibility(controller.isTextFormat() ||
            // AppState.get().isCustomizeBgAndColors ? View.VISIBLE :
            // View.GONE);
            final int padding = Dips.dpToPx(3);
            final Runnable colorsLine = new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    lc.removeAllViews();
                    for (String line : AppState.get().readColors.split(";")) {
                        if (TxtUtils.isEmpty(line)) {
                            continue;
                        }
                        String[] split = line.split(",");
                        LOG.d("Split colors", split[0], split[1], split[2]);
                        String name = split[0];
                        final int bg = Color.parseColor(split[1]);
                        final int text = Color.parseColor(split[2]);
                        final boolean isDay = split[3].equals("0");
                        BorderTextView t1 = new BorderTextView(controller.getActivity());
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
                        params.setMargins(padding, padding, padding, padding);
                        t1.setLayoutParams(params);
                        t1.setGravity(Gravity.CENTER);
                        t1.setBackgroundColor(bg);
                        if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
                            t1.setText(name);
                            t1.setTextColor(text);
                            t1.setTypeface(null, Typeface.BOLD);
                        }
                        t1.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (isDay) {
                                    if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
                                        AppState.get().colorDayText = text;
                                        textDayColor.setTextColor(text);
                                    }
                                    AppState.get().colorDayBg = bg;
                                    textDayColor.setBackgroundColor(bg);
                                    AppState.get().isUseBGImageDay = false;
                                } else {
                                    if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
                                        AppState.get().colorNigthText = text;
                                        textNigthColor.setTextColor(text);
                                    }
                                    AppState.get().colorNigthBg = bg;
                                    textNigthColor.setBackgroundColor(bg);
                                    AppState.get().isUseBGImageNight = false;
                                }
                                TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
                                TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
                            }
                        });
                        lc.addView(t1);
                    }
                    // add DayBG
                    {
                        ImageView t1 = new ImageView(controller.getActivity());
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
                        params.setMargins(padding, padding, padding, padding);
                        t1.setLayoutParams(params);
                        t1.setScaleType(ScaleType.FIT_XY);
                        t1.setImageDrawable(MagicHelper.getBgImageDayDrawable(false));
                        t1.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                AppState.get().colorDayText = AppState.COLOR_BLACK;
                                AppState.get().colorDayBg = AppState.COLOR_WHITE;
                                textDayColor.setTextColor(Color.BLACK);
                                textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(false));
                                AppState.get().isUseBGImageDay = true;
                                TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
                            }
                        });
                        lc.addView(t1, AppState.get().readColors.split(";").length / 2);
                    }
                    // add Night
                    {
                        ImageView t2 = new ImageView(controller.getActivity());
                        LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
                        params2.setMargins(padding, padding, padding, padding);
                        t2.setLayoutParams(params2);
                        t2.setScaleType(ScaleType.FIT_XY);
                        t2.setImageDrawable(MagicHelper.getBgImageNightDrawable(false));
                        t2.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                AppState.get().colorNigthText = AppState.COLOR_WHITE;
                                AppState.get().colorNigthBg = AppState.COLOR_BLACK;
                                textNigthColor.setTextColor(Color.WHITE);
                                textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(false));
                                AppState.get().isUseBGImageNight = true;
                                TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
                            }
                        });
                        lc.addView(t2);
                    }
                }
            };
            colorsLine.run();
            TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDefaultColor)).setOnClickListener(new OnClickListener() {

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

                        @Override
                        public void run() {
                            AppState.get().readColors = AppState.READ_COLORS_DEAFAUL;
                            AppState.get().isUseBGImageDay = false;
                            AppState.get().isUseBGImageNight = false;
                            AppState.get().bgImageDayTransparency = AppState.DAY_TRANSPARENCY;
                            AppState.get().bgImageDayPath = MagicHelper.IMAGE_BG_1;
                            AppState.get().bgImageNightTransparency = AppState.NIGHT_TRANSPARENCY;
                            AppState.get().bgImageNightPath = MagicHelper.IMAGE_BG_1;
                            AppState.get().isCustomizeBgAndColors = false;
                            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);
                            TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
                            TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
                            AppState.get().statusBarColorDay = AppState.TEXT_COLOR_DAY;
                            AppState.get().statusBarColorNight = AppState.TEXT_COLOR_NIGHT;
                            colorsLine.run();
                        }
                    });
                }
            });
            inflate.findViewById(R.id.moreReadColorSettings).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(controller.getActivity());
                    builder.setTitle(R.string.customize);
                    final LinearLayout root = new LinearLayout(controller.getActivity());
                    root.setOrientation(LinearLayout.VERTICAL);
                    for (String line : AppState.get().readColors.split(";")) {
                        if (TxtUtils.isEmpty(line)) {
                            continue;
                        }
                        final String[] split = line.split(",");
                        LOG.d("Split colors", split[0], split[1], split[2]);
                        final String name = split[0];
                        final int bg = Color.parseColor(split[1]);
                        final int text = Color.parseColor(split[2]);
                        final boolean isDay = split[3].equals("0");
                        final LinearLayout child = new LinearLayout(controller.getActivity());
                        child.setOrientation(LinearLayout.HORIZONTAL);
                        child.setTag(line);
                        final TextView t1Img = new TextView(controller.getActivity());
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(60), Dips.dpToPx(30));
                        params.setMargins(padding, padding, padding, padding);
                        t1Img.setLayoutParams(params);
                        t1Img.setGravity(Gravity.CENTER);
                        t1Img.setBackgroundColor(bg);
                        t1Img.setText(name);
                        t1Img.setTextColor(text);
                        t1Img.setTypeface(null, Typeface.BOLD);
                        t1Img.setTag(isDay);
                        TextView t0 = new TextView(controller.getActivity());
                        t0.setEms(1);
                        TextView t00 = new TextView(controller.getActivity());
                        t00.setEms(2);
                        final TextView t2BG = new TextView(controller.getActivity());
                        t2BG.setText(TxtUtils.underline(split[1]));
                        t2BG.setEms(5);
                        t2BG.setTag(bg);
                        final TextView t3Text = new TextView(controller.getActivity());
                        t3Text.setText(TxtUtils.underline(split[2]));
                        t3Text.setEms(5);
                        t3Text.setTag(text);
                        child.addView(t0);
                        child.addView(t1Img);
                        child.addView(t00);
                        child.addView(t2BG);
                        child.addView(t3Text);
                        child.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                new ColorsDialog((FragmentActivity) controller.getActivity(), (Boolean) t1Img.getTag(), (Integer) t3Text.getTag(), (Integer) t2BG.getTag(), true, true, new ColorsDialogResult() {

                                    @Override
                                    public void onChooseColor(int colorText, int colorBg) {
                                        t1Img.setTextColor(colorText);
                                        t1Img.setBackgroundColor(colorBg);
                                        t2BG.setText(TxtUtils.underline(MagicHelper.colorToString(colorBg)));
                                        t3Text.setText(TxtUtils.underline(MagicHelper.colorToString(colorText)));
                                        t2BG.setTag(colorBg);
                                        t3Text.setTag(colorText);
                                        String line = name + "," + MagicHelper.colorToString(colorBg) + "," + MagicHelper.colorToString(colorText) + "," + split[3];
                                        child.setTag(line);
                                    }
                                });
                            }
                        });
                        root.addView(child);
                    }
                    builder.setView(root);
                    builder.setNegativeButton(R.string.apply, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String res = "";
                            for (int i = 0; i < root.getChildCount(); i++) {
                                View childAt = root.getChildAt(i);
                                String line = (String) childAt.getTag();
                                res = res + line + ";";
                            }
                            AppState.get().readColors = res;
                            LOG.d("SAVE readColors", AppState.get().readColors);
                            colorsLine.run();
                        }
                    });
                    builder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    builder.show();
                }
            });
            return inflate;
        }
    }.show(DragingPopup.PREF + "_preferences").setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            if (// 
            // 
            appHash != Objects.hashCode(AppState.get()) || (controller.isTextFormat() && cssHash != BookCSS.get().toCssString().hashCode())) {
                if (onRefresh != null) {
                    onRefresh.run();
                }
                controller.restartActivity();
            }
        }
    });
    return dialog;
}
Also used : ResultResponse(com.foobnix.android.utils.ResultResponse) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) FontPack(com.foobnix.pdf.info.model.BookCSS.FontPack) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) OnClickListener(android.view.View.OnClickListener) 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) FragmentActivity(android.support.v4.app.FragmentActivity) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) SuppressLint(android.annotation.SuppressLint) ColorsDialog(com.foobnix.pdf.info.widget.ColorsDialog) ColorsDialogResult(com.foobnix.pdf.info.widget.ColorsDialog.ColorsDialogResult) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout) InvalidateMessage(com.foobnix.pdf.search.activity.msg.InvalidateMessage) PopupMenu(android.widget.PopupMenu)

Example 2 with ResultResponse

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

the class DragingDialogs method textToSpeachDialog.

public static void textToSpeachDialog(final FrameLayout anchor, final DocumentController controller, final String textToRead) {
    if (TTSEngine.get().hasNoEngines()) {
        Urls.openTTS(controller.getActivity());
        return;
    }
    DragingPopup dialog = new DragingPopup(R.string.text_to_speech, anchor, 300, 440) {

        @Override
        @SuppressLint("NewApi")
        public View getContentView(LayoutInflater inflater) {
            final Activity activity = controller.getActivity();
            final View view = inflater.inflate(R.layout.dialog_tts, null, false);
            final TextView ttsPage = (TextView) view.findViewById(R.id.ttsPage);
            // ttsPage.setText(activity.getString(R.string.page) + " " +
            // controller.getCurentPageFirst1());
            final TextView textEngine = (TextView) view.findViewById(R.id.ttsEngine);
            final TextView textDebug = (TextView) view.findViewById(R.id.textDebug);
            final TextView timerTime = (TextView) view.findViewById(R.id.timerTime);
            final TextView timerStart = (TextView) view.findViewById(R.id.timerStart);
            timerTime.setText(AppState.get().ttsTimer + " " + controller.getString(R.string.minutes).toLowerCase(Locale.US));
            timerTime.setOnClickListener(new OnClickListener() {

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

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                AppState.get().ttsTimer = number;
                                timerTime.setText(AppState.get().ttsTimer + " " + controller.getString(R.string.minutes).toLowerCase(Locale.US));
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            timerStart.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (TempHolder.get().timerFinishTime == 0) {
                        TempHolder.get().timerFinishTime = System.currentTimeMillis() + AppState.get().ttsTimer * 60 * 1000;
                    } else {
                        TempHolder.get().timerFinishTime = 0;
                    }
                    timerStart.setText(TempHolder.get().timerFinishTime == 0 ? R.string.start : R.string.cancel);
                    ttsPage.setText(TempHolder.get().timerFinishTime == 0 ? "" : controller.getString(R.string.reading_will_be_stopped) + " " + DateFormat.getTimeFormat(activity).format(TempHolder.get().timerFinishTime));
                }
            });
            timerStart.setText(TempHolder.get().timerFinishTime == 0 ? R.string.start : R.string.cancel);
            ttsPage.setText(TempHolder.get().timerFinishTime == 0 ? "" : controller.getString(R.string.reading_will_be_stopped) + " " + DateFormat.getTimeFormat(activity).format(TempHolder.get().timerFinishTime));
            TTSEngine.get().getTTS(new OnInitListener() {

                @Override
                public void onInit(int status) {
                    textEngine.setText(TTSEngine.get().getCurrentEngineName());
                    TxtUtils.underlineTextView(textEngine);
                }
            });
            textEngine.setText(TTSEngine.get().getCurrentEngineName());
            TxtUtils.underlineTextView(textEngine);
            textEngine.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PopupMenu menu = new PopupMenu(v.getContext(), v);
                    List<EngineInfo> engines = TTSEngine.get().getTTS().getEngines();
                    for (final EngineInfo eInfo : engines) {
                        final String name = TTSEngine.engineToString(eInfo);
                        menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                textEngine.setText(name);
                                TTSEngine.get().setTTSWithEngine(eInfo.name);
                                TxtUtils.underlineTextView(textEngine);
                                return false;
                            }
                        });
                    }
                    menu.show();
                }
            });
            view.findViewById(R.id.ttsSettings).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    try {
                        TTSEngine.get().stop();
                        Intent intent = new Intent();
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        if (Build.VERSION.SDK_INT >= 14) {
                            intent.setAction("com.android.settings.TTS_SETTINGS");
                        } else {
                            intent.addCategory(Intent.CATEGORY_LAUNCHER);
                            intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings"));
                        }
                        activity.startActivity(intent);
                    } catch (Exception e) {
                        Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show();
                        LOG.e(e);
                    }
                }
            });
            view.findViewById(R.id.onPlay).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    TTSService.playBookPage(controller.getCurentPageFirst1() - 1, controller.getCurrentBook().getPath(), "", controller.getBookWidth(), controller.getBookHeight(), AppState.get().fontSizeSp);
                }
            });
            view.findViewById(R.id.onPause).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    TTSEngine.get().stop();
                    TTSNotification.hideNotification();
                }
            });
            view.findViewById(R.id.onPause).setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    textDebug.setVisibility(View.VISIBLE);
                    return true;
                }
            });
            final SeekBar seekBarSpeed = (SeekBar) view.findViewById(R.id.seekBarSpeed);
            seekBarSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (fromUser) {
                        AppState.get().ttsSpeed = (float) progress / 100;
                    }
                }
            });
            final SeekBar seekBarPitch = (SeekBar) view.findViewById(R.id.seekBarPitch);
            seekBarPitch.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (fromUser) {
                        AppState.get().ttsPitch = (float) progress / 100;
                    }
                }
            });
            seekBarPitch.setProgress((int) (AppState.get().ttsPitch * 100));
            seekBarSpeed.setProgress((int) (AppState.get().ttsSpeed * 100));
            final AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
            final SeekBar seekVolume = (SeekBar) view.findViewById(R.id.seekVolume);
            seekVolume.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
            seekVolume.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
            seekVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (fromUser) {
                        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
                    }
                }
            });
            TxtUtils.underlineTextView((TextView) view.findViewById(R.id.restore_defaults)).setOnClickListener(new OnClickListener() {

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

                        @Override
                        public void run() {
                            seekBarPitch.setProgress(100);
                            seekBarSpeed.setProgress(100);
                            AppState.get().ttsPitch = (float) 1.0;
                            AppState.get().ttsSpeed = (float) 1.0;
                            TTSEngine.get().shutdown();
                            TTSEngine.get().getTTS();
                            textEngine.setText(TTSEngine.get().getCurrentEngineName());
                            TxtUtils.underlineTextView(textEngine);
                        }
                    });
                }
            });
            // 
            CheckBox notificationOngoing = (CheckBox) view.findViewById(R.id.notificationOngoing);
            notificationOngoing.setChecked(AppState.get().notificationOngoing);
            notificationOngoing.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().notificationOngoing = isChecked;
                    TTSNotification.hideNotification();
                    TTSNotification.showLast();
                }
            });
            CheckBox stopReadingOnCall = (CheckBox) view.findViewById(R.id.stopReadingOnCall);
            stopReadingOnCall.setChecked(AppState.get().stopReadingOnCall);
            stopReadingOnCall.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    AppState.get().stopReadingOnCall = isChecked;
                }
            });
            view.findViewById(R.id.ttsSkeakToFile).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    AlertDialog.Builder dialog = new AlertDialog.Builder(controller.getActivity());
                    dialog.setTitle(R.string.speak_into_file_wav_);
                    View inflate = LayoutInflater.from(v.getContext()).inflate(R.layout.dialog_tts_wav, null, false);
                    final TextView ttsSpeakPath = (TextView) inflate.findViewById(R.id.ttsSpeakPath);
                    final TextView progressText = (TextView) inflate.findViewById(R.id.progressText);
                    final ProgressBar progressBar1 = (ProgressBar) inflate.findViewById(R.id.progressBar1);
                    final Button start = (Button) inflate.findViewById(R.id.start);
                    final Button stop = (Button) inflate.findViewById(R.id.stop);
                    progressBar1.setVisibility(View.GONE);
                    progressText.setText("");
                    ttsSpeakPath.setText(Html.fromHtml("<u>" + AppState.get().ttsSpeakPath + "/<b>" + controller.getCurrentBook().getName() + "</b></u>"));
                    ttsSpeakPath.setOnClickListener(new OnClickListener() {

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

                                @Override
                                public boolean onResultRecive(String nPath, Dialog dialog) {
                                    AppState.get().ttsSpeakPath = nPath;
                                    ttsSpeakPath.setText(Html.fromHtml("<u>" + AppState.get().ttsSpeakPath + "/<b>" + controller.getCurrentBook().getName() + "</b></u>"));
                                    dialog.dismiss();
                                    return false;
                                }
                            });
                        }
                    });
                    final ResultResponse<String> info = new ResultResponse<String>() {

                        @Override
                        public boolean onResultRecive(final String result) {
                            controller.getActivity().runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    progressText.setText(result);
                                }
                            });
                            return false;
                        }
                    };
                    stop.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            TempHolder.isRecordTTS = false;
                            progressBar1.setVisibility(View.GONE);
                        }
                    });
                    start.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            if (!TempHolder.isRecordTTS) {
                                TempHolder.isRecordTTS = true;
                                progressBar1.setVisibility(View.VISIBLE);
                                TTSEngine.get().speakToFile(controller, info);
                            }
                        }
                    });
                    dialog.setView(inflate);
                    dialog.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            TempHolder.isRecordTTS = false;
                        }
                    });
                    AlertDialog create = dialog.create();
                    create.setOnDismissListener(new OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            TempHolder.isRecordTTS = false;
                        }
                    });
                    create.show();
                }
            });
            return view;
        }
    };
    dialog.setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            AppState.get().save(controller.getActivity());
        }
    });
    dialog.show("TTS");
}
Also used : AlertDialog(android.app.AlertDialog) ResultResponse(com.foobnix.android.utils.ResultResponse) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) FragmentActivity(android.support.v4.app.FragmentActivity) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) Activity(android.app.Activity) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) EngineInfo(android.speech.tts.TextToSpeech.EngineInfo) AudioManager(android.media.AudioManager) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) ColorsDialog(com.foobnix.pdf.info.widget.ColorsDialog) AlertDialog(android.app.AlertDialog) FontDialog(com.foobnix.pdf.info.widget.FontDialog) TapZoneDialog(com.foobnix.pdf.info.widget.TapZoneDialog) OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) ComponentName(android.content.ComponentName) ProgressBar(android.widget.ProgressBar) OnInitListener(android.speech.tts.TextToSpeech.OnInitListener) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) OnDismissListener(android.content.DialogInterface.OnDismissListener) MenuItem(android.view.MenuItem) Intent(android.content.Intent) 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) FragmentActivity(android.support.v4.app.FragmentActivity) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) CompoundButton(android.widget.CompoundButton) PopupMenu(android.widget.PopupMenu)

Example 3 with ResultResponse

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

the class DragingDialogs method searchMenu.

public static void searchMenu(final FrameLayout anchor, final DocumentController controller, final String text) {
    DragingPopup dialog = new DragingPopup(R.string.search, anchor, 250, 150) {

        @Override
        public View getContentView(LayoutInflater inflater) {
            final View view = inflater.inflate(R.layout.search_dialog, null, false);
            final EditText searchEdit = (EditText) view.findViewById(R.id.edit1);
            searchEdit.setText(text);
            final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar1);
            final TextView searchingMsg = (TextView) view.findViewById(R.id.searching);
            final GridView gridView = (GridView) view.findViewById(R.id.grid1);
            gridView.setColumnWidth(Dips.dpToPx(80));
            final BaseItemLayoutAdapter<Integer> adapter = new BaseItemLayoutAdapter<Integer>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item) {

                @Override
                public void populateView(View inflate, int arg1, Integer page) {
                    final TextView text = Views.text(inflate, android.R.id.text1, TxtUtils.deltaPage(page + 1, 0));
                    text.setGravity(Gravity.CENTER);
                    text.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                }

                @Override
                public long getItemId(int position) {
                    return getItem(position) + 1;
                }
            };
            gridView.setAdapter(adapter);
            gridView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    controller.onGoToPage((int) id);
                }
            });
            ImageView onClear = (ImageView) view.findViewById(R.id.imageClear);
            onClear.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    boolean isRun = TempHolder.isSeaching;
                    TempHolder.isSeaching = false;
                    if (!isRun) {
                        searchEdit.setText("");
                        controller.clearSelectedText();
                        searchingMsg.setVisibility(View.GONE);
                        adapter.getItems().clear();
                        adapter.notifyDataSetChanged();
                    }
                }
            });
            final View onSearch = view.findViewById(R.id.onSearch);
            TintUtil.setTintBg(onSearch);
            EditTextHelper.enableKeyboardSearch(searchEdit, new Runnable() {

                @Override
                public void run() {
                    onSearch.performClick();
                }
            });
            if (TxtUtils.isNotEmpty(text)) {
                onSearch.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        onSearch.performClick();
                    }
                }, 250);
            }
            final String searchingString = anchor.getContext().getString(R.string.searching_please_wait_);
            final int count = controller.getPageCount();
            final Handler hMessage = new Handler() {

                @Override
                public void handleMessage(android.os.Message msg) {
                    int pageNumber = msg.what;
                    LOG.d("Receive page", pageNumber);
                    progressBar.setVisibility(View.GONE);
                    gridView.setVisibility(View.VISIBLE);
                    if (pageNumber < -1) {
                        searchingMsg.setVisibility(View.VISIBLE);
                        searchingMsg.setText(searchingString + " " + Math.abs(pageNumber) + "/" + count);
                        return;
                    }
                    if (pageNumber == -1) {
                        if (adapter.getItems().size() == 0) {
                            searchingMsg.setVisibility(View.VISIBLE);
                            searchingMsg.setText(R.string.msg_no_text_found);
                        } else {
                            searchingMsg.setVisibility(View.GONE);
                        }
                    }
                    if (pageNumber == Integer.MAX_VALUE) {
                        adapter.notifyDataSetChanged();
                        return;
                    }
                    if (pageNumber >= 0) {
                        pageNumber = PageUrl.realToFake(pageNumber);
                        searchingMsg.setVisibility(View.VISIBLE);
                        adapter.getItems().add(pageNumber);
                        adapter.notifyDataSetChanged();
                    }
                }
            };
            onSearch.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (TempHolder.isSeaching) {
                        return;
                    }
                    String searchString = searchEdit.getText().toString().trim();
                    if (searchString.length() < 2) {
                        return;
                    }
                    TempHolder.isSeaching = true;
                    searchingMsg.setText(R.string.searching_please_wait_);
                    searchingMsg.setVisibility(View.VISIBLE);
                    progressBar.setVisibility(View.VISIBLE);
                    gridView.setVisibility(View.GONE);
                    adapter.getItems().clear();
                    adapter.notifyDataSetChanged();
                    Keyboards.close(searchEdit);
                    hMessage.removeCallbacksAndMessages(null);
                    controller.doSearch(searchString, new ResultResponse<Integer>() {

                        @Override
                        public boolean onResultRecive(final Integer pageNumber) {
                            hMessage.sendEmptyMessage(pageNumber);
                            return false;
                        }
                    });
                }
            });
            return view;
        }
    };
    dialog.setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            TempHolder.isSeaching = false;
        }
    });
    dialog.show("searchMenu");
}
Also used : EditText(android.widget.EditText) ResultResponse(com.foobnix.android.utils.ResultResponse) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) InvalidateMessage(com.foobnix.pdf.search.activity.msg.InvalidateMessage) Handler(android.os.Handler) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Example 4 with ResultResponse

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

the class DefaultListeners method getOnItemClickListener.

public static ResultResponse<FileMeta> getOnItemClickListener(final Activity a) {
    return new ResultResponse<FileMeta>() {

        @Override
        public boolean onResultRecive(FileMeta result) {
            if (isTagCicked(a, result)) {
                return true;
            }
            final File item = new File(result.getPath());
            if (item.isDirectory()) {
                Intent intent = // 
                new Intent(UIFragment.INTENT_TINT_CHANGE).putExtra(MainTabs2.EXTRA_PAGE_NUMBER, // 
                UITab.getCurrentTabIndex(UITab.BrowseFragment));
                LocalBroadcastManager.getInstance(a).sendBroadcast(intent);
                EventBus.getDefault().post(new OpenDirMessage(result.getPath()));
            } else {
                ExtUtils.openFile(a, result);
            }
            return false;
        }
    };
}
Also used : ResultResponse(com.foobnix.android.utils.ResultResponse) OpenDirMessage(com.foobnix.pdf.search.activity.msg.OpenDirMessage) Intent(android.content.Intent) File(java.io.File) DocumentFile(android.support.v4.provider.DocumentFile) FileMeta(com.foobnix.dao2.FileMeta)

Example 5 with ResultResponse

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

the class DefaultListeners method getOnAuthorClickListener.

public static ResultResponse<String> getOnAuthorClickListener(final Activity a) {
    return new ResultResponse<String>() {

        @Override
        public boolean onResultRecive(String result) {
            result = AppDB.SEARCH_IN.AUTHOR.getDotPrefix() + " " + result;
            Intent intent = // 
            new Intent(UIFragment.INTENT_TINT_CHANGE).putExtra(MainTabs2.EXTRA_SEACH_TEXT, // 
            result).putExtra(MainTabs2.EXTRA_PAGE_NUMBER, // 
            UITab.getCurrentTabIndex(UITab.SearchFragment));
            LocalBroadcastManager.getInstance(a).sendBroadcast(intent);
            return false;
        }
    };
}
Also used : ResultResponse(com.foobnix.android.utils.ResultResponse) Intent(android.content.Intent)

Aggregations

ResultResponse (com.foobnix.android.utils.ResultResponse)10 Intent (android.content.Intent)5 File (java.io.File)5 SuppressLint (android.annotation.SuppressLint)4 RecyclerView (android.support.v7.widget.RecyclerView)4 LayoutInflater (android.view.LayoutInflater)4 View (android.view.View)4 OnClickListener (android.view.View.OnClickListener)4 AbsListView (android.widget.AbsListView)4 AdapterView (android.widget.AdapterView)4 GridView (android.widget.GridView)4 ImageView (android.widget.ImageView)4 ListView (android.widget.ListView)4 TextView (android.widget.TextView)4 AlertDialog (android.app.AlertDialog)3 ProgressDialog (android.app.ProgressDialog)3 DialogInterface (android.content.DialogInterface)3 DocumentFile (android.support.v4.provider.DocumentFile)3 MenuItem (android.view.MenuItem)3 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)3