public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { if (!Settings.IsFireTV()) { Console.WriteLine("Not starting KFTV Watcher Service, not FireTV..."); return(StartCommandResult.NotSticky); } if (timer == null) { activityManager = ActivityManager.FromContext(this); timer = new Timer(state => { if (Settings.Instance.DisableHomeDetection) { Console.WriteLine("Disabled Home Detection... Not starting KFTV Watcher Service..."); return; } // Gets the topmost running task var topTask = activityManager.GetRunningTasks(1).FirstOrDefault(); if (topTask == null || topTask.TopActivity == null) { return; } // We can detect that the firetv home launcher was called // by simply getting the top task's top activity and matching the // package name and class name // Package Name: com.amazon.tv.launcher // Class Name: com.amazon.tv.launcher.ui.HomeActivity if (topTask.TopActivity.PackageName == Settings.HOME_PACKAGE_NAME && topTask.TopActivity.ClassName == Settings.HOME_CLASS_NAME) { var actedAgo = DateTime.UtcNow - acted; // Just to be safe, we don't want to call this multiple times in a row // Also there's a static flag that the firedtv app can set // to allow the user to launch the firetv homescreen if (actedAgo > TimeSpan.FromMilliseconds(500) && !AllowFireTVHome) { //Come back to papa var actIntent = new Intent(ApplicationContext, typeof(MainActivity)); actIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop); StartActivity(actIntent); // Set the flag acted = DateTime.UtcNow; } } else { // It wasn't a match (another task is top) so reset the flag acted = DateTime.MinValue; } }, null, Settings.Instance.HomeDetectIntervalMs, Settings.Instance.HomeDetectIntervalMs); } return(StartCommandResult.Sticky); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Console.WriteLine("Is Amazon FireTV: " + Settings.IsFireTV()); RequestWindowFeature(WindowFeatures.NoTitle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); textDate = FindViewById <TextView> (Resource.Id.textViewDate); textTime = FindViewById <TextView> (Resource.Id.textViewTime); gridView = FindViewById <GridView> (Resource.Id.gridView); frameTopBar = FindViewById <FrameLayout> (Resource.Id.frameTopBar); wallpaper = FindViewById <ImageView> (Resource.Id.imageWallpaper); StartService(new Intent(this, typeof(ExcuseMeService))); adapter = new AppsAdapter() { Context = this }; gridViewTopPadding = gridView.PaddingTop; gridView.ItemClick += (sender, e) => { var app = adapter[e.Position]; // If we're launching home, tell the service that checks // for intercepting this that it's ok if (app.PackageName == Settings.HOME_PACKAGE_NAME) { ExcuseMeService.AllowFireTVHome = true; } if (app.PackageName == "APP_SETTINGS") { StartActivity(typeof(SettingsActivity)); return; } StartActivity(app.LaunchIntent); if (app.PackageName == Android.Provider.Settings.ActionSettings) { Toast.MakeText(this, "You may need to press 'UP' on your remote", ToastLength.Long).Show(); } }; gridView.Adapter = adapter; timerUpdate = new Timer(state => Setup(true), null, Timeout.Infinite, Timeout.Infinite); RegisterForContextMenu(gridView); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Console.WriteLine("Is Amazon FireTV: " + Settings.IsFireTV()); RequestWindowFeature(WindowFeatures.NoTitle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); textDate = FindViewById <TextView> (Resource.Id.textViewDate); textTime = FindViewById <TextView> (Resource.Id.textViewTime); imageLogo = FindViewById <ImageView> (Resource.Id.imageViewLogo); dividerLine = FindViewById <View> (Resource.Id.dividerLine); imageLogo.SetImageResource(Resource.Drawable.firedtv); gridView = FindViewById <GridView> (Resource.Id.gridView); StartService(new Intent(this, typeof(ExcuseMeService))); adapter = new AppsAdapter() { Context = this }; gridView.ItemClick += (sender, e) => { var app = adapter[e.Position]; // If we're launching home, tell the service that checks // for intercepting this that it's ok if (app.PackageName == Settings.HOME_PACKAGE_NAME) { ExcuseMeService.AllowFireTVHome = true; } StartActivity(app.LaunchIntent); }; gridView.Adapter = adapter; timerUpdate = new Timer(state => Setup(), null, Timeout.Infinite, Timeout.Infinite); RegisterForContextMenu(gridView); }
protected override void OnHandleIntent(Intent intent) { if (Settings.Instance.DisableHomeDetection) { Console.WriteLine("Disabled Home Detection... Not starting KFTV Watcher Service..."); return; } if (!Settings.IsFireTV()) { Console.WriteLine("Not starting KFTV Watcher Service, not FireTV..."); return; } if (timer == null) { activityManager = ActivityManager.FromContext(this); timer = new Timer(state => { if (Settings.Instance.DisableHomeDetection) { timer.Change(Timeout.Infinite, Timeout.Infinite); timer = null; return; } // Gets the topmost running task var topTask = activityManager.GetRunningTasks(1).FirstOrDefault(); if (topTask == null || topTask.TopActivity == null) { return; } // We can detect that the firetv home launcher was called // by simply getting the top task's top activity and matching the // package name and class name // Package Name: com.amazon.tv.launcher // Class Name: com.amazon.tv.launcher.ui.HomeActivity if (topTask.TopActivity.PackageName == Settings.HOME_PACKAGE_NAME && topTask.TopActivity.ClassName == Settings.HOME_CLASS_NAME) { // Just to be safe, we don't want to call this multiple times in a row // Also there's a static flag that the firedtv app can set // to allow the user to launch the firetv homescreen if (!didAct && !AllowFireTVHome) { //Come back to papa var actIntent = new Intent(ApplicationContext, typeof(MainActivity)); actIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop); StartActivity(actIntent); // Set the flag didAct = true; } } else { // It wasn't a match (another task is top) so reset the flag didAct = false; } }, null, Settings.Instance.HomeDetectIntervalMs, Settings.Instance.HomeDetectIntervalMs); } }