use of android.content.res.AssetFileDescriptor in project Zom-Android by zom.
the class MessageListItem method bindOutgoingMessage.
public void bindOutgoingMessage(MessageViewHolder holder, int id, int messageType, String address, final String mimeType, final String body, Date date, Markup smileyRes, boolean scrolling, DeliveryState delivery, EncryptionState encryption, String packetId) {
mHolder = holder;
applyStyleColors();
mHolder.mTextViewForMessages.setVisibility(View.VISIBLE);
mHolder.mAudioContainer.setVisibility(View.GONE);
mHolder.mMediaContainer.setVisibility(View.GONE);
mHolder.resetOnClickListenerMediaThumbnail();
this.packetId = packetId;
lastMessage = body;
if (mimeType != null) {
String mediaPath = body;
if (body.contains(" "))
mediaPath = body.split(" ")[0];
Uri mediaUri = Uri.parse(mediaPath);
if (mimeType.startsWith("audio")) {
try {
mHolder.mAudioContainer.setVisibility(View.VISIBLE);
showAudioPlayer(mimeType, mediaUri, id, mHolder, mHolder.mLayoutInflater);
} catch (Exception e) {
mHolder.mAudioContainer.setVisibility(View.GONE);
}
} else {
mHolder.mTextViewForMessages.setVisibility(View.GONE);
mHolder.mMediaContainer.setVisibility(View.VISIBLE);
boolean isJpeg = mimeType.contains("jpg") || mimeType.contains("jpeg");
showMediaThumbnail(mimeType, mediaUri, id, mHolder, isJpeg);
}
} else if ((!TextUtils.isEmpty(lastMessage)) && (lastMessage.charAt(0) == '/' || lastMessage.charAt(0) == ':')) {
// String cmd = lastMessage.toString().substring(1);
boolean cmdSuccess = false;
if (lastMessage.startsWith("/sticker:")) {
String[] cmds = lastMessage.split(":");
String mimeTypeSticker = "image/png";
try {
// make sure sticker exists
AssetFileDescriptor afd = getContext().getAssets().openFd(cmds[1]);
afd.getLength();
afd.close();
// now setup the new URI for loading local sticker asset
Uri mediaUri = Uri.parse("asset://localhost/" + cmds[1].toLowerCase());
// now load the thumbnail
cmdSuccess = showMediaThumbnail(mimeTypeSticker, mediaUri, id, mHolder, false);
} catch (Exception e) {
cmdSuccess = false;
}
} else if (lastMessage.startsWith(":")) {
String[] cmds = lastMessage.split(":");
String mimeTypeSticker = "image/png";
try {
String[] stickerParts = cmds[1].split("-");
String folder = stickerParts[0];
StringBuffer name = new StringBuffer();
for (int i = 1; i < stickerParts.length; i++) {
name.append(stickerParts[i]);
if (i + 1 < stickerParts.length)
name.append('-');
}
String stickerPath = "stickers/" + folder + "/" + name.toString() + ".png";
// make sure sticker exists
AssetFileDescriptor afd = getContext().getAssets().openFd(stickerPath);
afd.getLength();
afd.close();
// now setup the new URI for loading local sticker asset
Uri mediaUri = Uri.parse("asset://localhost/" + stickerPath);
// now load the thumbnail
cmdSuccess = showMediaThumbnail(mimeTypeSticker, mediaUri, id, mHolder, false);
} catch (Exception e) {
cmdSuccess = false;
}
}
if (!cmdSuccess) {
mHolder.mTextViewForMessages.setText(new SpannableString(lastMessage));
} else {
holder.mContainer.setBackgroundResource(android.R.color.transparent);
}
} else {
mHolder.mTextViewForMessages.setText(new SpannableString(lastMessage));
}
if (isSelected())
mHolder.mContainer.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright));
if (date != null) {
CharSequence tsText = formatTimeStamp(date, messageType, delivery, encryption, null);
mHolder.mTextViewForTimestamp.setText(tsText);
mHolder.mTextViewForTimestamp.setVisibility(View.VISIBLE);
} else {
mHolder.mTextViewForTimestamp.setText("");
}
if (linkify)
LinkifyHelper.addLinks(mHolder.mTextViewForMessages, new URLSpanConverter());
LinkifyHelper.addTorSafeLinks(mHolder.mTextViewForMessages);
}
use of android.content.res.AssetFileDescriptor in project Zom-Android by zom.
the class MessageListItem method bindIncomingMessage.
public void bindIncomingMessage(MessageViewHolder holder, int id, int messageType, String address, String nickname, final String mimeType, final String body, Date date, Markup smileyRes, boolean scrolling, EncryptionState encryption, boolean showContact, int presenceStatus, IChatSession session, String packetId) {
mHolder = holder;
applyStyleColors();
mHolder.mTextViewForMessages.setVisibility(View.VISIBLE);
mHolder.mAudioContainer.setVisibility(View.GONE);
mHolder.mMediaContainer.setVisibility(View.GONE);
this.packetId = packetId;
if (nickname == null)
nickname = address;
lastMessage = formatMessage(body);
showAvatar(address, nickname, true, presenceStatus);
mHolder.resetOnClickListenerMediaThumbnail();
boolean cmdSuccess = false;
if (mimeType != null) {
Uri mediaUri = Uri.parse(body);
lastMessage = body;
if (mediaUri != null && mediaUri.getScheme() != null) {
if (mimeType.startsWith("audio")) {
try {
mHolder.mAudioContainer.setVisibility(View.VISIBLE);
showAudioPlayer(mimeType, mediaUri, id, mHolder, mHolder.mLayoutInflater);
cmdSuccess = true;
} catch (Exception e) {
mHolder.mAudioContainer.setVisibility(View.GONE);
}
} else {
mHolder.mTextViewForMessages.setVisibility(View.GONE);
boolean isJpeg = mimeType.contains("jpg") || mimeType.contains("jpeg");
cmdSuccess = showMediaThumbnail(mimeType, mediaUri, id, mHolder, isJpeg);
mHolder.mMediaContainer.setVisibility(View.VISIBLE);
}
}
} else if ((!TextUtils.isEmpty(lastMessage)) && (lastMessage.charAt(0) == '/' || lastMessage.charAt(0) == ':' || lastMessage.startsWith("aesgcm://"))) {
if (lastMessage.startsWith("/sticker:")) {
String[] cmds = lastMessage.split(":");
String mimeTypeSticker = "image/png";
try {
// just get up to any whitespace;
String assetPath = cmds[1].split(" ")[0].toLowerCase();
// make sure sticker exists
AssetFileDescriptor afd = getContext().getAssets().openFd(assetPath);
afd.getLength();
afd.close();
// now setup the new URI for loading local sticker asset
Uri mediaUri = Uri.parse("asset://localhost/" + assetPath);
// now load the thumbnail
cmdSuccess = showMediaThumbnail(mimeTypeSticker, mediaUri, id, mHolder, false);
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "error loading sticker bitmap: " + cmds[1], e);
cmdSuccess = false;
}
} else if (lastMessage.startsWith(":")) {
String[] cmds = lastMessage.split(":");
String mimeTypeSticker = "image/png";
try {
String[] stickerParts = cmds[1].split("-");
String folder = stickerParts[0];
StringBuffer name = new StringBuffer();
for (int i = 1; i < stickerParts.length; i++) {
name.append(stickerParts[i]);
if (i + 1 < stickerParts.length)
name.append('-');
}
String stickerPath = "stickers/" + folder + "/" + name.toString() + ".png";
// make sure sticker exists
AssetFileDescriptor afd = getContext().getAssets().openFd(stickerPath);
afd.getLength();
afd.close();
// now setup the new URI for loading local sticker asset
Uri mediaUri = Uri.parse("asset://localhost/" + stickerPath);
// now load the thumbnail
cmdSuccess = showMediaThumbnail(mimeTypeSticker, mediaUri, id, mHolder, false);
} catch (Exception e) {
cmdSuccess = false;
}
} else if (lastMessage.startsWith("aesgcm://")) {
// now load the thumbnail
cmdSuccess = showDownloadThumbnail(lastMessage, id, mHolder, session, packetId);
}
if (!cmdSuccess) {
mHolder.mTextViewForMessages.setText(new SpannableString(lastMessage));
} else {
mHolder.mContainer.setBackgroundResource(android.R.color.transparent);
}
} else if (!TextUtils.isEmpty(lastMessage)) {
mHolder.mTextViewForMessages.setText(new SpannableString(lastMessage));
}
if (date != null) {
String contact = null;
if (showContact) {
if (nickname != null) {
String[] nickParts = nickname.split("/");
contact = nickParts[nickParts.length - 1];
}
}
CharSequence tsText = formatTimeStamp(date, messageType, null, encryption, contact);
mHolder.mTextViewForTimestamp.setText(tsText);
mHolder.mTextViewForTimestamp.setVisibility(View.VISIBLE);
} else {
mHolder.mTextViewForTimestamp.setText("");
}
if (linkify)
LinkifyHelper.addLinks(mHolder.mTextViewForMessages, new URLSpanConverter());
if (isSelected())
mHolder.mContainer.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright));
}
use of android.content.res.AssetFileDescriptor in project silverblog_android by SilverBlogTeam.
the class CaptureActivity method initBeepSound.
private void initBeepSound() {
if (playBeep && mediaPlayer == null) {
// The volume on STREAM_SYSTEM is not adjustable, and users found it
// too loud,
// so we now play on the music stream.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(beepListener);
AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
file.close();
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
} catch (IOException e) {
mediaPlayer = null;
}
}
}
use of android.content.res.AssetFileDescriptor in project android-database-sqlcipher by sqlcipher.
the class SQLiteContentHelper method getBlobColumnAsAssetFile.
/**
* Runs an SQLite query and returns an AssetFileDescriptor for the
* blob in column 0 of the first row. If the first column does
* not contain a blob, an unspecified exception is thrown.
*
* @param db Handle to a readable database.
* @param sql SQL query, possibly with query arguments.
* @param selectionArgs Query argument values, or {@code null} for no argument.
* @return If no exception is thrown, a non-null AssetFileDescriptor is returned.
* @throws FileNotFoundException If the query returns no results or the
* value of column 0 is NULL, or if there is an error creating the
* asset file descriptor.
*/
public static AssetFileDescriptor getBlobColumnAsAssetFile(SQLiteDatabase db, String sql, String[] selectionArgs) throws FileNotFoundException {
android.os.ParcelFileDescriptor fd = null;
try {
MemoryFile file = simpleQueryForBlobMemoryFile(db, sql, selectionArgs);
if (file == null) {
throw new FileNotFoundException("No results.");
}
Class c = file.getClass();
try {
java.lang.reflect.Method m = c.getDeclaredMethod("getParcelFileDescriptor");
m.setAccessible(true);
fd = (android.os.ParcelFileDescriptor) m.invoke(file);
} catch (Exception e) {
android.util.Log.i("SQLiteContentHelper", "SQLiteCursor.java: " + e);
}
AssetFileDescriptor afd = new AssetFileDescriptor(fd, 0, file.length());
return afd;
} catch (IOException ex) {
throw new FileNotFoundException(ex.toString());
}
}
use of android.content.res.AssetFileDescriptor in project android-app by eoecn.
the class CaptureActivity method initBeepSound.
/**
* 扫描正确后的震动声音,如果感觉apk大了,可以删除
*/
private void initBeepSound() {
if (playBeep && mediaPlayer == null) {
// The volume on STREAM_SYSTEM is not adjustable, and users found it
// too loud,
// so we now play on the music stream.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(beepListener);
AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
file.close();
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
} catch (IOException e) {
mediaPlayer = null;
}
}
}
Aggregations