Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Context = new LiteIDContext();

            SetContentView(Resource.Layout.Main);
            ImageButton bOpt = FindViewById <ImageButton>(Resource.Id.buttonOptions);
            ImageButton bAdd = FindViewById <ImageButton>(Resource.Id.buttonAdd);

            ListView doclistView = FindViewById <ListView>(Resource.Id.docList);

            doclistAdapter         = new DocListAdapter(this, Context.DocStore);
            doclistView.Adapter    = doclistAdapter;
            doclistView.ItemClick += delegate(object sender, ItemClickEventArgs e)
            {
                Intent docView = new Intent(this, typeof(ViewDoc));
                docView.PutExtra("TargetID", Context.DocStore.Documents[e.Position].ID);
                StartActivity(docView);
            };
            UpdateList();

            bOpt.Click += delegate
            {
                StartActivity(typeof(Options));
            };

            bAdd.Click += delegate
            {
                StartActivity(typeof(AddDoc));
            };
        }
Example #2
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);
            };
        }
Example #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Context = new LiteIDContext();
            if (!Context.Config.Configured)
            {
                Toast.MakeText(this.ApplicationContext, "You must set up your ID.", ToastLength.Long).Show();
                Finish();
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M &&
                CheckSelfPermission(Manifest.Permission.ReadExternalStorage) != Android.Content.PM.Permission.Granted)
            {
                RequestPermissions(new String[] { Manifest.Permission.ReadExternalStorage }, 1);
            }

            SetContentView(Resource.Layout.AddDoc);
            EditText    textTitle     = FindViewById <EditText>(Resource.Id.textTitle);
            RadioButton radioFile     = FindViewById <RadioButton>(Resource.Id.radioFile);
            Button      buttonFile    = FindViewById <Button>(Resource.Id.buttonFile);
            RadioButton radioText     = FindViewById <RadioButton>(Resource.Id.radioText);
            EditText    textContent   = FindViewById <EditText>(Resource.Id.textContent);
            Button      buttonCreate  = FindViewById <Button>(Resource.Id.buttonCreate);
            Button      buttonDiscard = FindViewById <Button>(Resource.Id.buttonDiscard);

            radioFile.Click += delegate
            {
                radioText.Checked = false;
            };

            buttonFile.Click += delegate
            {
                radioFile.Checked = true;
                radioText.Checked = false;
                PackageManager pm = ApplicationContext.PackageManager;
                Intent         getFileIntent;
                getFileIntent = new Intent(Intent.ActionGetContent);
                getFileIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
                getFileIntent.SetType("*/*");
                getFileIntent.PutExtra(Intent.ExtraLocalOnly, true);
                if (getFileIntent.ResolveActivity(pm) != null)
                {
                    StartActivityForResult(getFileIntent, 1);
                }
                else
                {
                    Toast.MakeText(this.ApplicationContext, "There are no file browsers!", ToastLength.Long).Show();
                }
            };

            radioText.Click += delegate
            {
                radioFile.Checked = false;
            };

            textContent.Click += delegate
            {
                radioFile.Checked = false;
                radioText.Checked = true;
            };

            buttonCreate.Click += delegate
            {
                if (textTitle.Text != "")
                {
                    if (radioFile.Checked && newFileUri != null)
                    {
                        Document newDoc = Document.IngestDocument(ContentResolver.OpenInputStream(newFileUri), newMimeType);
                        newDoc.Name     = textTitle.Text;
                        newDoc.OriginID = Context.Config.BlockchainID;
                        Context.DocStore.Documents.Add(newDoc);
                        Context.DocStore.SaveList("documents.lxm");
                        Finish();
                    }
                    else if (radioText.Checked && textContent.Text != "")
                    {
                        Document newDoc = Document.IngestDocument(textContent.Text);
                        newDoc.Name     = textTitle.Text;
                        newDoc.OriginID = Context.Config.BlockchainID;
                        Context.DocStore.Documents.Add(newDoc);
                        Context.DocStore.SaveList("documents.lxm");
                        Finish();
                    }
                    else
                    {
                        Toast.MakeText(this.ApplicationContext, "You must set the content", ToastLength.Long).Show();
                    }
                }
                else
                {
                    Toast.MakeText(this.ApplicationContext, "You must set a title", ToastLength.Long).Show();
                }
            };

            buttonDiscard.Click += delegate
            {
                Finish();
            };

            if (Intent.HasExtra(Intent.ExtraText))
            {
                radioFile.Checked = false;
                radioText.Checked = true;
                textContent.Text  = Intent.GetStringExtra(Intent.ExtraText);
            }
            else if (Intent.Data != null)
            {
                OnActivityResult(1, Result.Ok, Intent);
            }
        }
Example #4
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();
            };
        }
Example #5
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();
                };
            }
        }