private boolean updateContentProvider() { /* remove from ContentProvider */ Iterator<Uri> eu = uriList.iterator(); while (eu.hasNext()) { Uri fileUri = eu.next(); File file = UriUtils.getFileFromUri(fileUri, this); Log.d("gallorg", "uri: " + fileUri.toString()); if (file.exists() == false && fileUri.getScheme().equals("content")) { int count = getContentResolver().delete(fileUri, null, null); Log.i( "gallorg", "deleted " + Integer.toString(count) + " record(s) from content provider."); } else if (!fileUri.getScheme().equals("content")) { Log.i("gallorg", "scheme of file is not 'content'. (" + fileUri.getScheme() + ") ignore."); /* XXX how can i alert/broadcast file deletion to parent program? */ } else { /* maybe on case of ERROR or COPYing. */ Log.i( "gallorg", "selected file(" + file.getName() + ") yet exist. cancel record deletion."); } } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayList<String> dirStringList = new ArrayList<String>(); setContentView(R.layout.share); TextView tv = (TextView) findViewById(R.id.filelist); TextView amount = (TextView) findViewById(R.id.amount_of_files); AutoCompleteTextView destination = (AutoCompleteTextView) findViewById(R.id.destination); Spinner exists = (Spinner) findViewById(R.id.exists); /* set default options */ // ((CheckBox) findViewById(R.id.copy)).setChecked(false); /* get existing album(directory) list from ORION_ROOT */ File rootDir = new File(ORION_ROOT); if (rootDir.exists() && rootDir.isDirectory()) { ArrayList<File> dirList = new ArrayList<File>(Arrays.asList(rootDir.listFiles())); Iterator<File> e = dirList.iterator(); while (e.hasNext()) { dirStringList.add(((File) e.next()).getName()); } } /* sort and insert default destinations. */ Collections.sort(dirStringList); SimpleDateFormat nowFormatted = new SimpleDateFormat("yyyyMMdd"); default_destination = nowFormatted.format(new Date()).toString(); destination.setText(default_destination); /* remove default folder from 'existing album list'. but Camera */ dirStringList.add(0, "<Camera>"); /* make array and adapter for spinner and auto-completion. */ String[] dirArray = new String[dirStringList.size()]; dirStringList.toArray(dirArray); Log.i("gallorg", "existing dirs(array): " + Arrays.asList(dirArray).toString()); /* disabling drop-down auto-completion. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, dirArray); destination.setAdapter(adapter); */ ArrayAdapter<String> adapterSpinner = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, dirArray); exists.setAdapter(adapterSpinner); exists.setOnItemSelectedListener(this); /* get selected files and add it to src list (counting and debugging purpose.) */ Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (Intent.ACTION_SEND.equals(intent.getAction())) { if (extras != null) { Uri fileUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); fileArray.add(UriUtils.getFileFromUri(fileUri, this)); uriList.add(fileUri); } else { tv.append(", extras == null"); } } else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) { if (extras != null) { ArrayList<Uri> uriArray = extras.getParcelableArrayList(Intent.EXTRA_STREAM); uriList.addAll(uriArray); Iterator<Uri> e = uriArray.iterator(); while (e.hasNext()) { fileArray.add(UriUtils.getFileFromUri((Uri) e.next(), this)); } } else { tv.append(", extras == null"); } } /* file list for debugging. */ Iterator<File> e = fileArray.iterator(); while (e.hasNext()) { File file = (File) e.next(); if (file.exists() && file.isFile()) { tv.append("* " + file.getName()); } tv.append("\n"); } Log.d("gallorg", "selected content list: " + uriList.toString()); Log.d("gallorg", "selected file list: " + fileArray.toString()); /* display amount of selected files. */ amount.setText(Integer.toString(fileArray.size())); /* button binding. */ btnMove = (Button) findViewById(R.id.ok); btnCancel = (Button) findViewById(R.id.cancel); btnMove.setOnClickListener(this); btnCancel.setOnClickListener(this); }