use of com.foobnix.ui2.MainTabs2 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.ui2.MainTabs2 in project LibreraReader by foobnix.
the class FileMetaAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holderAll, final int position) {
final FileMeta fileMeta = getItem(position);
if (holderAll instanceof StarsTitleViewHolder) {
final StarsTitleViewHolder holder = (StarsTitleViewHolder) holderAll;
if (holder.clearAllFolders != null) {
TxtUtils.underlineTextView(holder.clearAllFolders).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearAllStarredFolders.run();
}
});
}
if (holder.clearAllBooks != null) {
TxtUtils.underlineTextView(holder.clearAllBooks).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearAllStarredBooks.run();
}
});
}
if (holder.onGridList != null) {
PopupHelper.updateGridOrListIcon(holder.onGridList, AppState.get().starsMode);
holder.onGridList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onGridOrList.onResultRecive(holder.onGridList);
}
});
}
TintUtil.setBackgroundFillColor(holder.parent, TintUtil.color);
}
if (holderAll instanceof FileMetaViewHolder) {
final FileMetaViewHolder holder = (FileMetaViewHolder) holderAll;
if (!AppState.get().isShowImages && adapterType == ADAPTER_COVERS) {
adapterType = ADAPTER_GRID;
}
bindFileMetaView(holder, position);
IMG.getCoverPageWithEffect(holder.image, fileMeta.getPath(), IMG.getImageSize(), new SimpleImageLoadingListener() {
@Override
public void onLoadingCancelled(String imageUri, View view) {
super.onLoadingCancelled(imageUri, view);
}
@Override
public void onLoadingStarted(String imageUri, View view) {
super.onLoadingStarted(imageUri, view);
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
if (position <= items.size() - 1) {
FileMeta it = AppDB.get().load(fileMeta.getPath());
if (it != null) {
items.set(position, it);
bindFileMetaView(holder, position);
}
}
}
});
holder.imageParent.setVisibility(AppState.get().isShowImages ? View.VISIBLE : View.GONE);
} else if (holderAll instanceof TagViewHolder) {
final TagViewHolder holder = (TagViewHolder) holderAll;
holder.title.setText(fileMeta.getPathTxt());
TintUtil.setTintImageWithAlpha(holder.image);
bindItemClickAndLongClickListeners(holder.parent, fileMeta);
} else if (holderAll instanceof DirectoryViewHolder) {
final DirectoryViewHolder holder = (DirectoryViewHolder) holderAll;
holder.title.setText(fileMeta.getPathTxt());
holder.path.setText(fileMeta.getPath());
TintUtil.setTintImageWithAlpha(holder.image, holder.image.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
bindItemClickAndLongClickListeners(holder.parent, fileMeta);
if (!AppState.get().isBorderAndShadow) {
holder.parent.setBackgroundColor(Color.TRANSPARENT);
}
if (AppDB.get().isStarFolder(fileMeta.getPath())) {
holder.starIcon.setImageResource(R.drawable.star_1);
} else {
holder.starIcon.setImageResource(R.drawable.star_2);
}
TintUtil.setTintImageWithAlpha(holder.starIcon, holder.starIcon.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
if (onStarClickListener != null) {
holder.starIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
}
});
}
holder.starIcon.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
// holder.image.setVisibility(View.GONE);
holder.path.setVisibility(View.GONE);
} else {
// holder.image.setVisibility(View.VISIBLE);
if (tempValue == TEMP_VALUE_FOLDER_PATH) {
holder.path.setVisibility(View.VISIBLE);
} else {
holder.path.setVisibility(View.GONE);
}
}
} else if (holderAll instanceof StarsLayoutViewHolder) {
final StarsLayoutViewHolder holder = (StarsLayoutViewHolder) holderAll;
final FileMetaAdapter adapter = new FileMetaAdapter();
adapter.setOnItemClickListener(onItemClickListener);
adapter.setOnItemLongClickListener(onItemLongClickListener);
adapter.setOnMenuClickListener(onMenuClickListener);
adapter.setOnStarClickListener(onStarClickListener);
adapter.setOnAuthorClickListener(onAuthorClickListener);
adapter.setOnSeriesClickListener(onSeriesClickListener);
adapter.setAdapterType(FileMetaAdapter.ADAPTER_GRID);
adapter.tempValue = TEMP_VALUE_STAR_GRID_ITEM;
holder.recyclerView.setAdapter(adapter);
adapter.getItemsList().clear();
TintUtil.setBackgroundFillColor(holder.panelRecent, TintUtil.color);
TintUtil.setBackgroundFillColor(holder.panelStars, TintUtil.color);
List<FileMeta> allStars = AppDB.get().getStarsFiles();
final String STARRED = holder.starredName.getContext().getString(R.string.starred).toUpperCase(Locale.US) + " (" + allStars.size() + ")";
holder.recentName.setText(holder.starredName.getContext().getString(R.string.recent) + " (" + (getItemCount() - 1) + ")");
holder.starredNameIcon.setImageResource(R.drawable.star_1);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underlineTextView(holder.starredName);
holder.starredName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
MyPopupMenu menu = new MyPopupMenu(v.getContext(), v);
menu.getMenu().add(STARRED).setIcon(R.drawable.star_1).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().recentTag = "";
holder.starredNameIcon.setImageResource(R.drawable.star_1);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underline(holder.starredName, STARRED);
adapter.getItemsList().clear();
List<FileMeta> allStars = AppDB.get().getStarsFiles();
adapter.getItemsList().addAll(allStars);
adapter.notifyDataSetChanged();
return false;
}
});
List<String> tags = AppDB.get().getAll(SEARCH_IN.TAGS);
Collections.sort(tags);
for (final String tag : tags) {
int count = AppDB.get().getAllWithTag(tag).size();
final String nameName = tag + " (" + count + ")";
menu.getMenu().add(nameName).setIcon(R.drawable.glyphicons_67_tags).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().recentTag = tag;
holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underline(holder.starredName, nameName);
adapter.getItemsList().clear();
List<FileMeta> allTags = AppDB.get().searchBy("@tags " + tag, SORT_BY.FILE_NAME, false);
adapter.getItemsList().addAll(allTags);
adapter.notifyDataSetChanged();
return false;
}
});
}
menu.show();
}
});
if (TxtUtils.isEmpty(AppState.get().recentTag)) {
holder.starredNameIcon.setImageResource(R.drawable.star_1);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underline(holder.starredName, STARRED);
adapter.getItemsList().clear();
adapter.getItemsList().addAll(allStars);
adapter.notifyDataSetChanged();
} else {
holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
adapter.getItemsList().clear();
List<FileMeta> allTags = AppDB.get().searchBy("@tags " + AppState.get().recentTag, SORT_BY.FILE_NAME, false);
adapter.getItemsList().addAll(allTags);
adapter.notifyDataSetChanged();
TxtUtils.underline(holder.starredName, AppState.get().recentTag + " (" + allTags.size() + ")");
}
} else if (holderAll instanceof AuthorViewHolder) {
AuthorViewHolder aHolder = (AuthorViewHolder) holderAll;
aHolder.onBindViewHolder(aHolder, fileMeta.getSequence());
aHolder.parent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onSeriesClickListener != null) {
onSeriesClickListener.onResultRecive(fileMeta.getSequence());
}
}
});
}
}
use of com.foobnix.ui2.MainTabs2 in project LibreraReader by foobnix.
the class FileMetaAdapter method bindFileMetaView.
private FileMeta bindFileMetaView(final FileMetaViewHolder holder, final int position) {
if (position >= items.size()) {
return new FileMeta();
}
final FileMeta fileMeta = getItem(position);
if (fileMeta == null) {
return new FileMeta();
}
holder.title.setText(fileMeta.getTitle());
holder.author.setText(fileMeta.getAuthor());
if (AppState.get().isUiTextColor) {
TintUtil.setUITextColor(holder.author, AppState.get().uiTextColor);
TintUtil.setUITextColor(holder.series, AppState.get().uiTextColor);
}
if (TxtUtils.isEmpty(fileMeta.getAuthor())) {
if (adapterType == ADAPTER_GRID) {
holder.author.setVisibility(View.INVISIBLE);
} else {
holder.author.setVisibility(View.GONE);
}
} else {
holder.author.setVisibility(View.VISIBLE);
}
if (holder.series != null && onSeriesClickListener != null) {
String sequence = fileMeta.getSequence();
holder.series.setVisibility(TxtUtils.isNotEmpty(sequence) ? View.VISIBLE : View.GONE);
holder.series.setText(sequence);
holder.series.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onSeriesClickListener != null) {
onSeriesClickListener.onResultRecive(fileMeta.getSequence());
}
}
});
}
holder.author.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onAuthorClickListener != null) {
onAuthorClickListener.onResultRecive(fileMeta.getAuthor());
}
}
});
if (holder.tags != null) {
if (TxtUtils.isNotEmpty(fileMeta.getTag())) {
holder.tags.setVisibility(View.VISIBLE);
holder.tags.removeAllViews();
for (final String tag : StringDB.asList(fileMeta.getTag())) {
TextView t = new TextView(holder.tags.getContext());
t.setTextAppearance(holder.tags.getContext(), R.style.textLink);
TxtUtils.bold(t);
t.setText(tag + " ");
t.setTextSize(12);
t.setGravity(Gravity.CENTER_VERTICAL);
TypedValue outValue = new TypedValue();
holder.tags.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
t.setBackgroundResource(outValue.resourceId);
if (AppState.get().isUiTextColor) {
TintUtil.setUITextColor(t, AppState.get().uiTextColor);
}
t.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onTagClickListner != null) {
onTagClickListner.onResultRecive(tag);
}
}
});
t.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {
@Override
public void run() {
notifyDataSetChanged();
}
});
return true;
}
});
holder.tags.addView(t);
}
} else {
holder.tags.setVisibility(View.GONE);
}
}
holder.path.setText(fileMeta.getPathTxt());
holder.browserExt.setText(fileMeta.getChild() != null ? fileMeta.getChild() : fileMeta.getExt());
if (fileMeta.getPages() != null && fileMeta.getPages() != 0) {
holder.size.setText(fileMeta.getSizeTxt() + " (" + fileMeta.getPages() + ")");
} else {
holder.size.setText(fileMeta.getSizeTxt());
}
if (holder.date != null) {
holder.date.setText(fileMeta.getDateTxt());
}
double recentProgress = fileMeta.getIsRecentProgress() == null ? 0 : fileMeta.getIsRecentProgress();
if (holder.idProgressColor != null && recentProgress > 0) {
holder.progresLayout.setVisibility(View.VISIBLE);
holder.idPercentText.setVisibility(View.VISIBLE);
holder.idProgressColor.setBackgroundColor(TintUtil.color);
int width = adapterType == ADAPTER_LIST_COMPACT ? Dips.dpToPx(100) : Dips.dpToPx(200);
holder.idProgressBg.getLayoutParams().width = width;
holder.idProgressColor.getLayoutParams().width = (int) (width * recentProgress);
holder.idProgressColor.setLayoutParams(holder.idProgressColor.getLayoutParams());
holder.idPercentText.setText("" + Math.round(100f * recentProgress) + "%");
} else if (holder.progresLayout != null) {
holder.progresLayout.setVisibility(View.INVISIBLE);
holder.idPercentText.setVisibility(View.INVISIBLE);
}
if (adapterType == ADAPTER_GRID && recentProgress > 0) {
holder.idPercentText.setText("" + (int) (100 * recentProgress) + "%");
if (AppState.get().coverBigSize < IMG.TWO_LINE_COVER_SIZE) {
holder.browserExt.setVisibility(View.GONE);
} else {
holder.browserExt.setVisibility(View.VISIBLE);
}
} else if (adapterType == ADAPTER_GRID) {
holder.idPercentText.setText("");
holder.browserExt.setVisibility(View.VISIBLE);
}
if (fileMeta.getIsStar() == null || fileMeta.getIsStar() == false) {
holder.star.setImageResource(R.drawable.star_2);
} else {
holder.star.setImageResource(R.drawable.star_1);
}
TintUtil.setTintImageWithAlpha(holder.star, holder.parent.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
if (onStarClickListener != null) {
holder.star.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
}
});
holder.star.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {
@Override
public void run() {
notifyDataSetChanged();
}
});
return true;
}
});
} else {
}
holder.star.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
if (holder.signIcon != null) {
holder.signIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {
@Override
public void run() {
TintUtil.setTintImageWithAlpha(holder.signIcon, TxtUtils.isEmpty(fileMeta.getTag()) ? TintUtil.COLOR_TINT_GRAY : TintUtil.color);
}
});
}
});
TintUtil.setTintImageWithAlpha(holder.signIcon, TxtUtils.isEmpty(fileMeta.getTag()) ? TintUtil.COLOR_TINT_GRAY : TintUtil.color);
}
bindItemClickAndLongClickListeners(holder.parent, fileMeta);
if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
holder.path.setVisibility(View.GONE);
holder.size.setVisibility(View.GONE);
int sizeDP = AppState.get().coverBigSize;
if (tempValue == TEMP_VALUE_STAR_GRID_ITEM) {
sizeDP = Math.max(80, AppState.get().coverSmallSize);
}
IMG.updateImageSizeBig((View) holder.image.getParent().getParent(), sizeDP);
LayoutParams lp = holder.image.getLayoutParams();
lp.width = Dips.dpToPx(sizeDP);
if (AppState.get().isCropBookCovers) {
lp.height = (int) (lp.width * IMG.WIDTH_DK);
} else {
lp.width = LayoutParams.WRAP_CONTENT;
lp.height = LayoutParams.WRAP_CONTENT;
}
} else {
holder.path.setVisibility(View.VISIBLE);
holder.size.setVisibility(View.VISIBLE);
IMG.updateImageSizeSmall((View) holder.image.getParent().getParent());
LayoutParams lp = holder.image.getLayoutParams();
lp.width = Dips.dpToPx(AppState.get().coverSmallSize);
if (AppState.get().isCropBookCovers) {
lp.height = (int) (lp.width * IMG.WIDTH_DK);
} else {
lp.height = LayoutParams.WRAP_CONTENT;
}
}
if (holder.date != null) {
holder.date.setVisibility(View.VISIBLE);
holder.size.setVisibility(View.VISIBLE);
if (adapterType == ADAPTER_LIST_COMPACT) {
holder.date.setVisibility(View.GONE);
holder.size.setVisibility(View.GONE);
}
}
if (AppState.get().isBorderAndShadow) {
View parent = (View) holder.image.getParent();
parent.setBackgroundColor(Color.TRANSPARENT);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) parent.getLayoutParams();
layoutParams.setMargins(0, 0, 0, 0);
}
if (AppState.get().isCropBookCovers) {
holder.image.setScaleType(ScaleType.CENTER_CROP);
} else {
holder.image.setScaleType(ScaleType.FIT_CENTER);
}
if (holder.layoutBootom != null) {
if (adapterType == ADAPTER_COVERS) {
holder.layoutBootom.setVisibility(View.GONE);
holder.infoLayout.setVisibility(View.GONE);
} else {
holder.layoutBootom.setVisibility(View.VISIBLE);
holder.infoLayout.setVisibility(View.VISIBLE);
}
}
holder.authorParent.setVisibility(View.VISIBLE);
if (adapterType == ADAPTER_LIST || adapterType == ADAPTER_LIST_COMPACT) {
if (AppState.get().coverSmallSize >= IMG.TWO_LINE_COVER_SIZE) {
holder.title.setSingleLine(false);
holder.title.setLines(2);
holder.path.setVisibility(View.VISIBLE);
holder.title.setTextSize(16);
} else {
holder.title.setSingleLine(false);
holder.title.setLines(2);
holder.title.setTextSize(14);
holder.authorParent.setVisibility(View.GONE);
holder.path.setVisibility(View.GONE);
holder.infoLayout.setVisibility(View.VISIBLE);
holder.title.setText(fileMeta.getPathTxt());
}
}
TintUtil.setTintImageWithAlpha(holder.menu, holder.parent.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
if (holder.remove != null) {
holder.remove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onDeleteClickListener.onResultRecive(fileMeta);
}
});
if (onDeleteClickListener == null) {
holder.remove.setVisibility(View.GONE);
}
}
holder.menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onMenuClickListener != null) {
onMenuClickListener.onResultRecive(fileMeta);
}
}
});
holder.parent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onItemClickListener.onResultRecive(fileMeta);
}
});
holder.parent.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
onItemLongClickListener.onResultRecive(fileMeta);
return true;
}
});
if (!AppState.get().isBorderAndShadow) {
holder.parent.setBackgroundColor(Color.TRANSPARENT);
}
return fileMeta;
}
use of com.foobnix.ui2.MainTabs2 in project LibreraReader by foobnix.
the class MainTabs2 method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
if (AppState.get().isWhiteTheme) {
setTheme(R.style.StyledIndicatorsWhite);
} else {
setTheme(R.style.StyledIndicatorsBlack);
}
super.onCreate(savedInstanceState);
if (PasswordDialog.isNeedPasswordDialog(this)) {
return;
}
LOG.d(TAG, "onCreate");
LOG.d("EXTRA_EXIT", EXTRA_EXIT);
if (getIntent().getBooleanExtra(EXTRA_EXIT, false)) {
finish();
return;
}
isEink = Dips.isEInk(this);
TintUtil.setStatusBarColor(this);
DocumentController.doRotation(this);
setContentView(R.layout.main_tabs);
imageMenu = (ImageView) findViewById(R.id.imageMenu1);
imageMenuParent = findViewById(R.id.imageParent1);
imageMenuParent.setBackgroundColor(TintUtil.color);
overlay = findViewById(R.id.overlay);
toastBrightnessText = (TextView) findViewById(R.id.toastBrightnessText);
toastBrightnessText.setVisibility(View.GONE);
TintUtil.setDrawableTint(toastBrightnessText.getCompoundDrawables()[0], Color.WHITE);
tabFragments = new ArrayList<UIFragment>();
try {
for (UITab tab : UITab.getOrdered(AppState.get().tabsOrder)) {
if (tab.isVisible()) {
tabFragments.add(tab.getClazz().newInstance());
}
}
} catch (Exception e) {
LOG.e(e);
Toast.makeText(MainTabs2.this, R.string.msg_unexpected_error, Toast.LENGTH_LONG).show();
tabFragments.add(new SearchFragment2());
tabFragments.add(new BrowseFragment2());
tabFragments.add(new RecentFragment2());
tabFragments.add(new BookmarksFragment2());
tabFragments.add(new OpdsFragment2());
tabFragments.add(new PrefFragment2());
}
getSupportFragmentManager().beginTransaction().replace(R.id.left_drawer, new PrefFragment2()).commit();
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
imageMenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (drawerLayout.isDrawerOpen(Gravity.START))
drawerLayout.closeDrawer(Gravity.START, !AppState.get().isInkMode);
else
drawerLayout.openDrawer(Gravity.START, !AppState.get().isInkMode);
}
});
if (UITab.isShowPreferences()) {
imageMenu.setVisibility(View.GONE);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else {
imageMenu.setVisibility(View.VISIBLE);
}
// ((BrigtnessDraw)
// findViewById(R.id.brigtnessProgressView)).setActivity(this);
adapter = new TabsAdapter2(this, tabFragments);
pager = (ViewPager) findViewById(R.id.pager);
if (Android6.canWrite(this)) {
pager.setAdapter(adapter);
}
pager.setOffscreenPageLimit(5);
pager.addOnPageChangeListener(onPageChangeListener);
drawerLayout.addDrawerListener(new DrawerListener() {
@Override
public void onDrawerStateChanged(int arg0) {
}
@Override
public void onDrawerSlide(View arg0, float arg1) {
}
@Override
public void onDrawerOpened(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void onDrawerClosed(View arg0) {
tabFragments.get(pager.getCurrentItem()).onSelectFragment();
}
});
indicator = (SlidingTabLayout) findViewById(R.id.slidingTabs);
indicator.setViewPager(pager);
indicator.setDividerColors(getResources().getColor(R.color.tint_divider));
indicator.setSelectedIndicatorColors(Color.WHITE);
indicator.setBackgroundColor(TintUtil.color);
if (AppState.get().isInkMode) {
TintUtil.setTintImageNoAlpha(imageMenu, TintUtil.color);
indicator.setSelectedIndicatorColors(TintUtil.color);
indicator.setDividerColors(TintUtil.color);
indicator.setBackgroundColor(Color.TRANSPARENT);
imageMenuParent.setBackgroundColor(Color.TRANSPARENT);
}
Android6.checkPermissions(this);
// Analytics.onStart(this);
List<String> actions = Arrays.asList("android.intent.action.PROCESS_TEXT", "android.intent.action.SEARCH", "android.intent.action.SEND");
List<String> extras = Arrays.asList(Intent.EXTRA_PROCESS_TEXT_READONLY, Intent.EXTRA_PROCESS_TEXT, SearchManager.QUERY, Intent.EXTRA_TEXT);
if (getIntent() != null && getIntent().getAction() != null) {
if (actions.contains(getIntent().getAction())) {
for (String extra : extras) {
final String text = getIntent().getStringExtra(extra);
if (TxtUtils.isNotEmpty(text)) {
AppState.get().lastClosedActivity = null;
pager.postDelayed(new Runnable() {
@Override
public void run() {
((SearchFragment2) tabFragments.get(0)).searchAndOrderExteral(text);
}
}, 250);
break;
}
}
}
}
boolean showTabs = getIntent().getBooleanExtra(EXTRA_SHOW_TABS, false);
LOG.d("EXTRA_SHOW_TABS", showTabs, AppState.get().lastMode);
if (showTabs == false && AppState.get().isOpenLastBook) {
LOG.d("Open lastBookPath", AppState.get().lastBookPath);
if (AppState.get().lastBookPath == null || !new File(AppState.get().lastBookPath).isFile()) {
LOG.d("Open Last book not found");
return;
}
AppState.get().lastClosedActivity = null;
Safe.run(new Runnable() {
@Override
public void run() {
boolean isEasyMode = HorizontalViewActivity.class.getSimpleName().equals(AppState.get().lastMode);
Intent intent = new Intent(MainTabs2.this, isEasyMode ? HorizontalViewActivity.class : VerticalViewActivity.class);
intent.putExtra(PasswordDialog.EXTRA_APP_PASSWORD, getIntent().getStringExtra(PasswordDialog.EXTRA_APP_PASSWORD));
intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
startActivity(intent);
}
});
} else if (!AppState.get().isOpenLastBook) {
LOG.d("Open book lastA", AppState.get().lastClosedActivity);
if (AppState.get().lastBookPath == null || !new File(AppState.get().lastBookPath).isFile()) {
LOG.d("Open Last book not found");
return;
}
final String saveMode = AppState.get().lastClosedActivity;
Safe.run(new Runnable() {
@Override
public void run() {
if (HorizontalViewActivity.class.getSimpleName().equals(saveMode)) {
Intent intent = new Intent(MainTabs2.this, HorizontalViewActivity.class);
intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
startActivity(intent);
LOG.d("Start lastA", saveMode);
} else if (VerticalViewActivity.class.getSimpleName().equals(saveMode)) {
Intent intent = new Intent(MainTabs2.this, VerticalViewActivity.class);
intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
startActivity(intent);
LOG.d("Start lastA", saveMode);
}
}
});
} else {
RecentUpates.updateAll(this);
}
checkGoToPage(getIntent());
try {
AndroidWhatsNew.checkForNewBeta(this);
} catch (Exception e) {
LOG.e(e);
}
if (Android6.canWrite(this)) {
FontExtractor.extractFonts(this);
}
EventBus.getDefault().register(this);
}
use of com.foobnix.ui2.MainTabs2 in project LibreraReader by foobnix.
the class BrowseFragment2 method onCreateView.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_browse2, container, false);
Bundle arguments = getArguments();
pathContainer = view.findViewById(R.id.pathContainer);
View onCloseActionPaner = view.findViewById(R.id.onCloseActionPaner);
onClose = view.findViewById(R.id.onClose);
starIcon = (ImageView) view.findViewById(R.id.starIcon);
onSort = (ImageView) view.findViewById(R.id.onSort);
onSort.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AppState.get().sortByReverse = !AppState.get().sortByReverse;
onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
populate();
return true;
}
});
onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
onAction = view.findViewById(R.id.onAction);
editPath = (EditText) view.findViewById(R.id.editPath);
fragmentType = TYPE_DEFAULT;
if (arguments != null) {
fragmentType = arguments.getInt(EXTRA_TYPE, TYPE_DEFAULT);
fragmentText = arguments.getString(EXTRA_TEXT);
editPath.setText(fragmentText);
}
onClose.setOnClickListener(onCloseButtonActoin);
onAction.setOnClickListener(onSelectAction);
if (TYPE_DEFAULT == fragmentType) {
editPath.setVisibility(View.GONE);
onCloseActionPaner.setVisibility(View.GONE);
}
if (TYPE_SELECT_FOLDER == fragmentType) {
editPath.setVisibility(View.VISIBLE);
editPath.setEnabled(false);
onCloseActionPaner.setVisibility(View.VISIBLE);
}
if (TYPE_SELECT_FILE == fragmentType) {
editPath.setVisibility(View.VISIBLE);
editPath.setEnabled(false);
onCloseActionPaner.setVisibility(View.VISIBLE);
}
if (TYPE_CREATE_FILE == fragmentType) {
editPath.setVisibility(View.VISIBLE);
editPath.setEnabled(true);
onCloseActionPaner.setVisibility(View.VISIBLE);
}
View onBack = view.findViewById(R.id.onBack);
recyclerView = (FastScrollRecyclerView) view.findViewById(R.id.recyclerView);
paths = (LinearLayout) view.findViewById(R.id.paths);
scroller = (HorizontalScrollView) view.findViewById(R.id.scroller);
final View onHome = view.findViewById(R.id.onHome);
onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
onListGrid.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupMenu(onListGrid);
}
});
searchAdapter = new FileMetaAdapter();
bindAdapter(searchAdapter);
bindAuthorsSeriesAdapter(searchAdapter);
onGridList();
onHome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
List<String> extFolders = new ArrayList<String>();
extFolders = ExtUtils.getExternalStorageDirectories(getActivity());
String sdPath = ExtUtils.getSDPath();
if (TxtUtils.isNotEmpty(sdPath) && !extFolders.contains(sdPath)) {
extFolders.add(sdPath);
}
MyPopupMenu menu = new MyPopupMenu(getActivity(), onHome);
menu.getMenu().add(R.string.internal_storage).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(Environment.getExternalStorageDirectory().getPath());
return false;
}
}).setIcon(R.drawable.glyphicons_146_folder_sd1);
for (final String info : extFolders) {
String name;
if (ExtUtils.isExteralSD(info)) {
name = ExtUtils.getExtSDDisplayName(getContext(), info);
} else {
name = new File(info).getName();
}
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(info);
return false;
}
}).setIcon(R.drawable.glyphicons_146_folder_sd1);
}
menu.getMenu().add("Librera").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(AppState.get().downlodsPath);
return false;
}
}).setIcon(R.drawable.glyphicons_591_folder_heart);
if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
List<String> safs = StringDB.asList(AppState.get().pathSAF);
for (final String saf : safs) {
String fileName = DocumentsContract.getTreeDocumentId(Uri.parse(saf));
menu.getMenu().add(fileName).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(saf);
return false;
}
}).setOnMenuItemLongClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().pathSAF = StringDB.delete(AppState.get().pathSAF, saf);
return false;
}
}).setIcon(R.drawable.glyphicons_146_folder_plus);
}
}
// stars
List<FileMeta> starFolders = AppDB.get().getStarsFolder();
List<String> names = new ArrayList<String>();
for (FileMeta f : starFolders) {
names.add(f.getPath());
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
for (final String info : names) {
String name;
if (ExtUtils.isExteralSD(info)) {
name = ExtUtils.getExtSDDisplayName(getContext(), info);
} else {
name = new File(info).getName();
}
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(info);
return false;
}
}).setIcon(R.drawable.glyphicons_591_folder_star);
}
if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
menu.getMenu().add(R.string.add_resource).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(//
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | //
Intent.FLAG_GRANT_PREFIX_URI_PERMISSION | //
Intent.FLAG_GRANT_READ_URI_PERMISSION | //
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getActivity().startActivityForResult(intent, MainTabs2.REQUEST_CODE_ADD_RESOURCE);
return true;
}
}).setIcon(R.drawable.glyphicons_146_add_folder_plus);
}
menu.show();
}
});
onBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onBackAction();
}
});
searchAdapter.setOnItemClickListener(new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(FileMeta result) {
if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
setDirPath(result.getPath());
if (fragmentType == TYPE_SELECT_FOLDER) {
editPath.setText(fragmentText);
}
} else {
if (fragmentType == TYPE_DEFAULT) {
DefaultListeners.getOnItemClickListener(getActivity()).onResultRecive(result);
} else if (fragmentType == TYPE_SELECT_FILE) {
editPath.setText(ExtUtils.getFileName(result.getPath()));
}
}
return false;
}
});
searchAdapter.setOnItemLongClickListener(new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(FileMeta result) {
if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
// setDirPath(result.getPath());
} else {
DefaultListeners.getOnItemLongClickListener(getActivity(), searchAdapter).onResultRecive(result);
}
return false;
}
});
onSort.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
List<String> names = //
Arrays.asList(//
getActivity().getString(R.string.by_file_name), //
getActivity().getString(R.string.by_date), //
getActivity().getString(R.string.by_size), //
getActivity().getString(R.string.by_title), //
getActivity().getString(R.string.by_number_in_serie), //
getActivity().getString(R.string.by_number_of_pages), //
getActivity().getString(R.string.by_extension));
//
final List<Integer> ids = //
Arrays.asList(//
AppState.BR_SORT_BY_PATH, //
AppState.BR_SORT_BY_DATE, //
AppState.BR_SORT_BY_SIZE, //
AppState.BR_SORT_BY_TITLE, //
AppState.BR_SORT_BY_NUMBER, //
AppState.BR_SORT_BY_PAGES, //
AppState.BR_SORT_BY_EXT);
//
MyPopupMenu menu = new MyPopupMenu(getActivity(), v);
for (int i = 0; i < names.size(); i++) {
String name = names.get(i);
final int j = i;
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().sortByBrowse = ids.get(j);
populate();
return false;
}
});
}
menu.show();
}
});
populate();
onTintChanged();
return view;
}
Aggregations