/*
* Copyright (C) 2015 MummyDing
*
* This file is part of Leisure( <https://github.com/MummyDing/Leisure> )
*
* Leisure 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.
* `
* Leisure 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 Leisure. If not, see <http://www.gnu.org/licenses/>.
*/
package com.mummyding.app.leisure.ui.setting;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.mummyding.app.leisure.R;
import com.mummyding.app.leisure.support.CONSTANT;
import com.mummyding.app.leisure.support.Settings;
import com.mummyding.app.leisure.support.Utils;
import com.mummyding.app.leisure.ui.support.SwipeBackActivity;
public class SettingsActivity extends SwipeBackActivity implements SensorEventListener {
private Toolbar toolbar;
private int mLang = -1;
private SensorManager mSensorManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Language
mLang = Utils.getCurrentLanguage();
if (mLang > -1) {
Utils.changeLanguage(this, mLang);
}
//set Theme
if(Settings.isNightMode){
this.setTheme(R.style.NightTheme);
}else{
this.setTheme(R.style.DayTheme);
}
Settings.swipeID = Settings.getInstance().getInt(Settings.SWIPE_BACK,0);
setContentView(R.layout.activity_settings);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.setting);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
getFragmentManager().beginTransaction().replace(R.id.framelayout,new SettingsFragment()).commit();
}
@Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onStop() {
mSensorManager.unregisterListener(this);
super.onStop();
}
@Override
protected void onPause() {
mSensorManager.unregisterListener(this);
super.onPause();
}
@Override
public void onSensorChanged(SensorEvent event) {
if(Settings.isShakeMode == false){
return;
}
float value[] = event.values;
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
if((Math.abs(value[0]) + Math.abs(value[1]) + Math.abs(value[2]))>CONSTANT.shakeValue){
onBackPressed();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}