feat: add camera selector interface with choice of camera modes
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
<!-- 相机权限 -->
|
<!-- 相机权限 -->
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<!-- 硬件功能声明 -->
|
<!-- 硬件功能声明 -->
|
||||||
<uses-feature android:name="android.hardware.camera" android:required="true" />
|
<uses-feature android:name="android.hardware.camera" android:required="true" />
|
||||||
@@ -34,6 +36,14 @@
|
|||||||
android:name=".WatermarkCameraActivity"
|
android:name=".WatermarkCameraActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:screenOrientation="portrait" />
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".CameraActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".SettingsActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
34
app/src/main/java/com/example/app/CameraSelectorActivity.kt
Normal file
34
app/src/main/java/com/example/app/CameraSelectorActivity.kt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package com.example.app
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.Button
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
||||||
|
class CameraSelectorActivity : AppCompatActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_camera_selector)
|
||||||
|
|
||||||
|
val btnSimpleCamera = findViewById<Button>(R.id.btnSimpleCamera)
|
||||||
|
val btnWatermarkCamera = findViewById<Button>(R.id.btnWatermarkCamera)
|
||||||
|
val btnMultiCamera = findViewById<Button>(R.id.btnMultiCamera)
|
||||||
|
val btnSettings = findViewById<Button>(R.id.btnSettings)
|
||||||
|
|
||||||
|
btnSimpleCamera.setOnClickListener {
|
||||||
|
startActivity(Intent(this, SimpleCameraActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
btnWatermarkCamera.setOnClickListener {
|
||||||
|
startActivity(Intent(this, WatermarkCameraActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
btnMultiCamera.setOnClickListener {
|
||||||
|
startActivity(Intent(this, CameraActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
btnSettings.setOnClickListener {
|
||||||
|
startActivity(Intent(this, SettingsFragment::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,15 +2,33 @@ package com.example.app
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.Button
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_camera_selector)
|
||||||
|
|
||||||
// 启动带水印相机Activity
|
val btnSimpleCamera = findViewById<Button>(R.id.btnSimpleCamera)
|
||||||
startActivity(Intent(this, WatermarkCameraActivity::class.java))
|
val btnWatermarkCamera = findViewById<Button>(R.id.btnWatermarkCamera)
|
||||||
finish() // 关闭MainActivity,避免返回键回到空白页面
|
val btnMultiCamera = findViewById<Button>(R.id.btnMultiCamera)
|
||||||
|
val btnSettings = findViewById<Button>(R.id.btnSettings)
|
||||||
|
|
||||||
|
btnSimpleCamera.setOnClickListener {
|
||||||
|
startActivity(Intent(this, SimpleCameraActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
btnWatermarkCamera.setOnClickListener {
|
||||||
|
startActivity(Intent(this, WatermarkCameraActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
btnMultiCamera.setOnClickListener {
|
||||||
|
startActivity(Intent(this, CameraActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
btnSettings.setOnClickListener {
|
||||||
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
27
app/src/main/java/com/example/app/SettingsActivity.kt
Normal file
27
app/src/main/java/com/example/app/SettingsActivity.kt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.app
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
|
||||||
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_settings)
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
supportFragmentManager
|
||||||
|
.beginTransaction()
|
||||||
|
.replace(R.id.settings_container, SettingsFragment())
|
||||||
|
.commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置ActionBar返回按钮
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
|
onBackPressed()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
56
app/src/main/res/layout/activity_camera_selector.xml
Normal file
56
app/src/main/res/layout/activity_camera_selector.xml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:gravity="center"
|
||||||
|
tools:context=".CameraSelectorActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="选择相机模式"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginBottom="48dp"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnSimpleCamera"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:text="简单相机"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:padding="20dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnWatermarkCamera"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:text="水印相机"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:padding="20dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnMultiCamera"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:text="多图合成相机"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:padding="20dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnSettings"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
|
android:text="设置"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:padding="16dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
5
app/src/main/res/layout/activity_settings.xml
Normal file
5
app/src/main/res/layout/activity_settings.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/settings_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
Reference in New Issue
Block a user