package com.jackwink.tweakabledemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.jackwink.tweakable.controls.TweaksFragment;
import com.jackwink.tweakable.generators.java.PreferenceCategoryBuilder;
import com.jackwink.tweakable.generators.java.PreferenceScreenBuilder;
import com.squareup.seismic.ShakeDetector;


public class MainActivity extends Activity implements ShakeDetector.Listener {
    private static final String TAG = MainActivity.class.getSimpleName();

    TextView featureFlagView;
    TextView featureFlag2View;
    TextView featureFlag3View;
    TextView featureFlag4View;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        featureFlagView = (TextView) findViewById(R.id.featureFlagView);
        featureFlag2View = (TextView) findViewById(R.id.featureFlag2View);
        featureFlag3View = (TextView) findViewById(R.id.featureFlag3View);
        featureFlag4View = (TextView) findViewById(R.id.featureFlag4View);
        hearShake();
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onResume() {
        super.onResume();
        featureFlagView.setText("featureFlag: " + Settings.featureFlag);
        featureFlag2View.setText("featureFlag2: " + Settings.featureFlag2);
        featureFlag3View.setText("featureFlag3: " + Settings.featureFlag3);
        featureFlag4View.setText("featureFlag4: " + Settings.featureFlag4);
    }

    @Override
    public void hearShake() {
        Log.i(TAG, "Shake!");
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsIntent);
    }

}

@@ -118,24 +118,63 @@
 ent.Intent;%0A
+import android.hardware.SensorManager;%0A
 import andro
@@ -1159,16 +1159,50 @@
 4View;%0A%0A
+    ShakeDetector shakeDetector;%0A%0A
     @Ove
@@ -1655,24 +1655,26 @@
 4View);%0A
+%0A%0A
         
 hearShak
@@ -1669,29 +1669,58 @@
     
-hearShake(
+shakeDetector = new ShakeDetector(this
 );%0A
+%0A
     %7D%0A%0A%0A
 %0A   
@@ -1715,16 +1715,120 @@
     %7D%0A%0A%0A
+    @Override%0A    public void onPause() %7B%0A        super.onPause();%0A        shakeDetector.stop();%0A    %7D%0A%0A
 %0A    @Ov
@@ -2918,16 +2918,149 @@
 eFlag4);
+%0A%0A        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);%0A        shakeDetector.start(sensorManager);
 %0A    %7D%0A%0A
@@ -3133,16 +3133,46 @@
 ake!%22);%0A
+        shakeDetector.stop();%0A
         

fix shake listener