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

Commit 96350ea7 authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Clean up quick settings tile code.

- Fix up coding style
- Add copyright headers
- Fix some multi-user bugs
- Streamline code

Change-Id: I0a118f7154bdd8cfdacdd7fdf8b76241010179de
parent c14b3898
Loading
Loading
Loading
Loading
+35 −23
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013-2014 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.quicksettings;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnLongClickListener;

import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.phone.QuickSettingsContainerView;
import com.android.systemui.statusbar.policy.MSimNetworkController;
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChangedCallback;

public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignalChangedCallback {
    private NetworkController mController;
    private boolean enabled = false;
    private boolean mEnabled = false;

    public AirplaneModeTile(Context context, QuickSettingsController qsc, NetworkController controller) {
    public AirplaneModeTile(Context context, QuickSettingsController qsc,
            NetworkController controller) {
        super(context, qsc);

        mController = controller;
@@ -27,17 +41,16 @@ public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignal
            @Override
            public void onClick(View v) {
                // Change the system setting
                Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
                                        !enabled ? 1 : 0);
                Settings.Global.putInt(mContext.getContentResolver(),
                        Settings.Global.AIRPLANE_MODE_ON, mEnabled ? 0 : 1);

                // Post the intent
                Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
                intent.putExtra("state", !enabled);
                intent.putExtra("state", !mEnabled);
                mContext.sendBroadcast(intent);
            }
        };
        mOnLongClick = new OnLongClickListener() {

        mOnLongClick = new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                startSettingsActivity(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
@@ -65,11 +78,6 @@ public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignal
        super.updateResources();
    }

    private synchronized void updateTile() {
        mLabel = mContext.getString(R.string.quick_settings_airplane_mode_label);
        mDrawable = (enabled) ? R.drawable.ic_qs_airplane_on : R.drawable.ic_qs_airplane_off;
    }

    @Override
    public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId,
            boolean activityIn, boolean activityOut,
@@ -85,8 +93,12 @@ public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignal

    @Override
    public void onAirplaneModeChanged(boolean enabled) {
        this.enabled = enabled;
        mEnabled = enabled;
        updateResources();
    }

    private void updateTile() {
        mLabel = mContext.getString(R.string.quick_settings_airplane_mode_label);
        mDrawable = mEnabled ? R.drawable.ic_qs_airplane_on : R.drawable.ic_qs_airplane_off;
    }
}
+24 −18
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013-2014 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.quicksettings;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.AlarmClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.phone.QuickSettingsContainerView;
import com.android.systemui.statusbar.phone.QuickSettingsController;

public class AlarmTile extends QuickSettingsTile {

    public AlarmTile(Context context, 
            QuickSettingsController qsc, Handler handler) {
    public AlarmTile(Context context, QuickSettingsController qsc) {
        super(context, qsc);

        mOnClick = new View.OnClickListener() {
@@ -45,17 +57,6 @@ public class AlarmTile extends QuickSettingsTile {
        super.updateResources();
    }

    private synchronized void updateTile() {
        mDrawable = R.drawable.ic_qs_alarm_on;
        mLabel = Settings.System.getStringForUser(mContext.getContentResolver(),
                Settings.System.NEXT_ALARM_FORMATTED, UserHandle.USER_CURRENT);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        updateResources();
    }

    @Override
    public void onChangeUri(ContentResolver resolver, Uri uri) {
        updateResources();
@@ -63,8 +64,13 @@ public class AlarmTile extends QuickSettingsTile {

    @Override
    public void updateQuickSettings() {
        mTile.setVisibility(!TextUtils.isEmpty(mLabel) ? View.VISIBLE : View.GONE);
        mTile.setVisibility(TextUtils.isEmpty(mLabel) ? View.GONE : View.VISIBLE);
        super.updateQuickSettings();
    }

    private void updateTile() {
        mDrawable = R.drawable.ic_qs_alarm_on;
        mLabel = Settings.System.getStringForUser(mContext.getContentResolver(),
                Settings.System.NEXT_ALARM_FORMATTED, UserHandle.USER_CURRENT);
    }
}
+38 −27
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013-2014 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.quicksettings;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;

import com.android.internal.view.RotationPolicy;
import com.android.systemui.R; 
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.phone.QuickSettingsContainerView;
import com.android.systemui.statusbar.phone.QuickSettingsController;

public class AutoRotateTile extends QuickSettingsTile {

    public AutoRotateTile(Context context, QuickSettingsController qsc, Handler handler) {
    public AutoRotateTile(Context context, QuickSettingsController qsc) {
        super(context, qsc);

        mOnClick = new OnClickListener() {
        mOnClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RotationPolicy.setRotationLock(mContext, getAutoRotation());
                RotationPolicy.setRotationLock(mContext, isAutoRotateEnabled());
            }
        };

        mOnLongClick = new OnLongClickListener() {
        mOnLongClick = new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                startSettingsActivity(Settings.ACTION_DISPLAY_SETTINGS);
                return true;
            }
        };
        qsc.registerObservedContent(Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION)
                , this);
        qsc.registerObservedContent(
                Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), this);
    }

    @Override
    public void updateResources() {
        updateTile();
        updateQuickSettings();
    }

    private synchronized void updateTile() {
        if(!getAutoRotation()){
            mDrawable = R.drawable.ic_qs_rotation_locked;
            mLabel = mContext.getString(R.string.quick_settings_rotation_locked_label);
        }else{
            mDrawable = R.drawable.ic_qs_auto_rotate;
            mLabel = mContext.getString(R.string.quick_settings_rotation_unlocked_label);
        }
        super.updateResources();
    }

    @Override
@@ -60,12 +61,22 @@ public class AutoRotateTile extends QuickSettingsTile {
        super.onPostCreate();
    }

    private boolean getAutoRotation() {
        return !RotationPolicy.isRotationLocked(mContext);
    }

    @Override
    public void onChangeUri(ContentResolver resolver, Uri uri) {
        updateResources();
    }

    private void updateTile() {
        if (isAutoRotateEnabled()) {
            mDrawable = R.drawable.ic_qs_auto_rotate;
            mLabel = mContext.getString(R.string.quick_settings_rotation_unlocked_label);
        } else {
            mDrawable = R.drawable.ic_qs_rotation_locked;
            mLabel = mContext.getString(R.string.quick_settings_rotation_locked_label);
        }
    }

    private boolean isAutoRotateEnabled() {
        return !RotationPolicy.isRotationLocked(mContext);
    }
}
+29 −17
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013-2014 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.quicksettings;

import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import com.android.systemui.BatteryMeterView;
import com.android.systemui.R;
import com.android.systemui.BatteryMeterView.BatteryMeterMode;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
@@ -44,13 +61,16 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange
        updateTile();
        mBatteryView = getBatteryMeterView();
        mBatteryView.setMode(BatteryMeterMode.BATTERY_METER_ICON_PORTRAIT);

        if (mQsc.isRibbonMode()) {
            boolean showPercent = Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.STATUS_BAR_BATTERY_SHOW_PERCENT, 0) == 1;
            boolean showPercent = Settings.System.getIntForUser(mContext.getContentResolver(),
                    Settings.System.STATUS_BAR_BATTERY_SHOW_PERCENT,
                    0, UserHandle.USER_CURRENT) == 1;
            mBatteryView.setShowPercent(showPercent);
        } else {
            mBatteryView.setShowPercent(false);
        }

        mController.addStateChangedCallback(this);
        super.onPostCreate();
    }
@@ -71,12 +91,12 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange

    @Override
    public void onBatteryMeterModeChanged(BatteryMeterMode mode) {
        // All the battery tiles (qs and ribbon) uses the NORMAL battery mode
        // All the battery tiles (qs and ribbon) use the NORMAL battery mode
    }

    @Override
    public void onBatteryMeterShowPercent(boolean showPercent) {
        // PowerWidget tile uses the same settings that status bar
        // PowerWidget tile uses the same settings as status bar
        if (mQsc.isRibbonMode()) {
            mBatteryView.setShowPercent(showPercent);
        }
@@ -97,18 +117,10 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange
        if (mBatteryLevel == 100) {
            mLabel = mContext.getString(R.string.quick_settings_battery_charged_label);
        } else {
            mLabel = mPluggedIn
                ? mContext.getString(R.string.quick_settings_battery_charging_label,
                        mBatteryLevel)
                : mContext.getString(R.string.status_bar_settings_battery_meter_format,
                        mBatteryLevel);
            int resId = mPluggedIn
                ? R.string.quick_settings_battery_charging_label
                : R.string.status_bar_settings_battery_meter_format;
            mLabel = mContext.getString(resId, mBatteryLevel);
        }
    }

    @Override
    void updateQuickSettings() {
        TextView tv = (TextView) mTile.findViewById(R.id.text);
        tv.setText(mLabel);
    }

}
+40 −26
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013-2014 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.quicksettings;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;

import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsController;
@@ -24,13 +37,14 @@ public class BluetoothTile extends QuickSettingsTile implements
    private BluetoothAdapter mBluetoothAdapter;
    private BluetoothController mController;

    public BluetoothTile(Context context, QuickSettingsController qsc, BluetoothController controller) {
    public BluetoothTile(Context context, QuickSettingsController qsc,
            BluetoothController controller) {
        super(context, qsc);

        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mController = controller;

        mOnClick = new OnClickListener() {
        mOnClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mEnabled) {
@@ -40,8 +54,7 @@ public class BluetoothTile extends QuickSettingsTile implements
                }
            }
        };

        mOnLongClick = new OnLongClickListener() {
        mOnLongClick = new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
@@ -72,14 +85,32 @@ public class BluetoothTile extends QuickSettingsTile implements
        super.updateResources();
    }

    void checkBluetoothState() {
    @Override
    public void onBluetoothStateChange(boolean on) {
        checkBluetoothState();
        updateResources();
    }

    @Override
    public void onDeviceConnectionStateChange(BluetoothDevice device) {
        updateResources();
    }

    @Override
    public void onDeviceNameChange(BluetoothDevice device) {
        if (mController.getConnectedBluetoothDevices().size() == 1) {
            updateResources();
        }
    }

    private void checkBluetoothState() {
        mEnabled = mBluetoothAdapter.isEnabled() &&
                mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON;
        mConnected = mEnabled &&
                mBluetoothAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED;
    }

    private synchronized void updateTile() {
    private void updateTile() {
        if (mEnabled) {
            if (mConnected) {
                final Set<BluetoothDevice> connected = mController.getConnectedBluetoothDevices();
@@ -108,21 +139,4 @@ public class BluetoothTile extends QuickSettingsTile implements
        }
    }

    @Override
    public void onBluetoothStateChange(boolean on) {
        checkBluetoothState();
        updateResources();
    }

    @Override
    public void onDeviceConnectionStateChange(BluetoothDevice device) {
        updateResources();
    }

    @Override
    public void onDeviceNameChange(BluetoothDevice device) {
        if (mController.getConnectedBluetoothDevices().size() == 1) {
            updateResources();
        }
    }
}
Loading