Skip to content

Commit 844459f

Browse files
committed
add VideoRecord feature
1 parent fc59df1 commit 844459f

9 files changed

Lines changed: 124 additions & 0 deletions

File tree

core/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
88
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
99

10+
<uses-feature
11+
android:name="android.hardware.camera"
12+
android:required="true" />
13+
1014
<application>
1115
<provider
1216
android:name="com.omega_r.libs.omegaintentbuilder.providers.FileProvider"

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
@@ -163,4 +163,10 @@ object OmegaIntentBuilder {
163163
@RequiresApi(Build.VERSION_CODES.KITKAT)
164164
fun createAlarm() = AlarmIntentBuilder()
165165

166+
/**
167+
* @return VideoRecordBuilder
168+
*/
169+
@JvmStatic
170+
fun recordVideo() = VideoRecordBuilder()
171+
166172
}
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
4444
findViewById(R.id.button_insert_contact).setOnClickListener(this);
4545
findViewById(R.id.button_search_web).setOnClickListener(this);
4646
findViewById(R.id.button_create_timer).setOnClickListener(this);
47+
findViewById(R.id.button_record_video).setOnClickListener(this);
4748
}
4849

4950
@Override
@@ -109,6 +110,9 @@ public void onClick(View v) {
109110
case R.id.button_create_timer:
110111
onCreateTimerClicked();
111112
break;
113+
case R.id.button_record_video:
114+
onRecordVideoClicked();
115+
break;
112116
}
113117
}
114118

@@ -313,4 +317,11 @@ private void onCreateTimerClicked() {
313317
.startActivity(this);
314318
}
315319

320+
321+
private void onRecordVideoClicked() {
322+
OmegaIntentBuilder
323+
.activity(VideoRecordActivity.class)
324+
.startActivity(this);
325+
}
326+
316327
}
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
@@ -167,6 +167,13 @@
167167
android:theme="@style/ButtonStyle"
168168
android:text="@string/create_timer"/>
169169

170+
<Button
171+
android:id="@+id/button_record_video"
172+
android:layout_width="match_parent"
173+
android:layout_height="wrap_content"
174+
android:theme="@style/ButtonStyle"
175+
android:text="@string/record_video"/>
176+
170177
</LinearLayout>
171178

172179
</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
@@ -25,4 +25,6 @@
2525
<string name="create_timer">Create Timer</string>
2626
<string name="insert_contact">Insert Contact</string>
2727
<string name="search_web">Search Web</string>
28+
<string name="open_camera_to_record">Open Camera To Record</string>
29+
<string name="record_video">Record Video</string>
2830
</resources>

0 commit comments

Comments
 (0)