Merge changes from topic "convert_result" into androidx-main
* changes:
Convert ActivityResult to Kotlin
Rename ActivityResult.java to .kt
diff --git a/activity/activity-ktx/api/current.ignore b/activity/activity-ktx/api/current.ignore
index 70cfa3e..4f14c5c 100644
--- a/activity/activity-ktx/api/current.ignore
+++ b/activity/activity-ktx/api/current.ignore
@@ -1,5 +1,3 @@
// Baseline format: 1.0
-RemovedClass: androidx.activity.result.ActivityResultCallerKt:
- Removed class androidx.activity.result.ActivityResultCallerKt
-RemovedClass: androidx.activity.result.ActivityResultLauncherKt:
- Removed class androidx.activity.result.ActivityResultLauncherKt
+RemovedPackage: androidx.activity.result:
+ Removed package androidx.activity.result
diff --git a/activity/activity-ktx/api/current.txt b/activity/activity-ktx/api/current.txt
index bd594bc..a62da75 100644
--- a/activity/activity-ktx/api/current.txt
+++ b/activity/activity-ktx/api/current.txt
@@ -12,12 +12,3 @@
}
-package androidx.activity.result {
-
- public final class ActivityResultKt {
- method public static operator int component1(androidx.activity.result.ActivityResult);
- method public static operator android.content.Intent? component2(androidx.activity.result.ActivityResult);
- }
-
-}
-
diff --git a/activity/activity-ktx/api/restricted_current.ignore b/activity/activity-ktx/api/restricted_current.ignore
index 70cfa3e..4f14c5c 100644
--- a/activity/activity-ktx/api/restricted_current.ignore
+++ b/activity/activity-ktx/api/restricted_current.ignore
@@ -1,5 +1,3 @@
// Baseline format: 1.0
-RemovedClass: androidx.activity.result.ActivityResultCallerKt:
- Removed class androidx.activity.result.ActivityResultCallerKt
-RemovedClass: androidx.activity.result.ActivityResultLauncherKt:
- Removed class androidx.activity.result.ActivityResultLauncherKt
+RemovedPackage: androidx.activity.result:
+ Removed package androidx.activity.result
diff --git a/activity/activity-ktx/api/restricted_current.txt b/activity/activity-ktx/api/restricted_current.txt
index bd594bc..a62da75 100644
--- a/activity/activity-ktx/api/restricted_current.txt
+++ b/activity/activity-ktx/api/restricted_current.txt
@@ -12,12 +12,3 @@
}
-package androidx.activity.result {
-
- public final class ActivityResultKt {
- method public static operator int component1(androidx.activity.result.ActivityResult);
- method public static operator android.content.Intent? component2(androidx.activity.result.ActivityResult);
- }
-
-}
-
diff --git a/activity/activity-ktx/src/main/java/androidx/activity/result/ActivityResult.kt b/activity/activity-ktx/src/main/java/androidx/activity/result/ActivityResult.kt
deleted file mode 100644
index b1cb01f..0000000
--- a/activity/activity-ktx/src/main/java/androidx/activity/result/ActivityResult.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.activity.result
-
-import android.content.Intent
-
-/**
- * Destructuring declaration for [ActivityResult] to provide the requestCode
- *
- * @return the resultCode of the [ActivityResult]
- */
-public operator fun ActivityResult.component1(): Int = resultCode
-
-/**
- * Destructuring declaration for [ActivityResult] to provide the intent
- *
- * @return the intent of the [ActivityResult]
- */
-public operator fun ActivityResult.component2(): Intent? = data
diff --git a/activity/activity/api/current.ignore b/activity/activity/api/current.ignore
index 9ab3df4..86b150a 100644
--- a/activity/activity/api/current.ignore
+++ b/activity/activity/api/current.ignore
@@ -3,6 +3,8 @@
Method androidx.activity.ComponentActivity.registerForActivityResult has changed return type from androidx.activity.result.ActivityResultLauncher<I> to androidx.activity.result.ActivityResultLauncher<I>
ChangedType: androidx.activity.ComponentActivity#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract<I,O>, androidx.activity.result.ActivityResultRegistry, androidx.activity.result.ActivityResultCallback<O>):
Method androidx.activity.ComponentActivity.registerForActivityResult has changed return type from androidx.activity.result.ActivityResultLauncher<I> to androidx.activity.result.ActivityResultLauncher<I>
+ChangedType: androidx.activity.result.ActivityResult#CREATOR:
+ Field androidx.activity.result.ActivityResult.CREATOR has changed type from android.os.Parcelable.Creator<androidx.activity.result.ActivityResult!> to android.os.Parcelable.Creator<androidx.activity.result.ActivityResult>
ChangedType: androidx.activity.result.ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract<I,O>, androidx.activity.result.ActivityResultCallback<O>):
Method androidx.activity.result.ActivityResultCaller.registerForActivityResult has changed return type from androidx.activity.result.ActivityResultLauncher<I> to androidx.activity.result.ActivityResultLauncher<I>
ChangedType: androidx.activity.result.ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract<I,O>, androidx.activity.result.ActivityResultRegistry, androidx.activity.result.ActivityResultCallback<O>):
diff --git a/activity/activity/api/current.txt b/activity/activity/api/current.txt
index bcdf6c6..999befd 100644
--- a/activity/activity/api/current.txt
+++ b/activity/activity/api/current.txt
@@ -204,13 +204,20 @@
package androidx.activity.result {
public final class ActivityResult implements android.os.Parcelable {
- ctor public ActivityResult(int, android.content.Intent?);
+ ctor public ActivityResult(int resultCode, android.content.Intent? data);
method public int describeContents();
method public android.content.Intent? getData();
method public int getResultCode();
- method public static String resultCodeToString(int);
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<androidx.activity.result.ActivityResult!> CREATOR;
+ method public static String resultCodeToString(int resultCode);
+ method public void writeToParcel(android.os.Parcel dest, int flags);
+ property public final android.content.Intent? data;
+ property public final int resultCode;
+ field public static final android.os.Parcelable.Creator<androidx.activity.result.ActivityResult> CREATOR;
+ field public static final androidx.activity.result.ActivityResult.Companion Companion;
+ }
+
+ public static final class ActivityResult.Companion {
+ method public String resultCodeToString(int resultCode);
}
public fun interface ActivityResultCallback<O> {
@@ -227,6 +234,11 @@
method public static <I, O> androidx.activity.result.ActivityResultLauncher<kotlin.Unit> registerForActivityResult(androidx.activity.result.ActivityResultCaller, androidx.activity.result.contract.ActivityResultContract<I,O> contract, I input, kotlin.jvm.functions.Function1<O,kotlin.Unit> callback);
}
+ public final class ActivityResultKt {
+ method public static operator int component1(androidx.activity.result.ActivityResult);
+ method public static operator android.content.Intent? component2(androidx.activity.result.ActivityResult);
+ }
+
public abstract class ActivityResultLauncher<I> {
ctor public ActivityResultLauncher();
method public abstract androidx.activity.result.contract.ActivityResultContract<I,?> getContract();
diff --git a/activity/activity/api/restricted_current.ignore b/activity/activity/api/restricted_current.ignore
index 9ab3df4..86b150a 100644
--- a/activity/activity/api/restricted_current.ignore
+++ b/activity/activity/api/restricted_current.ignore
@@ -3,6 +3,8 @@
Method androidx.activity.ComponentActivity.registerForActivityResult has changed return type from androidx.activity.result.ActivityResultLauncher<I> to androidx.activity.result.ActivityResultLauncher<I>
ChangedType: androidx.activity.ComponentActivity#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract<I,O>, androidx.activity.result.ActivityResultRegistry, androidx.activity.result.ActivityResultCallback<O>):
Method androidx.activity.ComponentActivity.registerForActivityResult has changed return type from androidx.activity.result.ActivityResultLauncher<I> to androidx.activity.result.ActivityResultLauncher<I>
+ChangedType: androidx.activity.result.ActivityResult#CREATOR:
+ Field androidx.activity.result.ActivityResult.CREATOR has changed type from android.os.Parcelable.Creator<androidx.activity.result.ActivityResult!> to android.os.Parcelable.Creator<androidx.activity.result.ActivityResult>
ChangedType: androidx.activity.result.ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract<I,O>, androidx.activity.result.ActivityResultCallback<O>):
Method androidx.activity.result.ActivityResultCaller.registerForActivityResult has changed return type from androidx.activity.result.ActivityResultLauncher<I> to androidx.activity.result.ActivityResultLauncher<I>
ChangedType: androidx.activity.result.ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract<I,O>, androidx.activity.result.ActivityResultRegistry, androidx.activity.result.ActivityResultCallback<O>):
diff --git a/activity/activity/api/restricted_current.txt b/activity/activity/api/restricted_current.txt
index 02169d2..8346a8b 100644
--- a/activity/activity/api/restricted_current.txt
+++ b/activity/activity/api/restricted_current.txt
@@ -203,13 +203,20 @@
package androidx.activity.result {
public final class ActivityResult implements android.os.Parcelable {
- ctor public ActivityResult(int, android.content.Intent?);
+ ctor public ActivityResult(int resultCode, android.content.Intent? data);
method public int describeContents();
method public android.content.Intent? getData();
method public int getResultCode();
- method public static String resultCodeToString(int);
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<androidx.activity.result.ActivityResult!> CREATOR;
+ method public static String resultCodeToString(int resultCode);
+ method public void writeToParcel(android.os.Parcel dest, int flags);
+ property public final android.content.Intent? data;
+ property public final int resultCode;
+ field public static final android.os.Parcelable.Creator<androidx.activity.result.ActivityResult> CREATOR;
+ field public static final androidx.activity.result.ActivityResult.Companion Companion;
+ }
+
+ public static final class ActivityResult.Companion {
+ method public String resultCodeToString(int resultCode);
}
public fun interface ActivityResultCallback<O> {
@@ -226,6 +233,11 @@
method public static <I, O> androidx.activity.result.ActivityResultLauncher<kotlin.Unit> registerForActivityResult(androidx.activity.result.ActivityResultCaller, androidx.activity.result.contract.ActivityResultContract<I,O> contract, I input, kotlin.jvm.functions.Function1<O,kotlin.Unit> callback);
}
+ public final class ActivityResultKt {
+ method public static operator int component1(androidx.activity.result.ActivityResult);
+ method public static operator android.content.Intent? component2(androidx.activity.result.ActivityResult);
+ }
+
public abstract class ActivityResultLauncher<I> {
ctor public ActivityResultLauncher();
method public abstract androidx.activity.result.contract.ActivityResultContract<I,?> getContract();
diff --git a/activity/activity-ktx/src/androidTest/java/androidx/activity/result/ActivityResultTest.kt b/activity/activity/src/androidTest/java/androidx/activity/result/ActivityResultTest.kt
similarity index 100%
rename from activity/activity-ktx/src/androidTest/java/androidx/activity/result/ActivityResultTest.kt
rename to activity/activity/src/androidTest/java/androidx/activity/result/ActivityResultTest.kt
diff --git a/activity/activity/src/main/java/androidx/activity/result/ActivityResult.java b/activity/activity/src/main/java/androidx/activity/result/ActivityResult.java
deleted file mode 100644
index 785569f..0000000
--- a/activity/activity/src/main/java/androidx/activity/result/ActivityResult.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.activity.result;
-
-import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-/**
- * A container for an activity result as obtained from {@link Activity#onActivityResult}
- *
- * @see Activity#onActivityResult
- */
-@SuppressLint("BanParcelableUsage")
-public final class ActivityResult implements Parcelable {
- private final int mResultCode;
- @Nullable
- private final Intent mData;
-
- /**
- * Create a new instance
- *
- * @param resultCode status to indicate the success of the operation
- * @param data an intent that carries the result data
- */
- public ActivityResult(int resultCode, @Nullable Intent data) {
- mResultCode = resultCode;
- mData = data;
- }
-
- ActivityResult(Parcel in) {
- mResultCode = in.readInt();
- mData = in.readInt() == 0 ? null : Intent.CREATOR.createFromParcel(in);
- }
-
- /**
- * @return the resultCode
- */
- public int getResultCode() {
- return mResultCode;
- }
-
- /**
- * @return the intent
- */
- @Nullable
- public Intent getData() {
- return mData;
- }
-
- @Override
- public String toString() {
- return "ActivityResult{"
- + "resultCode=" + resultCodeToString(mResultCode)
- + ", data=" + mData
- + '}';
- }
-
- /**
- * A readable representation of standard activity result codes
- *
- * @param resultCode the result code
- *
- * @return RESULT_OK, RESULT_CANCELED, or the number otherwise
- */
- @NonNull
- public static String resultCodeToString(int resultCode) {
- switch (resultCode) {
- case Activity.RESULT_OK: return "RESULT_OK";
- case Activity.RESULT_CANCELED: return "RESULT_CANCELED";
- default: return String.valueOf(resultCode);
- }
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mResultCode);
- dest.writeInt(mData == null ? 0 : 1);
- if (mData != null) {
- mData.writeToParcel(dest, flags);
- }
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- public static final Creator<ActivityResult> CREATOR = new Creator<ActivityResult>() {
- @Override
- public ActivityResult createFromParcel(@NonNull Parcel in) {
- return new ActivityResult(in);
- }
-
- @Override
- public ActivityResult[] newArray(int size) {
- return new ActivityResult[size];
- }
- };
-}
diff --git a/activity/activity/src/main/java/androidx/activity/result/ActivityResult.kt b/activity/activity/src/main/java/androidx/activity/result/ActivityResult.kt
new file mode 100644
index 0000000..bbd1a03
--- /dev/null
+++ b/activity/activity/src/main/java/androidx/activity/result/ActivityResult.kt
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package androidx.activity.result
+
+import android.annotation.SuppressLint
+import android.app.Activity
+import android.content.Intent
+import android.os.Parcel
+import android.os.Parcelable
+
+/**
+ * A container for an activity result as obtained from [Activity.onActivityResult]
+ *
+ * @see Activity.onActivityResult
+ */
+@SuppressLint("BanParcelableUsage")
+class ActivityResult(
+ /**
+ * Status to indicate the success of the operation
+ */
+ val resultCode: Int,
+
+ /**
+ * The intent that carries the result data
+ */
+ val data: Intent?
+) : Parcelable {
+
+ internal constructor(parcel: Parcel) : this(
+ parcel.readInt(),
+ if (parcel.readInt() == 0) null else Intent.CREATOR.createFromParcel(parcel)
+ )
+
+ override fun toString(): String {
+ return "ActivityResult{resultCode=${resultCodeToString(resultCode)}, data=$data}"
+ }
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ dest.writeInt(resultCode)
+ dest.writeInt(if (data == null) 0 else 1)
+ data?.writeToParcel(dest, flags)
+ }
+
+ override fun describeContents() = 0
+
+ companion object {
+ /**
+ * A readable representation of standard activity result codes for the given [resultCode]
+ *
+ * @return RESULT_OK, RESULT_CANCELED, or the number otherwise
+ */
+ @JvmStatic
+ fun resultCodeToString(resultCode: Int): String {
+ return when (resultCode) {
+ Activity.RESULT_OK -> "RESULT_OK"
+ Activity.RESULT_CANCELED -> "RESULT_CANCELED"
+ else -> resultCode.toString()
+ }
+ }
+
+ @Suppress("unused")
+ @JvmField
+ val CREATOR = object : Parcelable.Creator<ActivityResult> {
+ override fun createFromParcel(parcel: Parcel) = ActivityResult(parcel)
+
+ override fun newArray(size: Int) = arrayOfNulls<ActivityResult>(size)
+ }
+ }
+}
+
+/**
+ * Destructuring declaration for [ActivityResult] to provide the requestCode
+ *
+ * @return the resultCode of the [ActivityResult]
+ */
+operator fun ActivityResult.component1(): Int = resultCode
+
+/**
+ * Destructuring declaration for [ActivityResult] to provide the intent
+ *
+ * @return the intent of the [ActivityResult]
+ */
+operator fun ActivityResult.component2(): Intent? = data