Migrate Android test app models to kotlin (#613)
This commit is contained in:
@@ -181,7 +181,7 @@ class OfflineActivity : AppCompatActivity(), DownloadRegionDialogListener {
|
||||
/*
|
||||
* Dialogs
|
||||
*/
|
||||
override fun onDownloadRegionDialogPositiveClick(regionName: String) {
|
||||
override fun onDownloadRegionDialogPositiveClick(regionName: String?) {
|
||||
if (TextUtils.isEmpty(regionName)) {
|
||||
Toast.makeText(this@OfflineActivity, "Region name cannot be empty.", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.activity;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Feature implements Parcelable {
|
||||
|
||||
private String name;
|
||||
private String label;
|
||||
private String description;
|
||||
private String category;
|
||||
|
||||
public Feature(String name, String label, String description, String category) {
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
private Feature(Parcel in) {
|
||||
name = in.readString();
|
||||
label = in.readString();
|
||||
description = in.readString();
|
||||
category = in.readString();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSimpleName() {
|
||||
String[] split = name.split("\\.");
|
||||
return split[split.length - 1];
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label != null ? label : getSimpleName();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description != null ? description : "-";
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(name);
|
||||
out.writeString(label);
|
||||
out.writeString(description);
|
||||
out.writeString(category);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Feature> CREATOR
|
||||
= new Parcelable.Creator<Feature>() {
|
||||
public Feature createFromParcel(Parcel in) {
|
||||
return new Feature(in);
|
||||
}
|
||||
|
||||
public Feature[] newArray(int size) {
|
||||
return new Feature[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.activity
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
class Feature : Parcelable {
|
||||
var name: String
|
||||
private set
|
||||
private var label: String?
|
||||
private var description: String?
|
||||
var category: String
|
||||
private set
|
||||
|
||||
constructor(name: String, label: String?, description: String?, category: String) {
|
||||
this.name = name
|
||||
this.label = label
|
||||
this.description = description
|
||||
this.category = category
|
||||
}
|
||||
|
||||
private constructor(`in`: Parcel) {
|
||||
name = `in`.readString().toString()
|
||||
label = `in`.readString()
|
||||
description = `in`.readString()
|
||||
category = `in`.readString().toString()
|
||||
}
|
||||
|
||||
val simpleName: String
|
||||
get() {
|
||||
val split = name.split("\\.").toTypedArray()
|
||||
return split[split.size - 1]
|
||||
}
|
||||
|
||||
fun getLabel(): String {
|
||||
return if (label != null) label!! else simpleName
|
||||
}
|
||||
|
||||
fun getDescription(): String {
|
||||
return if (description != null) description!! else "-"
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||
out.writeString(name)
|
||||
out.writeString(label)
|
||||
out.writeString(description)
|
||||
out.writeString(category)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<Feature?> = object : Parcelable.Creator<Feature?> {
|
||||
override fun createFromParcel(`in`: Parcel): Feature {
|
||||
return Feature(`in`)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Feature?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
|
||||
public class CityStateMarker extends Marker {
|
||||
|
||||
private String infoWindowBackgroundColor;
|
||||
|
||||
public CityStateMarker(CityStateMarkerOptions cityStateOptions, String color) {
|
||||
super(cityStateOptions);
|
||||
infoWindowBackgroundColor = color;
|
||||
}
|
||||
|
||||
public String getInfoWindowBackgroundColor() {
|
||||
return infoWindowBackgroundColor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Marker
|
||||
|
||||
class CityStateMarker(
|
||||
cityStateOptions: CityStateMarkerOptions?,
|
||||
val infoWindowBackgroundColor: String
|
||||
) : Marker(cityStateOptions)
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
public class CityStateMarkerOptions extends BaseMarkerOptions<CityStateMarker, CityStateMarkerOptions> {
|
||||
|
||||
private String infoWindowBackgroundColor;
|
||||
|
||||
public CityStateMarkerOptions infoWindowBackground(String color) {
|
||||
infoWindowBackgroundColor = color;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public CityStateMarkerOptions() {
|
||||
}
|
||||
|
||||
private CityStateMarkerOptions(Parcel in) {
|
||||
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
|
||||
snippet(in.readString());
|
||||
String iconId = in.readString();
|
||||
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
|
||||
Icon icon = IconFactory.recreate(iconId, iconBitmap);
|
||||
icon(icon);
|
||||
title(in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CityStateMarkerOptions getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CityStateMarker getMarker() {
|
||||
return new CityStateMarker(this, infoWindowBackgroundColor);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<CityStateMarkerOptions> CREATOR
|
||||
= new Parcelable.Creator<CityStateMarkerOptions>() {
|
||||
public CityStateMarkerOptions createFromParcel(Parcel in) {
|
||||
return new CityStateMarkerOptions(in);
|
||||
}
|
||||
|
||||
public CityStateMarkerOptions[] newArray(int size) {
|
||||
return new CityStateMarkerOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeParcelable(position, flags);
|
||||
out.writeString(snippet);
|
||||
out.writeString(icon.getId());
|
||||
out.writeParcelable(icon.getBitmap(), flags);
|
||||
out.writeString(title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
|
||||
class CityStateMarkerOptions : BaseMarkerOptions<CityStateMarker?, CityStateMarkerOptions?> {
|
||||
private var infoWindowBackgroundColor: String? = null
|
||||
fun infoWindowBackground(color: String?): CityStateMarkerOptions {
|
||||
infoWindowBackgroundColor = color
|
||||
return getThis()
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
private constructor(`in`: Parcel) {
|
||||
position(`in`.readParcelable<Parcelable>(LatLng::class.java.classLoader) as LatLng)
|
||||
snippet(`in`.readString())
|
||||
val iconId = `in`.readString()
|
||||
val iconBitmap = `in`.readParcelable<Bitmap>(Bitmap::class.java.classLoader)
|
||||
val icon = iconBitmap?.let { IconFactory.recreate(iconId.toString(), it) }
|
||||
icon(icon)
|
||||
title(`in`.readString())
|
||||
}
|
||||
|
||||
override fun getThis(): CityStateMarkerOptions {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun getMarker(): CityStateMarker? {
|
||||
return infoWindowBackgroundColor?.let { CityStateMarker(this, it) }
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||
out.writeParcelable(position, flags)
|
||||
out.writeString(snippet)
|
||||
out.writeString(icon.id)
|
||||
out.writeParcelable(icon.bitmap, flags)
|
||||
out.writeString(title)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<CityStateMarkerOptions?> =
|
||||
object : Parcelable.Creator<CityStateMarkerOptions?> {
|
||||
override fun createFromParcel(`in`: Parcel): CityStateMarkerOptions {
|
||||
return CityStateMarkerOptions(`in`)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<CityStateMarkerOptions?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
|
||||
public class CountryMarker extends Marker {
|
||||
|
||||
private String abbrevName;
|
||||
private int flagRes;
|
||||
|
||||
public CountryMarker(BaseMarkerOptions baseMarkerOptions, String abbrevName, int iconRes) {
|
||||
super(baseMarkerOptions);
|
||||
this.abbrevName = abbrevName;
|
||||
this.flagRes = iconRes;
|
||||
}
|
||||
|
||||
public String getAbbrevName() {
|
||||
return abbrevName;
|
||||
}
|
||||
|
||||
public int getFlagRes() {
|
||||
return flagRes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions
|
||||
import com.mapbox.mapboxsdk.annotations.Marker
|
||||
|
||||
class CountryMarker(
|
||||
baseMarkerOptions: BaseMarkerOptions<*, *>?,
|
||||
val abbrevName: String,
|
||||
val flagRes: Int
|
||||
) : Marker(baseMarkerOptions)
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
public class CountryMarkerOptions extends BaseMarkerOptions<CountryMarker, CountryMarkerOptions> {
|
||||
|
||||
private String abbrevName;
|
||||
private int flagRes;
|
||||
|
||||
public CountryMarkerOptions abbrevName(String name) {
|
||||
abbrevName = name;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public CountryMarkerOptions flagRes(int imageRes) {
|
||||
flagRes = imageRes;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public CountryMarkerOptions() {
|
||||
}
|
||||
|
||||
private CountryMarkerOptions(Parcel in) {
|
||||
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
|
||||
snippet(in.readString());
|
||||
String iconId = in.readString();
|
||||
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
|
||||
Icon icon = IconFactory.recreate(iconId, iconBitmap);
|
||||
icon(icon);
|
||||
title(in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountryMarkerOptions getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountryMarker getMarker() {
|
||||
return new CountryMarker(this, abbrevName, flagRes);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<CountryMarkerOptions> CREATOR
|
||||
= new Parcelable.Creator<CountryMarkerOptions>() {
|
||||
public CountryMarkerOptions createFromParcel(Parcel in) {
|
||||
return new CountryMarkerOptions(in);
|
||||
}
|
||||
|
||||
public CountryMarkerOptions[] newArray(int size) {
|
||||
return new CountryMarkerOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeParcelable(position, flags);
|
||||
out.writeString(snippet);
|
||||
out.writeString(icon.getId());
|
||||
out.writeParcelable(icon.getBitmap(), flags);
|
||||
out.writeString(title);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.annotations
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
|
||||
class CountryMarkerOptions : BaseMarkerOptions<CountryMarker?, CountryMarkerOptions?> {
|
||||
private var abbrevName: String? = null
|
||||
private var flagRes = 0
|
||||
fun abbrevName(name: String?): CountryMarkerOptions {
|
||||
abbrevName = name
|
||||
return getThis()
|
||||
}
|
||||
|
||||
fun flagRes(imageRes: Int): CountryMarkerOptions {
|
||||
flagRes = imageRes
|
||||
return getThis()
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
private constructor(`in`: Parcel) {
|
||||
position(`in`.readParcelable<Parcelable>(LatLng::class.java.classLoader) as LatLng)
|
||||
snippet(`in`.readString())
|
||||
val iconId = `in`.readString()
|
||||
val iconBitmap = `in`.readParcelable<Bitmap>(Bitmap::class.java.classLoader)
|
||||
val icon = iconBitmap?.let { IconFactory.recreate(iconId.toString(), it) }
|
||||
icon(icon)
|
||||
title(`in`.readString())
|
||||
}
|
||||
|
||||
override fun getThis(): CountryMarkerOptions {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun getMarker(): CountryMarker {
|
||||
return CountryMarker(this, abbrevName!!, flagRes)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||
out.writeParcelable(position, flags)
|
||||
out.writeString(snippet)
|
||||
out.writeString(icon.id)
|
||||
out.writeParcelable(icon.bitmap, flags)
|
||||
out.writeString(title)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<CountryMarkerOptions?> =
|
||||
object : Parcelable.Creator<CountryMarkerOptions?> {
|
||||
override fun createFromParcel(`in`: Parcel): CountryMarkerOptions {
|
||||
return CountryMarkerOptions(`in`)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<CountryMarkerOptions?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.customlayer;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
@Keep
|
||||
public class ExampleCustomLayer {
|
||||
static {
|
||||
System.loadLibrary("example-custom-layer");
|
||||
}
|
||||
|
||||
public static native long createContext();
|
||||
|
||||
public static native void setColor(float red, float green, float blue, float alpha);
|
||||
|
||||
public static long InitializeFunction;
|
||||
public static long RenderFunction;
|
||||
public static long ContextLostFunction;
|
||||
public static long DeinitializeFunction;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.customlayer
|
||||
|
||||
import androidx.annotation.Keep
|
||||
|
||||
@Keep
|
||||
object ExampleCustomLayer {
|
||||
init {
|
||||
System.loadLibrary("example-custom-layer")
|
||||
}
|
||||
|
||||
external fun createContext(): Long
|
||||
external fun setColor(red: Float, green: Float, blue: Float, alpha: Float)
|
||||
var InitializeFunction: Long = 0
|
||||
var RenderFunction: Long = 0
|
||||
var ContextLostFunction: Long = 0
|
||||
var DeinitializeFunction: Long = 0
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.other;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class OfflineDownloadRegionDialog extends DialogFragment {
|
||||
|
||||
public interface DownloadRegionDialogListener {
|
||||
void onDownloadRegionDialogPositiveClick(String regionName);
|
||||
}
|
||||
|
||||
DownloadRegionDialogListener listener;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
listener = (DownloadRegionDialogListener) activity;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
// Let the user choose a name for the region
|
||||
final EditText regionNameEdit = new EditText(getActivity());
|
||||
|
||||
builder.setTitle("Choose a name for the region")
|
||||
.setIcon(R.drawable.ic_airplanemode_active_black)
|
||||
.setView(regionNameEdit)
|
||||
.setPositiveButton("Start", (dialog, which) -> {
|
||||
String regionName = regionNameEdit.getText().toString();
|
||||
listener.onDownloadRegionDialogPositiveClick(regionName);
|
||||
}).setNegativeButton("Cancel", (dialog, which) -> Timber.d("Download cancelled."));
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.other
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import com.mapbox.mapboxsdk.testapp.model.other.OfflineDownloadRegionDialog.DownloadRegionDialogListener
|
||||
import timber.log.Timber
|
||||
|
||||
class OfflineDownloadRegionDialog : DialogFragment() {
|
||||
interface DownloadRegionDialogListener {
|
||||
fun onDownloadRegionDialogPositiveClick(regionName: String?)
|
||||
}
|
||||
|
||||
var listener: DownloadRegionDialogListener? = null
|
||||
override fun onAttach(activity: Activity) {
|
||||
super.onAttach(activity)
|
||||
listener = activity as DownloadRegionDialogListener
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(
|
||||
requireActivity()
|
||||
)
|
||||
|
||||
// Let the user choose a name for the region
|
||||
val regionNameEdit = EditText(activity)
|
||||
builder.setTitle("Choose a name for the region")
|
||||
.setIcon(R.drawable.ic_airplanemode_active_black)
|
||||
.setView(regionNameEdit)
|
||||
.setPositiveButton("Start") { dialog: DialogInterface?, which: Int ->
|
||||
val regionName = regionNameEdit.text.toString()
|
||||
listener!!.onDownloadRegionDialogPositiveClick(regionName)
|
||||
}
|
||||
.setNegativeButton("Cancel") { dialog: DialogInterface?, which: Int -> Timber.d("Download cancelled.") }
|
||||
return builder.create()
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.other;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class OfflineListRegionsDialog extends DialogFragment {
|
||||
|
||||
public static final String ITEMS = "ITEMS";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
// Read args
|
||||
Bundle args = getArguments();
|
||||
ArrayList<String> offlineRegionsNames = (args == null ? null : args.getStringArrayList(ITEMS));
|
||||
CharSequence[] items = offlineRegionsNames.toArray(new CharSequence[offlineRegionsNames.size()]);
|
||||
|
||||
builder.setTitle("List of offline regions")
|
||||
.setIcon(R.drawable.ic_airplanemode_active_black)
|
||||
.setItems(items, (dialog, which) -> Timber.d("Selected item: %s", which))
|
||||
.setPositiveButton("Accept", (dialog, which) -> Timber.d("Dialog dismissed"));
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mapbox.mapboxsdk.testapp.model.other
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import timber.log.Timber
|
||||
|
||||
class OfflineListRegionsDialog : DialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(
|
||||
requireActivity()
|
||||
)
|
||||
|
||||
// Read args
|
||||
val args = arguments
|
||||
val offlineRegionsNames = args?.getStringArrayList(ITEMS)
|
||||
val items = offlineRegionsNames!!.toTypedArray<CharSequence>()
|
||||
builder.setTitle("List of offline regions")
|
||||
.setIcon(R.drawable.ic_airplanemode_active_black)
|
||||
.setItems(items) { dialog: DialogInterface?, which: Int ->
|
||||
Timber.d(
|
||||
"Selected item: %s",
|
||||
which
|
||||
)
|
||||
}
|
||||
.setPositiveButton("Accept") { dialog: DialogInterface?, which: Int -> Timber.d("Dialog dismissed") }
|
||||
return builder.create()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ITEMS = "ITEMS"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user