Add: Sample Script Tab, EMCAScript Guide
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.stardust.scriptdroid.external.floating_window;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
@@ -16,8 +19,32 @@ import com.stardust.view.ResizableFloaty;
|
||||
public class FloatingWindowManger {
|
||||
|
||||
public static void showFloatingWindow() {
|
||||
if (!HoverMenuService.isServiceRunning())
|
||||
App.getApp().startService(new Intent(App.getApp(), HoverMenuService.class));
|
||||
if (!HoverMenuService.isServiceRunning()) {
|
||||
if (!hasFloatingWindowPermission()) {
|
||||
goToFloatingWindowPermissionSetting();
|
||||
} else {
|
||||
HoverMenuService.startService(App.getApp());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void goToFloatingWindowPermissionSetting() {
|
||||
String packageName = App.getApp().getPackageName();
|
||||
Intent intent;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + packageName));
|
||||
} else {
|
||||
intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + packageName));
|
||||
}
|
||||
App.getApp().startActivity(intent);
|
||||
}
|
||||
|
||||
private static boolean hasFloatingWindowPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return Settings.canDrawOverlays(App.getApp());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isFloatingWindowShowing() {
|
||||
|
||||
@@ -77,7 +77,7 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
|
||||
private View getTabViewInner(int index) {
|
||||
String menuItemId = mTabIds.get(index);
|
||||
if (ID_MAIN.equals(menuItemId)) {
|
||||
return createTabView(R.drawable.ic_android_eat_js);
|
||||
return createTabView(R.drawable.ic_android_eat_js_100);
|
||||
} else if (ID_RECORD.equals(menuItemId)) {
|
||||
return createTabView(R.drawable.ic_video_record);
|
||||
} else if (ID_SCRIPT_LIST.equals(menuItemId)) {
|
||||
|
||||
@@ -7,13 +7,15 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.hover.HoverMenuBuilder;
|
||||
import com.stardust.hover.SimpleHoverMenuTransitionListener;
|
||||
import com.stardust.hover.WindowHoverMenu;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.floating_window.view.FloatingLayoutBoundsView;
|
||||
import com.stardust.scriptdroid.external.floating_window.view.FloatingLayoutHierarchyView;
|
||||
import com.stardust.scriptdroid.layout_inspector.LayoutInspector;
|
||||
@@ -35,31 +37,50 @@ import io.mattcarroll.hover.defaulthovermenu.window.WindowViewController;
|
||||
|
||||
public class HoverMenuService extends Service {
|
||||
|
||||
public static class ServiceStateChangedEvent {
|
||||
ServiceStateChangedEvent(boolean state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public boolean state;
|
||||
}
|
||||
|
||||
public static final String MESSAGE_SHOW_AND_EXPAND_MENU = "MESSAGE_SHOW_AND_EXPAND_MENU";
|
||||
public static final String MESSAGE_SHOW_LAYOUT_HIERARCHY = "MESSAGE_SHOW_LAYOUT_HIERARCHY";
|
||||
public static final String MESSAGE_SHOW_LAYOUT_BOUNDS = "MESSAGE_SHOW_LAYOUT_BOUNDS";
|
||||
public static final String MESSAGE_COLLAPSE_MENU = "MESSAGE_COLLAPSE_MENU";
|
||||
public static final String MESSAGE_MENU_COLLAPSING = "MESSAGE_MENU_COLLAPSING";
|
||||
|
||||
private static WeakReference<HoverMenuService> service;
|
||||
private static WeakReference<HoverMenuService> service = new WeakReference<>(null);
|
||||
private static boolean sIsRunning;
|
||||
|
||||
public static void startService(Context context) {
|
||||
context.startService(new Intent(context, HoverMenuService.class));
|
||||
setIsRunning(true);
|
||||
}
|
||||
|
||||
public static boolean isServiceRunning() {
|
||||
return service != null && service.get() != null;
|
||||
return sIsRunning;
|
||||
}
|
||||
|
||||
public static void stopService() {
|
||||
if (isServiceRunning()) {
|
||||
if (isServiceRunning() && service.get() != null) {
|
||||
service.get().stopSelf();
|
||||
setIsRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setIsRunning(boolean isRunning) {
|
||||
sIsRunning = isRunning;
|
||||
EventBus.getDefault().post(new ServiceStateChangedEvent(sIsRunning));
|
||||
}
|
||||
|
||||
|
||||
private static final String TAG = "HoverMenuService";
|
||||
|
||||
private static final String PREF_FILE = "hover_menu";
|
||||
private static final String PREF_HOVER_MENU_VISUAL_STATE = "hover_menu_visual_state";
|
||||
|
||||
private boolean mIsRunning;
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
private WindowViewController mWindowViewController;
|
||||
@@ -80,14 +101,21 @@ public class HoverMenuService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
if (isServiceRunning()) {
|
||||
if (service.get() != null) {
|
||||
stopSelf();
|
||||
} else {
|
||||
service = new WeakReference<>(this);
|
||||
return;
|
||||
}
|
||||
service = new WeakReference<>(this);
|
||||
EventBus.getDefault().register(this);
|
||||
mPrefs = getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
|
||||
initViews();
|
||||
try {
|
||||
initViews();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
FloatingWindowManger.goToFloatingWindowPermissionSetting();
|
||||
stopService();
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
@@ -138,18 +166,16 @@ public class HoverMenuService extends Service {
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (!mIsRunning) {
|
||||
mIsRunning = true;
|
||||
mWindowHoverMenu.show();
|
||||
}
|
||||
mWindowHoverMenu.show();
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mWindowHoverMenu.hide();
|
||||
mIsRunning = false;
|
||||
if (isServiceRunning() && service.get() == this)
|
||||
EventBus.getDefault().unregister(this);
|
||||
setIsRunning(false);
|
||||
if (service.get() == this)
|
||||
service.clear();
|
||||
}
|
||||
|
||||
@@ -167,14 +193,14 @@ public class HoverMenuService extends Service {
|
||||
public void onMessageEvent(MessageEvent event) {
|
||||
switch (event.message) {
|
||||
case MESSAGE_SHOW_AND_EXPAND_MENU:
|
||||
mWindowHoverMenu.show();
|
||||
showView(mWindowHoverMenu.getHoverMenuView());
|
||||
break;
|
||||
case MESSAGE_SHOW_LAYOUT_HIERARCHY:
|
||||
mWindowHoverMenu.hide();
|
||||
mWindowHoverMenu.getHoverMenuView().setVisibility(View.GONE);
|
||||
showView(mFloatingLayoutHierarchyView);
|
||||
break;
|
||||
case MESSAGE_SHOW_LAYOUT_BOUNDS:
|
||||
mWindowHoverMenu.hide();
|
||||
mWindowHoverMenu.getHoverMenuView().setVisibility(View.GONE);
|
||||
showView(mFloatingLayoutBoundsView);
|
||||
break;
|
||||
case MESSAGE_COLLAPSE_MENU:
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.stardust.scriptdroid.external.floating_window.content;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.droid.Droid;
|
||||
import com.stardust.scriptdroid.external.floating_window.HoverMenuService;
|
||||
import com.stardust.scriptdroid.layout_inspector.LayoutInspector;
|
||||
import com.stardust.util.MessageEvent;
|
||||
@@ -59,6 +61,15 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.stop_all_running_scripts)
|
||||
private void stopAllRunningScripts() {
|
||||
int n = Droid.getInstance().stopAll();
|
||||
if (n > 0)
|
||||
Toast.makeText(mView.getContext(), String.format(mView.getContext().getString(R.string.text_already_stop_n_scripts), n), Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(mView.getContext(), R.string.text_no_running_script, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView() {
|
||||
|
||||
Reference in New Issue
Block a user