private async Task <Bitmap> DecodeCustomIcon(CustomIcon customIcon) { if (_decodedCustomIcons.TryGetValue(customIcon.Id, out var bitmap)) { return(bitmap); } await _customIconDecodeLock.WaitAsync(); try { if (_decodedCustomIcons.TryGetValue(customIcon.Id, out bitmap)) { return(bitmap); } bitmap = await BitmapFactory.DecodeByteArrayAsync(customIcon.Data, 0, customIcon.Data.Length); _decodedCustomIcons.Add(customIcon.Id, bitmap); return(bitmap); } finally { _customIconDecodeLock.Release(); } }
public async Task SetCustomIconAsync(Authenticator auth, CustomIcon icon) { if (icon == null) { throw new ArgumentException("Icon cannot be null"); } var iconId = CustomIcon.Prefix + icon.Id; if (auth.Icon == iconId) { return; } await _customIconService.AddIfNotExists(icon); auth.Icon = iconId; try { await _authenticatorRepository.UpdateAsync(auth); } catch { await _customIconRepository.DeleteAsync(icon); throw; } await _customIconService.CullUnused(); }
public async Task AddIfNotExists(CustomIcon icon) { var existing = await _customIconRepository.GetAsync(icon.Id); if (existing == null) { await _customIconRepository.CreateAsync(icon); } }
public Task CreateAsync(CustomIcon item) { if (_customIcons.Any(a => a.Id == item.Id)) { throw new EntityDuplicateException(); } _customIcons.Add(item.Clone()); return(Task.CompletedTask); }
public Task DeleteAsync(CustomIcon item) { var index = _customIcons.FindIndex(a => a.Id == item.Id); if (index >= 0) { _customIcons.RemoveAt(index); } return(Task.CompletedTask); }
public Task UpdateAsync(CustomIcon item) { var index = _customIcons.FindIndex(a => a.Id == item.Id); if (index >= 0) { _customIcons[index] = item.Clone(); } return(Task.CompletedTask); }
public async Task Add(CustomIcon icon) { if (Exists(icon.Id)) { throw new ArgumentException("Custom icon already exists"); } await _connection.InsertAsync(icon); await Update(); }
private async Task SetCustomIcon(Uri uri) { MemoryStream memoryStream = null; Stream stream = null; CustomIcon icon; try { stream = ContentResolver.OpenInputStream(uri); memoryStream = new MemoryStream(); await stream.CopyToAsync(memoryStream); var fileData = memoryStream.ToArray(); icon = await CustomIcon.FromBytes(fileData); } catch (Exception) { ShowSnackbar(Resource.String.filePickError, Snackbar.LengthShort); return; } finally { memoryStream?.Close(); stream?.Close(); } var auth = _authSource.Get(_customIconApplyPosition); if (auth == null || auth.Icon == CustomIcon.Prefix + icon.Id) { return; } if (!_customIconSource.IsDuplicate(icon.Id)) { await _connection.InsertAsync(icon); } await TryCleanupCustomIcon(auth.Icon); auth.Icon = CustomIcon.Prefix + icon.Id; await _connection.UpdateAsync(auth); await _customIconSource.Update(); RunOnUiThread(() => { _authListAdapter.NotifyItemChanged(_customIconApplyPosition); }); await NotifyWearAppOfChange(); }
public override async Task <Backup> Convert(byte[] data, string password = null) { var json = Encoding.UTF8.GetString(data); var backup = JsonConvert.DeserializeObject <AegisBackup>(json); if (backup.Version != 1) { throw new NotSupportedException("Unsupported backup version"); } var authenticators = backup.Database.Entries.Select(entry => entry.Convert()).ToList(); var categories = new List <Category>(); var bindings = new List <AuthenticatorCategory>(); var icons = new List <CustomIcon>(); for (var i = 0; i < backup.Database.Entries.Count; i++) { var entry = backup.Database.Entries[i]; var auth = authenticators[i]; if (!String.IsNullOrEmpty(entry.Group)) { var category = categories.FirstOrDefault(c => c.Name == entry.Group); if (category == null) { category = new Category(entry.Group); categories.Add(category); } var binding = new AuthenticatorCategory(auth.Secret, category.Id); bindings.Add(binding); } if (entry.Icon != null) { var newIcon = await CustomIcon.FromBytes(entry.Icon); var icon = icons.FirstOrDefault(ic => ic.Id == newIcon.Id); if (icon == null) { icon = newIcon; icons.Add(newIcon); } auth.Icon = CustomIcon.Prefix + icon.Id; } } return(new Backup(authenticators, categories, bindings, icons)); }
/// <summary> /// Exports the location as an url encoded string /// </summary> /// <returns>Url encoded string of the location</returns> public override string ToString() { string ReturnValue = "markers=size:" + Size.ToString().ToLower() + (Color.IsNullOrEmpty() ? "" : "|color:" + Color) + (Label.IsNullOrEmpty() ? "" : "|label:" + Label.ToUpper()) + (CustomIcon.IsNull() ? "" : ("|icon:" + CustomIcon + "|shadow:" + CustomIconShadow.ToString().ToLower())); foreach (ILocation Marker in MarkerList) { ReturnValue += "|" + Marker.ToString(); } return(ReturnValue); }
public CustomIconButton(CustomIcon icon, Color c) { Width = Settings.TextFont.Height + Settings.OutlineThickness * 2; Height = Width; Icon = icon; ForeColor = c; Render(); BackgroundImage = Default; BackgroundImageLayout = ImageLayout.Center; Margin = new Padding(Settings.SpacerThickness, 0, Settings.SpacerThickness, 0); MouseEnter += EnterCallback; MouseLeave += LeaveCallback; MouseDown += DownCallback; MouseUp += EnterCallback; }
private async void CreateNewShortcut(object sender, EventArgs args) { var icon = ResolveEmbeddedIcon(IconTypePicker.SelectedItem.ToString()); if (!string.IsNullOrWhiteSpace(CustomIconEntry.Text)) { icon = new CustomIcon(CustomIconEntry.Text); } _shortcut.Label = TitleEntry.Text; _shortcut.Description = SubtitleEntry.Text; _shortcut.Icon = icon; _shortcut.Uri = $"stc://{nameof(AppShortcutsTests)}/{nameof(AddShortcutPage)}/{_shortcut.ShortcutId}"; await CrossAppShortcuts.Current.AddShortcut(_shortcut); Navigation.PopAsync(); }
public async Task DeleteAsync(CustomIcon item) { var conn = await _database.GetConnection(); await conn.DeleteAsync(item); }
public async Task CreateAsync(CustomIcon item) { var conn = await _database.GetConnection(); await conn.InsertAsync(item); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { try { foreach (string path in importedAssets) { string guid = AssetDatabase.AssetPathToGUID(path); Texture2D icon = null; CustomIcon.m_guidToIcon.TryGetValue(guid, out icon); if (icon == null) { if (path.EndsWith("mat")) { Material mat = AssetDatabase.LoadAssetAtPath <Material>(path); if (mat != null) { if (mat.shader.name.ToLower().Contains("daydream")) { IconCache.IconEntry entry = CustomIcon.Cache.Find(guid); if (entry == null) { entry = new IconCache.IconEntry(); // add to cache CustomIcon.Cache.m_iconList.Add(entry); } CustomIcon.BuildIcon(mat, ref entry.m_icon); entry.m_dirty = true; entry.m_guid = guid; if (CustomIcon.m_guidToIcon.ContainsKey(guid)) { // update dictionary CustomIcon.m_guidToIcon[guid] = entry.m_icon; } else { // add to dictionary CustomIcon.m_guidToIcon.Add(guid, entry.m_icon); } } } } } } foreach (string path in deletedAssets) { string guid = AssetDatabase.AssetPathToGUID(path); Texture2D icon = null; CustomIcon.m_guidToIcon.TryGetValue(guid, out icon); if (icon != null) { CustomIcon.m_guidToIcon.Remove(guid); Object.DestroyImmediate(icon); } IconCache.IconEntry entry = CustomIcon.Cache.Find(guid); if (entry != null) { if (entry.m_icon != null) { Object.DestroyImmediate(entry.m_icon); } CustomIcon.Cache.m_iconList.Remove(entry); entry.Remove(); } } for (int i = 0; i < movedAssets.Length; i++) { //Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]); string oldGuid = AssetDatabase.AssetPathToGUID(movedFromAssetPaths[i]); string newGuid = AssetDatabase.AssetPathToGUID(movedAssets[i]); Texture2D icon = null; CustomIcon.m_guidToIcon.TryGetValue(oldGuid, out icon); if (icon != null) { CustomIcon.m_guidToIcon.Add(newGuid, icon); CustomIcon.m_guidToIcon.Remove(newGuid); } IconCache.IconEntry entry = CustomIcon.Cache.Find(oldGuid); if (entry != null) { // remove current entry.Remove(); // update to new guild entry.m_guid = newGuid; entry.m_dirty = true; } } } finally { CustomIcon.Cache.Serialize(); } }