// Path: app/src/main/java/top/soyask/calendarii/utils/PermissionUtils.java
// public class PermissionUtils {
// 
//     public static boolean checkSelfPermission(Activity activity, String permission, int requestCode) {
//         boolean had = true;
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
//                 activity.requestPermissions(new String[]{ permission }, requestCode);
//                 had = false;
//             }
//         }
//         return had;
//     }
// 
//     public static boolean checkSelfPermission(Fragment fragment, String permission, int requestCode) {
//         boolean had = true;
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             FragmentActivity activity = fragment.getActivity();
//             if(activity == null) return false;
//             if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
//                 fragment.requestPermissions(new String[]{permission}, requestCode);
//                 had = false;
//             }
//         }
//         return had;
//     }
// 
//     public static boolean handleResults(String[] permissions, int[] grantResults) {
//         for (int i = 0; i < permissions.length; i++) {
//             if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
//                 return false;
//             }
//         }
//         return true;
//     }
// 
//     public static void manual(Activity activity) {
//         new AlertDialog.Builder(activity)
//                 .setMessage("你拒绝授予权限，该功能将无法正常使用...")
//                 .setPositiveButton("手动授权", (dialog, which) -> {
//                     toSettings(activity);
//                 })
//                 .setNegativeButton("不使用该功能", null)
//                 .show();
//     }
// 
//     public static void toSettings(Context context) {
//         Uri uri = Uri.fromParts("package", context.getPackageName(), null);
//         Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
//         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//         context.startActivity(intent);
//     }
// }


import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import top.soyask.calendarii.R;
import top.soyask.calendarii.utils.PermissionUtils;
package top.soyask.calendarii.ui.floatwindow;



public class FloatWindowService extends Service {

    private FloatWindowManager mFloatWindow;

    public FloatWindowService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mFloatWindow = FloatWindowManager.getInstance();
        try {
            mFloatWindow.show(this);
        } catch (WindowManager.BadTokenException e) {
            e.printStackTrace();
            Toast.makeText(this, "请在设置里开启悬浮窗权限", Toast.LENGTH_SHORT).show();
// Path: app/src/main/java/top/soyask/calendarii/utils/PermissionUtils.java
// public class PermissionUtils {
// 
//     public static boolean checkSelfPermission(Activity activity, String permission, int requestCode) {
//         boolean had = true;
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
//                 activity.requestPermissions(new String[]{ permission }, requestCode);
//                 had = false;
//             }
//         }
//         return had;
//     }
// 
//     public static boolean checkSelfPermission(Fragment fragment, String permission, int requestCode) {
//         boolean had = true;
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             FragmentActivity activity = fragment.getActivity();
//             if(activity == null) return false;
//             if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
//                 fragment.requestPermissions(new String[]{permission}, requestCode);
//                 had = false;
//             }
//         }
//         return had;
//     }
// 
//     public static boolean handleResults(String[] permissions, int[] grantResults) {
//         for (int i = 0; i < permissions.length; i++) {
//             if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
//                 return false;
//             }
//         }
//         return true;
//     }
// 
//     public static void manual(Activity activity) {
//         new AlertDialog.Builder(activity)
//                 .setMessage("你拒绝授予权限，该功能将无法正常使用...")
//                 .setPositiveButton("手动授权", (dialog, which) -> {
//                     toSettings(activity);
//                 })
//                 .setNegativeButton("不使用该功能", null)
//                 .show();
//     }
// 
//     public static void toSettings(Context context) {
//         Uri uri = Uri.fromParts("package", context.getPackageName(), null);
//         Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
//         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//         context.startActivity(intent);
//     }
// }


// Path: app/src/main/java/top/soyask/calendarii/ui/floatwindow/FloatWindowService.java
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import top.soyask.calendarii.R;
import top.soyask.calendarii.utils.PermissionUtils;

package top.soyask.calendarii.ui.floatwindow;



public class FloatWindowService extends Service {

    private FloatWindowManager mFloatWindow;

    public FloatWindowService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mFloatWindow = FloatWindowManager.getInstance();
        try {
            mFloatWindow.show(this);
        } catch (WindowManager.BadTokenException e) {
            e.printStackTrace();
            Toast.makeText(this, "请在设置里开启悬浮窗权限", Toast.LENGTH_SHORT).show();
            PermissionUtils.toSettings(this);