Error Message: False Android

I want to save the captured image and set them in a gridview , then the user can drag and drop to change the position of the captured image, that is, the first image, but I'm very new to using drag and drop and can you explain this?

How to change this code?

public class MainActivity extends Activity {

private Button btPhoto, btSave;
private GridView gridview;
private File imgFile;
private String path;
private ArrayList<File> List_File;
private static final int imageCode = 100;
private Context context;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btPhoto = (Button) findViewById(R.id.btPhoto);
    btSave = (Button) findViewById(R.id.bt_save);
    gridview = (GridView) findViewById(R.id.gridview);


    path = "/TongFolder/";
    context = this;
    List_File = new ArrayList<File>();
    File imgDir = new File(Environment.getExternalStorageDirectory()+path);
    imgDir.mkdirs();
    boolean check = imgDir.isDirectory();
    if(check == true){
    btPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            capture();

        }
    });
    }else{
        System.out.println("not create");
    }
 }


public void capture(){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    imgFile = new File(Environment.getExternalStorageDirectory()+path, 
            "img_"+System.currentTimeMillis()+".jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imgFile));
    startActivityForResult(intent, imageCode);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data){

    if(requestCode == imageCode && resultCode == RESULT_OK){

        //add path to arrayList
        List_File.add(imgFile);
        for (File file : List_File) {
            String showPath = file.getPath();
            System.out.println(showPath);
        }

        gridview.setAdapter(new gridViewAdapter(context, List_File));
        if(gridview != null){
            DragDrop();
        }

    }

}

public void DragDrop(){

    gridview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> adapter, View v,
                int position, long id) {

            DragShadow dragshadow = new DragShadow(v);

            ClipData data = ClipData.newPlainText("", "");

            v.startDrag(data, dragshadow, v, 0);

            return true;

        }
    }); 

}

OnDragListener dragListener = new OnDragListener() {

    @Override
    public boolean onDrag(View v, DragEvent event) {
        int action = event.getAction();

        switch (action) {

        case DragEvent.ACTION_DRAG_ENTERED:
            Log.i("drag event", "entered");
            break;

        case DragEvent.ACTION_DRAG_EXITED:
            Log.i("drag event", "exited");
            break;

        case DragEvent.ACTION_DROP:

            Log.i("drag event", "drop");

            break;
        }
        return true;
    }
};

private class DragShadow extends View.DragShadowBuilder{

    ColorDrawable boxShadow;

    public DragShadow(View view) {
        super(view);
        boxShadow = new ColorDrawable(Color.LTGRAY);
    }

    @Override
    public void onDrawShadow(Canvas canvas) {

        boxShadow.draw(canvas);
    }

    @Override
    public void onProvideShadowMetrics(Point shadowSize,
            Point shadowTouchPoint) {

        View v = getView();
        int height = (int)v.getHeight();
        int weight = (int)v.getWidth();

        boxShadow.setBounds(0, 0, weight, height);
        shadowSize.set(weight, height);
        shadowTouchPoint.set((int)weight/2, (int)height/2);

    }

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

} 
+3
source share

All Articles