Ejemplo n.º 1
0
        private AndroidJavaObject GetAdMetadataJavaObject(MATAdMetadata metadata)
        {
            // Convert C# MATAdMetadata to new Java TuneAdRequest object
            AndroidJavaObject objRequest = new AndroidJavaObject("com.tune.crosspromo.TuneAdMetadata");

            // Set debug mode boolean
            objRequest = objRequest.Call <AndroidJavaObject>("withDebugMode", metadata.getDebugMode());

            // Set gender as MATAdGender enum value
            AndroidJavaObject gender;

            if (metadata.getGender() == MATAdGender.MALE)
            {
                gender = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic <AndroidJavaObject>("MALE");
            }
            else if (metadata.getGender() == MATAdGender.FEMALE)
            {
                gender = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic <AndroidJavaObject>("FEMALE");
            }
            else
            {
                gender = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic <AndroidJavaObject>("UNKNOWN");
            }
            objRequest = objRequest.Call <AndroidJavaObject>("withGender", gender);

            // Set latitude/longitude as doubles
            if (metadata.getLatitude() != 0.0 && metadata.getLongitude() != 0.0)
            {
                double latitude  = Convert.ToDouble(metadata.getLatitude());
                double longitude = Convert.ToDouble(metadata.getLongitude());
                objRequest = objRequest.Call <AndroidJavaObject>("withLocation", latitude, longitude);
            }

            // Set birthdate
            if (metadata.getBirthDate().HasValue)
            {
                DateTime birthDate = metadata.getBirthDate().GetValueOrDefault();
                int      year      = birthDate.Year;
                int      month     = birthDate.Month;
                int      day       = birthDate.Day;
                objRequest = objRequest.Call <AndroidJavaObject>("withBirthDate", year, month, day);
            }

            // Set custom targets: create a new HashMap<String, String> and populate
            if (metadata.getCustomTargets().Count != 0)
            {
                AndroidJavaObject objMap = new AndroidJavaObject("java.util.HashMap");
                // Unity AndroidJavaObject Call doesn't support null responses, so use JNI to populate
                IntPtr methodPut = AndroidJNIHelper.GetMethodID(objMap.GetRawClass(), "put",
                                                                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                object[] args = new object[2];
                foreach (KeyValuePair <string, string> target in metadata.getCustomTargets())
                {
                    AndroidJavaObject key   = new AndroidJavaObject("java.lang.String", target.Key + "");
                    AndroidJavaObject value = new AndroidJavaObject("java.lang.String", target.Value + "");
                    args[0] = key;
                    args[1] = value;
                    AndroidJNI.CallObjectMethod(objMap.GetRawObject(), methodPut, AndroidJNIHelper.CreateJNIArgArray(args));
                }
                objRequest = objRequest.Call <AndroidJavaObject>("withCustomTargets", objMap);
            }

            // Set keywords: create a new Set<String> and populate
            if (metadata.getKeywords().Count != 0)
            {
                AndroidJavaObject objSet = new AndroidJavaObject("java.util.HashSet");
                foreach (string keyword in metadata.getKeywords())
                {
                    objSet.Call <bool>("add", keyword);
                }
                objRequest = objRequest.Call <AndroidJavaObject>("withKeywords", objSet);
            }

            return(objRequest);
        }
Ejemplo n.º 2
0
        private AndroidJavaObject GetAdMetadataJavaObject(MATAdMetadata metadata)
        {
            AndroidJavaObject @static;
            AndroidJavaObject obj2 = new AndroidJavaObject("com.tune.crosspromo.TuneAdMetadata", new object[0]);

            object[] args = new object[] { metadata.getDebugMode() };
            obj2 = obj2.Call <AndroidJavaObject>("withDebugMode", args);
            if (metadata.getGender() == MATAdGender.MALE)
            {
                @static = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic <AndroidJavaObject>("MALE");
            }
            else if (metadata.getGender() == MATAdGender.FEMALE)
            {
                @static = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic <AndroidJavaObject>("FEMALE");
            }
            else
            {
                @static = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic <AndroidJavaObject>("UNKNOWN");
            }
            object[] objArray2 = new object[] { @static };
            obj2 = obj2.Call <AndroidJavaObject>("withGender", objArray2);
            if ((metadata.getLatitude() != 0.0) && (metadata.getLongitude() != 0.0))
            {
                double   num       = Convert.ToDouble(metadata.getLatitude());
                double   num2      = Convert.ToDouble(metadata.getLongitude());
                object[] objArray3 = new object[] { num, num2 };
                obj2 = obj2.Call <AndroidJavaObject>("withLocation", objArray3);
            }
            if (metadata.getBirthDate().HasValue)
            {
                DateTime valueOrDefault = metadata.getBirthDate().GetValueOrDefault();
                int      year           = valueOrDefault.Year;
                int      month          = valueOrDefault.Month;
                int      day            = valueOrDefault.Day;
                object[] objArray4      = new object[] { year, month, day };
                obj2 = obj2.Call <AndroidJavaObject>("withBirthDate", objArray4);
            }
            if (metadata.getCustomTargets().Count != 0)
            {
                AndroidJavaObject obj4     = new AndroidJavaObject("java.util.HashMap", new object[0]);
                IntPtr            methodID = AndroidJNIHelper.GetMethodID(obj4.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                object[]          objArray = new object[2];
                foreach (KeyValuePair <string, string> pair in metadata.getCustomTargets())
                {
                    object[]          objArray5 = new object[] { pair.Key + string.Empty };
                    AndroidJavaObject obj5      = new AndroidJavaObject("java.lang.String", objArray5);
                    object[]          objArray6 = new object[] { pair.Value + string.Empty };
                    AndroidJavaObject obj6      = new AndroidJavaObject("java.lang.String", objArray6);
                    objArray[0] = obj5;
                    objArray[1] = obj6;
                    AndroidJNI.CallObjectMethod(obj4.GetRawObject(), methodID, AndroidJNIHelper.CreateJNIArgArray(objArray));
                }
                object[] objArray7 = new object[] { obj4 };
                obj2 = obj2.Call <AndroidJavaObject>("withCustomTargets", objArray7);
            }
            if (metadata.getKeywords().Count == 0)
            {
                return(obj2);
            }
            AndroidJavaObject obj7 = new AndroidJavaObject("java.util.HashSet", new object[0]);

            foreach (string str in metadata.getKeywords())
            {
                object[] objArray8 = new object[] { str };
                obj7.Call <bool>("add", objArray8);
            }
            object[] objArray9 = new object[] { obj7 };
            return(obj2.Call <AndroidJavaObject>("withKeywords", objArray9));
        }
Ejemplo n.º 3
0
        // Load an ad.
        private static IntPtr CreateMetadata(MATAdMetadata metadata)
        {
            IntPtr metadataPtr = MATExterns.TuneCreateMetadata();
            foreach (string keyword in metadata.getKeywords()) {
                MATExterns.TuneAddKeyword(metadataPtr, keyword);
            }

            if (metadata.getBirthDate().HasValue) {
                DateTime birthDate = metadata.getBirthDate().GetValueOrDefault();
                MATExterns.TuneSetBirthDate(metadataPtr, birthDate.Year, birthDate.Month, birthDate.Day);
            }

            MATExterns.TuneAdSetDebugMode(metadataPtr, (bool)metadata.getDebugMode ());
            MATExterns.TuneAdSetGender(metadataPtr, (int)metadata.getGender ());

            MATExterns.TuneSetLatitude(metadataPtr, (int)metadata.getLatitude ());
            MATExterns.TuneSetLongitude(metadataPtr, (int)metadata.getLongitude ());
            MATExterns.TuneSetAltitude(metadataPtr, (int)metadata.getAltitude ());

            foreach (KeyValuePair<string, string> entry in metadata.getCustomTargets()) {
                MATExterns.TuneSetCustomTargets(metadataPtr, entry.Key, entry.Value);
            }

            return metadataPtr;
        }
Ejemplo n.º 4
0
        private AndroidJavaObject GetAdMetadataJavaObject(MATAdMetadata metadata)
        {
            // Convert C# MATAdMetadata to new Java TuneAdRequest object
            AndroidJavaObject objRequest = new AndroidJavaObject("com.tune.crosspromo.TuneAdMetadata");

            // Set debug mode boolean
            objRequest = objRequest.Call<AndroidJavaObject>("withDebugMode", metadata.getDebugMode());

            // Set gender as MATAdGender enum value
            AndroidJavaObject gender;
            if (metadata.getGender() == MATAdGender.MALE)
            {
                gender = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic<AndroidJavaObject>("MALE");
            }
            else if (metadata.getGender() == MATAdGender.FEMALE)
            {
                gender = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic<AndroidJavaObject>("FEMALE");
            }
            else
            {
                gender = new AndroidJavaClass("com.mobileapptracker.MATGender").GetStatic<AndroidJavaObject>("UNKNOWN");
            }
            objRequest = objRequest.Call<AndroidJavaObject>("withGender", gender);

            // Set latitude/longitude as doubles
            if (metadata.getLatitude() != 0.0 && metadata.getLongitude() != 0.0)
            {
                double latitude = Convert.ToDouble(metadata.getLatitude());
                double longitude = Convert.ToDouble(metadata.getLongitude());
                objRequest = objRequest.Call<AndroidJavaObject>("withLocation", latitude, longitude);
            }

            // Set birthdate
            if (metadata.getBirthDate().HasValue)
            {
                DateTime birthDate = metadata.getBirthDate().GetValueOrDefault();
                int year = birthDate.Year;
                int month = birthDate.Month;
                int day = birthDate.Day;
                objRequest = objRequest.Call<AndroidJavaObject>("withBirthDate", year, month, day);
            }

            // Set custom targets: create a new HashMap<String, String> and populate
            if (metadata.getCustomTargets().Count != 0)
            {
                AndroidJavaObject objMap = new AndroidJavaObject("java.util.HashMap");
                // Unity AndroidJavaObject Call doesn't support null responses, so use JNI to populate
                IntPtr methodPut = AndroidJNIHelper.GetMethodID(objMap.GetRawClass(), "put",
                                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                object[] args = new object[2];
                foreach (KeyValuePair<string, string> target in metadata.getCustomTargets())
                {
                    AndroidJavaObject key = new AndroidJavaObject("java.lang.String", target.Key + "");
                    AndroidJavaObject value = new AndroidJavaObject("java.lang.String", target.Value + "");
                    args[0] = key;
                    args[1] = value;
                    AndroidJNI.CallObjectMethod(objMap.GetRawObject(),methodPut, AndroidJNIHelper.CreateJNIArgArray(args));
                }
                objRequest = objRequest.Call<AndroidJavaObject>("withCustomTargets", objMap);
            }

            // Set keywords: create a new Set<String> and populate
            if (metadata.getKeywords().Count != 0)
            {
                AndroidJavaObject objSet = new AndroidJavaObject("java.util.HashSet");
                foreach (string keyword in metadata.getKeywords())
                {
                    objSet.Call<bool>("add", keyword);
                }
                objRequest = objRequest.Call<AndroidJavaObject>("withKeywords", objSet);
            }

            return objRequest;
        }