Add another QML Component into qml_in_kotlin_based_android_project
Add implementation for second qml component in qml_in_kotlin_based_android_project Task-number: QTBUG-125099 Pick-to: 6.8 Change-Id: Id0b6c693aac2d67cceda74e623fcd18c9568b84a Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
parent
cdb2540589
commit
1d61d52098
|
@ -5,16 +5,19 @@ import android.graphics.Color
|
|||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.qml_in_kotlin_based_android_project.databinding.ActivityMainBinding
|
||||
import org.qtproject.example.qml_in_android_view.QmlModule.Main
|
||||
import org.qtproject.example.qml_in_android_view.QmlModule.Second
|
||||
import org.qtproject.qt.android.QtQmlStatus
|
||||
import org.qtproject.qt.android.QtQmlStatusChangeListener
|
||||
import org.qtproject.qt.android.QtQuickView
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity(), QtQmlStatusChangeListener {
|
||||
|
||||
private val TAG = "myTag"
|
||||
|
@ -25,6 +28,7 @@ class MainActivity : AppCompatActivity(), QtQmlStatusChangeListener {
|
|||
//! [qmlComponent]
|
||||
private var m_mainQmlComponent: Main = Main()
|
||||
//! [qmlComponent]
|
||||
private val m_secondQmlComponent: Second = Second()
|
||||
private val m_statusNames = hashMapOf(
|
||||
QtQmlStatus.READY to "READY",
|
||||
QtQmlStatus.LOADING to "LOADING",
|
||||
|
@ -51,6 +55,7 @@ class MainActivity : AppCompatActivity(), QtQmlStatusChangeListener {
|
|||
//! [setStatusChangeListener]
|
||||
m_mainQmlComponent.setStatusChangeListener(this)
|
||||
//! [setStatusChangeListener]
|
||||
m_secondQmlComponent.setStatusChangeListener(this)
|
||||
|
||||
//! [layoutParams]
|
||||
val params: ViewGroup.LayoutParams = FrameLayout.LayoutParams(
|
||||
|
@ -63,6 +68,9 @@ class MainActivity : AppCompatActivity(), QtQmlStatusChangeListener {
|
|||
//! [loadComponent]
|
||||
|
||||
m_binding.changeColorButton.setOnClickListener { onClickListener() }
|
||||
m_binding.loadMainQml.setOnClickListener { loadMainQml() }
|
||||
m_binding.loadSecondQml.setOnClickListener { loadSecondQml() }
|
||||
m_binding.rotateQmlGridButton.setOnClickListener { rotateQmlGrid() }
|
||||
|
||||
// Check target device orientation on launch
|
||||
handleOrientationChanges()
|
||||
|
@ -110,7 +118,10 @@ class MainActivity : AppCompatActivity(), QtQmlStatusChangeListener {
|
|||
m_binding.getPropertyValueText.text = qmlBackgroundColor
|
||||
|
||||
// Display the QML View background color in a view
|
||||
m_binding.colorBox.setBackgroundColor(Color.parseColor(qmlBackgroundColor))
|
||||
// if qmlBackgroundColor is not null
|
||||
if (qmlBackgroundColor != null) {
|
||||
m_binding.colorBox.setBackgroundColor(Color.parseColor(qmlBackgroundColor))
|
||||
}
|
||||
}
|
||||
//! [onClickListener]
|
||||
|
||||
|
@ -165,4 +176,27 @@ class MainActivity : AppCompatActivity(), QtQmlStatusChangeListener {
|
|||
//! [qml signal listener]
|
||||
}
|
||||
//! [onStatusChanged]
|
||||
|
||||
private fun loadSecondQml() {
|
||||
m_qtQuickView!!.loadComponent(m_secondQmlComponent)
|
||||
|
||||
// Reset box color and color text after component reload
|
||||
m_binding.colorBox.setBackgroundColor(Color.parseColor("#00ffffff"))
|
||||
m_binding.getPropertyValueText.text = ""
|
||||
}
|
||||
|
||||
private fun loadMainQml() {
|
||||
m_qtQuickView!!.loadComponent(m_mainQmlComponent)
|
||||
|
||||
// Reset box color and color text after component reload
|
||||
m_binding.colorBox.setBackgroundColor(Color.parseColor("#00ffffff"))
|
||||
m_binding.getPropertyValueText.text = ""
|
||||
}
|
||||
|
||||
private fun rotateQmlGrid() {
|
||||
val previousGridRotation = m_secondQmlComponent.gridRotation
|
||||
if (previousGridRotation != null) {
|
||||
m_secondQmlComponent.gridRotation = previousGridRotation + 45
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
<LinearLayout
|
||||
android:id="@+id/qmlColorLinear"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp">
|
||||
|
||||
|
@ -159,6 +159,40 @@
|
|||
android:layout_weight="0"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/loadSecondQml"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/load_second_qml"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginRight="20dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/loadMainQml"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/load_main_qml"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/rotateQmlGridButton"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/rotate_qml_grid"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -9,4 +9,7 @@
|
|||
<string name="off">Off</string>
|
||||
<string name="qml_view_status">QML view status: </string>
|
||||
<string name="qml_view_background_color">QML view background color:</string>
|
||||
<string name="load_main_qml">Load Main Qml</string>
|
||||
<string name="load_second_qml">Load Second Qml</string>
|
||||
<string name="rotate_qml_grid">Rotate Qml grid</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue