Пример #1
0
  @Test(expected = NoSuchFieldException.class)
  public void testAddFieldValueToColumn() throws NoSuchFieldException {
    SugarContext context = SugarContext.getSugarContext();
    TestRecord record = new TestRecord();
    record.setName("lala");

    Field column = TestRecord.class.getField("name");
    ContentValues values = new ContentValues();

    ReflectionUtil.addFieldValueToColumn(values, column, record, context.getEntitiesMap());

    Assert.assertEquals(record.getName(), values.getAsString("NAME"));
  }
 @Override
 public void onTerminate() {
   super.onTerminate();
   // release whatever is needed
   mBeaconManager.unbind(this);
   mBeaconManager = null;
   SugarContext.terminate();
 }
  public void onCreate() {
    super.onCreate();
    mBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);

    // By default the AndroidBeaconLibrary will only find AltBeacons.  If you wish to make it
    // find a different type of beacon, you must specify the byte layout for that beacon's
    // advertisement with a line like below.  The example shows how to find a beacon with the
    // same byte layout as AltBeacon but with a beaconTypeCode of 0xaabb.  To find the proper
    // layout expression for other beacon types, do a web search for "setBeaconLayout"
    // including the quotes.
    //
    mBeaconManager.getBeaconParsers().clear();
    mBeaconManager
        .getBeaconParsers()
        .add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

    Log.d(TAG, "setting up background monitoring for beacons and power saving");
    // wake up the app when a beacon is seen
    Region region = new Region("backgroundRegion", null, null, null);
    regionBootstrap = new RegionBootstrap(this, region);

    // simply constructing this class and holding a reference to it in your custom Application
    // class will automatically cause the BeaconLibrary to save battery whenever the application
    // is not visible.  This reduces bluetooth power usage by about 60%
    backgroundPowerSaver = new BackgroundPowerSaver(this);

    // If you wish to test beacon detection in the Android Emulator, you can use code like this:

    //        BeaconManager.setBeaconSimulator(new TimedBeaconSimulator() );
    //        ((TimedBeaconSimulator)
    // BeaconManager.getBeaconSimulator()).createTimedSimulatedBeacons();

    mBeaconManager.bind(this);

    SugarContext.init(getApplicationContext());
  }