use of com.foobnix.pdf.search.activity.msg.InvalidateMessage in project LibreraReader by foobnix.
the class DragingDialogs method preferences.
public static DragingPopup preferences(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
final int cssHash = BookCSS.get().toCssString().hashCode();
final int appHash = Objects.hashCode(AppState.get());
if (ExtUtils.isNotValidFile(controller.getCurrentBook())) {
DragingPopup dialog = new DragingPopup(R.string.preferences, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public View getContentView(final LayoutInflater inflater) {
TextView txt = new TextView(anchor.getContext());
txt.setText(R.string.file_not_found);
return txt;
}
};
return dialog;
}
DragingPopup dialog = new DragingPopup(R.string.preferences, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public View getContentView(final LayoutInflater inflater) {
View inflate = inflater.inflate(R.layout.dialog_prefs, null, false);
// TOP panel start
View topPanelLine = inflate.findViewById(R.id.topPanelLine);
View topPanelLineDiv = inflate.findViewById(R.id.topPanelLineDiv);
// topPanelLine.setVisibility(controller instanceof
// DocumentControllerHorizontalView ? View.VISIBLE : View.GONE);
topPanelLine.setVisibility(View.GONE);
topPanelLineDiv.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.allBGConfig).setVisibility(Dips.isEInk(inflate.getContext()) ? View.GONE : View.VISIBLE);
View onRecent = inflate.findViewById(R.id.onRecent);
onRecent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
closeDialog();
DragingDialogs.recentBooks(anchor, controller);
}
});
final View onRotate = inflate.findViewById(R.id.onRotate);
onRotate.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT <= 10) {
Toast.makeText(anchor.getContext(), R.string.this_function_will_works_in_modern_android, Toast.LENGTH_SHORT).show();
return;
}
// closeDialog();
MenuBuilderM.addRotateMenu(onRotate, null, updateUIRefresh).show();
}
});
inflate.findViewById(R.id.onPageFlip).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
closeDialog();
DragingDialogs.pageFlippingDialog(anchor, controller, onRefresh);
}
});
ImageView brightness = (ImageView) inflate.findViewById(R.id.onBrightness);
brightness.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isDayNotInvert = !AppState.get().isDayNotInvert;
controller.restartActivity();
}
});
brightness.setImageResource(!AppState.get().isDayNotInvert ? R.drawable.glyphicons_232_sun : R.drawable.glyphicons_2_moon);
final ImageView isCrop = (ImageView) inflate.findViewById(R.id.onCrop);
// isCrop.setVisibility(controller.isTextFormat() ||
// AppState.get().isCut ? View.GONE : View.VISIBLE);
isCrop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isCrop = !AppState.get().isCrop;
SettingsManager.getBookSettings().updateFromAppState();
TintUtil.setTintImageWithAlpha(isCrop, !AppState.get().isCrop ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
updateUIRefresh.run();
}
});
TintUtil.setTintImageWithAlpha(isCrop, !AppState.get().isCrop ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
final ImageView bookCut = (ImageView) inflate.findViewById(R.id.bookCut);
// bookCut.setVisibility(controller.isTextFormat() ? View.GONE :
// View.VISIBLE);
bookCut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
closeDialog();
DragingDialogs.sliceDialog(anchor, controller, updateUIRefresh, new ResultResponse<Integer>() {
@Override
public boolean onResultRecive(Integer result) {
TintUtil.setTintImageWithAlpha(bookCut, !AppState.get().isCut ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
SettingsManager.getBookSettings().updateFromAppState();
EventBus.getDefault().post(new InvalidateMessage());
return false;
}
});
}
});
TintUtil.setTintImageWithAlpha(bookCut, !AppState.get().isCut ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
inflate.findViewById(R.id.onFullScreen).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isFullScreen = !AppState.get().isFullScreen;
DocumentController.chooseFullScreen(controller.getActivity(), AppState.get().isFullScreen);
if (controller.isTextFormat()) {
if (onRefresh != null) {
onRefresh.run();
}
controller.restartActivity();
}
}
});
View tts = inflate.findViewById(R.id.onTTS);
tts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
closeDialog();
DragingDialogs.textToSpeachDialog(anchor, controller);
}
});
final ImageView pin = (ImageView) inflate.findViewById(R.id.onPin);
pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isShowToolBar = !AppState.get().isShowToolBar;
pin.setImageResource(AppState.get().isShowToolBar ? R.drawable.glyphicons_336_pushpin : R.drawable.glyphicons_200_ban);
if (onRefresh != null) {
onRefresh.run();
}
}
});
pin.setImageResource(AppState.get().isShowToolBar ? R.drawable.glyphicons_336_pushpin : R.drawable.glyphicons_200_ban);
// TOP panel end
CheckBox isPreText = (CheckBox) inflate.findViewById(R.id.isPreText);
isPreText.setChecked(AppState.get().isPreText);
isPreText.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isPreText = isChecked;
}
});
isPreText.setVisibility(BookType.TXT.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
CheckBox isLineBreaksText = (CheckBox) inflate.findViewById(R.id.isLineBreaksText);
isLineBreaksText.setChecked(AppState.get().isLineBreaksText);
isLineBreaksText.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isLineBreaksText = isChecked;
}
});
isLineBreaksText.setVisibility(BookType.TXT.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
//
TextView moreSettings = (TextView) inflate.findViewById(R.id.moreSettings);
moreSettings.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.moreSettingsDiv).setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
// View moreSettingsImage =
// inflate.findViewById(R.id.moreSettingsImage);
// moreSettingsImage.setVisibility(controller.isTextFormat() ?
// View.VISIBLE : View.GONE);
TxtUtils.underlineTextView(moreSettings).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
moreBookSettings(anchor, controller, onRefresh, updateUIRefresh);
}
});
TextView performanceSettings = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.performanceSettigns));
performanceSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
performanceSettings(anchor, controller, onRefresh, updateUIRefresh);
}
});
TextView statusBarSettings = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.statusBarSettings));
statusBarSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
statusBarSettings(anchor, controller, onRefresh, updateUIRefresh);
}
});
final CustomSeek fontSizeSp = (CustomSeek) inflate.findViewById(R.id.fontSizeSp);
fontSizeSp.init(10, 70, AppState.get().fontSizeSp);
fontSizeSp.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
AppState.get().fontSizeSp = result;
return false;
}
});
fontSizeSp.setValueText("" + AppState.get().fontSizeSp);
inflate.findViewById(R.id.fontSizeLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.fontNameSelectionLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
final TextView textFontName = (TextView) inflate.findViewById(R.id.textFontName);
textFontName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final List<FontPack> fontPacks = BookCSS.get().getAllFontsPacks();
MyPopupMenu popup = new MyPopupMenu(controller.getActivity(), v);
for (final FontPack pack : fontPacks) {
LOG.d("pack.normalFont", pack.normalFont);
popup.getMenu().add(pack.dispalyName, pack.normalFont).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
BookCSS.get().resetAll(pack);
TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
return false;
}
});
}
popup.show();
}
});
TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
final View moreFontSettings = inflate.findViewById(R.id.moreFontSettings);
moreFontSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FontDialog.show(controller.getActivity(), new Runnable() {
@Override
public void run() {
TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
}
});
}
});
final View downloadFonts = inflate.findViewById(R.id.downloadFonts);
downloadFonts.setVisibility(FontExtractor.hasZipFonts() ? View.GONE : View.VISIBLE);
downloadFonts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FontExtractor.showDownloadFontsDialog(controller.getActivity(), downloadFonts, textFontName);
}
});
// crop
CheckBox isCropBorders = (CheckBox) inflate.findViewById(R.id.isCropBorders);
isCropBorders.setChecked(controller.isCropCurrentBook());
isCropBorders.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
controller.onCrop();
}
});
// volume
final CheckBox isReverseKyes = (CheckBox) inflate.findViewById(R.id.isReverseKyes);
isReverseKyes.setChecked(AppState.get().isReverseKeys);
isReverseKyes.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isReverseKeys = isChecked;
}
});
isReverseKyes.setEnabled(AppState.get().isUseVolumeKeys ? true : false);
CheckBox isUseVolumeKeys = (CheckBox) inflate.findViewById(R.id.isUseVolumeKeys);
isUseVolumeKeys.setChecked(AppState.get().isUseVolumeKeys);
isUseVolumeKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isUseVolumeKeys = isChecked;
isReverseKyes.setEnabled(AppState.get().isUseVolumeKeys ? true : false);
}
});
// orientation begin
final TextView screenOrientation = (TextView) inflate.findViewById(R.id.screenOrientation);
screenOrientation.setText(DocumentController.getRotationText());
TxtUtils.underlineTextView(screenOrientation);
screenOrientation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu menu = new PopupMenu(v.getContext(), v);
for (int i = 0; i < DocumentController.orientationIds.size(); i++) {
final int j = i;
final int name = DocumentController.orientationTexts.get(i);
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().orientation = DocumentController.orientationIds.get(j);
screenOrientation.setText(DocumentController.orientationTexts.get(j));
TxtUtils.underlineTextView(screenOrientation);
DocumentController.doRotation(controller.getActivity());
return false;
}
});
}
menu.show();
}
});
// orientation end
BrightnessHelper.showBlueLigthDialogAndBrightness(controller.getActivity(), inflate, onRefresh);
// brightness end
// dicts
final TextView selectedDictionaly = (TextView) inflate.findViewById(R.id.selectedDictionaly);
selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
selectedDictionaly.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DialogTranslateFromTo.show(controller.getActivity(), new Runnable() {
@Override
public void run() {
selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
}
});
}
});
((CheckBox) inflate.findViewById(R.id.isRememberDictionary)).setChecked(AppState.get().isRememberDictionary);
((CheckBox) inflate.findViewById(R.id.isRememberDictionary)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isRememberDictionary = isChecked;
}
});
// Colors
TextView textCustomizeFontBGColor = (TextView) inflate.findViewById(R.id.textCustomizeFontBGColor);
if (AppState.get().isCustomizeBgAndColors || controller.isTextFormat()) {
textCustomizeFontBGColor.setText(R.string.customize_font_background_colors);
} else {
textCustomizeFontBGColor.setText(R.string.customize_background_color);
}
final ImageView onDayColorImage = (ImageView) inflate.findViewById(R.id.onDayColorImage);
final TextView textDayColor = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDayColor));
textDayColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isSolid = !AppState.get().isUseBGImageDay;
new ColorsDialog((FragmentActivity) controller.getActivity(), true, AppState.get().colorDayText, AppState.get().colorDayBg, false, isSolid, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
textDayColor.setTextColor(colorText);
textDayColor.setBackgroundColor(colorBg);
TintUtil.setTintImageWithAlpha(onDayColorImage, colorText);
AppState.get().colorDayText = colorText;
AppState.get().colorDayBg = colorBg;
ImageLoader.getInstance().clearDiskCache();
ImageLoader.getInstance().clearMemoryCache();
if (AppState.get().isUseBGImageDay) {
textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(true));
}
}
});
}
});
final ImageView onNigthColorImage = (ImageView) inflate.findViewById(R.id.onNigthColorImage);
final TextView textNigthColor = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onNigthColor));
textNigthColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isSolid = !AppState.get().isUseBGImageNight;
new ColorsDialog((FragmentActivity) controller.getActivity(), false, AppState.get().colorNigthText, AppState.get().colorNigthBg, false, isSolid, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
textNigthColor.setTextColor(colorText);
textNigthColor.setBackgroundColor(colorBg);
TintUtil.setTintImageWithAlpha(onNigthColorImage, colorText);
AppState.get().colorNigthText = colorText;
AppState.get().colorNigthBg = colorBg;
if (AppState.get().isUseBGImageNight) {
textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(true));
}
}
});
}
});
final LinearLayout lc = (LinearLayout) inflate.findViewById(R.id.preColors);
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
textNigthColor.setTextColor(AppState.get().colorNigthText);
textNigthColor.setBackgroundColor(AppState.get().colorNigthBg);
textDayColor.setTextColor(AppState.get().colorDayText);
textDayColor.setBackgroundColor(AppState.get().colorDayBg);
if (AppState.get().isUseBGImageDay) {
textDayColor.setTextColor(Color.BLACK);
textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(true));
}
if (AppState.get().isUseBGImageNight) {
textNigthColor.setTextColor(Color.WHITE);
textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(true));
}
// lc.setVisibility(controller.isTextFormat() ||
// AppState.get().isCustomizeBgAndColors ? View.VISIBLE :
// View.GONE);
final int padding = Dips.dpToPx(3);
final Runnable colorsLine = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
lc.removeAllViews();
for (String line : AppState.get().readColors.split(";")) {
if (TxtUtils.isEmpty(line)) {
continue;
}
String[] split = line.split(",");
LOG.d("Split colors", split[0], split[1], split[2]);
String name = split[0];
final int bg = Color.parseColor(split[1]);
final int text = Color.parseColor(split[2]);
final boolean isDay = split[3].equals("0");
BorderTextView t1 = new BorderTextView(controller.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
params.setMargins(padding, padding, padding, padding);
t1.setLayoutParams(params);
t1.setGravity(Gravity.CENTER);
t1.setBackgroundColor(bg);
if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
t1.setText(name);
t1.setTextColor(text);
t1.setTypeface(null, Typeface.BOLD);
}
t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isDay) {
if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
AppState.get().colorDayText = text;
textDayColor.setTextColor(text);
}
AppState.get().colorDayBg = bg;
textDayColor.setBackgroundColor(bg);
AppState.get().isUseBGImageDay = false;
} else {
if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
AppState.get().colorNigthText = text;
textNigthColor.setTextColor(text);
}
AppState.get().colorNigthBg = bg;
textNigthColor.setBackgroundColor(bg);
AppState.get().isUseBGImageNight = false;
}
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
}
});
lc.addView(t1);
}
// add DayBG
{
ImageView t1 = new ImageView(controller.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
params.setMargins(padding, padding, padding, padding);
t1.setLayoutParams(params);
t1.setScaleType(ScaleType.FIT_XY);
t1.setImageDrawable(MagicHelper.getBgImageDayDrawable(false));
t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
textDayColor.setTextColor(Color.BLACK);
textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(false));
AppState.get().isUseBGImageDay = true;
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
}
});
lc.addView(t1, AppState.get().readColors.split(";").length / 2);
}
// add Night
{
ImageView t2 = new ImageView(controller.getActivity());
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
params2.setMargins(padding, padding, padding, padding);
t2.setLayoutParams(params2);
t2.setScaleType(ScaleType.FIT_XY);
t2.setImageDrawable(MagicHelper.getBgImageNightDrawable(false));
t2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().colorNigthText = AppState.COLOR_WHITE;
AppState.get().colorNigthBg = AppState.COLOR_BLACK;
textNigthColor.setTextColor(Color.WHITE);
textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(false));
AppState.get().isUseBGImageNight = true;
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
}
});
lc.addView(t2);
}
}
};
colorsLine.run();
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDefaultColor)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog(controller.getActivity(), controller.getString(R.string.restore_defaults_full), new Runnable() {
@Override
public void run() {
AppState.get().readColors = AppState.READ_COLORS_DEAFAUL;
AppState.get().isUseBGImageDay = false;
AppState.get().isUseBGImageNight = false;
AppState.get().bgImageDayTransparency = AppState.DAY_TRANSPARENCY;
AppState.get().bgImageDayPath = MagicHelper.IMAGE_BG_1;
AppState.get().bgImageNightTransparency = AppState.NIGHT_TRANSPARENCY;
AppState.get().bgImageNightPath = MagicHelper.IMAGE_BG_1;
AppState.get().isCustomizeBgAndColors = false;
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
textDayColor.setTextColor(AppState.COLOR_BLACK);
textDayColor.setBackgroundColor(AppState.COLOR_WHITE);
AppState.get().colorNigthText = AppState.COLOR_WHITE;
AppState.get().colorNigthBg = AppState.COLOR_BLACK;
textNigthColor.setTextColor(AppState.COLOR_WHITE);
textNigthColor.setBackgroundColor(AppState.COLOR_BLACK);
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
AppState.get().statusBarColorDay = AppState.TEXT_COLOR_DAY;
AppState.get().statusBarColorNight = AppState.TEXT_COLOR_NIGHT;
colorsLine.run();
}
});
}
});
inflate.findViewById(R.id.moreReadColorSettings).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(controller.getActivity());
builder.setTitle(R.string.customize);
final LinearLayout root = new LinearLayout(controller.getActivity());
root.setOrientation(LinearLayout.VERTICAL);
for (String line : AppState.get().readColors.split(";")) {
if (TxtUtils.isEmpty(line)) {
continue;
}
final String[] split = line.split(",");
LOG.d("Split colors", split[0], split[1], split[2]);
final String name = split[0];
final int bg = Color.parseColor(split[1]);
final int text = Color.parseColor(split[2]);
final boolean isDay = split[3].equals("0");
final LinearLayout child = new LinearLayout(controller.getActivity());
child.setOrientation(LinearLayout.HORIZONTAL);
child.setTag(line);
final TextView t1Img = new TextView(controller.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(60), Dips.dpToPx(30));
params.setMargins(padding, padding, padding, padding);
t1Img.setLayoutParams(params);
t1Img.setGravity(Gravity.CENTER);
t1Img.setBackgroundColor(bg);
t1Img.setText(name);
t1Img.setTextColor(text);
t1Img.setTypeface(null, Typeface.BOLD);
t1Img.setTag(isDay);
TextView t0 = new TextView(controller.getActivity());
t0.setEms(1);
TextView t00 = new TextView(controller.getActivity());
t00.setEms(2);
final TextView t2BG = new TextView(controller.getActivity());
t2BG.setText(TxtUtils.underline(split[1]));
t2BG.setEms(5);
t2BG.setTag(bg);
final TextView t3Text = new TextView(controller.getActivity());
t3Text.setText(TxtUtils.underline(split[2]));
t3Text.setEms(5);
t3Text.setTag(text);
child.addView(t0);
child.addView(t1Img);
child.addView(t00);
child.addView(t2BG);
child.addView(t3Text);
child.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new ColorsDialog((FragmentActivity) controller.getActivity(), (Boolean) t1Img.getTag(), (Integer) t3Text.getTag(), (Integer) t2BG.getTag(), true, true, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
t1Img.setTextColor(colorText);
t1Img.setBackgroundColor(colorBg);
t2BG.setText(TxtUtils.underline(MagicHelper.colorToString(colorBg)));
t3Text.setText(TxtUtils.underline(MagicHelper.colorToString(colorText)));
t2BG.setTag(colorBg);
t3Text.setTag(colorText);
String line = name + "," + MagicHelper.colorToString(colorBg) + "," + MagicHelper.colorToString(colorText) + "," + split[3];
child.setTag(line);
}
});
}
});
root.addView(child);
}
builder.setView(root);
builder.setNegativeButton(R.string.apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String res = "";
for (int i = 0; i < root.getChildCount(); i++) {
View childAt = root.getChildAt(i);
String line = (String) childAt.getTag();
res = res + line + ";";
}
AppState.get().readColors = res;
LOG.d("SAVE readColors", AppState.get().readColors);
colorsLine.run();
}
});
builder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
}
});
return inflate;
}
}.show(DragingPopup.PREF + "_preferences").setOnCloseListener(new Runnable() {
@Override
public void run() {
if (//
//
appHash != Objects.hashCode(AppState.get()) || (controller.isTextFormat() && cssHash != BookCSS.get().toCssString().hashCode())) {
if (onRefresh != null) {
onRefresh.run();
}
controller.restartActivity();
}
}
});
return dialog;
}
use of com.foobnix.pdf.search.activity.msg.InvalidateMessage in project LibreraReader by foobnix.
the class DragingDialogs method sliceDialog.
public static void sliceDialog(final FrameLayout anchor, final DocumentController controller, final Runnable onRefreshDoc, final ResultResponse<Integer> onMoveCut) {
new DragingPopup(anchor.getContext().getString(R.string.split_pages_in_two), anchor, 300, 200) {
SeekBar seek;
EditText editPercent;
Runnable updateUI = new Runnable() {
@Override
public void run() {
seek.setProgress(AppState.get().cutP);
editPercent.setText(AppState.get().cutP + "%");
if (onMoveCut != null) {
onMoveCut.onResultRecive(AppState.get().cutP);
}
PageImageState.get().isShowCuttingLine = true;
}
};
@Override
public View getContentView(LayoutInflater inflater) {
PageImageState.get().isShowCuttingLine = false;
View view = inflater.inflate(R.layout.slice_dialog, null, false);
editPercent = (EditText) view.findViewById(R.id.editPercent);
seek = (SeekBar) view.findViewById(R.id.seekBar);
seek.setMax(100);
view.findViewById(R.id.imagePlus).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (AppState.get().cutP < 80) {
AppState.get().cutP += 1;
}
updateUI.run();
}
});
view.findViewById(R.id.imageMinus).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (AppState.get().cutP > 20) {
AppState.get().cutP -= 1;
}
updateUI.run();
}
});
seek.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 (progress <= 20) {
progress = 20;
}
if (progress >= 80) {
progress = 80;
}
AppState.get().cutP = progress;
updateUI.run();
}
});
Button buttonCancel = (Button) view.findViewById(R.id.buttonCancel);
buttonCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PageImageState.get().isShowCuttingLine = false;
AppState.get().isCut = false;
BookSettings bookSettings = SettingsManager.getBookSettings(controller.getCurrentBook().getPath());
boolean wasSplit = bookSettings.splitPages;
bookSettings.splitPages = false;
onRefreshDoc.run();
closeDialog();
if (wasSplit) {
controller.onGoToPage(controller.getCurentPage() / 2 + 1);
}
}
});
Button buttonApply = (Button) view.findViewById(R.id.buttonApply);
buttonApply.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PageImageState.get().isShowCuttingLine = false;
AppState.get().isCut = true;
AppState.get().isCrop = false;
boolean init = SettingsManager.getBookSettings().splitPages;
SettingsManager.getBookSettings().updateFromAppState();
onRefreshDoc.run();
closeDialog();
if (!init) {
controller.onGoToPage(controller.getCurentPage() * 2 + 1);
}
}
});
updateUI.run();
return view;
}
}.show("cutDialog").setOnCloseListener(new Runnable() {
@Override
public void run() {
PageImageState.get().isShowCuttingLine = false;
EventBus.getDefault().post(new InvalidateMessage());
}
});
}
use of com.foobnix.pdf.search.activity.msg.InvalidateMessage in project LibreraReader by foobnix.
the class HorizontalModeController method clearSelectedText.
@Override
public void clearSelectedText() {
AppState.get().selectedText = null;
PageImageState.get().cleanSelectedWords();
EventBus.getDefault().post(new InvalidateMessage());
}
use of com.foobnix.pdf.search.activity.msg.InvalidateMessage in project LibreraReader by foobnix.
the class HorizontalModeController method doSearch.
@Override
public void doSearch(final String text, final com.foobnix.android.utils.ResultResponse<Integer> result) {
if (searchTask != null && searchTask.getStatus() != CopyAsyncTask.Status.FINISHED) {
return;
}
searchTask = new CopyAsyncTask() {
@Override
protected Object doInBackground(Object... params) {
try {
PageImageState.get().cleanSelectedWords();
String textLowCase = text.toLowerCase(Locale.US);
String bookPath = getBookPath();
int prev = -1;
boolean nextWorld = false;
String firstPart = "";
TextWord firstWord = null;
for (int i = 0; i < getPageCount(); i++) {
if (!TempHolder.isSeaching) {
result.onResultRecive(Integer.MAX_VALUE);
return null;
}
if (isClosed) {
TempHolder.isSeaching = false;
return null;
}
if (i > 1) {
result.onResultRecive(i * -1);
}
TextWord[][] pageText = getPageText(i);
recyclePage(i);
if (pageText == null) {
continue;
}
int index = 0;
List<TextWord> find = new ArrayList<TextWord>();
for (TextWord[] line : pageText) {
find.clear();
index = 0;
for (TextWord word : line) {
if (AppState.get().selectingByLetters) {
String it = String.valueOf(textLowCase.charAt(index));
if (word.w.toLowerCase(Locale.US).equals(it)) {
index++;
find.add(word);
} else {
index = 0;
find.clear();
}
if (index == text.length()) {
index = 0;
if (prev != i) {
result.onResultRecive(i);
prev = i;
}
for (TextWord t : find) {
PageImageState.get().addWord(i, t);
}
}
} else if (word.w.toLowerCase(Locale.US).contains(textLowCase)) {
LOG.d("Contains 1", word.w);
if (prev != i) {
result.onResultRecive(i);
prev = i;
}
PageImageState.get().addWord(i, word);
} else if (word.w.length() >= 3 && word.w.endsWith("-")) {
nextWorld = true;
firstWord = word;
firstPart = word.w.replace("-", "");
} else if (nextWorld && (firstPart + word.w.toLowerCase(Locale.US)).contains(text)) {
LOG.d("Contains 2", firstPart, word.w, text);
PageImageState.get().addWord(i, firstWord);
PageImageState.get().addWord(i, word);
nextWorld = false;
firstWord = null;
firstPart = "";
if (prev != i) {
result.onResultRecive(i);
prev = i;
}
} else if (nextWorld && TxtUtils.isNotEmpty(word.w)) {
nextWorld = false;
firstWord = null;
}
}
}
}
result.onResultRecive(-1);
} catch (Exception e) {
result.onResultRecive(-1);
}
TempHolder.isSeaching = false;
return null;
}
@Override
protected void onPostExecute(Object result) {
EventBus.getDefault().post(new InvalidateMessage());
}
}.execute();
}
Aggregations