Search in sources :

Example 1 with ImageViewer

use of com.stfalcon.frescoimageviewer.ImageViewer 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);
}
Also used : SoundFile(com.github.derlio.waveform.soundfile.SoundFile) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AudioWife(nl.changer.audiowife.AudioWife) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) SimpleWaveformView(com.github.derlio.waveform.SimpleWaveformView) TextView(android.widget.TextView) View(android.view.View) VideoView(android.widget.VideoView) LayoutInflater(android.view.LayoutInflater) File(java.io.File) SoundFile(com.github.derlio.waveform.soundfile.SoundFile) ImageViewer(com.stfalcon.frescoimageviewer.ImageViewer) EventTrigger(org.havenapp.main.model.EventTrigger)

Aggregations

Intent (android.content.Intent)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 VideoView (android.widget.VideoView)1 SimpleWaveformView (com.github.derlio.waveform.SimpleWaveformView)1 SoundFile (com.github.derlio.waveform.soundfile.SoundFile)1 ImageViewer (com.stfalcon.frescoimageviewer.ImageViewer)1 File (java.io.File)1 AudioWife (nl.changer.audiowife.AudioWife)1 EventTrigger (org.havenapp.main.model.EventTrigger)1