Esempio n. 1
0
        public virtual void updateCities()
        {
            // Pull all the cities from the realm
            RealmResults <City> cities = realm.@where(typeof(City)).findAll();

            // Put these items in the Adapter
            mAdapter.Data = cities;
            mAdapter.notifyDataSetChanged();
            mGridView.invalidate();
        }
Esempio n. 2
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            // Generate a key
            // IMPORTANT! This is a silly way to generate a key. It is also never stored.
            // For proper key handling please consult:
            // * https://developer.android.com/training/articles/keystore.html
            // * http://nelenkov.blogspot.dk/2012/05/storing-application-secrets-in-androids.html
            sbyte[] key = new sbyte[64];
            (new SecureRandom()).NextBytes(key);
            RealmConfiguration realmConfiguration = (new RealmConfiguration.Builder(this)).encryptionKey(key).build();

            // Start with a clean slate every time
            Realm.deleteRealm(realmConfiguration);

            // Open the Realm with encryption enabled
            realm = Realm.getInstance(realmConfiguration);

            // Everything continues to work as normal except for that the file is encrypted on disk
            realm.beginTransaction();
            Person person = realm.createObject(typeof(Person));

            person.Name = "Happy Person";
            person.Age  = 14;
            realm.commitTransaction();

            person = realm.@where(typeof(Person)).findFirst();
            Log.i(TAG, string.Format("Person name: {0}", person.Name));
        }
        public override void handleMessage(Message msg)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final android.os.Bundle bundle = msg.getData();
            Bundle bundle = msg.Data;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int action = bundle.getInt(ACTION);
            int action = bundle.getInt(ACTION);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String timestamp = bundle.getString(TIMESTAMP);
            string timestamp = bundle.getString(TIMESTAMP);

            switch (action)
            {
            case ADD_TIMESTAMP:
                realm.beginTransaction();
                realm.createObject(typeof(TimeStamp)).TimeStamp = timestamp;
                realm.commitTransaction();
                break;

            case REMOVE_TIMESTAMP:
                realm.beginTransaction();
                realm.@where(typeof(TimeStamp)).equalTo("timeStamp", timestamp).findAll().clear();
                realm.commitTransaction();
                break;
            }
        }
        private void basicCRUD(Realm realm)
        {
            showStatus("Perform basic Create/Read/Update/Delete (CRUD) operations...");

            // All writes must be wrapped in a transaction to facilitate safe multi threading
            realm.beginTransaction();

            // Add a person
            Person person = realm.createObject(typeof(Person));

            person.Id   = 1;
            person.Name = "Young Person";
            person.Age  = 14;

            // When the transaction is committed, all changes a synced to disk.
            realm.commitTransaction();

            // Find the first person (no query conditions) and read a field
            person = realm.@where(typeof(Person)).findFirst();
            showStatus(person.Name + ":" + person.Age);

            // Update person in a transaction
            realm.beginTransaction();
            person.Name = "Senior Person";
            person.Age  = 99;
            showStatus(person.Name + " got older: " + person.Age);
            realm.commitTransaction();

            // Delete all persons
            realm.beginTransaction();
            realm.allObjects(typeof(Person)).clear();
            realm.commitTransaction();
        }
		protected internal override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);

			// Generate a key
			// IMPORTANT! This is a silly way to generate a key. It is also never stored.
			// For proper key handling please consult:
			// * https://developer.android.com/training/articles/keystore.html
			// * http://nelenkov.blogspot.dk/2012/05/storing-application-secrets-in-androids.html
			sbyte[] key = new sbyte[64];
			(new SecureRandom()).NextBytes(key);
			RealmConfiguration realmConfiguration = (new RealmConfiguration.Builder(this)).encryptionKey(key).build();

			// Start with a clean slate every time
			Realm.deleteRealm(realmConfiguration);

			// Open the Realm with encryption enabled
			realm = Realm.getInstance(realmConfiguration);

			// Everything continues to work as normal except for that the file is encrypted on disk
			realm.beginTransaction();
			Person person = realm.createObject(typeof(Person));
			person.Name = "Happy Person";
			person.Age = 14;
			realm.commitTransaction();

			person = realm.@where(typeof(Person)).findFirst();
			Log.i(TAG, string.Format("Person name: {0}", person.Name));
		}
Esempio n. 6
0
		public override void onStart()
		{
			base.onStart();
			// Create Realm instance for the UI thread
			realm = Realm.DefaultInstance;
			allSortedDots = realm.@where(typeof(Dot)).between("x", 25, 75).between("y", 0, 50).findAllSortedAsync("x", RealmResults.SORT_ORDER_ASCENDING, "y", RealmResults.SORT_ORDER_DESCENDING);
			dotAdapter.updateList(allSortedDots);
			allSortedDots.addChangeListener(this);
		}
        private void basicLinkQuery(Realm realm)
        {
            showStatus("\nPerforming basic Link Query operation...");
            showStatus("Number of persons: " + realm.allObjects(typeof(Person)).size());

            RealmResults <Person> results = realm.@where(typeof(Person)).equalTo("cats.name", "Tiger").findAll();

            showStatus("Size of result set: " + results.size());
        }
        private string complexQuery()
        {
            string status = "\n\nPerforming complex Query operation...";

            Realm realm = Realm.getInstance(this);

            status += "\nNumber of persons: " + realm.allObjects(typeof(Person)).size();

            // Find all persons where age between 7 and 9 and name begins with "Person".
            RealmResults <Person> results = realm.@where(typeof(Person)).between("age", 7, 9).beginsWith("name", "Person").findAll();            // Notice implicit "and" operation

            status += "\nSize of result set: " + results.size();

            realm.close();
            return(status);
        }
Esempio n. 9
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_my;

            RealmConfiguration realmConfig = (new RealmConfiguration.Builder(this)).build();

            Realm.deleteRealm(realmConfig);
            realm = Realm.getInstance(realmConfig);

            RealmResults <TimeStamp> timeStamps = realm.@where(typeof(TimeStamp)).findAll();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final MyAdapter adapter = new MyAdapter(this, R.id.listView, timeStamps, true);
            MyAdapter adapter  = new MyAdapter(this, R.id.listView, timeStamps, true);
            ListView  listView = (ListView)findViewById(R.id.listView);

            listView.Adapter = adapter;
            listView.OnItemLongClickListener = new OnItemLongClickListenerAnonymousInnerClassHelper(this, adapter);
        }
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_modules_example;
            rootLayout  = ((LinearLayout)findViewById(R.id.container));
            rootLayout.removeAllViews();

            // The default Realm instance implicitly knows about all classes in the realmModuleAppExample Android Studio
            // module. This does not include the classes from the realmModuleLibraryExample AS module so a Realm using this
            // configuration would know about the following classes: { Cow, Pig, Snake, Spider }
            RealmConfiguration defaultConfig = (new RealmConfiguration.Builder(this)).build();

            // It is possible to extend the default schema by adding additional Realm modules using setModule(). This can
            // also be Realm modules from libraries. The below Realm contains the following classes: { Cow, Pig, Snake,
            // Spider, Cat, Dog }
            RealmConfiguration farmAnimalsConfig = (new RealmConfiguration.Builder(this)).name("farm.realm").setModules(Realm.DefaultModule, new DomesticAnimalsModule()).build();

            // Or you can completely replace the default schema.
            // This Realm contains the following classes: { Elephant, Lion, Zebra, Snake, Spider }
            RealmConfiguration exoticAnimalsConfig = (new RealmConfiguration.Builder(this)).name("exotic.realm").setModules(new ZooAnimalsModule(), new CreepyAnimalsModule()).build();

            // Multiple Realms can be open at the same time
            showStatus("Opening multiple Realms");
            Realm defaultRealm = Realm.getInstance(defaultConfig);
            Realm farmRealm    = Realm.getInstance(farmAnimalsConfig);
            Realm exoticRealm  = Realm.getInstance(exoticAnimalsConfig);

            // Objects can be added to each Realm independantly
            showStatus("Create objects in the default Realm");
            defaultRealm.executeTransaction(new TransactionAnonymousInnerClassHelper(this));

            showStatus("Create objects in the farm Realm");
            farmRealm.executeTransaction(new TransactionAnonymousInnerClassHelper2(this));

            showStatus("Create objects in the exotic Realm");
            exoticRealm.executeTransaction(new TransactionAnonymousInnerClassHelper3(this));

            // You can copy objects between Realms
            showStatus("Copy objects between Realms");
            showStatus("Number of pigs on the farm : " + farmRealm.@where(typeof(Pig)).count());
            showStatus("Copy pig from defaultRealm to farmRealm");
            Pig defaultPig = defaultRealm.@where(typeof(Pig)).findFirst();

            farmRealm.beginTransaction();
            farmRealm.copyToRealm(defaultPig);
            farmRealm.commitTransaction();
            showStatus("Number of pigs on the farm : " + farmRealm.@where(typeof(Pig)).count());

            // Each Realm is restricted to only accept the classes in their schema.
            showStatus("Trying to add an unsupported class");
            defaultRealm.beginTransaction();
            try
            {
                defaultRealm.createObject(typeof(Elephant));
            }
            catch (RealmException expected)
            {
                showStatus("This throws a :" + expected.ToString());
            }
            finally
            {
                defaultRealm.cancelTransaction();
            }

            // And Realms in library projects are independent from Realms in the app code
            showStatus("Interacting with library code that uses Realm internally");
            int animals    = 5;
            Zoo libraryZoo = new Zoo(this);

            libraryZoo.open();
            showStatus("Adding animals: " + animals);
            libraryZoo.addAnimals(5);
            showStatus("Number of animals in the library Realm:" + libraryZoo.NoOfAnimals);
            libraryZoo.close();

            // Remember to close all open Realms
            defaultRealm.close();
            farmRealm.close();
            exoticRealm.close();
        }