package {{ args.package }};

import android.content.Intent;
import android.content.Context;
import android.app.Notification;
import android.app.PendingIntent;
import android.os.Bundle;
import org.kivy.android.PythonService;
import org.kivy.android.PythonActivity;


public class Service{{ name|capitalize }} extends PythonService {
    {% if sticky %}
    @Override
    public int startType() {
        return START_STICKY;
    }
    {% endif %}

    {% if not foreground %}
    @Override
    public boolean canDisplayNotification() {
        return false;
    }
    {% endif %}

    @Override
    protected void doStartForeground(Bundle extras) {
        Context context = getApplicationContext();
        Notification notification = new Notification(context.getApplicationInfo().icon,
            "{{ args.name }}", System.currentTimeMillis());
        Intent contextIntent = new Intent(context, PythonActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(context, "{{ args.name }}", "{{ name| capitalize }}", pIntent);
        startForeground({{ service_id }}, notification);
    }

    static public void start(Context ctx, String pythonServiceArgument) {
        Intent intent = new Intent(ctx, Service{{ name|capitalize }}.class);
        String argument = ctx.getFilesDir().getAbsolutePath();
        intent.putExtra("androidPrivate", argument);
        intent.putExtra("androidArgument", argument);
        intent.putExtra("serviceEntrypoint", "{{ entrypoint }}");
        intent.putExtra("pythonName", "{{ name }}");
        intent.putExtra("pythonHome", argument);
        intent.putExtra("pythonPath", argument + ":" + argument + "/lib");
        intent.putExtra("pythonServiceArgument", pythonServiceArgument);
        ctx.startService(intent);
    }

    static public void stop(Context ctx) {
        Intent intent = new Intent(ctx, Service{{ name|capitalize }}.class);
        ctx.stopService(intent);
    }
}

@@ -96,171 +96,38 @@
 ort 
-android.app.Notification;%0Aimport android.app.PendingIntent;%0Aimport android.os.Bundle;%0Aimport org.kivy.android.PythonService;%0Aimport org.kivy.android.PythonActivity
+org.kivy.android.PythonService
 ;%0A%0A%0A
@@ -208,24 +208,61 @@
 f sticky %25%7D%0A
+    /**%0A     * %7B@inheritDoc%7D%0A     */%0A
     @Overrid
@@ -368,24 +368,61 @@
 reground %25%7D%0A
+    /**%0A     * %7B@inheritDoc%7D%0A     */%0A
     @Overrid
@@ -522,719 +522,137 @@
     
-@Override%0A    protected void doStartForeground(Bundle extras) %7B%0A        Context context = getApplicationContext();%0A        Notification notification = new Notification(context.getApplicationInfo().icon,%0A            %22%7B%7B args.name %7D%7D%22, System.currentTimeMillis());%0A        Intent contextIntent = new Intent(context, PythonActivity.class);%0A        PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,%0A            PendingIntent.FLAG_UPDATE_CURRENT);%0A        notification.setLatestEventInfo(context, %22%7B%7B args.name %7D%7D%22, %22%7B%7B name%7C capitalize %7D%7D%22, pIntent);%0A        startForeground(%7B%7B service_id %7D%7D, notification);%0A    %7D%0A%0A    static public void start(Context ctx, String pythonServiceArgument) %7B
+public static void start(Context ctx, String pythonServiceArgument) %7B%0A    %09String argument = ctx.getFilesDir().getAbsolutePath();
 %0A   
@@ -729,71 +729,8 @@
 s);%0A
-        String argument = ctx.getFilesDir().getAbsolutePath();%0A
     
@@ -894,24 +894,141 @@
 point %7D%7D%22);%0A
+        intent.putExtra(%22serviceTitle%22, %22%7B%7B name%7Ccapitalize %7D%7D%22);%0A        intent.putExtra(%22serviceDescription%22, %22%22);%0A
         inte
@@ -1309,24 +1309,28 @@
   %7D%0A
-%0A
     
-static publ
+%0A    public stat
 ic v
@@ -1463,16 +1463,17 @@
 ntent);%0A
-
     %7D%0A
+%0A
 %7D%0A

refactor python service template