Add Slices Data object and DB Contract
Add in a Data object used to represent one row in a new SQLite database used for building Slices. The database has the following schema: - Key - Title - Subtitle - Screentitle - Icon - Fragment - Controller The key is the preference key. Title, subtitle and Icon are for UI info. Screentitle and fragment are for the intent. Controller is used to get dynamic ui info (like summary), and to take actions on the slice (like a toggle). The actual indexing and a Slice will be handled in a subsquent CL, but a prototype can be found here: ag/3324435 Test: robotests Bug: 67996923 Change-Id: Id91deb58a3ab89ce1dab5a3f34cdb9ade6263aa8
This commit is contained in:
51
src/com/android/settings/slices/SliceBroadcastReceiver.java
Normal file
51
src/com/android/settings/slices/SliceBroadcastReceiver.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_WIFI_CHANGED;
|
||||
|
||||
import android.app.slice.Slice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
|
||||
/**
|
||||
* Responds to actions performed on slices and notifies slices of updates in state changes.
|
||||
*/
|
||||
public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent i) {
|
||||
String action = i.getAction();
|
||||
switch (action) {
|
||||
case ACTION_WIFI_CHANGED:
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
boolean newState = i.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE, wm.isWifiEnabled());
|
||||
wm.setWifiEnabled(newState);
|
||||
// Wait a bit for wifi to update (TODO: is there a better way to do this?)
|
||||
Handler h = new Handler();
|
||||
h.postDelayed(() -> {
|
||||
Uri uri = SettingsSliceProvider.getUri(SettingsSliceProvider.PATH_WIFI);
|
||||
context.getContentResolver().notifyChange(uri, null);
|
||||
}, 1000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user