1 package com.android.settings; 2 3 import android.content.ComponentName; 4 import android.content.Context; 5 import android.content.Intent; 6 import android.util.AttributeSet; 7 import android.view.View; 8 import android.view.ViewGroup; 9 10 /** 11 * An AppListPreference with optional settings button. 12 */ 13 public class AppListPreferenceWithSettings extends AppListPreference { 14 15 private View mSettingsIcon; 16 private ComponentName mSettingsComponent; 17 AppListPreferenceWithSettings(Context context, AttributeSet attrs)18 public AppListPreferenceWithSettings(Context context, AttributeSet attrs) { 19 super(context, attrs); 20 setWidgetLayoutResource(R.layout.preference_widget_settings); 21 } 22 23 @Override onBindView(View view)24 protected void onBindView(View view) { 25 super.onBindView(view); 26 27 mSettingsIcon = view.findViewById(R.id.settings_button); 28 mSettingsIcon.setOnClickListener(new View.OnClickListener() { 29 @Override 30 public void onClick(View v) { 31 Intent intent = new Intent(Intent.ACTION_MAIN); 32 intent.setComponent(mSettingsComponent); 33 getContext().startActivity(new Intent(intent)); 34 } 35 }); 36 37 ViewGroup container = (ViewGroup) mSettingsIcon.getParent(); 38 container.setPaddingRelative(0, 0, 0, 0); 39 40 updateSettingsVisibility(); 41 } 42 updateSettingsVisibility()43 private void updateSettingsVisibility() { 44 if (mSettingsIcon == null) { 45 return; 46 } 47 48 if (mSettingsComponent == null) { 49 mSettingsIcon.setVisibility(View.GONE); 50 } else { 51 mSettingsIcon.setVisibility(View.VISIBLE); 52 } 53 } 54 setSettingsComponent(ComponentName settings)55 protected void setSettingsComponent(ComponentName settings) { 56 mSettingsComponent = settings; 57 updateSettingsVisibility(); 58 } 59 } 60