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

Commit 0f167d75 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Restore bluetooth icons on tablets.

- status bar
- notification panel header area

Bug: 5385369
Change-Id: I382b9e4fbd3dd440919484c70d50b00ce85a8fa1
parent 27812a8f
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -116,22 +116,23 @@
            android:orientation="horizontal"
            android:gravity="center"
            >
            <include layout="@layout/signal_cluster_view" 
                android:id="@+id/signal_cluster"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
            <ImageView
                android:id="@+id/bluetooth"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:paddingLeft="4dip"
                android:visibility="gone"
                />
            <include layout="@layout/signal_cluster_view" 
                android:id="@+id/signal_cluster"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
            <ImageView
                android:id="@+id/battery"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:paddingLeft="6dip"
                android:paddingLeft="4dip"
                />
        </LinearLayout>
    </LinearLayout>
+32 −7
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ public class BluetoothController extends BroadcastReceiver {
    private ArrayList<ImageView> mIconViews = new ArrayList<ImageView>();

    private int mIconId = R.drawable.stat_sys_data_bluetooth;
    private int mContentDescriptionId = 0;
    private boolean mEnabled;

    public BluetoothController(Context context) {
@@ -44,6 +45,11 @@ public class BluetoothController extends BroadcastReceiver {
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
        context.registerReceiver(this, filter);

        final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        handleAdapterStateChange(adapter.getState());
        handleConnectionStateChange(adapter.getConnectionState());
        refreshViews();
    }

    public void addIconView(ImageView v) {
@@ -52,24 +58,43 @@ public class BluetoothController extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
                BluetoothAdapter.STATE_DISCONNECTED);
        int contentDescriptionResId = 0;
        final String action = intent.getAction();

        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            handleAdapterStateChange(
                    intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR));
        } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
            handleConnectionStateChange(
                    intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
                        BluetoothAdapter.STATE_DISCONNECTED));
        }
        refreshViews();
    }

        if (state == BluetoothAdapter.STATE_CONNECTED) {
    public void handleAdapterStateChange(int adapterState) {
        mEnabled = (adapterState == BluetoothAdapter.STATE_ON);
    }

    public void handleConnectionStateChange(int connectionState) {
        final boolean connected = (connectionState == BluetoothAdapter.STATE_CONNECTED);
        if (connected) {
            mIconId = R.drawable.stat_sys_data_bluetooth_connected;
            contentDescriptionResId = R.string.accessibility_bluetooth_connected;
            mContentDescriptionId = R.string.accessibility_bluetooth_connected;
        } else {
            mIconId = R.drawable.stat_sys_data_bluetooth;
            contentDescriptionResId = R.string.accessibility_bluetooth_disconnected;
            mContentDescriptionId = R.string.accessibility_bluetooth_disconnected;
        }
    }

    public void refreshViews() {
        int N = mIconViews.size();
        for (int i=0; i<N; i++) {
            ImageView v = mIconViews.get(i);
            v.setImageResource(mIconId);
            v.setVisibility(mEnabled ? View.VISIBLE : View.GONE);
            v.setContentDescription(mContext.getString(contentDescriptionResId));
            v.setContentDescription((mContentDescriptionId == 0)
                    ? null
                    : mContext.getString(mContentDescriptionId));
        }
    }
}