Search in sources :

Example 71 with PopupMenu

use of android.support.v7.widget.PopupMenu 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 72 with PopupMenu

use of android.support.v7.widget.PopupMenu in project LibreraReader by foobnix.

the class DragingDialogs method moreBookSettings.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Example 73 with PopupMenu

use of android.support.v7.widget.PopupMenu in project LibreraReader by foobnix.

the class RecentFragment2 method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_recent, container, false);
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    panelRecent = view.findViewById(R.id.panelRecent);
    onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
    onListGrid.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popupMenu(onListGrid);
        }
    });
    TxtUtils.underlineTextView((TextView) view.findViewById(R.id.clearAllRecent)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialogs.showDialog(getActivity(), getString(R.string.do_you_want_to_clear_everything_), getString(R.string.ok), new Runnable() {

                @Override
                public void run() {
                    clearAllRecent.run();
                    RecentUpates.updateAll(getActivity());
                }
            });
        }
    });
    recentAdapter = new FileMetaAdapter();
    recentAdapter.tempValue = FileMetaAdapter.TEMP_VALUE_FOLDER_PATH;
    bindAdapter(recentAdapter);
    bindAuthorsSeriesAdapter(recentAdapter);
    recentAdapter.setOnDeleteClickListener(onDeleteRecentClick);
    onGridList();
    populate();
    TintUtil.setBackgroundFillColor(panelRecent, TintUtil.color);
    return view;
}
Also used : OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) FileMetaAdapter(com.foobnix.ui2.adapter.FileMetaAdapter)

Example 74 with PopupMenu

use of android.support.v7.widget.PopupMenu in project letterpress by Pixplicity.

the class MainActivity method showPopupMenu.

private void showPopupMenu(View anchorView) {
    PopupMenu popup = new PopupMenu(MainActivity.this, anchorView);
    popup.getMenuInflater().inflate(R.menu.menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            // ...
            return true;
        }
    });
    // Apply custom font to popup menu
    FontUtil.applyTypeface(popup.getMenu(), mTypeface);
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.support.v7.widget.PopupMenu)

Example 75 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Roblu by wdavies973.

the class Drawing method showPopup.

private void showPopup() {
    View menuItemView = findViewById(R.id.mode);
    final PopupMenu popup = new PopupMenu(Drawing.this, menuItemView);
    MenuInflater inflate = popup.getMenuInflater();
    inflate.inflate(R.menu.drawing_modes, popup.getMenu());
    final PopupMenu.OnMenuItemClickListener popupListener = new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            canvas.setMode(CanvasView.Mode.DRAW);
            if (item.getItemId() == R.id.pen) {
                canvas.setDrawer(CanvasView.Drawer.PEN);
                return true;
            } else if (item.getItemId() == R.id.eraser) {
                DRAWINGS = null;
                getIntent().putExtra("fieldDrawings", DRAWINGS);
                recreate();
                return true;
            } else if (item.getItemId() == R.id.line) {
                canvas.setDrawer(CanvasView.Drawer.LINE);
                return true;
            } else if (item.getItemId() == R.id.rectangle) {
                canvas.setDrawer(CanvasView.Drawer.RECTANGLE);
                return true;
            } else if (item.getItemId() == R.id.circle) {
                canvas.setDrawer(CanvasView.Drawer.CIRCLE);
                return true;
            } else if (item.getItemId() == R.id.ellipse) {
                canvas.setDrawer(CanvasView.Drawer.ELLIPSE);
                return true;
            } else if (item.getItemId() == R.id.quad) {
                canvas.setDrawer(CanvasView.Drawer.QUADRATIC_BEZIER);
                return true;
            } else if (item.getItemId() == R.id.stroke) {
                changeWidth();
                return true;
            } else if (item.getItemId() == R.id.color) {
                ColorPickerDialog.newBuilder().setAllowPresets(true).setPresets(new int[] { Color.RED, Color.BLUE, Color.CYAN, Color.YELLOW, Color.MAGENTA, Color.BLACK, Color.WHITE, Color.GRAY, Color.GREEN, Color.DKGRAY, Color.LTGRAY }).setColor(color).setShowColorShades(true).show(Drawing.this);
                return true;
            }
            return false;
        }
    };
    popup.setOnMenuItemClickListener(popupListener);
    popup.show();
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) View(android.view.View) CanvasView(com.android.graphics.CanvasView) TextView(android.widget.TextView) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15