blob: bbbd3325aa93d56a2f9fb23b48ff20507aba9460 (
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
|
package com.android.settings;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/**
* An AppListPreference with optional settings button.
*/
public class AppListPreferenceWithSettings extends AppListPreference {
private View mSettingsIcon;
private ComponentName mSettingsComponent;
public AppListPreferenceWithSettings(Context context, AttributeSet attrs) {
super(context, attrs);
setWidgetLayoutResource(R.layout.preference_widget_settings);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
mSettingsIcon = view.findViewById(R.id.settings_button);
mSettingsIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(mSettingsComponent);
getContext().startActivity(new Intent(intent));
}
});
ViewGroup container = (ViewGroup) mSettingsIcon.getParent();
container.setPaddingRelative(0, 0, 0, 0);
updateSettingsVisibility();
}
private void updateSettingsVisibility() {
if (mSettingsIcon == null) {
return;
}
if (mSettingsComponent == null) {
mSettingsIcon.setVisibility(View.GONE);
} else {
mSettingsIcon.setVisibility(View.VISIBLE);
}
}
protected void setSettingsComponent(ComponentName settings) {
mSettingsComponent = settings;
updateSettingsVisibility();
}
}
|