/*
* Author: Balch
* Created: 8/19/16 11:42 AM
*
* This file is part of MockTrade.
*
* MockTrade is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MockTrade is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MockTrade. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2016
*
*/
package com.balch.mocktrade.settings;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.balch.mocktrade.BuildConfig;
import com.balch.mocktrade.R;
import com.balch.mocktrade.services.WearSyncService;
import com.balch.mocktrade.shared.utils.VersionUtils;
public class WearSettingsActivity extends AppCompatActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.settings_view_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
getFragmentManager().beginTransaction().replace(R.id.settings_view_content_frame, new WearSettingsPreferenceFragment()).commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
startService(WearSyncService.getIntent(this, true, true, true, false));
}
@Override
public void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
public static class WearSettingsPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.wear_settings_pref_screen);
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("settings_version");
preferenceGroup.setTitle("Version: " + VersionUtils.getVersion(this.getActivity(), BuildConfig.DEBUG));
}
}
}