public void JavaCast_BaseToGenericWrapper()
 {
     using (var list = new JavaList(new[] { 1, 2, 3 }))
         using (var generic = JavaObjectExtensions.JavaCast <JavaList <int> > (list)) {
             // Yay, no exceptions!
             Assert.AreEqual(1, generic [0]);
         }
 }
Beispiel #2
0
 protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] native_parms)
 {
     TParams[] parms = new TParams[native_parms.Length];
     for (int i = 0; i < parms.Length; i++)
     {
         parms [i] = JavaConvert.FromJavaObject <TParams>(native_parms [i]);
     }
     return(JavaObjectExtensions.JavaCast <Java.Lang.Object>(JavaConvert.ToJavaObject(RunInBackground(parms))));
 }
Beispiel #3
0
 protected void PublishProgress(params TProgress[] values)
 {
     Java.Lang.Object[] native_values = new Java.Lang.Object [values.Length];
     for (int i = 0; i < values.Length; i++)
     {
         native_values [i] = JavaObjectExtensions.JavaCast <Java.Lang.Object>(JavaConvert.ToJavaObject(values [i]));
     }
     base.PublishProgress(native_values);
 }
Beispiel #4
0
        protected override Java.Lang.Object? DoInBackground(params Java.Lang.Object[]? native_parms)
        {
            TParams[] parms = new TParams[native_parms?.Length ?? 0];
            for (int i = 0; i < parms.Length; i++)
#pragma warning disable CS8601 // Possible null reference assignment.
            {
                parms [i] = JavaConvert.FromJavaObject <TParams>(native_parms? [i]);
            }
#pragma warning restore CS8601 // Possible null reference assignment.
            return(JavaObjectExtensions.JavaCast <Java.Lang.Object>(JavaConvert.ToJavaObject(RunInBackground(parms))));
        }
Beispiel #5
0
        protected void PublishProgress(params TProgress[] values)
        {
            Java.Lang.Object[] native_values = new Java.Lang.Object [values.Length];
            for (int i = 0; i < values.Length; i++)
#pragma warning disable CS8601 // Possible null reference assignment.
            {
                native_values [i] = JavaObjectExtensions.JavaCast <Java.Lang.Object>(JavaConvert.ToJavaObject(values [i]));
            }
#pragma warning restore CS8601 // Possible null reference assignment.
            base.PublishProgress(native_values);
        }
Beispiel #6
0
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i)))
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(MessagePath));

            if (dataEvent == null)
            {
                return;
            }

            //do stuffs here
        }
Beispiel #7
0
        public override void OnNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type)
        {
            base.OnNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type);
            var fabChild = JavaObjectExtensions.JavaCast <FloatingActionButton>(child);

            if (dyConsumed > 0 && fabChild.Visibility == ViewStates.Visible)
            {
                fabChild.Hide(new CustomOnVisibilityChangedListener());
            }
            else if (dyConsumed < 0 && fabChild.Visibility != ViewStates.Visible)
            {
                fabChild.Show();
            }
        }
        public void JavaCast_InterfaceCast()
        {
            IntPtr g;

            using (var n = new Java.Lang.Integer(42)) {
                g = JNIEnv.NewGlobalRef(n.Handle);
            }
            // We want a Java.Lang.Object so that we create an IComparableInvoker
            // instead of just getting back the original instance.
            using (var o = Java.Lang.Object.GetObject <Java.Lang.Object> (g, JniHandleOwnership.TransferGlobalRef)) {
                var c = JavaObjectExtensions.JavaCast <Java.Lang.IComparable> (o);
                c.Dispose();
            }
        }
Beispiel #9
0
 private LayoutInflaterFactoryWrapper(LayoutInflater inflater, IViewFactory viewFactory)
 {
     Should.NotBeNull(inflater, nameof(inflater));
     Should.NotBeNull(viewFactory, nameof(viewFactory));
     _viewFactory = viewFactory;
     _factory     = inflater.Factory;
     if (Factory2Field != null)
     {
         _factory2 = inflater.Factory2;
     }
     if (PrivateFactoryField != null)
     {
         _privateFactory = JavaObjectExtensions.JavaCast <LayoutInflater.IFactory2>(PrivateFactoryField.Get(inflater));
     }
 }
Beispiel #10
0
        /// <summary>
        /// Receives data from handheld; this isn't really used, but is handy for connection tests and such
        /// </summary>
        /// <param name="dataEvents"></param>
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            debugLog("Data changed");
            dataStatusHandler.updateStatus("Data changed");
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i)))
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(TestDataPath));

            if (dataEvent == null)
            {
                return;
            }
            else
            {
                var    dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
                var    map         = dataMapItem.DataMap;
                string message     = dataMapItem.DataMap.GetString("Message");
                debugLog("Test data actually received! message: " + message);
            }
        }
        public void OnResult(Java.Lang.Object result)
        {
            var ar = JavaObjectExtensions.JavaCast <IAchievementsLoadAchievementsResult>(result);
            var waveAchievements = new List <WaveEngine.Social.Achievement>();

            if (ar != null)
            {
                var achievements = new List <IAchievement>();

                achievements.Clear();
                var count = ar.Achievements.Count;
                for (int i = 0; i < count; i++)
                {
                    var item = ar.Achievements.Get(i);
                    var a    = JavaObjectExtensions.JavaCast <IAchievement>(item);
                    achievements.Add(a);
                }

                waveAchievements = AndroidMapper.MapAchievements(achievements);
            }

            this.tcs.TrySetResult(waveAchievements);
        }
        public void OnResult(Java.Lang.Object result)
        {
            var ar         = JavaObjectExtensions.JavaCast <ILeaderboardsLoadScoresResult>(result);
            var waveScores = new List <WaveEngine.Social.LeaderboardScore>();

            if (ar != null)
            {
                var id = ar.Leaderboard.LeaderboardId;

                var scores = new List <ILeaderboardScore>();
                var count  = ar.Scores.Count;
                for (int i = 0; i < count; i++)
                {
                    var item = ar.Scores.Get(i);

                    var score = JavaObjectExtensions.JavaCast <ILeaderboardScore>(item);
                    scores.Add(score);
                }

                waveScores = AndroidMapper.MapLeaderBoards(scores);
            }

            this.tcs.TrySetResult(waveScores);
        }
 public void JavaCast_CheckForManagedSubclasses()
 {
     using (var o = CreateObject()) {
         Assert.Throws <InvalidCastException> (() => JavaObjectExtensions.JavaCast <MyObject> (o));
     }
 }
 public void JavaCast_InvalidTypeCastThrows()
 {
     using (var s = new Java.Lang.String("value")) {
         Assert.Throws <InvalidCastException> (() => JavaObjectExtensions.JavaCast <Java.Lang.Integer> (s));
     }
 }
Beispiel #15
0
 protected virtual void OnPostExecute([AllowNull] TResult result)
 {
     base.OnPostExecute(JavaObjectExtensions.JavaCast <Java.Lang.Object>(JavaConvert.ToJavaObject(result)));
 }
Beispiel #16
0
        public void OnSuccess(Object result)
        {
            var c = HandleSuccess;

            c?.Invoke(JavaObjectExtensions.JavaCast <TResult>(result));
        }
Beispiel #17
0
 public override Java.Lang.Object? GetItem(int position)
 {
     return(JavaObjectExtensions.JavaCast <Java.Lang.Object>(JavaConvert.ToJavaObject(this [position])));
 }