fix: 控件库化

This commit is contained in:
guangli.lgl
2017-03-02 11:02:45 +08:00
parent c696071f3c
commit 9b2341be6c
29 changed files with 41 additions and 111 deletions

2
.idea/gradle.xml generated
View File

@@ -8,7 +8,7 @@
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/lib" /> <option value="$PROJECT_DIR$/corelibrary" />
<option value="$PROJECT_DIR$/simple" /> <option value="$PROJECT_DIR$/simple" />
</set> </set>
</option> </option>

2
.idea/modules.xml generated
View File

@@ -3,7 +3,7 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/VerificationCodeInput.iml" filepath="$PROJECT_DIR$/VerificationCodeInput.iml" /> <module fileurl="file://$PROJECT_DIR$/VerificationCodeInput.iml" filepath="$PROJECT_DIR$/VerificationCodeInput.iml" />
<module fileurl="file://$PROJECT_DIR$/lib/lib.iml" filepath="$PROJECT_DIR$/lib/lib.iml" /> <module fileurl="file://$PROJECT_DIR$/corelibrary/corelibrary.iml" filepath="$PROJECT_DIR$/corelibrary/corelibrary.iml" />
<module fileurl="file://$PROJECT_DIR$/simple/simple.iml" filepath="$PROJECT_DIR$/simple/simple.iml" /> <module fileurl="file://$PROJECT_DIR$/simple/simple.iml" filepath="$PROJECT_DIR$/simple/simple.iml" />
</modules> </modules>
</component> </component>

View File

@@ -15,6 +15,7 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
jcenter() jcenter()
maven { url "https://jitpack.io" }
} }
} }

View File

@@ -1,11 +1,10 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.library'
android { android {
compileSdkVersion 24 compileSdkVersion 24
buildToolsVersion "25.0.0" buildToolsVersion "25.0.0"
defaultConfig { defaultConfig {
applicationId "com.dalimao.lib"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 24 targetSdkVersion 24
versionCode 1 versionCode 1

View File

@@ -1,4 +1,4 @@
package com.dalimao.lib; package com.dalimao.corelibrary;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
@@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
// Context of the app under test. // Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext(); Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.dalimao.lib", appContext.getPackageName()); assertEquals("com.dalimao.corelibrary.test", appContext.getPackageName());
} }
} }

View File

@@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dalimao.corelibrary">
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>

View File

@@ -6,7 +6,7 @@
* *
*/ */
package com.dalimao.lib; package com.dalimao.corelibrary;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@@ -100,12 +100,13 @@ public class VerificationCodeInput extends ViewGroup {
layoutParams.topMargin = childVPadding; layoutParams.topMargin = childVPadding;
layoutParams.leftMargin = childHPadding; layoutParams.leftMargin = childHPadding;
layoutParams.rightMargin = childHPadding; layoutParams.rightMargin = childHPadding;
layoutParams.gravity = Gravity.CENTER;
editText.setBackground(boxBg);
editText.setLayoutParams(layoutParams);
editText.setGravity(Gravity.CENTER); editText.setGravity(Gravity.CENTER);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1)}); editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1)});
editText.setCursorVisible(false); editText.setCursorVisible(false);
editText.setInputType(InputType.TYPE_CLASS_NUMBER); editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setBackground(boxBg);
editText.setLayoutParams(layoutParams);
editText.setId(i); editText.setId(i);
editText.setEms(1); editText.setEms(1);
editText.addTextChangedListener(textWatcher); editText.addTextChangedListener(textWatcher);

View File

@@ -2,7 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"> <item android:state_window_focused="false">
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFff" /> <solid android:color="#FaFafa" />
<corners android:radius="3dip"/> <corners android:radius="3dip"/>
<stroke <stroke
android:width="1dip" android:width="1dip"
@@ -15,7 +15,7 @@
<corners android:radius="3dip"/> <corners android:radius="3dip"/>
<stroke <stroke
android:width="1dip" android:width="1dip"
android:color="@color/colorAccent" /> android:color="#ffee33" />
</shape> </shape>
</item> </item>
</selector> </selector>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">CoreLibrary</string>
</resources>

View File

@@ -1,4 +1,4 @@
package com.dalimao.lib; package com.dalimao.corelibrary;
import org.junit.Test; import org.junit.Test;

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dalimao.lib">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -1,22 +0,0 @@
package com.dalimao.lib;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VerificationCodeInput input = (VerificationCodeInput) findViewById(R.id.verificationCodeInput);
input.setOnCompleteListener(new VerificationCodeInput.Listener() {
@Override
public void onComplete(String content) {
Toast.makeText(MainActivity.this,content, Toast.LENGTH_LONG);
}
});
}
}

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
xmlns:ver="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.dalimao.lib.MainActivity">
<com.dalimao.lib.VerificationCodeInput
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ver:box="4"
ver:box_bg="@drawable/edit_bg_selector"
ver:child_h_padding="5dp"
android:layout_centerInParent="true"
android:id="@+id/verificationCodeInput"
>
</com.dalimao.lib.VerificationCodeInput>
</RelativeLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -1,6 +0,0 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -1,5 +0,0 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@@ -1,3 +0,0 @@
<resources>
<string name="app_name">Lib</string>
</resources>

View File

@@ -1,11 +0,0 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

View File

@@ -1 +1 @@
include ':simple', ':lib' include ':simple', ':corelibrary'

View File

@@ -26,4 +26,6 @@ dependencies {
}) })
compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
// compile 'com.github.liuguangli:VerificationCodeInput:master-SNAPSHOT'
compile project(':corelibrary');
} }

View File

@@ -1,17 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:id="@+id/activity_main" xmlns:ver="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.dalimao.verificationcodeinput.MainActivity"> tools:context="com.dalimao.verificationcodeinput.MainActivity">
<TextView
<com.dalimao.corelibrary.VerificationCodeInput
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Hello World!" /> ver:box="4"
ver:box_bg="@drawable/verification_edit_bg_selector"
ver:child_h_padding="5dp"
android:layout_centerInParent="true"
android:id="@+id/verificationCodeInput"
>
</com.dalimao.corelibrary.VerificationCodeInput>
</RelativeLayout> </RelativeLayout>