Skip to content

Commit ab34f16

Browse files
committed
Check API version and other improvement
1 parent b2ea88d commit ab34f16

File tree

10 files changed

+184
-160
lines changed

10 files changed

+184
-160
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The best Android spinner library for your android application
1919

2020
```gradle
2121
dependencies {
22-
implementation 'com.github.chivorns:smartmaterialspinner:1.0.4'
22+
implementation 'com.github.chivorns:smartmaterialspinner:1.0.5'
2323
}
2424
```
2525

build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext{
3+
ext {
44
kotlin_version = '1.3.31'
55
}
66

@@ -13,7 +13,7 @@ buildscript {
1313
classpath 'com.android.tools.build:gradle:3.4.1'
1414
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1515
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
16-
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
16+
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
1717
// NOTE: Do not place your application dependencies here; they belong
1818
// in the individual module build.gradle files
1919
}
@@ -31,6 +31,13 @@ allprojects {
3131
options.addStringOption('encoding', 'UTF-8')
3232
options.addBooleanOption('Xdoclint:none', true)
3333
}
34+
35+
gradle.projectsEvaluated {
36+
tasks.withType(JavaCompile) {
37+
options.compilerArgs << "-Xlint:deprecation"
38+
options.compilerArgs << "-Xlint:unchecked"
39+
}
40+
}
3441
}
3542

3643
task clean(type: Delete) {

demojava/src/main/java/com/chivorn/demojava/MainActivity.java

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,40 @@
11
package com.chivorn.demojava;
22

33
import android.os.Bundle;
4+
import android.support.v4.content.ContextCompat;
45
import android.view.View;
56
import android.widget.AdapterView;
67
import android.widget.Toast;
78

89
import com.chivorn.resourcemodule.MainApp;
910
import com.chivorn.smartmaterialspinner.SmartMaterialSpinner;
1011

11-
import java.util.ArrayList;
12-
1312
public class MainActivity extends MainApp {
1413
@Override
1514
protected void onCreate(Bundle savedInstanceState) {
1615
super.onCreate(savedInstanceState);
1716
setContentView(R.layout.smart_material_spinner_sample_layout);
1817

1918
initBaseView();
19+
initItemList();
2020
initSpinnerInJava();
21-
onClickListenter();
21+
onClickListener();
2222
}
2323

2424
private void initSpinnerInJava() {
25-
provinceList = new ArrayList<>();
26-
provinceList.add("Banteay Meanchey");
27-
provinceList.add("Battambang");
28-
provinceList.add("Kampong Cham");
29-
provinceList.add("Kampong Chhnang");
30-
provinceList.add("Kampong Speu");
31-
provinceList.add("Kampong Thom");
32-
provinceList.add("Kampot");
33-
provinceList.add("Kandal");
34-
provinceList.add("Kep");
35-
provinceList.add("Koh Kong");
36-
provinceList.add("Kratie");
37-
provinceList.add("Mondulkiri");
38-
provinceList.add("Oddar Meanchey");
39-
provinceList.add("Pailin");
40-
provinceList.add("Phnom Penh");
41-
provinceList.add("Preah Vihear");
42-
provinceList.add("Prey Veng");
43-
provinceList.add("Pursat");
44-
provinceList.add("Ratanakiri");
45-
provinceList.add("Siem Reap");
46-
provinceList.add("Sihanoukville");
47-
provinceList.add("Stung Treng");
48-
provinceList.add("Svay Rieng");
49-
provinceList.add("Takeo");
50-
provinceList.add("Tbong Khmum");
51-
5225
spProvince.setItems(provinceList);
5326
spProvinceDialog.setItems(provinceList);
5427
spCustomColor.setItems(provinceList);
5528
spSearchable.setItems(provinceList);
5629

57-
spCustomColor.setItemColor(getResources().getColor(R.color.custom_item_color));
58-
spCustomColor.setSelectedItemColor(getResources().getColor(R.color.custom_selected_item_color));
59-
spCustomColor.setItemListColor(getResources().getColor(R.color.custom_item_list_color));
30+
spCustomColor.setItemColor(ContextCompat.getColor(this, R.color.custom_item_color));
31+
spCustomColor.setSelectedItemColor(ContextCompat.getColor(this, R.color.custom_selected_item_color));
32+
spCustomColor.setItemListColor(ContextCompat.getColor(this, R.color.custom_item_list_color));
6033

6134
spProvince.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
6235
@Override
6336
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
64-
spProvince.setError("You are selecting on spinner item -> \"" + provinceList.get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
37+
spProvince.setError("You are selecting on spinner item -> \"" + spProvince.getItems().get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
6538
}
6639

6740
@Override
@@ -73,7 +46,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
7346
spProvinceDialog.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
7447
@Override
7548
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
76-
spProvinceDialog.setError("You are selecting on spinner item -> \"" + provinceList.get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
49+
spProvinceDialog.setError("You are selecting on spinner item -> \"" + spProvinceDialog.getItems().get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
7750
}
7851

7952
@Override
@@ -85,7 +58,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
8558
spCustomColor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
8659
@Override
8760
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
88-
spCustomColor.setError("You are selecting on spinner item -> \"" + provinceList.get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
61+
spCustomColor.setError("You are selecting on spinner item -> \"" + spCustomColor.getItems().get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
8962
}
9063

9164
@Override
@@ -97,7 +70,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
9770
spSearchable.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
9871
@Override
9972
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
100-
spSearchable.setError("Your selected item is \"" + provinceList.get(position) + "\" .");
73+
spSearchable.setError("Your selected item is \"" + spSearchable.getItems().get(position) + "\" .");
10174
}
10275

10376
@Override
Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,60 @@
11
package com.chivorn.demokotlin
22

33
import android.os.Bundle
4-
import android.view.MotionEvent
54
import android.view.View
65
import android.widget.AdapterView
76
import android.widget.Toast
87
import com.chivorn.resourcemodule.MainApp
9-
import java.util.*
108

119
class MainActivity : MainApp() {
1210
override fun onCreate(savedInstanceState: Bundle?) {
1311
super.onCreate(savedInstanceState)
1412
setContentView(R.layout.smart_material_spinner_sample_layout)
1513

1614
initBaseView()
15+
initItemList()
1716
initSpinnerInKotlin()
18-
onClickListenter()
17+
onClickListener()
1918
}
2019

2120
private fun initSpinnerInKotlin() {
22-
provinceList = ArrayList()
23-
provinceList.add("Banteay Meanchey")
24-
provinceList.add("Battambang")
25-
provinceList.add("Kampong Cham")
26-
provinceList.add("Kampong Chhnang")
27-
provinceList.add("Kampong Speu")
28-
provinceList.add("Kampong Thom")
29-
provinceList.add("Kampot")
30-
provinceList.add("Kandal")
31-
provinceList.add("Kep")
32-
provinceList.add("Koh Kong")
33-
provinceList.add("Kratie")
34-
provinceList.add("Mondulkiri")
35-
provinceList.add("Oddar Meanchey")
36-
provinceList.add("Pailin")
37-
provinceList.add("Phnom Penh")
38-
provinceList.add("Preah Vihear")
39-
provinceList.add("Prey Veng")
40-
provinceList.add("Pursat")
41-
provinceList.add("Ratanakiri")
42-
provinceList.add("Siem Reap")
43-
provinceList.add("Sihanoukville")
44-
provinceList.add("Stung Treng")
45-
provinceList.add("Svay Rieng")
46-
provinceList.add("Takeo")
47-
provinceList.add("Tbong Khmum")
48-
49-
spProvince!!.setItems<Any>(provinceList!!)
50-
spProvinceDialog!!.setItems<Any>(provinceList)
51-
spCustomColor!!.setItems<Any>(provinceList)
52-
spSearchable!!.setItems<Any>(provinceList)
21+
spProvince!!.items = (provinceList as List<Any>?)!!
22+
spProvinceDialog!!.items = provinceList as List<Any>
23+
spCustomColor!!.items = provinceList as List<Any>
24+
spSearchable!!.items = provinceList as List<Any>
5325

5426
spProvince!!.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
5527
override fun onItemSelected(adapterView: AdapterView<*>, view: View, position: Int, id: Long) {
56-
spProvince?.error = "You are selecting on spinner item -> \"" + provinceList[position] + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines"
28+
spProvince?.error = "You are selecting on spinner item -> \"" + spProvince.items[position] + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines"
5729
}
5830

5931
override fun onNothingSelected(adapterView: AdapterView<*>) {}
6032
}
6133

6234
spProvinceDialog!!.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
6335
override fun onItemSelected(adapterView: AdapterView<*>, view: View, position: Int, id: Long) {
64-
spProvinceDialog?.error = "You are selecting on spinner item -> \"" + provinceList[position] + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines"
36+
spProvinceDialog?.error = "You are selecting on spinner item -> \"" + spProvinceDialog.items[position] + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines"
6537
}
6638

6739
override fun onNothingSelected(adapterView: AdapterView<*>) {}
6840
}
6941

7042
spCustomColor!!.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
7143
override fun onItemSelected(adapterView: AdapterView<*>, view: View, position: Int, id: Long) {
72-
spCustomColor?.error = "You are selecting on spinner item -> \"" + provinceList[position] + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines"
44+
spCustomColor?.error = "You are selecting on spinner item -> \"" + spCustomColor.items[position] + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines"
7345
}
7446

7547
override fun onNothingSelected(adapterView: AdapterView<*>) {}
7648
}
7749

7850
spSearchable!!.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
7951
override fun onItemSelected(adapterView: AdapterView<*>, view: View, position: Int, id: Long) {
80-
spSearchable?.error = "Your selected item is \"" + provinceList.get(position) + "\" ."
52+
spSearchable?.error = "Your selected item is \"" + spSearchable.items[position] + "\" ."
8153
}
8254

8355
override fun onNothingSelected(adapterView: AdapterView<*>) {}
8456
}
8557

86-
spEmptyItem!!.setShowEmptyDropdown(false)
87-
// Use this method instead of OnClicklistener() to handle touch even.
88-
spEmptyItem!!.setOnTouchListener({ v, event ->
89-
if (event.action == MotionEvent.ACTION_UP) {
90-
Toast.makeText(this@MainActivity, getString(R.string.empty_item_spinner_click_msg), Toast.LENGTH_SHORT).show()
91-
}
92-
false
93-
})
58+
spEmptyItem!!.setOnEmptySpinnerClicked { Toast.makeText(this@MainActivity, getString(R.string.empty_item_spinner_click_msg), Toast.LENGTH_SHORT).show() }
9459
}
9560
}

resources/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 27
4+
compileSdkVersion 28
55
defaultConfig {
66
minSdkVersion 14
7-
targetSdkVersion 27
7+
targetSdkVersion 28
88
versionCode 1
99
versionName "1.0.0"
1010

@@ -26,9 +26,9 @@ android {
2626
dependencies {
2727
implementation fileTree(dir: 'libs', include: ['*.jar'])
2828
implementation project(':smartmaterialspinner')
29-
api 'com.android.support:appcompat-v7:27.1.1'
30-
api 'com.android.support.constraint:constraint-layout:1.1.0'
31-
api'junit:junit:4.12'
29+
api 'com.android.support:appcompat-v7:28.0.0'
30+
api 'com.android.support.constraint:constraint-layout:1.1.3'
31+
api 'junit:junit:4.12'
3232
api 'com.android.support.test:runner:1.0.2'
3333
api 'com.android.support.test.espresso:espresso-core:3.0.2'
3434
}

resources/src/main/java/com/chivorn/resourcemodule/MainApp.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
import com.chivorn.smartmaterialspinner.SmartMaterialSpinner;
1111

12+
import java.util.ArrayList;
13+
import java.util.HashMap;
1214
import java.util.List;
15+
import java.util.Map;
1316

1417
public class MainApp extends AppCompatActivity implements View.OnClickListener {
1518
private final String repoUrl = "https://github.com/Chivorns/SmartMaterialSpinner";
@@ -19,7 +22,7 @@ public class MainApp extends AppCompatActivity implements View.OnClickListener {
1922
protected SmartMaterialSpinner spCustomColor;
2023
protected SmartMaterialSpinner spEmptyItem;
2124
protected SmartMaterialSpinner spSearchable;
22-
protected List<String> provinceList;
25+
protected List<Object> provinceList;
2326

2427
private LinearLayout githubRepo;
2528
private Button btnShowError;
@@ -37,7 +40,51 @@ public void initBaseView() {
3740
githubRepoBtn = findViewById(R.id.github_repo_btn);
3841
}
3942

40-
public void onClickListenter() {
43+
public void initItemList() {
44+
provinceList = new ArrayList<>();
45+
provinceList.add("Banteay Meanchey");
46+
provinceList.add("Battambang");
47+
provinceList.add("Kampong Cham");
48+
provinceList.add("Kampong Chhnang");
49+
provinceList.add("Kampong Speu");
50+
provinceList.add("Kampong Thom");
51+
provinceList.add("Kampot");
52+
provinceList.add("Kandal");
53+
provinceList.add("Kep");
54+
provinceList.add("Koh Kong");
55+
provinceList.add("Kratie");
56+
provinceList.add("Mondulkiri");
57+
provinceList.add("Oddar Meanchey");
58+
provinceList.add("Pailin");
59+
provinceList.add("Phnom Penh");
60+
provinceList.add("Preah Vihear");
61+
provinceList.add("Prey Veng");
62+
provinceList.add("Pursat");
63+
provinceList.add("Ratanakiri");
64+
provinceList.add("Siem Reap");
65+
provinceList.add("Sihanoukville");
66+
provinceList.add("Stung Treng");
67+
provinceList.add("Svay Rieng");
68+
provinceList.add("Takeo");
69+
provinceList.add("Tbong Khmum");
70+
71+
provinceList.add(111);
72+
provinceList.add(222);
73+
provinceList.add(333);
74+
provinceList.add(444);
75+
provinceList.add(555.555);
76+
77+
provinceList.add(true);
78+
79+
Map<String, String> map = new HashMap<>();
80+
map.put("A", "This is value of A");
81+
map.put("B", "This is value of B");
82+
map.put("C", "This is value of C");
83+
84+
provinceList.add(map);
85+
}
86+
87+
public void onClickListener() {
4188
if (githubRepo != null && githubRepoBtn != null) {
4289
githubRepo.setOnClickListener(this);
4390
githubRepoBtn.setOnClickListener(this);

resources/src/main/res/layout/smart_material_spinner_sample_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
android:layout_height="wrap_content"
2828
android:spinnerMode="dialog"
2929
app:smsp_error="@string/sample_error_message"
30-
app:smsp_errorTextSize="12dp"
30+
app:smsp_errorTextSize="12sp"
3131
app:smsp_hint="Searchable Spinner"
3232
app:smsp_hintTextSize="14sp"
3333
app:smsp_isSearchable="true"

smartmaterialspinner/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ ext {
55
LIBRARY_NAME = 'SmartMaterialSpinner'
66
PUBLISH_GROUP_ID = 'com.github.chivorns'
77
PUBLISH_ARTIFACT_ID = LIBRARY_NAME.toLowerCase()
8-
PUBLISH_VERSION = '1.0.4'
8+
PUBLISH_VERSION = '1.0.5'
99

1010
// Bintray
1111
BINTRAY_REPO = 'maven'
1212
LIBRARY_DESC = 'Provide with more customization for your spinner.'
1313

1414
// Github
1515
GIT_REPO_URL = 'https://github.com/Chivorns/SmartMaterialSpinner'
16-
GIT_VCS_URL = GIT_REPO_URL + '.git'
16+
GIT_VCS_URL = GIT_REPO_URL + '.git'
1717
GIT_USER_REPO_NAME = 'Chivorns/SmartMaterialSpinner'
1818

1919
// Developer Info
@@ -28,11 +28,11 @@ ext {
2828
}
2929

3030
android {
31-
compileSdkVersion 27
31+
compileSdkVersion 28
3232
defaultConfig {
3333
minSdkVersion 14
34-
targetSdkVersion 27
35-
versionCode 4
34+
targetSdkVersion 28
35+
versionCode 5
3636
versionName "$PUBLISH_VERSION"
3737

3838
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -57,7 +57,7 @@ android {
5757
dependencies {
5858
implementation fileTree(dir: 'libs', include: ['*.jar'])
5959

60-
implementation 'com.android.support:appcompat-v7:27.1.1'
60+
implementation 'com.android.support:appcompat-v7:28.0.0'
6161
testImplementation 'junit:junit:4.12'
6262
androidTestImplementation 'com.android.support.test:runner:1.0.2'
6363
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

0 commit comments

Comments
 (0)