/*
* Copyright 2014 Google Inc. All rights reserved.
*
* 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 org.starfishrespect.myconsumption.android.ui;
import android.content.ComponentName;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v4.content.IntentCompat;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import org.starfishrespect.myconsumption.android.R;
import org.starfishrespect.myconsumption.android.util.PrefUtils;
/**
* Activity for customizing app settings.
* S23Y (2015). Licensed under the Apache License, Version 2.0.
* Author: Thibaud Ledent
*/
public class SettingsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = getActionBarToolbar();
getSupportActionBar().setTitle(getString(R.string.title_settings));
toolbar.setNavigationIcon(R.drawable.ic_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigateUpToFromChild(SettingsActivity.this,
IntentCompat.makeMainActivity(new ComponentName(SettingsActivity.this,
ChartActivity.class)));
}
});
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new SettingsFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public void refreshData() {
}
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
public SettingsFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupSimplePreferencesScreen();
PrefUtils.registerOnSharedPreferenceChangeListener(getActivity(), this);
}
@Override
public void onDestroy() {
super.onDestroy();
PrefUtils.unregisterOnSharedPreferenceChangeListener(getActivity(), this);
}
private void setupSimplePreferencesScreen() {
// Add 'general' preferences.
addPreferencesFromResource(R.xml.preferences);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
}
}
}