diff options
author | Alan Viverette <alanv@google.com> | 2014-04-08 15:27:24 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-04-08 15:27:24 -0700 |
commit | f6a679870f6e0cb9c4327e2b89049f3bd8893448 (patch) | |
tree | 34cd13b912fbe7f578f538c0608283ca5a42dd58 /packages/SystemUI/src/com/android/systemui/settings | |
parent | 9e0ca634e2201c2f633f2e82b8c86fc689669e0b (diff) | |
download | frameworks_base-f6a679870f6e0cb9c4327e2b89049f3bd8893448.zip frameworks_base-f6a679870f6e0cb9c4327e2b89049f3bd8893448.tar.gz frameworks_base-f6a679870f6e0cb9c4327e2b89049f3bd8893448.tar.bz2 |
Make toggle slider use default assets
BUG: 13817697
Change-Id: Ibae671a35b55a195b40d8c943f45685fb7b3ac4f
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/settings')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/settings/ToggleSeekBar.java | 45 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java | 98 |
2 files changed, 101 insertions, 42 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/ToggleSeekBar.java b/packages/SystemUI/src/com/android/systemui/settings/ToggleSeekBar.java new file mode 100644 index 0000000..a0a5561 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/settings/ToggleSeekBar.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 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.settings; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.widget.SeekBar; + +public class ToggleSeekBar extends SeekBar { + public ToggleSeekBar(Context context) { + super(context); + } + + public ToggleSeekBar(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ToggleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (!isEnabled()) { + setEnabled(true); + } + + return super.onTouchEvent(event); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java b/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java index c99f691..7d38058 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java +++ b/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java @@ -19,20 +19,18 @@ package com.android.systemui.settings; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.RelativeLayout; import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import com.android.systemui.R; -public class ToggleSlider extends RelativeLayout - implements CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener { - private static final String TAG = "StatusBar.ToggleSlider"; - +public class ToggleSlider extends RelativeLayout { public interface Listener { public void onInit(ToggleSlider v); public void onChanged(ToggleSlider v, boolean tracking, boolean checked, int value); @@ -55,20 +53,21 @@ public class ToggleSlider extends RelativeLayout public ToggleSlider(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + View.inflate(context, R.layout.status_bar_toggle_slider, this); final Resources res = context.getResources(); - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ToggleSlider, - defStyle, 0); + final TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.ToggleSlider, defStyle, 0); - mToggle = (CompoundButton)findViewById(R.id.toggle); - mToggle.setOnCheckedChangeListener(this); - mToggle.setBackgroundDrawable(res.getDrawable(R.drawable.status_bar_toggle_button)); + mToggle = (CompoundButton) findViewById(R.id.toggle); + mToggle.setOnCheckedChangeListener(mCheckListener); + mToggle.setBackground(res.getDrawable(R.drawable.status_bar_toggle_button)); - mSlider = (SeekBar)findViewById(R.id.slider); - mSlider.setOnSeekBarChangeListener(this); + mSlider = (SeekBar) findViewById(R.id.slider); + mSlider.setOnSeekBarChangeListener(mSeekListener); - mLabel = (TextView)findViewById(R.id.label); + mLabel = (TextView) findViewById(R.id.label); mLabel.setText(a.getString(R.styleable.ToggleSlider_text)); a.recycle(); @@ -82,35 +81,6 @@ public class ToggleSlider extends RelativeLayout } } - public void onCheckedChanged(CompoundButton toggle, boolean checked) { - mSlider.setEnabled(checked); - - 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; } @@ -130,5 +100,49 @@ public class ToggleSlider extends RelativeLayout public void setValue(int value) { mSlider.setProgress(value); } + + private final OnCheckedChangeListener mCheckListener = new OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton toggle, boolean checked) { + mSlider.setEnabled(!checked); + + if (mListener != null) { + mListener.onChanged( + ToggleSlider.this, mTracking, checked, mSlider.getProgress()); + } + } + }; + + private final OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (mListener != null) { + mListener.onChanged( + ToggleSlider.this, mTracking, mToggle.isChecked(), progress); + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + mTracking = true; + + if (mListener != null) { + mListener.onChanged( + ToggleSlider.this, mTracking, mToggle.isChecked(), mSlider.getProgress()); + } + + mToggle.setChecked(false); + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + mTracking = false; + + if (mListener != null) { + mListener.onChanged( + ToggleSlider.this, mTracking, mToggle.isChecked(), mSlider.getProgress()); + } + } + }; } |