@@ -9,28 +9,32 @@ import android.util.Log
9
9
import android.view.Menu
10
10
import android.view.MenuItem
11
11
import android.view.View
12
- import android.widget.*
13
12
import android.widget.AdapterView.OnItemClickListener
13
+ import android.widget.ArrayAdapter
14
+ import android.widget.Button
15
+ import android.widget.TextView
16
+ import android.widget.Toast
14
17
import androidx.appcompat.app.AppCompatActivity
15
18
import androidx.appcompat.widget.Toolbar
16
19
import com.sothree.slidinguppanel.PanelSlideListener
17
20
import com.sothree.slidinguppanel.PanelState
18
21
import com.sothree.slidinguppanel.demo.databinding.ActivityDemoBinding
19
- import java.util.*
20
22
21
23
class DemoActivity : AppCompatActivity () {
22
24
25
+ private val tag = " DemoActivity"
23
26
private lateinit var binding: ActivityDemoBinding
24
-
27
+
25
28
override fun onCreate (savedInstanceState : Bundle ? ) {
26
29
super .onCreate(savedInstanceState)
27
30
binding = ActivityDemoBinding .inflate(layoutInflater)
28
31
setContentView(binding.root)
29
-
32
+
30
33
setSupportActionBar(findViewById<View >(R .id.main_toolbar) as Toolbar )
31
- binding.listView.onItemClickListener =
32
- OnItemClickListener { parent, view, position, id -> Toast .makeText(this @DemoActivity, " onItemClick" , Toast .LENGTH_SHORT ).show() }
33
- val yourArrayList = Arrays .asList(
34
+ binding.listView.onItemClickListener = OnItemClickListener { _, _, _, _ ->
35
+ Toast .makeText(this @DemoActivity, " onItemClick" , Toast .LENGTH_SHORT ).show()
36
+ }
37
+ val yourArrayList = listOf (
34
38
" This" ,
35
39
" Is" ,
36
40
" An" ,
@@ -61,18 +65,16 @@ class DemoActivity : AppCompatActivity() {
61
65
// first parameter, the type of list view as a second parameter and your
62
66
// array as a third parameter.
63
67
val arrayAdapter = ArrayAdapter (
64
- this ,
65
- android.R .layout.simple_list_item_1,
66
- yourArrayList
68
+ this , android.R .layout.simple_list_item_1, yourArrayList
67
69
)
68
70
binding.listView.adapter = arrayAdapter
69
71
binding.slidingLayout.addPanelSlideListener(object : PanelSlideListener {
70
72
override fun onPanelSlide (panel : View , slideOffset : Float ) {
71
- Log .i(TAG , " onPanelSlide, offset $slideOffset " )
73
+ Log .i(tag , " onPanelSlide, offset $slideOffset " )
72
74
}
73
75
74
76
override fun onPanelStateChanged (panel : View , previousState : PanelState , newState : PanelState ) {
75
- Log .i(TAG , " onPanelStateChanged $newState " )
77
+ Log .i(tag , " onPanelStateChanged $newState " )
76
78
}
77
79
})
78
80
binding.slidingLayout.setFadeOnClickListener { binding.slidingLayout.setPanelState(PanelState .COLLAPSED ) }
@@ -92,38 +94,35 @@ class DemoActivity : AppCompatActivity() {
92
94
// Inflate the menu; this adds items to the action bar if it is present.
93
95
menuInflater.inflate(R .menu.demo, menu)
94
96
val item = menu.findItem(R .id.action_toggle)
95
- if (binding.slidingLayout.panelState == PanelState .HIDDEN ) {
97
+ if (binding.slidingLayout.getPanelState() == PanelState .HIDDEN ) {
96
98
item.setTitle(R .string.action_show)
97
99
} else {
98
100
item.setTitle(R .string.action_hide)
99
101
}
100
102
return true
101
103
}
102
104
103
- override fun onPrepareOptionsMenu (menu : Menu ): Boolean {
104
- return super .onPrepareOptionsMenu(menu)
105
- }
106
-
107
105
override fun onOptionsItemSelected (item : MenuItem ): Boolean {
108
106
when (item.itemId) {
109
107
R .id.action_toggle -> {
110
- if (binding.slidingLayout.panelState != PanelState .HIDDEN ) {
111
- binding.slidingLayout.panelState = PanelState .HIDDEN
108
+ if (binding.slidingLayout.getPanelState() != PanelState .HIDDEN ) {
109
+ binding.slidingLayout.setPanelState( PanelState .HIDDEN )
112
110
item.setTitle(R .string.action_show)
113
111
} else {
114
- binding.slidingLayout.panelState = PanelState .COLLAPSED
112
+ binding.slidingLayout.setPanelState( PanelState .COLLAPSED )
115
113
item.setTitle(R .string.action_hide)
116
114
}
117
115
return true
118
116
}
117
+
119
118
R .id.action_anchor -> {
120
119
if (binding.slidingLayout.anchorPoint == 1.0f ) {
121
120
binding.slidingLayout.anchorPoint = 0.7f
122
- binding.slidingLayout.panelState = PanelState .ANCHORED
121
+ binding.slidingLayout.setPanelState( PanelState .ANCHORED )
123
122
item.setTitle(R .string.action_anchor_disable)
124
123
} else {
125
124
binding.slidingLayout.anchorPoint = 1.0f
126
- binding.slidingLayout.panelState = PanelState .COLLAPSED
125
+ binding.slidingLayout.setPanelState( PanelState .COLLAPSED )
127
126
item.setTitle(R .string.action_anchor_enable)
128
127
}
129
128
return true
@@ -133,14 +132,10 @@ class DemoActivity : AppCompatActivity() {
133
132
}
134
133
135
134
override fun onBackPressed () {
136
- if ((binding.slidingLayout.panelState == PanelState .EXPANDED || binding.slidingLayout.panelState == PanelState .ANCHORED )) {
137
- binding.slidingLayout.panelState = PanelState .COLLAPSED
135
+ if ((binding.slidingLayout.getPanelState() == PanelState .EXPANDED || binding.slidingLayout.getPanelState() == PanelState .ANCHORED )) {
136
+ binding.slidingLayout.setPanelState( PanelState .COLLAPSED )
138
137
} else {
139
138
super .onBackPressed()
140
139
}
141
140
}
142
-
143
- companion object {
144
- private const val TAG = " DemoActivity"
145
- }
146
- }
141
+ }
0 commit comments