use of com.foobnix.android.utils.ResultResponse2 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;
}
use of com.foobnix.android.utils.ResultResponse2 in project LibreraReader by foobnix.
the class MultyDocSearchDialog method getDialogView.
public static View getDialogView(final FragmentActivity c) {
View inflate = LayoutInflater.from(c).inflate(R.layout.dialog_multy_search, null, false);
inflate.setKeepScreenOn(true);
final EditText editPath = (EditText) inflate.findViewById(R.id.editPath);
final Button buttonPath = (Button) inflate.findViewById(R.id.buttonPath);
final EditText editSearchText = (EditText) inflate.findViewById(R.id.editSearchText);
final Button searchStart = (Button) inflate.findViewById(R.id.searchStart);
final Button searchStop = (Button) inflate.findViewById(R.id.searchStop);
infoView1 = (TextView) inflate.findViewById(R.id.infoView1);
final ListView listView = (ListView) inflate.findViewById(R.id.listView);
final CheckBox searchInTheSubfolders = (CheckBox) inflate.findViewById(R.id.searchInTheSubfolders);
final BaseItemLayoutAdapter adapter = new BaseItemLayoutAdapter<Pair<String, Integer>>(c, android.R.layout.simple_list_item_1, Model.get().res) {
@Override
public void populateView(View layout, int position, final Pair<String, Integer> item) {
final File file = new File(item.first);
TextView t = (TextView) layout.findViewById(android.R.id.text1);
t.setText(file.getName() + " [" + (item.second == -1 ? "not found" : (item.second + 1)) + "]");
t.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ExtUtils.showDocument(c, file, item.second + 1);
}
});
}
};
listView.setAdapter(adapter);
buttonPath.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder(c, Model.get().path).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
Model.get().path = nPath;
AppState.get().dirLastPath = nPath;
editPath.setText(Model.get().path);
dialog.dismiss();
return false;
}
});
}
});
editPath.setText(Model.get().path);
final Handler updater2 = new Handler() {
@Override
public void handleMessage(Message msg) {
adapter.notifyDataSetChanged();
}
};
final Handler updater1 = new Handler() {
@Override
public void handleMessage(Message msg) {
infoView1.setText((Model.get().currentPage + 1) + "/" + Model.get().currentPagesCount + " " + Model.get().currentDoc);
}
};
searchStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Model.get().text = editSearchText.getText().toString().trim();
if (TxtUtils.isEmpty(Model.get().text)) {
Toast.makeText(c, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
return;
}
if (Model.get().text.contains(" ")) {
Toast.makeText(c, R.string.you_can_search_only_one_word, Toast.LENGTH_SHORT).show();
return;
}
if (Model.get().isSearcingRun) {
Toast.makeText(c, R.string.searching_please_wait_, Toast.LENGTH_SHORT).show();
return;
}
Model.get().isSearcingRun = true;
new MyTask(updater1, updater2, c, searchInTheSubfolders.isChecked()).execute();
infoView1.setText("");
Model.get().res.clear();
adapter.notifyDataSetChanged();
Keyboards.close(editSearchText);
}
});
editSearchText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
searchStart.performClick();
handled = true;
}
return handled;
}
});
editSearchText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
searchStart.performClick();
return true;
}
return false;
}
});
searchStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Model.get().isSearcingRun = false;
infoView1.setText("");
}
});
infoView1.setText("");
Model.get().res.clear();
adapter.notifyDataSetChanged();
return inflate;
}
use of com.foobnix.android.utils.ResultResponse2 in project LibreraReader by foobnix.
the class PrefFragment2 method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
inflate = inflater.inflate(R.layout.preferences, container, false);
// tabs position
final DragLinearLayout dragLinearLayout = (DragLinearLayout) inflate.findViewById(R.id.dragLinearLayout);
final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2));
final Runnable dragLinear = new Runnable() {
@Override
public void run() {
dragLinearLayout.removeAllViews();
for (UITab tab : UITab.getOrdered(AppState.get().tabsOrder)) {
View library = LayoutInflater.from(getActivity()).inflate(R.layout.item_tab_line, null, false);
((TextView) library.findViewById(R.id.text1)).setText(tab.getName());
((CheckBox) library.findViewById(R.id.isVisible)).setChecked(tab.isVisible());
((ImageView) library.findViewById(R.id.image1)).setImageResource(tab.getIcon());
TintUtil.setTintImageWithAlpha(((ImageView) library.findViewById(R.id.image1)), TintUtil.COLOR_TINT_GRAY);
library.setTag(tab.getIndex());
dragLinearLayout.addView(library, layoutParams);
}
for (int i = 0; i < dragLinearLayout.getChildCount(); i++) {
View child = dragLinearLayout.getChildAt(i);
View handle = child.findViewById(R.id.imageDrag);
dragLinearLayout.setViewDraggable(child, handle);
}
}
};
dragLinear.run();
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.tabsApply)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().tabsOrder = "";
for (int i = 0; i < dragLinearLayout.getChildCount(); i++) {
View child = dragLinearLayout.getChildAt(i);
boolean isVisible = ((CheckBox) child.findViewById(R.id.isVisible)).isChecked();
AppState.get().tabsOrder += child.getTag() + "#" + (isVisible ? "1" : "0") + ",";
}
AppState.get().tabsOrder = TxtUtils.replaceLast(AppState.get().tabsOrder, ",", "");
LOG.d("tabsApply", AppState.get().tabsOrder);
AppState.get().save(getActivity());
onTheme();
}
});
final CheckBox isshowPrefAsMenu = (CheckBox) inflate.findViewById(R.id.isshowPrefAsMenu);
isshowPrefAsMenu.setChecked(AppState.get().tabsOrder.contains(UITab.PrefFragment.index + "#0"));
isshowPrefAsMenu.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
AppState.get().tabsOrder = AppState.get().tabsOrder.replace(UITab.PrefFragment.index + "#1", UITab.PrefFragment.index + "#0");
} else {
AppState.get().tabsOrder = AppState.get().tabsOrder.replace(UITab.PrefFragment.index + "#0", UITab.PrefFragment.index + "#1");
}
dragLinear.run();
}
});
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.tabsDefaul)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog(getActivity(), getActivity().getString(R.string.restore_defaults_full), new Runnable() {
@Override
public void run() {
AppState.get().tabsOrder = AppState.DEFAULTS_TABS_ORDER;
isshowPrefAsMenu.setChecked(false);
dragLinear.run();
}
});
}
});
// tabs position
section1 = inflate.findViewById(R.id.section1);
section2 = inflate.findViewById(R.id.section2);
section3 = inflate.findViewById(R.id.section3);
section4 = inflate.findViewById(R.id.section4);
section5 = inflate.findViewById(R.id.section5);
section6 = inflate.findViewById(R.id.section6);
section7 = inflate.findViewById(R.id.section7);
onTintChanged();
final int max = Dips.pxToDp(Dips.screenMinWH() / 2) - 2 * 4;
final CustomSeek coverSmallSize = (CustomSeek) inflate.findViewById(R.id.coverSmallSize);
coverSmallSize.init(40, max, AppState.get().coverSmallSize);
coverSmallSize.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
TempHolder.listHash++;
AppState.get().coverSmallSize = result;
return false;
}
});
final CustomSeek coverBigSize = (CustomSeek) inflate.findViewById(R.id.coverBigSize);
coverBigSize.init(40, Math.max(max, AppState.get().coverBigSize), AppState.get().coverBigSize);
coverBigSize.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
TempHolder.listHash++;
AppState.get().coverBigSize = result;
return false;
}
});
final TextView columsCount = (TextView) inflate.findViewById(R.id.columsCount);
columsCount.setText("" + Dips.screenWidthDP() / AppState.get().coverBigSize);
TxtUtils.underlineTextView(columsCount);
columsCount.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
PopupMenu p = new PopupMenu(getContext(), columsCount);
for (int i = 1; i <= 8; i++) {
final int k = i;
p.getMenu().add("" + k).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int result = Dips.screenWidthDP() / k - 8;
TempHolder.listHash++;
AppState.get().coverBigSize = result;
columsCount.setText("" + k);
TxtUtils.underlineTextView(columsCount);
coverBigSize.init(40, Math.max(max, AppState.get().coverBigSize), AppState.get().coverBigSize);
return false;
}
});
}
p.show();
}
});
final TextView columsDefaul = (TextView) inflate.findViewById(R.id.columsDefaul);
TxtUtils.underlineTextView(columsDefaul);
columsDefaul.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog(getActivity(), getActivity().getString(R.string.restore_defaults_full), new Runnable() {
@Override
public void run() {
IMG.clearDiscCache();
IMG.clearMemoryCache();
AppState.get().coverBigSize = (int) (((Dips.screenWidthDP() / (Dips.screenWidthDP() / 120)) - 8) * (Dips.isXLargeScreen() ? 1.5f : 1));
AppState.get().coverSmallSize = 80;
TempHolder.listHash++;
columsCount.setText("" + Dips.screenWidthDP() / AppState.get().coverBigSize);
TxtUtils.underlineTextView(columsCount);
coverSmallSize.init(40, max, AppState.get().coverSmallSize);
coverBigSize.init(40, Math.max(max, AppState.get().coverBigSize), AppState.get().coverBigSize);
}
});
}
});
final ScrollView scrollView = (ScrollView) inflate.findViewById(R.id.scroll);
scrollView.setVerticalScrollBarEnabled(false);
((TextView) inflate.findViewById(R.id.section6)).setText(String.format("%s: %s", getString(R.string.product), AppsConfig.TXT_APP_NAME));
try {
PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
final String version = packageInfo.versionName;
((TextView) inflate.findViewById(R.id.pVersion)).setText(String.format("%s: %s (%s)", getString(R.string.version), version, AppsConfig.MUPDF_VERSION));
} catch (final NameNotFoundException e) {
}
TextView onCloseApp = (TextView) inflate.findViewById(R.id.onCloseApp);
TxtUtils.underlineTextView(onCloseApp);
onCloseApp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
((MainTabs2) getActivity()).showInterstial();
}
});
final TextView onFullScreen = (TextView) inflate.findViewById(R.id.fullscreen);
onFullScreen.setText(AppState.get().isFullScreenMain ? R.string.yes : R.string.no);
TxtUtils.underlineTextView(onFullScreen);
onFullScreen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
MyPopupMenu popup = new MyPopupMenu(getActivity(), v);
popup.getMenu().add(R.string.yes).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().isFullScreenMain = true;
onFullScreen.setText(R.string.yes);
TxtUtils.underlineTextView(onFullScreen);
DocumentController.chooseFullScreen(getActivity(), AppState.get().isFullScreenMain);
return false;
}
});
popup.getMenu().add(R.string.no).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().isFullScreenMain = false;
onFullScreen.setText(R.string.no);
TxtUtils.underlineTextView(onFullScreen);
DocumentController.chooseFullScreen(getActivity(), AppState.get().isFullScreenMain);
return false;
}
});
popup.show();
}
});
screenOrientation = (TextView) inflate.findViewById(R.id.screenOrientation);
screenOrientation.setText(DocumentController.getRotationText());
TxtUtils.underlineTextView(screenOrientation);
screenOrientation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu menu = new PopupMenu(v.getContext(), v);
for (int i = 0; i < DocumentController.orientationIds.size(); i++) {
final int j = i;
final int name = DocumentController.orientationTexts.get(i);
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().orientation = DocumentController.orientationIds.get(j);
screenOrientation.setText(DocumentController.orientationTexts.get(j));
TxtUtils.underlineTextView(screenOrientation);
DocumentController.doRotation(getActivity());
return false;
}
});
}
menu.show();
}
});
// inflate.findViewById(R.id.onHelpTranslate).setOnClickListener(new
// OnClickListener() {
//
// @Override
// public void onClick(final View v) {
// Urls.open(getActivity(),
// "https://www.dropbox.com/sh/8el7kon2sbx46w8/xm3qoHYT7n");
// }
// });
inflate.findViewById(R.id.onKeyCode).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
new KeyCodeDialog(getActivity(), onCloseDialog);
}
});
themeColor = (TextView) inflate.findViewById(R.id.themeColor);
themeColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
PopupMenu p = new PopupMenu(getContext(), themeColor);
p.getMenu().add(R.string.light).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().isWhiteTheme = true;
AppState.get().isInkMode = false;
AppState.get().contrastImage = 0;
AppState.get().brigtnessImage = 0;
AppState.get().bolderTextOnImage = false;
AppState.get().isEnableBC = false;
AppState.get().save(getActivity());
IMG.clearDiscCache();
IMG.clearMemoryCache();
onTheme();
return false;
}
});
p.getMenu().add(R.string.black).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().isWhiteTheme = false;
AppState.get().isInkMode = false;
AppState.get().contrastImage = 0;
AppState.get().brigtnessImage = 0;
AppState.get().bolderTextOnImage = false;
AppState.get().isEnableBC = false;
AppState.get().save(getActivity());
IMG.clearDiscCache();
IMG.clearMemoryCache();
onTheme();
return false;
}
});
p.getMenu().add("Ink").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
IMG.clearDiscCache();
IMG.clearMemoryCache();
onEink();
return false;
}
});
p.show();
}
});
final TextView hypenLang = (TextView) inflate.findViewById(R.id.appLang);
hypenLang.setText(DialogTranslateFromTo.getLanuageByCode(AppState.get().appLang));
TxtUtils.underlineTextView(hypenLang);
hypenLang.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
final List<String> codes = //
Arrays.asList(//
"en", //
"ar", //
"de", //
"es", //
"fa", //
"fi", //
"fr", //
"he", //
"hi", //
"hu", //
"id", //
"it", //
"ja", //
"ko", //
"la", //
"lt", //
"nl", //
"no", //
"pl", //
"pt", //
"ro", //
"ru", //
"sk", //
"sv", "sw", "th", "tr", "uk", "vi", "zh");
List<String> langs = new ArrayList<String>();
for (String code : codes) {
langs.add(DialogTranslateFromTo.getLanuageByCode(code) + ":" + code);
}
Collections.sort(langs);
popupMenu.getMenu().add(R.string.system_language).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
TxtUtils.underlineTextView(hypenLang);
AppState.get().appLang = AppState.MY_SYSTEM_LANG;
TempHolder.get().forseAppLang = true;
MyContextWrapper.wrap(getContext());
AppState.get().save(getActivity());
onTheme();
return false;
}
});
for (int i = 0; i < langs.size(); i++) {
String[] all = langs.get(i).split(":");
final String name = all[0];
final String code = all[1];
popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().appLang = code;
TxtUtils.underlineTextView(hypenLang);
AppState.get().save(getActivity());
onTheme();
return false;
}
});
}
popupMenu.show();
}
});
final TextView appFontScale = (TextView) inflate.findViewById(R.id.appFontScale);
appFontScale.setText(getFontName(AppState.get().appFontScale));
TxtUtils.underlineTextView(appFontScale);
appFontScale.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (float i = 0.7f; i < 2.1f; i += 0.1) {
final float number = i;
popupMenu.getMenu().add(getFontName(number)).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().appFontScale = number;
AppState.get().save(getActivity());
onTheme();
return false;
}
});
}
popupMenu.show();
}
});
final TextView onMail = (TextView) inflate.findViewById(R.id.onMailSupport);
onMail.setText(TxtUtils.underline(getString(R.string.my_email)));
onMail.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
onEmail();
}
});
rememberMode = (CheckBox) inflate.findViewById(R.id.isRememberMode);
rememberMode.setChecked(AppState.get().isRememberMode);
rememberMode.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isRememberMode = isChecked;
}
});
selectedOpenMode = (TextView) inflate.findViewById(R.id.selectedOpenMode);
selectedOpenMode.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT <= 10) {
Toast.makeText(selectedOpenMode.getContext(), R.string.this_function_will_works_in_modern_android, Toast.LENGTH_SHORT).show();
return;
}
final PopupMenu popupMenu = new PopupMenu(selectedOpenMode.getContext(), selectedOpenMode);
final MenuItem advanced_mode = popupMenu.getMenu().add(AppState.get().nameVerticalMode);
advanced_mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().isAlwaysOpenAsMagazine = false;
AppState.get().isMusicianMode = false;
checkOpenWithSpinner();
return false;
}
});
final MenuItem easy_mode = popupMenu.getMenu().add(AppState.get().nameHorizontalMode);
easy_mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().isAlwaysOpenAsMagazine = true;
AppState.get().isMusicianMode = false;
checkOpenWithSpinner();
return false;
}
});
final MenuItem music_mode = popupMenu.getMenu().add(AppState.get().nameMusicianMode);
music_mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().isAlwaysOpenAsMagazine = false;
AppState.get().isMusicianMode = true;
checkOpenWithSpinner();
return false;
}
});
popupMenu.show();
}
});
checkOpenWithSpinner();
final CheckBox isCropBookCovers = (CheckBox) inflate.findViewById(R.id.isCropBookCovers);
isCropBookCovers.setOnCheckedChangeListener(null);
isCropBookCovers.setChecked(AppState.get().isCropBookCovers);
isCropBookCovers.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isCropBookCovers = isChecked;
TempHolder.listHash++;
}
});
final CheckBox isBookCoverEffect = (CheckBox) inflate.findViewById(R.id.isBookCoverEffect);
isBookCoverEffect.setOnCheckedChangeListener(null);
isBookCoverEffect.setChecked(AppState.get().isBookCoverEffect);
isBookCoverEffect.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isBookCoverEffect = isChecked;
ImageLoader.getInstance().clearMemoryCache();
ImageLoader.getInstance().clearDiskCache();
TempHolder.listHash++;
if (isChecked) {
isCropBookCovers.setEnabled(false);
isCropBookCovers.setChecked(true);
} else {
isCropBookCovers.setEnabled(true);
}
}
});
final CheckBox isBorderAndShadow = (CheckBox) inflate.findViewById(R.id.isBorderAndShadow);
isBorderAndShadow.setOnCheckedChangeListener(null);
isBorderAndShadow.setChecked(AppState.get().isBorderAndShadow);
isBorderAndShadow.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isBorderAndShadow = isChecked;
TempHolder.listHash++;
}
});
final CheckBox isShowImages = (CheckBox) inflate.findViewById(R.id.isShowImages);
isShowImages.setOnCheckedChangeListener(null);
isShowImages.setChecked(AppState.get().isShowImages);
isShowImages.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isShowImages = isChecked;
TempHolder.listHash++;
isCropBookCovers.setEnabled(AppState.get().isShowImages);
isBookCoverEffect.setEnabled(AppState.get().isShowImages);
isBorderAndShadow.setEnabled(AppState.get().isShowImages);
}
});
isCropBookCovers.setEnabled(AppState.get().isShowImages);
isBookCoverEffect.setEnabled(AppState.get().isShowImages);
isBorderAndShadow.setEnabled(AppState.get().isShowImages);
CheckBox isLoopAutoplay = (CheckBox) inflate.findViewById(R.id.isLoopAutoplay);
isLoopAutoplay.setChecked(AppState.get().isLoopAutoplay);
isLoopAutoplay.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isLoopAutoplay = isChecked;
}
});
CheckBox isOpenLastBook = (CheckBox) inflate.findViewById(R.id.isOpenLastBook);
isOpenLastBook.setChecked(AppState.get().isOpenLastBook);
isOpenLastBook.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isOpenLastBook = isChecked;
}
});
CheckBox isShowCloseAppDialog = (CheckBox) inflate.findViewById(R.id.isShowCloseAppDialog);
isShowCloseAppDialog.setChecked(AppState.get().isShowCloseAppDialog);
isShowCloseAppDialog.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isShowCloseAppDialog = isChecked;
}
});
final Handler handler = new Handler();
final Runnable ask = new Runnable() {
@Override
public void run() {
AlertDialogs.showDialog(getActivity(), getActivity().getString(R.string.you_need_to_update_the_library), getString(R.string.ok), new Runnable() {
@Override
public void run() {
onScan();
}
}, null);
}
};
final int timeout = 1500;
final CheckBox isFirstSurname = (CheckBox) inflate.findViewById(R.id.isFirstSurname);
isFirstSurname.setChecked(AppState.get().isFirstSurname);
isFirstSurname.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isFirstSurname = isChecked;
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
final CheckBox isAddKeywordsToGenres = (CheckBox) inflate.findViewById(R.id.isAddKeywordsToGenres);
isAddKeywordsToGenres.setChecked(AppState.get().isAddKeywordsToGenres);
isAddKeywordsToGenres.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isAddKeywordsToGenres = isChecked;
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
// //
((CheckBox) inflate.findViewById(R.id.supportPDF)).setChecked(AppState.get().supportPDF);
((CheckBox) inflate.findViewById(R.id.supportPDF)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportPDF = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportXPS)).setChecked(AppState.get().supportXPS);
((CheckBox) inflate.findViewById(R.id.supportXPS)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportXPS = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportDJVU)).setChecked(AppState.get().supportDJVU);
((CheckBox) inflate.findViewById(R.id.supportDJVU)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportDJVU = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportEPUB)).setChecked(AppState.get().supportEPUB);
((CheckBox) inflate.findViewById(R.id.supportEPUB)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportEPUB = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportFB2)).setChecked(AppState.get().supportFB2);
((CheckBox) inflate.findViewById(R.id.supportFB2)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportFB2 = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
isAddKeywordsToGenres.setVisibility(AppState.get().supportFB2 ? View.VISIBLE : View.GONE);
}
});
isAddKeywordsToGenres.setVisibility(AppState.get().supportFB2 ? View.VISIBLE : View.GONE);
((CheckBox) inflate.findViewById(R.id.supportTXT)).setChecked(AppState.get().supportTXT);
((CheckBox) inflate.findViewById(R.id.supportTXT)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportTXT = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportMOBI)).setChecked(AppState.get().supportMOBI);
((CheckBox) inflate.findViewById(R.id.supportMOBI)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportMOBI = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportRTF)).setChecked(AppState.get().supportRTF);
((CheckBox) inflate.findViewById(R.id.supportRTF)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportRTF = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
((CheckBox) inflate.findViewById(R.id.supportCBZ)).setChecked(AppState.get().supportCBZ);
((CheckBox) inflate.findViewById(R.id.supportCBZ)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportCBZ = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
CheckBox supportZIP = (CheckBox) inflate.findViewById(R.id.supportZIP);
supportZIP.setChecked(AppState.get().supportZIP);
supportZIP.setText(getString(R.string.archives) + " (ZIP/RAR/...)");
supportZIP.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportZIP = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
CheckBox supportOther = (CheckBox) inflate.findViewById(R.id.supportOther);
supportOther.setChecked(AppState.get().supportOther);
supportOther.setText(getString(R.string.other) + " (DOC/CHM/...)");
supportOther.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().supportOther = isChecked;
ExtUtils.updateSearchExts();
handler.removeCallbacks(ask);
handler.postDelayed(ask, timeout);
}
});
CheckBox isDisplayAllFilesInFolder = (CheckBox) inflate.findViewById(R.id.isDisplayAllFilesInFolder);
isDisplayAllFilesInFolder.setChecked(AppState.get().isDisplayAllFilesInFolder);
isDisplayAllFilesInFolder.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isDisplayAllFilesInFolder = isChecked;
TempHolder.listHash++;
}
});
// app password
final CheckBox isAppPassword = (CheckBox) inflate.findViewById(R.id.isAppPassword);
isAppPassword.setChecked(PasswordState.get().isAppPassword);
isAppPassword.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
PasswordState.get().isAppPassword = isChecked;
if (isChecked && TxtUtils.isEmpty(PasswordState.get().appPassword)) {
PasswordDialog.showDialog(getActivity(), true, new Runnable() {
@Override
public void run() {
if (TxtUtils.isEmpty(PasswordState.get().appPassword)) {
isAppPassword.setChecked(false);
}
}
});
}
}
});
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.appPassword)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PasswordDialog.showDialog(getActivity(), true, new Runnable() {
@Override
public void run() {
if (TxtUtils.isEmpty(PasswordState.get().appPassword)) {
isAppPassword.setChecked(false);
}
}
});
}
});
// What is new
CheckBox showWhatIsNew = (CheckBox) inflate.findViewById(R.id.isShowWhatIsNewDialog);
showWhatIsNew.setChecked(AppState.get().isShowWhatIsNewDialog);
showWhatIsNew.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isShowWhatIsNewDialog = isChecked;
}
});
final TextView whatIsNew = (TextView) inflate.findViewById(R.id.whatIsNew);
whatIsNew.setText(getActivity().getString(R.string.what_is_new_in) + " " + Apps.getApplicationName(getActivity()) + " " + Apps.getVersionName(getActivity()));
TxtUtils.underlineTextView(whatIsNew);
whatIsNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AndroidWhatsNew.show(getActivity());
}
});
// /
// BrightnessHelper.controlsWrapper(inflate, getActivity());
nextKeys = (TextView) inflate.findViewById(R.id.textNextKeys);
prevKeys = (TextView) inflate.findViewById(R.id.textPrevKeys);
ch = (CheckBox) inflate.findViewById(R.id.onReverse);
ch.setOnCheckedChangeListener(null);
ch.setChecked(AppState.get().isReverseKeys);
ch.setOnCheckedChangeListener(reverseListener);
inflate.findViewById(R.id.onColorChoser).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
}
});
initKeys();
searchPaths = (TextView) inflate.findViewById(R.id.searchPaths);
searchPaths.setText(TxtUtils.underline(AppState.get().searchPaths.replace(",", "<br>")));
searchPaths.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onFolderConfigDialog();
}
});
TextView addFolder = (TextView) inflate.findViewById(R.id.onConfigPath);
TxtUtils.underlineTextView(addFolder);
addFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onFolderConfigDialog();
}
});
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.importButton)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
PrefDialogs.importDialog(getActivity());
}
});
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.exportButton)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
PrefDialogs.exportDialog(getActivity());
}
});
final CheckBox isAutomaticExport = (CheckBox) inflate.findViewById(R.id.isAutomaticExport);
isAutomaticExport.setChecked(AppState.get().isAutomaticExport);
isAutomaticExport.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isAutomaticExport = isChecked;
}
});
// folders
final TextView fontFolder = (TextView) inflate.findViewById(R.id.fontFolder);
TxtUtils.underline(fontFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
fontFolder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder(getActivity(), BookCSS.get().fontFolder).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
BookCSS.get().fontFolder = nPath;
TxtUtils.underline(fontFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
dialog.dismiss();
return false;
}
});
}
});
final TextView downloadFolder = (TextView) inflate.findViewById(R.id.downloadFolder);
TxtUtils.underline(downloadFolder, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
downloadFolder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().downlodsPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
AppState.get().downlodsPath = nPath;
TxtUtils.underline(downloadFolder, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
dialog.dismiss();
return false;
}
});
}
});
final TextView ttsFolder = (TextView) inflate.findViewById(R.id.ttsFolder);
TxtUtils.underline(ttsFolder, TxtUtils.lastTwoPath(AppState.get().ttsSpeakPath));
ttsFolder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().ttsSpeakPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
AppState.get().ttsSpeakPath = nPath;
TxtUtils.underline(ttsFolder, TxtUtils.lastTwoPath(AppState.get().ttsSpeakPath));
dialog.dismiss();
return false;
}
});
}
});
final TextView backupPath = (TextView) inflate.findViewById(R.id.backupFolder);
TxtUtils.underline(backupPath, TxtUtils.lastTwoPath(AppState.get().backupPath));
backupPath.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().backupPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
AppState.get().backupPath = nPath;
TxtUtils.underline(backupPath, TxtUtils.lastTwoPath(AppState.get().backupPath));
dialog.dismiss();
return false;
}
});
}
});
// Widget Configuration
final TextView widgetLayout = (TextView) inflate.findViewById(R.id.widgetLayout);
widgetLayout.setText(AppState.get().widgetType == AppState.WIDGET_LIST ? R.string.list : R.string.grid);
TxtUtils.underlineTextView(widgetLayout);
widgetLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
final MenuItem recent = popupMenu.getMenu().add(R.string.list);
recent.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().widgetType = AppState.WIDGET_LIST;
widgetLayout.setText(R.string.list);
TxtUtils.underlineTextView(widgetLayout);
return false;
}
});
final MenuItem starred = popupMenu.getMenu().add(R.string.grid);
starred.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().widgetType = AppState.WIDGET_GRID;
widgetLayout.setText(R.string.grid);
TxtUtils.underlineTextView(widgetLayout);
return false;
}
});
popupMenu.show();
}
});
final TextView widgetForRecent = (TextView) inflate.findViewById(R.id.widgetForRecent);
widgetForRecent.setText(AppState.get().isStarsInWidget ? R.string.starred : R.string.recent);
TxtUtils.underlineTextView(widgetForRecent);
widgetForRecent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(widgetForRecent.getContext(), widgetForRecent);
final MenuItem recent = popupMenu.getMenu().add(R.string.recent);
recent.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().isStarsInWidget = false;
widgetForRecent.setText(AppState.get().isStarsInWidget ? R.string.starred : R.string.recent);
TxtUtils.underlineTextView(widgetForRecent);
return false;
}
});
final MenuItem starred = popupMenu.getMenu().add(R.string.starred);
starred.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
AppState.get().isStarsInWidget = true;
widgetForRecent.setText(AppState.get().isStarsInWidget ? R.string.starred : R.string.recent);
TxtUtils.underlineTextView(widgetForRecent);
return false;
}
});
popupMenu.show();
}
});
final TextView widgetItemsCount = (TextView) inflate.findViewById(R.id.widgetItemsCount);
widgetItemsCount.setText("" + AppState.get().widgetItemsCount);
TxtUtils.underlineTextView(widgetItemsCount);
widgetItemsCount.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
PopupMenu p = new PopupMenu(getContext(), columsCount);
for (int i = 1; i <= 50; i++) {
final int k = i;
p.getMenu().add("" + k).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().widgetItemsCount = k;
widgetItemsCount.setText("" + k);
TxtUtils.underlineTextView(widgetItemsCount);
return false;
}
});
}
p.show();
}
});
// dictionary
isRememberDictionary = (CheckBox) inflate.findViewById(R.id.isRememberDictionary);
isRememberDictionary.setChecked(AppState.get().isRememberDictionary);
isRememberDictionary.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isRememberDictionary = isChecked;
}
});
selectedDictionaly = (TextView) inflate.findViewById(R.id.selectedDictionaly);
selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
selectedDictionaly.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DialogTranslateFromTo.show(getActivity(), new Runnable() {
@Override
public void run() {
selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
}
});
}
});
textDayColor = (TextView) inflate.findViewById(R.id.onDayColor);
textDayColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new ColorsDialog(getActivity(), true, AppState.get().colorDayText, AppState.get().colorDayBg, false, true, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
textDayColor.setTextColor(colorText);
textDayColor.setBackgroundColor(colorBg);
AppState.get().colorDayText = colorText;
AppState.get().colorDayBg = colorBg;
ImageLoader.getInstance().clearDiskCache();
ImageLoader.getInstance().clearMemoryCache();
}
});
}
});
textNigthColor = (TextView) inflate.findViewById(R.id.onNigthColor);
textNigthColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new ColorsDialog(getActivity(), false, AppState.get().colorNigthText, AppState.get().colorNigthBg, false, true, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
textNigthColor.setTextColor(colorText);
textNigthColor.setBackgroundColor(colorBg);
AppState.get().colorNigthText = colorText;
AppState.get().colorNigthBg = colorBg;
}
});
}
});
TextView onDefalt = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDefaultColor));
onDefalt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
textDayColor.setTextColor(AppState.COLOR_BLACK);
textDayColor.setBackgroundColor(AppState.COLOR_WHITE);
AppState.get().colorNigthText = AppState.COLOR_WHITE;
AppState.get().colorNigthBg = AppState.COLOR_BLACK;
textNigthColor.setTextColor(AppState.COLOR_WHITE);
textNigthColor.setBackgroundColor(AppState.COLOR_BLACK);
}
});
LinearLayout colorsLine = (LinearLayout) inflate.findViewById(R.id.colorsLine);
colorsLine.removeAllViews();
for (String color : AppState.STYLE_COLORS) {
View view = inflater.inflate(R.layout.item_color, (ViewGroup) inflate, false);
view.setBackgroundColor(Color.TRANSPARENT);
final int intColor = Color.parseColor(color);
final View img = view.findViewById(R.id.itColor);
img.setBackgroundColor(intColor);
colorsLine.addView(view, new LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30)));
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TintUtil.color = intColor;
AppState.get().tintColor = intColor;
TempHolder.listHash++;
onTintChanged();
sendNotifyTintChanged();
AppState.get().save(getActivity());
}
});
}
View view = inflater.inflate(R.layout.item_color, (ViewGroup) inflate, false);
view.setBackgroundColor(Color.TRANSPARENT);
final ImageView img = (ImageView) view.findViewById(R.id.itColor);
img.setColorFilter(getResources().getColor(R.color.tint_gray));
img.setImageResource(R.drawable.glyphicons_433_plus);
img.setBackgroundColor(AppState.get().userColor);
colorsLine.addView(view, new LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30)));
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new HSVColorPickerDialog(getContext(), AppState.get().userColor, new OnColorSelectedListener() {
@Override
public void colorSelected(Integer color) {
AppState.get().userColor = color;
AppState.get().tintColor = color;
TintUtil.color = color;
img.setBackgroundColor(color);
onTintChanged();
sendNotifyTintChanged();
AppState.get().save(getActivity());
TempHolder.listHash++;
}
}).show();
}
});
underline(inflate.findViewById(R.id.linksColor)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
closeLeftMenu();
Dialogs.showLinksColorDialog(getActivity(), new Runnable() {
@Override
public void run() {
TempHolder.listHash++;
onTintChanged();
sendNotifyTintChanged();
((MainTabs2) getActivity()).updateCurrentFragment();
}
});
}
});
underline(inflate.findViewById(R.id.onContrast)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Dialogs.showContrastDialogByUrl(getActivity(), new Runnable() {
@Override
public void run() {
ImageLoader.getInstance().clearDiskCache();
ImageLoader.getInstance().clearMemoryCache();
TempHolder.listHash++;
notifyFragment();
}
});
}
});
underline(inflate.findViewById(R.id.onRateIt)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
rateIT();
}
});
underline(inflate.findViewById(R.id.openWeb)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Urls.open(getActivity(), WWW_SITE);
}
});
underline(inflate.findViewById(R.id.openBeta)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Urls.open(getActivity(), WWW_BETA_SITE);
}
});
underline(inflate.findViewById(R.id.openArchive)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Urls.open(getActivity(), WWW_ARCHIVE_SITE);
}
});
underline(inflate.findViewById(R.id.onTelegram)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Urls.open(getActivity(), "https://t.me/LibreraReader");
}
});
TextView proText = (TextView) inflate.findViewById(R.id.downloadPRO);
TxtUtils.underlineTextView(proText);
((View) proText.getParent()).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Urls.openPdfPro(getActivity());
}
});
// if (AppsConfig.checkIsProInstalled(getActivity())) {
// ((View) proText.getParent()).setVisibility(View.GONE);
// }
inflate.findViewById(R.id.cleanRecent).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getString(R.string.clear_all_recent) + "?");
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AppSharedPreferences.get().cleanRecent();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
}
});
inflate.findViewById(R.id.cleanBookmarks).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getString(R.string.clear_all_bookmars) + "?");
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AppSharedPreferences.get().cleanBookmarks();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
}
});
// tutorials
TextView tutorialLink = (TextView) inflate.findViewById(R.id.tutorialLink);
TxtUtils.underlineTextView(tutorialLink);
tutorialLink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Urls.open(getActivity(), AndroidWhatsNew.DETAIL_URL_RU);
}
});
// licences link
underline(inflate.findViewById(R.id.libraryLicenses)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.licenses_for_libraries);
WebView wv = new WebView(getActivity());
wv.loadUrl("file:///android_asset/licenses.html");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
alert.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog create = alert.create();
create.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.hideNavigation(getActivity());
}
});
create.show();
}
});
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.docSearch)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MultyDocSearchDialog.show(getActivity());
}
});
// convert
final TextView docConverter = (TextView) inflate.findViewById(R.id.docConverter);
TxtUtils.underlineTextView(docConverter);
docConverter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu p = new PopupMenu(getContext(), v);
for (final String id : AppState.CONVERTERS.keySet()) {
p.getMenu().add("" + getActivity().getString(R.string.convert_to) + " " + id).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ShareDialog.showsItemsDialog(getActivity(), getActivity().getString(R.string.convert_to) + " " + id, AppState.CONVERTERS.get(id));
return false;
}
});
}
p.show();
}
});
overlay = getActivity().findViewById(R.id.overlay);
return inflate;
}
use of com.foobnix.android.utils.ResultResponse2 in project LibreraReader by foobnix.
the class PrefDialogs method chooseFolderDialog.
public static void chooseFolderDialog(final FragmentActivity a, final Runnable onChanges, final Runnable onScan) {
final PathAdapter recentAdapter = new PathAdapter();
recentAdapter.setPaths(AppState.get().searchPaths);
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
builder.setTitle(R.string.scan_device_for_new_books);
final ListView list = new ListView(a);
list.setAdapter(recentAdapter);
builder.setView(list);
builder.setPositiveButton(R.string.search, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
onScan.run();
}
});
builder.setNeutralButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
ChooserDialogFragment.chooseFolder(a, AppState.get().dirLastPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
boolean isExists = false;
String existPath = "";
for (String str : AppState.get().searchPaths.split(",")) {
if (str != null && str.trim().length() != 0 && nPath.equals(str)) {
isExists = true;
existPath = str;
break;
}
}
if (ExtUtils.isExteralSD(nPath)) {
Toast.makeText(a, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
} else if (isExists) {
Toast.makeText(a, String.format("[ %s == %s ] %s", nPath, existPath, a.getString(R.string.this_directory_is_already_in_the_list)), Toast.LENGTH_LONG).show();
} else {
if (AppState.get().searchPaths.endsWith(",")) {
AppState.get().searchPaths = AppState.get().searchPaths + "" + nPath;
} else {
AppState.get().searchPaths = AppState.get().searchPaths + "," + nPath;
}
}
dialog.dismiss();
onChanges.run();
chooseFolderDialog(a, onChanges, onScan);
return false;
}
});
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
recentAdapter.setOnDeleClick(new ResultResponse<Uri>() {
@Override
public boolean onResultRecive(Uri result) {
String path = result.getPath();
LOG.d("TEST", "Remove " + AppState.get().searchPaths);
LOG.d("TEST", "Remove " + path);
StringBuilder builder = new StringBuilder();
for (String str : AppState.get().searchPaths.split(",")) {
if (str != null && str.trim().length() > 0 && !str.equals(path)) {
builder.append(str);
builder.append(",");
}
}
AppState.get().searchPaths = builder.toString();
LOG.d("TEST", "Remove " + AppState.get().searchPaths);
recentAdapter.setPaths(AppState.get().searchPaths);
onChanges.run();
return false;
}
});
AlertDialog create = builder.create();
create.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.hideNavigation(a);
}
});
create.show();
}
Aggregations