Example usage for android.view GestureDetector onTouchEvent

List of usage examples for android.view GestureDetector onTouchEvent

Introduction

In this page you can find the example usage for android.view GestureDetector onTouchEvent.

Prototype

public boolean onTouchEvent(MotionEvent ev) 

Source Link

Document

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.

Usage

From source file:com.caro.smartmodule.viewComponent.viewpagers.SmartViewPager.java

private void setup() {
    final GestureDetector tapGestureDetector = new GestureDetector(getContext(), new TapGestureListener());

    setOnTouchListener(new OnTouchListener() {
        @Override//from   ww  w  . j a  v  a 2s. c  om
        public boolean onTouch(View v, MotionEvent event) {
            tapGestureDetector.onTouchEvent(event);
            return false;
        }
    });
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    DisplayMetrics metrics = new DisplayMetrics();
    SherlockFragmentActivity activity = getSherlockActivity();

    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    displayPageNumber(-1); // Initializes the pagenumber view properly

    final GestureDetector gestureDetector = new GestureDetector(context,
            new NavGestureDetector(bookView, this, metrics));

    View.OnTouchListener gestureListener = (View v, MotionEvent event) -> !ttsIsRunning()
            && gestureDetector.onTouchEvent(event);

    this.viewSwitcher.setOnTouchListener(gestureListener);
    this.bookView.setOnTouchListener(gestureListener);
    this.dummyView.setOnTouchListener(gestureListener);

    registerForContextMenu(bookView);//w w w .jav  a 2 s .c om
    saveConfigState();

    Intent intent = activity.getIntent();
    String file = null;

    if (intent.getData() != null) {
        file = intent.getData().getPath();
    }

    if (file == null) {
        file = config.getLastOpenedFile();
    }

    updateFromPrefs();
    updateFileName(savedInstanceState, file);

    if ("".equals(fileName) || !new File(fileName).exists()) {

        LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. "
                + "Switching back to the library.");

        Intent newIntent = new Intent(context, LibraryActivity.class);
        startActivity(newIntent);
        activity.finish();
        return;

    } else {

        if (savedInstanceState == null && config.isSyncEnabled()) {
            new DownloadProgressTask().execute();
        } else {
            bookView.restore();
        }
    }

    if (ttsIsRunning()) {
        this.mediaLayout.setVisibility(View.VISIBLE);
        this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this::speechCompleted);
        uiHandler.post(progressBarUpdater);
    }

    activity.getSupportActionBar().addOnMenuVisibilityListener(isVisible -> {

        LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible);
        int visibility = isVisible ? View.VISIBLE : View.GONE;
        titleBarLayout.setVisibility(visibility);

    });

}

From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from w w w.  ja v  a 2  s . co m
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set values
    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Get filename of saved note
    filename = getArguments().getString("filename");

    // Change window title
    String title;

    try {
        title = listener.loadNoteTitle(filename);
    } catch (IOException e) {
        title = getResources().getString(R.string.view_note);
    }

    getActivity().setTitle(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo))
                .getBitmap();

        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap,
                ContextCompat.getColor(getActivity(), R.color.primary));
        getActivity().setTaskDescription(taskDescription);
    }

    // Show the Up button in the action bar.
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Animate elevation change
    if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = getActivity().findViewById(R.id.noteList);

        noteList.animate().z(0f);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            noteViewEdit.animate()
                    .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land));
        else
            noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation));
    }

    // Set up content view
    TextView noteContents = getActivity().findViewById(R.id.textView);
    markdownView = getActivity().findViewById(R.id.markdownView);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView scrollView = getActivity().findViewById(R.id.scrollView);
    String theme = pref.getString("theme", "light-sans");
    int textSize = -1;
    int textColor = -1;

    String fontFamily = null;

    if (theme.contains("light")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary));
            noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
        }

        if (markdownView != null) {
            markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    }

    if (theme.contains("dark")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark));
            noteContents
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
        }

        if (markdownView != null) {
            markdownView
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
    }

    if (theme.contains("sans")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SANS_SERIF);

        if (markdownView != null)
            fontFamily = "sans-serif";
    }

    if (theme.contains("serif")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SERIF);

        if (markdownView != null)
            fontFamily = "serif";
    }

    if (theme.contains("monospace")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.MONOSPACE);

        if (markdownView != null)
            fontFamily = "monospace";
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        textSize = 12;
        break;
    case "small":
        textSize = 14;
        break;
    case "normal":
        textSize = 16;
        break;
    case "large":
        textSize = 18;
        break;
    case "largest":
        textSize = 20;
        break;
    }

    if (noteContents != null)
        noteContents.setTextSize(textSize);

    String css = "";
    if (markdownView != null) {
        String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom)
                / getResources().getDisplayMetrics().density) + "px";
        String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right)
                / getResources().getDisplayMetrics().density) + "px";
        String fontSize = " " + Integer.toString(textSize) + "px";
        String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff");
        String linkColor = " #" + StringUtils.remove(
                Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff");

        css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:"
                + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}"
                + "a { " + "color:" + linkColor + "; " + "}";

        markdownView.getSettings().setJavaScriptEnabled(false);
        markdownView.getSettings().setLoadsImagesAutomatically(false);
        markdownView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException | FileUriExposedException e) {
                        /* Gracefully fail */ }
                else
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        /* Gracefully fail */ }

                return true;
            }
        });
    }

    // Load note contents
    try {
        contentsOnLoad = listener.loadNote(filename);
    } catch (IOException e) {
        showToast(R.string.error_loading_note);

        // Add NoteListFragment or WelcomeFragment
        Fragment fragment;
        if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal"))
            fragment = new NoteListFragment();
        else
            fragment = new WelcomeFragment();

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }

    // Set TextView contents
    if (noteContents != null)
        noteContents.setText(contentsOnLoad);

    if (markdownView != null)
        markdownView.loadMarkdown(contentsOnLoad,
                "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT));

    // Show a toast message if this is the user's first time viewing a note
    final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    firstLoad = sharedPref.getInt("first-load", 0);
    if (firstLoad == 0) {
        // Show dialog with info
        DialogFragment firstLoad = new FirstViewDialogFragment();
        firstLoad.show(getFragmentManager(), "firstloadfragment");

        // Set first-load preference to 1; we don't need to show the dialog anymore
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt("first-load", 1);
        editor.apply();
    }

    // Detect single and double-taps using GestureDetector
    final GestureDetector detector = new GestureDetector(getActivity(),
            new GestureDetector.OnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    return false;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    return false;
                }
            });

    detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true)) {
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean("show_double_tap_message", false);
                editor.apply();
            }

            Bundle bundle = new Bundle();
            bundle.putString("filename", filename);

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                    .commit();

            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) {
                showToastLong(R.string.double_tap);
                showMessage = false;
            }

            return false;
        }

    });

    if (noteContents != null)
        noteContents.setOnTouchListener((v, event) -> {
            detector.onTouchEvent(event);
            return false;
        });

    if (markdownView != null)
        markdownView.setOnTouchListener((v, event) -> {
            detector.onTouchEvent(event);
            return false;
        });
}

From source file:net.zorgblub.typhon.fragment.ReadingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    DisplayMetrics metrics = new DisplayMetrics();
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    this.context = activity;

    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    displayPageNumber(-1); // Initializes the pagenumber view properly

    final GestureDetector gestureDetector = new GestureDetector(context,
            new NavGestureDetector(bookView, this, metrics));

    View.OnTouchListener gestureListener = (View v, MotionEvent event) -> !ttsIsRunning()
            && gestureDetector.onTouchEvent(event);

    this.viewSwitcher.setOnTouchListener(gestureListener);
    this.bookView.setOnTouchListener(gestureListener);
    this.dummyView.setOnTouchListener(gestureListener);

    registerForContextMenu(bookView);//from w  ww  .jav  a 2  s. c o m
    saveConfigState();

    Intent intent = activity.getIntent();
    String file = null;

    if (intent.getData() != null) {
        file = intent.getData().getPath();
    }

    if (file == null) {
        file = config.getLastOpenedFile();
    }

    updateFromPrefs();
    updateFileName(savedInstanceState, file);

    if ("".equals(fileName) || !new File(fileName).exists()) {

        LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. "
                + "Switching back to the library.");

        Intent newIntent = new Intent(context, LibraryActivity.class);
        startActivity(newIntent);
        activity.finish();
        return;

    } else {

        if (savedInstanceState == null && config.isSyncEnabled()) {
            new DownloadProgressTask().execute();
        } else {
            bookView.restore();
        }
    }

    if (ttsIsRunning()) {
        this.mediaLayout.setVisibility(View.VISIBLE);
        this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this::speechCompleted);
        uiHandler.post(progressBarUpdater);
    }

    activity.getSupportActionBar().addOnMenuVisibilityListener(isVisible -> {

        LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible);
        int visibility = isVisible ? View.VISIBLE : View.GONE;
        titleBarLayout.setVisibility(visibility);

    });

}

From source file:com.anjalimacwan.fragment.NoteViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*from  w  ww . java 2s  .c  om*/
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set values
    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Get filename of saved note
    filename = getArguments().getString("filename");

    // Change window title
    String title;

    try {
        title = listener.loadNoteTitle(filename);
    } catch (IOException e) {
        title = getResources().getString(R.string.view_note);
    }

    getActivity().setTitle(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null,
                ContextCompat.getColor(getActivity(), R.color.primary));
        getActivity().setTaskDescription(taskDescription);
    }

    // Show the Up button in the action bar.
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Animate elevation change
    if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout noteViewEdit = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = (LinearLayout) getActivity().findViewById(R.id.noteList);

        noteList.animate().z(0f);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            noteViewEdit.animate()
                    .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land));
        else
            noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation));
    }

    // Set up content view
    TextView noteContents = (TextView) getActivity().findViewById(R.id.textView);
    markdownView = (MarkdownView) getActivity().findViewById(R.id.markdownView);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollView);
    String theme = pref.getString("theme", "light-sans");
    int textSize = -1;
    int textColor = -1;

    String fontFamily = null;

    if (theme.contains("light")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary));
            noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
        }

        if (markdownView != null) {
            markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    }

    if (theme.contains("dark")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark));
            noteContents
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
        }

        if (markdownView != null) {
            markdownView
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
    }

    if (theme.contains("sans")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SANS_SERIF);

        if (markdownView != null)
            fontFamily = "sans-serif";
    }

    if (theme.contains("serif")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SERIF);

        if (markdownView != null)
            fontFamily = "serif";
    }

    if (theme.contains("monospace")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.MONOSPACE);

        if (markdownView != null)
            fontFamily = "monospace";
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        textSize = 12;
        break;
    case "small":
        textSize = 14;
        break;
    case "normal":
        textSize = 16;
        break;
    case "large":
        textSize = 18;
        break;
    case "largest":
        textSize = 20;
        break;
    }

    if (noteContents != null)
        noteContents.setTextSize(textSize);

    if (markdownView != null) {
        String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom)
                / getResources().getDisplayMetrics().density) + "px";
        String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right)
                / getResources().getDisplayMetrics().density) + "px";
        String fontSize = " " + Integer.toString(textSize) + "px";
        String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff");

        final String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; "
                + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor
                + "; " + "}";

        final String js = "var styleNode = document.createElement('style');\n"
                + "styleNode.type = \"text/css\";\n" + "var styleText = document.createTextNode('" + css
                + "');\n" + "styleNode.appendChild(styleText);\n"
                + "document.getElementsByTagName('head')[0].appendChild(styleNode);\n";

        markdownView.getSettings().setJavaScriptEnabled(true);
        markdownView.getSettings().setLoadsImagesAutomatically(false);
        markdownView.setWebViewClient(new WebViewClient() {
            @TargetApi(Build.VERSION_CODES.N)
            @Override
            public void onLoadResource(WebView view, String url) {
                view.stopLoading();
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException | FileUriExposedException e) {
                        /* Gracefully fail */ }
                else
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        /* Gracefully fail */ }
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
                    view.evaluateJavascript(js, null);
                else
                    view.loadUrl("javascript:" + js);
            }
        });
    }

    // Load note contents
    try {
        contentsOnLoad = listener.loadNote(filename);
    } catch (IOException e) {
        showToast(R.string.error_loading_note);

        // Add NoteListFragment or WelcomeFragment
        Fragment fragment;
        if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal"))
            fragment = new NoteListFragment();
        else
            fragment = new WelcomeFragment();

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }

    // Set TextView contents
    if (noteContents != null)
        noteContents.setText(contentsOnLoad);

    if (markdownView != null)
        markdownView.loadMarkdown(contentsOnLoad);

    // Show a toast message if this is the user's first time viewing a note
    final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    firstLoad = sharedPref.getInt("first-load", 0);
    if (firstLoad == 0) {
        // Show dialog with info
        DialogFragment firstLoad = new FirstViewDialogFragment();
        firstLoad.show(getFragmentManager(), "firstloadfragment");

        // Set first-load preference to 1; we don't need to show the dialog anymore
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt("first-load", 1);
        editor.apply();
    }

    // Detect single and double-taps using GestureDetector
    final GestureDetector detector = new GestureDetector(getActivity(),
            new GestureDetector.OnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    return false;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    return false;
                }
            });

    detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true)) {
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean("show_double_tap_message", false);
                editor.apply();
            }

            Bundle bundle = new Bundle();
            bundle.putString("filename", filename);

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                    .commit();

            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) {
                showToastLong(R.string.double_tap);
                showMessage = false;
            }

            return false;
        }

    });

    if (noteContents != null)
        noteContents.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                detector.onTouchEvent(event);
                return false;
            }
        });

    if (markdownView != null)
        markdownView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                detector.onTouchEvent(event);
                return false;
            }
        });
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    DisplayMetrics metrics = new DisplayMetrics();
    SherlockFragmentActivity activity = getSherlockActivity();

    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    displayPageNumber(-1); // Initializes the pagenumber view properly

    final GestureDetector gestureDetector = new GestureDetector(context,
            new NavGestureDetector(bookView, this, metrics));

    View.OnTouchListener gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

            if (ttsIsRunning()) {
                return false;
            }/*from  ww w  .  jav  a 2 s.c  om*/

            return gestureDetector.onTouchEvent(event);
        }
    };

    this.viewSwitcher.setOnTouchListener(gestureListener);
    this.bookView.setOnTouchListener(gestureListener);
    this.dummyView.setOnTouchListener(gestureListener);

    registerForContextMenu(bookView);
    saveConfigState();

    Intent intent = activity.getIntent();
    String file = null;

    if (intent.getData() != null) {
        file = intent.getData().getPath();
    }

    if (file == null) {
        file = config.getLastOpenedFile();
    }

    updateFromPrefs();
    updateFileName(savedInstanceState, file);

    if ("".equals(fileName) || !new File(fileName).exists()) {

        LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. "
                + "Switching back to the library.");

        Intent newIntent = new Intent(context, LibraryActivity.class);
        startActivity(newIntent);
        activity.finish();
        return;

    } else {

        if (savedInstanceState == null && config.isSyncEnabled()) {
            new DownloadProgressTask().execute();
        } else {
            bookView.restore();
        }
    }

    if (ttsIsRunning()) {
        this.mediaLayout.setVisibility(View.VISIBLE);
        this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this);
        uiHandler.post(progressBarUpdater);
    }

    activity.getSupportActionBar().addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
        @Override
        public void onMenuVisibilityChanged(boolean isVisible) {

            LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible);

            if (isVisible) {
                titleBarLayout.setVisibility(View.VISIBLE);
            } else {
                titleBarLayout.setVisibility(View.GONE);
            }
        }
    });

    /*
    new ShakeListener(getActivity()).setOnShakeListener(new ShakeListener.OnShakeListener() {
    @Override
    public void onShake() {
        if ( ! ttsIsRunning() ) {
            startTextToSpeech();
        }
    }
    });
    */
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    DisplayMetrics metrics = new DisplayMetrics();
    SherlockFragmentActivity activity = getSherlockActivity();

    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    displayPageNumber(-1); // Initializes the pagenumber view properly

    final GestureDetector gestureDetector = new GestureDetector(context,
            new NavGestureDetector(bookView, this, metrics));

    View.OnTouchListener gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

            if (ttsIsRunning()) {
                return false;
            }// w  w w  .j  av  a2s  .c o  m

            return gestureDetector.onTouchEvent(event);
        }
    };

    this.viewSwitcher.setOnTouchListener(gestureListener);
    this.bookView.setOnTouchListener(gestureListener);
    this.dummyView.setOnTouchListener(gestureListener);

    registerForContextMenu(bookView);
    saveConfigState();

    Intent intent = activity.getIntent();
    String file = null;

    if (intent.getData() != null) {
        file = intent.getData().getPath();
    }

    if (file == null) {
        file = config.getLastOpenedFile();
    }

    updateFromPrefs();
    updateFileName(savedInstanceState, file);

    if ("".equals(fileName) || !new File(fileName).exists()) {

        LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. "
                + "Switching back to the library.");

        Intent newIntent = new Intent(context, LibraryActivity.class);
        startActivity(newIntent);
        activity.finish();
        return;

    } else {

        if (savedInstanceState == null && config.isSyncEnabled()) {
            new DownloadProgressTask().execute();
        } else {
            bookView.restore();
        }
    }

    if (ttsIsRunning()) {
        this.mediaLayout.setVisibility(View.VISIBLE);
        this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this);
        uiHandler.post(progressBarUpdater);
    }

    activity.getSupportActionBar().addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
        @Override
        public void onMenuVisibilityChanged(boolean isVisible) {

            LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible);

            if (isVisible) {
                titleBarLayout.setVisibility(View.VISIBLE);
            } else {
                titleBarLayout.setVisibility(View.GONE);
            }
        }
    });

    /*
     * new ShakeListener(getActivity()).setOnShakeListener(new
     * ShakeListener.OnShakeListener() {
     * 
     * @Override public void onShake() { if ( ! ttsIsRunning() ) {
     * startTextToSpeech(); } } });
     */
}

From source file:com.farmerbb.taskbar.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    View view = new View(this);
    view.setOnClickListener(view1 -> LocalBroadcastManager.getInstance(HomeActivity.this)
            .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")));

    view.setOnLongClickListener(view12 -> {
        setWallpaper();//from  w  ww  . ja  v a 2  s . c  om
        return false;
    });

    view.setOnGenericMotionListener((view13, motionEvent) -> {
        if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            setWallpaper();
        }
        return false;
    });

    final GestureDetector detector = new GestureDetector(this, new GestureDetector.OnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }

        @Override
        public void onShowPress(MotionEvent e) {
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            return false;
        }

        @Override
        public void onLongPress(MotionEvent e) {
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            return false;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return false;
        }
    });

    detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            final SharedPreferences pref = U.getSharedPreferences(HomeActivity.this);
            if (!pref.getBoolean("dont_show_double_tap_dialog", false)) {
                if (pref.getBoolean("double_tap_to_sleep", false)) {
                    U.lockDevice(HomeActivity.this);
                } else {
                    int theme = -1;
                    switch (pref.getString("theme", "light")) {
                    case "light":
                        theme = R.style.AppTheme;
                        break;
                    case "dark":
                        theme = R.style.AppTheme_Dark;
                        break;
                    }

                    AlertDialog.Builder builder = new AlertDialog.Builder(
                            new ContextThemeWrapper(HomeActivity.this, theme));
                    builder.setTitle(R.string.double_tap_to_sleep)
                            .setMessage(R.string.enable_double_tap_to_sleep)
                            .setNegativeButton(
                                    pref.getBoolean("double_tap_dialog_shown", false)
                                            ? R.string.action_dont_show_again
                                            : R.string.action_cancel,
                                    (dialog, which) -> pref.edit()
                                            .putBoolean(pref.getBoolean("double_tap_dialog_shown", false)
                                                    ? "dont_show_double_tap_dialog"
                                                    : "double_tap_dialog_shown", true)
                                            .apply())
                            .setPositiveButton(R.string.action_ok, (dialog, which) -> {
                                pref.edit().putBoolean("double_tap_to_sleep", true).apply();
                                U.lockDevice(HomeActivity.this);
                            });

                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
            }

            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return false;
        }

    });

    view.setOnTouchListener((v, event) -> {
        detector.onTouchEvent(event);
        return false;
    });

    setContentView(view);

    LocalBroadcastManager.getInstance(this).registerReceiver(killReceiver,
            new IntentFilter("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
    LocalBroadcastManager.getInstance(this).registerReceiver(forceTaskbarStartReceiver,
            new IntentFilter("com.farmerbb.taskbar.FORCE_TASKBAR_RESTART"));
}

From source file:org.awesomeapp.messenger.ui.ConversationView.java

protected void initViews() {
    //  mStatusIcon = (ImageView) mActivity.findViewById(R.id.statusIcon);
    //   mDeliveryIcon = (ImageView) mActivity.findViewById(R.id.deliveryIcon);
    // mTitle = (TextView) mActivity.findViewById(R.id.title);
    mHistory = (RecyclerView) mActivity.findViewById(R.id.history);
    LinearLayoutManager llm = new LinearLayoutManager(mHistory.getContext());
    llm.setStackFromEnd(true);//from  w w  w .j a  va2  s .c om
    mHistory.setLayoutManager(llm);

    mComposeMessage = (EditText) mActivity.findViewById(R.id.composeMessage);
    mSendButton = (ImageButton) mActivity.findViewById(R.id.btnSend);
    mMicButton = (ImageButton) mActivity.findViewById(R.id.btnMic);
    mButtonTalk = (TextView) mActivity.findViewById(R.id.buttonHoldToTalk);

    mButtonDeleteVoice = (ImageView) mActivity.findViewById(R.id.btnDeleteVoice);
    mViewDeleteVoice = mActivity.findViewById(R.id.viewDeleteVoice);

    mButtonDeleteVoice.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                int resolvedColor = mHistory.getResources().getColor(android.R.color.holo_red_light);
                mButtonDeleteVoice.setBackgroundColor(resolvedColor);
            }

            return false;
        }
    });

    mButtonAttach = (ImageButton) mActivity.findViewById(R.id.btnAttach);
    mViewAttach = mActivity.findViewById(R.id.attachPanel);

    mStatusWarningView = mActivity.findViewById(R.id.warning);
    mWarningText = (TextView) mActivity.findViewById(R.id.warningText);

    mButtonAttach.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            toggleAttachMenu();
        }

    });

    mActivity.findViewById(R.id.btnAttachPicture).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.startImagePicker();
        }

    });

    mActivity.findViewById(R.id.btnTakePicture).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.startPhotoTaker();
        }

    });

    /**
    mActivity.findViewById(R.id.btnAttachFile).setOnClickListener(new View.OnClickListener() {
            
    @Override
    public void onClick(View v) {
        mActivity.startFilePicker();
    }
            
    });*/

    mActivity.findViewById(R.id.btnAttachSticker).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleAttachMenu();
            showStickers();
        }

    });

    mMicButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //this is the tap to change to hold to talk mode
            if (mMicButton.getVisibility() == View.VISIBLE) {
                mComposeMessage.setVisibility(View.GONE);
                mMicButton.setVisibility(View.GONE);

                // Check if no view has focus:
                View view = mActivity.getCurrentFocus();
                if (view != null) {
                    InputMethodManager imm = (InputMethodManager) mActivity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }

                mSendButton.setImageResource(R.drawable.ic_keyboard_black_36dp);
                mSendButton.setVisibility(View.VISIBLE);
                mButtonTalk.setVisibility(View.VISIBLE);

            }
        }

    });

    final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {

            //this is for recording audio directly from one press
            mActivity.startAudioRecording();

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {

            if (mActivity.isAudioRecording()) {
                boolean send = true;//inViewInBounds(mMicButton, (int) motionEvent.getX(), (int) motionEvent.getY());
                mActivity.stopAudioRecording(send);
            }

            return super.onSingleTapUp(e);
        }
    });

    mMicButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return gestureDetector.onTouchEvent(motionEvent);

        }
    });

    mButtonTalk.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View btnTalk, MotionEvent theMotion) {
            switch (theMotion.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mActivity.startAudioRecording();
                mButtonTalk.setText(mActivity.getString(R.string.recording_release));
                mViewDeleteVoice.setVisibility(View.VISIBLE);

                break;
            case MotionEvent.ACTION_MOVE:
                boolean inBounds = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
                if (!inBounds)
                    mButtonTalk.setText(mActivity.getString(R.string.recording_delete));
                else {
                    mButtonTalk.setText(mActivity.getString(R.string.recording_release));
                    mViewDeleteVoice.setVisibility(View.VISIBLE);
                }
                break;
            case MotionEvent.ACTION_UP:
                mButtonTalk.setText(mActivity.getString(R.string.push_to_talk));
                boolean send = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
                mActivity.stopAudioRecording(send);
                mViewDeleteVoice.setVisibility(View.GONE);

                break;
            }
            return true;
        }
    });
    /**
    mHistory.setOnItemLongClickListener(new OnItemLongClickListener ()
    {
            
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            
            
     if (arg1 instanceof MessageView)
     {
            
         String textToCopy = ((MessageView)arg1).getLastMessage();
            
         int sdk = android.os.Build.VERSION.SDK_INT;
         if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
             android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
             clipboard.setText(textToCopy); //
         } else {
             android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
             android.content.ClipData clip = android.content.ClipData.newPlainText("chat",textToCopy);
             clipboard.setPrimaryClip(clip); //
         }
            
         Toast.makeText(mActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard), Toast.LENGTH_SHORT).show();
            
         return true;
            
     }
            
        return false;
    }
            
    });**/

    mWarningText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showVerifyDialog();
        }
    });

    mComposeMessage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            sendTypingStatus(true);

            return false;
        }
    });

    mComposeMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            sendTypingStatus(hasFocus);

        }
    });

    mComposeMessage.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                    sendMessage();
                    return true;

                case KeyEvent.KEYCODE_ENTER:
                    if (event.isAltPressed()) {
                        mComposeMessage.append("\n");
                        return true;
                    }
                }

            }

            return false;
        }
    });

    mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                if (event.isAltPressed()) {
                    return false;
                }
            }

            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null && imm.isActive(v)) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
            sendMessage();
            return true;
        }
    });

    // TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with
    // the soft keyboard, we should remove this hack.
    mComposeMessage.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int before, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int after) {

        }

        public void afterTextChanged(Editable s) {
            doWordSearch();
            userActionDetected();
        }
    });

    mSendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (mComposeMessage.getVisibility() == View.VISIBLE)
                sendMessage();
            else {
                mSendButton.setImageResource(R.drawable.ic_send_holo_light);

                if (mLastSessionStatus == SessionStatus.ENCRYPTED)
                    mSendButton.setImageResource(R.drawable.ic_send_secure);

                mSendButton.setVisibility(View.GONE);
                mButtonTalk.setVisibility(View.GONE);
                mComposeMessage.setVisibility(View.VISIBLE);
                mMicButton.setVisibility(View.VISIBLE);

            }
        }
    });

    mMessageAdapter = new ConversationRecyclerViewAdapter(mActivity, null);
    mHistory.setAdapter(mMessageAdapter);

}

From source file:org.readium.sdk.android.biblemesh.WebViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

    setContentView(R.layout.activity_web_view);

    final int abTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
    findViewById(abTitleId).setOnClickListener(new View.OnClickListener() {

        @Override/*w  w  w  .ja  v a  2 s . c om*/
        public void onClick(View v) {
            finish();
        }
    });

    mWebview = (WebView) findViewById(R.id.webview);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && 0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    mProgress = (ProgressBar) findViewById(R.id.progressBar);
    initWebView();

    final GestureDetector gestureDetector = new GestureDetector(this, new MyGestureListener());

    mWebview.setOnTouchListener(new View.OnTouchListener() {

        private final static long MAX_TOUCH_DURATION = 150;
        float lastEventX;
        float m_DownTime;

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastEventX = event.getX();
                m_DownTime = event.getEventTime(); //init time
                break;
            case MotionEvent.ACTION_MOVE: {
                float distanceX = lastEventX - event.getX();

                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mWebview
                        .getLayoutParams();

                marginLayoutParams.leftMargin = marginLayoutParams.leftMargin - (int) distanceX;
                marginLayoutParams.rightMargin = -marginLayoutParams.leftMargin;// marginLayoutParams.rightMargin + (int) distanceX;

                mWebview.requestLayout();
            }
                break;
            case MotionEvent.ACTION_UP: {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mWebview
                        .getLayoutParams();
                if (marginLayoutParams.leftMargin < 10 && marginLayoutParams.leftMargin > -10) {
                    Log.i("up", "small margin, open menu?");
                    if (event.getEventTime() - m_DownTime <= MAX_TOUCH_DURATION) {
                        Log.i("up", "quick");
                        showActionBar(null);
                    } else {
                        Log.i("up", "too long");
                    }
                }
            }
            case MotionEvent.ACTION_CANCEL: {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mWebview
                        .getLayoutParams();

                //Log.i("snap", "snap width: "+mWebview.getWidth()+" left:" + marginLayoutParams.leftMargin + " raw:" + event.getRawX() + " " + event.getX());//+" "+e2.toString()+" "+e1.toString());
                //mWebview.getWidth()
                if (marginLayoutParams.leftMargin < -0.5 * mWebview.getWidth()) {
                    mReadiumJSApi.openPageRight();
                    mWebview.setAlpha(0.0f);
                } else if (marginLayoutParams.leftMargin > 0.5 * mWebview.getWidth()) {
                    mReadiumJSApi.openPageLeft();
                    mWebview.setAlpha(0.0f);
                } else {
                    snapBack();
                    //return true;
                }
            }
                break;
            }
            ;
            return gestureDetector.onTouchEvent(event);
        }
    });
    /*mWebview.setHapticFeedbackEnabled(false);*/

    Intent intent = getIntent();
    if (intent.getFlags() == Intent.FLAG_ACTIVITY_NEW_TASK) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            mContainer = ContainerHolder.getInstance().get(extras.getLong(Constants.CONTAINER_ID));
            if (mContainer == null) {
                finish();
                return;
            }
            mPackage = mContainer.getDefaultPackage();

            String rootUrl = "http://" + EpubServer.HTTP_HOST + ":" + EpubServer.HTTP_PORT + "/";
            mPackage.setRootUrls(rootUrl, null);

            try {
                mOpenPageRequestData = OpenPageRequest
                        .fromJSON(extras.getString(Constants.OPEN_PAGE_REQUEST_DATA));
            } catch (JSONException e) {
                Log.e(TAG, "Constants.OPEN_PAGE_REQUEST_DATA must be a valid JSON object: " + e.getMessage(),
                        e);
            }
        }
    }

    // No need, EpubServer already launchers its own thread
    // new AsyncTask<Void, Void, Void>() {
    // @Override
    // protected Void doInBackground(Void... params) {
    // //xxx
    // return null;
    // }
    // }.execute();

    mServer = new EpubServer(EpubServer.HTTP_HOST, EpubServer.HTTP_PORT, mPackage, quiet, dataPreProcessor);
    mServer.startServer();

    // Load the page skeleton
    mWebview.loadUrl(READER_SKELETON);
    mViewerSettings = new ViewerSettings(ViewerSettings.SyntheticSpreadMode.SINGLE,
            ViewerSettings.ScrollMode.AUTO, 100, 20);

    mReadiumJSApi = new ReadiumJSApi(new ReadiumJSApi.JSLoader() {
        @Override
        public void loadJS(String javascript) {
            mWebview.loadUrl(javascript);
        }
    });

    /*Button back = (Button)findViewById(R.id.btnBack);
    back.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
    onBackPressed();
    if(getActionBar.isShowing())
    {
       hideActionBar();
    }
    else
    {
       getActionBar.show();
       hideActionBar();
    }
       }
    });*/
    r = new Runnable() {
        @Override
        public void run() {
            getActionBar().hide();
            //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        }
    };
    hide2 = null;
    hideActionBar();
    //ActionBar actionBar = getActionBar();
    //actionBar.hide();
    //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}