Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            string       ConfigFile = "config.lxm";
            LiteIDConfig Config     = LiteIDConfig.Load(ConfigFile);

            SetContentView(Resource.Layout.Options);
            Button   buttonGenerateAccount = FindViewById <Button>(Resource.Id.buttonGenerateAccount);
            Button   buttonResetID         = FindViewById <Button>(Resource.Id.buttonResetID);
            TextView textCurrentID         = FindViewById <TextView>(Resource.Id.textCurrentID);

            if (Config.Configured)
            {
                textCurrentID.Text = "0x" + LiteIDContext.BytesToHex(Config.BlockchainID);
            }
            else
            {
                textCurrentID.Text = "No ID - You must deploy a new contract.";
            }
            EditText textRPCAddress = FindViewById <EditText>(Resource.Id.textRPCAddress);
            Button   buttonSaveRPC  = FindViewById <Button>(Resource.Id.buttonSaveRPC);

            buttonGenerateAccount.Click += delegate
            {
                Toast.MakeText(this.ApplicationContext, "No connection; demo mode", ToastLength.Long).Show();
            };

            buttonResetID.Click += delegate
            {
                Config.BlockchainID = new byte[32];
                Random random = new Random();
                random.NextBytes(Config.BlockchainID);
                textCurrentID.Text = "0x" + LiteIDContext.BytesToHex(Config.BlockchainID);
                Config.Configured  = true;
                Config.Save(ConfigFile);
            };

            buttonSaveRPC.Click += delegate
            {
                Config.RPCAddress = textRPCAddress.Text;
                Config.Save(ConfigFile);
            };
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Context = new LiteIDContext();

            Uri PackedDocURI;

            if (Intent.HasExtra("PackedDocURI"))
            {
                PackedDocURI = (Uri)Intent.GetParcelableExtra("PackedDocURI");
            }
            else if (Intent.Data != null)
            {
                PackedDocURI = Intent.Data;
            }
            else
            {
                Android.Util.Log.Error("liteid-import", "No valid URI in intent!");
                Finish();
                return;
            }

            Stream PackedDocStream = ContentResolver.OpenInputStream(PackedDocURI);

            CurrentDoc = Document.ImportDocument(PackedDocStream);


            SetContentView(Resource.Layout.ImportDoc);
            TextView docTitle = FindViewById <TextView>(Resource.Id.docTitle);

            docTitle.Text = CurrentDoc.Name;
            TextView docDate = FindViewById <TextView>(Resource.Id.docDate);

            docDate.Text = "Added to blockchain on: " + CurrentDoc.IngestionTime.ToLongDateString();

            if (CurrentDoc.TextDoc)
            {
                LinearLayout modeText = FindViewById <LinearLayout>(Resource.Id.modeText);
                modeText.Visibility = ViewStates.Visible;
                TextView docContent = FindViewById <TextView>(Resource.Id.docContent);
                docContent.Text = CurrentDoc.GetTextContent();
            }
            else
            {
                LinearLayout modeFile = FindViewById <LinearLayout>(Resource.Id.modeFile);
                modeFile.Visibility = ViewStates.Visible;
                TextView docType = FindViewById <TextView>(Resource.Id.docType);
                docType.Text = "Type: " + CurrentDoc.MimeType;
                Button buttonOpen = FindViewById <Button>(Resource.Id.buttonOpen);

                buttonOpen.Click += delegate
                {
                    string       path       = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    string       filename   = Path.Combine(path, "import/" + CurrentDoc.ID);
                    Java.IO.File outfile    = new Java.IO.File(filename);
                    Uri          extURI     = FileProvider.GetUriForFile(ApplicationContext, "org.LiteID.fileprovider", outfile);
                    Intent       viewIntent = new Intent(Intent.ActionView);
                    viewIntent.SetDataAndType(extURI, CurrentDoc.MimeType);
                    viewIntent.AddFlags(ActivityFlags.NewTask);
                    viewIntent.SetFlags(ActivityFlags.GrantReadUriPermission);

                    if (viewIntent.ResolveActivity(ApplicationContext.PackageManager) != null)
                    {
                        StartActivity(viewIntent);
                    }
                    else
                    {
                        Toast.MakeText(this.ApplicationContext, "You don't have any apps that can open this.", ToastLength.Long).Show();
                    }
                };
            }

            TextView textOriginID = FindViewById <TextView>(Resource.Id.textOriginID);

            if (CurrentDoc.OriginID == Context.Config.BlockchainID)
            {
                textOriginID.Text = "0x" + LiteIDContext.BytesToHex(CurrentDoc.OriginID) + " (You)";
            }
            else
            {
                textOriginID.Text = "0x" + LiteIDContext.BytesToHex(CurrentDoc.OriginID);
            }

            Button buttonVerify  = FindViewById <Button>(Resource.Id.buttonVerify);
            Button buttonSave    = FindViewById <Button>(Resource.Id.buttonSave);
            Button buttonDiscard = FindViewById <Button>(Resource.Id.buttonDiscard);

            buttonVerify.Click += delegate
            {
                //TODO: Implement this
                Toast.MakeText(this.ApplicationContext, "Verified", ToastLength.Long).Show();
            };

            buttonSave.Click += delegate
            {
                string path        = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                string docImported = Path.Combine(path, "import/" + CurrentDoc.ID);
                string docFinal    = Path.Combine(path, CurrentDoc.ID);
                if (File.Exists(docFinal))
                {
                    Toast.MakeText(this.ApplicationContext, "You already have this document.", ToastLength.Long).Show();
                }
                else
                {
                    File.Move(docImported, docFinal);
                    Context.DocStore.Documents.Add(CurrentDoc);
                    Context.DocStore.SaveList(Context.DocStoreFile);
                }
                Finish();
            };

            buttonDiscard.Click += delegate
            {
                new AlertDialog.Builder(this)
                .SetIcon(Android.Resource.Drawable.IcDialogAlert)
                .SetTitle("Delete File")
                .SetMessage("Are you sure you want to discard this document? You can import it again later.")
                .SetPositiveButton("Yes", delegate
                {
                    string path     = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    string filename = Path.Combine(path, "import/" + CurrentDoc.ID);
                    File.Delete(filename);
                    Finish();
                })
                .SetNegativeButton("No", delegate { })
                .Show();
            };
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Context = new LiteIDContext();

            Document CurrentDoc;

            if (Intent.HasExtra("TargetID"))
            {
                string TargetID = Intent.GetStringExtra("TargetID");
                try
                {
                    CurrentDoc = Context.DocStore.GetDocumentById(TargetID);
                }
                catch
                {
                    Finish();
                    return;
                }
            }
            else
            {
                Finish();
                return;
            }

            SetContentView(Resource.Layout.ViewDoc);
            TextView docTitle = FindViewById <TextView>(Resource.Id.docTitle);

            docTitle.Text = CurrentDoc.Name;
            TextView docDate = FindViewById <TextView>(Resource.Id.docDate);

            docDate.Text = "Added on: " + CurrentDoc.IngestionTime.ToLongDateString();
            if (CurrentDoc.TextDoc)
            {
                LinearLayout modeText = FindViewById <LinearLayout>(Resource.Id.modeText);
                modeText.Visibility = ViewStates.Visible;
                TextView docContent = FindViewById <TextView>(Resource.Id.docContent);
                docContent.Text = CurrentDoc.GetTextContent();
            }
            else
            {
                LinearLayout modeFile = FindViewById <LinearLayout>(Resource.Id.modeFile);
                modeFile.Visibility = ViewStates.Visible;
                TextView docType = FindViewById <TextView>(Resource.Id.docType);
                docType.Text = "Type: " + CurrentDoc.MimeType;
                Button buttonOpen = FindViewById <Button>(Resource.Id.buttonOpen);

                buttonOpen.Click += delegate
                {
                    string       path       = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    string       filename   = Path.Combine(path, CurrentDoc.ID);
                    Java.IO.File outfile    = new Java.IO.File(filename);
                    Uri          extURI     = FileProvider.GetUriForFile(ApplicationContext, "org.LiteID.fileprovider", outfile);
                    Intent       viewIntent = new Intent(Intent.ActionView);
                    viewIntent.SetDataAndType(extURI, CurrentDoc.MimeType);
                    viewIntent.AddFlags(ActivityFlags.NewTask);
                    viewIntent.SetFlags(ActivityFlags.GrantReadUriPermission);

                    if (viewIntent.ResolveActivity(ApplicationContext.PackageManager) != null)
                    {
                        StartActivity(viewIntent);
                    }
                    else
                    {
                        Toast.MakeText(this.ApplicationContext, "You don't have any apps that can open this.", ToastLength.Long).Show();
                    }
                };
            }

            Button buttonExport = FindViewById <Button>(Resource.Id.buttonExport);
            Button buttonDelete = FindViewById <Button>(Resource.Id.buttonDelete);

            buttonExport.Click += delegate
            {
                System.Uri   PackedDoc   = CurrentDoc.ExportDocument();
                Java.IO.File outfile     = new Java.IO.File(PackedDoc.AbsolutePath);
                Uri          extURI      = FileProvider.GetUriForFile(ApplicationContext, "org.LiteID.fileprovider", outfile);
                Intent       emailIntent = new Intent(Intent.ActionSend);
                emailIntent.SetType("application/octet-stream");
                emailIntent.PutExtra(Intent.ExtraSubject, "LiteID Document");
                emailIntent.PutExtra(Intent.ExtraText, "Attached is a verifiable LiteID document.");
                emailIntent.PutExtra(Intent.ExtraStream, extURI);
                emailIntent.AddFlags(ActivityFlags.NewTask);
                emailIntent.SetFlags(ActivityFlags.GrantReadUriPermission);

                if (emailIntent.ResolveActivity(ApplicationContext.PackageManager) != null)
                {
                    IList <ResolveInfo> resInfoList = ApplicationContext.PackageManager.QueryIntentActivities(emailIntent, PackageInfoFlags.MatchDefaultOnly);
                    foreach (ResolveInfo resolveInfo in resInfoList)
                    {
                        string packageName = resolveInfo.ActivityInfo.PackageName;
                        ApplicationContext.GrantUriPermission(packageName, extURI, ActivityFlags.GrantReadUriPermission);
                    }
                    StartActivity(Intent.CreateChooser(emailIntent, "Share Document"));
                }
                else
                {
                    Toast.MakeText(this.ApplicationContext, "You don't have any apps that can share this.", ToastLength.Long).Show();
                }
            };

            buttonDelete.Click += delegate
            {
                new AlertDialog.Builder(this)
                .SetIcon(Android.Resource.Drawable.IcDialogAlert)
                .SetTitle("Delete File")
                .SetMessage("Are you sure you want to permanently delete this document?")
                .SetPositiveButton("Yes", delegate
                {
                    string path     = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    string filename = Path.Combine(path, CurrentDoc.ID);
                    File.Delete(filename);
                    Context.DocStore.Documents.Remove(CurrentDoc);
                    Context.DocStore.SaveList(Context.DocStoreFile);
                    Finish();
                })
                .SetNegativeButton("No", delegate { })
                .Show();
            };

            if (CurrentDoc.OriginID == null || !CurrentDoc.OriginID.SequenceEqual(Context.Config.BlockchainID))
            {
                LinearLayout modeRemote   = FindViewById <LinearLayout>(Resource.Id.modeRemote);
                TextView     textOriginID = FindViewById <TextView>(Resource.Id.textOriginID);
                Button       buttonVerify = FindViewById <Button>(Resource.Id.buttonVerify);

                modeRemote.Visibility = ViewStates.Visible;
                if (CurrentDoc.OriginID != null)
                {
                    textOriginID.Text = "0x" + LiteIDContext.BytesToHex(CurrentDoc.OriginID);
                }
                else
                {
                    textOriginID.Text       = "Local Document";
                    buttonVerify.Visibility = ViewStates.Gone;
                }

                buttonVerify.Click += delegate
                {
                    //TODO: Implement this
                    Toast.MakeText(this.ApplicationContext, "Verified", ToastLength.Long).Show();
                };
            }
        }