protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Name = Intent.Extras.GetString("name"); Address = Intent.Extras.GetString("address"); Title = $"{Name} ({Address})"; ScreenImageView = new ZoomableImageView(this, () => BitmapFactory.DecodeResource(Resources, Resource.Drawable.Preparing)); SetContentView(ScreenImageView); Api = new ApiClient(Address); try { RefreshAsync(); } catch (Exception e) { Log.Error(TAG, $"Failed to start activity with error {e}."); Toast.MakeText(this, $"Failed to connect to {Title}", ToastLength.Short).Show(); Finish(); } // Option menu setup. Options.AddItem("Refresh", () => { try { RefreshAsync(); } catch (Exception e) { Log.Error(TAG, $"Failed to refresh with error {e}."); Toast.MakeText(this, $"Failed to refresh.", ToastLength.Short).Show(); } }); }
private void LoadOption(Options.OptionList O, CONF.XmlLoad Base, CONF.XmlLoad X) { var I = new Options.OptionListItem(Base.GetAttribute("label")); I.Default = (Base.GetAttribute("default") != null); while (X.Read()) { switch (X.ElementName) { case "value": string N = X.GetAttribute("name"); string V = X.GetAttribute("val"); if(N != null) I.setString(N, V); break; } } X.Close(); O.AddItem(I); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Id = Intent.Extras.GetInt("id"); Name = Intent.Extras.GetString("name"); Address = Intent.Extras.GetString("address"); Title = $"{Name} ({Address})"; SetContentView(Resource.Layout.FileBrowser); FileListView = FindViewById <ListView>(Resource.Id.FileBrowserListView); FileListView.Adapter = new ActivityListAdapter(this); Api = new ApiClient(Address); // Register long press FileListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { try { var item = Adapter.GetItem(e.Position) as ActivityListItem; if (item == null) { return; } var entry = (Entry)item.Tag; if (CanClick(entry.Type)) { RenderDirectory(entry.Path); } } catch (Exception er) { Toast.MakeText(this, $"Failed to enter directory.", ToastLength.Short).Show(); Log.Error(TAG, $"Failed to enter directory with error {er}."); } }; // Context menu setup. RegisterForContextMenu(FileListView); ListViewMenuItems.Add(new ListViewMenuItem { Title = "Run", ValidTypes = new EntryType[] { EntryType.File }, Action = async i => { var entry = (Entry)i.Tag; await Api.Call <Api.Responses.RunFile>(new Api.Requests.RunFile(entry.Path, null), Canceller.Token); } }); // Option menu setup. Options.AddItem("Refresh", () => { RenderLastSuccessfulPath(); }); Options.AddItem("Drives", () => { RenderDrives(); }); try { RenderLastSuccessfulPath(); } catch (Exception e) { Toast.MakeText(this, $"Failed to browse files on {Title}.", ToastLength.Short).Show(); Log.Error(TAG, $"Failed to start activity with error {e}."); Finish(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); // Initialise the ListView content. MainListView = FindViewById <ListView>(Resource.Id.MainListView); MainListView.Adapter = new ActivityListAdapter(this); MainListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { var item = Adapter.GetItem(e.Position) as ActivityListItem; if (item == null) { return; } var server = (Server)item.Tag; // Add the ListViewItem to the Saved list. SaveServer(server); // Update ListView in case that an image has changed. UpdateListItem(item, server); Adapter.NotifyDataSetChanged(); // Send a ping for diagnostic purposes. new ApiClient(server.Address).Call <Api.Responses.Ping>(new Api.Requests.Ping($"HookshotMagic@{DateTime.Now}"), Canceller.Token) .ContinueWith(t => { if (t.IsCompleted) { Log.Info(TAG, t.Result.msg); } else { Log.Warn(TAG, $"Failed to ping {server.Address}"); } }); // Start the ServerActivity to display it. StartActivity(new Intent(this, typeof(ServerActivity)) .PutExtra("id", server.DbId.Value) .PutExtra("address", server.Address) .PutExtra("name", server.Name)); }; // Initialise item discovery. Client.Discovered += (DiscoveryClient.DiscoveredArgs args) => { RunOnUiThread(() => OnDiscovered(args)); }; Client.Run(); // Add in saved servers to ListView. foreach (var i in LoadSavedServers()) { AddToListView(i); } // Context menu setup. RegisterForContextMenu(MainListView); ListViewMenuItems.AddRange(new ListViewMenuItem[] { new ListViewMenuItem { Title = "Edit", Action = item => { ShowServerEditor((Server)item.Tag); } }, new ListViewMenuItem { Title = "Delete", Action = item => { var server = (Server)item.Tag; new Db().DeleteServer(server.ToServer()); Adapter.Items.Remove(item); Adapter.Items.Sort(Comparer); Adapter.NotifyDataSetChanged(); } }, }); // Option menu setup. Options.AddItem("Add", () => { ShowServerEditor(null); }); }