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();
}
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);
}
Aggregations