Exemple #1
0
        private bool GetIocFromViewIntent(Intent intent)
        {
            IOConnectionInfo ioc = new IOConnectionInfo();

            //started from "view" intent (e.g. from file browser)
            ioc.Path = intent.DataString;

            if (ioc.Path.StartsWith("file://"))
            {
                ioc.Path = URLDecoder.Decode(ioc.Path.Substring(7));

                if (ioc.Path.Length == 0)
                {
                    // No file name
                    Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show();
                    return(false);
                }

                File dbFile = new File(ioc.Path);
                if (!dbFile.Exists())
                {
                    // File does not exist
                    Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show();
                    return(false);
                }
            }
            else
            {
                if (!ioc.Path.StartsWith("content://"))
                {
                    Toast.MakeText(this, Resource.String.error_can_not_handle_uri, ToastLength.Long).Show();
                    return(false);
                }
                IoUtil.TryTakePersistablePermissions(this.ContentResolver, intent.Data);
            }

            if (App.Kp2a.TrySelectCurrentDb(ioc))
            {
                if (OpenAutoExecEntries(App.Kp2a.CurrentDb))
                {
                    return(false);
                }
                LaunchingOther = true;
                AppTask.CanActivateSearchViewOnStart = true;
                AppTask.LaunchFirstGroupActivity(this);
            }
            else
            {
                Intent launchIntent = new Intent(this, typeof(PasswordActivity));
                Util.PutIoConnectionToIntent(ioc, launchIntent);
                LaunchingOther = true;
                StartActivityForResult(launchIntent, ReqCodeOpenNewDb);
            }


            return(true);
        }
Exemple #2
0
        protected override void OnResume()
        {
            _isForeground = true;
            base.OnResume();
            if (!IsFinishing && !LaunchingOther)
            {
                if (App.Kp2a.OpenDatabases.Any() == false)
                {
                    StartFileSelect(true);
                    return;
                }

                //database loaded
                if (App.Kp2a.QuickLocked)
                {
                    AppTask.CanActivateSearchViewOnStart = true;
                    var i = new Intent(this, typeof(QuickUnlock));
                    Util.PutIoConnectionToIntent(App.Kp2a.GetDbForQuickUnlock().Ioc, i);
                    Kp2aLog.Log("Starting QuickUnlock");
                    StartActivityForResult(i, 0);
                    return;
                }

                //see if there are any AutoOpen items to open

                foreach (var db in App.Kp2a.OpenDatabases)
                {
                    try
                    {
                        if (OpenAutoExecEntries(db))
                        {
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        Toast.MakeText(this, "Failed to open child databases", ToastLength.Long).Show();
                        Kp2aLog.LogUnexpectedError(e);
                    }
                }

                //database(s) unlocked
                if ((App.Kp2a.OpenDatabases.Count() == 1) || (AppTask is SearchUrlTask))
                {
                    LaunchingOther = true;
                    AppTask.LaunchFirstGroupActivity(this);
                    return;
                }
            }

            //more than one database open or user requested to load another db. Don't launch another activity.
            _adapter.Update();
            _adapter.NotifyDataSetChanged();

            base.OnResume();
        }
        public void StartFileUsageProcess(IOConnectionInfo ioc, int requestCode, bool alwaysReturnSuccess)
        {
            Intent fileStorageSetupIntent = new Intent(_activity, typeof(FileStorageSetupActivity));

            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraProcessName, FileStorageSetupDefs.ProcessNameFileUsageSetup);
            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraAlwaysReturnSuccess, alwaysReturnSuccess);
            Util.PutIoConnectionToIntent(ioc, fileStorageSetupIntent);

            _activity.StartActivityForResult(fileStorageSetupIntent, requestCode);
        }
        public void StartSelectFileProcess(IOConnectionInfo ioc, bool isForSave, int requestCode)
        {
            Kp2aLog.Log("FSSIA: StartSelectFileProcess ");
            Intent fileStorageSetupIntent = new Intent(_activity, typeof(FileStorageSetupActivity));

            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraProcessName, FileStorageSetupDefs.ProcessNameSelectfile);
            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraIsForSave, isForSave);
            Util.PutIoConnectionToIntent(ioc, fileStorageSetupIntent);

            _activity.StartActivityForResult(fileStorageSetupIntent, requestCode);
        }
        protected override void OnResume()
        {
            base.OnResume();
            if (!IsFinishing && !LaunchingOther)
            {
                if (App.Kp2a.OpenDatabases.Any() == false)
                {
                    StartFileSelect(true);
                    return;
                }

                //database loaded
                if (App.Kp2a.QuickLocked)
                {
                    var i = new Intent(this, typeof(QuickUnlock));
                    Util.PutIoConnectionToIntent(App.Kp2a.GetDbForQuickUnlock().Ioc, i);
                    Kp2aLog.Log("Starting QuickUnlock");
                    StartActivityForResult(i, 0);
                    return;
                }

                //see if there are any AutoOpen items to open

                foreach (var db in App.Kp2a.OpenDatabases)
                {
                    if (OpenAutoExecEntries(db))
                    {
                        return;
                    }
                }

                //database(s) unlocked
                if (App.Kp2a.OpenDatabases.Count() == 1)
                {
                    LaunchingOther = true;
                    AppTask.LaunchFirstGroupActivity(this);
                    return;
                }

                //more than one database open or user requested to load another db. Don't launch another activity.
                _adapter.Update();
                _adapter.NotifyDataSetChanged();
            }
            base.OnResume();
        }
Exemple #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.open_db_selection);

            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.mytoolbar);

            SetSupportActionBar(toolbar);

            SupportActionBar.Title = GetString(Resource.String.select_database);


            //only load the AppTask if this is the "first" OnCreate (not because of kill/resume, i.e. savedInstanceState==null)
            // and if the activity is not launched from history (i.e. recent tasks) because this would mean that
            // the Activity was closed already (user cancelling the task or task complete) but is restarted due recent tasks.
            // Don't re-start the task (especially bad if tak was complete already)
            if (Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory))
            {
                AppTask = new NullTask();
            }
            else
            {
                AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
            }

            _adapter = new OpenDatabaseAdapter(this);
            var gridView = FindViewById <GridView>(Resource.Id.gridview);

            gridView.Adapter = _adapter;

            if (!string.IsNullOrEmpty(Intent.GetStringExtra(Util.KeyFilename)))
            {
                //forward to password activity
                Intent           i   = new Intent(this, typeof(PasswordActivity));
                IOConnectionInfo ioc = new IOConnectionInfo();
                Util.SetIoConnectionFromIntent(ioc, Intent);
                Util.PutIoConnectionToIntent(ioc, i);
                i.PutExtra(PasswordActivity.KeyKeyfile, i.GetStringExtra(PasswordActivity.KeyKeyfile));
                i.PutExtra(PasswordActivity.KeyPassword, i.GetStringExtra(PasswordActivity.KeyPassword));
                LaunchingOther = true;
                StartActivityForResult(i, ReqCodeOpenNewDb);
            }
            else
            {
                if (Intent.Action == Intent.ActionView)
                {
                    GetIocFromViewIntent(Intent);
                }
                else if (Intent.Action == Intent.ActionSend)
                {
                    AppTask = new SearchUrlTask {
                        UrlToSearchFor = Intent.GetStringExtra(Intent.ExtraText)
                    };
                }
            }

            _intentReceiver = new MyBroadcastReceiver(this);
            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intents.DatabaseLocked);
            RegisterReceiver(_intentReceiver, filter);
        }
 public void IocToIntent(Intent intent, IOConnectionInfo ioc)
 {
     Util.PutIoConnectionToIntent(ioc, intent);
 }