1010import android .content .Intent ;
1111import android .content .SharedPreferences ;
1212import android .content .pm .PackageManager ;
13- import android .net .Uri ;
1413import android .os .Build ;
15- import android .os .PowerManager ;
1614import android .preference .PreferenceManager ;
17- import android .provider .Settings ;
1815import android .util .Log ;
1916
2017import java .util .Calendar ;
2118import java .util .Date ;
22- import java .util .Arrays ;
2319
2420import androidx .core .app .ActivityCompat ;
2521import androidx .core .content .ContextCompat ;
2622
2723import static android .Manifest .permission .ACTIVITY_RECOGNITION ;
28- import static androidx .core .app .ActivityCompat .requestPermissions ;
2924
3025public final class Bridge extends Application {
3126 static int summarySteps ;
@@ -34,10 +29,10 @@ public final class Bridge extends Application {
3429 static Activity myActivity ;
3530 static Context appContext ;
3631 Date currentDate ;
37- static final String STEPS = "steps" ;
38- static final String SUMMARY_STEPS = "summarySteps" ;
39- static final String DATE = "currentDate" ;
40- static final String INIT_DATE = "initialDate" ;
32+ static final String STEPS = "steps" ;
33+ static final String SUMMARY_STEPS = "summarySteps" ;
34+ static final String DATE = "currentDate" ;
35+ static final String INIT_DATE = "initialDate" ;
4136 public static final Intent [] POWERMANAGER_INTENTS = new Intent []{
4237 new Intent ().setComponent (new ComponentName ("com.miui.securitycenter" , "com.miui.permcenter.autostart.AutoStartManagementActivity" )),
4338 new Intent ().setComponent (new ComponentName ("com.letv.android.letvsafe" , "com.letv.android.letvsafe.AutobootManageActivity" )),
@@ -57,8 +52,10 @@ public final class Bridge extends Application {
5752
5853 public static void ReceiveActivityInstance (Activity tempActivity ) {
5954 myActivity = tempActivity ;
60- String [] perms = new String [1 ];
61- perms [0 ]=Manifest .permission .ACTIVITY_RECOGNITION ;
55+ String [] perms = new String [1 ];
56+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
57+ perms [0 ] = ACTIVITY_RECOGNITION ;
58+ }
6259 if (ContextCompat .checkSelfPermission (myActivity , Manifest .permission .ACTIVITY_RECOGNITION )
6360 != PackageManager .PERMISSION_GRANTED ) {
6461 Log .i ("PEDOMETER" , "Permision isnt granted!" );
@@ -90,57 +87,58 @@ public void onClick(DialogInterface dialog, int which) {
9087 }
9188 }
9289 start ();
93- }
94- else {
90+ } else {
9591 start ();
9692 }
9793 }
9894
99- private static void start (){
95+ private static void start () {
10096 myActivity .startForegroundService (new Intent (myActivity , PedometerService .class ));
10197
10298 }
103- public static void StopService (){
99+
100+ public static void StopService () {
104101 Intent serviceIntent = new Intent (myActivity , PedometerService .class );
105102 myActivity .stopService (serviceIntent );
106-
107103 }
108- public static int GetCurrentSteps (){
104+
105+ public static int GetCurrentSteps () {
109106 SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences (appContext );
110107 SharedPreferences .Editor editor = sharedPreferences .edit ();
111108 Date currentDate = Calendar .getInstance ().getTime ();
112109 editor .putString (DATE , currentDate .toString ());
113110 int walkedSteps = sharedPreferences .getInt (STEPS , 0 );
114- int allSteps = sharedPreferences .getInt (SUMMARY_STEPS ,0 );
115- summarySteps = walkedSteps + allSteps ;
116- Log .i ("PEDOMETER" , "FROM BRIDGE CLASS - GetCurrentSteps:" + summarySteps );
111+ int allSteps = sharedPreferences .getInt (SUMMARY_STEPS , 0 );
112+ summarySteps = walkedSteps + allSteps ;
113+ Log .i ("PEDOMETER" , "FROM BRIDGE CLASS - GetCurrentSteps:" + summarySteps );
117114 return summarySteps ;
118115 }
119- public static String SyncData (){
116+
117+ public static String SyncData () {
120118 SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences (appContext );
121- int stepsToSend = GetCurrentSteps ();
122- String firstDate = sharedPreferences .getString (INIT_DATE ,"" );
123- String lastDate = sharedPreferences .getString (DATE ,"" );
124- String data = firstDate + '#' + lastDate + '#' + stepsToSend ;
119+ int stepsToSend = GetCurrentSteps ();
120+ String firstDate = sharedPreferences .getString (INIT_DATE , "" );
121+ String lastDate = sharedPreferences .getString (DATE , "" );
122+ String data = firstDate + '#' + lastDate + '#' + stepsToSend ;
125123 SharedPreferences .Editor editor = sharedPreferences .edit ();
126- editor .putInt (STEPS ,0 );
127- editor .putInt (SUMMARY_STEPS ,0 );
128- steps = 0 ;
129- summarySteps = 0 ;
130- initialSteps = 0 ;
124+ editor .putInt (STEPS , 0 );
125+ editor .putInt (SUMMARY_STEPS , 0 );
126+ steps = 0 ;
127+ summarySteps = 0 ;
128+ initialSteps = 0 ;
131129 Date currentDate = Calendar .getInstance ().getTime ();
132- editor .putString (INIT_DATE ,currentDate .toString ());
133- editor .putString (DATE ,currentDate .toString ());
130+ editor .putString (INIT_DATE , currentDate .toString ());
131+ editor .putString (DATE , currentDate .toString ());
134132 editor .apply ();
135- Log .i ("PEDOMETER" , "SyncData: " + steps + ' ' + summarySteps + data );
133+ Log .i ("PEDOMETER" , "SyncData: " + steps + ' ' + summarySteps + data );
136134 return data ;
137135 }
138136
139137
140138 @ Override
141139 public void onCreate () {
142140 super .onCreate ();
143- Bridge .appContext = getApplicationContext ();
141+ Bridge .appContext = getApplicationContext ();
144142
145143 }
146144}
0 commit comments