blob: c75be1374cb1ffcd49ab8f66ac2cda9ffccb0f4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package com.android.settings;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.Map;
/**
* This class extends Preference to display bluetooth status icons. One
* icon specifies the connection/pairing status that is right-aligned.
* An optional headset icon can be added to its left as well.
*/
public class BluetoothListItem extends Preference {
private boolean mIsHeadset;
private int mWeight;
public BluetoothListItem(Context context, AttributeSet attrs) {
super(context, attrs);
setWidgetLayoutResource(R.layout.preference_widget_btdevice_status);
}
private void updateIcons(View view) {
ImageView headsetView = (ImageView) view.findViewById(R.id.device_headset);
headsetView.setVisibility(mIsHeadset ? View.VISIBLE : View.GONE);
}
@Override
public void onBindView(View view) {
super.onBindView(view);
updateIcons(view);
}
/**
* Set whether the device is of headset type
* @param headset whether or not the headset icon should be shown
*/
public void setHeadset(boolean headset) {
mIsHeadset = headset;
notifyChanged();
}
/**
* Sets the weight for ordering by signal strength or importance
* @param weight the ordering weight
*/
public void setWeight(int weight) {
mWeight = weight;
}
/**
* Returns the currently set ordering weight
* @return the current ordering weight
*/
public int getWeight() {
return mWeight;
}
@Override
public int compareTo(Preference another) {
int diff = ((BluetoothListItem)another).mWeight - mWeight;
// Let the new one be after the old one, if they are the same weight
// TODO: Implement a more reliable way to consistently order items of
// the same weight
if (diff == 0) diff = 1;
return diff;
}
}
|