// Path: app/src/main/java/com/kuahusg/weather/UI/Fragment/SettingFragment.java
// public class SettingFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
//     public static final String AUTO_UPDATE = "auto_update";
//     public static final String UPDATE_TIME = "update_time";
//     public static final String OPEN_SOURCE = "open_source";
//     public static final String ABOUT = "about";
//     public static final String UPDATE_APP = "update_app";
//     private SwitchPreference autoUpdatePreference;
//     private EditTextPreference updateTimePreference;
//     private Activity activity;
// 
// 
//     @Override
//     public void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         activity = getActivity();
// 
//         addPreferencesFromResource(R.xml.preference);
// 
// 
//         autoUpdatePreference = (SwitchPreference) findPreference(AUTO_UPDATE);
//         updateTimePreference = (EditTextPreference) findPreference(UPDATE_TIME);
//         autoUpdatePreference.setOnPreferenceChangeListener(this);
//         updateTimePreference.setOnPreferenceChangeListener(this);
// 
//         updateTimePreference.setEnabled(autoUpdatePreference.isChecked());
//     }
// 
// 
//     @Override
//     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
//         switch (preference.getKey()) {
//             case AUTO_UPDATE:
//                 updateTimePreference.setEnabled(autoUpdatePreference.isChecked());
//                 break;
//             case ABOUT:
//                 Intent intent = new Intent(activity, AboutMeActivity.class);
//                 activity.startActivity(intent);
//                 break;
//             case OPEN_SOURCE:
//                 Intent intent1 = new Intent(Intent.ACTION_VIEW);
//                 intent1.setData(Uri.parse("https://github.com/Kuanghusing/Weather"));
//                 activity.startActivity(intent1);
//                 break;
//             case UPDATE_APP:
//                 Intent i = new Intent(Intent.ACTION_VIEW);
//                 i.setData(Uri.parse("http://fir.im/eync"));
//                 startActivity(i);
//                 break;
//         }
//         return super.onPreferenceTreeClick(preferenceScreen, preference);
//     }
// 
// 
//     @Override
//     public boolean onPreferenceChange(Preference preference, Object newValue) {
//         Intent intent = new Intent(activity, AutoUpdateService.class);
//         LogUtil.v(this.toString(), "onPreferenceChange()");
//         if (preference.getKey().equals(SettingFragment.UPDATE_TIME)) {
//             LogUtil.v(this.toString(), "onPreferenceChange() -> UPDATE");
//             if (TextUtils.isEmpty((String) newValue)) {
//                 Toast.makeText(activity, activity.getString(R.string.no_value_error), Toast.LENGTH_LONG).show();
//                 return false;
//             }
//             activity.stopService(intent);
//             activity.startService(intent);
//         } else if (preference.getKey().equals(SettingFragment.AUTO_UPDATE)) {
//             LogUtil.v(this.toString(), "onPreferenceChange() -> AUTO");
// 
//             if ((boolean) newValue) {
//                 activity.startService(intent);
//             } else {
//                 activity.stopService(intent);
//             }
//         }
//         return true;
//     }
// 
// 
// }


import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.kuahusg.weather.R;
import com.kuahusg.weather.UI.Fragment.SettingFragment;
package com.kuahusg.weather.UI.activities;



/**
 * Created by kuahusg on 16-6-10.
 * com.kuahusg.weather.UI.activities
 */
public class SettingActivity extends AppCompatActivity {
    private Toolbar toolbar;

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        addPreferencesFromResource(R.xml.preference);
        setContentView(R.layout.activity_setting);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null) {
            actionbar.setDisplayHomeAsUpEnabled(true);
        }

/*
        ViewGroup viewRoot = (ViewGroup) findViewById(android.R.id.content);
        View content = viewRoot.getChildAt(0);

        LinearLayout toolbarLayout = (LinearLayout)LayoutInflater.from(this).inflate(R.layout.activity_setting, null);
        viewRoot.removeAllViews();
        toolbarLayout.addView(content);
        viewRoot.addView(toolbarLayout);*/

// Path: app/src/main/java/com/kuahusg/weather/UI/Fragment/SettingFragment.java
// public class SettingFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
//     public static final String AUTO_UPDATE = "auto_update";
//     public static final String UPDATE_TIME = "update_time";
//     public static final String OPEN_SOURCE = "open_source";
//     public static final String ABOUT = "about";
//     public static final String UPDATE_APP = "update_app";
//     private SwitchPreference autoUpdatePreference;
//     private EditTextPreference updateTimePreference;
//     private Activity activity;
// 
// 
//     @Override
//     public void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         activity = getActivity();
// 
//         addPreferencesFromResource(R.xml.preference);
// 
// 
//         autoUpdatePreference = (SwitchPreference) findPreference(AUTO_UPDATE);
//         updateTimePreference = (EditTextPreference) findPreference(UPDATE_TIME);
//         autoUpdatePreference.setOnPreferenceChangeListener(this);
//         updateTimePreference.setOnPreferenceChangeListener(this);
// 
//         updateTimePreference.setEnabled(autoUpdatePreference.isChecked());
//     }
// 
// 
//     @Override
//     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
//         switch (preference.getKey()) {
//             case AUTO_UPDATE:
//                 updateTimePreference.setEnabled(autoUpdatePreference.isChecked());
//                 break;
//             case ABOUT:
//                 Intent intent = new Intent(activity, AboutMeActivity.class);
//                 activity.startActivity(intent);
//                 break;
//             case OPEN_SOURCE:
//                 Intent intent1 = new Intent(Intent.ACTION_VIEW);
//                 intent1.setData(Uri.parse("https://github.com/Kuanghusing/Weather"));
//                 activity.startActivity(intent1);
//                 break;
//             case UPDATE_APP:
//                 Intent i = new Intent(Intent.ACTION_VIEW);
//                 i.setData(Uri.parse("http://fir.im/eync"));
//                 startActivity(i);
//                 break;
//         }
//         return super.onPreferenceTreeClick(preferenceScreen, preference);
//     }
// 
// 
//     @Override
//     public boolean onPreferenceChange(Preference preference, Object newValue) {
//         Intent intent = new Intent(activity, AutoUpdateService.class);
//         LogUtil.v(this.toString(), "onPreferenceChange()");
//         if (preference.getKey().equals(SettingFragment.UPDATE_TIME)) {
//             LogUtil.v(this.toString(), "onPreferenceChange() -> UPDATE");
//             if (TextUtils.isEmpty((String) newValue)) {
//                 Toast.makeText(activity, activity.getString(R.string.no_value_error), Toast.LENGTH_LONG).show();
//                 return false;
//             }
//             activity.stopService(intent);
//             activity.startService(intent);
//         } else if (preference.getKey().equals(SettingFragment.AUTO_UPDATE)) {
//             LogUtil.v(this.toString(), "onPreferenceChange() -> AUTO");
// 
//             if ((boolean) newValue) {
//                 activity.startService(intent);
//             } else {
//                 activity.stopService(intent);
//             }
//         }
//         return true;
//     }
// 
// 
// }


// Path: app/src/main/java/com/kuahusg/weather/UI/activities/SettingActivity.java
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.kuahusg.weather.R;
import com.kuahusg.weather.UI.Fragment.SettingFragment;

package com.kuahusg.weather.UI.activities;



/**
 * Created by kuahusg on 16-6-10.
 * com.kuahusg.weather.UI.activities
 */
public class SettingActivity extends AppCompatActivity {
    private Toolbar toolbar;

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        addPreferencesFromResource(R.xml.preference);
        setContentView(R.layout.activity_setting);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null) {
            actionbar.setDisplayHomeAsUpEnabled(true);
        }

/*
        ViewGroup viewRoot = (ViewGroup) findViewById(android.R.id.content);
        View content = viewRoot.getChildAt(0);

        LinearLayout toolbarLayout = (LinearLayout)LayoutInflater.from(this).inflate(R.layout.activity_setting, null);
        viewRoot.removeAllViews();
        toolbarLayout.addView(content);
        viewRoot.addView(toolbarLayout);*/

        getFragmentManager().beginTransaction().replace(R.id.setting_part, new SettingFragment()).commit();