File tree Expand file tree Collapse file tree 1 file changed +31
-4
lines changed
Expand file tree Collapse file tree 1 file changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ allprojects {
1616}
1717
1818dependencies {
19- compile 'com.github.safetysystemtechnology:android-shake-detector:v1.0 '
19+ compile 'com.github.safetysystemtechnology:android-shake-detector:v1.2 '
2020}
2121
2222```
@@ -47,19 +47,46 @@ protected void onCreate(Bundle savedInstanceState) {
4747 super . onCreate(savedInstanceState);
4848 setContentView(R . layout. activity_main);
4949
50+ buildView();
51+
5052 ShakeOptions options = new ShakeOptions ()
5153 .background(true )
52- .interval(2000 )
54+ .interval(1000 )
5355 .shakeCount(2 )
54- .sensibility(1.2f );
56+ .sensibility(2.0f );
5557
5658 this . shakeDetector = new ShakeDetector (options). start(this , new ShakeCallback () {
5759 @Override
5860 public void onShake () {
59- ...
61+ Log . d(" event" , " onShake" );
62+ }
63+ });
64+
65+ // IF YOU WANT JUST IN BACKGROUND
66+ // this.shakeDetector = new ShakeDetector(options).start(this);
67+ }
68+
69+ private void buildView() {
70+ Button btnStopService = (Button ) findViewById(R . id. btnStopService);
71+ btnStopService. setOnClickListener(new View .OnClickListener () {
72+ @Override
73+ public void onClick (View v ) {
74+ Log . d(" destroy" , " destroy service shake" );
75+ shakeDetector. stopShakeDetector(getBaseContext());
6076 }
6177 });
6278}
79+
80+ @Override
81+ protected void onStop() {
82+ super . onStop();
83+ }
84+
85+ @Override
86+ protected void onDestroy() {
87+ shakeDetector. destroy(getBaseContext());
88+ super . onDestroy();
89+ }
6390```
6491if you will run in background, create your broadcast receiver
6592
You can’t perform that action at this time.
0 commit comments