3

CustomWebView次のように実装するために、選択したテキストを強調表示したいActionmode......

  public class CustomWebView extends WebView {


public ActionMode mActionMode;
public ActionMode.Callback mActionModeCallback;

private ActionMode.Callback mSelectActionModeCallback;


public CustomWebView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomWebView(Context context) {
    super(context);

    this.context = context;
    sm = new ScreenManager((Activity) context);
}   



@Override
public ActionMode startActionMode(Callback callback) {

    ViewParent parent = getParent();
    if (parent == null) {
        return null;
    }
    String name = "";
    if (callback != null)
        name = callback.getClass().toString();
    if (name.contains("SelectActionModeCallback")) {
        mSelectActionModeCallback = callback;
    }
    System.out.println("startActionMode"+name);
    mActionModeCallback = new CustomActionModeCallback();

    return super.startActionModeForChild(this, mActionModeCallback);
}

private class CustomActionModeCallback implements ActionMode.Callback {


    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu)   
        mActionMode = mode;
        MenuInflater inflater = mode.getMenuInflater();
        inflater.inflate(R.menu.reader_epub_menu, menu);
        return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
        return false; // Return false if nothing is done
    }


    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_highlight_add:
            loadUrl(highlightSelection());
            break;
        case R.id.action_note_add:
            frag.call(spineIndex, tocIndex);
            break;
        }

        mActionMode.finish(); 
        return true;
    }


    @Override
    public void onDestroyActionMode(ActionMode mode) {

        frag.makeSwipeEnable();
        clearFocus(); // Remove the selection highlight and handles.


        if (mSelectActionModeCallback != null) {
            mSelectActionModeCallback.onDestroyActionMode(mode);
        }

        mActionMode = null;
    }
}



public ActionMode getActionMode() {
    return mActionMode;
}

and my in my reader fragment implemented Gesture listner as follows 


public class GestureListener extends
            GestureDetector.SimpleOnGestureListener {

 @Override
        public void onLongPress(MotionEvent e) {
            makeSwipeDisable();
            reader.startActionMode(reader.mActionModeCallback);
            reader.dispatchTouchEvent(e);
            super.onLongPress(e);
        }
}

以下からonTouchEventを削除した後、それは機能しましたがonFling()、webviewでは失われ、水平にスクロールするだけです。

reader = new CustomWebView(getActivity()) {

        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
            // TODO Auto-generated method stub
            super.onScrollChanged(l, t, oldl, oldt);
            // checking whether the current page has been bookmarked and
            // animates the ribbon down and up
            if (isBookmarked(rOffset, currentContent))
                scaleDown();
            else
                scaleUp();
        }


        @Override
       public boolean onTouchEvent(MotionEvent event) {
            return (gestureDetector.onTouchEvent(event) || super
                   .onTouchEvent(event));
      }

このコードに何か問題がありますか?CAB は表示され、機能していますが、問題はテキストが選択されていません。

4

1 に答える 1

2

あなたの本当の質問を教えてください: 選択したテキストを強調表示するか、ページ フリップ効果が正しく機能しませんか?

https://github.com/openaphid/android-flipのような他のライブラリを使用していて、それが機能しないということですか?

IMHO、独自のジェスチャー検出器を単独で使用して、スーパー onTouch イベントを返すのはどうですか?
onTouchEvent に対して true を返すことは、イベントを消費し、親への伝播を防ぐことを意味します。

 @Override
       public boolean onTouchEvent(MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            return super.onTouchEvent(event);
      }

詳細を参照してください: http://developer.android.com/reference/android/view/View.OnTouchListener.html

"リスナーがイベントを消費した場合は True を返し、それ以外の場合は False を返します。"

于 2015-08-12T11:41:15.243 に答える