Files
app_Settings/src/com/android/settings/nfc/AndroidBeam.java
Fabrice Di Meglio 072d98aba6 Use SwitchBar for Android Beam Settings
- follow up CL to 4193776698

Related to bug #14898161 On/Off switches must move down from Action Bar

Change-Id: I2e3ffb34a589b32deda9de19107f38041aa341c9
2014-05-15 15:00:19 -07:00

91 lines
2.8 KiB
Java

/*
* Copyright (C) 2011 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.settings.nfc;
import android.app.Fragment;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.widget.SwitchBar;
public class AndroidBeam extends Fragment
implements SwitchBar.OnSwitchChangeListener {
private View mView;
private NfcAdapter mNfcAdapter;
private SwitchBar mSwitchBar;
private Switch mSwitch;
private CharSequence mOldActivityTitle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingsActivity activity = (SettingsActivity) getActivity();
mOldActivityTitle = activity.getActionBar().getTitle();
activity.getActionBar().setTitle(R.string.android_beam_settings_title);
mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
mSwitchBar = activity.getSwitchBar();
mSwitch = mSwitchBar.getSwitch();
mSwitch.setChecked(mNfcAdapter.isNdefPushEnabled());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.android_beam, container, false);
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
mSwitch.setChecked(mNfcAdapter.isNdefPushEnabled());
return mView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mSwitchBar.removeOnSwitchChangeListener(this);
mSwitchBar.hide();
if (mOldActivityTitle != null) {
getActivity().getActionBar().setTitle(mOldActivityTitle);
}
}
@Override
public void onSwitchChanged(Switch switchView, boolean desiredState) {
boolean success = false;
mSwitch.setEnabled(false);
if (desiredState) {
success = mNfcAdapter.enableNdefPush();
} else {
success = mNfcAdapter.disableNdefPush();
}
if (success) {
mSwitch.setChecked(desiredState);
}
mSwitch.setEnabled(true);
}
}