Android Open Source - trifork-ibeacon-demo Persistent State






From Project

Back to project page trifork-ibeacon-demo.

License

The source code is released under:

Apache License

If you think the Android project trifork-ibeacon-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.trifork.ibeacon.util;
/*from  w w  w .jav  a 2  s.  co  m*/
import android.content.Context;
import android.content.SharedPreferences;

import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.Identifier;
import org.altbeacon.beacon.Region;

public class PersistentState  {

    private static final String PREFERENCE_FILE_NAME = "ibeacon_demo_settings";
    private static final String KEY_UUID = "uuid";
    private static final String KEY_MAJOR = "major";
    private static final String KEY_MINOR = "minor";

    private SharedPreferences prefs;

    public PersistentState(Context context) {
        prefs = context.getSharedPreferences(PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
    }

    public Region getSelectedRegion() {
        String uuid = prefs.getString(KEY_UUID, "");
        int major = prefs.getInt(KEY_MAJOR, 0);
        int minor = prefs.getInt(KEY_MINOR, 0);
        if (uuid.equals("")) {
            return null;
        } else {
            return new Region(generateLabel(uuid,major,minor),
                    Identifier.parse(uuid),
                    Identifier.fromInt(major),
                    Identifier.fromInt(minor));
        }
    }

    public void setSelectedRegion(Beacon beacon) {
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(KEY_UUID,beacon.getId1().toString());
        editor.putInt(KEY_MAJOR, beacon.getId2().toInt());
        editor.putInt(KEY_MINOR, beacon.getId3().toInt());
        editor.commit();
    }

    private String generateLabel(String uuid, int major, int minor) {
        if (uuid.length() < 10) {
            return uuid;
        } else {
            return uuid.substring(0, 5) + ":" + uuid.substring(uuid.length() - 5, uuid.length());
         }
    }
}




Java Source Code List

com.echo.holographlibrary.BarGraph.java
com.echo.holographlibrary.Bar.java
com.echo.holographlibrary.LineGraph.java
com.echo.holographlibrary.LinePoint.java
com.echo.holographlibrary.Line.java
com.echo.holographlibrary.PieGraph.java
com.echo.holographlibrary.PieSlice.java
com.echo.holographlibrary.Utils.java
com.trifork.ibeacon.ApplicationContext.java
com.trifork.ibeacon.ApplicationModule.java
com.trifork.ibeacon.BaseActivity.java
com.trifork.ibeacon.BaseApplication.java
com.trifork.ibeacon.BaseFragment.java
com.trifork.ibeacon.BootBroadcastReceiver.java
com.trifork.ibeacon.MainActivity.java
com.trifork.ibeacon.database.Dao.java
com.trifork.ibeacon.database.Database.java
com.trifork.ibeacon.database.RegionHistoryCursorLoader.java
com.trifork.ibeacon.database.RegionHistoryEntry.java
com.trifork.ibeacon.detectors.BeaconController.java
com.trifork.ibeacon.detectors.IBeaconParser.java
com.trifork.ibeacon.eventbus.FullScanCompleteEvent.java
com.trifork.ibeacon.eventbus.NewBeaconSelectedEvent.java
com.trifork.ibeacon.eventbus.OttoEvent.java
com.trifork.ibeacon.eventbus.RangeScanCompleteEvent.java
com.trifork.ibeacon.eventbus.RequestBeaconScanEvent.java
com.trifork.ibeacon.eventbus.RequestBeaconTransmit.java
com.trifork.ibeacon.eventbus.RequestFullScanEvent.java
com.trifork.ibeacon.eventbus.StopFullScanEvent.java
com.trifork.ibeacon.eventbus.StopScanEvent.java
com.trifork.ibeacon.eventbus.StopTransmitEvent.java
com.trifork.ibeacon.ui.BeaconDataFragment.java
com.trifork.ibeacon.ui.LocationFragment.java
com.trifork.ibeacon.ui.NotificationFragment.java
com.trifork.ibeacon.ui.RangingFragment.java
com.trifork.ibeacon.ui.RegionLogFragment.java
com.trifork.ibeacon.ui.ScanFragment.java
com.trifork.ibeacon.util.CircularBuffer.java
com.trifork.ibeacon.util.PersistentState.java
com.trifork.ibeacon.util.Utils.java
com.trifork.ibeacon.widgets.BeaconView.java
com.trifork.ibeacon.widgets.LocationTrackerView.java