use of android.widget.CompoundButton.OnCheckedChangeListener in project LibreraReader by foobnix.
the class DragingDialogs method performanceSettings.
public static DragingPopup performanceSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
AppState.get().saveIn(controller.getActivity());
final int cssHash = BookCSS.get().toCssString().hashCode();
final int appHash = Objects.hashCode(AppState.get());
DragingPopup dialog = new DragingPopup(R.string.advanced_settings, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public void beforeCreate() {
titleAction = controller.getString(R.string.preferences);
titleRunnable = new Runnable() {
@Override
public void run() {
if (appHash != Objects.hashCode(AppState.get())) {
AlertDialogs.showDialog(controller.getActivity(), controller.getString(R.string.you_neet_to_apply_the_new_settings), controller.getString(R.string.apply), new Runnable() {
@Override
public void run() {
closeDialog();
}
});
} else {
preferences(anchor, controller, onRefresh, updateUIRefresh);
}
}
};
}
@Override
public View getContentView(final LayoutInflater inflater) {
View inflate = inflater.inflate(R.layout.dialog_adv_preferences, null, false);
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 isScrollSpeedByVolumeKeys = (CheckBox) inflate.findViewById(R.id.isScrollSpeedByVolumeKeys);
isScrollSpeedByVolumeKeys.setChecked(AppState.get().isScrollSpeedByVolumeKeys);
isScrollSpeedByVolumeKeys.setVisibility(View.GONE);
isScrollSpeedByVolumeKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isScrollSpeedByVolumeKeys = isChecked;
}
});
CheckBox isBrighrnessEnable = (CheckBox) inflate.findViewById(R.id.isBrighrnessEnable);
isBrighrnessEnable.setChecked(AppState.get().isBrighrnessEnable);
isBrighrnessEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isBrighrnessEnable = isChecked;
}
});
CheckBox isShowLongBackDialog = (CheckBox) inflate.findViewById(R.id.isShowLongBackDialog);
isShowLongBackDialog.setChecked(AppState.get().isShowLongBackDialog);
isShowLongBackDialog.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isShowLongBackDialog = isChecked;
}
});
CheckBox isAllowTextSelection = (CheckBox) inflate.findViewById(R.id.isAllowTextSelection);
isAllowTextSelection.setChecked(AppState.get().isAllowTextSelection);
isAllowTextSelection.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isAllowTextSelection = isChecked;
if (isChecked) {
TempHolder.get().isAllowTextSelectionFirstTime = true;
}
}
});
CheckBox isZoomInOutWithVolueKeys = (CheckBox) inflate.findViewById(R.id.isZoomInOutWithVolueKeys);
isZoomInOutWithVolueKeys.setChecked(AppState.get().isZoomInOutWithVolueKeys);
isZoomInOutWithVolueKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isZoomInOutWithVolueKeys = isChecked;
}
});
final CustomSeek mouseWheelSpeed = (CustomSeek) inflate.findViewById(R.id.seekWheelSpeed);
mouseWheelSpeed.getTitleText().setSingleLine(false);
mouseWheelSpeed.init(1, 200, AppState.get().mouseWheelSpeed);
mouseWheelSpeed.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
AppState.get().mouseWheelSpeed = result;
return false;
}
});
CheckBox isScrollAnimation = (CheckBox) inflate.findViewById(R.id.isScrollAnimation);
isScrollAnimation.setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
isScrollAnimation.setChecked(AppState.get().isScrollAnimation);
isScrollAnimation.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isScrollAnimation = isChecked;
}
});
CheckBox isDisableSwipe = (CheckBox) inflate.findViewById(R.id.isDisableSwipe);
isDisableSwipe.setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
isDisableSwipe.setChecked(AppState.get().isDisableSwipe);
isDisableSwipe.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isDisableSwipe = isChecked;
}
});
CheckBox isVibration = (CheckBox) inflate.findViewById(R.id.isVibration);
isVibration.setChecked(AppState.get().isVibration);
isVibration.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isVibration = isChecked;
}
});
CheckBox isOLED = (CheckBox) inflate.findViewById(R.id.isOLED);
isOLED.setChecked(AppState.get().isOLED);
isOLED.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isOLED = isChecked;
}
});
CheckBox isLockPDF = (CheckBox) inflate.findViewById(R.id.isLockPDF);
isLockPDF.setChecked(AppState.get().isLockPDF);
isLockPDF.setVisibility(controller.isTextFormat() ? View.GONE : View.VISIBLE);
isLockPDF.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isLockPDF = isChecked;
}
});
CheckBox isCropPDF = (CheckBox) inflate.findViewById(R.id.isCropPDF);
isCropPDF.setChecked(AppState.get().isCropPDF);
isCropPDF.setVisibility(controller.isTextFormat() ? View.GONE : View.VISIBLE);
isCropPDF.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isCropPDF = isChecked;
}
});
CheckBox isCustomizeBgAndColors = (CheckBox) inflate.findViewById(R.id.isCustomizeBgAndColors);
isCustomizeBgAndColors.setVisibility(controller.isTextFormat() ? View.GONE : View.VISIBLE);
isCustomizeBgAndColors.setChecked(AppState.get().isCustomizeBgAndColors);
isCustomizeBgAndColors.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isCustomizeBgAndColors = isChecked;
}
});
final CheckBox isReplaceWhite = (CheckBox) inflate.findViewById(R.id.isReplaceWhite);
isReplaceWhite.setChecked(AppState.get().isReplaceWhite);
isReplaceWhite.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
isReplaceWhite.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isReplaceWhite = isChecked;
}
});
CheckBox isIgnoreAnnotatations = (CheckBox) inflate.findViewById(R.id.isIgnoreAnnotatations);
isIgnoreAnnotatations.setChecked(AppState.get().isIgnoreAnnotatations);
isIgnoreAnnotatations.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isIgnoreAnnotatations = isChecked;
}
});
isIgnoreAnnotatations.setVisibility(!AppState.get().isAlwaysOpenAsMagazine && BookType.PDF.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
CheckBox isSaveAnnotatationsAutomatically = (CheckBox) inflate.findViewById(R.id.isSaveAnnotatationsAutomatically);
isSaveAnnotatationsAutomatically.setChecked(AppState.get().isSaveAnnotatationsAutomatically);
isSaveAnnotatationsAutomatically.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isSaveAnnotatationsAutomatically = isChecked;
}
});
isSaveAnnotatationsAutomatically.setVisibility(!AppState.get().isAlwaysOpenAsMagazine && BookType.PDF.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
CheckBox highlightByLetters = (CheckBox) inflate.findViewById(R.id.highlightByLetters);
highlightByLetters.setChecked(AppState.get().selectingByLetters);
highlightByLetters.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().selectingByLetters = isChecked;
}
});
CheckBox isCutRTL = (CheckBox) inflate.findViewById(R.id.isCutRTL);
isCutRTL.setChecked(AppState.get().isCutRTL);
isCutRTL.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isCutRTL = isChecked;
}
});
final TextView pageQuality = (TextView) inflate.findViewById(R.id.pageQuality);
((ViewGroup) pageQuality.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine && !ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
pageQuality.setText((int) (AppState.get().pageQuality * 100) + "%");
TxtUtils.underlineTextView(pageQuality);
pageQuality.setOnClickListener(new OnClickListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (float i = 0.5f; i < 2.1f; i += 0.1f) {
final float quality = i;
popupMenu.getMenu().add((int) (i * 100) + "%").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().pageQuality = quality;
pageQuality.setText((int) (AppState.get().pageQuality * 100) + "%");
TxtUtils.underlineTextView(pageQuality);
return false;
}
});
}
popupMenu.show();
}
});
final TextView pagesInMemory = (TextView) inflate.findViewById(R.id.pagesInMemory);
((ViewGroup) pagesInMemory.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
pagesInMemory.setText("" + AppState.get().pagesInMemory);
TxtUtils.underlineTextView(pagesInMemory);
pagesInMemory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.getMenu().add("" + 1).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().pagesInMemory = 1;
pagesInMemory.setText("" + AppState.get().pagesInMemory);
TxtUtils.underlineTextView(pagesInMemory);
return false;
}
});
popupMenu.getMenu().add("" + 3).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().pagesInMemory = 3;
pagesInMemory.setText("" + AppState.get().pagesInMemory);
TxtUtils.underlineTextView(pagesInMemory);
return false;
}
});
popupMenu.getMenu().add("" + 5).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().pagesInMemory = 5;
pagesInMemory.setText("" + AppState.get().pagesInMemory);
TxtUtils.underlineTextView(pagesInMemory);
return false;
}
});
popupMenu.show();
}
});
// /
final TextView inactivityTime = (TextView) inflate.findViewById(R.id.inactivityTime);
inactivityTime.setText("" + AppState.get().inactivityTime);
TxtUtils.underlineTextView(inactivityTime);
inactivityTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (int i = 1; i <= 10; i++) {
final int number = i;
popupMenu.getMenu().add("" + i).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().inactivityTime = number;
inactivityTime.setText("" + AppState.get().inactivityTime);
TxtUtils.underlineTextView(inactivityTime);
return false;
}
});
}
popupMenu.show();
}
});
// /
final TextView rotate = (TextView) inflate.findViewById(R.id.rotate);
((ViewGroup) rotate.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
rotate.setText("" + AppState.get().rotate + "°");
TxtUtils.underlineTextView(rotate);
rotate.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
MenuBuilderM.addRotateMenu(rotate, null, new Runnable() {
@Override
public void run() {
rotate.setText("" + AppState.get().rotate + "°");
TxtUtils.underlineTextView(rotate);
}
}).show();
}
});
final TextView tapzoneSize = (TextView) inflate.findViewById(R.id.tapzoneSize);
tapzoneSize.setText("" + AppState.get().tapzoneSize + "%");
TxtUtils.underlineTextView(tapzoneSize);
tapzoneSize.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (int i = 0; i <= 45f; i += 5) {
final int number = i;
popupMenu.getMenu().add("" + i + "%").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().tapzoneSize = number;
tapzoneSize.setText("" + AppState.get().tapzoneSize + "%");
TxtUtils.underlineTextView(tapzoneSize);
return false;
}
});
}
popupMenu.show();
}
});
// double tap
final List<String> doubleTapNames = //
Arrays.asList(//
controller.getString(R.string.db_auto_scroll), //
controller.getString(R.string.db_auto_alignemnt), //
controller.getString(R.string.db_auto_center_horizontally), //
controller.getString(R.string.zoom_in_zoom_out), //
controller.getString(R.string.close_book), //
controller.getString(R.string.close_book_and_application), //
controller.getString(R.string.hide_app), //
controller.getString(R.string.db_do_nothing));
final List<Integer> doubleTapIDS = //
Arrays.asList(//
AppState.DOUBLE_CLICK_AUTOSCROLL, //
AppState.DOUBLE_CLICK_ADJUST_PAGE, //
AppState.DOUBLE_CLICK_CENTER_HORIZONTAL, //
AppState.DOUBLE_CLICK_ZOOM_IN_OUT, //
AppState.DOUBLE_CLICK_CLOSE_BOOK, //
AppState.DOUBLE_CLICK_CLOSE_BOOK_AND_APP, //
AppState.DOUBLE_CLICK_CLOSE_HIDE_APP, //
AppState.DOUBLE_CLICK_NOTHING);
//
final TextView doubleClickAction1 = (TextView) inflate.findViewById(R.id.doubleTapValue);
doubleClickAction1.setText(doubleTapNames.get(doubleTapIDS.indexOf(AppState.get().doubleClickAction1)));
TxtUtils.underlineTextView(doubleClickAction1);
doubleClickAction1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MyPopupMenu popup = new MyPopupMenu(controller.getActivity(), v);
for (int i = 0; i < doubleTapNames.size(); i++) {
final int j = i;
final String fontName = doubleTapNames.get(i);
popup.getMenu().add(fontName).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().doubleClickAction1 = doubleTapIDS.get(j);
doubleClickAction1.setText(doubleTapNames.get(doubleTapIDS.indexOf(AppState.get().doubleClickAction1)));
TxtUtils.underlineTextView(doubleClickAction1);
return false;
}
});
}
popup.show();
}
});
final TextView tapzoneCustomize = (TextView) inflate.findViewById(R.id.tapzoneCustomize);
TxtUtils.underlineTextView(tapzoneCustomize);
tapzoneCustomize.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
TapZoneDialog.show(controller.getActivity());
}
});
final TextView allocatedMemorySize = (TextView) inflate.findViewById(R.id.allocatedMemorySize);
allocatedMemorySize.setText("" + AppState.get().allocatedMemorySize + "Mb");
TxtUtils.underlineTextView(allocatedMemorySize);
allocatedMemorySize.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (int i = 16; i <= 512 && i < MemoryUtils.MAX_MEMORY_SIZE; i += i) {
final int number = i;
popupMenu.getMenu().add("" + i + "Mb").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().allocatedMemorySize = number;
allocatedMemorySize.setText("" + AppState.get().allocatedMemorySize + "Mb");
TxtUtils.underlineTextView(allocatedMemorySize);
return false;
}
});
}
popupMenu.show();
}
});
// image format
final TextView imageFormat = (TextView) inflate.findViewById(R.id.imageFormat);
// ((ViewGroup)
// imageFormat.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine
// ? View.VISIBLE : View.GONE);
((ViewGroup) imageFormat.getParent()).setVisibility(View.GONE);
imageFormat.setText(AppState.get().imageFormat);
TxtUtils.underlineTextView(imageFormat);
imageFormat.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.getMenu().add(AppState.PNG).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().imageFormat = AppState.PNG;
imageFormat.setText(AppState.get().imageFormat);
TxtUtils.underlineTextView(imageFormat);
return false;
}
});
popupMenu.getMenu().add(AppState.JPG).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().imageFormat = AppState.JPG;
imageFormat.setText(AppState.get().imageFormat);
TxtUtils.underlineTextView(imageFormat);
return false;
}
});
popupMenu.show();
}
});
// remind rest time
final TextView remindRestTime = (TextView) inflate.findViewById(R.id.remindRestTime);
final String minutesString = controller.getString(R.string.minutes).toLowerCase(Locale.US);
if (AppState.get().remindRestTime == -1) {
remindRestTime.setText(R.string.no);
} else {
remindRestTime.setText(AppState.get().remindRestTime + " " + minutesString);
}
TxtUtils.underlineTextView(remindRestTime);
remindRestTime.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.getMenu().add(R.string.no).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().remindRestTime = -1;
remindRestTime.setText(R.string.no);
TxtUtils.underlineTextView(remindRestTime);
return false;
}
});
for (int i = 10; i <= 240; i += 10) {
final int j = i;
popupMenu.getMenu().add(i + " " + minutesString).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().remindRestTime = j;
remindRestTime.setText(AppState.get().remindRestTime + " " + minutesString);
TxtUtils.underlineTextView(remindRestTime);
return false;
}
});
}
popupMenu.show();
}
});
// rotate
final TextView rotateViewPager = (TextView) inflate.findViewById(R.id.rotateViewPager);
((ViewGroup) rotateViewPager.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
rotateViewPager.setText(AppState.get().rotateViewPager == 0 ? R.string.horizontal : R.string.vertical);
TxtUtils.underlineTextView(rotateViewPager);
rotateViewPager.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.getMenu().add(R.string.horizontal).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().rotateViewPager = 0;
rotateViewPager.setText(AppState.get().rotateViewPager == 0 ? R.string.horizontal : R.string.vertical);
TxtUtils.underlineTextView(rotateViewPager);
return false;
}
});
popupMenu.getMenu().add(R.string.vertical).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().rotateViewPager = 90;
rotateViewPager.setText(AppState.get().rotateViewPager == 0 ? R.string.horizontal : R.string.vertical);
TxtUtils.underlineTextView(rotateViewPager);
return false;
}
});
popupMenu.show();
}
});
// rtl
final TextView rtlText = (TextView) inflate.findViewById(R.id.rtlText);
((ViewGroup) rtlText.getParent()).setVisibility(AppState.get().isAlwaysOpenAsMagazine ? View.VISIBLE : View.GONE);
if (AppState.get().isRTL) {
rtlText.setText(R.string.right_to_left);
} else {
rtlText.setText(R.string.left_to_rigth);
}
TxtUtils.underlineTextView(rtlText);
rtlText.setOnClickListener(new OnClickListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.getMenu().add(R.string.left_to_rigth).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().isRTL = false;
rtlText.setText(R.string.left_to_rigth);
TxtUtils.underlineTextView(rtlText);
AppState.get().tapZoneTop = AppState.TAP_PREV_PAGE;
AppState.get().tapZoneBottom = AppState.TAP_NEXT_PAGE;
AppState.get().tapZoneLeft = AppState.TAP_PREV_PAGE;
AppState.get().tapZoneRight = AppState.TAP_NEXT_PAGE;
return false;
}
});
popupMenu.getMenu().add(R.string.right_to_left).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().isRTL = true;
rtlText.setText(R.string.right_to_left);
TxtUtils.underlineTextView(rtlText);
AppState.get().tapZoneTop = AppState.TAP_PREV_PAGE;
AppState.get().tapZoneBottom = AppState.TAP_NEXT_PAGE;
AppState.get().tapZoneLeft = AppState.TAP_NEXT_PAGE;
AppState.get().tapZoneRight = AppState.TAP_PREV_PAGE;
return false;
}
});
popupMenu.show();
}
});
return inflate;
}
};
dialog.show(DragingPopup.PREF + "_performanceSettings");
dialog.setOnCloseListener(new Runnable() {
@Override
public void run() {
boolean one = appHash != Objects.hashCode(AppState.get());
boolean two = controller.isTextFormat() && cssHash != BookCSS.get().toCssString().hashCode();
if (one || two) {
if (onRefresh != null) {
onRefresh.run();
}
controller.restartActivity();
}
}
});
return dialog;
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project LibreraReader by foobnix.
the class DragingDialogs method statusBarSettings.
public static DragingPopup statusBarSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
DragingPopup dialog = new DragingPopup(R.string.status_bar, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public void beforeCreate() {
titleAction = controller.getString(R.string.preferences);
titleRunnable = new Runnable() {
@Override
public void run() {
preferences(anchor, controller, onRefresh, updateUIRefresh);
}
};
}
@Override
public View getContentView(final LayoutInflater inflater) {
View inflate = inflater.inflate(R.layout.dialog_status_bar_settings, null, false);
final CheckBox isShowReadingProgress = (CheckBox) inflate.findViewById(R.id.isShowReadingProgress);
final CheckBox isShowChaptersOnProgress = (CheckBox) inflate.findViewById(R.id.isShowChaptersOnProgress);
isShowReadingProgress.setChecked(AppState.get().isShowReadingProgress);
isShowReadingProgress.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isShowReadingProgress = isChecked;
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
isShowChaptersOnProgress.setChecked(isChecked);
isShowChaptersOnProgress.setEnabled(isChecked);
}
});
isShowChaptersOnProgress.setChecked(AppState.get().isShowChaptersOnProgress);
isShowChaptersOnProgress.setEnabled(AppState.get().isShowReadingProgress);
isShowChaptersOnProgress.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isShowChaptersOnProgress = isChecked;
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
if (isChecked) {
isShowReadingProgress.setChecked(true);
}
}
});
final EditText musicText = (EditText) inflate.findViewById(R.id.musicText);
musicText.setText(AppState.get().musicText);
((View) musicText.getParent()).setVisibility(AppState.get().isMusicianMode ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.musicTextOk).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().musicText = musicText.getText().toString();
if (onRefresh != null) {
onRefresh.run();
}
}
});
CheckBox isRewindEnable = (CheckBox) inflate.findViewById(R.id.isRewindEnable);
isRewindEnable.setChecked(AppState.get().isRewindEnable);
isRewindEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isRewindEnable = isChecked;
}
});
//
final CheckBox isShowSatusBar = (CheckBox) inflate.findViewById(R.id.isShowSatusBar);
isShowSatusBar.setChecked(AppState.get().isShowToolBar);
isShowSatusBar.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isShowToolBar = isChecked;
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
}
});
final CheckBox isShowTime = (CheckBox) inflate.findViewById(R.id.isShowTime);
isShowTime.setChecked(AppState.get().isShowTime);
isShowTime.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isShowTime = isChecked;
if (onRefresh != null) {
onRefresh.run();
}
if (isChecked) {
isShowSatusBar.setChecked(true);
}
}
});
final CheckBox isShowBattery = (CheckBox) inflate.findViewById(R.id.isShowBattery);
isShowBattery.setChecked(AppState.get().isShowBattery);
isShowBattery.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isShowBattery = isChecked;
if (onRefresh != null) {
onRefresh.run();
}
if (isChecked) {
isShowSatusBar.setChecked(true);
}
}
});
// status bar
final List<Integer> modeIds = //
Arrays.asList(//
AppState.READING_PROGRESS_NUMBERS, //
AppState.READING_PROGRESS_PERCENT, //
AppState.READING_PROGRESS_PERCENT_NUMBERS);
//
final List<String> modeStrings = //
Arrays.asList(//
controller.getString(R.string.number), //
controller.getString(R.string.percent), //
controller.getString(R.string.percent_and_number));
//
final TextView readingProgress = (TextView) inflate.findViewById(R.id.readingProgress);
readingProgress.setText(modeStrings.get(modeIds.indexOf(AppState.get().readingProgress)));
TxtUtils.underlineTextView(readingProgress);
readingProgress.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final MyPopupMenu popupMenu = new MyPopupMenu(v.getContext(), v);
for (int i = 0; i < modeStrings.size(); i++) {
final int j = i;
popupMenu.getMenu().add(modeStrings.get(i)).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().readingProgress = modeIds.get(j);
readingProgress.setText(modeStrings.get(modeIds.indexOf(AppState.get().readingProgress)));
TxtUtils.underlineTextView(readingProgress);
if (onRefresh != null) {
onRefresh.run();
}
return false;
}
});
}
popupMenu.show();
}
});
// / asd
final CustomSeek statusBarTextSize = (CustomSeek) inflate.findViewById(R.id.statusBarTextSize);
statusBarTextSize.setTitleTextWidth(Dips.dpToPx(100));
statusBarTextSize.init(5, 30, controller.isEasyMode() ? AppState.get().statusBarTextSizeEasy : AppState.get().statusBarTextSizeAdv);
statusBarTextSize.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
isShowSatusBar.setChecked(true);
if (controller.isEasyMode()) {
AppState.get().statusBarTextSizeEasy = result;
} else {
AppState.get().statusBarTextSizeAdv = result;
}
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
return false;
}
});
final CustomSeek progressLineHeight = (CustomSeek) inflate.findViewById(R.id.progressLineHeight);
progressLineHeight.setTitleTextWidth(Dips.dpToPx(100));
progressLineHeight.init(1, 10, AppState.get().progressLineHeight);
progressLineHeight.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
isShowReadingProgress.setChecked(true);
AppState.get().progressLineHeight = result;
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
return false;
}
});
final CustomColorView statusBarColorDay = (CustomColorView) inflate.findViewById(R.id.statusBarColorDay);
statusBarColorDay.withDefaultColors(AppState.TEXT_COLOR_DAY, AppState.get().tintColor);
statusBarColorDay.init(AppState.get().statusBarColorDay);
statusBarColorDay.setOnColorChanged(new StringResponse() {
@Override
public boolean onResultRecive(String string) {
isShowSatusBar.setChecked(true);
AppState.get().statusBarColorDay = Color.parseColor(string);
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
Keyboards.hideNavigation(controller.getActivity());
return false;
}
});
final CustomColorView statusBarColorNight = (CustomColorView) inflate.findViewById(R.id.statusBarColorNight);
statusBarColorNight.withDefaultColors(AppState.TEXT_COLOR_NIGHT, AppState.get().tintColor);
statusBarColorNight.init(AppState.get().statusBarColorNight);
statusBarColorNight.setOnColorChanged(new StringResponse() {
@Override
public boolean onResultRecive(String string) {
isShowSatusBar.setChecked(true);
AppState.get().statusBarColorNight = Color.parseColor(string);
AppState.get().isEditMode = false;
if (onRefresh != null) {
onRefresh.run();
}
Keyboards.hideNavigation(controller.getActivity());
return false;
}
});
statusBarColorDay.getText1().getLayoutParams().width = Dips.dpToPx(150);
statusBarColorNight.getText1().getLayoutParams().width = Dips.dpToPx(150);
return inflate;
}
};
dialog.show(DragingPopup.PREF + "_statusBarSettings");
return dialog;
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project LibreraReader by foobnix.
the class ExtUtils method showDocument.
public static boolean showDocument(final Context c, final File file, final int page) {
ImageLoader.getInstance().clearAllTasks();
if (AppState.get().isRememberMode) {
showDocumentWithoutDialog(c, file, page);
return true;
}
View view = LayoutInflater.from(c).inflate(R.layout.choose_mode_dialog, null, false);
final TextView vertical = (TextView) view.findViewById(R.id.vertical);
final TextView horizontal = (TextView) view.findViewById(R.id.horizontal);
final TextView music = (TextView) view.findViewById(R.id.music);
final EditText verticalEdit = (EditText) view.findViewById(R.id.verticalEdit);
final EditText horizontalEdit = (EditText) view.findViewById(R.id.horizontalEdit);
final EditText musicEdit = (EditText) view.findViewById(R.id.musicEdit);
verticalEdit.setText(AppState.get().nameVerticalMode);
horizontalEdit.setText(AppState.get().nameHorizontalMode);
musicEdit.setText(AppState.get().nameMusicianMode);
vertical.setText(AppState.get().nameVerticalMode);
horizontal.setText(AppState.get().nameHorizontalMode);
music.setText(AppState.get().nameMusicianMode);
Views.gone(verticalEdit, horizontalEdit, musicEdit);
final TextView editNames = (TextView) view.findViewById(R.id.editNames);
TxtUtils.underlineTextView(editNames);
editNames.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AppState.get().nameVerticalMode = c.getString(R.string.mode_vertical);
AppState.get().nameHorizontalMode = c.getString(R.string.mode_horizontally);
AppState.get().nameMusicianMode = c.getString(R.string.mode_musician);
verticalEdit.setText(AppState.get().nameVerticalMode);
horizontalEdit.setText(AppState.get().nameHorizontalMode);
musicEdit.setText(AppState.get().nameMusicianMode);
vertical.setText(AppState.get().nameVerticalMode);
horizontal.setText(AppState.get().nameHorizontalMode);
music.setText(AppState.get().nameMusicianMode);
AppState.get().save(c);
return true;
}
});
editNames.setOnClickListener(new View.OnClickListener() {
boolean isEdit = true;
@Override
public void onClick(View v) {
String vText = verticalEdit.getText().toString().trim();
String hText = horizontalEdit.getText().toString().trim();
String mText = musicEdit.getText().toString().trim();
if (TxtUtils.isEmpty(vText)) {
verticalEdit.setSelected(true);
Toast.makeText(c, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
return;
}
if (TxtUtils.isEmpty(hText)) {
horizontalEdit.setSelected(true);
Toast.makeText(c, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
return;
}
if (TxtUtils.isEmpty(mText)) {
musicEdit.setSelected(true);
Toast.makeText(c, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
return;
}
if (isEdit) {
// edit
editNames.setText(R.string.save);
Views.visible(verticalEdit, horizontalEdit, musicEdit);
Views.gone(vertical, horizontal, music);
AppState.get().save(c);
} else {
// text view
editNames.setText(R.string.edit_names);
Views.visible(vertical, horizontal, music);
Views.gone(verticalEdit, horizontalEdit, musicEdit);
}
AppState.get().nameVerticalMode = vText;
AppState.get().nameHorizontalMode = hText;
AppState.get().nameMusicianMode = mText;
Keyboards.close(v);
verticalEdit.setText(AppState.get().nameVerticalMode);
horizontalEdit.setText(AppState.get().nameHorizontalMode);
musicEdit.setText(AppState.get().nameMusicianMode);
vertical.setText(AppState.get().nameVerticalMode);
horizontal.setText(AppState.get().nameHorizontalMode);
music.setText(AppState.get().nameMusicianMode);
TxtUtils.underlineTextView(editNames);
isEdit = !isEdit;
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setTitle(R.string.select_the_reading_mode);
builder.setView(view);
builder.setCancelable(true);
final AlertDialog dialog = builder.show();
vertical.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
AppState.get().isAlwaysOpenAsMagazine = false;
AppState.get().isMusicianMode = false;
showDocumentWithoutDialog(c, file, page);
}
});
horizontal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
AppState.get().isAlwaysOpenAsMagazine = true;
AppState.get().isMusicianMode = false;
showDocumentWithoutDialog(c, file, page);
}
});
music.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
AppState.get().isAlwaysOpenAsMagazine = false;
AppState.get().isMusicianMode = true;
showDocumentWithoutDialog(c, file, page);
}
});
if (Dips.isEInk(c)) {
view.findViewById(R.id.music).setVisibility(View.GONE);
}
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBoxRemember);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isRememberMode = isChecked;
}
});
return true;
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project LibreraReader by foobnix.
the class Dialogs method showTagsDialog.
public static void showTagsDialog(final Context a, File file, final Runnable refresh) {
final FileMeta fileMeta = AppDB.get().getOrCreate(file.getPath());
LOG.d("showTagsDialog book tags", fileMeta.getTag());
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
// builder.setTitle(R.string.tag);
View inflate = LayoutInflater.from(a).inflate(R.layout.dialog_tags, null, false);
final ListView list = (ListView) inflate.findViewById(R.id.listView1);
final TextView add = (TextView) inflate.findViewById(R.id.addTag);
TxtUtils.underline(add, "+ " + a.getString(R.string.add_tag));
final List<String> tags = StringDB.asList(AppState.get().bookTags);
List<String> fileTags = StringDB.asList(fileMeta.getTag());
for (String fileTag : fileTags) {
if (!StringDB.contains(AppState.get().bookTags, fileTag)) {
tags.add(fileTag);
}
}
Collections.sort(tags);
Iterator<String> iterator = tags.iterator();
while (iterator.hasNext()) {
if (TxtUtils.isEmpty(iterator.next().trim())) {
iterator.remove();
}
}
final Set<Integer> checked = new HashSet<>();
final BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(a, R.layout.tag_item, tags) {
@Override
public void populateView(View layout, final int position, final String tagName) {
CheckBox text = (CheckBox) layout.findViewById(R.id.tagName);
text.setText(tagName);
text.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
checked.add(position);
} else {
checked.remove(position);
}
}
});
text.setChecked(StringDB.contains(fileMeta.getTag(), tagName));
layout.findViewById(R.id.deleteTag).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog((Activity) a, a.getString(R.string.do_you_want_to_delete_this_tag_from_all_books_), new Runnable() {
@Override
public void run() {
checked.clear();
AppState.get().bookTags = StringDB.delete(AppState.get().bookTags, tagName);
tags.clear();
tags.addAll(StringDB.asList(AppState.get().bookTags));
notifyDataSetChanged();
List<FileMeta> allWithTag = AppDB.get().getAllWithTag(tagName);
for (FileMeta meta : allWithTag) {
meta.setTag(StringDB.delete(meta.getTag(), tagName));
}
AppDB.get().updateAll(allWithTag);
if (refresh != null) {
refresh.run();
}
}
});
}
});
}
};
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addTagsDialog(a, new Runnable() {
@Override
public void run() {
tags.clear();
tags.addAll(StringDB.asList(AppState.get().bookTags));
adapter.notifyDataSetChanged();
}
});
}
});
list.setAdapter(adapter);
builder.setView(inflate);
builder.setNegativeButton(R.string.close, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setPositiveButton(R.string.apply, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String res = "";
for (int i : checked) {
res = StringDB.add(res, tags.get(i));
}
LOG.d("showTagsDialog", res);
fileMeta.setTag(res);
AppDB.get().update(fileMeta);
if (refresh != null) {
refresh.run();
}
TempHolder.listHash++;
}
});
AlertDialog create = builder.create();
create.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.close((Activity) a);
Keyboards.hideNavigation((Activity) a);
}
});
create.show();
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project LibreraReader by foobnix.
the class Dialogs method getBCView.
public static LinearLayout getBCView(final Activity c, final Runnable action) {
LinearLayout l = new LinearLayout(c);
l.setPadding(Dips.dpToPx(5), Dips.dpToPx(5), Dips.dpToPx(5), Dips.dpToPx(5));
l.setOrientation(LinearLayout.VERTICAL);
final Handler handler = new Handler();
final Runnable actionWrapper = new Runnable() {
@Override
public void run() {
handler.removeCallbacks(action);
handler.postDelayed(action, 100);
}
};
final CheckBox isEnableBC = new CheckBox(c);
isEnableBC.setText(R.string.enable_contrast_and_brightness);
isEnableBC.setChecked(AppState.get().isEnableBC);
isEnableBC.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isEnableBC = isChecked;
actionWrapper.run();
}
});
final CustomSeek contrastSeek = new CustomSeek(c);
contrastSeek.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0));
contrastSeek.init(0, 200, AppState.get().contrastImage);
contrastSeek.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
AppState.get().contrastImage = result;
isEnableBC.setChecked(true);
actionWrapper.run();
return false;
}
});
final CustomSeek brightnesSeek = new CustomSeek(c);
brightnesSeek.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0));
brightnesSeek.init(-100, 100, AppState.get().brigtnessImage);
brightnesSeek.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
AppState.get().brigtnessImage = result;
isEnableBC.setChecked(true);
actionWrapper.run();
return false;
}
});
final CheckBox bolderText = new CheckBox(c);
bolderText.setText(R.string.make_text_bold);
bolderText.setChecked(AppState.get().bolderTextOnImage);
bolderText.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().bolderTextOnImage = isChecked;
if (isChecked) {
isEnableBC.setChecked(true);
}
actionWrapper.run();
}
});
TextView contrastText = new TextView(c);
contrastText.setText(R.string.contrast);
TextView brightnessText = new TextView(c);
brightnessText.setText(R.string.brightness);
l.addView(isEnableBC);
l.addView(contrastText);
l.addView(contrastSeek);
l.addView(brightnessText);
l.addView(brightnesSeek);
l.addView(bolderText);
TextView defaults = new TextView(c);
defaults.setTextAppearance(c, R.style.textLinkStyle);
defaults.setText(R.string.restore_defaults_short);
TxtUtils.underlineTextView(defaults);
defaults.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog(c, c.getString(R.string.restore_defaults_full), new Runnable() {
@Override
public void run() {
AppState.get().brigtnessImage = 0;
AppState.get().contrastImage = 0;
AppState.get().bolderTextOnImage = false;
isEnableBC.setChecked(AppState.get().bolderTextOnImage);
brightnesSeek.reset(AppState.get().brigtnessImage);
contrastSeek.reset(AppState.get().contrastImage);
actionWrapper.run();
}
});
}
});
l.addView(defaults);
return l;
}
Aggregations