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

            // This line still included, because looking it up proved a right pain in the butt.  To clear the SimpleStorage contents out entirely, this should do:
            // Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(ApplicationContext).Edit().Clear().Apply();

            InitializeAll();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            _nfcText   = FindViewById <TextView>(Resource.Id.nfc_text);
            _nfcStatus = FindViewById <TextView>(Resource.Id.nfc_status);

            _nfcAdapter = NfcAdapter.GetDefaultAdapter(this);

            _writeTagButton        = FindViewById <Button>(Resource.Id.write_tag_button);
            _writeTagButton.Click += WriteTagButtonOnClick;

            _selectInteractionModeButton        = FindViewById <Button>(Resource.Id.select_tag_type_button);
            _selectInteractionModeButton.Click += CycleThroughInteractionModes;

            _launchDirectlyButton        = FindViewById <Button>(Resource.Id.launch_directly_button);
            _launchDirectlyButton.Click += LaunchDirectly;

            selectedModeEnumerator = Res.InteractionModes.Values.GetEnumerator();
            selectedModeEnumerator.MoveNext();
            selectedMode = selectedModeEnumerator.Current;
        }
Beispiel #2
0
 private void CycleThroughInteractionModes(object sender, EventArgs args)
 {
     if (!selectedModeEnumerator.MoveNext())
     {
         selectedModeEnumerator.Reset(); selectedModeEnumerator.MoveNext();
     }
     selectedMode = selectedModeEnumerator.Current;
     FindViewById <TextView>(Resource.Id.current_mode).Text = selectedMode.PromptText;
 }
Beispiel #3
0
        protected void ActOnIntent(Intent intent)
        {
            // Housework and setup
            nfcDetailDisplay = FindViewById <TextView>(Resource.Id.tag_details);
            var button = FindViewById <Button>(Resource.Id.cancel_btn);

            button.Click += (sender, args) => Finish();

            // Process the actual tag contents...

            // Verify it to be one of ours[which it bloody ought to be, given the Intent's mimetype constraint]
            //if (intent.Type != Res.AtroposMimeType) return;

            // Parse everything found
            InteractionLibrary.CurrentTagHandle = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
            var    rawMessages            = intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages);
            var    msg                    = (NdefMessage)rawMessages[0];
            var    nfcRecordBody          = msg.GetRecords();
            string _nfcTagID              = InteractionLibrary.CurrentTagHandle.tagID();
            string _nfcTagInteractionMode = Encoding.ASCII.GetString(nfcRecordBody[0].GetPayload());
            string feedbackText           = string.Format("Tag ({0}):\n{1}\nLaunch <{2}>", Res.AtroposMimeType, _nfcTagID, _nfcTagInteractionMode);

            nfcDetailDisplay.Text = feedbackText;


            // Debugging - prevent the tag from triggering the activity (for now).
            Finish();
            return; // Not sure this is necessary but just in case.

            // Check to see if we have a matching InteractionMode in our resources library
            if (Res.InteractionModes.ContainsKey(_nfcTagInteractionMode))
            {
                Log.Info("TagFound", feedbackText);
                if (InteractionLibrary.Current?.Name == _nfcTagInteractionMode)
                {
                    Log.Debug("ActOnFoundTag", $"Discovered a tag for {_nfcTagInteractionMode} but we're already in that mode; ignoring.");
                    return;
                }

                Res.InteractionMode t = Res.InteractionModes[_nfcTagInteractionMode];

                LaunchActivity(this, t, _nfcTagID);
            }
            else
            {
                Log.Info("TagFound", $"Looked for but did not find the following:\n {feedbackText}");
                Log.Info("TagFound", $"In the tag dictionary, which contains [{Res.InteractionModes.Keys.Join()}]");
            }



            Finish();
        }
Beispiel #4
0
 public static void InitializeAll()
 {
     Gunfight       = Res.DefineInteractionMode("gunfight", "Fire Gun", new GunfightActivity_Base());
     GunCalibration = Res.DefineInteractionMode("calibGun", "Calibrate Gun", new GunfightActivity_Base(), (stringOrID)Resource.String.directive_calibrate_gun);
     //Res.InteractionModes.Remove("calibGun"); // We want it to exist, yes, but not to show up in the list when we run through it later.  This does that.
     SpellTeaching = Res.DefineInteractionMode("spellTeaching", "Train Spell", new SpellTrainingActivity());
     SpellCasting  = Res.DefineInteractionMode("spellCasting", "Cast Spell", new SpellCastingActivity());
     MeleeTeaching = Res.DefineInteractionMode("meleeTeaching", "Train Melee", new MeleeTrainingActivity());
     Examine       = Res.DefineInteractionMode("kit_examine", "Examine Objects", new BypassActivity(), (stringOrID)Resource.String.directive_examine);
     Multimeter    = Res.DefineInteractionMode("kit_multimeter", "Multimeter", new BypassActivity(), (stringOrID)Resource.String.directive_multimeter);
     Wirecutters   = Res.DefineInteractionMode("kit_wirecutters", "Wirecutters", new BypassActivity(), (stringOrID)Resource.String.directive_wirecutter);
     SolderingIron = Res.DefineInteractionMode("kit_solderingIron", "Soldering Iron", new BypassActivity(), (stringOrID)Resource.String.directive_soldering);
     LockPicking   = Res.DefineInteractionMode("kit_lockpicking", "Pick Lock", new BypassActivity(), (stringOrID)Resource.String.directive_lock_picking);
     SafeCracking  = Res.DefineInteractionMode("kit_safecracking", "Crack Safe", new BypassActivity(), (stringOrID)Resource.String.directive_safe_cracking);
     SecurityPanel = Res.DefineInteractionMode("kit_securitypanel", "Hack Electronics", new BypassActivity(), (stringOrID)Resource.String.directive_security_panel);
     //LockTraining = Res.DefineInteractionMode("lockTraining", "Train Lock/Vault", new Atropos.Locks.LockTrainingActivity());
 }
Beispiel #5
0
        public static void LaunchActivity(Context ctx, Res.InteractionMode interactionMode, string tagID, string ExtraDirective = "")
        {
            Bundle b = new Bundle();

            b.PutString(Res.bundleKey_tagID, tagID);
            b.PutString(Res.bundleKey_Directive, interactionMode.Directive + ExtraDirective); // Used to communicate any special needs or requests to the launched Activity.
            // Note that bundle-passing is currently busted.  Instead, use the following:

            InteractionLibrary.CurrentSpecificTag = tagID;
            InteractionLibrary.Current            = interactionMode;

            var intent = new Intent(ctx, interactionMode.Launches.GetType());

            intent.AddFlags(interactionMode.Flags);
            try
            {
                ctx.StartActivity(intent, b);
            }
            catch
            {
                intent.AddFlags(ActivityFlags.NewTask);
                ctx.StartActivity(intent, b);
            }
        }