如何从类中检索可读常量

时间:2018-09-24 18:03:47

标签: android

尝试在我的应用中使用此Github: https://github.com/anjlab/android-inapp-billing-v3/blob/master/README.md

我想从我的活动发送此代码:

 bp.getPurchaseListingDetails("YOUR PRODUCT ID FROM GOOGLE PLAY CONSOLE HERE");

Github表示:“结果,您将获得一个SkuDetails对象,其中包含以下信息:

public final String productId;

public final String title;

public final String description;

public final boolean isSubscription;

public final String currency;

public final Double priceValue;

public final String priceText;"

我正在尝试将textView的文本设置为上述“ priceValue”,但是无法访问该值。在此代码之后我要添加什么?

textViewPremiumTitle.setText();

下面是SkuDetails类中的代码:

public class SkuDetails implements Parcelable
{

public final String productId;

public final String title;

public final String description;

public final boolean isSubscription;

public final String currency;

public final Double priceValue;

public final String subscriptionPeriod;

public final String subscriptionFreeTrialPeriod;

public final boolean haveTrialPeriod;

public final double introductoryPriceValue;

public final String introductoryPricePeriod;

public final boolean haveIntroductoryPeriod;

public final int introductoryPriceCycles;

/**
 * Use this value to return the raw price from the product.
 * This allows math to be performed without needing to worry about errors
 * caused by floating point representations of the product's price.
 * <p>
 * This is in micros from the Play Store.
 */
public final long priceLong;

public final String priceText;

public final long introductoryPriceLong;

public final String introductoryPriceText;

public SkuDetails(JSONObject source) throws JSONException
{
    String responseType = source.optString(Constants.RESPONSE_TYPE);
    if (responseType == null)
    {
        responseType = Constants.PRODUCT_TYPE_MANAGED;
    }
    productId = source.optString(Constants.RESPONSE_PRODUCT_ID);
    title = source.optString(Constants.RESPONSE_TITLE);
    description = source.optString(Constants.RESPONSE_DESCRIPTION);
    isSubscription = responseType.equalsIgnoreCase(Constants.PRODUCT_TYPE_SUBSCRIPTION);
    currency = source.optString(Constants.RESPONSE_PRICE_CURRENCY);
    priceLong = source.optLong(Constants.RESPONSE_PRICE_MICROS);
    priceValue = priceLong / 1000000d;
    priceText = source.optString(Constants.RESPONSE_PRICE);
    subscriptionPeriod = source.optString(Constants.RESPONSE_SUBSCRIPTION_PERIOD);
    subscriptionFreeTrialPeriod = source.optString(Constants.RESPONSE_FREE_TRIAL_PERIOD);
    haveTrialPeriod = !TextUtils.isEmpty(subscriptionFreeTrialPeriod);
    introductoryPriceLong = source.optLong(Constants.RESPONSE_INTRODUCTORY_PRICE_MICROS);
    introductoryPriceValue = introductoryPriceLong / 1000000d;
    introductoryPriceText = source.optString(Constants.RESPONSE_INTRODUCTORY_PRICE);
    introductoryPricePeriod = source.optString(Constants.RESPONSE_INTRODUCTORY_PRICE_PERIOD);
    haveIntroductoryPeriod = !TextUtils.isEmpty(introductoryPricePeriod);
    introductoryPriceCycles = source.optInt(Constants.RESPONSE_INTRODUCTORY_PRICE_CYCLES);
}

@Override
public String toString()
{
    return String.format(Locale.US, "%s: %s(%s) %f in %s (%s)",
            productId,
            title,
            description,
            priceValue,
            currency,
            priceText);
}

@Override
public boolean equals(Object o)
{
    if (this == o)
    {
        return true;
    }
    if (o == null || getClass() != o.getClass())
    {
        return false;
    }

    SkuDetails that = (SkuDetails) o;

    if (isSubscription != that.isSubscription)
    {
        return false;
    }
    return !(productId != null ? !productId.equals(that.productId) : that.productId != null);
}

@Override
public int hashCode()
{
    int result = productId != null ? productId.hashCode() : 0;
    result = 31 * result + (isSubscription ? 1 : 0);
    return result;
}

@Override
public int describeContents()
{
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags)
{
    dest.writeString(this.productId);
    dest.writeString(this.title);
    dest.writeString(this.description);
    dest.writeByte(isSubscription ? (byte) 1 : (byte) 0);
    dest.writeString(this.currency);
    dest.writeDouble(this.priceValue);
    dest.writeLong(this.priceLong);
    dest.writeString(this.priceText);
    dest.writeString(this.subscriptionPeriod);
    dest.writeString(this.subscriptionFreeTrialPeriod);
    dest.writeByte(this.haveTrialPeriod ? (byte) 1 : (byte) 0);
    dest.writeDouble(this.introductoryPriceValue);
    dest.writeLong(this.introductoryPriceLong);
    dest.writeString(this.introductoryPriceText);
    dest.writeString(this.introductoryPricePeriod);
    dest.writeByte(this.haveIntroductoryPeriod ? (byte) 1 : (byte) 0);
    dest.writeInt(this.introductoryPriceCycles);
}

protected SkuDetails(Parcel in)
{
    this.productId = in.readString();
    this.title = in.readString();
    this.description = in.readString();
    this.isSubscription = in.readByte() != 0;
    this.currency = in.readString();
    this.priceValue = in.readDouble();
    this.priceLong = in.readLong();
    this.priceText = in.readString();
    this.subscriptionPeriod = in.readString();
    this.subscriptionFreeTrialPeriod = in.readString();
    this.haveTrialPeriod = in.readByte() != 0;
    this.introductoryPriceValue = in.readDouble();
    this.introductoryPriceLong = in.readLong();
    this.introductoryPriceText = in.readString();
    this.introductoryPricePeriod = in.readString();
    this.haveIntroductoryPeriod = in.readByte() != 0;
    this.introductoryPriceCycles = in.readInt();
}

public static final Parcelable.Creator<SkuDetails> CREATOR =
        new Parcelable.Creator<SkuDetails>()
        {
            public SkuDetails createFromParcel(Parcel source)
            {
                return new SkuDetails(source);
            }

            public SkuDetails[] newArray(int size)
            {
                return new SkuDetails[size];
            }
        };

}

0 个答案:

没有答案