1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-03 09:03:35 +00:00

mobile platform utils

This commit is contained in:
Kyle Spearrin
2019-04-09 23:24:03 -04:00
parent 36780c5ef8
commit 9e51c46522
11 changed files with 257 additions and 52 deletions

View File

@@ -49,6 +49,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Plugin.CurrentActivity">
<Version>2.1.0.4</Version>
</PackageReference>
<PackageReference Include="Portable.BouncyCastle">
<Version>1.8.5</Version>
</PackageReference>
@@ -76,6 +79,7 @@
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\CryptoPrimitiveService.cs" />
<Compile Include="Services\DeviceActionService.cs" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\FontAwesome.ttf" />

View File

@@ -15,5 +15,11 @@ namespace Bit.Droid
public MainApplication(IntPtr handle, JniHandleOwnership transer)
: base(handle, transer)
{ }
public override void OnCreate()
{
base.OnCreate();
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this);
}
}
}

View File

@@ -0,0 +1,35 @@
using Bit.App.Abstractions;
using Plugin.CurrentActivity;
namespace Bit.Droid.Services
{
public class DeviceActionService : IDeviceActionService
{
private Android.Widget.Toast _toast;
public void Toast(string text, bool longDuration = false)
{
if(_toast != null)
{
_toast.Cancel();
_toast.Dispose();
_toast = null;
}
_toast = Android.Widget.Toast.MakeText(CrossCurrentActivity.Current.Activity, text,
longDuration ? Android.Widget.ToastLength.Long : Android.Widget.ToastLength.Short);
_toast.Show();
}
public bool LaunchApp(string appName)
{
var activity = CrossCurrentActivity.Current.Activity;
appName = appName.Replace("androidapp://", string.Empty);
var launchIntent = activity.PackageManager.GetLaunchIntentForPackage(appName);
if(launchIntent != null)
{
activity.StartActivity(launchIntent);
}
return launchIntent != null;
}
}
}