WebViewMarker icon indicating copy to clipboard operation
WebViewMarker copied to clipboard

Double Selection in Android Lollipop

Open DineshNandhagopal opened this issue 9 years ago • 10 comments

Double selection is still occurring in Android 5.0 +. .Eventhough selection is same, as web view marker, CAB is appearing again.Thank you.

DineshNandhagopal avatar Aug 03 '15 05:08 DineshNandhagopal

Thanks for reporting. I've been away from actual Android development for almost 2 years, so it takes some time for building my android development. I'll check it in 2, 3 days.

naoak avatar Aug 03 '15 09:08 naoak

Thank you!

DineshNandhagopal avatar Aug 03 '15 11:08 DineshNandhagopal

I couldn't reproduce it on demo with Nexus 5 emulator (API 21). Do you have any sample code to reproduce it? And what is your specific environment?

naoak avatar Aug 05 '15 15:08 naoak

Thanks for taking time on it. API build tool is set to Version 23 rc3 and target is API22.

// grade build compileSdkVersion 22 buildToolsVersion "23.0.0 rc3"

defaultConfig {
    applicationId "com.example.webviewmarker"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}

This is my CustomView and the codes are below.

public class PageView extends WebView { private String data; private String baseUrl; private SelectActionModeCallback actionModeCallback; private TextSelectionSupport mTextSelectionSupport; private Context context;

public PageView(Context context, AttributeSet attrs) {
     super(context, attrs);
     this.context = context;
     setProperties();
}

public PageView(Context context, String data,String baseUrl){
    super(context);
    this.context = context;
    this.data = data;
    this.baseUrl = baseUrl;
    setProperties();
    this.loadDataWithBaseURL(baseUrl, data, "text/html", "utf-8", null);
}

private void setProperties(){
    getSettings().setJavaScriptEnabled(true);
    getSettings().setAllowFileAccess(true);
    getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    getSettings().getJavaScriptCanOpenWindowsAutomatically();
    getSettings().setBuiltInZoomControls(true);
    getSettings().setDisplayZoomControls(false);
    setSelectionListener();
    setWebViewClient();
    setWebChromrClient();
}


public void loadPage(String data,String baseUrl){
    this.loadDataWithBaseURL(baseUrl, data, "text/html", "utf-8", null);
}

private void  setWebViewClient() {

    setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            view.setVisibility(View.VISIBLE);
        }

        public void onScaleChanged(WebView view, float oldScale, float newScale) {
            mTextSelectionSupport.onScaleChanged(oldScale, newScale);
        }
    });
}
private  void setWebChromrClient() {
    setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) {
            if (message.startsWith("file:")) {

            } else {
                new AlertDialog.Builder(context)
                        .setTitle("javaScript dialog")
                        .setMessage(message)
                        .setPositiveButton(android.R.string.ok,
                                new AlertDialog.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        result.confirm();
                                    }
                                })
                        .setCancelable(false)
                        .create()
                        .show();
            }
            return true;
        }

        ;

    });
}



private void setSelectionListener()
{
    mTextSelectionSupport = TextSelectionSupport.support((Activity)context, this);
    mTextSelectionSupport.setSelectionListener(new TextSelectionSupport.SelectionListener() {
        @Override
        public void startSelection() {
        }

        @Override
        public void selectionChanged(String text) {
            Toast.makeText(context,text,Toast.LENGTH_LONG).show();
        }

        @Override
        public void endSelection() {
        }
    });


}

}

// To hide CAB , when double selection,

@Override
public void onActionModeStarted(ActionMode mode) {
    if (mActionMode == null) {
        mActionMode = mode;
        Menu menu = mode.getMenu();
        menu.clear();
        menu.removeItem(android.R.id.home);

        }

   super.onActionModeStarted(mode);
}


public void onContextualMenuItemClicked(MenuItem item) {
    switch (item.getItemId()) {
          default:
            // ...
            break;
    }

    // This will likely always be true, but check it anyway, just in case
    if (mActionMode != null) {
        mActionMode.finish();
    }
}

@Override
public void onActionModeFinished(ActionMode mode) {
    mActionMode = null;
    super.onActionModeFinished(mode);
}

This code is in the activity

DineshNandhagopal avatar Aug 06 '15 03:08 DineshNandhagopal

Thanks for the details. I'll check it after returning home.

naoak avatar Aug 06 '15 04:08 naoak

Are there any news on how to handle double selection in Android 5.0 +?

Davory avatar Dec 16 '15 09:12 Davory

Oh, it completely slipped my mind... I'm sorry that I have no news.

naoak avatar Dec 22 '15 11:12 naoak

I'm having the same problem. Have you found a solution ? Thanks

bertrandserres avatar Apr 01 '16 04:04 bertrandserres

Sorry, I have no news..

@DineshNandhagopal, @Davory Have you found any solutions?

naoak avatar Apr 01 '16 13:04 naoak

for future interested -> https://stackoverflow.com/a/28550635

defaultbr avatar Apr 25 '18 05:04 defaultbr