AndroidAPS/app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt

88 lines
4.7 KiB
Kotlin
Raw Normal View History

2020-05-03 15:04:08 +02:00
package info.nightscout.androidaps.skins
import android.util.DisplayMetrics
2020-11-23 13:24:38 +01:00
import android.util.TypedValue.COMPLEX_UNIT_PX
import android.view.View
import android.widget.LinearLayout
2020-11-23 13:24:38 +01:00
import android.widget.TextView
2020-05-03 15:04:08 +02:00
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.constraintlayout.widget.ConstraintLayout
import info.nightscout.androidaps.R
2020-05-03 15:04:08 +02:00
interface SkinInterface {
2020-11-23 13:24:38 +01:00
@get:StringRes val description: Int
2020-11-23 13:24:38 +01:00
val mainGraphHeight: Int // in dp
val secondaryGraphHeight: Int // in dp
@LayoutRes
fun actionsLayout(isLandscape: Boolean, isSmallWidth: Boolean): Int = R.layout.actions_fragment
2021-01-26 15:44:56 +01:00
fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, view: View, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) {
// pre-process landscape mode
val screenWidth = dm.widthPixels
val screenHeight = dm.heightPixels
val landscape = screenHeight < screenWidth
if (landscape) {
2021-01-23 22:42:13 +01:00
val iobLayout = view.findViewById<LinearLayout>(R.id.overview_iob_llayout)
val iobLayoutParams = iobLayout.layoutParams as ConstraintLayout.LayoutParams
val timeLayout = view.findViewById<LinearLayout>(R.id.overview_time_llayout)
iobLayoutParams.startToStart = ConstraintLayout.LayoutParams.UNSET
2021-01-23 22:42:13 +01:00
iobLayoutParams.startToEnd = timeLayout.id
iobLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET
iobLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
2021-01-23 22:42:13 +01:00
val timeLayoutParams = timeLayout.layoutParams as ConstraintLayout.LayoutParams
timeLayoutParams.endToEnd = ConstraintLayout.LayoutParams.UNSET
2021-01-23 22:42:13 +01:00
timeLayoutParams.endToStart = iobLayout.id
val cobLayoutParams = view.findViewById<LinearLayout>(R.id.overview_cob_llayout).layoutParams as ConstraintLayout.LayoutParams
2020-11-26 17:02:50 +01:00
cobLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
2021-01-23 22:42:13 +01:00
val basalLayoutParams = view.findViewById<LinearLayout>(R.id.overview_basal_llayout).layoutParams as ConstraintLayout.LayoutParams
2020-11-26 17:02:50 +01:00
basalLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
2021-01-23 22:42:13 +01:00
val extendedLayoutParams = view.findViewById<LinearLayout>(R.id.overview_extended_llayout).layoutParams as ConstraintLayout.LayoutParams
2020-11-26 17:02:50 +01:00
extendedLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
2021-01-23 22:42:13 +01:00
val asLayoutParams = view.findViewById<LinearLayout>(R.id.overview_as_llayout).layoutParams as ConstraintLayout.LayoutParams
2020-11-26 17:02:50 +01:00
asLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
2020-11-23 13:24:38 +01:00
if (isTablet) {
2020-12-07 22:42:04 +01:00
for (v in listOf<TextView?>(
2021-01-23 22:42:13 +01:00
view.findViewById(R.id.overview_bg),
view.findViewById(R.id.overview_time),
view.findViewById(R.id.overview_timeagoshort),
view.findViewById(R.id.overview_iob),
view.findViewById(R.id.overview_cob),
view.findViewById(R.id.overview_basebasal),
view.findViewById(R.id.overview_extendedbolus),
view.findViewById(R.id.overview_sensitivity)
2020-12-07 22:42:04 +01:00
)) v?.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.5f)
for (v in listOf<TextView?>(
2021-01-23 22:42:13 +01:00
view.findViewById(R.id.overview_pump),
view.findViewById(R.id.overview_openaps),
view.findViewById(R.id.overview_uploader),
view.findViewById(R.id.careportal_canulaage),
view.findViewById(R.id.careportal_insulinage),
view.findViewById(R.id.careportal_reservoirlevel),
view.findViewById(R.id.careportal_reservoirlevel),
view.findViewById(R.id.careportal_sensorage),
view.findViewById(R.id.careportal_pbage),
view.findViewById(R.id.careportal_batterylevel)
2020-12-07 22:42:04 +01:00
)) v?.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.3f)
2021-01-23 22:42:13 +01:00
timeLayout?.orientation = LinearLayout.HORIZONTAL
view.findViewById<TextView>(R.id.overview_timeagoshort)?.setTextSize(COMPLEX_UNIT_PX, view.findViewById<TextView>(R.id.overview_time).textSize)
2020-12-07 22:42:04 +01:00
2021-01-23 22:42:13 +01:00
view.findViewById<TextView>(R.id.overview_delta_large)?.visibility = View.VISIBLE
2020-12-07 22:42:04 +01:00
} else {
2021-01-23 22:42:13 +01:00
view.findViewById<TextView>(R.id.overview_delta_large)?.visibility = View.GONE
2020-11-23 13:24:38 +01:00
}
}
}
2021-01-26 15:44:56 +01:00
fun moveButtonsLayout(root: LinearLayout) {
val buttonsLayout = root.findViewById<LinearLayout>(R.id.buttons_layout)
root.removeView(buttonsLayout)
val innerLayout = root.findViewById<LinearLayout>(R.id.inner_layout)
innerLayout.addView(buttonsLayout)
}
2020-05-03 15:04:08 +02:00
}