package com.example.angluswang.superflashlight;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;

/**
 * Created by Jeson on 2016/7/1.
 * 设置，用于设置警示灯和警告灯的闪烁频率等
 */

public class Settings extends PoliceLight
        implements SeekBar.OnSeekBarChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        skWarningLight.setOnSeekBarChangeListener(this);
        skPoliceLight.setOnSeekBarChangeListener(this);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,
                                  boolean fromUser) {
        switch (seekBar.getId()) {
            case R.id.seekbar_warning_light:
                mCurrentWarningLightInterval = progress + 100;

                break;
            case R.id.seekbar_police_light:
                mCurrentPoliceLightInterval = progress + 50;

                break;
            default:
                break;
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    /**
     * 添加快捷方式到桌面
     */
    public void onClick_AddShortcut(View view) {
        Intent installShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        installShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "多功能手电筒");
        Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.app_icon);
        installShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

        Intent flashlightIntent = new Intent();
        flashlightIntent.setClassName("com.example.angluswang.superflashlight",
                "com.example.angluswang.superflashlight.FlashLight");
        flashlightIntent.setAction(Intent.ACTION_MAIN);
        flashlightIntent.addCategory(Intent.CATEGORY_DEFAULT);

        installShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, flashlightIntent);
        sendBroadcast(installShortcut);
        Toast.makeText(this, "桌面快捷方式创建成功！",
                Toast.LENGTH_SHORT).show();
    }

    /**
     * 从桌面移除快捷方式
     */
    public void onClick_RemoveShortcut(View view) {

    }
}

@@ -1865,18 +1865,20 @@
 ght.
-FlashLight
+MainActivity
 %22);%0A
@@ -2295,21 +2295,626 @@
 iew view) %7B%0A
+        Intent removeShortcut = new Intent(%22com.android.launcher.action.UNINSTALL_SHORTCUT%22);%0A        removeShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, %22%E5%A4%9A%E5%8A%9F%E8%83%BD%E6%89%8B%E7%94%B5%E7%AD%92%22);%0A%0A        Intent flashlightIntent = new Intent();%0A        flashlightIntent.setClassName(%22com.example.angluswang.superflashlight%22,%0A                %22com.example.angluswang.superflashlight.MainActivity%22);%0A        flashlightIntent.setAction(Intent.ACTION_MAIN);%0A        flashlightIntent.addCategory(Intent.CATEGORY_DEFAULT);%0A%0A        removeShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, flashlightIntent);%0A        sendBroadcast(removeShortcut);
 %0A    %7D%0A%7D%0A

添加与删除 桌面应用图标