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

Commit 1e28f411 authored by Joe Onorato's avatar Joe Onorato
Browse files

Brightness and volume controls in the quick settings panel.

Change-Id: I2d2394c84a2783772f16dbeb88664381917e0ead
parent df7cc31a
Loading
Loading
Loading
Loading
+1.44 KiB
Loading image diff...
+12 −0
Original line number Diff line number Diff line
@@ -104,6 +104,12 @@
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/ic_sysbar_brightness"
                />
        <com.android.systemui.statusbar.policy.ToggleSlider
                android:id="@+id/brightness"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

@@ -114,6 +120,12 @@
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/ic_sysbar_sound_on"
                />
        <com.android.systemui.statusbar.policy.ToggleSlider
                android:id="@+id/volume"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

+52 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * Copyright (C) 2010 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.
-->

<!--    android:background="@drawable/status_bar_closed_default_background" -->
<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
    >
    <ToggleButton
        android:id="@+id/toggle"
        android:layout_width="48dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        />
    <view
        class="com.android.systemui.statusbar.policy.ToggleSlider$Slider"
        android:id="@+id/slider"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/toggle"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:paddingLeft="20dp"
        />
        <!--
    <TextView
        android:id="@+id/label"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_alignLeft="@id/toggle"
        android:layout_alignRight="@id/toggle"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/toggle"
        android:gravity="center"
        />
        -->
</merge>
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.systemui.statusbar.policy;

import android.content.ContentResolver;
import android.content.Context;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Slog;
import android.view.IWindowManager;
import android.widget.CompoundButton;

public class BrightnessController implements ToggleSlider.Listener {
    private static final String TAG = "StatusBar.BrightnessController";

    // Backlight range is from 0 - 255. Need to make sure that user
    // doesn't set the backlight to 0 and get stuck
    private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10;
    private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON;

    private Context mContext;
    private ToggleSlider mControl;
    private IPowerManager mPower;

    public BrightnessController(Context context, ToggleSlider control) {
        mContext = context;
        mControl = control;

        boolean automaticAvailable = context.getResources().getBoolean(
                com.android.internal.R.bool.config_automatic_brightness_available);
        mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));

        if (automaticAvailable) {
            int automatic;
            try {
                automatic = Settings.System.getInt(mContext.getContentResolver(),
                        Settings.System.SCREEN_BRIGHTNESS_MODE);
            } catch (SettingNotFoundException snfe) {
                automatic = 0;
            }
            control.setChecked(automatic != 0);
        } else {
            control.setChecked(false);
            //control.hideToggle();
        }
        
        int value;
        try {
            value = Settings.System.getInt(mContext.getContentResolver(), 
                    Settings.System.SCREEN_BRIGHTNESS);
        } catch (SettingNotFoundException ex) {
            value = MAXIMUM_BACKLIGHT;
        }

        control.setMax(MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT);
        control.setValue(value - MINIMUM_BACKLIGHT);

        control.setOnChangedListener(this);
    }

    public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) {
        setMode(automatic ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
                : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        if (!automatic) {
            setBrightness(value + MINIMUM_BACKLIGHT);
        }
    }

    private void setMode(int mode) {
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE, mode);
    }
    
    private void setBrightness(int brightness) {
        try {
            mPower.setBacklightBrightness(brightness);
        } catch (RemoteException ex) {
        }        
    }
}
+144 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.systemui.statusbar.policy;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.android.systemui.R;

public class ToggleSlider extends RelativeLayout 
        implements CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener {
    private static final String TAG = "StatusBar.ToggleSlider";

    public interface Listener {
        public void onChanged(ToggleSlider v, boolean tracking, boolean checked, int value);
    }

    public static class Slider extends SeekBar {
        public Slider(Context context) {
            this(context, null);
        }

        public Slider(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public Slider(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    }

    private Listener mListener;
    private boolean mTracking;

    private ToggleButton mToggle;
    private SeekBar mSlider;
    private TextView mLabel;

    public ToggleSlider(Context context) {
        this(context, null);
    }

    public ToggleSlider(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ToggleSlider(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        View.inflate(context, R.layout.status_bar_toggle_slider, this);

        mToggle = (ToggleButton)findViewById(R.id.toggle);
        mToggle.setOnCheckedChangeListener(this);
        mToggle.setTextOn("hi");
        mToggle.setTextOff("hi");

        mSlider = (SeekBar)findViewById(R.id.slider);
        mSlider.setOnSeekBarChangeListener(this);

        /*
        mLabel = (TextView)findViewById(R.id.label);
        mLabel.setText("yo");
        */
    }

    public void onCheckedChanged(CompoundButton toggle, boolean checked) {
        Drawable thumb;
        final Resources res = getContext().getResources();
        if (checked) {
            thumb = res.getDrawable(R.drawable.scrubber_control_disabled_holo);
        } else {
            thumb = res.getDrawable(com.android.internal.R.drawable.scrubber_control_holo);
        }
        mSlider.setThumb(thumb);

        if (mListener != null) {
            mListener.onChanged(this, mTracking, checked, mSlider.getProgress());
        }
    }

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (mListener != null) {
            mListener.onChanged(this, mTracking, mToggle.isChecked(), progress);
        }
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
        mTracking = true;
        if (mListener != null) {
            mListener.onChanged(this, mTracking, mToggle.isChecked(), mSlider.getProgress());
        }
        mToggle.setChecked(false);
    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        mTracking = false;
        if (mListener != null) {
            mListener.onChanged(this, mTracking, mToggle.isChecked(), mSlider.getProgress());
        }
    }

    public void setOnChangedListener(Listener l) {
        mListener = l;
    }

    public void setChecked(boolean checked) {
        mToggle.setChecked(checked);
    }

    public boolean isChecked() {
        return mToggle.isChecked();
    }

    public void setMax(int max) {
        mSlider.setMax(max);
    }

    public void setValue(int value) {
        mSlider.setProgress(value);
    }
}
Loading