Add more layout adapters (#680)

IViewAdapter implementations for the following views have been added :
- GridViewAdapter
- ViewAnimatorAdapter
- ViewSwitcher
- TextSwitcher
- ImageSwitcher
- ViewFlipperAdapter
This commit is contained in:
Deep Kr. Ghosh
2023-01-01 22:30:49 +05:30
committed by GitHub
parent fed7b68a20
commit b2d6ec9c06
13 changed files with 487 additions and 0 deletions
@@ -0,0 +1,28 @@
<!--
~ 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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M1 4h4v4H1zM1 9h4v4H1zM6 4h4v4H6zM6 9h4v4H6zM11 4h4v4h-4zM11 9h4v4h-4z" />
</vector>
@@ -0,0 +1,32 @@
<!--
~ 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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M5 14V6h10v8H5zm3-4l-2 3h8l-2.571-4-2 3.007L8 10z" />
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M11 5H4v5H1V2h10v3z" />
</vector>
@@ -0,0 +1,32 @@
<!--
~ 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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M5 14V6h10v8H5zm6.256-2.397L11.755 13h1.105l-2.307-6h-0.95l-2.304 6H8.4l0.494-1.397h2.362z" />
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M9.187 10.762h1.767l-0.884-2.49zM11 5H4v5H1V2h10v3z" />
</vector>
@@ -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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="16"
android:viewportHeight="16"
android:width="24dp"
android:height="24dp">
<path
android:pathData="M5 14V6h10v8H5zm3 -7v6l5 -3 -5 -3z"
android:fillType="evenOdd"
android:fillColor="@color/primaryIconColor" />
<path
android:pathData="M11 5H4v5H1V2h10v3z"
android:fillType="evenOdd"
android:fillColor="@color/primaryIconColor" />
</vector>
@@ -0,0 +1,27 @@
<!--
~ 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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="16"
android:viewportHeight="16"
android:width="24dp"
android:height="24dp">
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M1 2h14v12H1V2zm7 2v8h5V4H8z" />
</vector>
@@ -0,0 +1,32 @@
<!--
~ 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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M5 14V6h10v8H5zm1-7v6h8V7H6z" />
<path
android:fillColor="@color/primaryIconColor"
android:fillType="evenOdd"
android:pathData="M11 5H4v5H1V2h10v3z" />
</vector>
@@ -510,6 +510,12 @@
<string name="widget_quick_contact_badge" translatable="false">QuickContactBadge</string> <string name="widget_quick_contact_badge" translatable="false">QuickContactBadge</string>
<string name="widget_videoview" translatable="false">VideoView</string> <string name="widget_videoview" translatable="false">VideoView</string>
<string name="widget_analog_clock" translatable="false">AnalogClock</string> <string name="widget_analog_clock" translatable="false">AnalogClock</string>
<string name="widget_grid_view" translatable="false">GridView</string>
<string name="widget_viewanimator" translatable="false">ViewAnimator</string>
<string name="widget_viewswitcher" translatable="false">ViewSwitcher</string>
<string name="widget_textswitcher" translatable="false">TextSwitcher</string>
<string name="widget_imageswitcher" translatable="false">ImageSwitcher</string>
<string name="widget_viewflipper" translatable="false">ViewFlipper</string>
<!-- GIT --> <!-- GIT -->
<string name="git_clone">Clone</string> <string name="git_clone">Clone</string>
@@ -0,0 +1,65 @@
/*
* 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.inflater.internal.adapters
import android.widget.GridView
import com.itsaky.androidide.annotations.inflater.ViewAdapter
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner.Group.LAYOUTS
import com.itsaky.androidide.inflater.AttributeHandlerScope
import com.itsaky.androidide.inflater.models.UiWidget
import com.itsaky.androidide.resources.R.drawable
import com.itsaky.androidide.resources.R.string
/**
* Attribute adapter for [GridView].
*
* @author Deep Kr. Ghosh
*/
@ViewAdapter(GridView::class)
@IncludeInDesigner(group = LAYOUTS)
open class GridViewAdapter<T : GridView> : AbsListViewAdapter<T>() {
override fun createAttrHandlers(create: (String, AttributeHandlerScope<T>.() -> Unit) -> Unit) {
super.createAttrHandlers(create)
create("columnWidth") { view.columnWidth = parseDimension(context, value) }
create("gravity") { view.gravity = parseGravity(value) }
create("horizontalSpacing") { view.horizontalSpacing = parseDimension(context, value) }
create("numColumns") {
view.numColumns = if (value == "auto_fit") GridView.AUTO_FIT else parseInteger(value)
}
create("stretchMode") { view.stretchMode = parseStretchMode(value) }
create("verticalSpacing") { view.verticalSpacing = parseDimension(context, value) }
}
override fun createUiWidgets(): List<UiWidget> {
return listOf(
UiWidget(GridView::class.java, string.widget_grid_view, drawable.ic_widget_grid_view)
)
}
protected fun parseStretchMode(value: String): Int {
return when (value) {
"columnWidth" -> GridView.STRETCH_COLUMN_WIDTH
"none" -> GridView.NO_STRETCH
"spacingWidth" -> GridView.STRETCH_SPACING
"spacingWidthUniform" -> GridView.STRETCH_SPACING_UNIFORM
else -> GridView.NO_STRETCH
}
}
}
@@ -0,0 +1,45 @@
/*
* 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.inflater.internal.adapters
import android.widget.ImageSwitcher
import com.itsaky.androidide.annotations.inflater.ViewAdapter
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner.Group.LAYOUTS
import com.itsaky.androidide.inflater.models.UiWidget
import com.itsaky.androidide.resources.R.drawable
import com.itsaky.androidide.resources.R.string
/**
* Attribute adapter for [ImageSwitcher].
*
* @author Deep Kr. Ghosh
*/
@ViewAdapter(ImageSwitcher::class)
@IncludeInDesigner(group = LAYOUTS)
open class ImageSwitcherAdapter<T : ImageSwitcher> : ViewSwitcherAdapter<T>() {
override fun createUiWidgets(): List<UiWidget> {
return listOf(
UiWidget(
ImageSwitcher::class.java,
string.widget_imageswitcher,
drawable.ic_widget_imageswitcher
)
)
}
}
@@ -0,0 +1,45 @@
/*
* 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.inflater.internal.adapters
import android.widget.TextSwitcher
import com.itsaky.androidide.annotations.inflater.ViewAdapter
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner.Group.LAYOUTS
import com.itsaky.androidide.inflater.models.UiWidget
import com.itsaky.androidide.resources.R.drawable
import com.itsaky.androidide.resources.R.string
/**
* Attribute adapter for [TextSwitcher].
*
* @author Deep Kr. Ghosh
*/
@ViewAdapter(TextSwitcher::class)
@IncludeInDesigner(group = LAYOUTS)
open class TextSwitcherAdapter<T : TextSwitcher> : ViewSwitcherAdapter<T>() {
override fun createUiWidgets(): List<UiWidget> {
return listOf(
UiWidget(
TextSwitcher::class.java,
string.widget_textswitcher,
drawable.ic_widget_textswitcher
)
)
}
}
@@ -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.inflater.internal.adapters
import android.widget.ViewAnimator
import com.itsaky.androidide.annotations.inflater.ViewAdapter
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner.Group.LAYOUTS
import com.itsaky.androidide.inflater.AttributeHandlerScope
import com.itsaky.androidide.inflater.models.UiWidget
import com.itsaky.androidide.resources.R
/**
* View adapter for [ViewAnimator].
*
* @author Deep Kr. Ghosh
*/
@ViewAdapter(ViewAnimator::class)
@IncludeInDesigner(group = LAYOUTS)
open class ViewAnimatorAdapter<T : ViewAnimator> : FrameLayoutAdapter<T>() {
override fun createAttrHandlers(create: (String, AttributeHandlerScope<T>.() -> Unit) -> Unit) {
super.createAttrHandlers(create)
create("animateFirstView") { view.animateFirstView = parseBoolean(value, false) }
}
override fun createUiWidgets(): List<UiWidget> {
return listOf(
UiWidget(
ViewAnimator::class.java,
R.string.widget_viewanimator,
R.drawable.ic_widget_viewanimator
)
)
}
}
@@ -0,0 +1,48 @@
/*
* 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.inflater.internal.adapters
import android.widget.ViewFlipper
import com.itsaky.androidide.annotations.inflater.ViewAdapter
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner.Group.LAYOUTS
import com.itsaky.androidide.inflater.AttributeHandlerScope
import com.itsaky.androidide.inflater.models.UiWidget
import com.itsaky.androidide.resources.R.drawable
import com.itsaky.androidide.resources.R.string
/**
* Attribute adapter for [ViewFlipper].
*
* @author Deep Kr. Ghosh
*/
@ViewAdapter(ViewFlipper::class)
@IncludeInDesigner(group = LAYOUTS)
open class ViewFlipperAdapter<T : ViewFlipper> : ViewAnimatorAdapter<T>() {
override fun createAttrHandlers(create: (String, AttributeHandlerScope<T>.() -> Unit) -> Unit) {
super.createAttrHandlers(create)
create("autoStart") { view.setAutoStart(parseBoolean(value)) }
create("flipInterval") { view.flipInterval = parseInteger(value) }
}
override fun createUiWidgets(): List<UiWidget> {
return listOf(
UiWidget(ViewFlipper::class.java, string.widget_viewflipper, drawable.ic_widget_viewflipper)
)
}
}
@@ -0,0 +1,45 @@
/*
* 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.inflater.internal.adapters
import android.widget.ViewSwitcher
import com.itsaky.androidide.annotations.inflater.ViewAdapter
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner
import com.itsaky.androidide.annotations.uidesigner.IncludeInDesigner.Group.LAYOUTS
import com.itsaky.androidide.inflater.models.UiWidget
import com.itsaky.androidide.resources.R.drawable
import com.itsaky.androidide.resources.R.string
/**
* Attribute adapter for [ViewSwitcher].
*
* @author Deep Kr. Ghosh
*/
@ViewAdapter(ViewSwitcher::class)
@IncludeInDesigner(group = LAYOUTS)
open class ViewSwitcherAdapter<T : ViewSwitcher> : ViewAnimatorAdapter<T>() {
override fun createUiWidgets(): List<UiWidget> {
return listOf(
UiWidget(
ViewSwitcher::class.java,
string.widget_viewswitcher,
drawable.ic_widget_viewswitcher
)
)
}
}