Search in sources :

Example 6 with EventTrigger

use of org.havenapp.main.model.EventTrigger in project haven by guardianproject.

the class EventActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_event);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    StrictMode.setVmPolicy(StrictMode.VmPolicy.LAX);
    long eventId = getIntent().getLongExtra("eventid", -1);
    if (eventId != -1) {
        mEvent = Event.findById(Event.class, eventId);
        mRecyclerView = findViewById(R.id.event_trigger_list);
        setTitle(mEvent.getStartTime().toLocaleString());
        mAdapter = new EventTriggerAdapter(this, mEvent.getEventTriggers());
        LinearLayoutManager llm = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(llm);
        mRecyclerView.setAdapter(mAdapter);
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                shareEvent();
            }
        });
        // Handling swipe to delete
        ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                return false;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                // Remove swiped item from list and notify the RecyclerView
                final int position = viewHolder.getAdapterPosition();
                final EventTrigger eventTrigger = mEvent.getEventTriggers().get(viewHolder.getAdapterPosition());
                deleteEventTrigger(eventTrigger, position);
            }
        };
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
        itemTouchHelper.attachToRecyclerView(mRecyclerView);
    } else
        finish();
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Event(org.havenapp.main.model.Event) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar) EventTrigger(org.havenapp.main.model.EventTrigger)

Example 7 with EventTrigger

use of org.havenapp.main.model.EventTrigger 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

EventTrigger (org.havenapp.main.model.EventTrigger)7 File (java.io.File)3 Event (org.havenapp.main.model.Event)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ArrayList (java.util.ArrayList)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 SmsManager (android.telephony.SmsManager)1 LayoutInflater (android.view.LayoutInflater)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