diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..15fe9d7 Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml deleted file mode 100644 index 183ec08..0000000 --- a/.idea/checkstyle-idea.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 0a0c222..99202cc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,18 +1,16 @@ - - - @@ -27,29 +25,10 @@ - + - - - - - - - 1.8 - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index f702f35..dfb3ec7 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml deleted file mode 100644 index e24d63d..0000000 --- a/.idea/qaplug_profiles.xml +++ /dev/null @@ -1,289 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 35b2f51..7acf9c8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.application' android { compileSdkVersion 25 - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { applicationId "com.lib.kingja.switchbutton" @@ -18,15 +17,23 @@ android { } } + testOptions{ + unitTests{ + includeAndroidResources = true + } + } + lintOptions { abortOnError false } + buildToolsVersion '27.0.3' } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile project(':libk-switchbutton') + implementation fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.12' + implementation project(':libk-switchbutton') // compile 'lib.kingja.switchbutton:switchbutton:1.1.6' - compile "com.android.support:appcompat-v7:$rootProject.ext.supportVersion" + implementation "com.android.support:appcompat-v7:$rootProject.ext.supportVersion" + testImplementation "org.robolectric:robolectric:3.8" } diff --git a/app/src/androidTest/java/com/kingja/switchbutton/ApplicationTest.java b/app/src/androidTest/java/com/kingja/switchbutton/ApplicationTest.java deleted file mode 100644 index c998a7e..0000000 --- a/app/src/androidTest/java/com/kingja/switchbutton/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.kingja.switchbutton; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/kingja/switchbutton/MainActivity.java b/app/src/main/java/com/kingja/switchbutton/MainActivity.java index 849b3a6..0a9dfac 100644 --- a/app/src/main/java/com/kingja/switchbutton/MainActivity.java +++ b/app/src/main/java/com/kingja/switchbutton/MainActivity.java @@ -19,6 +19,10 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.Switch; import android.widget.Toast; import com.lib.kingja.switchbutton.R; @@ -36,25 +40,82 @@ */ public class MainActivity extends AppCompatActivity { - private String[] tabTexts1 = {"才子", "帅哥", "大湿", "猛将兄"}; + private String[] tabTexts1 = {"test1", "test2", "test3", "test4"}; private String[] tabTexts4 = {"已经", "在家", "等你"}; + private SwitchMultiButton smb; + private boolean showToast = false; + + private SwitchMultiButton.OnSwitchListener onSwitchListener = new SwitchMultiButton.OnSwitchListener() { + @Override + public void onSwitch(int position, String tabText) { + //Toast.makeText(MainActivity.this, tabText, Toast.LENGTH_SHORT).show(); + } + }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - ((SwitchMultiButton) findViewById(R.id.switchmultibutton1)).setText(tabTexts1).setOnSwitchListener(onSwitchListener); + smb = ((SwitchMultiButton) findViewById(R.id.switchmultibutton1)); + smb.setText(tabTexts1).setOnSwitchListener(onSwitchListener); + + Integer in[] = new Integer[]{0, 2}; + + for (Integer i : in) { + smb.setSelectedTab(i); + } + ((SwitchMultiButton) findViewById(R.id.switchmultibutton2)).setText("点个Star", "狠心拒绝").setOnSwitchListener(onSwitchListener); ((SwitchMultiButton) findViewById(switchmultibutton3)).setOnSwitchListener(onSwitchListener).setSelectedTab(1); ((SwitchMultiButton) findViewById(R.id.switchmultibutton4)).setText(tabTexts4).setOnSwitchListener(onSwitchListener); - } - private SwitchMultiButton.OnSwitchListener onSwitchListener = new SwitchMultiButton.OnSwitchListener() { - @Override - public void onSwitch(int position, String tabText) { - Toast.makeText(MainActivity.this, tabText, Toast.LENGTH_SHORT).show(); - } - }; + Button unselect = (Button) findViewById(R.id.button); + Button select = (Button) findViewById(R.id.button2); + Switch sw = (Switch) findViewById(R.id.switch1); + + unselect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + smb.clearSelected(); + } + }); + + select.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Runnable r = new Runnable() { + @Override + public void run() { + for (int i = 0; i < tabTexts1.length; i++) { + final int ii[] = new int[1]; + ii[0] = i; + smb.setSelectedTab(ii[0]); + } + } + }; + new Thread(r).run(); + } + }); + + sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + showToast = isChecked; + } + }); + + smb.setOnSwitchListener(new SwitchMultiButton.OnSwitchListener() { + @Override + public void onSwitch(int position, String tabText) { + if (showToast) + Toast.makeText(getBaseContext(), tabText + " pressed", Toast.LENGTH_SHORT).show(); + } + }); + } + + public SwitchMultiButton getSwitchMultiButton() { + return smb; + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index cfcca24..78dbbd4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,11 +1,11 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:orientation="vertical" + android:padding="16dp"> - + app:textSize="14sp" /> + app:textSize="14sp" /> + app:textSize="14sp" + app:typeface="tielanti.ttf" /> + app:textSize="14sp" /> + app:typeface="DeVinneTxtBT.ttf" /> + + + +