Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.tipbox.pos.tipboxaqsi.Activities
- import android.content.Intent
- import android.graphics.Color
- import android.graphics.drawable.ColorDrawable
- import android.os.Bundle
- import android.os.Handler
- import android.view.View
- import android.view.animation.Animation
- import android.view.animation.AnimationUtils
- import android.widget.*
- import net.tipbox.pos.tipboxaqsi.MyApplication
- import net.tipbox.pos.tipboxaqsi.Counter
- import net.tipbox.pos.tipboxaqsi.LocaleHelper
- import androidx.appcompat.app.AppCompatActivity
- import androidx.core.app.ComponentActivity.ExtraData
- import androidx.core.content.ContextCompat.getSystemService
- import android.icu.lang.UCharacter.GraphemeClusterBreak.T
- import android.R
- import androidx.core.os.HandlerCompat.postDelayed
- import androidx.core.app.ComponentActivity.ExtraData
- import androidx.core.content.ContextCompat.getSystemService
- import android.icu.lang.UCharacter.GraphemeClusterBreak.T
- import androidx.core.app.ComponentActivity.ExtraData
- import androidx.core.content.ContextCompat.getSystemService
- import android.icu.lang.UCharacter.GraphemeClusterBreak.T
- import android.widget.Toast
- import androidx.core.app.ComponentActivity.ExtraData
- import androidx.core.content.ContextCompat.getSystemService
- import android.icu.lang.UCharacter.GraphemeClusterBreak.T
- open class BaseActivity : AppCompatActivity() {
- private val mLanguageCode = "en"
- private var frameEnBtn: FrameLayout? = null
- protected var btnEn: Button? = null
- private var btnToLogin: Button? = null
- private var btnServiceTerms: Button? = null
- private var activityContainer: FrameLayout? = null
- private var rlHeaderView: LinearLayout? = null
- private var scaleAnim: Animation? = null
- private var shakeAnim: Animation? = null
- val counter = net.tipbox.pos.tipboxaqsi.Counter()
- var handler: Handler? = null
- var runable: Runnable? = null
- override fun setContentView(layoutResID: Int) {
- val llparentView = layoutInflater
- .inflate(net.tipbox.pos.tipboxaqsi.R.layout.activity_header, null) as LinearLayout
- initViews(llparentView)
- layoutInflater.inflate(layoutResID, activityContainer, true)
- super.setContentView(llparentView)
- }
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- handler = Handler()
- runable = Runnable {
- // TODO Auto-generated method stub
- Toast.makeText(this@BaseActivity, "user is inactive from last 5 minutes", Toast.LENGTH_SHORT)
- .show()
- }
- startHandler()
- setContentView(net.tipbox.pos.tipboxaqsi.R.layout.activity_thx)
- scaleAnim = AnimationUtils.loadAnimation(this, net.tipbox.pos.tipboxaqsi.R.anim.button_scale)
- shakeAnim = AnimationUtils.loadAnimation(this, net.tipbox.pos.tipboxaqsi.R.anim.shake)
- }
- private fun initViews(view: View) {
- activityContainer = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.activity_content)
- rlHeaderView = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.header_view)
- btnEn = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btn_en)
- frameEnBtn = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btn_en_frame)
- btnToLogin = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btnLogin)
- btnServiceTerms = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btn_offer)
- frameEnBtn!!.setOnClickListener(enBtnListener)
- btnToLogin!!.setOnClickListener(loginBtnListener)
- btnServiceTerms!!.setOnClickListener(serviceBtnListener)
- btnEn!!.isSelected = btnEn!!.text == "ru"
- }
- private val enBtnListener = View.OnClickListener {
- ChangeLanguage()
- }
- open fun ChangeLanguage(){
- val lang = btnEn!!.text
- btnEn!!.isSelected = lang == "en"
- LocaleHelper.setLocale(this@BaseActivity, lang as String?)
- val stro = getString(net.tipbox.pos.tipboxaqsi.R.string.offer_text)
- (application as MyApplication).State?.SetOfferText(stro, lang)
- recreate()
- }
- private val loginBtnListener = View.OnClickListener {
- val c = counter.Count(true,3500)
- if(c == 2){
- Handler().postDelayed({
- val fc = counter.Count(false)
- if(fc == 2){
- val pm = this.packageManager
- val myIntent = pm.getLaunchIntentForPackage(this.packageName)
- myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
- myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- finish()
- startActivity(myIntent)
- }
- else{counter.Reset()}
- }, 1000)
- }
- }
- private val serviceBtnListener = View.OnClickListener {
- val app = application as MyApplication
- val dialog = net.tipbox.pos.tipboxaqsi.Activities.OfferDialog(this, app.State!!)
- dialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
- dialog.show()
- }
- fun showHeader(show: Boolean) {
- rlHeaderView!!.visibility = if (show) View.VISIBLE else View.GONE
- }
- fun showTerms(show: Boolean) {
- btnServiceTerms!!.visibility = if (show) View.VISIBLE else View.INVISIBLE
- }
- fun playScaleAnim(view: View){
- view.isSelected = true
- view.startAnimation(scaleAnim)
- }
- fun playShakeAnim(view: View){
- view.startAnimation(shakeAnim)
- }
- fun startIntentWithDelay(intent: Intent, delay:Long){
- Handler().postDelayed({
- finish()
- startActivity(intent)
- }, delay)
- }
- override fun onUserInteraction() {
- // TODO Auto-generated method stub
- super.onUserInteraction()
- stopHandler()//stop first and then start
- startHandler()
- }
- fun stopHandler() {
- handler.removeCallbacks(runable)
- }
- fun startHandler() {
- handler.postDelayed(runable, 5 * 60 * 1000) //for 5 minutes
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement