Skip to content

Commit

Permalink
Convert CustomViewActivity class to Kotlin.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Apr 28, 2022
1 parent 86f612e commit 5c7efe2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 74 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* 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 com.vanniktech.emoji.sample

import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import com.vanniktech.emoji.EmojiPopup
import com.vanniktech.emoji.sample.databinding.ViewCustomBinding
import com.vanniktech.emoji.traits.EmojiTrait

class CustomViewActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val customView = CustomView(this, null)
setContentView(customView)
customView.setUpEmojiPopup()
}

internal class CustomView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
) : LinearLayout(context, attrs) {
private val binding = ViewCustomBinding.inflate(LayoutInflater.from(context), this)

private var forceSingleEmoji: EmojiTrait? = null

init {
orientation = VERTICAL
}

fun setUpEmojiPopup() {
binding.onlyAllowSingleEmoji.setOnCheckedChangeListener { _, isChecked: Boolean ->
if (isChecked) {
forceSingleEmoji = binding.editText.installForceSingleEmoji()
} else if (forceSingleEmoji != null) {
forceSingleEmoji!!.uninstall()
}
}
val emojiPopup = EmojiPopup.Builder.fromRootView(this)
.setKeyboardAnimationStyle(R.style.emoji_fade_animation_style)
.setPageTransformer(PageTransformer())
.build(binding.editText)
binding.editText.disableKeyboardInput(emojiPopup)
binding.button.setOnClickListener { binding.editText.requestFocus() }
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:text="Custom view which only allows emojis to be entered."
/>
<Button
android:id="@+id/customViewButton"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
Expand All @@ -28,7 +28,7 @@
android:text="Only allow single emoji"
/>
<com.vanniktech.emoji.EmojiEditText
android:id="@+id/customViewEditText"
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
Expand Down

0 comments on commit 5c7efe2

Please sign in to comment.