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