Drag and Drop in android web view for image
<p>I want to do the drag and drop operation in android web view for the images in the webpages.</p>

<p>Code is like this.</p>

<pre><code>WebView webView;
ImageView imageView;
ImageView shadowImageView;

private static final String IMAGEVIEW_TAG = "icon bitmap";
public static final String TAG="ResourceSharing";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browser);
    webView=(WebView) findViewById(R.id.webView);

    imageView=(ImageView) findViewById(R.id.downloadImage);
    webView.setWebViewClient(new WebViewController());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://www.picasaweb.google.com");
    webView.clearCache(true);
    webView.setOnLongClickListener(this);
    shadowImageView=new ImageView(this);
    shadowImageView.setImageBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.picasa_logo));
    shadowImageView.setTag(IMAGEVIEW_TAG);  


}
public class WebViewController extends WebViewClient {

     @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
}
@Override
public boolean onLongClick(View v) {

    HitTestResult hitTestResult=webView.getHitTestResult();
    Log.i(TAG, "Hit type"+hitTestResult.getType());
    switch (hitTestResult.getType()) {
    case HitTestResult.IMAGE_TYPE:
        Log.i(TAG, "Ïnside image type");
        imageView.setVisibility(View.VISIBLE);
        break;
    case HitTestResult.IMAGE_ANCHOR_TYPE:
        Log.i(TAG, "Ïnside image type");
        imageView.setVisibility(View.VISIBLE);
        break;
    case HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
        Log.i(TAG, "Ïnside image type");
        imageView.setVisibility(View.VISIBLE);
        performDragAndDropOperation();
        break;
    default:
        break;
    }

    return true;
}
@TargetApi(11)
private void performDragAndDropOperation(){
    ClipData.Item item = new ClipData.Item((CharSequence) shadowImageView.getTag());
    ClipData dragData = new ClipData((CharSequence) shadowImageView.getTag(),new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },item);
    DragShadowBuilder shadowBuilder = new MyDragShadowBuilder(shadowImageView);
    shadowImageView.startDrag(dragData, shadowBuilder, null, 0);
}

 private static class MyDragShadowBuilder extends View.DragShadowBuilder {
        private static Drawable shadow;
            public MyDragShadowBuilder(View v) {
                super(v);
                shadow = new ColorDrawable(Color.LTGRAY);
            }
            @Override
            public void onProvideShadowMetrics (Point size, Point touch){
                int width;
                int height;
                Log.i(TAG, "calling getVIew" +getView());
                width = getView().getWidth() / 2;
                height = getView().getHeight() / 2;
                shadow.setBounds(0, 0, width, height);
                size.set(width, height);
                touch.set(width / 2, height / 2);
                Log.i(TAG, "calling getVIew" +getView());
            }
            @Override
            public void onDrawShadow(Canvas canvas) {
                Log.i(TAG, "calling getVIew" +getView());
                shadow.draw(canvas);
            }
        }
</code></pre>

<p>But when i run the application and try to drag an image after long press an error is coming in the logcat unable to initiate drag in andriod with null pointer exception.</p>

<p>Looking for help</p>
