Added bluetooth setting to area.
This commit is contained in:
parent
37de69ae63
commit
d9e8bc0dd2
8 changed files with 51 additions and 15 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
||||||
<application android:label="@string/app_name"
|
<application android:label="@string/app_name"
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
<!-- AreaEdit -->
|
<!-- AreaEdit -->
|
||||||
<string name="areaedit_profile">Profile</string>
|
<string name="areaedit_profile">Profile</string>
|
||||||
<string name="areaedit_wifi">Wifi Enabled</string>
|
<string name="areaedit_wifi">Wifi Enabled</string>
|
||||||
|
<string name="areaedit_bluetooth">Bluetooth Enabled</string>
|
||||||
|
|
||||||
<string-array name="arealist_learn_area_strings">
|
<string-array name="arealist_learn_area_strings">
|
||||||
<item>Next 6 hours</item>
|
<item>Next 6 hours</item>
|
||||||
|
@ -85,6 +86,5 @@
|
||||||
|
|
||||||
<!-- LocationService -->
|
<!-- LocationService -->
|
||||||
<string name="locationservice_area_unknown">Unknown Area</string>
|
<string name="locationservice_area_unknown">Unknown Area</string>
|
||||||
<string name="locationservice_profile_none">No profile</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -26,4 +26,9 @@
|
||||||
android:title="@string/areaedit_wifi"
|
android:title="@string/areaedit_wifi"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="bluetooth_enabled"
|
||||||
|
android:title="@string/areaedit_bluetooth"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
|
@ -21,11 +21,11 @@ import java.util.Set;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.DatabaseUtils;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -213,7 +213,7 @@ public class LocationService extends Service {
|
||||||
Cursor c = db.getReadableDatabase().query(
|
Cursor c = db.getReadableDatabase().query(
|
||||||
AreaColumns.TABLE_NAME + " as a, " + CellColumns.TABLE_NAME + " as c",
|
AreaColumns.TABLE_NAME + " as a, " + CellColumns.TABLE_NAME + " as c",
|
||||||
new String[] { "a." + AreaColumns.PROFILE_ID, "a." + AreaColumns.NAME,
|
new String[] { "a." + AreaColumns.PROFILE_ID, "a." + AreaColumns.NAME,
|
||||||
"a." + AreaColumns.WIFI_ENABLED },
|
"a." + AreaColumns.WIFI_ENABLED, "a." + AreaColumns.BLUETOOTH_ENABLED},
|
||||||
"a." + AreaColumns._ID + " = c." + CellColumns.AREA_ID + " AND " +
|
"a." + AreaColumns._ID + " = c." + CellColumns.AREA_ID + " AND " +
|
||||||
"c." + CellColumns.CELL_ID + " = ? AND " +
|
"c." + CellColumns.CELL_ID + " = ? AND " +
|
||||||
"c." + CellColumns.CELL_TYPE + " = ?",
|
"c." + CellColumns.CELL_TYPE + " = ?",
|
||||||
|
@ -227,10 +227,21 @@ public class LocationService extends Service {
|
||||||
if (c.moveToFirst()) {
|
if (c.moveToFirst()) {
|
||||||
profileId = c.getLong(c.getColumnIndex(AreaColumns.PROFILE_ID));
|
profileId = c.getLong(c.getColumnIndex(AreaColumns.PROFILE_ID));
|
||||||
areaName = c.getString(c.getColumnIndex(AreaColumns.NAME));
|
areaName = c.getString(c.getColumnIndex(AreaColumns.NAME));
|
||||||
|
|
||||||
WifiManager wm = (WifiManager) LocationService.this
|
WifiManager wm = (WifiManager) LocationService.this
|
||||||
.getSystemService(Context.WIFI_SERVICE);
|
.getSystemService(Context.WIFI_SERVICE);
|
||||||
wm.setWifiEnabled((c.getInt(c.getColumnIndex(AreaColumns.WIFI_ENABLED)) == 1)
|
wm.setWifiEnabled((c.getInt(c.getColumnIndex(AreaColumns.WIFI_ENABLED)) == 1)
|
||||||
? true : false);
|
? true : false);
|
||||||
|
|
||||||
|
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
if (bt != null) {
|
||||||
|
if ((c.getInt(c.getColumnIndex(AreaColumns.BLUETOOTH_ENABLED)) == 1)) {
|
||||||
|
bt.enable();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bt.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
areaName = getResources().getString(
|
areaName = getResources().getString(
|
||||||
|
|
|
@ -27,7 +27,6 @@ import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.github.nutomic.pegasus.LocationService;
|
import com.github.nutomic.pegasus.LocationService;
|
||||||
|
@ -55,6 +54,7 @@ public class AreaEdit extends PreferenceActivity implements
|
||||||
private long mArea;
|
private long mArea;
|
||||||
private Preference mProfile;
|
private Preference mProfile;
|
||||||
private CheckBoxPreference mWifi;
|
private CheckBoxPreference mWifi;
|
||||||
|
private CheckBoxPreference mBluetooth;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -70,7 +70,8 @@ public class AreaEdit extends PreferenceActivity implements
|
||||||
protected Cursor doInBackground(Void... params) {
|
protected Cursor doInBackground(Void... params) {
|
||||||
return Database.getInstance(AreaEdit.this).getReadableDatabase()
|
return Database.getInstance(AreaEdit.this).getReadableDatabase()
|
||||||
.query(AreaColumns.TABLE_NAME,
|
.query(AreaColumns.TABLE_NAME,
|
||||||
new String[] { AreaColumns.WIFI_ENABLED },
|
new String[] { AreaColumns.WIFI_ENABLED,
|
||||||
|
AreaColumns.BLUETOOTH_ENABLED },
|
||||||
AreaColumns._ID + " = ?",
|
AreaColumns._ID + " = ?",
|
||||||
new String[] { Long.toString(mArea) },
|
new String[] { Long.toString(mArea) },
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
@ -79,7 +80,6 @@ public class AreaEdit extends PreferenceActivity implements
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Cursor c) {
|
protected void onPostExecute(Cursor c) {
|
||||||
c.moveToFirst();
|
c.moveToFirst();
|
||||||
// TODO: nothing here works
|
|
||||||
mProfile = findPreference("profile");
|
mProfile = findPreference("profile");
|
||||||
mProfile.setOnPreferenceClickListener(AreaEdit.this);
|
mProfile.setOnPreferenceClickListener(AreaEdit.this);
|
||||||
|
|
||||||
|
@ -87,6 +87,11 @@ public class AreaEdit extends PreferenceActivity implements
|
||||||
mWifi.setChecked((c.getInt(c.getColumnIndex(AreaColumns.WIFI_ENABLED)) == 1)
|
mWifi.setChecked((c.getInt(c.getColumnIndex(AreaColumns.WIFI_ENABLED)) == 1)
|
||||||
? true : false);
|
? true : false);
|
||||||
mWifi.setOnPreferenceChangeListener(AreaEdit.this);
|
mWifi.setOnPreferenceChangeListener(AreaEdit.this);
|
||||||
|
|
||||||
|
mBluetooth = (CheckBoxPreference) findPreference("bluetooth_enabled");
|
||||||
|
mBluetooth.setChecked((c.getInt(c.getColumnIndex(AreaColumns.BLUETOOTH_ENABLED)) == 1)
|
||||||
|
? true : false);
|
||||||
|
mBluetooth.setOnPreferenceChangeListener(AreaEdit.this);
|
||||||
}
|
}
|
||||||
}.execute((Void) null);
|
}.execute((Void) null);
|
||||||
}
|
}
|
||||||
|
@ -98,9 +103,11 @@ public class AreaEdit extends PreferenceActivity implements
|
||||||
cv.put(AreaColumns.WIFI_ENABLED, (Boolean) newValue);
|
cv.put(AreaColumns.WIFI_ENABLED, (Boolean) newValue);
|
||||||
}
|
}
|
||||||
else if (preference.equals(mProfile)) {
|
else if (preference.equals(mProfile)) {
|
||||||
// TODO: does not cause profile to be applied
|
|
||||||
cv.put(AreaColumns.PROFILE_ID, (Long) newValue);
|
cv.put(AreaColumns.PROFILE_ID, (Long) newValue);
|
||||||
}
|
}
|
||||||
|
else if (preference.equals(mBluetooth)) {
|
||||||
|
cv.put(AreaColumns.BLUETOOTH_ENABLED, (Boolean) newValue);
|
||||||
|
}
|
||||||
|
|
||||||
final ContentValues values = cv;
|
final ContentValues values = cv;
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
|
|
@ -357,6 +357,8 @@ public class AreaList extends ListActivity {
|
||||||
cv.put(AreaColumns.NAME, getResources()
|
cv.put(AreaColumns.NAME, getResources()
|
||||||
.getString(R.string.arealist_new));
|
.getString(R.string.arealist_new));
|
||||||
cv.put(AreaColumns.PROFILE_ID, Database.ROW_NONE);
|
cv.put(AreaColumns.PROFILE_ID, Database.ROW_NONE);
|
||||||
|
cv.put(AreaColumns.WIFI_ENABLED, true);
|
||||||
|
cv.put(AreaColumns.BLUETOOTH_ENABLED, false);
|
||||||
return Database.getInstance(AreaList.this).getWritableDatabase()
|
return Database.getInstance(AreaList.this).getWritableDatabase()
|
||||||
.insert(AreaColumns.TABLE_NAME, null, cv);
|
.insert(AreaColumns.TABLE_NAME, null, cv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,14 @@ public class AreaColumns implements BaseColumns {
|
||||||
public static final String NAME = "name";
|
public static final String NAME = "name";
|
||||||
public static final String PROFILE_ID = "profile_id";
|
public static final String PROFILE_ID = "profile_id";
|
||||||
public static final String WIFI_ENABLED = "wifi_enabled";
|
public static final String WIFI_ENABLED = "wifi_enabled";
|
||||||
|
public static final String BLUETOOTH_ENABLED = "bluetooth_enabled";
|
||||||
|
|
||||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
|
||||||
_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
|
_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||||
NAME + " TEXT," +
|
NAME + " TEXT," +
|
||||||
PROFILE_ID + " INTEGER, " +
|
PROFILE_ID + " INTEGER, " +
|
||||||
WIFI_ENABLED + " INTEGER " +
|
WIFI_ENABLED + " INTEGER, " +
|
||||||
|
BLUETOOTH_ENABLED + " INTEGER " +
|
||||||
");";
|
");";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ public class Database extends SQLiteOpenHelper {
|
||||||
.getString(R.string.sql_area_unknown));
|
.getString(R.string.sql_area_unknown));
|
||||||
cv.put(AreaColumns.PROFILE_ID, normal);
|
cv.put(AreaColumns.PROFILE_ID, normal);
|
||||||
cv.put(AreaColumns.WIFI_ENABLED, false);
|
cv.put(AreaColumns.WIFI_ENABLED, false);
|
||||||
|
cv.put(AreaColumns.BLUETOOTH_ENABLED, false);
|
||||||
db.insert(AreaColumns.TABLE_NAME, null, cv);
|
db.insert(AreaColumns.TABLE_NAME, null, cv);
|
||||||
|
|
||||||
// Insert "Home" area.
|
// Insert "Home" area.
|
||||||
|
@ -112,6 +113,7 @@ public class Database extends SQLiteOpenHelper {
|
||||||
.getString(R.string.sql_area_home));
|
.getString(R.string.sql_area_home));
|
||||||
cv.put(AreaColumns.PROFILE_ID, normal);
|
cv.put(AreaColumns.PROFILE_ID, normal);
|
||||||
cv.put(AreaColumns.WIFI_ENABLED, true);
|
cv.put(AreaColumns.WIFI_ENABLED, true);
|
||||||
|
cv.put(AreaColumns.BLUETOOTH_ENABLED, false);
|
||||||
db.insert(AreaColumns.TABLE_NAME, null, cv);
|
db.insert(AreaColumns.TABLE_NAME, null, cv);
|
||||||
|
|
||||||
// Insert "Work" area.
|
// Insert "Work" area.
|
||||||
|
@ -120,21 +122,27 @@ public class Database extends SQLiteOpenHelper {
|
||||||
.getString(R.string.sql_area_work));
|
.getString(R.string.sql_area_work));
|
||||||
cv.put(AreaColumns.PROFILE_ID, silent);
|
cv.put(AreaColumns.PROFILE_ID, silent);
|
||||||
cv.put(AreaColumns.WIFI_ENABLED, true);
|
cv.put(AreaColumns.WIFI_ENABLED, true);
|
||||||
|
cv.put(AreaColumns.BLUETOOTH_ENABLED, false);
|
||||||
db.insert(AreaColumns.TABLE_NAME, null, cv);
|
db.insert(AreaColumns.TABLE_NAME, null, cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
// Move wifi preference from profile to area.
|
|
||||||
if (oldVersion == 1) {
|
if (oldVersion == 1) {
|
||||||
db.rawQuery("ALTER TABLE " + ProfileColumns.TABLE_NAME +
|
// Add wifi preference to area (Wifi reference in area will not
|
||||||
" DROP wifi_enabled", null);
|
// be used any more).
|
||||||
|
db.execSQL("ALTER TABLE area " +
|
||||||
db.rawQuery("ALTER TABLE " + AreaColumns.TABLE_NAME +
|
"ADD COLUMN " + AreaColumns.WIFI_ENABLED + " INTEGER;");
|
||||||
" ADD " + AreaColumns.WIFI_ENABLED + " INTEGER", null);
|
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(AreaColumns.WIFI_ENABLED, true);
|
cv.put(AreaColumns.WIFI_ENABLED, true);
|
||||||
db.update(AreaColumns.TABLE_NAME, cv, null, null);
|
db.update(AreaColumns.TABLE_NAME, cv, null, null);
|
||||||
|
|
||||||
|
// Add bluetooth column to area.
|
||||||
|
db.execSQL("ALTER TABLE area " +
|
||||||
|
"ADD COLUMN " + AreaColumns.BLUETOOTH_ENABLED + " INTEGER;");
|
||||||
|
cv = new ContentValues();
|
||||||
|
cv.put(AreaColumns.BLUETOOTH_ENABLED, false);
|
||||||
|
db.update(AreaColumns.TABLE_NAME, cv, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue