Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. package net.tipbox.pos.tipboxaqsi.Activities
  2.  
  3. import android.content.Intent
  4. import android.graphics.Color
  5. import android.graphics.drawable.ColorDrawable
  6. import android.os.Bundle
  7. import android.os.Handler
  8. import android.view.View
  9. import android.view.animation.Animation
  10. import android.view.animation.AnimationUtils
  11. import android.widget.*
  12. import net.tipbox.pos.tipboxaqsi.MyApplication
  13. import net.tipbox.pos.tipboxaqsi.Counter
  14. import net.tipbox.pos.tipboxaqsi.LocaleHelper
  15. import androidx.appcompat.app.AppCompatActivity
  16. import androidx.core.app.ComponentActivity.ExtraData
  17. import androidx.core.content.ContextCompat.getSystemService
  18. import android.icu.lang.UCharacter.GraphemeClusterBreak.T
  19. import android.R
  20. import androidx.core.os.HandlerCompat.postDelayed
  21. import androidx.core.app.ComponentActivity.ExtraData
  22. import androidx.core.content.ContextCompat.getSystemService
  23. import android.icu.lang.UCharacter.GraphemeClusterBreak.T
  24. import androidx.core.app.ComponentActivity.ExtraData
  25. import androidx.core.content.ContextCompat.getSystemService
  26. import android.icu.lang.UCharacter.GraphemeClusterBreak.T
  27. import android.widget.Toast
  28. import androidx.core.app.ComponentActivity.ExtraData
  29. import androidx.core.content.ContextCompat.getSystemService
  30. import android.icu.lang.UCharacter.GraphemeClusterBreak.T
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. open class BaseActivity : AppCompatActivity() {
  42.  
  43. private val mLanguageCode = "en"
  44.  
  45. private var frameEnBtn: FrameLayout? = null
  46. protected var btnEn: Button? = null
  47. private var btnToLogin: Button? = null
  48. private var btnServiceTerms: Button? = null
  49.  
  50. private var activityContainer: FrameLayout? = null
  51. private var rlHeaderView: LinearLayout? = null
  52. private var scaleAnim: Animation? = null
  53. private var shakeAnim: Animation? = null
  54. val counter = net.tipbox.pos.tipboxaqsi.Counter()
  55. var handler: Handler? = null
  56. var runable: Runnable? = null
  57.  
  58. override fun setContentView(layoutResID: Int) {
  59. val llparentView = layoutInflater
  60. .inflate(net.tipbox.pos.tipboxaqsi.R.layout.activity_header, null) as LinearLayout
  61. initViews(llparentView)
  62. layoutInflater.inflate(layoutResID, activityContainer, true)
  63. super.setContentView(llparentView)
  64. }
  65.  
  66.  
  67.  
  68. override fun onCreate(savedInstanceState: Bundle?) {
  69. super.onCreate(savedInstanceState)
  70. handler = Handler()
  71. runable = Runnable {
  72. // TODO Auto-generated method stub
  73. Toast.makeText(this@BaseActivity, "user is inactive from last 5 minutes", Toast.LENGTH_SHORT)
  74. .show()
  75. }
  76. startHandler()
  77.  
  78. setContentView(net.tipbox.pos.tipboxaqsi.R.layout.activity_thx)
  79. scaleAnim = AnimationUtils.loadAnimation(this, net.tipbox.pos.tipboxaqsi.R.anim.button_scale)
  80. shakeAnim = AnimationUtils.loadAnimation(this, net.tipbox.pos.tipboxaqsi.R.anim.shake)
  81. }
  82.  
  83. private fun initViews(view: View) {
  84. activityContainer = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.activity_content)
  85. rlHeaderView = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.header_view)
  86. btnEn = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btn_en)
  87. frameEnBtn = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btn_en_frame)
  88. btnToLogin = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btnLogin)
  89. btnServiceTerms = view.findViewById(net.tipbox.pos.tipboxaqsi.R.id.btn_offer)
  90. frameEnBtn!!.setOnClickListener(enBtnListener)
  91. btnToLogin!!.setOnClickListener(loginBtnListener)
  92. btnServiceTerms!!.setOnClickListener(serviceBtnListener)
  93.  
  94. btnEn!!.isSelected = btnEn!!.text == "ru"
  95. }
  96.  
  97. private val enBtnListener = View.OnClickListener {
  98. ChangeLanguage()
  99. }
  100.  
  101. open fun ChangeLanguage(){
  102. val lang = btnEn!!.text
  103.  
  104. btnEn!!.isSelected = lang == "en"
  105.  
  106. LocaleHelper.setLocale(this@BaseActivity, lang as String?)
  107. val stro = getString(net.tipbox.pos.tipboxaqsi.R.string.offer_text)
  108. (application as MyApplication).State?.SetOfferText(stro, lang)
  109. recreate()
  110. }
  111.  
  112. private val loginBtnListener = View.OnClickListener {
  113.  
  114. val c = counter.Count(true,3500)
  115.  
  116. if(c == 2){
  117. Handler().postDelayed({
  118. val fc = counter.Count(false)
  119. if(fc == 2){
  120. val pm = this.packageManager
  121. val myIntent = pm.getLaunchIntentForPackage(this.packageName)
  122. myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
  123. myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  124. finish()
  125. startActivity(myIntent)
  126. }
  127. else{counter.Reset()}
  128. }, 1000)
  129. }
  130. }
  131.  
  132. private val serviceBtnListener = View.OnClickListener {
  133. val app = application as MyApplication
  134. val dialog = net.tipbox.pos.tipboxaqsi.Activities.OfferDialog(this, app.State!!)
  135. dialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
  136. dialog.show()
  137. }
  138.  
  139. fun showHeader(show: Boolean) {
  140. rlHeaderView!!.visibility = if (show) View.VISIBLE else View.GONE
  141. }
  142.  
  143. fun showTerms(show: Boolean) {
  144. btnServiceTerms!!.visibility = if (show) View.VISIBLE else View.INVISIBLE
  145. }
  146.  
  147. fun playScaleAnim(view: View){
  148. view.isSelected = true
  149. view.startAnimation(scaleAnim)
  150. }
  151.  
  152. fun playShakeAnim(view: View){
  153. view.startAnimation(shakeAnim)
  154. }
  155.  
  156. fun startIntentWithDelay(intent: Intent, delay:Long){
  157. Handler().postDelayed({
  158. finish()
  159. startActivity(intent)
  160. }, delay)
  161. }
  162.  
  163. override fun onUserInteraction() {
  164. // TODO Auto-generated method stub
  165. super.onUserInteraction()
  166. stopHandler()//stop first and then start
  167. startHandler()
  168. }
  169.  
  170. fun stopHandler() {
  171. handler.removeCallbacks(runable)
  172. }
  173.  
  174. fun startHandler() {
  175. handler.postDelayed(runable, 5 * 60 * 1000) //for 5 minutes
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement