<commit_before>/*
 * Copyright 2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package kotlinx.android.koan

import android.view.View
import android.view.ViewManager
import android.widget.LinearLayout
import android.widget.ImageView
import android.widget.TextView
import android.content.Context
import android.app.Fragment
import android.app.Activity
import android.graphics.drawable.Drawable
import android.widget.EditText

/* SECTION VIEWS */
//type casting is now under the hood
public fun <T : View> View.find(id: Int): T = findViewById(id) as T
/* END SECTION */

/* SECTION COLORS */
//returns 0xC0C0C0 for 0xC0
public val Int.gray: Int
    get() = this or (this shl 8) or (this shl 16)

//returns 0xFFABCDEF for 0xABCDEF
public val Int.opaque: Int
    get() = this or 0xff000000.toInt()
/* END SECTION */


/* SECTION DIMENSIONS */
//returns dip(dp) dimension value in pixels
public fun Context.dip(value: Int): Int =
    (value * (getResources()?.getDisplayMetrics()?.density ?: 0f)).toInt()
public fun Context.dip(value: Float): Int =
    (value * (getResources()?.getDisplayMetrics()?.density ?: 0f)).toInt()

//return sp dimension value in pixels
public fun Context.sp(value: Int): Int =
    (value * (getResources()?.getDisplayMetrics()?.scaledDensity ?: 0f)).toInt()
public fun Context.sp(value: Float): Int =
    (value * (getResources()?.getDisplayMetrics()?.scaledDensity ?: 0f)).toInt()

//converts px value into dip or sp
public fun Context.px2dip(px: Int): Float =
    (px.toFloat() / (getResources()?.getDisplayMetrics()?.density ?: 1f)).toFloat()
public fun Context.px2sp(px: Int): Float =
    (px.toFloat() / (getResources()?.getDisplayMetrics()?.scaledDensity ?: 1f)).toFloat()

//the same for nested DSL components
public fun UiHelper.dip(value: Int): Int = ctx.dip(value)
public fun UiHelper.dip(value: Float): Int = ctx.dip(value)
public fun UiHelper.sp(value: Int): Int = ctx.sp(value)
public fun UiHelper.sp(value: Float): Int = ctx.sp(value)
public fun UiHelper.px2dip(px: Int): Float = ctx.px2dip(px)
public fun UiHelper.px2sp(px: Int): Float = ctx.px2sp(px)

//the same for Fragments
public fun Fragment.dip(value: Int): Int = ctx.dip(value)
public fun Fragment.dip(value: Float): Int = ctx.dip(value)
public fun Fragment.sp(value: Int): Int = ctx.sp(value)
public fun Fragment.sp(value: Float): Int = ctx.sp(value)
public fun Fragment.px2dip(px: Int): Float = ctx.px2dip(px)
public fun Fragment.px2sp(px: Int): Float = ctx.px2sp(px)
/* END SECTION */


/* SECTION CUSTOM VIEWS */
private val verticalLayoutFactory = { (ctx: Context) ->
    val v = _LinearLayout(ctx)
    v.setOrientation(LinearLayout.VERTICAL)
    v
}

public fun ViewManager.verticalLayout(init: _LinearLayout.() -> Unit): LinearLayout =
    __dslAddView(verticalLayoutFactory, init, this): LinearLayout

public fun Activity.verticalLayout(init: _LinearLayout.() -> Unit): LinearLayout =<commit_msg>Remove verticalLayout dublicate for Activity<commit_after>/*
 * Copyright 2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package kotlinx.android.koan

import android.view.View
import android.view.ViewManager
import android.widget.LinearLayout
import android.widget.ImageView
import android.widget.TextView
import android.content.Context
import android.app.Fragment
import android.app.Activity
import android.graphics.drawable.Drawable
import android.widget.EditText

/* SECTION VIEWS */
//type casting is now under the hood
public fun <T : View> View.find(id: Int): T = findViewById(id) as T
/* END SECTION */

/* SECTION COLORS */
//returns 0xC0C0C0 for 0xC0
public val Int.gray: Int
    get() = this or (this shl 8) or (this shl 16)

//returns 0xFFABCDEF for 0xABCDEF
public val Int.opaque: Int
    get() = this or 0xff000000.toInt()
/* END SECTION */


/* SECTION DIMENSIONS */
//returns dip(dp) dimension value in pixels
public fun Context.dip(value: Int): Int =
    (value * (getResources()?.getDisplayMetrics()?.density ?: 0f)).toInt()
public fun Context.dip(value: Float): Int =
    (value * (getResources()?.getDisplayMetrics()?.density ?: 0f)).toInt()

//return sp dimension value in pixels
public fun Context.sp(value: Int): Int =
    (value * (getResources()?.getDisplayMetrics()?.scaledDensity ?: 0f)).toInt()
public fun Context.sp(value: Float): Int =
    (value * (getResources()?.getDisplayMetrics()?.scaledDensity ?: 0f)).toInt()

//converts px value into dip or sp
public fun Context.px2dip(px: Int): Float =
    (px.toFloat() / (getResources()?.getDisplayMetrics()?.density ?: 1f)).toFloat()
public fun Context.px2sp(px: Int): Float =
    (px.toFloat() / (getResources()?.getDisplayMetrics()?.scaledDensity ?: 1f)).toFloat()

//the same for nested DSL components
public fun UiHelper.dip(value: Int): Int = ctx.dip(value)
public fun UiHelper.dip(value: Float): Int = ctx.dip(value)
public fun UiHelper.sp(value: Int): Int = ctx.sp(value)
public fun UiHelper.sp(value: Float): Int = ctx.sp(value)
public fun UiHelper.px2dip(px: Int): Float = ctx.px2dip(px)
public fun UiHelper.px2sp(px: Int): Float = ctx.px2sp(px)

//the same for Fragments
public fun Fragment.dip(value: Int): Int = ctx.dip(value)
public fun Fragment.dip(value: Float): Int = ctx.dip(value)
public fun Fragment.sp(value: Int): Int = ctx.sp(value)
public fun Fragment.sp(value: Float): Int = ctx.sp(value)
public fun Fragment.px2dip(px: Int): Float = ctx.px2dip(px)
public fun Fragment.px2sp(px: Int): Float = ctx.px2sp(px)
/* END SECTION */


/* SECTION CUSTOM VIEWS */
private val verticalLayoutFactory = { (ctx: Context) ->
    val v = _LinearLayout(ctx)
    v.setOrientation(LinearLayout.VERTICAL)
    v
}

public fun ViewManager.verticalLayout(init: _LinearLayout.() -> Unit): LinearLayout =
{'fraction_non_alphanumeric': 0.12928094885100075, 'fraction_numerical': 0.01245366938472943, 'mean_word_length': 4.471208434712084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5739305', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2090, 'n_words': 678}