Esempio n. 1
0
 public static HtmlActivityTask launchHtmlScript(
     File script, Service service, Intent intent, InterpreterConfiguration config) {
   if (!script.exists()) {
     throw new RuntimeException("No such script to launch.");
   }
   HtmlInterpreter interpreter =
       (HtmlInterpreter) config.getInterpreterByName(HtmlInterpreter.HTML);
   if (interpreter == null) {
     throw new RuntimeException("HtmlInterpreter is not available.");
   }
   final FacadeManager manager =
       new FacadeManager(
           FacadeConfiguration.getSdkLevel(),
           service,
           intent,
           FacadeConfiguration.getFacadeClasses());
   FutureActivityTaskExecutor executor =
       ((BaseApplication) service.getApplication()).getTaskExecutor();
   final HtmlActivityTask task =
       new HtmlActivityTask(
           manager,
           interpreter.getAndroidJsSource(),
           interpreter.getJsonSource(),
           script.getAbsolutePath(),
           true);
   executor.execute(task);
   return task;
 }
Esempio n. 2
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
     final File script = new File(data.getStringExtra(Constants.EXTRA_SCRIPT_PATH));
     if (requestCode == MenuId.ADD.getId()) {
       Map<String, MethodDescriptor> eventMethodDescriptors =
           FacadeConfiguration.collectStartEventMethodDescriptors();
       final List<String> eventNames = Lists.newArrayList(eventMethodDescriptors.keySet());
       Collections.sort(eventNames);
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder.setItems(
           eventNames.toArray(new CharSequence[eventNames.size()]),
           new OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int position) {
               mTriggerRepository.put(new ScriptTrigger(eventNames.get(position), script));
             }
           });
       builder.show();
     }
   }
 }
Esempio n. 3
0
        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
          final File file = (File) mList.getItemAtPosition(position);
          mCurrent = file;
          if (file.isDirectory()) {
            mCurrentDir = file;
            mAdapter.notifyDataSetInvalidated();
            return;
          }
          if (FacadeConfiguration.getSdkLevel() <= 3
              || !mPreferences.getBoolean("use_quick_menu", true)) {
            doDialogMenu();
            return;
          }

          final QuickAction actionMenu = new QuickAction(view);

          ActionItem terminal = new ActionItem();
          terminal.setIcon(getResources().getDrawable(R.drawable.terminal));
          terminal.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  Intent intent = new Intent(ScriptManager.this, ScriptingLayerService.class);
                  intent.setAction(Constants.ACTION_LAUNCH_FOREGROUND_SCRIPT);
                  intent.putExtra(Constants.EXTRA_SCRIPT_PATH, file.getPath());
                  startService(intent);
                  dismissQuickActions(actionMenu);
                }
              });

          final ActionItem background = new ActionItem();
          background.setIcon(getResources().getDrawable(R.drawable.background));
          background.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  Intent intent = new Intent(ScriptManager.this, ScriptingLayerService.class);
                  intent.setAction(Constants.ACTION_LAUNCH_BACKGROUND_SCRIPT);
                  intent.putExtra(Constants.EXTRA_SCRIPT_PATH, file.getPath());
                  startService(intent);
                  dismissQuickActions(actionMenu);
                }
              });

          final ActionItem edit = new ActionItem();
          edit.setIcon(getResources().getDrawable(android.R.drawable.ic_menu_edit));
          edit.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  editScript(file);
                  dismissQuickActions(actionMenu);
                }
              });

          final ActionItem delete = new ActionItem();
          delete.setIcon(getResources().getDrawable(android.R.drawable.ic_menu_delete));
          delete.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  delete(file);
                  dismissQuickActions(actionMenu);
                }
              });

          final ActionItem rename = new ActionItem();
          rename.setIcon(getResources().getDrawable(android.R.drawable.ic_menu_save));
          rename.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  rename(file);
                  dismissQuickActions(actionMenu);
                }
              });

          final ActionItem external = new ActionItem();
          external.setIcon(getResources().getDrawable(android.R.drawable.ic_menu_directions));
          external.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  // externalEditor(file);
                  dismissQuickActions(actionMenu);
                  if (!file.getAbsolutePath().endsWith(".pyc") && !file.isDirectory()) {
                    // 非文件夹或者非pyc文件提示无法反编译
                    Crouton.cancelAllCroutons();
                    Crouton.showText(
                        ScriptManager.this, getString(R.string.s_Cannotdecompile), Style.ALERT);
                  } else {
                    Decompile.show(ScriptManager.this, file.getAbsolutePath());
                  }
                }
              });

          actionMenu.addActionItems(terminal, background, edit, rename, delete, external);
          actionMenu.setAnimStyle(QuickAction.ANIM_GROW_FROM_CENTER);
          actionMenu.show();
        }