use of com.github.derlio.waveform.soundfile.SoundFile in project haven by guardianproject.
the class EventTriggerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(EventTriggerVH holder, int position) {
final EventTrigger eventTrigger = eventTriggers.get(position);
String title = eventTrigger.getStringType(context);
String desc = eventTrigger.getTriggerTime().toLocaleString();
holder.image.setVisibility(View.GONE);
holder.video.setVisibility(View.GONE);
holder.extra.setVisibility(View.GONE);
holder.sound.setVisibility(View.GONE);
if (eventTrigger.getPath() != null) {
switch(eventTrigger.getType()) {
case EventTrigger.CAMERA_VIDEO:
holder.video.setVisibility(View.VISIBLE);
BitmapDrawable bitmapD = new BitmapDrawable(context.getResources(), ThumbnailUtils.createVideoThumbnail(eventTrigger.getPath(), MediaStore.Video.Thumbnails.FULL_SCREEN_KIND));
holder.video.setBackground(bitmapD);
holder.video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(eventTrigger.getPath()));
intent.setDataAndType(Uri.parse(eventTrigger.getPath()), "video/*");
context.startActivity(intent);
}
});
holder.video.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
shareMedia(eventTrigger);
return false;
}
});
break;
case EventTrigger.CAMERA:
holder.image.setVisibility(View.VISIBLE);
Picasso.get().load(new File(eventTrigger.getPath())).into(holder.image);
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int startPosition = 0;
for (int i = 0; i < eventTriggerImagePaths.size(); i++) {
if (eventTriggerImagePaths.get(i).contains(eventTrigger.getPath())) {
startPosition = i;
break;
}
}
ShareOverlayView overlayView = new ShareOverlayView(context);
ImageViewer viewer = new ImageViewer.Builder(context, eventTriggerImagePaths).setStartPosition(startPosition).setOverlayView(overlayView).show();
overlayView.setImageViewer(viewer);
}
});
holder.image.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
shareMedia(eventTrigger);
return false;
}
});
break;
case EventTrigger.MICROPHONE:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
holder.sound.setVisibility(View.VISIBLE);
final File fileSound = new File(eventTrigger.getPath());
try {
final SoundFile soundFile = SoundFile.create(fileSound.getPath(), new SoundFile.ProgressListener() {
int lastProgress = 0;
@Override
public boolean reportProgress(double fractionComplete) {
final int progress = (int) (fractionComplete * 100);
if (lastProgress == progress) {
return true;
}
lastProgress = progress;
return true;
}
});
holder.sound.setAudioFile(soundFile);
holder.sound.invalidate();
} catch (Exception e) {
}
holder.extra.setVisibility(View.VISIBLE);
holder.extra.removeAllViews();
AudioWife audioWife = new AudioWife();
audioWife.init(context, Uri.fromFile(fileSound)).useDefaultUi(holder.extra, inflater);
break;
case EventTrigger.ACCELEROMETER:
desc += "\n" + context.getString(R.string.data_speed) + ": " + eventTrigger.getPath();
break;
case EventTrigger.LIGHT:
desc += "\n" + context.getString(R.string.data_light) + ": " + eventTrigger.getPath();
break;
case EventTrigger.PRESSURE:
desc += "\n" + context.getString(R.string.data_pressure) + ": " + eventTrigger.getPath();
break;
case EventTrigger.POWER:
desc += "\n" + context.getString(R.string.data_power) + ": " + eventTrigger.getPath();
break;
}
}
holder.title.setText(title);
holder.note.setText(desc);
}
Aggregations