Skip to content

Commit

Permalink
Added buttons for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyvasilyev committed Jun 27, 2020
1 parent e080185 commit ee633a3
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${kotlin_version}"
implementation "androidx.appcompat:appcompat:${androidXAppcompatVersion}"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation "androidx.navigation:navigation-fragment:${androidXNavigationVersion}"
implementation "androidx.navigation:navigation-ui:${androidXNavigationVersion}"
implementation "androidx.navigation:navigation-fragment-ktx:${androidXNavigationVersion}"
implementation "androidx.navigation:navigation-ui-ktx:${androidXNavigationVersion}"
implementation project(':library-timeline')
}
66 changes: 63 additions & 3 deletions app/src/main/java/com/alexvas/timeline/demo/ui/TimelineFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.alexvas.timeline.demo.ui

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.View
Expand All @@ -10,6 +12,7 @@ import androidx.lifecycle.ViewModelProvider
import com.alexvas.timeline.demo.R
import com.alexvas.widget.TimelineView
import com.alexvas.widget.TimelineView.TimeRecord
import kotlin.math.max

class TimelineFragment : Fragment() {

Expand Down Expand Up @@ -47,6 +50,33 @@ class TimelineFragment : Fragment() {
override fun onRequestMoreBackgroundData() {
}
})
val zoomIn = root.findViewById<View>(R.id.zoomIn)
val zoomOut = root.findViewById<View>(R.id.zoomOut)
zoomIn.setOnClickListener {
timelineView.decreaseIntervalWithAnimation()
// isMinInterval will be valid only after animation completed (150 msec)
Handler(Looper.getMainLooper()).postDelayed({
zoomIn.isEnabled = !timelineView.isMinInterval
zoomOut.isEnabled = true
}, TimelineView.ANIMATION_DURATION_MSEC + 1)
}
zoomOut.setOnClickListener {
timelineView.increaseIntervalWithAnimation()
// isMaxInterval will be valid only after animation completed (150 msec)
Handler(Looper.getMainLooper()).postDelayed({
zoomOut.isEnabled = !timelineView.isMaxInterval
zoomIn.isEnabled = true
}, TimelineView.ANIMATION_DURATION_MSEC + 1)
}
root.findViewById<View>(R.id.lastEvent).setOnClickListener {
gotoLastMajor1Record()
}
root.findViewById<View>(R.id.prevEvent).setOnClickListener {
gotoPrevRecord(true)
}
root.findViewById<View>(R.id.nextEvent).setOnClickListener {
gotoNextRecord(true)
}
return root
}

Expand Down Expand Up @@ -98,7 +128,7 @@ class TimelineFragment : Fragment() {

private fun gotoLastMajor1Record() {
if (DEBUG) Log.v(TAG, "gotoLastMajor1Record()")
var records: java.util.ArrayList<TimeRecord> = timelineView.getMajor1Records()
var records: java.util.ArrayList<TimeRecord> = timelineView.major1Records
// At least one event exists
if (records.size > 0) {
val record = records[0]
Expand All @@ -108,18 +138,48 @@ class TimelineFragment : Fragment() {
timelineView.invalidate()
} else {
// No events found. Show last video recording.
records = timelineView.getBackgroundRecords()
records = timelineView.backgroundRecords
if (records.size > 0) {
val record = records[0]
// 30 sec before video finished.
val timestamp = record.timestampMsec + Math.max(record.durationMsec - 30000, 0)
val timestamp = record.timestampMsec + max(record.durationMsec - 30000, 0)
onTimeSelected(timestamp, record)
timelineView.setCurrentWithAnimation(record.timestampMsec)
timelineView.invalidate()
}
}
}

private fun gotoPrevRecord(animation: Boolean) {
if (DEBUG) Log.v(TAG, "gotoPrevRecord(animation=$animation)")
val record: TimeRecord? = timelineView.getPrevMajorRecord()
if (record != null) {
Log.i(TAG, record.toString())
val timestamp = getTimestampFromRecord(record)
onTimeSelected(timestamp, record)
if (animation)
timelineView.setCurrentWithAnimation(record.timestampMsec)
else
timelineView.setCurrent(record.timestampMsec)
timelineView.invalidate()
}
}

private fun gotoNextRecord(animation: Boolean) {
if (DEBUG) Log.v(TAG, "gotoNextRecord(animation=$animation)")
val record: TimeRecord? = timelineView.getNextMajorRecord()
if (record != null) {
Log.i(TAG, record.toString())
val timestamp = getTimestampFromRecord(record)
onTimeSelected(timestamp, record)
if (animation)
timelineView.setCurrentWithAnimation(record.timestampMsec)
else
timelineView.setCurrent(record.timestampMsec)
timelineView.invalidate()
}
}

private fun getTimestampFromRecord(record: TimeRecord): Long {
return record.timestampMsec
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/ic_minus_black_36dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="36dp"
android:width="36dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M19,13H5V11H19V13Z" />
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/ic_plus_black_36dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="36dp"
android:width="36dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/ic_rewind_black_36dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="36dp"
android:width="36dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M11.5,12L20,18V6M11,18V6L2.5,12L11,18Z" />
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/ic_skip_forward_black_36dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="36dp"
android:width="36dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M4,5V19L11,12M18,5V19H20V5M11,5V19L18,12" />
</vector>
58 changes: 56 additions & 2 deletions app/src/main/res/layout/fragment_timeline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.TimelineFragment">

<FrameLayout
Expand All @@ -27,4 +28,57 @@

</FrameLayout>

</FrameLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/prevEvent"
android:src="@drawable/ic_rewind_black_36dp"
android:background="?attr/selectableItemBackgroundBorderless"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:rotation="180"
android:id="@+id/nextEvent"
android:src="@drawable/ic_rewind_black_36dp"
android:background="?attr/selectableItemBackgroundBorderless"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:padding="10dp"
android:id="@+id/lastEvent"
android:layout_marginEnd="10dp"
android:src="@drawable/ic_skip_forward_black_36dp"
android:background="?attr/selectableItemBackgroundBorderless"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:padding="10dp"
android:id="@+id/zoomIn"
android:src="@drawable/ic_plus_black_36dp"
android:background="?attr/selectableItemBackgroundBorderless"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/zoomOut"
android:layout_marginEnd="10dp"
android:src="@drawable/ic_minus_black_36dp"
android:background="?attr/selectableItemBackgroundBorderless"/>
</LinearLayout>
</HorizontalScrollView>

</LinearLayout>
7 changes: 4 additions & 3 deletions constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ project.ext {
compileSdkVersion = 30
buildToolsVersion = '30.0.0'
minSdkVersion = 21 // 5.0
targetSdkVersion = 30 // 10.0
releaseVersion = "1.2.0"
releaseVersionCode = 120
targetSdkVersion = 30 // 11.0
releaseVersion = "1.3.0"
releaseVersionCode = 130

androidXAnnotationVersion = '1.1.0'
androidXAppcompatVersion = '1.1.0'
androidXNavigationVersion = '2.3.0'
}

0 comments on commit ee633a3

Please sign in to comment.