diff options
author | Roman Birg <roman@cyngn.com> | 2015-01-21 18:59:20 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2015-12-09 13:25:16 -0800 |
commit | a616e3a243c31af415318aff273103a1bf523258 (patch) | |
tree | 8b2f2e5ac43d6f3bcf4d772045f43100c6e859cf /packages | |
parent | 3187e88f31c8bd5a4cf2b2b45f9cda5a77dc88d8 (diff) | |
download | frameworks_base-a616e3a243c31af415318aff273103a1bf523258.zip frameworks_base-a616e3a243c31af415318aff273103a1bf523258.tar.gz frameworks_base-a616e3a243c31af415318aff273103a1bf523258.tar.bz2 |
SystemUI: add NFC tile
Change-Id: I884b3492b1d81c39235df1660e4e0e06653abce2
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'packages')
5 files changed, 192 insertions, 0 deletions
diff --git a/packages/SystemUI/res/drawable/ic_qs_nfc_off.xml b/packages/SystemUI/res/drawable/ic_qs_nfc_off.xml new file mode 100644 index 0000000..1349c7c --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_nfc_off.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright (C) 2015 The CyanogenMod 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. + */ +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="64dp" + android:height="64dp" + android:viewportWidth="48" + android:viewportHeight="48"> + + <path + android:fillColor="#4DFFFFFF" + android:pathData="M16.4,8l-4-4H40c2.2,0,4,1.8,4,4v27.6l-4-4V8H16.4Z +M26,12c-1.5,0-2.8,0.9-3.5,2.1l3.5,3.5 V16h6v7.6l4,4V12H26z +M43.8,41.1c-0.5,1.7-2,2.9-3.8,2.9H8c-2.2,0-4-1.8-4-4V8c0-1.8,1.3-3.4,2.9-3.8L32,29.2l4,4L43.8,41.1z +M25,27.9c-0.3,0.1-0.7,0.1-1,0.1c-2.2,0-4-1.8-4-4c0-0.4,0-0.7,0.1-1L16,18.8V32h13.2L25,27.9z +M37.2,40l-4-4H12V14.8l-4-4V40H37.2 z" /> +</vector>
\ No newline at end of file diff --git a/packages/SystemUI/res/drawable/ic_qs_nfc_on.xml b/packages/SystemUI/res/drawable/ic_qs_nfc_on.xml new file mode 100644 index 0000000..73e735c --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_nfc_on.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright (C) 2015 The CyanogenMod 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. + */ +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="64dp" + android:height="64dp" + android:viewportWidth="48" + android:viewportHeight="48"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M40,4H8C5.8,4,4,5.8,4,8v32c0,2.2,1.8,4,4,4h32c2.2,0,4-1.8,4-4V8C44,5.8,42.2,4,40,4Z +M40,40H8V8h32V40z +M36,12H26c-2.2,0-4,1.8-4,4v4.6c-1.2,0.7-2,2-2,3.4c0,2.2,1.8,4,4,4s4-1.8,4-4c0-1.5-0.8-2.8-2-3.4V16h6v16H16 +V16h4v-4h-8v24h24V12z" /> +</vector>
\ No newline at end of file diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml index 964b217..073b332 100644 --- a/packages/SystemUI/res/values/cm_strings.xml +++ b/packages/SystemUI/res/values/cm_strings.xml @@ -95,4 +95,6 @@ <string name="quick_settings_network_adb_disabled_label">Disabled</string> <string name="qs_tile_adb_over_network">ADB over network</string> <string name="qs_tile_compass">Compass</string> + <string name="quick_settings_nfc">NFC</string> + <string name="quick_settings_nfc_off">NFC off</string> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/NfcTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/NfcTile.java new file mode 100644 index 0000000..a5be535 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/NfcTile.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015 The CyanogenMod 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.systemui.qs.tiles; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.nfc.NfcAdapter; + +import com.android.internal.logging.MetricsConstants; +import com.android.systemui.R; +import com.android.systemui.qs.QSTile; + +public class NfcTile extends QSTile<QSTile.BooleanState> { + private NfcAdapter mNfcAdapter; + private boolean mListening; + + private BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + refreshState(); + } + }; + + public NfcTile(Host host) { + super(host); + mNfcAdapter = NfcAdapter.getDefaultAdapter(mContext); + } + + @Override + protected BooleanState newTileState() { + return new BooleanState(); + } + + @Override + protected void handleClick() { + toggleState(); + } + + @Override + protected void handleLongClick() { + mHost.startActivityDismissingKeyguard(new Intent("android.settings.NFC_SETTINGS")); + } + + protected void toggleState() { + int state = getNfcState(); + switch (state) { + case NfcAdapter.STATE_TURNING_ON: + case NfcAdapter.STATE_ON: + mNfcAdapter.disable(); + break; + case NfcAdapter.STATE_TURNING_OFF: + case NfcAdapter.STATE_OFF: + mNfcAdapter.enable(); + break; + } + } + + private boolean isEnabled() { + int state = getNfcState(); + switch (state) { + case NfcAdapter.STATE_TURNING_ON: + case NfcAdapter.STATE_ON: + return true; + case NfcAdapter.STATE_TURNING_OFF: + case NfcAdapter.STATE_OFF: + default: + return false; + } + } + + private int getNfcState() { + return mNfcAdapter.getAdapterState(); + } + + @Override + protected void handleUpdateState(BooleanState state, Object arg) { + if (mNfcAdapter == null) { + mNfcAdapter = NfcAdapter.getDefaultAdapter(mContext); + } + state.visible = mNfcAdapter != null; + state.value = mNfcAdapter != null && isEnabled(); + state.icon = ResourceIcon.get(state.value ? + R.drawable.ic_qs_nfc_on : R.drawable.ic_qs_nfc_off); + state.label = mContext.getString(state.value + ? R.string.quick_settings_nfc : R.string.quick_settings_nfc_off); + } + + @Override + public int getMetricsCategory() { + return MetricsConstants.DONT_TRACK_ME_BRO; + } + + @Override + public void setListening(boolean listening) { + if (mListening == listening) return; + mListening = listening; + if (listening) { + if (mNfcAdapter == null) { + mNfcAdapter = NfcAdapter.getDefaultAdapter(mContext); + refreshState(); + } + mContext.registerReceiver(mReceiver, + new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)); + } else { + mContext.unregisterReceiver(mReceiver); + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java index f1dba43..040eeef 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -50,6 +50,7 @@ import com.android.systemui.qs.tiles.FlashlightTile; import com.android.systemui.qs.tiles.HotspotTile; import com.android.systemui.qs.tiles.IntentTile; import com.android.systemui.qs.tiles.LocationTile; +import com.android.systemui.qs.tiles.NfcTile; import com.android.systemui.qs.tiles.RotationLockTile; import com.android.systemui.qs.tiles.WifiTile; import com.android.systemui.statusbar.CustomTileData; @@ -332,6 +333,7 @@ public class QSTileHost implements QSTile.Host, Tunable { else if (tileSpec.equals("hotspot")) return new HotspotTile(this); else if (tileSpec.equals("edit")) return new EditTile(this); else if (tileSpec.equals("compass")) return new CompassTile(this); + else if (tileSpec.equals("nfc")) return new NfcTile(this); else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec); else throw new IllegalArgumentException("Bad tile spec: " + tileSpec); } @@ -404,6 +406,7 @@ public class QSTileHost implements QSTile.Host, Tunable { else if (spec.equals("edit")) return R.string.quick_settings_edit_label; else if (spec.equals("adb_network")) return R.string.qs_tile_adb_over_network; else if (spec.equals("compass")) return R.string.qs_tile_compass; + else if (spec.equals("nfc")) return R.string.quick_settings_nfc; return 0; } |