|
| 1 | +/* |
| 2 | + * This file is part of AndroidIDE. |
| 3 | + * |
| 4 | + * AndroidIDE is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * AndroidIDE is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.itsaky.inflater.adapters.android.widget |
| 19 | + |
| 20 | +import android.util.DisplayMetrics |
| 21 | +import android.view.View |
| 22 | +import android.widget.AbsListView |
| 23 | +import com.itsaky.inflater.IAttribute |
| 24 | +import com.itsaky.inflater.IResourceTable |
| 25 | + |
| 26 | +/** |
| 27 | + * Attribute adapter for the [AbsListView] widget. |
| 28 | + * |
| 29 | + * @author Akash Yadav |
| 30 | + */ |
| 31 | +open class AbsListViewAttrAdapter(resourceTable: IResourceTable, displayMetrics: DisplayMetrics) : |
| 32 | + AdapterViewAttrAdapter(resourceTable, displayMetrics) { |
| 33 | + |
| 34 | + override fun isApplicableTo(view: View?): Boolean { |
| 35 | + return view is AbsListView |
| 36 | + } |
| 37 | + |
| 38 | + override fun apply(attribute: IAttribute, view: View): Boolean { |
| 39 | + val list = view as AbsListView |
| 40 | + val context = list.context |
| 41 | + val value = attribute.value |
| 42 | + |
| 43 | + if (!canHandleNamespace(attribute)) { |
| 44 | + return false |
| 45 | + } |
| 46 | + |
| 47 | + var handled = true |
| 48 | + when (attribute.attributeName) { |
| 49 | + "cacheColorHint" -> list.cacheColorHint = parseColor(value, context) |
| 50 | + "choiceMode" -> list.choiceMode = parseChoiceMode(value) |
| 51 | + "drawSelectorOnTop" -> list.isDrawSelectorOnTop = parseBoolean(value) |
| 52 | + "fastScrollEnabled" -> list.isFastScrollEnabled = parseBoolean(value) |
| 53 | + "listSelector" -> list.selector = parseDrawable(value, context) |
| 54 | + "smoothScrollbar" -> list.isSmoothScrollbarEnabled = parseBoolean(value) |
| 55 | + "stackFromBottom" -> list.isStackFromBottom = parseBoolean(value) |
| 56 | + "textFilterEnabled" -> list.isTextFilterEnabled = parseBoolean(value) |
| 57 | + "transcriptMode" -> list.transcriptMode = parseTranscriptMode(value) |
| 58 | + else -> handled = false |
| 59 | + } |
| 60 | + |
| 61 | + if (!handled) { |
| 62 | + handled = super.apply(attribute, view) |
| 63 | + } |
| 64 | + |
| 65 | + return handled |
| 66 | + } |
| 67 | + |
| 68 | + protected open fun parseTranscriptMode(value: String): Int { |
| 69 | + return when (value) { |
| 70 | + "normal" -> AbsListView.TRANSCRIPT_MODE_NORMAL |
| 71 | + "alwaysScroll" -> AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL |
| 72 | + else -> AbsListView.TRANSCRIPT_MODE_DISABLED |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + protected open fun parseChoiceMode(value: String): Int { |
| 77 | + return when (value) { |
| 78 | + "multipleChoice" -> AbsListView.CHOICE_MODE_MULTIPLE |
| 79 | + "multipleChoiceModal" -> AbsListView.CHOICE_MODE_MULTIPLE_MODAL |
| 80 | + "singleChoice" -> AbsListView.CHOICE_MODE_SINGLE |
| 81 | + else -> AbsListView.CHOICE_MODE_NONE |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments