序列化例子
This commit is contained in:
@@ -18,6 +18,11 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="com.plugin.component.ParcelableActivity"
|
||||||
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.plugin.component;
|
package com.plugin.component;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
@@ -10,6 +11,8 @@ import com.plugin.library.ISdk;
|
|||||||
import com.plugin.library.ISdk2;
|
import com.plugin.library.ISdk2;
|
||||||
import com.plugin.librarykotlin.IGetFromLibrary;
|
import com.plugin.librarykotlin.IGetFromLibrary;
|
||||||
import com.plugin.librarykotlin.IProvideFromKotlin;
|
import com.plugin.librarykotlin.IProvideFromKotlin;
|
||||||
|
import com.plugin.librarykotlin.JavaParcelable;
|
||||||
|
import com.plugin.librarykotlin.KotlinParcelable;
|
||||||
import com.plugin.module.R;
|
import com.plugin.module.R;
|
||||||
import com.plugin.pin.MainBase;
|
import com.plugin.pin.MainBase;
|
||||||
import com.plugin.pin.base.PBase;
|
import com.plugin.pin.base.PBase;
|
||||||
@@ -56,6 +59,18 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
stringBuilder.append("common -> " + new PCommon().getString() + "\n");
|
stringBuilder.append("common -> " + new PCommon().getString() + "\n");
|
||||||
stringBuilder.append("普通模块测试 -> " + new LibraryWithoutPlugin().getString() + "\n");
|
stringBuilder.append("普通模块测试 -> " + new LibraryWithoutPlugin().getString() + "\n");
|
||||||
((TextView) findViewById(R.id.text)).setText(stringBuilder);
|
((TextView) findViewById(R.id.text)).setText(stringBuilder);
|
||||||
|
findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
JavaParcelable javaParcelable = new JavaParcelable();
|
||||||
|
KotlinParcelable kotlinParcelable = new KotlinParcelable();
|
||||||
|
Intent intent = new Intent(MainActivity.this, ParcelableActivity.class);
|
||||||
|
intent.putExtra("javaParcelable",javaParcelable);
|
||||||
|
intent.putExtra("kotlinParcelable",kotlinParcelable);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initComponent() {
|
public void initComponent() {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.plugin.component;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.plugin.librarykotlin.JavaParcelable;
|
||||||
|
import com.plugin.librarykotlin.KotlinParcelable;
|
||||||
|
import com.plugin.module.R;
|
||||||
|
|
||||||
|
public class ParcelableActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_parcelable);
|
||||||
|
|
||||||
|
JavaParcelable javaParcelable = getIntent().getParcelableExtra("javaParcelable");
|
||||||
|
KotlinParcelable kotlinParcelable = getIntent().getParcelableExtra("kotlinParcelable");
|
||||||
|
TextView textView = this.findViewById(R.id.text);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("javaParcelable ->" + "\n");
|
||||||
|
stringBuilder.append("int : " + javaParcelable.i + "\n");
|
||||||
|
stringBuilder.append("string : " + javaParcelable.string + "\n");
|
||||||
|
stringBuilder.append("kotlinParcelable ->" + "\n");
|
||||||
|
stringBuilder.append("int : " + kotlinParcelable.getInt() + "\n");
|
||||||
|
stringBuilder.append("string : " + kotlinParcelable.getString() + "\n");
|
||||||
|
textView.setText(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/src/main/res/layout/activity_parcelable.xml
Normal file
12
app/src/main/res/layout/activity_parcelable.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Hello World!" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -11,13 +11,14 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.0'
|
classpath 'com.android.tools.build:gradle:3.1.0'
|
||||||
classpath "com.effective.plugins:component:$component_version"
|
// classpath "com.effective.plugins:component:$component_version"
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
//调试需要
|
//调试需要
|
||||||
// classpath "com.effective.plugins:component-plugin"
|
classpath "com.effective.plugins:component-plugin"
|
||||||
|
|
||||||
//发布需要
|
//发布需要
|
||||||
classpath 'com.novoda:bintray-release:0.9.1'
|
classpath 'com.novoda:bintray-release:0.9.1'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package com.plugin.component
|
||||||
|
|
||||||
|
import org.gradle.api.artifacts.ModuleIdentifier
|
||||||
|
import org.gradle.api.artifacts.VersionConstraint
|
||||||
|
import org.gradle.api.artifacts.component.ComponentIdentifier
|
||||||
|
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||||
|
import org.gradle.api.artifacts.component.ModuleComponentSelector
|
||||||
|
import org.gradle.api.attributes.AttributeContainer
|
||||||
|
import org.gradle.api.capabilities.Capability
|
||||||
|
import org.gradle.api.internal.artifacts.DefaultModuleIdentifier
|
||||||
|
import org.gradle.api.internal.artifacts.ImmutableVersionConstraint
|
||||||
|
import org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint
|
||||||
|
import org.gradle.api.internal.attributes.ImmutableAttributes
|
||||||
|
import org.gradle.internal.component.external.model.DefaultModuleComponentSelector
|
||||||
|
|
||||||
|
public class FlatDirModuleComponentSelector implements ModuleComponentSelector {
|
||||||
|
|
||||||
|
private final ModuleIdentifier moduleIdentifier
|
||||||
|
private final ImmutableVersionConstraint versionConstraint
|
||||||
|
private final ImmutableAttributes attributes
|
||||||
|
private final List<Capability> requestedCapabilities
|
||||||
|
private final int hashCode
|
||||||
|
|
||||||
|
private FlatDirModuleComponentSelector(ModuleIdentifier module, ImmutableVersionConstraint version, ImmutableAttributes attributes, List<Capability> requestedCapabilities) {
|
||||||
|
assert module != null: "module cannot be null"
|
||||||
|
|
||||||
|
assert version != null: "version cannot be null"
|
||||||
|
|
||||||
|
assert attributes != null: "attributes cannot be null"
|
||||||
|
|
||||||
|
assert requestedCapabilities != null: "capabilities cannot be null"
|
||||||
|
|
||||||
|
this.moduleIdentifier = module
|
||||||
|
this.versionConstraint = version
|
||||||
|
this.attributes = attributes
|
||||||
|
this.requestedCapabilities = requestedCapabilities
|
||||||
|
this.hashCode = Objects.hash(version, module, attributes, requestedCapabilities)
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
String group = this.moduleIdentifier.getGroup()
|
||||||
|
String module = this.moduleIdentifier.getName()
|
||||||
|
String version = this.getVersion()
|
||||||
|
StringBuilder builder = new StringBuilder(group.length() + module.length() + this.versionConstraint.getRequiredVersion().length() + 2)
|
||||||
|
builder.append(group)
|
||||||
|
builder.append(":")
|
||||||
|
builder.append(module)
|
||||||
|
if (version.length() > 0) {
|
||||||
|
builder.append(":")
|
||||||
|
builder.append(version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.versionConstraint.getBranch() != null) {
|
||||||
|
builder.append(" (branch: ")
|
||||||
|
builder.append(this.versionConstraint.getBranch())
|
||||||
|
builder.append(")")
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroup() {
|
||||||
|
return this.moduleIdentifier.getGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModule() {
|
||||||
|
return this.moduleIdentifier.getName()
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return this.versionConstraint.getRequiredVersion().isEmpty() ? this.versionConstraint.getPreferredVersion() : this.versionConstraint.getRequiredVersion()
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionConstraint getVersionConstraint() {
|
||||||
|
return this.versionConstraint
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleIdentifier getModuleIdentifier() {
|
||||||
|
return this.moduleIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttributeContainer getAttributes() {
|
||||||
|
return this.attributes
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Capability> getRequestedCapabilities() {
|
||||||
|
return this.requestedCapabilities
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesStrictly(ComponentIdentifier identifier) {
|
||||||
|
assert identifier != null: "identifier cannot be null"
|
||||||
|
|
||||||
|
if (identifier instanceof ModuleComponentIdentifier) {
|
||||||
|
ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier) identifier
|
||||||
|
if (this.moduleIdentifier.getGroup() == moduleComponentIdentifier.getGroup()
|
||||||
|
&& this.moduleIdentifier.getName() == moduleComponentIdentifier.getModule()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o != null && o instanceof DefaultModuleComponentSelector) {
|
||||||
|
DefaultModuleComponentSelector selector = (DefaultModuleComponentSelector) o
|
||||||
|
if (this.moduleIdentifier.getName() == selector.moduleIdentifier.getName() &&
|
||||||
|
this.moduleIdentifier.getGroup() == selector.moduleIdentifier.getGroup()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return this.hashCode
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.getDisplayName()
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModuleComponentSelector newSelector(String name) {
|
||||||
|
return new FlatDirModuleComponentSelector(DefaultModuleIdentifier.newId("", name), DefaultImmutableVersionConstraint.of(), ImmutableAttributes.EMPTY, new ArrayList<Capability>())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ component {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.code.gson:gson:2.8.1'
|
implementation 'com.google.code.gson:gson:2.8.1'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +65,7 @@ component {
|
|||||||
targetModuleName 'debugModule'
|
targetModuleName 'debugModule'
|
||||||
|
|
||||||
//申明调试模块运行时链接组件的资源,表明运行 debugModule 时使用目录资源
|
//申明调试模块运行时链接组件的资源,表明运行 debugModule 时使用目录资源
|
||||||
// targetDebugName 'libraryWithoutPlugin'
|
targetDebugName 'library'
|
||||||
|
|
||||||
configuration {
|
configuration {
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ android {
|
|||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
androidExtensions {
|
||||||
|
experimental = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.plugin.librarykotlin;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public class JavaParcelable implements Parcelable {
|
||||||
|
|
||||||
|
public int i = 0;
|
||||||
|
public String string = "JavaParcelable";
|
||||||
|
|
||||||
|
public JavaParcelable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaParcelable(Parcel source) {
|
||||||
|
this.i = source.readInt();
|
||||||
|
this.string = source.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<JavaParcelable> CREATOR = new Creator<JavaParcelable>() {
|
||||||
|
@Override
|
||||||
|
public JavaParcelable createFromParcel(Parcel source) {
|
||||||
|
return new JavaParcelable(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JavaParcelable[] newArray(int size) {
|
||||||
|
return new JavaParcelable[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(i);
|
||||||
|
dest.writeString(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.plugin.librarykotlin
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
class KotlinParcelable : Parcelable {
|
||||||
|
|
||||||
|
var int: Int = 0
|
||||||
|
|
||||||
|
var string: String = "KotlinParcelable"
|
||||||
|
|
||||||
|
constructor()
|
||||||
|
|
||||||
|
constructor(source: Parcel) {
|
||||||
|
source.writeInt(int)
|
||||||
|
source.writeString(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object{
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val CREATOR: Parcelable.Creator<KotlinParcelable> = object : Parcelable.Creator<KotlinParcelable> {
|
||||||
|
override fun createFromParcel(source: Parcel): KotlinParcelable {
|
||||||
|
return KotlinParcelable(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<KotlinParcelable> {
|
||||||
|
return Array(size) {KotlinParcelable()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun writeToParcel(dest: Parcel?, flags: Int) {
|
||||||
|
dest?.writeInt(int)
|
||||||
|
dest?.writeString(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
//include ':component-plugin'
|
//include ':component-plugin'
|
||||||
|
|
||||||
//调试插件
|
//调试插件
|
||||||
//includeBuild './component-plugin'
|
includeBuild './component-plugin'
|
||||||
//
|
|
||||||
include ':app', ':pins'
|
include ':app', ':pins'
|
||||||
include ':debugModule'
|
include ':debugModule'
|
||||||
include ':library', ':libraryKotlin', ':libraryWithoutPlugin'
|
include ':library', ':libraryKotlin', ':libraryWithoutPlugin'
|
||||||
|
|||||||
Reference in New Issue
Block a user