Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a616e3a2 authored by Roman Birg's avatar Roman Birg Committed by Danesh M
Browse files

SystemUI: add NFC tile



Change-Id: I884b3492b1d81c39235df1660e4e0e06653abce2
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 3187e88f
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
<?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
+31 −0
Original line number Diff line number Diff line
<?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
+2 −0
Original line number Diff line number Diff line
@@ -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>
+124 −0
Original line number Diff line number Diff line
/*
 * 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);
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -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;
    }