List of usage examples for android.content Intent EXTRA_STREAM
String EXTRA_STREAM
To view the source code for android.content Intent EXTRA_STREAM.
Click Source Link
From source file:com.silentcircle.contacts.detail.ContactLoaderFragment.java
private void setShareIntent() { if (mShareActionProvider != null) { long rawContactId = ContentUris.parseId(mLookupUri); Uri shareUri = ContentUris.withAppendedId(RawContacts.CONTENT_VCARD_URI, rawContactId); // (RawContacts.CONTENT_VCARD_URI, lookupKey); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/x-vcard"); // RawContacts.CONTENT_VCARD_TYPE is not supported by standard Bluetooth sender app // intent.setType(RawContacts.CONTENT_VCARD_TYPE); intent.putExtra(Intent.EXTRA_STREAM, shareUri); mShareActionProvider.setShareIntent(intent); }//from w ww. j a va 2 s .co m }
From source file:com.kanchi.periyava.old.Activity.MainActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.radio: // RunRadio(item); break;//from w w w .jav a 2s .c o m case R.id.share: case R.id.feedback: // TODO Auto-generated method stub takeScreenshot(); Uri uri = null; try { File F = new File(Environment.getExternalStorageDirectory() + "/screenshot.png"); uri = Uri.fromFile(F); } catch (Exception e) { e.printStackTrace(); } Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (uri != null) { emailIntent.setType("image/png"); emailIntent.putExtra(Intent.EXTRA_STREAM, uri); } startActivity(Intent.createChooser(emailIntent, "Share Using...")); break; case android.R.id.home: { return mDrawerToggle.onOptionsItemSelected(item); } } return super.onOptionsItemSelected(item); }
From source file:de.tap.easy_xkcd.fragments.comics.ComicFragment.java
protected void shareComicImage(Uri uri, Comic comic) { Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM, uri); share.putExtra(Intent.EXTRA_SUBJECT, comic.getComicData()[0]); if (prefHelper.shareAlt()) { share.putExtra(Intent.EXTRA_TEXT, comic.getComicData()[1]); }/* ww w.j av a2 s. c o m*/ startActivity(Intent.createChooser(share, this.getResources().getString(R.string.share_image))); }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (resultCode != RESULT_OK) return;/* www . j a v a 2 s.c o m*/ switch (requestCode) { case SELECT_FILE_REQ: // clear previous data mFilePath = null; mFileStreamUri = null; // and read new one final Uri uri = data.getData(); /* * The URI returned from application may be in 'file' or 'content' schema. * 'File' schema allows us to create a File object and read details from if directly. * * Data from 'Content' schema must be read by Content Provider. To do that we are using a Loader. */ if (uri.getScheme().equals("file")) { // the direct path to the file has been returned final String path = uri.getPath(); final File file = new File(path); mFilePath = path; mFileNameView.setText(file.getName()); mFileSizeView.setText(getString(R.string.dfu_file_size_text, file.length())); final boolean isHexFile = mStatusOk = MimeTypeMap.getFileExtensionFromUrl(path) .equalsIgnoreCase("HEX"); mFileStatusView.setText(isHexFile ? R.string.dfu_file_status_ok : R.string.dfu_file_status_invalid); mUploadButton.setEnabled(mSelectedDevice != null && isHexFile); } else if (uri.getScheme().equals("content")) { // an Uri has been returned mFileStreamUri = uri; // if application returned Uri for streaming, let's us it. Does it works? // FIXME both Uris works with Google Drive app. Why both? What's the difference? How about other apps like DropBox? final Bundle extras = data.getExtras(); if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)) mFileStreamUri = extras.getParcelable(Intent.EXTRA_STREAM); // file name and size must be obtained from Content Provider final Bundle bundle = new Bundle(); bundle.putParcelable(EXTRA_URI, uri); getSupportLoaderManager().restartLoader(0, bundle, this); } break; default: break; } }
From source file:com.sentaroh.android.DriveRecorder.Log.LogFileListDialogFragment.java
private void sendLogFile(final LogFileListAdapter lfm_adapter) { final String zip_file_name = mGlblParms.settingsLogFileDir + "log.zip"; int no_of_files = 0; for (int i = 0; i < lfm_adapter.getCount(); i++) { if (lfm_adapter.getItem(i).isChecked) no_of_files++;// ww w . j a v a 2s.c o m } final String[] file_name = new String[no_of_files]; int files_pos = 0; for (int i = 0; i < lfm_adapter.getCount(); i++) { if (lfm_adapter.getItem(i).isChecked) { file_name[files_pos] = lfm_adapter.getItem(i).log_file_path; files_pos++; } } final ThreadCtrl tc = new ThreadCtrl(); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { } @Override public void negativeResponse(Context c, Object[] o) { tc.setDisabled(); } }); final ProgressBarDialogFragment pbdf = ProgressBarDialogFragment.newInstance( mContext.getString(R.string.msgs_log_file_list_dlg_send_zip_file_creating), "", mContext.getString(R.string.msgs_common_dialog_cancel), mContext.getString(R.string.msgs_common_dialog_cancel)); pbdf.showDialog(getFragmentManager(), pbdf, ntfy, true); Thread th = new Thread() { @Override public void run() { File lf = new File(zip_file_name); lf.delete(); MiscUtil.createZipFile(tc, pbdf, zip_file_name, file_name); if (tc.isEnabled()) { Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_SEND); // intent.setType("message/rfc822"); // intent.setType("text/plain"); intent.setType("application/zip"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(lf)); mFragment.getActivity().startActivity(intent); } else { lf.delete(); MessageDialogFragment mdf = MessageDialogFragment.newInstance(false, "W", mContext.getString(R.string.msgs_log_file_list_dlg_send_zip_file_cancelled), ""); mdf.showDialog(mFragment.getFragmentManager(), mdf, null); } pbdf.dismiss(); }; }; th.start(); }
From source file:com.fa.mastodon.activity.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose); ButterKnife.bind(this); // Setup the toolbar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w ww . j a v a2 s .c om*/ ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(null); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp); ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint); actionBar.setHomeAsUpIndicator(closeIcon); } // Setup the interface buttons. floatingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSendClicked(); } }); pickBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onMediaPick(); } }); takeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCameraApp(); } }); nsfwBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleNsfw(); } }); visibilityBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showComposeOptions(); } }); /* Initialise all the state, or restore it from a previous run, to determine a "starting" * state. */ SharedPreferences preferences = getPrivatePreferences(); String startingVisibility; boolean startingHideText; String startingContentWarning = null; ArrayList<SavedQueuedMedia> savedMediaQueued = null; if (savedInstanceState != null) { showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); startingVisibility = savedInstanceState.getString("statusVisibility"); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); startingHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued"); // These are for restoring an in-progress commit content operation. InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo")); int previousFlags = savedInstanceState.getInt("commitContentFlags"); if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } } else { showMarkSensitive = false; startingVisibility = preferences.getString("rememberedVisibility", "public"); statusMarkSensitive = false; startingHideText = false; } /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ Intent intent = getIntent(); String[] mentionedUsernames = null; inReplyToId = null; if (intent != null) { inReplyToId = intent.getStringExtra("in_reply_to_id"); String replyVisibility = intent.getStringExtra("reply_visibility"); if (replyVisibility != null && startingVisibility != null) { // Lowest possible visibility setting in response if (startingVisibility.equals("private") || replyVisibility.equals("private")) { startingVisibility = "private"; } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) { startingVisibility = "unlisted"; } else { startingVisibility = replyVisibility; } } mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames"); if (inReplyToId != null) { startingHideText = !intent.getStringExtra("content_warning").equals(""); if (startingHideText) { startingContentWarning = intent.getStringExtra("content_warning"); } } } /* If the currently logged in account is locked, its posts should default to private. This * should override even the reply settings, so this must be done after those are set up. */ if (preferences.getBoolean("loggedInAccountLocked", false)) { startingVisibility = "private"; } // After the starting state is finalised, the interface can be set to reflect this state. setStatusVisibility(startingVisibility); postProgress.setVisibility(View.INVISIBLE); updateNsfwButtonColor(); // Setup the main text field. setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" } final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color); SpanUtils.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable editable) { SpanUtils.highlightSpans(editable, mentionColour); } }); // Add any mentions to the text field when a reply is first composed. if (mentionedUsernames != null) { StringBuilder builder = new StringBuilder(); for (String name : mentionedUsernames) { builder.append('@'); builder.append(name); builder.append(' '); } textEditor.setText(builder); textEditor.setSelection(textEditor.length()); } // Initialise the content warning editor. contentWarningEditor.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void afterTextChanged(Editable s) { } }); showContentWarning(startingHideText); if (startingContentWarning != null) { contentWarningEditor.setText(startingContentWarning); } // Initialise the empty media queue state. mediaQueued = new ArrayList<>(); waitForMediaLatch = new CountUpDownLatch(); statusAlreadyInFlight = false; // These can only be added after everything affected by the media queue is initialized. if (savedMediaQueued != null) { for (SavedQueuedMedia item : savedMediaQueued) { addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); } } else if (intent != null && savedInstanceState == null) { /* Get incoming images being sent through a share action from another app. Only do this * when savedInstanceState is null, otherwise both the images from the intent and the * instance state will be re-queued. */ String type = intent.getType(); if (type != null) { if (type.startsWith("image/")) { List<Uri> uriList = new ArrayList<>(); switch (intent.getAction()) { case Intent.ACTION_SEND: { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { uriList.add(uri); } break; } case Intent.ACTION_SEND_MULTIPLE: { ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Uri uri : list) { if (uri != null) { uriList.add(uri); } } } break; } } for (Uri uri : uriList) { long mediaSize = getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (type.equals("text/plain")) { String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text != null) { int start = Math.max(textEditor.getSelectionStart(), 0); int end = Math.max(textEditor.getSelectionEnd(), 0); int left = Math.min(start, end); int right = Math.max(start, end); textEditor.getText().replace(left, right, text, 0, text.length()); } } } } } }
From source file:com.groksolutions.grok.mobile.GrokActivity.java
/** * Send user feedback via email with pre-populated email address, screen capture and optional * upload identifier/*w w w. ja va 2 s . com*/ * <p/> * * @param uploadId the identifier of the uploaded information; null if none */ protected void emailFeedback(final CharSequence uploadId) { Intent feedbackIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { getResources().getText(R.string.feedback_email_address).toString() }); String subject = getResources().getText(R.string.feedback_email_subject).toString(); feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, subject); feedbackIntent.setType("message/rfc822"); ArrayList<Uri> uris = new ArrayList<Uri>(); uris.add(takeScreenCapture(true)); if (uploadId != null) { uris.add(writeTextFileToSend(uploadId.toString())); } feedbackIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(feedbackIntent, getResources().getText(R.string.title_feedback))); }
From source file:net.maa123.tatuky.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose); ButterKnife.bind(this); // Setup the toolbar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);// w w w .ja v a 2 s . c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(null); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp); ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint); actionBar.setHomeAsUpIndicator(closeIcon); } // Setup the interface buttons. floatingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSendClicked(); } }); pickBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onMediaPick(); } }); takeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCameraApp(); } }); nsfwBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleNsfw(); } }); visibilityBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showComposeOptions(); } }); /* Initialise all the state, or restore it from a previous run, to determine a "starting" * state. */ SharedPreferences preferences = getPrivatePreferences(); String startingVisibility; boolean startingHideText; String startingContentWarning = null; ArrayList<SavedQueuedMedia> savedMediaQueued = null; if (savedInstanceState != null) { showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); startingVisibility = savedInstanceState.getString("statusVisibility"); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); startingHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued"); // These are for restoring an in-progress commit content operation. InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo")); int previousFlags = savedInstanceState.getInt("commitContentFlags"); if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } } else { showMarkSensitive = false; startingVisibility = preferences.getString("rememberedVisibility", "public"); statusMarkSensitive = false; startingHideText = false; } /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ Intent intent = getIntent(); String[] mentionedUsernames = null; inReplyToId = null; if (intent != null) { inReplyToId = intent.getStringExtra("in_reply_to_id"); String replyVisibility = intent.getStringExtra("reply_visibility"); if (replyVisibility != null && startingVisibility != null) { // Lowest possible visibility setting in response if (startingVisibility.equals("direct") || replyVisibility.equals("direct")) { startingVisibility = "direct"; } else if (startingVisibility.equals("private") || replyVisibility.equals("private")) { startingVisibility = "private"; } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) { startingVisibility = "unlisted"; } else { startingVisibility = replyVisibility; } } mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames"); if (inReplyToId != null) { startingHideText = !intent.getStringExtra("content_warning").equals(""); if (startingHideText) { startingContentWarning = intent.getStringExtra("content_warning"); } } } /* If the currently logged in account is locked, its posts should default to private. This * should override even the reply settings, so this must be done after those are set up. */ if (preferences.getBoolean("loggedInAccountLocked", false)) { startingVisibility = "private"; } // After the starting state is finalised, the interface can be set to reflect this state. setStatusVisibility(startingVisibility); postProgress.setVisibility(View.INVISIBLE); updateNsfwButtonColor(); // Setup the main text field. setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" } final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color); SpanUtils.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable editable) { SpanUtils.highlightSpans(editable, mentionColour); } }); // Add any mentions to the text field when a reply is first composed. if (mentionedUsernames != null) { StringBuilder builder = new StringBuilder(); for (String name : mentionedUsernames) { builder.append('@'); builder.append(name); builder.append(' '); } textEditor.setText(builder); textEditor.setSelection(textEditor.length()); } // Initialise the content warning editor. contentWarningEditor.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void afterTextChanged(Editable s) { } }); showContentWarning(startingHideText); if (startingContentWarning != null) { contentWarningEditor.setText(startingContentWarning); } // Initialise the empty media queue state. mediaQueued = new ArrayList<>(); waitForMediaLatch = new CountUpDownLatch(); statusAlreadyInFlight = false; // These can only be added after everything affected by the media queue is initialized. if (savedMediaQueued != null) { for (SavedQueuedMedia item : savedMediaQueued) { addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); } } else if (intent != null && savedInstanceState == null) { /* Get incoming images being sent through a share action from another app. Only do this * when savedInstanceState is null, otherwise both the images from the intent and the * instance state will be re-queued. */ String type = intent.getType(); if (type != null) { if (type.startsWith("image/")) { List<Uri> uriList = new ArrayList<>(); switch (intent.getAction()) { case Intent.ACTION_SEND: { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { uriList.add(uri); } break; } case Intent.ACTION_SEND_MULTIPLE: { ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Uri uri : list) { if (uri != null) { uriList.add(uri); } } } break; } } for (Uri uri : uriList) { long mediaSize = getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (type.equals("text/plain")) { String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text != null) { int start = Math.max(textEditor.getSelectionStart(), 0); int end = Math.max(textEditor.getSelectionEnd(), 0); int left = Math.min(start, end); int right = Math.max(start, end); textEditor.getText().replace(left, right, text, 0, text.length()); } } } } } }
From source file:de.baumann.hhsmoodle.data_files.Files_Fragment.java
public void setFilesList() { getActivity().deleteDatabase("files_DB_v01.db"); File f = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath() + "/HHS_Moodle/")); final File[] files = f.listFiles(); // looping through all items <item> if (files.length == 0) { Snackbar.make(lv, R.string.toast_files, Snackbar.LENGTH_LONG).show(); }/* w w w.ja v a2 s. c om*/ for (File file : files) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String file_Name = file.getName(); String file_Size = getReadableFileSize(file.length()); String file_date = formatter.format(new Date(file.lastModified())); String file_path = file.getAbsolutePath(); String file_ext; if (file.isDirectory()) { file_ext = "."; } else { file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); } db.open(); if (db.isExist(file_Name)) { Log.i(TAG, "Entry exists" + file_Name); } else { db.insert(file_Name, file_Size, file_ext, file_path, file_date); } } try { db.insert("...", "", "", "", ""); } catch (Exception e) { Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "files_title", "files_content", "files_creation" }; final Cursor row = db.fetchAllData(getActivity()); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); View v = super.getView(position, convertView, parent); final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes); iv.setVisibility(View.VISIBLE); if (pathFile.isDirectory()) { iv.setImageResource(R.drawable.folder); } else { switch (files_icon) { case "": new Handler().postDelayed(new Runnable() { public void run() { iv.setImageResource(R.drawable.arrow_up); } }, 200); break; case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".JPG": case ".jpeg": try { Glide.with(getActivity()).load(files_attachment) // or URI/path .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_image); } break; case ".m3u8": case ".mp3": case ".wma": case ".midi": case ".wav": case ".aac": case ".aif": case ".amp3": case ".weba": case ".ogg": iv.setImageResource(R.drawable.file_music); break; case ".mpeg": case ".mp4": case ".webm": case ".qt": case ".3gp": case ".3g2": case ".avi": case ".f4v": case ".flv": case ".h261": case ".h263": case ".h264": case ".asf": case ".wmv": try { Glide.with(getActivity()).load(files_attachment) // or URI/path .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_video); } break; case ".vcs": case ".vcf": case ".css": case ".ics": case ".conf": case ".config": case ".java": case ".html": iv.setImageResource(R.drawable.file_xml); break; case ".apk": iv.setImageResource(R.drawable.android); break; case ".pdf": iv.setImageResource(R.drawable.file_pdf); break; case ".rtf": case ".csv": case ".txt": case ".doc": case ".xls": case ".ppt": case ".docx": case ".pptx": case ".xlsx": case ".odt": case ".ods": case ".odp": iv.setImageResource(R.drawable.file_document); break; case ".zip": case ".rar": iv.setImageResource(R.drawable.zip_box); break; default: iv.setImageResource(R.drawable.file); break; } } return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_filesBY", "files_title"); sharedPref.edit().putString("filter_filesBY", "files_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { try { sharedPref.edit().putString("files_startFolder", files_attachment).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_attachment.equals("")) { try { final File pathActual = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath())); sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else { helper_main.openAtt(getActivity(), lv, files_attachment); } } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { Snackbar snackbar = Snackbar.make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { sharedPref.edit().putString("files_startFolder", pathFile.getParent()).apply(); deleteRecursive(pathFile); setFilesList(); } }); snackbar.show(); } else { final CharSequence[] options = { getString(R.string.choose_menu_2), getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) }; final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); dialog.setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.choose_menu_2))) { if (pathFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title); Uri bmpUri = Uri.fromFile(pathFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_file)))); } } if (options[item].equals(getString(R.string.choose_menu_4))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { pathFile.delete(); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.choose_menu_3))) { android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder( getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_file, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setText(files_title); builder.setView(dialogView); builder.setTitle(R.string.choose_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); File dir = pathFile.getParentFile(); File to = new File(dir, inputTag); pathFile.renameTo(to); pathFile.delete(); setFilesList(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } } }); dialog.show(); } return true; } }); }
From source file:de.baumann.browser.popups.Popup_files.java
private void setFilesList() { deleteDatabase("files_DB_v01.db"); File f = new File(sharedPref.getString("files_startFolder", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())); final File[] files = f.listFiles(); Arrays.sort(files, new Comparator<File>() { @Override// w w w . j a va 2s . c om public int compare(File file1, File file2) { if (file1.isDirectory()) { if (file2.isDirectory()) { return String.valueOf(file1.getName().toLowerCase()) .compareTo(file2.getName().toLowerCase()); } else { return -1; } } else { if (file2.isDirectory()) { return 1; } else { return String.valueOf(file1.getName().toLowerCase()) .compareTo(file2.getName().toLowerCase()); } } } }); // looping through all items <item> if (files.length == 0) { Snackbar.make(listView, R.string.toast_files, Snackbar.LENGTH_LONG).show(); } for (File file : files) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String file_Name = file.getName().substring(0, 1).toUpperCase() + file.getName().substring(1); String file_Size = getReadableFileSize(file.length()); String file_date = formatter.format(new Date(file.lastModified())); String file_path = file.getAbsolutePath(); String file_ext; if (file.isDirectory()) { file_ext = "."; } else { file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); } db.open(); if (db.isExist(file_Name)) { Log.i(TAG, "Entry exists" + file_Name); } else { db.insert(file_Name, file_Size, file_ext, file_path, file_date); } } try { db.insert("...", "", "", "", ""); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "files_title", "files_content", "files_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); View v = super.getView(position, convertView, parent); final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes); iv.setVisibility(View.VISIBLE); if (pathFile.isDirectory()) { iv.setImageResource(R.drawable.folder); } else { switch (files_icon) { case "": iv.setImageResource(R.drawable.arrow_up_dark); break; case ".m3u8": case ".mp3": case ".wma": case ".midi": case ".wav": case ".aac": case ".aif": case ".amp3": case ".weba": case ".ogg": iv.setImageResource(R.drawable.file_music); break; case ".mpeg": case ".mp4": case ".webm": case ".qt": case ".3gp": case ".3g2": case ".avi": case ".f4v": case ".flv": case ".h261": case ".h263": case ".h264": case ".asf": case ".wmv": try { Glide.with(Popup_files.this).load(files_attachment) // or URI/path .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_video); } break; case ".vcs": case ".vcf": case ".css": case ".ics": case ".conf": case ".config": case ".java": case ".html": iv.setImageResource(R.drawable.file_xml); break; case ".apk": iv.setImageResource(R.drawable.android); break; case ".pdf": iv.setImageResource(R.drawable.file_pdf); break; case ".rtf": case ".csv": case ".txt": case ".doc": case ".xls": case ".ppt": case ".docx": case ".pptx": case ".xlsx": case ".odt": case ".ods": case ".odp": iv.setImageResource(R.drawable.file_document); break; case ".zip": case ".rar": iv.setImageResource(R.drawable.zip_box); break; case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".JPG": case ".jpeg": try { Glide.with(Popup_files.this).load(files_attachment) // or URI/path .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true) .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_image); } break; default: iv.setImageResource(R.drawable.file); break; } } if (files_attachment.isEmpty()) { new Handler().postDelayed(new Runnable() { public void run() { iv.setImageResource(R.drawable.arrow_up_dark); } }, 350); } return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_filesBY", "files_title"); sharedPref.edit().putString("filter_filesBY", "files_title").apply(); editText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { try { sharedPref.edit().putString("files_startFolder", files_attachment).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_attachment.equals("")) { try { final File pathActual = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath())); sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else { helper_main.open(files_icon, Popup_files.this, pathFile, listView); } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { sharedPref.edit().putString("files_startFolder", pathFile.getParent()).apply(); deleteRecursive(pathFile); setFilesList(); } }); snackbar.show(); } else { final CharSequence[] options = { getString(R.string.choose_menu_2), getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) }; final AlertDialog.Builder dialog = new AlertDialog.Builder(Popup_files.this); dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); dialog.setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.choose_menu_2))) { if (pathFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title); Uri bmpUri = Uri.fromFile(pathFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_file)))); } } if (options[item].equals(getString(R.string.choose_menu_4))) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { pathFile.delete(); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.choose_menu_3))) { sharedPref.edit().putString("pathFile", files_attachment).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_files.this, editText, 2, files_title, getString(R.string.bookmark_edit_title)); } } }); dialog.show(); } return true; } }); }