I need to perform a task on Viewing mode (Single, Double, Cover) and color mode (Dark, Light) click so I tried to find callback of those click.
So I tried from here -
In this link viewmode dialog is shown by dialog.show() method but I want callback from that dialog opened by a user from the menu button(3 dot button )=>View Mode => Viewing Mode or Color mode.
Yes, I know about that callback method but this method call when “dialog.show()” will be use ex. “dialog.show(fragmentManager, “view_mode_picker”)”.
But I want that when user open viewmode dialog from the menu button(3 dot button )=>View Mode => Viewing Mode or Color mode. then these callback should be call.
For reference, you can add a callback for view mode or color mode changes by calling the following:
ViewModePickerDialogFragment dialog = ...
dialog.setViewModePickerDialogFragmentListener(new ViewModePickerDialogFragment.ViewModePickerDialogFragmentListener() {
/** * Called when a view mode has been selected. * * @param viewMode The selected view mode */
@Override
public void onViewModeSelected(String viewMode) {
// Implement functionality for each view mode selected
// ...
}
/** * Called when a color mode has been selected. * * @param colorMode The color mode * @return True if the dialog should be dismissed */
@Override
public boolean onViewModeColorSelected(int colorMode) {
return false;
}
/** * Called when a custom color mode is selected * * @param bgColor The selected background color * @param txtColor The selected text color * @return True if the dialog should be dismissed */
@Override
public boolean onCustomColorModeSelected(int bgColor, int txtColor) {
return false;
}
/** * Called when the dialog has been dismissed. */
@Override
public void onViewModePickerDialogFragmentDismiss() {
// Do something when the dialog is dismissed
}
/** * The implementation should zoom in/out reflow * * @param flagZoomIn True if zoom in; False if zoom out * @return The text size raging from 0 to 100 */
@Override
public int onReflowZoomInOut(boolean flagZoomIn) {
return 0;
}
/** * The implementation should check tab conversion and shows the alert if needed. * * @param messageID The message ID * @param allowConverted True if conversion is allowed * @return True if handled */
@Override
public boolean checkTabConversionAndAlert(int messageID, boolean allowConverted) {
return false;
}
});
If i am not using dialog.show(mPdfViewCtrlTabHostFragment.getFragmentManager(),“view_mode_picker”); then these callback method is not working.
@Override
public void onTabDocumentLoaded(String tag) {
ViewModePickerDialogFragment dialog = ViewModePickerDialogFragment.newInstance(
mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getPDFViewCtrl().getPagePresentationMode(),
true,
true,
0);
dialog.setViewModePickerDialogFragmentListener(new ViewModePickerDialogFragment.ViewModePickerDialogFragmentListener() {
@Override
public void onViewModeSelected(String viewMode) {
Log.e("viewmode", viewMode);
}
@Override
public boolean onViewModeColorSelected(int colorMode) {
Log.e("colorMode", "" + colorMode);
return false;
}
@Override
public boolean onCustomColorModeSelected(int bgColor, int txtColor) {
Log.e("onCustomColorMode", ""+bgColor+" --- " + txtColor);
return false;
}
@Override
public void onViewModePickerDialogFragmentDismiss() {
}
@Override
public int onReflowZoomInOut(boolean flagZoomIn) {
return 0;
}
@Override
public boolean checkTabConversionAndAlert(int messageID, boolean allowConverted) {
return false;
}
});
dialog.show(mPdfViewCtrlTabHostFragment.getFragmentManager(),"view_mode_picker");
}
I am doing this stuff in onTabDocumentLoaded() so that I can have instance of PDFCtrlView (mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getPDFViewCtrl()) when this method is calling dialog is showing and this methods are working properly. If I don’t use dialog.show() and open view mode dialog manually from menu button(3 dot button )=>View Mode dialog will be shown but these callback is not working.
I tried in one more way. I used dialog.show() in onOptionsItemSelected on click of View Mode so now luckily callback method start working but it’s not changing the view neither on view mode click nor on color mode click.
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.title.contentEquals(“View Mode”, true)) {
viewModePickerDialogFragment.show(mPdfViewCtrlTabHostFragment.fragmentManage!!,"view_mode_picker)
return true
}
return super.onOptionsItemSelected(item)
}
Since you are using the ViewModeDialog in the viewer fragment directly, I recommend extending PdfViewCtrlTabHostFragment2 and overriding the required methods in your custom class.
For example:
public class CustomTabHostFragment extends PdfViewCtrlTabHostFragment2 {
@Override
public boolean onViewModeColorSelected(int colorMode) {
boolean dismissed = super.onViewModeColorSelected(colorMode);
// Implement custom functionality here ...
return dismissed;
}
@Override
public void onViewModeSelected(String viewMode) {
super.onViewModeSelected(viewMode);
// Implement custom functionality here ...
}
// Override other listeners from ViewModePickerDialogFragmentListener
// ...
}
Then you can build and use your custom viewer as follows: