コード例 #1
0
        private void BtnClickSaveData_Click(object sender, EventArgs e)
        {
            // Serial number
            EditText serialNumberLoyalty = FindViewById <EditText>(Resource.Id.serinumberLoyalty);
            string   serialNumber        = serialNumberLoyalty.Text.ToString().Trim();

            if (TextUtils.IsEmpty(serialNumber))
            {
                Toast.MakeText(this, "Serial number can't be empty.", ToastLength.Long).Show();
                return;
            }

            // Pass type.
            EditText passStyleIdentifier = FindViewById <EditText>(Resource.Id.passStyleIdentifier);
            TextView passTypeId          = FindViewById <TextView>(Resource.Id.passTypeId);
            string   typeId = passTypeId.Text.ToString().Trim();

            if (TextUtils.IsEmpty(typeId))
            {
                Toast.MakeText(this, "Pass type can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Issuer Id(App ID)
            TextView issuerIdView = FindViewById <TextView>(Resource.Id.issuerId);
            string   issuerId     = issuerIdView.Text.ToString().Trim();

            if (TextUtils.IsEmpty(issuerId))
            {
                Toast.MakeText(this, "IssuerId can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Card Number.
            EditText edtCardNumber = FindViewById <EditText>(Resource.Id.cardNumberLoyalty);
            string   cardNumber    = edtCardNumber.Text.ToString().Trim();

            if (TextUtils.IsEmpty(cardNumber))
            {
                Toast.MakeText(this, "Card Number can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Member Name.
            EditText edtMemberName = FindViewById <EditText>(Resource.Id.memberName);
            string   memberName    = edtMemberName.Text.ToString().Trim();

            if (TextUtils.IsEmpty(memberName))
            {
                Toast.MakeText(this, "Member Name can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Locations
            EditText latitude   = FindViewById <EditText>(Resource.Id.latitude);
            EditText longitude  = FindViewById <EditText>(Resource.Id.longitude);
            EditText latitude1  = FindViewById <EditText>(Resource.Id.latitude1);
            EditText longitude1 = FindViewById <EditText>(Resource.Id.longitude1);

            //Add location.
            double latitudeValue  = 0.0;
            double longitudeValue = 0.0;
            string latitudeStr    = latitude.Text.ToString().Trim();
            string longitudeStr   = longitude.Text.ToString().Trim();
            string latitude1Str   = latitude1.Text.ToString().Trim();
            string longitude1Str  = longitude1.Text.ToString().Trim();

            if (TextUtils.IsEmpty(latitudeStr) || TextUtils.IsEmpty(longitudeStr))
            {
                Toast.MakeText(this, "Latitude & Longitude can't be empty.", ToastLength.Long).Show();
                return;
            }
            else
            {
                if (-90.0d <= Convert.ToDouble(latitudeStr) && Convert.ToDouble(latitudeStr) <= 90.0d &&
                    -180.0d <= Convert.ToDouble(longitudeStr) && Convert.ToDouble(longitudeStr) <= 180.0d)
                {
                    latitudeValue  = Convert.ToDouble(latitudeStr);
                    longitudeValue = Convert.ToDouble(longitudeStr);
                }
                else
                {
                    Toast.MakeText(this, "Latitude or Longitude value is illegal.", ToastLength.Long).Show();
                    return;
                }
            }

            //State
            string state = WalletPassConstant.PassStateActive;

            switch (dataList[index])
            {
            case "ACTIVE":
                state = WalletPassConstant.PassStateActive;
                break;

            case "COMPLETED":
                state = WalletPassConstant.PassStateCompleted;
                break;

            case "EXPIRED":
                state = WalletPassConstant.PassStateExpired;
                break;

            case "INACTIVE":
                state = WalletPassConstant.PassStateInactive;
                break;

            default:
                break;
            }

            //Create PassObject.Builder object.
            PassObject.Builder passBuilder = PassObject.GetBuilder();
            //Create common fields list.
            List <CommonField> commonField = new List <CommonField>();
            //Create append fields list.
            List <AppendField> appendFields = new List <AppendField>();

            //1	Background image of the card
            EditText    backgroundImage            = FindViewById <EditText>(Resource.Id.backgroundImage);
            CommonField backgroundImageCommonField = CommonField.GetBuilder()
                                                     .SetKey(WalletPassConstant.PassCommonFieldKeyBackgroundImg)
                                                     .SetLabel("backgroundImageLabel")
                                                     .SetValue(backgroundImage.Text.Trim().ToString())
                                                     .Build();

            commonField.Add(backgroundImageCommonField);

            //2	Logo on the card
            EditText    logoLoyalty     = FindViewById <EditText>(Resource.Id.logoLoyalty);
            CommonField logoCommonField = CommonField.GetBuilder()
                                          .SetKey(WalletPassConstant.PassCommonFieldKeyLogo)
                                          .SetLabel("This is logo label")
                                          .SetValue(logoLoyalty.Text.Trim().ToString())
                                          .Build();

            commonField.Add(logoCommonField);

            //3 Merchant name
            EditText    merchantNameLoyalty     = FindViewById <EditText>(Resource.Id.merchantNameLoyalty);
            CommonField merchantNameCommonField = CommonField.GetBuilder()
                                                  .SetKey(WalletPassConstant.PassCommonFieldKeyMerchantName)
                                                  .SetLabel("This is merchantName label.")
                                                  .SetValue(merchantNameLoyalty.Text.Trim().ToString())
                                                  .Build();

            commonField.Add(merchantNameCommonField);

            //4 Card name
            EditText    cardNameLoyalty     = FindViewById <EditText>(Resource.Id.nameLoyalty);
            CommonField cardNameCommonField = CommonField.GetBuilder()
                                              .SetKey(WalletPassConstant.PassCommonFieldKeyName)
                                              .SetLabel("This is cardName label")
                                              .SetValue(cardNameLoyalty.Text.Trim().ToString())
                                              .Build();

            commonField.Add(cardNameCommonField);

            //5 Card number
            CommonField cardNumberCommonField = CommonField.GetBuilder()
                                                .SetKey(WalletPassConstant.PassCommonFieldKeyCardNumber)
                                                .SetLabel("This is cardNumber label")
                                                .SetValue(cardNumber)
                                                .Build();

            //6 Balance
            EditText    balance            = FindViewById <EditText>(Resource.Id.balanceLoyalty);
            AppendField balanceCommonField = AppendField.GetBuilder()
                                             .SetKey(WalletPassConstant.PassCommonFieldKeyBalance)
                                             .SetLabel("Balance")
                                             .SetValue(balance.Text.Trim().ToString())
                                             .Build();

            appendFields.Add(balanceCommonField);

            //7 Number of associated coupons
            EditText relatedPassIdOne = FindViewById <EditText>(Resource.Id.relatedPassId1);
            EditText relatedPassTwo   = FindViewById <EditText>(Resource.Id.relatedPassId2);
            EditText relatedPassThree = FindViewById <EditText>(Resource.Id.relatedPassId3);
            EditText relatedPassFour  = FindViewById <EditText>(Resource.Id.relatedPassId4);
            List <RelatedPassInfo> relatedPassInfos = new List <RelatedPassInfo>();

            relatedPassInfos.Add(new RelatedPassInfo(relatedPassIdOne.Text.Trim().ToString(), relatedPassTwo.Text.Trim().ToString()));
            relatedPassInfos.Add(new RelatedPassInfo(relatedPassThree.Text.Trim().ToString(), relatedPassFour.Text.Trim().ToString()));
            passBuilder.AddRelatedPassIds(relatedPassInfos);

            //8 Number of loyalty points
            EditText    pointsLoyalty        = FindViewById <EditText>(Resource.Id.pointsLoyalty);
            AppendField pointsNubAppendField = AppendField.GetBuilder()
                                               .SetKey(WalletPassConstant.PassAppendFieldKeyPoints)
                                               .SetLabel("Points")
                                               .SetValue(pointsLoyalty.Text.Trim().ToString())
                                               .Build();

            appendFields.Add(pointsNubAppendField);

            //9 Barcode or QR Code
            //10 Remarks
            EditText barcodeText  = FindViewById <EditText>(Resource.Id.barcodeTextLoyalty);
            EditText barcodeValue = FindViewById <EditText>(Resource.Id.barcodeValueLoyalty);
            BarCode  barCode      = BarCode.GetBuilder()
                                    .SetType(BarCode.BarcodeTypeQrCode)
                                    .SetValue(barcodeValue.Text.Trim().ToString())
                                    .SetText(barcodeText.Text.Trim().ToString())
                                    .Build();

            passBuilder.SetBarCode(barCode);

            //11 Member name
            CommonField memberNameCommonField = CommonField.GetBuilder()
                                                .SetKey(WalletPassConstant.PassCommonFieldKeyMemberName)
                                                .SetLabel("Member Name")
                                                .SetValue(memberName)
                                                .Build();

            commonField.Add(memberNameCommonField);
            //12	Loyalty card number ->same to 5.Card number

            //13 Loyalty level
            EditText    edtLevelLoyalty  = FindViewById <EditText>(Resource.Id.levelLoyalty);
            AppendField levelAppendField = AppendField.GetBuilder()
                                           .SetKey(WalletPassConstant.PassAppendFieldKeyRewardsLevel)
                                           .SetLabel("Tier")
                                           .SetValue(edtLevelLoyalty.Text.Trim().ToString())
                                           .Build();

            appendFields.Add(levelAppendField);

            //14 Message
            EditText           messageHeader    = FindViewById <EditText>(Resource.Id.messageHeader);
            EditText           messageBody      = FindViewById <EditText>(Resource.Id.messageBody);
            EditText           messageHeaderOne = FindViewById <EditText>(Resource.Id.messageHeader1);
            EditText           messageBodyOne   = FindViewById <EditText>(Resource.Id.messageBody1);
            List <AppendField> messageList      = new List <AppendField>();

            messageList.Add(AppendField.GetBuilder()
                            .SetKey("1")
                            .SetLabel(messageHeader.Text.Trim().ToString())
                            .SetValue(messageBody.Text.Trim().ToString())
                            .Build());
            messageList.Add(AppendField.GetBuilder()
                            .SetKey("2")
                            .SetLabel(messageHeaderOne.Text.Trim().ToString())
                            .SetValue(messageBodyOne.Text.Trim().ToString())
                            .Build());
            passBuilder.AddMessageList(messageList);

            //15 Scrolling Images
            //ImageUris
            EditText           imageModuleDataMainUris       = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUris);
            EditText           imageModuleDataMainUrisDes    = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUrisDes);
            EditText           imageModuleDataMainUrisOne    = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUris1);
            EditText           imageModuleDataMainUrisDesOne = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUrisDes1);
            List <AppendField> imageList = new List <AppendField>();

            imageList.Add(AppendField.GetBuilder()
                          .SetKey("1")
                          .SetLabel(imageModuleDataMainUrisDes.Text.Trim().ToString())
                          .SetValue(imageModuleDataMainUris.Text.Trim().ToString())
                          .Build());
            imageList.Add(AppendField.GetBuilder()
                          .SetKey("2")
                          .SetLabel(imageModuleDataMainUrisDesOne.Text.Trim().ToString())
                          .SetValue(imageModuleDataMainUrisOne.Text.Trim().ToString())
                          .Build());
            passBuilder.AddImageList(imageList);

            //UrlList
            EditText           loyaltyUrlLabel    = FindViewById <EditText>(Resource.Id.loyaltyUrlLable);
            EditText           loyaltyUrlValue    = FindViewById <EditText>(Resource.Id.loyaltyUrlValue);
            EditText           loyaltyUrlLabelOne = FindViewById <EditText>(Resource.Id.loyaltyUrlLable1);
            EditText           loyaltyUrlValueOne = FindViewById <EditText>(Resource.Id.loyaltyUrlValue1);
            List <AppendField> urlList            = new List <AppendField>();

            urlList.Add(AppendField.GetBuilder()
                        .SetKey("1")
                        .SetLabel(loyaltyUrlLabel.Text.Trim().ToString())
                        .SetValue(loyaltyUrlValue.Text.Trim().ToString())
                        .Build());
            urlList.Add(AppendField.GetBuilder()
                        .SetKey("2")
                        .SetLabel(loyaltyUrlLabelOne.Text.Trim().ToString())
                        .SetValue(loyaltyUrlValueOne.Text.Trim().ToString())
                        .Build());
            passBuilder.AddUrlList(urlList);

            //16 Nearby stores
            EditText    nearbyLocationsLabel    = FindViewById <EditText>(Resource.Id.nearbyLocationsLable);
            EditText    nearbyLocationsValue    = FindViewById <EditText>(Resource.Id.nearbyLocationsValue);
            string      nearbyLocationsLabelStr = nearbyLocationsLabel.Text.Trim().ToString();
            string      nearbyLocationsValueStr = nearbyLocationsValue.Text.Trim().ToString();
            AppendField nearbyAppendField       = AppendField.GetBuilder()
                                                  .SetKey(WalletPassConstant.PassAppendFieldKeyNearbyLocations)
                                                  .SetLabel(nearbyLocationsLabelStr)
                                                  .SetValue(nearbyLocationsValueStr)
                                                  .Build();

            appendFields.Add(nearbyAppendField);

            //17 Main Page
            EditText    webSiteLabel        = FindViewById <EditText>(Resource.Id.websiteLable);
            EditText    webSiteValue        = FindViewById <EditText>(Resource.Id.websiteValue);
            string      webSiteLabelStr     = webSiteLabel.Text.Trim().ToString();
            string      webSiteValueStr     = webSiteValue.Text.Trim().ToString();
            AppendField mainPageAppendField = AppendField.GetBuilder()
                                              .SetKey(WalletPassConstant.PassAppendFieldKeyMainpage)
                                              .SetLabel(webSiteLabelStr)
                                              .SetValue(webSiteValueStr)
                                              .Build();

            appendFields.Add(mainPageAppendField);

            //18 Hotline
            EditText    hotLineLabel       = FindViewById <EditText>(Resource.Id.hotlineLable);
            EditText    hotLineValue       = FindViewById <EditText>(Resource.Id.hotlineValue);
            string      hotLineLabelStr    = hotLineLabel.Text.Trim().ToString();
            string      hotLineValueStr    = hotLineValue.Text.Trim().ToString();
            AppendField hotLineAppendField = AppendField.GetBuilder()
                                             .SetKey(WalletPassConstant.PassAppendFieldKeyHotline)
                                             .SetLabel(hotLineLabelStr)
                                             .SetValue(hotLineValueStr)
                                             .Build();

            appendFields.Add(hotLineAppendField);

            //Latlng
            List <Location> locationList = new List <Location>();

            locationList.Add(new Location(longitudeStr, latitudeStr));
            locationList.Add(new Location(longitude1Str, latitude1Str));
            passBuilder.AddLocationList(locationList);

            //Time
            long start = 0;
            long end   = 0;
            Date date  = new Date();

            if (TextUtils.IsEmpty(startTime))
            {
                Toast.MakeText(this, "Please select StartTime", ToastLength.Long).Show();
                return;
            }
            else
            {
                start = BasisTimesUtils.GetLongtimeOfYMD(startTime);
            }

            if (TextUtils.IsEmpty(endTime))
            {
                Toast.MakeText(this, "Please select EndTime", ToastLength.Long).Show();
                return;
            }
            else
            {
                end = BasisTimesUtils.GetLongtimeOfYMD(endTime);
            }

            if (end <= start || end <= date.Time)
            {
                Toast.MakeText(this, "Please check (EndTime > StartTime) && (EndTime > Current time)", ToastLength.Long).Show();
                return;
            }

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.English);

            passBuilder.SetStatus(PassStatus.GetBuilder()
                                  .SetState(state)
                                  .SetEffectTime(format.Format(new Date(start)))
                                  .SetExpireTime(format.Format(new Date(end)))
                                  .Build())
            .SetOrganizationPassId(cardNumber)
            .SetPassStyleIdentifier(passStyleIdentifier.Text.Trim().ToString())
            .SetPassTypeIdentifier(typeId)
            .SetSerialNumber(serialNumber)
            .AddAppendFields(appendFields)
            .AddCommonFields(commonField);

            PassObject passObject = passBuilder.Build();
            Intent     intent     = new Intent(this, typeof(PassTestActivity));

            intent.PutExtra("passObject", passObject.ToJson());
            intent.PutExtra("passId", cardNumber);
            intent.PutExtra("issuerId", issuerId);
            intent.PutExtra("typeId", typeId);
            StartActivity(intent);
        }
コード例 #2
0
        private void BtnClickSaveCouponData_Click(object sender, EventArgs e)
        {
            //Serial number
            EditText edtSerialNumberCoupon = FindViewById <EditText>(Resource.Id.serinumberCoupon);
            string   serialNumber          = edtSerialNumberCoupon.Text.Trim().ToString();

            if (TextUtils.IsEmpty(serialNumber))
            {
                Toast.MakeText(this, "Serialnumber can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Organization id
            EditText edtOrganizationIdCoupon = FindViewById <EditText>(Resource.Id.cardNumberCoupon);
            string   organizationId          = edtOrganizationIdCoupon.Text.Trim().ToString();

            if (TextUtils.IsEmpty(organizationId))
            {
                Toast.MakeText(this, "Cardnumber can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Style id
            EditText edtPassStyleIdentifierCoupon = FindViewById <EditText>(Resource.Id.passStyleIdentifierCoupon);
            string   styleId = edtPassStyleIdentifierCoupon.Text.Trim().ToString();

            if (TextUtils.IsEmpty(styleId))
            {
                Toast.MakeText(this, "Template ID can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Pass type id
            EditText edtPassType = FindViewById <EditText>(Resource.Id.typeIdentifierCoupon);
            string   typeId      = edtPassType.Text.Trim().ToString();

            if (TextUtils.IsEmpty(typeId))
            {
                Toast.MakeText(this, "Pass type can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Issuer id.
            EditText edtIssuerId = FindViewById <EditText>(Resource.Id.issuerIdCoupon);
            string   issuerId    = edtIssuerId.Text.Trim().ToString();

            if (TextUtils.IsEmpty(issuerId))
            {
                Toast.MakeText(this, "Issuer id can't be empty.", ToastLength.Long).Show();
                return;
            }

            EditText edtBackgroundColor = FindViewById <EditText>(Resource.Id.backgroundColorCoupon);
            EditText edtLogoCoupon      = FindViewById <EditText>(Resource.Id.logoCoupon);

            //Merchant name
            EditText edtMerchantNameCoupon = FindViewById <EditText>(Resource.Id.merchantNameCoupon);
            string   merchantName          = edtMerchantNameCoupon.Text.Trim().ToString();

            if (TextUtils.IsEmpty(merchantName))
            {
                Toast.MakeText(this, "Merchant name can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Coupon title
            EditText edtNameCoupon = FindViewById <EditText>(Resource.Id.nameCoupon);
            string   name          = edtNameCoupon.Text.Trim().ToString();

            if (TextUtils.IsEmpty(name))
            {
                Toast.MakeText(this, "Coupon title can't be empty.", ToastLength.Long).Show();
                return;
            }

            //State
            string state = WalletPassConstant.PassStateActive;

            switch (dataList[index])
            {
            case "ACTIVE":
                state = WalletPassConstant.PassStateActive;
                break;

            case "COMPLETED":
                state = WalletPassConstant.PassStateCompleted;
                break;

            case "EXPIRED":
                state = WalletPassConstant.PassStateExpired;
                break;

            case "INACTIVE":
                state = WalletPassConstant.PassStateInactive;
                break;

            default:
                break;
            }

            //Time check
            long start = 0;
            long end   = 0;
            Date date  = new Date();

            if (TextUtils.IsEmpty(startTime))
            {
                Toast.MakeText(this, "Please select StartTime.", ToastLength.Long).Show();
                return;
            }
            else
            {
                start = BasisTimesUtils.GetLongtimeOfYMD(startTime);
            }

            if (TextUtils.IsEmpty(endTime))
            {
                Toast.MakeText(this, "Please select EndTime", ToastLength.Long).Show();
                return;
            }
            else
            {
                end = BasisTimesUtils.GetLongtimeOfYMD(endTime);
            }

            if (end <= start || end <= date.Time)
            {
                Toast.MakeText(this, "Please check (EndTime > StartTime) && (EndTime > CurrentTime)", ToastLength.Long).Show();
                return;
            }

            //Provider name
            EditText edtMerchantProviderCoupon = FindViewById <EditText>(Resource.Id.merchantProvidesCoupon);
            string   providesCoupon            = edtMerchantProviderCoupon.Text.ToString();

            if (TextUtils.IsEmpty(providesCoupon))
            {
                Toast.MakeText(this, "ProvidesName can't be empty.", ToastLength.Long).Show();
                return;
            }

            //Bar code
            EditText edtPassBarcode      = FindViewById <EditText>(Resource.Id.barcodeTextCoupon);
            EditText edtPassBarcodeValue = FindViewById <EditText>(Resource.Id.barcodeValueCoupon);

            //Details
            EditText edtDetailsCoupon = FindViewById <EditText>(Resource.Id.DetailsCoupon);

            //ImageUris
            EditText edtImageModuleDataMainImageUrisCoupon        = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUrisCoupon);
            EditText edtImageModuleDataMainImageUrisDescCoupon    = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUrisDesCoupon);
            EditText edtImageModuleDataMainImageUrisCouponOne     = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUrisCoupon1);
            EditText edtImageModuleDataMainImageUrisDescCouponOne = FindViewById <EditText>(Resource.Id.imageModuleDataMainImageUrisDesCoupon1);

            string imageUris    = edtImageModuleDataMainImageUrisCoupon.Text.Trim().ToString();
            string imageDesc    = edtImageModuleDataMainImageUrisDescCoupon.Text.Trim().ToString();
            string imageUrisOne = edtImageModuleDataMainImageUrisCouponOne.Text.Trim().ToString();
            string imageDescOne = edtImageModuleDataMainImageUrisDescCouponOne.Text.Trim().ToString();

            //DisclaimerCoupon
            EditText edtDisclaimerCoupon = FindViewById <EditText>(Resource.Id.disclaimerCoupon);

            //Message
            EditText edtMessageHeaderCoupon    = FindViewById <EditText>(Resource.Id.messageHeaderCoupon);
            EditText edtMessageBodyCoupon      = FindViewById <EditText>(Resource.Id.messageBodyCoupon);
            EditText edtMessageHeaderCouponOne = FindViewById <EditText>(Resource.Id.messageHeaderCoupon1);
            EditText edtMessageBodyCouponOne   = FindViewById <EditText>(Resource.Id.messageBodyCoupon1);

            string messageHeader    = edtMessageHeaderCoupon.Text.Trim().ToString();
            string messageBody      = edtMessageBodyCoupon.Text.Trim().ToString();
            string messageHeaderOne = edtMessageHeaderCouponOne.Text.Trim().ToString();
            string messageBodyOne   = edtMessageBodyCouponOne.Text.Trim().ToString();

            PassObject.Builder passBuilder = PassObject.GetBuilder();
            //Common fields
            List <CommonField> commonFields = new List <CommonField>();
            //Append fields
            List <AppendField> appendFields = new List <AppendField>();

            //1 Background color of the outer frame.
            CommonField backgroundColorCommonField = CommonField.GetBuilder()
                                                     .SetKey(WalletPassConstant.PassAppendFieldKeyBackgroundColor)
                                                     .SetLabel("Background color label")
                                                     .SetValue(edtBackgroundColor.Text.Trim().ToString())
                                                     .Build();

            commonFields.Add(backgroundColorCommonField);

            //3 Logo on the coupon.
            CommonField logoCommonField = CommonField.GetBuilder()
                                          .SetKey(WalletPassConstant.PassCommonFieldKeyLogo)
                                          .SetLabel("This is logo label")
                                          .SetValue(edtLogoCoupon.Text.Trim().ToString())
                                          .Build();

            commonFields.Add(logoCommonField);

            //4 Merchant name
            CommonField merchantNameCommonField = CommonField.GetBuilder()
                                                  .SetKey(WalletPassConstant.PassCommonFieldKeyMerchantName)
                                                  .SetLabel("This is merchant name label")
                                                  .SetValue(merchantName)
                                                  .Build();

            commonFields.Add(merchantNameCommonField);

            //5 Coupon title
            CommonField couponTitleCommonField = CommonField.GetBuilder()
                                                 .SetKey(WalletPassConstant.PassCommonFieldKeyName)
                                                 .SetLabel("This is Coupon title label")
                                                 .SetValue(name)
                                                 .Build();

            commonFields.Add(couponTitleCommonField);

            //6 Expiration time
            //Simple date format.
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

            passBuilder.SetStatus(PassStatus.GetBuilder().SetState(state).SetEffectTime(format.Format(new Date(start))).SetExpireTime(format.Format(new Date(end))).Build());

            //7 Merchant that provides the coupon
            AppendField merchantProvidesAppendField = AppendField.GetBuilder()
                                                      .SetKey(WalletPassConstant.PassCommonFieldKeyProviderName)
                                                      .SetLabel("This is merchant provider label")
                                                      .SetValue(providesCoupon)
                                                      .Build();

            appendFields.Add(merchantProvidesAppendField);

            //8 Barcode or QR code
            //9 Remarks
            BarCode barCode = BarCode.GetBuilder()
                              .SetType(BarCode.BarcodeTypeQrCode)
                              .SetValue(edtPassBarcodeValue.Text.Trim().ToString())
                              .SetText(edtPassBarcode.Text.Trim().ToString())
                              .Build();

            passBuilder.SetBarCode(barCode);

            //10 Details
            AppendField detailsAppendField = AppendField.GetBuilder()
                                             .SetKey(WalletPassConstant.PassAppendFieldKeyDetails)
                                             .SetLabel("This is details label")
                                             .SetValue(edtDetailsCoupon.Text.Trim().ToString())
                                             .Build();

            appendFields.Add(detailsAppendField);

            //11 Scrolling images
            List <AppendField> imageList = new List <AppendField>();

            imageList.Add(AppendField.GetBuilder()
                          .SetKey("1")
                          .SetLabel(imageDesc)
                          .SetValue(imageUris)
                          .Build());
            imageList.Add(AppendField.GetBuilder()
                          .SetKey("2")
                          .SetLabel(imageDescOne)
                          .SetValue(imageUrisOne)
                          .Build());
            passBuilder.AddImageList(imageList);

            //Urllist
            EditText edtCouponUrlLabel    = FindViewById <EditText>(Resource.Id.couponUrlLable);
            EditText edtCouponUrlValue    = FindViewById <EditText>(Resource.Id.couponUrlValue);
            EditText edtCouponUrlLabelOne = FindViewById <EditText>(Resource.Id.couponUrlLable1);
            EditText edtCouponUrlValueOne = FindViewById <EditText>(Resource.Id.couponUrlValue1);

            List <AppendField> urlList = new List <AppendField>();

            urlList.Add(AppendField.GetBuilder()
                        .SetKey("1")
                        .SetLabel(edtCouponUrlLabel.Text.Trim().ToString())
                        .SetValue(edtCouponUrlValue.Text.Trim().ToString())
                        .Build());
            urlList.Add(AppendField.GetBuilder()
                        .SetKey("2")
                        .SetLabel(edtCouponUrlLabelOne.Text.Trim().ToString())
                        .SetValue(edtCouponUrlValueOne.Text.Trim().ToString())
                        .Build());
            passBuilder.AddUrlList(urlList);

            //12 Disclaimer
            AppendField disclaimerAppendField = AppendField.GetBuilder()
                                                .SetKey(WalletPassConstant.PassAppendFieldKeyDisclaimer)
                                                .SetLabel("This is Disclaimer label")
                                                .SetValue(edtDisclaimerCoupon.Text.Trim().ToString())
                                                .Build();

            appendFields.Add(disclaimerAppendField);

            //13 Message
            List <AppendField> messageList = new List <AppendField>();

            messageList.Add(AppendField.GetBuilder()
                            .SetKey("1")
                            .SetLabel(messageHeader)
                            .SetValue(messageBody)
                            .Build());
            messageList.Add(AppendField.GetBuilder()
                            .SetKey("2")
                            .SetLabel(messageHeaderOne)
                            .SetValue(messageBodyOne)
                            .Build());
            passBuilder.AddMessageList(messageList);

            passBuilder.SetOrganizationPassId(organizationId);
            passBuilder.SetPassStyleIdentifier(styleId);
            passBuilder.SetPassTypeIdentifier(typeId);
            passBuilder.SetSerialNumber(serialNumber);
            passBuilder.AddAppendFields(appendFields);
            passBuilder.AddCommonFields(commonFields);

            PassObject passObject = passBuilder.Build();
            Intent     intent     = new Intent(this, typeof(PassTestActivity));

            intent.PutExtra("passObject", passObject.ToJson());
            intent.PutExtra("passId", organizationId);
            intent.PutExtra("issuerId", issuerId);
            intent.PutExtra("typeId", typeId);
            StartActivity(intent);
        }
コード例 #3
0
        private void BtnClickSaveGiftData_Click(object sender, EventArgs e)
        {
            //Pass style identifier.
            EditText edtPassStyleIdentifierGift = FindViewById <EditText>(Resource.Id.passStyleIdentifierGift);
            string   styleId = edtPassStyleIdentifierGift.Text.Trim().ToString();

            if (TextUtils.IsEmpty(styleId))
            {
                Toast.MakeText(this, "Template Id cant be empty.", ToastLength.Long).Show();
                return;
            }

            //Construct gift card data.
            PassObject.Builder passBuilder = PassObject.GetBuilder();

            //Common fields.
            List <CommonField> commonFields = new List <CommonField>();
            //Append fields.
            List <AppendField> appendFields = new List <AppendField>();

            //Background and description
            EditText edtBackgroundColor     = FindViewById <EditText>(Resource.Id.giftBackGroundImage);
            EditText edtBackgroundColorDesc = FindViewById <EditText>(Resource.Id.giftBackGroundImageDesc);

            //1 Background image of the card.
            CommonField backgroundImageCommonField = CommonField.GetBuilder()
                                                     .SetKey(WalletPassConstant.PassCommonFieldKeyBackgroundImg)
                                                     .SetLabel(edtBackgroundColorDesc.Text.Trim().ToString())
                                                     .SetValue(edtBackgroundColor.Text.Trim().ToString())
                                                     .Build();

            commonFields.Add(backgroundImageCommonField);

            //2 Logo on the card
            //Logo
            EditText    edtGiftCardLogo = FindViewById <EditText>(Resource.Id.giftCardLogo);
            CommonField logoCommonField = CommonField.GetBuilder()
                                          .SetKey(WalletPassConstant.PassCommonFieldKeyLogo)
                                          .SetLabel("This is logo label")
                                          .SetValue(edtGiftCardLogo.Text.Trim().ToString())
                                          .Build();

            commonFields.Add(logoCommonField);

            //3 Merchant name
            EditText edtMerchantName = FindViewById <EditText>(Resource.Id.giftMerchantName);

            CommonField merchantNameCommonField = CommonField.GetBuilder()
                                                  .SetKey(WalletPassConstant.PassCommonFieldKeyMerchantName)
                                                  .SetLabel("This is Merchant Name label")
                                                  .SetValue(edtMerchantName.Text.Trim().ToString())
                                                  .Build();

            commonFields.Add(merchantNameCommonField);

            //4 Card name
            EditText    edtGiftCardname     = FindViewById <EditText>(Resource.Id.giftCardname);
            CommonField cardNameCommonField = CommonField.GetBuilder()
                                              .SetKey(WalletPassConstant.PassCommonFieldKeyName)
                                              .SetLabel("This is Card name label")
                                              .SetValue(edtGiftCardname.Text.Trim().ToString())
                                              .Build();

            commonFields.Add(cardNameCommonField);

            //5 Card number
            EditText edtGiftCardNumber = FindViewById <EditText>(Resource.Id.giftCardNumber);
            string   giftCardNumber    = edtGiftCardNumber.Text.Trim().ToString();

            if (TextUtils.IsEmpty(giftCardNumber))
            {
                Toast.MakeText(this, "Card number can't be empty.", ToastLength.Long).Show();
                return;
            }
            CommonField cardNumberCommonField = CommonField.GetBuilder()
                                                .SetKey(WalletPassConstant.PassCommonFieldKeyCardNumber)
                                                .SetLabel("This is CardNumber label")
                                                .SetValue(giftCardNumber)
                                                .Build();

            commonFields.Add(cardNumberCommonField);

            //6 Balance
            EditText    edtGiftBalance     = FindViewById <EditText>(Resource.Id.giftBalance);
            CommonField balanceCommonField = CommonField.GetBuilder()
                                             .SetKey(WalletPassConstant.PassCommonFieldKeyBalance)
                                             .SetLabel("This is balance label")
                                             .SetValue(edtGiftBalance.Text.Trim().ToString())
                                             .Build();

            commonFields.Add(balanceCommonField);

            //Gift currrency
            EditText edtGiftCurrency = FindViewById <EditText>(Resource.Id.giftCurrency);

            passBuilder.SetCurrencyCode(edtGiftCurrency.Text.Trim().ToString());

            //7 Barcode or Qrcode
            EditText edtPassBarcodeAlternate = FindViewById <EditText>(Resource.Id.passBarcodeAlternateText);
            string   barType             = BarCode.BarcodeTypeQrCode;
            EditText edtPassBarcodeValue = FindViewById <EditText>(Resource.Id.passBarcodeValue);

            switch (barcodeStyleList[barcodeStyleIndex])
            {
            case "Codabar":
                barType = BarCode.BarcodeTypeCodabar;
                break;

            case "QrCode":
                barType = BarCode.BarcodeTypeQrCode;
                break;

            default:
                break;
            }

            BarCode barCode = BarCode.GetBuilder()
                              .SetType(barType)
                              .SetValue(edtPassBarcodeValue.Text.Trim().ToString())
                              .SetText(edtPassBarcodeAlternate.Text.Trim().ToString())
                              .Build();

            passBuilder.SetBarCode(barCode);

            //9 Balance update time
            // balance update time
            long update = 0;

            if (TextUtils.IsEmpty(updateTime))
            {
                Toast.MakeText(this, "Please select balance updateTime", ToastLength.Long).Show();
                return;
            }
            else
            {
                update = BasisTimesUtils.GetLongtimeOfYMD(updateTime);
            }

            //Simple date format
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
            // Create SimpleDateFormat
            string      updateTimeValue = format.Format(new Java.Util.Date(update));
            CommonField balanceUpdateTimeAppendfield = CommonField.GetBuilder()
                                                       .SetKey(WalletPassConstant.PassCommonFieldKeyBalanceRefreshTime)
                                                       .SetLabel("Updated")
                                                       .SetValue(updateTimeValue)
                                                       .Build();

            commonFields.Add(balanceUpdateTimeAppendfield);

            //10 Pin
            EditText    edtGiftCardPin = FindViewById <EditText>(Resource.Id.giftCardPin);
            CommonField pinCommonField = CommonField.GetBuilder()
                                         .SetKey(WalletPassConstant.PassCommonFieldKeyBlancePin)
                                         .SetLabel("PIN Number")
                                         .SetValue(edtGiftCardPin.Text.ToString())
                                         .Build();

            commonFields.Add(pinCommonField);

            //11 Event number
            EditText    edtGiftEventNumber     = FindViewById <EditText>(Resource.Id.giftEventNumber);
            AppendField eventNumberAppendField = AppendField.GetBuilder()
                                                 .SetKey(WalletPassConstant.PassAppendFieldKeyEventNumber)
                                                 .SetLabel("Event Number")
                                                 .SetValue(edtGiftEventNumber.Text.Trim().ToString())
                                                 .Build();

            appendFields.Add(eventNumberAppendField);

            //12 Message
            //message
            EditText edtMessageHeaderGift    = FindViewById <EditText>(Resource.Id.messageHeaderGift);
            EditText edtMessageBodyGift      = FindViewById <EditText>(Resource.Id.messageBodyGift);
            EditText edtMessageHeaderGiftOne = FindViewById <EditText>(Resource.Id.messageHeaderGift1);
            EditText edtMessageBodyGiftOne   = FindViewById <EditText>(Resource.Id.messageBodyGift1);

            List <AppendField> messageList = new List <AppendField>();

            messageList.Add(AppendField.GetBuilder()
                            .SetKey("1")
                            .SetLabel(edtMessageHeaderGift.Text.Trim().ToString())
                            .SetValue(edtMessageBodyGift.Text.Trim().ToString())
                            .Build());
            messageList.Add(AppendField.GetBuilder()
                            .SetKey("2")
                            .SetLabel(edtMessageHeaderGiftOne.Text.Trim().ToString())
                            .SetValue(edtMessageBodyGiftOne.Text.Trim().ToString())
                            .Build());
            passBuilder.AddMessageList(messageList);

            //13 Scrolling images
            List <AppendField> imageList                 = new List <AppendField>();
            EditText           edtScrollingImagesOne     = FindViewById <EditText>(Resource.Id.giftScrollingImages1);
            EditText           edtScrollingImagesDescOne = FindViewById <EditText>(Resource.Id.giftScrollingDesc1);
            EditText           edtScrollingImagesTwo     = FindViewById <EditText>(Resource.Id.giftScrollingImages2);
            EditText           edtScrollingImagesDescTwo = FindViewById <EditText>(Resource.Id.giftScrollingDesc2);

            imageList.Add(AppendField.GetBuilder()
                          .SetKey("1")
                          .SetLabel(edtScrollingImagesDescOne.Text.Trim().ToString())
                          .SetValue(edtScrollingImagesDescTwo.Text.Trim().ToString())
                          .Build());
            imageList.Add(AppendField.GetBuilder()
                          .SetKey("2")
                          .SetLabel(edtScrollingImagesDescTwo.Text.Trim().ToString())
                          .SetValue(edtScrollingImagesTwo.Text.Trim().ToString())
                          .Build());
            passBuilder.AddImageList(imageList);

            //UrlList
            EditText edtGiftUrlLabel    = FindViewById <EditText>(Resource.Id.giftUrlLable);
            EditText edtGiftUrlValue    = FindViewById <EditText>(Resource.Id.giftUrlValue);
            EditText edtGiftUrlLabelOne = FindViewById <EditText>(Resource.Id.giftUrlLable1);
            EditText edtGiftUrlValueOne = FindViewById <EditText>(Resource.Id.giftUrlValue1);

            List <AppendField> urlList = new List <AppendField>();

            urlList.Add(AppendField.GetBuilder()
                        .SetKey("1")
                        .SetLabel(edtGiftUrlLabel.Text.Trim().ToString())
                        .SetValue(edtGiftUrlValue.Text.Trim().ToString())
                        .Build());
            urlList.Add(AppendField.GetBuilder()
                        .SetKey("2")
                        .SetLabel(edtGiftUrlLabelOne.Text.Trim().ToString())
                        .SetValue(edtGiftUrlValueOne.Text.Trim().ToString())
                        .Build());
            passBuilder.AddUrlList(urlList);

            //14 Nearby stores
            EditText    edtGiftNearbyStoresUrl  = FindViewById <EditText>(Resource.Id.giftNearbyStoresUrl);
            EditText    edtGiftNearbyStoresName = FindViewById <EditText>(Resource.Id.giftNearbyStoresName);
            AppendField nearbyAppendField       = AppendField.GetBuilder()
                                                  .SetKey(WalletPassConstant.PassAppendFieldKeyNearbyLocations)
                                                  .SetLabel(edtGiftNearbyStoresName.Text.Trim().ToString())
                                                  .SetValue(edtGiftNearbyStoresUrl.Text.Trim().ToString())
                                                  .Build();

            appendFields.Add(nearbyAppendField);

            //15 Main page
            EditText edtGiftMainPageUrl  = FindViewById <EditText>(Resource.Id.giftMainPageUrl);
            EditText edtGiftMainPageName = FindViewById <EditText>(Resource.Id.giftMainPageName);

            AppendField mainPageAppendField = AppendField.GetBuilder()
                                              .SetKey(WalletPassConstant.PassAppendFieldKeyMainpage)
                                              .SetLabel(edtGiftMainPageName.Text.Trim().ToString())
                                              .SetValue(edtGiftMainPageUrl.Text.Trim().ToString())
                                              .Build();

            appendFields.Add(mainPageAppendField);
            //16 Hotline
            EditText    edtGiftHotlinePone = FindViewById <EditText>(Resource.Id.giftHotlinePone);
            EditText    edtGiftHotlineName = FindViewById <EditText>(Resource.Id.giftHotlineName);
            AppendField hotlineAppendField = AppendField.GetBuilder()
                                             .SetKey(WalletPassConstant.PassAppendFieldKeyHotline)
                                             .SetLabel(edtGiftHotlineName.Text.Trim().ToString())
                                             .SetValue(edtGiftHotlinePone.Text.Trim().ToString())
                                             .Build();
            //Public constant
            //Time check
            long start = 0;
            long end   = 0;
            Date date  = new Date();

            if (TextUtils.IsEmpty(startTime))
            {
                Toast.MakeText(this, "Please select Starttime", ToastLength.Long).Show();
                return;
            }
            else
            {
                start = BasisTimesUtils.GetLongtimeOfYMD(startTime);
            }

            if (TextUtils.IsEmpty(endTime))
            {
                Toast.MakeText(this, "Please select EndTime", ToastLength.Long).Show();
                return;
            }
            else
            {
                end = BasisTimesUtils.GetLongtimeOfYMD(endTime);
            }

            if (end <= start || end <= date.Time)
            {
                Toast.MakeText(this, "Please check (EndTime > StartTime)&& (EndTime > Current Time)", ToastLength.Long).Show();
                return;
            }
            //serial Number
            EditText organizationPassIdGift = FindViewById <EditText>(Resource.Id.organizationPassIdGift);
            string   organizationPassId     = organizationPassIdGift.Text.Trim().ToString();

            if (TextUtils.IsEmpty(organizationPassId))
            {
                Toast.MakeText(this, "SerialNumber can't be empty.", ToastLength.Long).Show();
                return;
            }

            EditText passTypeId = FindViewById <EditText>(Resource.Id.passTypeIdentifier);
            string   typeId     = passTypeId.Text.Trim().ToString();

            if (TextUtils.IsEmpty(typeId))
            {
                Toast.MakeText(this, "Pass Type can't be empty", ToastLength.Long).Show();
                return;
            }

            EditText edtIssuerIdGift = FindViewById <EditText>(Resource.Id.issuerIdGift);
            string   issuerId        = edtIssuerIdGift.Text.Trim().ToString();

            if (TextUtils.IsEmpty(issuerId))
            {
                Toast.MakeText(this, "Issuer id can't be empty.", ToastLength.Long).Show();
                return;
            }

            //State
            string state = WalletPassConstant.PassStateActive;

            switch (dataList[index])
            {
            case "ACTIVE":
                state = WalletPassConstant.PassStateActive;
                break;

            case "COMPLETED":
                state = WalletPassConstant.PassStateCompleted;
                break;

            case "EXPIRED":
                state = WalletPassConstant.PassStateExpired;
                break;

            case "INACTIVE":
                state = WalletPassConstant.PassStateInactive;
                break;

            default:
                break;
            }

            appendFields.Add(hotlineAppendField);
            //PassStyleIdentifier
            EditText edtPassStyleIdentifier = FindViewById <EditText>(Resource.Id.passStyleIdentifierGift);

            passBuilder.SetOrganizationPassId(edtGiftCardNumber.Text.Trim().ToString());
            passBuilder.SetPassStyleIdentifier(edtPassStyleIdentifier.Text.Trim().ToString());
            passBuilder.SetPassTypeIdentifier(typeId);
            passBuilder.SetSerialNumber(organizationPassId);
            passBuilder.SetStatus(PassStatus.GetBuilder().SetState(state).SetEffectTime(format.Format(new Date(start))).SetExpireTime(format.Format(new Date(end))).Build());
            passBuilder.AddAppendFields(appendFields);
            passBuilder.AddCommonFields(commonFields);
            PassObject passObject = passBuilder.Build();

            Log.Info("GiftCardActivity", "passObject: " + passObject.ToJson());
            Intent intent = new Intent(this, typeof(PassTestActivity));

            intent.PutExtra("passObject", passObject.ToJson());
            intent.PutExtra("passId", organizationPassId);
            intent.PutExtra("issuerId", issuerId);
            intent.PutExtra("typeId", typeId);
            StartActivity(intent);
        }