Skip to content

Commit eff1d07

Browse files
Merge pull request #124 from Omega-R/feature/video_record_intent_builder
add VideoRecord feature
2 parents a99276d + 159e58f commit eff1d07

8 files changed

Lines changed: 119 additions & 0 deletions

File tree

core/src/main/java/com/omega_r/libs/omegaintentbuilder/OmegaIntentBuilder.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,10 @@ object OmegaIntentBuilder {
176176
@JvmStatic
177177
fun showAlarms() = ShowAlarmsTimersIntentBuilder(ShowType.ALARMS)
178178

179+
/**
180+
* @return VideoRecordBuilder
181+
*/
182+
@JvmStatic
183+
fun recordVideo() = VideoRecordBuilder()
184+
179185
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.omega_r.libs.omegaintentbuilder.builders
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.provider.MediaStore
6+
7+
class VideoRecordBuilder: BaseActivityBuilder() {
8+
override fun createIntent(context: Context): Intent {
9+
return Intent(MediaStore.ACTION_VIDEO_CAPTURE);
10+
}
11+
}

examples/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<activity android:name=".TabActivity"
2525
android:label="@string/title_activity_tab"
2626
android:theme="@style/AppTheme.NoActionBar"/>
27+
<activity android:name=".VideoRecordActivity" />
2728

2829
<service android:name=".service_example.TestService" />
2930

examples/src/main/java/com/omega_r/omegaintentbuilder/MainActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
4646
findViewById(R.id.button_create_timer).setOnClickListener(this);
4747
findViewById(R.id.button_show_timers).setOnClickListener(this);
4848
findViewById(R.id.button_show_alarms).setOnClickListener(this);
49+
findViewById(R.id.button_record_video).setOnClickListener(this);
4950
}
5051

5152
@Override
@@ -117,6 +118,9 @@ public void onClick(View v) {
117118
case R.id.button_show_alarms:
118119
onShowAlarmsClicked();
119120
break;
121+
case R.id.button_record_video:
122+
onRecordVideoClicked();
123+
break;
120124
}
121125
}
122126

@@ -333,4 +337,10 @@ private void onShowAlarmsClicked() {
333337
.startActivity(this);
334338
}
335339

340+
private void onRecordVideoClicked() {
341+
OmegaIntentBuilder
342+
.activity(VideoRecordActivity.class)
343+
.startActivity(this);
344+
}
345+
336346
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.omega_r.omegaintentbuilder;
2+
3+
import android.content.Intent;
4+
import android.net.Uri;
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
import android.view.View;
8+
import android.widget.Toast;
9+
import android.widget.VideoView;
10+
11+
import com.omega_r.libs.omegaintentbuilder.OmegaIntentBuilder;
12+
import com.omega_r.libs.omegaintentbuilder.handlers.ActivityResultCallback;
13+
import com.omega_r.libs.omegaintentbuilder.handlers.FailCallback;
14+
15+
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
public class VideoRecordActivity extends BaseActivity implements View.OnClickListener {
19+
private VideoView videoView;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_video_record);
25+
videoView = findViewById(R.id.video_view);
26+
findViewById(R.id.button_open_camera_to_record).setOnClickListener(this);
27+
}
28+
29+
@Override
30+
public void onClick(View v) {
31+
OmegaIntentBuilder
32+
.recordVideo()
33+
.createIntentHandler(this)
34+
.failCallback(new FailCallback() {
35+
@Override
36+
public void onActivityStartError(@NotNull Exception exc) {
37+
Toast.makeText(VideoRecordActivity.this, exc.toString(), Toast.LENGTH_SHORT).show();
38+
}
39+
})
40+
.startActivityForResult(new ActivityResultCallback() {
41+
@Override
42+
public void onActivityResult(int resultCode, @Nullable Intent data) {
43+
if (resultCode == RESULT_OK) {
44+
Uri videoUri = data.getData();
45+
if (videoUri != null) {
46+
videoView.setVisibility(View.VISIBLE);
47+
videoView.setVideoURI(videoUri);
48+
videoView.start();
49+
}
50+
}
51+
}
52+
});
53+
}
54+
55+
}

examples/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@
180180
android:text="@string/show_alarms"
181181
android:theme="@style/ButtonStyle" />
182182

183+
<Button
184+
android:id="@+id/button_record_video"
185+
android:layout_width="match_parent"
186+
android:layout_height="wrap_content"
187+
android:theme="@style/ButtonStyle"
188+
android:text="@string/record_video"/>
189+
183190
</LinearLayout>
184191

185192
</androidx.core.widget.NestedScrollView>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:orientation="vertical"
8+
tools:context="com.omega_r.omegaintentbuilder.VideoRecordActivity">
9+
10+
<Button
11+
android:id="@+id/button_open_camera_to_record"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_marginTop="8dp"
15+
android:layout_marginBottom="8dp"
16+
android:text="@string/open_camera_to_record"
17+
android:theme="@style/ButtonStyle"
18+
tools:ignore="MissingConstraints" />
19+
20+
<VideoView
21+
android:id="@+id/video_view"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:layout_gravity="center"
25+
android:visibility="invisible"/>
26+
27+
</LinearLayout>

examples/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
<string name="search_web">Search Web</string>
2828
<string name="show_timers">Show Timers</string>
2929
<string name="show_alarms">Show Alarms</string>
30+
<string name="open_camera_to_record">Open Camera To Record</string>
31+
<string name="record_video">Record Video</string>
3032
</resources>

0 commit comments

Comments
 (0)