public static void ShowBanner(string placement, MATAdMetadata metadata, MATBannerPosition position) { if (!Application.isEditor) { MATAndroid.Instance.ShowBanner(placement, metadata, position); } }
public static void ShowInterstitial(string placement, MATAdMetadata metadata) { if (!Application.isEditor) { MATAndroid.Instance.ShowInterstitial(placement, metadata); } }
public void ShowInterstitial(string placement, MATAdMetadata metadata) { AndroidJavaObject adMetadataJavaObject = this.GetAdMetadataJavaObject(metadata); object[] args = new object[] { placement, adMetadataJavaObject }; this.ajcAlliances.Call("showInterstitial", args); }
public static void CacheInterstitial(string placement, MATAdMetadata metadata) { if (!Application.isEditor) { #if UNITY_ANDROID MATAndroid.Instance.CacheInterstitial(placement, metadata); #endif #if UNITY_IPHONE IntPtr metadataPtr = CreateMetadata(metadata); MATExterns.TuneCacheInterstitialWithMetadata(placement, metadataPtr); MATExterns.TuneRelease(metadataPtr); #endif } }
public void ShowBanner(String placement, MATAdMetadata metadata, MATBannerPosition position) { AndroidJavaObject objRequest = GetAdMetadataJavaObject(metadata); AndroidJavaObject objPosition; if (position == MATBannerPosition.TOP_CENTER) { objPosition = new AndroidJavaClass("com.tune.crosspromo.TuneBannerPosition").GetStatic<AndroidJavaObject>("TOP_CENTER"); } else { objPosition = new AndroidJavaClass("com.tune.crosspromo.TuneBannerPosition").GetStatic<AndroidJavaObject>("BOTTOM_CENTER"); } ajcAlliances.Call("showBanner", placement, objRequest, objPosition); }
public void ShowBanner(String placement, MATAdMetadata metadata, MATBannerPosition position) { AndroidJavaObject objRequest = GetAdMetadataJavaObject(metadata); AndroidJavaObject objPosition; if (position == MATBannerPosition.TOP_CENTER) { objPosition = new AndroidJavaClass("com.tune.crosspromo.TuneBannerPosition").GetStatic <AndroidJavaObject>("TOP_CENTER"); } else { objPosition = new AndroidJavaClass("com.tune.crosspromo.TuneBannerPosition").GetStatic <AndroidJavaObject>("BOTTOM_CENTER"); } ajcAlliances.Call("showBanner", placement, objRequest, objPosition); }
public void ShowBanner(string placement, MATAdMetadata metadata, MATBannerPosition position) { AndroidJavaObject @static; AndroidJavaObject adMetadataJavaObject = this.GetAdMetadataJavaObject(metadata); if (position == MATBannerPosition.TOP_CENTER) { @static = new AndroidJavaClass("com.tune.crosspromo.TuneBannerPosition").GetStatic <AndroidJavaObject>("TOP_CENTER"); } else { @static = new AndroidJavaClass("com.tune.crosspromo.TuneBannerPosition").GetStatic <AndroidJavaObject>("BOTTOM_CENTER"); } object[] args = new object[] { placement, adMetadataJavaObject, @static }; this.ajcAlliances.Call("showBanner", args); }
public void ShowBanner(string placement, MATAdMetadata metadata) { AndroidJavaObject objRequest = GetAdMetadataJavaObject(metadata); ajcAlliances.Call("showBanner", placement, objRequest); }
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); }
public static void ShowBanner(string placement, MATAdMetadata metadata, MATBannerPosition position) { if (!Application.isEditor) { #if UNITY_ANDROID MATAndroid.Instance.ShowBanner(placement, metadata, position); #endif #if UNITY_IPHONE IntPtr metadataPtr = null == metadata ? IntPtr.Zero : CreateMetadata(metadata); MATExterns.TuneShowBannerWithPosition(placement, metadataPtr, position); if(IntPtr.Zero != metadataPtr) { MATExterns.TuneRelease(metadataPtr); } #endif } }
public static void ShowBanner(string placement, MATAdMetadata metadata) { if (!Application.isEditor) { #if UNITY_ANDROID MATAndroid.Instance.ShowBanner(placement, metadata); #endif #if UNITY_IPHONE ShowBanner(placement, metadata, MATBannerPosition.BOTTOM_CENTER); #endif } }
// 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; }
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)); }
public void CacheInterstitial(string placement, MATAdMetadata metadata) { AndroidJavaObject objMetadata = GetAdMetadataJavaObject(metadata); ajcAlliances.Call("cacheInterstitial", placement, objMetadata); }
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; }
void OnGUI () { GUIStyle headingLabelStyle = new GUIStyle(); headingLabelStyle.fontStyle = FontStyle.Bold; headingLabelStyle.fontSize = 50; headingLabelStyle.alignment = TextAnchor.MiddleCenter; headingLabelStyle.normal.textColor = Color.white; float titleHeight = Screen.height / 10; GUI.Label(new Rect(10, topMargin, Screen.width - 20, titleHeight), "MAT Unity Test App", headingLabelStyle); GUI.skin.button.fontSize = 40; GUI.skin.verticalScrollbar.fixedWidth = Screen.width * 0.05f; GUI.skin.verticalScrollbarThumb.fixedWidth = Screen.width * 0.05f; float scrollViewContentHeight = (float)(numButtons * 0.125) * Screen.height; scrollPosition = GUI.BeginScrollView( new Rect(0.1f * Screen.width, 0.15f * Screen.height, Screen.width - 0.1f * Screen.width, Screen.height - 0.15f * Screen.height - topMargin - bottomMargin), scrollPosition, new Rect(0.1f * Screen.width, 0.15f * Screen.height, Screen.width - 0.1f * Screen.width, scrollViewContentHeight)); int buttonIndex = 0; float yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; Rect rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Start MAT SDK")) { print ("Start MAT SDK clicked"); MATBinding.Init(MAT_ADVERTISER_ID, MAT_CONVERSION_KEY); MATBinding.SetPackageName(MAT_PACKAGE_NAME); } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Set Delegate")) { print ("Set Delegate clicked"); #if (UNITY_ANDROID || UNITY_IPHONE) MATBinding.SetDelegate(true); #endif #if UNITY_METRO MATBinding.SetMATResponse(new SampleWinMATResponse()); #endif } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Show Banner")) { print ("Show Banner"); MATBinding.ShowBanner("place1"); } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Hide Banner")) { print ("Hide Banner"); MATBinding.HideBanner(); } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Destroy Banner")) { print ("Destroy Banner"); MATBinding.DestroyBanner(); } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Cache Interstitial")) { MATAdMetadata metadata = new MATAdMetadata(); metadata.setBirthDate(DateTime.Today.AddYears(-45)); metadata.setGender(MATAdGender.FEMALE); metadata.setLocation(120.8f, 234.5f, 579.6f); metadata.setDebugMode(true); HashSet<string> keywords = new HashSet<string>(); keywords.Add("pro"); keywords.Add("evening"); metadata.setKeywords(keywords); Dictionary<string, string> customTargets = new Dictionary<string, string>(); customTargets.Add("type", "game"); customTargets.Add("subtype1", "adventure"); customTargets.Add("subtype2", "action"); metadata.setCustomTargets(customTargets); MATBinding.CacheInterstitial("place1", metadata); } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Show Interstitial")) { print ("Show Interstitial"); MATBinding.ShowInterstitial("place1"); } ++buttonIndex; yPos = (float)(0.15f + buttonIndex * 0.125) * Screen.height; rect = new Rect(0.1f * Screen.width, yPos, 0.8f * Screen.width, 0.1f * Screen.height); if (GUI.Button(rect, "Destroy Interstitial")) { print ("Destroy Interstitial"); MATBinding.DestroyInterstitial(); } GUI.EndScrollView(); numButtons = buttonIndex + 1; // resize banner ad for current orientation MATBinding.LayoutBanner(); }