convert SimpleActivity to kotlin
This commit is contained in:
parent
0dab91be56
commit
e9fca9e7dd
|
@ -166,7 +166,7 @@ public class MainActivity extends SimpleActivity
|
|||
lp.setMargins(0, 0, 0, lp.bottomMargin + Utils.Companion.getNavBarHeight(getResources()));
|
||||
}
|
||||
|
||||
mCurrCamera = mConfig.getLastUsedCamera();
|
||||
mCurrCamera = getConfig().getLastUsedCamera();
|
||||
mPreview = new Preview(this, (SurfaceView) findViewById(R.id.camera_view), this);
|
||||
mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
mViewHolder.addView(mPreview);
|
||||
|
@ -179,7 +179,7 @@ public class MainActivity extends SimpleActivity
|
|||
mIsInPhotoMode = true;
|
||||
mTimerHandler = new Handler();
|
||||
mFadeHandler = new Handler();
|
||||
mIsFlashEnabled = mConfig.getLastFlashlightState();
|
||||
mIsFlashEnabled = getConfig().getLastFlashlightState();
|
||||
setupPreviewImage(true);
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ public class MainActivity extends SimpleActivity
|
|||
mCurrCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||
}
|
||||
|
||||
mConfig.setLastUsedCamera(mCurrCamera);
|
||||
getConfig().setLastUsedCamera(mCurrCamera);
|
||||
int newIconId = R.mipmap.camera_front;
|
||||
mPreview.releaseCamera();
|
||||
if (mPreview.setCamera(mCurrCamera)) {
|
||||
|
@ -279,14 +279,14 @@ public class MainActivity extends SimpleActivity
|
|||
mPreview.disableFlash();
|
||||
mToggleFlashBtn.setImageResource(R.mipmap.flash_off);
|
||||
mIsFlashEnabled = false;
|
||||
mConfig.setLastFlashlightState(mIsFlashEnabled);
|
||||
getConfig().setLastFlashlightState(mIsFlashEnabled);
|
||||
}
|
||||
|
||||
private void enableFlash() {
|
||||
mPreview.enableFlash();
|
||||
mToggleFlashBtn.setImageResource(R.mipmap.flash_on);
|
||||
mIsFlashEnabled = true;
|
||||
mConfig.setLastFlashlightState(mIsFlashEnabled);
|
||||
getConfig().setLastFlashlightState(mIsFlashEnabled);
|
||||
}
|
||||
|
||||
@OnClick(R.id.shutter)
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package com.simplemobiletools.camera.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.simplemobiletools.camera.Config;
|
||||
import com.simplemobiletools.camera.R;
|
||||
|
||||
public class SimpleActivity extends AppCompatActivity {
|
||||
protected Config mConfig;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
int theme = mConfig.getIsDarkTheme() ? R.style.AppTheme_Base_Dark : R.style.AppTheme_Base;
|
||||
if (this instanceof MainActivity) {
|
||||
theme = mConfig.getIsDarkTheme() ? R.style.FullScreenTheme_Dark : R.style.FullScreenTheme;
|
||||
}
|
||||
setTheme(theme);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,16 +52,16 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupDarkTheme() {
|
||||
settings_dark_theme.isChecked = mConfig.isDarkTheme
|
||||
settings_dark_theme.isChecked = config.isDarkTheme
|
||||
settings_dark_theme_holder.setOnClickListener {
|
||||
settings_dark_theme.toggle()
|
||||
mConfig.isDarkTheme = settings_dark_theme.isChecked
|
||||
config.isDarkTheme = settings_dark_theme.isChecked
|
||||
restartActivity()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSavePhotosFolder() {
|
||||
mCurrPath = mConfig.savePhotosFolder
|
||||
mCurrPath = config.savePhotosFolder
|
||||
settings_save_photos.text = getHumanPath()
|
||||
settings_save_photos_holder.setOnClickListener {
|
||||
FilePickerDialog(this, mCurrPath, false, false, object : FilePickerDialog.OnFilePickerListener {
|
||||
|
@ -70,9 +70,9 @@ class SettingsActivity : SimpleActivity() {
|
|||
|
||||
override fun onSuccess(pickedPath: String) {
|
||||
mWantedPath = pickedPath
|
||||
if (!isShowingWritePermissions(File(pickedPath), mConfig.treeUri, OPEN_DOCUMENT_TREE)) {
|
||||
if (!isShowingWritePermissions(File(pickedPath), config.treeUri, OPEN_DOCUMENT_TREE)) {
|
||||
mCurrPath = if (pickedPath.length == 1) pickedPath else pickedPath.trimEnd('/')
|
||||
mConfig.savePhotosFolder = mCurrPath
|
||||
config.savePhotosFolder = mCurrPath
|
||||
settings_save_photos.text = getHumanPath()
|
||||
}
|
||||
}
|
||||
|
@ -98,11 +98,11 @@ class SettingsActivity : SimpleActivity() {
|
|||
if (requestCode == OPEN_DOCUMENT_TREE) {
|
||||
if (resultCode == Activity.RESULT_OK && resultData != null) {
|
||||
mCurrPath = mWantedPath
|
||||
mConfig.savePhotosFolder = mCurrPath
|
||||
config.savePhotosFolder = mCurrPath
|
||||
settings_save_photos.text = getHumanPath()
|
||||
saveTreeUri(resultData)
|
||||
} else {
|
||||
mCurrPath = mConfig.savePhotosFolder
|
||||
mCurrPath = config.savePhotosFolder
|
||||
settings_save_photos.text = getHumanPath()
|
||||
}
|
||||
}
|
||||
|
@ -111,25 +111,25 @@ class SettingsActivity : SimpleActivity() {
|
|||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private fun saveTreeUri(resultData: Intent) {
|
||||
val treeUri = resultData.data
|
||||
mConfig.treeUri = treeUri.toString()
|
||||
config.treeUri = treeUri.toString()
|
||||
|
||||
val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
contentResolver.takePersistableUriPermission(treeUri, takeFlags)
|
||||
}
|
||||
|
||||
private fun setupSound() {
|
||||
settings_sound.isChecked = mConfig.isSoundEnabled
|
||||
settings_sound.isChecked = config.isSoundEnabled
|
||||
settings_sound_holder.setOnClickListener {
|
||||
settings_sound.toggle()
|
||||
mConfig.isSoundEnabled = settings_sound.isChecked
|
||||
config.isSoundEnabled = settings_sound.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupForceRatio() {
|
||||
settings_force_ratio.isChecked = mConfig.forceRatioEnabled
|
||||
settings_force_ratio.isChecked = config.forceRatioEnabled
|
||||
settings_force_ratio_holder.setOnClickListener {
|
||||
settings_force_ratio.toggle()
|
||||
mConfig.forceRatioEnabled = settings_force_ratio.isChecked
|
||||
config.forceRatioEnabled = settings_force_ratio.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
settings_max_photo_resolution.setSelection(getMaxPhotoSelection())
|
||||
settings_max_photo_resolution.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
mConfig.maxPhotoResolution = getMaxPhotoPx(settings_max_photo_resolution.selectedItemPosition)
|
||||
config.maxPhotoResolution = getMaxPhotoPx(settings_max_photo_resolution.selectedItemPosition)
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
|
@ -146,7 +146,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun getMaxPhotoSelection(): Int {
|
||||
val maxRes = mConfig.maxPhotoResolution
|
||||
val maxRes = config.maxPhotoResolution
|
||||
return when (maxRes) {
|
||||
Constants.TWO_MPX -> 0
|
||||
Constants.FIVE_MPX -> 1
|
||||
|
@ -171,13 +171,13 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
mConfig.maxVideoResolution = getMaxVideoPx(settings_max_video_resolution.selectedItemPosition)
|
||||
config.maxVideoResolution = getMaxVideoPx(settings_max_video_resolution.selectedItemPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMaxVideoSelection(): Int {
|
||||
val maxRes = mConfig.maxVideoResolution
|
||||
val maxRes = config.maxVideoResolution
|
||||
return when (maxRes) {
|
||||
Constants.P480 -> 0
|
||||
Constants.P720 -> 1
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.simplemobiletools.camera.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.MenuItem
|
||||
|
||||
import com.simplemobiletools.camera.Config
|
||||
import com.simplemobiletools.camera.R
|
||||
|
||||
open class SimpleActivity : AppCompatActivity() {
|
||||
lateinit var config: Config
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
config = Config.newInstance(applicationContext)
|
||||
var theme = if (config.isDarkTheme) R.style.AppTheme_Base_Dark else R.style.AppTheme_Base
|
||||
if (this is MainActivity) {
|
||||
theme = if (config.isDarkTheme) R.style.FullScreenTheme_Dark else R.style.FullScreenTheme
|
||||
}
|
||||
setTheme(theme)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
finish()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue