mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
feat(templates): add 'No AndroidX Activity' template
This commit is contained in:
+3
-1
@@ -27,6 +27,7 @@ import com.itsaky.androidide.templates.impl.composeActivity.composeActivityProje
|
||||
import com.itsaky.androidide.templates.impl.emptyActivity.emptyActivityProject
|
||||
import com.itsaky.androidide.templates.impl.navDrawerActivity.navDrawerActivityProject
|
||||
import com.itsaky.androidide.templates.impl.noActivity.noActivityProjectTemplate
|
||||
import com.itsaky.androidide.templates.impl.noAndroidXActivity.noAndroidXActivityProject
|
||||
import com.itsaky.androidide.templates.impl.tabbedActivity.tabbedActivityProject
|
||||
|
||||
/**
|
||||
@@ -35,7 +36,7 @@ import com.itsaky.androidide.templates.impl.tabbedActivity.tabbedActivityProject
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@Suppress("unused")
|
||||
@AutoService(ITemplateProvider::class) //
|
||||
@AutoService(ITemplateProvider::class)
|
||||
class TemplateProviderImpl : ITemplateProvider {
|
||||
|
||||
private val templates = mutableMapOf<String, Template<*>>().apply {
|
||||
@@ -53,6 +54,7 @@ class TemplateProviderImpl : ITemplateProvider {
|
||||
navDrawerActivityProject(),
|
||||
bottomNavActivityProject(),
|
||||
tabbedActivityProject(),
|
||||
noAndroidXActivityProject(),
|
||||
composeActivityProject()
|
||||
)
|
||||
//@formatter:on
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.noAndroidXActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.noAndroidXActivitySrcJava() = """
|
||||
package ${data.packageName};
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import ${data.packageName}.databinding.ActivityMainBinding;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private ActivityMainBinding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
this.binding = null;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.noAndroidXActivitySrcKt() = """
|
||||
package ${data.packageName}
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import ${data.packageName}.databinding.ActivityMainBinding
|
||||
|
||||
public class MainActivity : Activity() {
|
||||
|
||||
private var _binding: ActivityMainBinding? = null
|
||||
|
||||
private val binding: ActivityMainBinding
|
||||
get() = checkNotNull(_binding) { "Activity has been destroyed" }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
_binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.noAndroidXActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.modules.android.defaultAppModule
|
||||
import com.itsaky.androidide.templates.base.util.AndroidModuleResManager
|
||||
import com.itsaky.androidide.templates.impl.R
|
||||
import com.itsaky.androidide.templates.impl.base.createRecipe
|
||||
import com.itsaky.androidide.templates.impl.base.emptyThemesAndColors
|
||||
import com.itsaky.androidide.templates.impl.base.emptyValuesFile
|
||||
import com.itsaky.androidide.templates.impl.base.writeMainActivity
|
||||
import com.itsaky.androidide.templates.impl.baseProjectImpl
|
||||
|
||||
fun noAndroidXActivityProject() = baseProjectImpl {
|
||||
templateName = R.string.template_no_AndroidX
|
||||
thumb = R.drawable.template_empty_noandroidx
|
||||
defaultAppModule {
|
||||
recipe = createRecipe {
|
||||
emptyThemesAndColors()
|
||||
res {
|
||||
writeXmlResource("colors",
|
||||
AndroidModuleResManager.ResourceType.VALUES, source = emptyValuesFile())
|
||||
writeXmlResource("themes", AndroidModuleResManager.ResourceType.VALUES,
|
||||
source = noAndroidXTheme())
|
||||
|
||||
writeXmlResource("activity_main", AndroidModuleResManager.ResourceType.LAYOUT,
|
||||
source = noAndroidXActivityLayout())
|
||||
}
|
||||
|
||||
sources {
|
||||
writeMainActivity(this, ktSrc = ::noAndroidXActivitySrcKt,
|
||||
javaSrc = ::noAndroidXActivitySrcJava)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.noAndroidXActivity
|
||||
|
||||
internal fun noAndroidXActivityLayout() = """
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Hello World!"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
""".trim()
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.noAndroidXActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.noAndroidXTheme() = """
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Base.${manifest.themeRes}" parent="android:Theme.Material.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
<style name="${manifest.themeRes}" parent="Base.${manifest.themeRes}" />
|
||||
</resources>
|
||||
""".trim()
|
||||
@@ -32,6 +32,7 @@ import com.itsaky.androidide.templates.impl.composeActivity.composeActivityProje
|
||||
import com.itsaky.androidide.templates.impl.emptyActivity.emptyActivityProject
|
||||
import com.itsaky.androidide.templates.impl.navDrawerActivity.navDrawerActivityProject
|
||||
import com.itsaky.androidide.templates.impl.noActivity.noActivityProjectTemplate
|
||||
import com.itsaky.androidide.templates.impl.noAndroidXActivity.noAndroidXActivityProject
|
||||
import com.itsaky.androidide.templates.impl.tabbedActivity.tabbedActivityProject
|
||||
import com.itsaky.androidide.xml.permissions.Permission.INTERNET
|
||||
import com.squareup.javapoet.ArrayTypeName
|
||||
@@ -186,6 +187,13 @@ class TemplateBuilderTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test no AndroidX activity template`() {
|
||||
testTemplate("NoAndroidXActivity") {
|
||||
noAndroidXActivityProject()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test compose activity template`() {
|
||||
testTemplate("ComposeActivity", languages = arrayOf(Kotlin)) {
|
||||
|
||||
Reference in New Issue
Block a user