Advertisement
Guest User

Untitled

a guest
May 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. package com.taylorworld.tw1
  2.  
  3. import android.content.Context
  4. import android.content.Context.*
  5. import android.content.Intent
  6. import android.net.Uri
  7. import android.os.Bundle
  8. import android.support.design.widget.FloatingActionButton
  9. import android.support.design.widget.Snackbar
  10. import android.support.v4.view.GravityCompat
  11. import android.support.v7.app.ActionBarDrawerToggle
  12. import android.view.MenuItem
  13. import android.support.v4.widget.DrawerLayout
  14. import android.support.design.widget.NavigationView
  15. import android.support.v7.app.AppCompatActivity
  16. import android.support.v7.widget.Toolbar
  17. import android.view.Menu
  18. import android.view.View
  19. //import com.google.firebase.firestore.FirebaseFirestore
  20. import kotlinx.android.synthetic.main.content_main.*
  21.  
  22. class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
  23.  
  24.  
  25. override fun onCreate(savedInstanceState: Bundle?) {
  26. super.onCreate(savedInstanceState)
  27. setContentView(R.layout.activity_main)
  28. val toolbar: Toolbar = findViewById(R.id.toolbar)
  29. setSupportActionBar(toolbar)
  30.  
  31. val fab: FloatingActionButton = findViewById(R.id.fab)
  32. fab.setOnClickListener { view ->
  33. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  34. .setAction("Action", null).show()
  35. }
  36. val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
  37. val navView: NavigationView = findViewById(R.id.nav_view)
  38. val toggle = ActionBarDrawerToggle(
  39. this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
  40. )
  41. drawerLayout.addDrawerListener(toggle)
  42. toggle.syncState()
  43.  
  44. navView.setNavigationItemSelectedListener(this)
  45.  
  46. //val db = FirebaseFirestore.getInstance()
  47. }
  48.  
  49. override fun onBackPressed() {
  50. val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
  51. if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
  52. drawerLayout.closeDrawer(GravityCompat.START)
  53. } else {
  54. super.onBackPressed()
  55. }
  56. }
  57.  
  58. override fun onCreateOptionsMenu(menu: Menu): Boolean {
  59. // Inflate the menu; this adds items to the action bar if it is present.
  60. menuInflater.inflate(R.menu.main, menu)
  61. return true
  62. }
  63.  
  64. override fun onOptionsItemSelected(item: MenuItem): Boolean {
  65. // Handle action bar item clicks here. The action bar will
  66. // automatically handle clicks on the Home/Up button, so long
  67. // as you specify a parent activity in AndroidManifest.xml.
  68. return when (item.itemId) {
  69. R.id.action_settings -> true
  70. else -> super.onOptionsItemSelected(item)
  71. }
  72. }
  73.  
  74. override fun onNavigationItemSelected(item: MenuItem): Boolean {
  75. // Handle navigation view item clicks here.
  76. when (item.itemId) {
  77. R.id.nav_home -> {
  78. // Handle the camera action
  79. val i = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/brobostigon/"))
  80. startActivity(i)
  81. }
  82. R.id.nav_gallery -> {
  83.  
  84. }
  85. R.id.nav_slideshow -> {
  86.  
  87. }
  88. R.id.nav_tools -> {
  89.  
  90. }
  91. R.id.nav_share -> {
  92.  
  93. }
  94. R.id.nav_send -> {
  95.  
  96. }
  97. }
  98. val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
  99. drawerLayout.closeDrawer(GravityCompat.START)
  100. return true
  101. }
  102.  
  103. public fun saveStr(view: View) {
  104. var strength = Integer.parseInt(editText2.text.toString())
  105. // this should be getPreferences
  106. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  107. with(sharedPref.edit()) {
  108. putInt(getString(R.string.STR), strength)
  109. apply()
  110. }
  111. }
  112.  
  113. public fun saveDex(view: View) {
  114. var dexterity = Integer.parseInt(editText.text.toString())
  115. // this should be getPreferences
  116. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  117. with(sharedPref.edit()) {
  118. putInt(getString(R.string.DEX), dexterity)
  119. apply()
  120. }
  121. }
  122.  
  123. public fun saveInt(view: View) {
  124. var intelligance = Integer.parseInt(editText4.text.toString())
  125. // this should be getPreferences
  126. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  127. with(sharedPref.edit()) {
  128. putInt(getString(R.string.INT), intelligance)
  129. apply()
  130. }
  131. }
  132.  
  133. public fun saveWis(view: View) {
  134. var wisdom = Integer.parseInt(editText3.text.toString())
  135. // this should be getPreferences
  136. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  137. with(sharedPref.edit()) {
  138. putInt(getString(R.string.WIS), wisdom)
  139. apply()
  140. }
  141.  
  142. }
  143.  
  144. public fun saveCha(view: View) {
  145. var charisma = Integer.parseInt(editText5.text.toString())
  146. // this should be getPreferences
  147. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  148. with(sharedPref.edit()) {
  149. putInt(getString(R.string.CHA), charisma)
  150. apply()
  151. }
  152.  
  153. }
  154.  
  155. public fun saveCon(view: View) {
  156. var constitution = Integer.parseInt(editText6.text.toString())
  157. // this should be getPreferences
  158. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  159. with(sharedPref.edit()) {
  160. putInt(getString(R.string.CON), constitution)
  161. apply()
  162. }
  163.  
  164. }
  165.  
  166. public fun saveChr(view: View) {
  167. var chrname = editText7.text.toString()
  168. // this should be getPreferences
  169. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE);
  170. with(sharedPref.edit()) {
  171. putString(getString(R.string.CHR), chrname)
  172. apply()
  173. }
  174. }
  175.  
  176. public fun readSP(view: View) {
  177.  
  178. val sharedPref = this?.getPreferences(Context.MODE_PRIVATE)
  179.  
  180. val mystr = sharedPref.getInt(getString(R.string.STR), 0);
  181. editText2.setText(Integer.toString(mystr))
  182.  
  183. val mydex = sharedPref.getInt(getString(R.string.DEX), 0);
  184. editText.setText(Integer.toString(mydex))
  185.  
  186. val myint = sharedPref.getInt(getString(R.string.INT), 0);
  187. editText4.setText(Integer.toString(myint))
  188.  
  189. val mywis = sharedPref.getInt(getString(R.string.WIS), 0);
  190. editText3.setText(Integer.toString(mywis))
  191.  
  192. val mycon = sharedPref.getInt(getString(R.string.CON), 0);
  193. editText6.setText(Integer.toString(mycon))
  194.  
  195. val mycha = sharedPref.getInt(getString(R.string.CHA), 0);
  196. editText2.setText(Integer.toString(mycha))
  197.  
  198. val mychr = sharedPref.getString(getString(R.string.CHR), null);
  199. editText2.setText(mychr)
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement