package ru.olegsvs.custombatterynotification;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.util.Log;
import android.widget.TextView;

import static ru.olegsvs.custombatterynotification.BatteryManager.getValues;

public class SettingsActivity extends AppCompatActivity {
    public static String TAG = SettingsActivity.class.getSimpleName();

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

        TextView tvBattery = (TextView) findViewById(R.id.tvBattery);
//        if (BatteryManager.checkJSRSupport()) Log.w(TAG, "onCreate: " + "SUPPORT" );
        tvBattery.setText("BAT1 " +  BatteryManager.getValues(BatteryManager.SYS_BATTERY_CAPACITY) + "%\n"
                +BatteryManager.getValues(BatteryManager.SYS_BATTERY_STATUS) +
                "\nBAT2 " +  BatteryManager.getValues(BatteryManager.SYS_BATTERY_CAPACITY_JSR) + "%\n"
                +BatteryManager.getValues(BatteryManager.SYS_BATTERY_STATUS_JSR));
        Log.i(SettingsActivity.TAG, "onCreate: " + tvBattery.getText());
    /*    NotificationCompat.Builder mBuilder =
                (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                        .setSmallIcon(android.R.drawable.ic_menu_zoom)
                        .setContentTitle("Battery")
                        .setContentText("BAT1: null\nBAT2: null");
// Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, SettingsActivity.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(SettingsActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
        mNotificationManager.notify(444, mBuilder.build()); */
    }
}

@@ -169,32 +169,89 @@
 content.Intent;%0A
+import android.os.Handler;%0Aimport android.os.StrictMode;%0A
 import android.s
@@ -278,24 +278,24 @@
 ackBuilder;%0A
-
 import andro
@@ -849,16 +849,22 @@
         
+final 
 TextView
@@ -1388,82 +1388,13 @@
     
-Log.i(SettingsActivity.TAG, %22onCreate: %22 + tvBattery.getText());%0A    /*   
+final
  Not
@@ -1677,32 +1677,38 @@
 ext(
-%22BAT1: null%5CnBAT2: null%22
+tvBattery.getText().toString()
 );%0A/
@@ -2619,16 +2619,22 @@
         
+final 
 Notifica
@@ -2872,11 +2872,994 @@
 ());
- */
+%0A%0A        final Handler myHandler;%0A        myHandler = new Handler();%0A        Runnable runnable = new Runnable()%7B%0A%0A            @Override%0A            public void run() %7B%0A%0A                if(true) %7B%0A                    tvBattery.setText(%22BAT1 %22 + BatteryManager.getValues(BatteryManager.SYS_BATTERY_CAPACITY) + %22%25%5Cn%22%0A                            + BatteryManager.getValues(BatteryManager.SYS_BATTERY_STATUS) +%0A                            %22%5CnBAT2 %22 + BatteryManager.getValues(BatteryManager.SYS_BATTERY_CAPACITY_JSR) + %22%25%5Cn%22%0A                            + BatteryManager.getValues(BatteryManager.SYS_BATTERY_STATUS_JSR));%0A                    Log.i(SettingsActivity.TAG, %22onCreate: %22 + tvBattery.getText());%0A                    mBuilder.setContentText(tvBattery.getText());%0A                    mNotificationManager.notify(444, mBuilder.build());%0A                    myHandler.postDelayed(this, 2000);%0A                %7D%0A            %7D%0A%0A        %7D;%0A%0A        myHandler.postDelayed(runnable, 2000);
 %0A   

add test code for testing kernel every 2 sec (bad code)