Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.settings.bluetooth;
     18 
     19 import android.app.Fragment;
     20 import android.content.Context;
     21 import android.support.annotation.VisibleForTesting;
     22 import android.support.v7.preference.Preference;
     23 
     24 import com.android.internal.logging.nano.MetricsProto;
     25 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
     26 import com.android.settings.overlay.FeatureFactory;
     27 import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
     28 import com.android.settingslib.core.lifecycle.Lifecycle;
     29 
     30 public class BluetoothDeviceRenamePreferenceController extends
     31         BluetoothDeviceNamePreferenceController {
     32 
     33     public static final String PREF_KEY = "bt_rename_device";
     34 
     35     private final Fragment mFragment;
     36     private MetricsFeatureProvider mMetricsFeatureProvider;
     37 
     38     public BluetoothDeviceRenamePreferenceController(Context context, Fragment fragment,
     39             Lifecycle lifecycle) {
     40         super(context, lifecycle);
     41         mFragment = fragment;
     42         mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     43     }
     44 
     45     @VisibleForTesting
     46     BluetoothDeviceRenamePreferenceController(Context context, Fragment fragment,
     47             LocalBluetoothAdapter localAdapter) {
     48         super(context, localAdapter);
     49         mFragment = fragment;
     50         mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     51     }
     52 
     53     @Override
     54     public String getPreferenceKey() {
     55         return PREF_KEY;
     56     }
     57 
     58     @Override
     59     protected void updateDeviceName(final Preference preference, final String deviceName) {
     60         preference.setSummary(deviceName);
     61     }
     62 
     63     @Override
     64     public boolean handlePreferenceTreeClick(Preference preference) {
     65         if (PREF_KEY.equals(preference.getKey())) {
     66             mMetricsFeatureProvider.action(mContext,
     67                     MetricsProto.MetricsEvent.ACTION_BLUETOOTH_RENAME);
     68             LocalDeviceNameDialogFragment.newInstance()
     69                     .show(mFragment.getFragmentManager(), LocalDeviceNameDialogFragment.TAG);
     70             return true;
     71         }
     72 
     73         return false;
     74     }
     75 }
     76