diff --git a/BotLibre/README.md b/BotLibre/README.md index 107d7c0822d9850c6ec7b8456ec056fb2c202129..eef39d62e9a7a7b7a32201e291e70b0563231f1c 100644 --- a/BotLibre/README.md +++ b/BotLibre/README.md @@ -5,10 +5,10 @@ - 项目名称:BotLibre - 所属系列:OpenHarmony的第三方组件适配移植 - 功能:人工智能、nlp、聊天机器人、虚拟代理、社交媒体自动化和实时聊天自动化的开源平台 -- 基线版本:master - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 Beta1 +- 基线版本:master ## 效果演示 @@ -23,7 +23,7 @@ Demo中调用library组件,然后通过五个功能操作展示组件。 ")) { message = "Server Error, ensure you are connected to the Internet"; } - MainAbility.showMessage(null,message, activity); + MainAbility.showMessage(null, message, ability); } catch (Throwable error) { error.printStackTrace(); } } - public static void errorInfo(int type,String message, Exception exception, Ability activity) { + public static void errorInfo(int type, String message, Exception exception, Ability ability) { try { if (DEBUG) { System.out.println(String.valueOf(message)); @@ -546,29 +550,29 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag if (message.contains("")) { message = "Server Error, ensure you are connected to the Internet"; } - MainAbility.showMessageInfo(type,null,message, activity); + MainAbility.showMessageInfo(type, null, message, ability); } catch (Throwable error) { error.printStackTrace(); } } - public static void showMessage(String title, String message, Ability activity) { - CommonDialog mCommonDialog = new CommonDialog(activity); + public static void showMessage(String title, String message, Ability ability) { + CommonDialog mCommonDialog = new CommonDialog(ability); Optional - display = DisplayManager.getInstance().getDefaultDisplay(activity); + display = DisplayManager.getInstance().getDefaultDisplay(ability); DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(activity). + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability). parse(ResourceTable.Layout_content_dialog, null, false); mCommonDialog.setContentCustomComponent(layout) .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width-100,DirectionalLayout.LayoutConfig.MATCH_CONTENT) + .setSize(displayAttributes.width - 100, DirectionalLayout.LayoutConfig.MATCH_CONTENT) .setAutoClosable(false) .setTransparent(false) .show(); - Text ok = (Text)layout.findComponentById(ResourceTable.Id_ok); - Text contentinfo = (Text)layout.findComponentById(ResourceTable.Id_contentinfo); + Text ok = (Text) layout.findComponentById(ResourceTable.Id_ok); + Text contentinfo = (Text) layout.findComponentById(ResourceTable.Id_contentinfo); if (message != null) { contentinfo.setText(message); } @@ -580,23 +584,23 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - public void showLogin(String title, String message, Ability activity) { - CommonDialog mCommonDialog = new CommonDialog(activity); + public void showLogin(String title, String message, Ability ability) { + CommonDialog mCommonDialog = new CommonDialog(ability); Optional - display = DisplayManager.getInstance().getDefaultDisplay(activity); + display = DisplayManager.getInstance().getDefaultDisplay(ability); DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(activity). + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability). parse(ResourceTable.Layout_content_dialog, null, false); mCommonDialog.setContentCustomComponent(layout) .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width - 100,DirectionalLayout.LayoutConfig.MATCH_CONTENT) + .setSize(displayAttributes.width - 100, DirectionalLayout.LayoutConfig.MATCH_CONTENT) .setAutoClosable(false) .setTransparent(false) .show(); - Text ok = (Text)layout.findComponentById(ResourceTable.Id_ok); - Text contentinfo = (Text)layout.findComponentById(ResourceTable.Id_contentinfo); + Text ok = (Text) layout.findComponentById(ResourceTable.Id_ok); + Text contentinfo = (Text) layout.findComponentById(ResourceTable.Id_contentinfo); if (message != null) { contentinfo.setText(message); } @@ -610,23 +614,24 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } public static Text execcontentinfo; - public static void showMessageInfo(int type,String title, String message, Ability activity) { - CommonDialog mCommonDialog = new CommonDialog(activity); + + public static void showMessageInfo(int type, String title, String message, Ability ability) { + CommonDialog mCommonDialog = new CommonDialog(ability); Optional - display = DisplayManager.getInstance().getDefaultDisplay(activity); + display = DisplayManager.getInstance().getDefaultDisplay(ability); DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(activity). + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability). parse(ResourceTable.Layout_exception_dialog, null, false); mCommonDialog.setContentCustomComponent(layout) .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width - 100,displayAttributes.height - 200) + .setSize(displayAttributes.width - 100, displayAttributes.height - 200) .setAutoClosable(false) .setTransparent(false) .show(); - Text ok = (Text)layout.findComponentById(ResourceTable.Id_ok); - execcontentinfo = (Text)layout.findComponentById(ResourceTable.Id_execcontentinfo); + Text ok = (Text) layout.findComponentById(ResourceTable.Id_ok); + execcontentinfo = (Text) layout.findComponentById(ResourceTable.Id_execcontentinfo); if (message != null) { execcontentinfo.setText(message); } @@ -647,12 +652,12 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - public static void showMessage(String message, Ability activity) { - showMessage(null, message, activity); + public static void showMessage(String message, Ability ability) { + showMessage(null, message, ability); } - public static void prompt(String message, Ability activity, TextField text, IDialog.ClickedListener listener) { - CommonDialog dialog = new CommonDialog(activity); + public static void prompt(String message, Ability ability, TextField text, IDialog.ClickedListener listener) { + CommonDialog dialog = new CommonDialog(ability); dialog.setContentText(message); dialog.setContentCustomComponent(text); dialog.setButton(0, "OK", listener); @@ -691,8 +696,8 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag builder.show(); } - public static void confirm(String message, Ability activity, Boolean cancelable, IDialog.ClickedListener listener) { - CommonDialog dialog = new CommonDialog(activity); + public static void confirm(String message, Ability ability, Boolean cancelable, IDialog.ClickedListener listener) { + CommonDialog dialog = new CommonDialog(ability); dialog.setTitleText("Pizza Bot"); dialog.setContentText(message); dialog.setButton(0, "Yes", listener); @@ -703,10 +708,10 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag dialog.show(); } - public static List getAllTemplates(Ability activity) { + public static List getAllTemplates(Ability ability) { if (templates == null) { try { - HttpGetTemplatesAction action = new HttpGetTemplatesAction(activity); + HttpGetTemplatesAction action = new HttpGetTemplatesAction(ability); action.postExecute(action.execute().get()); if (action.getException() != null) { templates = new ArrayList(); @@ -824,7 +829,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag hd = isTablet(this); } - public void initChat(){ + public void initChat() { chatButton = (Button) findComponentById(ResourceTable.Id_chatButton); // chat chatButton.setClickedListener(new Component.ClickedListener() { @Override @@ -834,7 +839,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - public void initMain(){ + public void initMain() { spin = (Button) findComponentById(ResourceTable.Id_selectButton); // 底部类型选择 spin.setClickedListener(new Component.ClickedListener() { @Override @@ -895,7 +900,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - public void initBrowse(){ + public void initBrowse() { chatButton = (Button) findComponentById(ResourceTable.Id_chatButton); chatButton.setClickedListener(new Component.ClickedListener() { @Override @@ -930,6 +935,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } }); } + //动态权限 private void reqPermissions() { mPermissions.removeIf(perM -> verifySelfPermission(perM) == PERMISSION_GRANTED || !canRequestPermission(perM)); @@ -944,8 +950,8 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag /** * 权限回调 * - * @param requestCode requestCode - * @param ss ss + * @param requestCode requestCode + * @param ss ss * @param grantResults grantResults */ @Override @@ -977,7 +983,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag launchInstanceId = oneItem.getId(); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) public void resetView() { menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); // 菜单选择 menuButton.setClickedListener(new Component.ClickedListener() { @@ -988,38 +994,21 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); - if (domain != null) { // setTitle(Utils.stripTags(domain.name)); - HttpGetImageAction.fetchImage(this, domain.avatar, null); //----------------- // HttpGetImageAction.fetchImage(this, domain.avatar, (Image) findComponentById(ResourceTable.Id_splash)); } if (MainAbility.user == null) { findComponentById(ResourceTable.Id_viewUserButton).setVisibility(HIDE); - //findViewById(R.id.logoutButton).setVisibility(View.GONE); - //findViewById(R.id.loginButton).setVisibility(View.VISIBLE); } else { - //findViewById(R.id.logoutButton).setVisibility(View.VISIBLE); - //findViewById(R.id.loginButton).setVisibility(View.GONE); findComponentById(ResourceTable.Id_viewUserButton).setVisibility(VISIBLE); - //HttpGetImageAction.fetchImage(this, MainActivity.user.avatar, findViewById(R.id.viewUserButton)); } resetMenu(this.menu); resetLast(); } public void resetLast() { -// String type = MainAbility.defaultType; -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); // 需要放入 adapter中做判断 -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// if (type.equals("Chat Bot Wars")) { -// spin.setSelection(0); -// war(null); -// return; -// } -// } if (type.equals("Chat Bot Wars")) { war(); return; @@ -1212,8 +1201,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag editor.delete("deviceVoice"); editor.flushSync(); - HttpGetImageAction.clearFileCache(this); - Intent intent = getIntent(); terminateAbility(); startAbility(intent); @@ -1228,7 +1215,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) .parse(ResourceTable.Layout_menu_main, null, false); menuDialog.setCustomComponent(menuComponent); - menuDialog.showOnCertainPosition(1,displayAttributes.width,-displayAttributes.width + 150); + menuDialog.showOnCertainPosition(1, displayAttributes.width, -displayAttributes.width + 150); menuDialog.setAutoClosable(true); Text statistics = (Text) menuComponent.findComponentById(ResourceTable.Id_title); Text changelanguage = (Text) menuComponent.findComponentById(ResourceTable.Id_changelanguage); @@ -1236,7 +1223,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag Text searchinfo = (Text) menuComponent.findComponentById(ResourceTable.Id_searchinfo); Text helpopt = (Text) menuComponent.findComponentById(ResourceTable.Id_helpopt); Text contentrating = (Text) menuComponent.findComponentById(ResourceTable.Id_contentrating); - menuDialog.setAlignment(LayoutAlignment.RIGHT|LayoutAlignment.TOP); + menuDialog.setAlignment(LayoutAlignment.RIGHT | LayoutAlignment.TOP); menuDialog.show(); Text loginButton = (Text) menuComponent.findComponentById(ResourceTable.Id_loginButton); @@ -1287,7 +1274,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag changelanguage.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { - changeLanguage(MainAbility.this,null); + changeLanguage(MainAbility.this, null); menuDialog.destroy(); } }); @@ -1323,55 +1310,27 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } public void createUser() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// -// Intent intent = new Intent(this, CreateUserActivity.class); -// startActivity(intent); startOpenAbility(this, CreateUserAbility.class.getName()); } public void editUser() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// -// Intent intent = new Intent(this, EditUserActivity.class); -// startActivity(intent); -// startOpenAbility(this, EditUserAbility.class.getName()); //================ } - public static void setOnline(boolean result){ - if(result){ + public static void setOnline(boolean result) { + if (result) { connection = remoteConnection; - }else{ + } else { connection = localConnection; } online = result; } public void help() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// super.help(view); startOpenAbility(this, HelpAbility.class.getName()); } public void viewUser() { viewUser = user; -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } - -// Intent intent = new Intent(this, ViewUserActivity.class); -// startActivity(intent); -// startOpenAbility(this, ViewUserAbility.class.getName()); //================ } public void openWebsite() { @@ -1389,7 +1348,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag public void createInstance() { if (user == null) { - showLogin("","You must sign in first",this); + showLogin("", "You must sign in first", this); return; } // Spinner spin = (Spinner) findViewById(getResources().getIdentifier("typeSpin", "id", getPackageName())); @@ -1401,75 +1360,28 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } if (type.equals("Bots")) { MainAbility.template = ""; -// Intent intent = new Intent(this, CreateBotActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateBotAbility.class.getName()); //================ - } else if (type.equals("Forums")) { -// Intent intent = new Intent(this, CreateForumActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateForumAbility.class.getName()); //================ - } else if (type.equals("Live Chat")) { -// Intent intent = new Intent(this, CreateChannelActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateChannelAbility.class.getName()); //================ - } else if (type.equals("Domains")) { -// Intent intent = new Intent(this, CreateDomainActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateDomainAbility.class.getName()); //================ - } else if (type.equals("Avatars")) { -// Intent intent = new Intent(this, CreateAvatarActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateAvatarAbility.class.getName()); //================ - } else if (type.equals("Scripts")) { -// Intent intent = new Intent(this, CreateScriptActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateScriptAbility.class.getName()); //================ - } else if (type.equals("Graphics")) { -// Intent intent = new Intent(this, CreateGraphicActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateGraphicAbility.class.getName()); //================ } } public void search() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } if (type.equals("Bots")) { -// Intent intent = new Intent(this, BotSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); } else if (type.equals("Forums")) { -// Intent intent = new Intent(this, ForumSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); } else if (type.equals("Live Chat")) { -// Intent intent = new Intent(this, ChannelSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); } else if (type.equals("Domains")) { -// Intent intent = new Intent(this, DomainSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); } else if (type.equals("Avatars")) { -// Intent intent = new Intent(this, AvatarSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); } else if (type.equals("Scripts")) { -// Intent intent = new Intent(this, ScriptSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); } else if (type.equals("Graphics")) { -// Intent intent = new Intent(this, GraphicSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); - }else if (type.equals("Chat Bot Wars")) { -// Intent intent = new Intent(this, GraphicSearchActivity.class); -// startActivity(intent); + } else if (type.equals("Chat Bot Wars")) { startOpenAbility(this, BotSearchAbility.class.getName()); } } @@ -1568,12 +1480,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag // the launch type is bot. if (MainAbility.launchType == LaunchType.Bot) { if (!MicroMemory.checkExists()) { - //ListTemplateView.offlineTemplate = true; - //Intent intent = new Intent(MainActivity.this, ListTemplateView.class); - //startActivity(intent); config = new InstanceConfig(); - OfflineTemplateConfig templates = new OfflineTemplateConfig(ResourceTable.Media_bot,"Pizza Bot","",""+0,0); + OfflineTemplateConfig templates = new OfflineTemplateConfig(ResourceTable.Media_bot, "Pizza Bot", "", "" + 0, 0); //saving a template number for getting the icons and pictures of the bot saveAllData(MainAbility.launchInstanceName = templates.getTitle(), MainAbility.launchInstanceId = templates.getId(), MainAbility.templateID = 0); config.id = MainAbility.launchInstanceId; @@ -1598,7 +1507,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } - public void saveAllData(String instanceId, String instanceName, int id){ + public void saveAllData(String instanceId, String instanceName, int id) { // Preferences cookies = MainAbility.current.getPreferences(Context.MODE_PRIVATE).edit(); Preferences cookies = PreferencesUtils.getPreferences(this); cookies.putString("instanceID", instanceId); @@ -1632,6 +1541,8 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag /** * Start a chat session with the user's personal instance. + * + * @param view view */ public void launchMyBot(View view) { if (user == null) { @@ -1655,7 +1566,8 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag public static String selectInfo = ""; Text languageselect; - @SuppressWarnings({ "rawtypes", "unchecked" }) + + @SuppressWarnings({"rawtypes", "unchecked"}) public void changeLanguage(Ability activty, final IDialog.ClickedListener listener) { Optional display = DisplayManager.getInstance().getDefaultDisplay(this); @@ -1667,7 +1579,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag CommonDialog dialog = new CommonDialog(MainAbility.this); setOnline(true); // dialog.setTitleText(" Languages"); - dialog.setSize(displayAttributes.width - 100,displayAttributes.width - 300); + dialog.setSize(displayAttributes.width - 100, displayAttributes.width - 300); // dialog.setContentText("Select your language"); dialog.setContentCustomComponent(layout); dialog.show(); @@ -1676,7 +1588,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag Text ok = (Text) layout.findComponentById(ResourceTable.Id_ok); Text cancel = (Text) layout.findComponentById(ResourceTable.Id_cancel); - SpinnerAdapter spinnerAdapter = new SpinnerAdapter(this,MainAbility.languages); + SpinnerAdapter spinnerAdapter = new SpinnerAdapter(this, MainAbility.languages); languageselect.setClickedListener(new Component.ClickedListener() {//弹出选择语言对话框 @Override public void onClick(Component component) { @@ -1690,15 +1602,15 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag index = Arrays.asList(MainAbility.languages).indexOf(MainAbility.voice.language); } // spin.setSelection(index); - if(MainAbility.voice.language==null||MainAbility.voice.language.isEmpty()){ + if (MainAbility.voice.language == null || MainAbility.voice.language.isEmpty()) { languageselect.setText(MainAbility.languages[0] + ""); - }else{ + } else { languageselect.setText(MainAbility.voice.language + ""); } - if (MainAbility.voice != null && MainAbility.voice.language != null){ + if (MainAbility.voice != null && MainAbility.voice.language != null) { for (int i = 0; i < spinnerAdapter.getCount(); i++) { - if(MainAbility.languages[i].contains(MainAbility.voice.language + " - ")){ + if (MainAbility.languages[i].contains(MainAbility.voice.language + " - ")) { // spin.setSelection(i); selectInfo = MainAbility.languages[i]; } @@ -1754,19 +1666,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - public static void readZipAvatars(Ability activity, String fileName) { - // this is only for letting Julie Assistance Avatar works, since there - // is only one file called - // "Julie" I will have to take this name and read the file from the - // method @readZipAvatars. + public static void readZipAvatars(Ability ability, String fileName) { String args[] = fileName.split("\\s+"); - // ex: Julie = Julie - // Julie Assistant = Julie - // Its only going to take one name try { -// GetAvatarAction avatar = new GetAvatarAction(activity); -// avatar.readZipFile(args[0] + ".zip"); -// MicroConnection.avatarConfig = avatar.instance; } catch (Exception ignore) { } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java index 7dc7f7db821aa55b62b05a2cb1fc139543ab927e..fe1ac75f7e81a2765c563c747cdf003c45a3b5b6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java @@ -22,15 +22,14 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.StringReader; import java.net.URL; import java.util.ArrayList; import java.util.List; - import com.franmontiel.persistentcookiejar.ClearableCookieJar; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; +import ohos.agp.components.element.ShapeElement; import org.botlibre.sdk.config.AvatarConfig; import org.botlibre.sdk.config.AvatarMedia; import org.botlibre.sdk.config.AvatarMessage; @@ -55,7 +54,6 @@ import org.botlibre.sdk.config.ResponseSearchConfig; import org.botlibre.sdk.config.ScriptConfig; import org.botlibre.sdk.config.ScriptSourceConfig; import org.botlibre.sdk.config.Speech; -import org.botlibre.sdk.config.TrainingConfig; import org.botlibre.sdk.config.UserAdminConfig; import org.botlibre.sdk.config.UserConfig; import org.botlibre.sdk.config.UserMessageConfig; @@ -84,12 +82,7 @@ import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; -import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.xml.sax.InputSource; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; /** * Connection class for a REST service connection. @@ -122,33 +115,27 @@ public class SDKConnection { protected SDKException exception; - /** - * Return the name of the default user image. - */ - public static String defaultUserImage() { - return "images/user-thumb.jpg"; - } - /** * Create an SDK connection. */ public SDKConnection() { } - + /** - * Create an SDK connection with the credentials. * Use the Credentials subclass specific to your server. + * + * @param credentials credentials */ public SDKConnection(Credentials credentials) { this.credentials = credentials; this.url = credentials.url; } - + /** - * Validate the user credentials (password, or token). - * The user details are returned (with a connection token, password removed). * The user credentials are soted in the connection, and used on subsequent calls. - * An SDKException is thrown if the connect failed. + * + * @param config config + * @return The user credentials are soted in the connection, and used on subsequent calls. */ public UserConfig connect(UserConfig config) { config.addCredentials(this); @@ -168,9 +155,14 @@ public class SDKConnection { } return this.user; } - + /** * Execute the custom API. + * + * @param api api + * @param config config + * @param result result + * @return Execute the custom API. */ public Config custom(String api, Config config, Config result) { config.addCredentials(this); @@ -187,41 +179,32 @@ public class SDKConnection { } return result; } - - /** - * Connect to the live chat channel and return a LiveChatConnection. - * A LiveChatConnection is separate from an SDKConnection and uses web sockets for - * asynchronous communication. - * The listener will be notified of all messages. - */ - public LiveChatConnection openLiveChat(ChannelConfig channel, LiveChatListener listener) { - LiveChatConnection connection = new LiveChatConnection(this.credentials, listener); - connection.connect(channel, this.user); - return connection; - } - + /** - * Connect to the domain. - * A domain is an isolated content space. * Any browse or query request will be specific to the domain's content. - */ + * + * @param config config + * @return Any browse or query request will be specific to the domain's content. + */ public DomainConfig connect(DomainConfig config) { this.domain = fetch(config); return this.domain; } - + /** - * Disconnect from the connection. * An SDKConnection does not keep a live connection, but this resets its connected user and domain. - */ + */ public void disconnect() { this.user = null; this.domain = null; } - + /** * Fetch the user details. - */ + * + * @param config config + * @return Fetch the user details. + */ public UserConfig fetch(UserConfig config) { config.addCredentials(this); String xml = POST(this.url + "/view-user", config.toXML()); @@ -238,10 +221,13 @@ public class SDKConnection { throw this.exception; } } - + /** * Fetch the URL for the image from the server. - */ + * + * @param image image + * @return Fetch the URL for the image from the server. + */ public URL fetchImage(String image) { try { return new URL("http://" + this.credentials.host + this.credentials.app + "/" + image); @@ -250,10 +236,13 @@ public class SDKConnection { throw this.exception; } } - + /** * Fetch the forum post details for the forum post id. - */ + * + * @param config config + * @return Fetch the forum post details for the forum post id. + */ public ForumPostConfig fetch(ForumPostConfig config) { config.addCredentials(this); String xml = POST(this.url + "/check-forum-post", config.toXML()); @@ -273,6 +262,9 @@ public class SDKConnection { /** * Fetch the issue details for the issue id. + * + * @param config config + * @return Fetch the issue details for the issue id. */ public IssueConfig fetch(IssueConfig config) { config.addCredentials(this); @@ -290,9 +282,13 @@ public class SDKConnection { throw this.exception; } } - + /** * Create a new user. + * + * @param ability ability + * @param config config + * @return Create a new user. */ public UserConfig create(Ability ability,UserConfig config) { config.addCredentials(this); @@ -311,10 +307,12 @@ public class SDKConnection { throw this.exception; } } - + /** * Create a new forum post. - * You must set the forum id for the post. + * + * @param config config + * @return Create a new forum post. */ public ForumPostConfig create(ForumPostConfig config) { config.addCredentials(this); @@ -335,7 +333,9 @@ public class SDKConnection { /** * Create a new issue. - * You must set the issue tracker id for the issue. + * + * @param config config + * @return Create a new issue. */ public IssueConfig create(IssueConfig config) { config.addCredentials(this); @@ -356,6 +356,10 @@ public class SDKConnection { /** * Create a new file/image/media attachment for a chat channel. + * + * @param file file + * @param config config + * @return Create a new file/image/media attachment for a chat channel. */ public MediaConfig createChannelFileAttachment(String file, MediaConfig config) { config.addCredentials(this); @@ -376,6 +380,10 @@ public class SDKConnection { /** * Create a new image attachment for a chat channel. + * + * @param file file + * @param config config + * @return Create a new image attachment for a chat channel. */ public MediaConfig createChannelImageAttachment(String file, MediaConfig config) { config.addCredentials(this); @@ -396,6 +404,10 @@ public class SDKConnection { /** * Create a new file/image/media attachment for an issue tracker. + * + * @param file file + * @param config config + * @return Create a new file/image/media attachment for an issue tracker. */ public MediaConfig createIssueTrackerFileAttachment(String file, MediaConfig config) { config.addCredentials(this); @@ -416,6 +428,10 @@ public class SDKConnection { /** * Create a new image attachment for an issue tracker. + * + * @param file file + * @param config config + * @return Create a new image attachment for an issue tracker. */ public MediaConfig createIssueTrackerImageAttachment(String file, MediaConfig config) { config.addCredentials(this); @@ -436,6 +452,10 @@ public class SDKConnection { /** * Create a new image attachment for an issue tracker. + * + * @param bitmap bitmap + * @param config config + * @return Create a new image attachment for an issue tracker. */ public MediaConfig createIssueTrackerImageAttachment(PixelMap bitmap, MediaConfig config) { config.addCredentials(this); @@ -453,10 +473,12 @@ public class SDKConnection { throw this.exception; } } - + /** * Create a reply to a forum post. - * You must set the parent id for the post replying to. + * + * @param config config + * @return Create a reply to a forum post. */ public ForumPostConfig createReply(ForumPostConfig config) { config.addCredentials(this); @@ -474,20 +496,23 @@ public class SDKConnection { throw this.exception; } } - + /** * Create a user message. - * This can be used to send a user a direct message. - * SPAM will cause your account to be deleted. + * + * @param config config */ public void createUserMessage(UserMessageConfig config) { config.addCredentials(this); POST(this.url + "/create-user-message", config.toXML()); } - + /** * Fetch the content details from the server. - * The id or name and domain of the object must be set. + * + * @param config config + * @param + * @return Fetch the content details from the server. */ @SuppressWarnings("unchecked") public T fetch(T config) { @@ -510,6 +535,10 @@ public class SDKConnection { /** * Create the new content. * The content will be returned with its new id. + * + * @param config config + * @param + * @return Create the new content. */ @SuppressWarnings("unchecked") public T create(T config) { @@ -528,9 +557,13 @@ public class SDKConnection { throw this.exception; } } - + /** * Update the content. + * + * @param config config + * @param + * @return Update the content. */ @SuppressWarnings("unchecked") public T update(T config) { @@ -549,9 +582,12 @@ public class SDKConnection { throw this.exception; } } - + /** * Update the forum post. + * + * @param config config + * @return Update the forum post. */ public ForumPostConfig update(ForumPostConfig config) { config.addCredentials(this); @@ -572,6 +608,9 @@ public class SDKConnection { /** * Update the issue. + * + * @param config config + * @return Update the issue. */ public IssueConfig update(IssueConfig config) { config.addCredentials(this); @@ -592,7 +631,9 @@ public class SDKConnection { /** * Create or update the response. - * This can also be used to flag, unflag, validate, or invalidate a response. + * + * @param config config + * @return Create or update the response. */ public ResponseConfig saveResponse(ResponseConfig config) { config.addCredentials(this); @@ -613,7 +654,9 @@ public class SDKConnection { /** * Update the user details. - * The password must be passed to allow the update. + * + * @param config config + * @return Update the user details. */ public UserConfig update(UserConfig config) { config.addCredentials(this); @@ -632,9 +675,11 @@ public class SDKConnection { throw this.exception; } } - + /** * Permanently delete the content with the id. + * + * @param config config */ public void delete(WebMediumConfig config) { config.addCredentials(this); @@ -643,9 +688,11 @@ public class SDKConnection { domain=null; } } - + /** * Permanently delete the forum post with the id. + * + * @param config config */ public void delete(ForumPostConfig config) { config.addCredentials(this); @@ -654,54 +701,68 @@ public class SDKConnection { /** * Permanently delete the issue with the id. + * + * @param config config */ public void delete(IssueConfig config) { config.addCredentials(this); POST(this.url + "/delete-issue", config.toXML()); } - + /** * Permanently delete the response, greetings, or default response with the response id (and question id). + * + * @param config config */ public void delete(ResponseConfig config) { config.addCredentials(this); POST(this.url + "/delete-response", config.toXML()); } - + /** * Permanently delete the avatar media. + * + * @param config config */ public void delete(AvatarMedia config) { config.addCredentials(this); POST(this.url + "/delete-avatar-media", config.toXML()); } - + /** * Permanently delete the avatar background. + * + * @param config config */ public void deleteAvatarBackground(AvatarConfig config) { config.addCredentials(this); POST(this.url + "/delete-avatar-background", config.toXML()); } - + /** * Save the avatar media tags. + * + * @param config config */ public void saveAvatarMedia(AvatarMedia config) { config.addCredentials(this); POST(this.url + "/save-avatar-media", config.toXML()); } - + /** * Flag the content as offensive, a reason is required. + * + * @param config config */ public void flag(WebMediumConfig config) { config.addCredentials(this); POST(this.url + "/flag-" + config.getType(), config.toXML()); } - + /** * Subscribe for email updates for the post. + * + * @param config config */ public void subscribe(ForumPostConfig config) { config.addCredentials(this); @@ -710,22 +771,28 @@ public class SDKConnection { /** * Subscribe for email updates for the issue. + * + * @param config config */ public void subscribe(IssueConfig config) { config.addCredentials(this); POST(this.url + "/subscribe-issue", config.toXML()); } - + /** * Subscribe for email updates for the forum. + * + * @param config config */ public void subscribe(ForumConfig config) { config.addCredentials(this); POST(this.url + "/subscribe-forum", config.toXML()); } - + /** * Unsubscribe from email updates for the post. + * + * @param config config */ public void unsubscribe(ForumPostConfig config) { config.addCredentials(this); @@ -734,70 +801,88 @@ public class SDKConnection { /** * Unsubscribe from email updates for the issue. + * + * @param config config */ public void unsubscribe(IssueConfig config) { config.addCredentials(this); POST(this.url + "/unsubscribe-issue", config.toXML()); } - + /** * Unsubscribe from email updates for the forum. + * + * @param config config */ public void unsubscribe(ForumConfig config) { config.addCredentials(this); POST(this.url + "/unsubscribe-forum", config.toXML()); } - + /** * Thumbs up the content. + * + * @param config config */ public void thumbsUp(WebMediumConfig config) { config.addCredentials(this); POST(this.url + "/thumbs-up-" + config.getType(), config.toXML()); } - + /** * Thumbs down the content. + * + * @param config config */ public void thumbsDown(WebMediumConfig config) { config.addCredentials(this); POST(this.url + "/thumbs-down-" + config.getType(), config.toXML()); } - + /** * Rate the content. + * + * @param config config */ public void star(WebMediumConfig config) { config.addCredentials(this); POST(this.url + "/star-" + config.getType(), config.toXML()); } - + /** * Thumbs up the content. + * + * @param config config */ public void thumbsUp(ForumPostConfig config) { config.addCredentials(this); POST(this.url + "/thumbs-up-post", config.toXML()); } - + /** * Thumbs down the content. + * + * @param config config */ public void thumbsDown(ForumPostConfig config) { config.addCredentials(this); POST(this.url + "/thumbs-down-post", config.toXML()); } - + /** * Rate the content. + * + * @param config config */ public void star(ForumPostConfig config) { config.addCredentials(this); POST(this.url + "/star-post", config.toXML()); } - + /** * Flag the forum post as offensive, a reason is required. + * + * @param config config */ public void flag(ForumPostConfig config) { config.addCredentials(this); @@ -806,6 +891,8 @@ public class SDKConnection { /** * Thumbs up the content. + * + * @param config config */ public void thumbsUp(IssueConfig config) { config.addCredentials(this); @@ -814,6 +901,8 @@ public class SDKConnection { /** * Thumbs down the content. + * + * @param config config */ public void thumbsDown(IssueConfig config) { config.addCredentials(this); @@ -822,6 +911,8 @@ public class SDKConnection { /** * Rate the content. + * + * @param config config */ public void star(IssueConfig config) { config.addCredentials(this); @@ -830,14 +921,18 @@ public class SDKConnection { /** * Flag the forum post as offensive, a reason is required. + * + * @param config config */ public void flag(IssueConfig config) { config.addCredentials(this); POST(this.url + "/flag-issue", config.toXML()); } - + /** * Flag the user post as offensive, a reason is required. + * + * @param config config */ public void flag(UserConfig config) { config.addCredentials(this); @@ -846,8 +941,9 @@ public class SDKConnection { /** * Process the bot chat message and return the bot's response. - * The ChatConfig should contain the conversation id if part of a conversation. - * If a new conversation the conversation id is returned in the response. + * + * @param config config + * @return Process the bot chat message and return the bot's response. */ public ChatResponse chat(ChatConfig config) { config.addCredentials(this); @@ -869,6 +965,9 @@ public class SDKConnection { /** * Process the avatar message and return the avatars response. * This allows the speech and video animation for an avatar to be generated for the message. + * + * @param config config + * @return avatarMessage */ public ChatResponse avatarMessage(AvatarMessage config) { config.addCredentials(this); @@ -886,18 +985,24 @@ public class SDKConnection { throw this.exception; } } - + /** * Process the speech message and return the server generate text-to-speech audio file. * This allows for server-side speech generation. + * + * @param config config + * @return tts */ public String tts(Speech config) { config.addCredentials(this); return POST(this.url + "/speak", config.toXML()); } - + /** * Return the administrators of the content. + * + * @param config config + * @return Return the administrators of the content. */ public List getAdmins(WebMediumConfig config) { config.addCredentials(this); @@ -914,9 +1019,12 @@ public class SDKConnection { } return users; } - + /** * Return the list of user details for the comma separated values list of user ids. + * + * @param usersCSV usersCSV + * @return getUsers */ public List getUsers(String usersCSV) { UserConfig config = new UserConfig(); @@ -936,9 +1044,12 @@ public class SDKConnection { } return users; } - + /** * Return the list of forum posts for the forum browse criteria. + * + * @param config config + * @return Return the list of forum posts for the forum browse criteria. */ public List getPosts(BrowseConfig config) { config.addCredentials(this); @@ -958,6 +1069,9 @@ public class SDKConnection { /** * Return the list of issues for the issue tracker browse criteria. + * + * @param config config + * @return Return the list of issues for the issue tracker browse criteria. */ public List getIssues(BrowseConfig config) { config.addCredentials(this); @@ -974,9 +1088,12 @@ public class SDKConnection { } return instances; } - + /** * Return the list of categories for the type, and domain. + * + * @param config config + * @return Return the list of categories for the type, and domain. */ public List getCategories(ContentConfig config) { config.addCredentials(this); @@ -993,9 +1110,12 @@ public class SDKConnection { } return categories; } - + /** * Return the list of tags for the type, and domain. + * + * @param config config + * @return Return the list of tags for the type, and domain. */ public List getTags(ContentConfig config) { config.addCredentials(this); @@ -1011,10 +1131,12 @@ public class SDKConnection { } return tags; } - + /** - * Return the list of bot templates. - */ + * Return the list of bot templates. + * + * @return Return the list of bot templates. + */ //return the list of templates with the pictures. public List getTemplates() { @@ -1031,9 +1153,12 @@ public class SDKConnection { } return instances; } - + /** * Return the users for the content. + * + * @param config config + * @return Return the users for the content. */ public List getUsers(WebMediumConfig config) { config.addCredentials(this); @@ -1050,9 +1175,12 @@ public class SDKConnection { } return users; } - + /** * Return the channel's bot configuration. + * + * @param config config + * @return Return the channel's bot configuration. */ public BotModeConfig getChannelBotMode(ChannelConfig config) { config.addCredentials(this); @@ -1070,73 +1198,84 @@ public class SDKConnection { throw this.exception; } } - + /** * Save the channel's bot configuration. + * + * @param config config */ public void saveChannelBotMode(BotModeConfig config) { config.addCredentials(this); POST(this.url + "/save-channel-bot-mode", config.toXML()); } - + /** * Save the forum's bot configuration. + * + * @param config config */ public void saveForumBotMode(BotModeConfig config) { config.addCredentials(this); POST(this.url + "/save-forum-bot-mode", config.toXML()); } - + /** * Save the bot's learning configuration. + * + * @param config config */ public void saveLearning(LearningConfig config) { config.addCredentials(this); POST(this.url + "/save-learning", config.toXML()); } - + /** * Save the bot's voice configuration. + * + * @param config config */ public void saveVoice(VoiceConfig config) { config.addCredentials(this); POST(this.url + "/save-voice", config.toXML()); } - + /** * Save the bot's avatar configuration. + * + * @param config config */ public void saveBotAvatar(InstanceConfig config) { config.addCredentials(this); POST(this.url + "/save-bot-avatar", config.toXML()); } - - /** - * Train the bot with a new question/response pair. - */ - public void train(TrainingConfig config) { - config.addCredentials(this); - POST(this.url + "/train-instance", config.toXML()); - } - + + /** * Perform the user administration task (add or remove users, or administrators). + * + * @param config config */ public void userAdmin(UserAdminConfig config) { config.addCredentials(this); POST(this.url + "/user-admin", config.toXML()); } - + /** * Save the image as the avatar's background. + * + * @param file file + * @param config config */ public void saveAvatarBackground(String file, AvatarMedia config) { config.addCredentials(this); POSTIMAGE(this.url + "/save-avatar-background", file, config.name, config.toXML()); } - + /** * Add the avatar media file to the avatar. + * + * @param file file + * @param config config */ public void createAvatarMedia(String file, AvatarMedia config) { config.addCredentials(this); @@ -1150,8 +1289,12 @@ public class SDKConnection { POSTFILE(this.url + "/create-avatar-media", file, config.name, config.toXML()); } } + /** * Add the graphic media file to the graphic. + * + * @param file file + * @param config config */ public void createGraphicMedia(String file, GraphicConfig config) { config.addCredentials(this); @@ -1161,9 +1304,15 @@ public class SDKConnection { POSTFILE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); } } + /** * Update the contents icon. * The file will be uploaded to the server. + * + * @param file file + * @param config config + * @param + * @return updateIcon */ @SuppressWarnings("unchecked") public T updateIcon(String file, T config) { @@ -1182,10 +1331,13 @@ public class SDKConnection { throw this.exception; } } - + /** * Update the user's icon. - * The file will be uploaded to the server. + * + * @param file file + * @param config config + * @return Update the user's icon. */ public UserConfig updateIcon(String file, UserConfig config) { config.addCredentials(this); @@ -1203,7 +1355,16 @@ public class SDKConnection { throw this.exception; } } - + + /** + * POSTIMAGE + * + * @param url url + * @param file file + * @param name name + * @param xml xml + * @return POSTIMAGE + */ public String POSTIMAGE(String url, String file, String name, String xml) { if (this.debug) { System.out.println("POST: " + url); @@ -1211,44 +1372,18 @@ public class SDKConnection { System.out.println("XML: " + xml); } String result = ""; -// try { //===================== -// Bitmap bitmap = loadImage(file, 600, 600); -// ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); -// byte[] byte_arr = stream.toByteArray(); -// ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); -// -// MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); -// -// multipartEntity.addPart("file", fileBody); -// multipartEntity.addPart("xml", new StringBody(xml)); -// -// HttpClient httpclient = new DefaultHttpClient(); -// HttpResponse response = null; -// -// HttpPost httppost = new HttpPost(url); -// httppost.setEntity(multipartEntity); -// response = httpclient.execute(httppost); -// -// HttpEntity entity = response.getEntity(); -// if (entity != null) { -// result = EntityUtils.toString(entity, HTTP.UTF_8); -// } -// -// if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { -// this.exception = new SDKException("" -// + response.getStatusLine().getStatusCode() -// + " : " + result); -// throw this.exception; -// } -// -// } catch (Exception exception) { -// this.exception = new SDKException(exception); -// throw this.exception; -// } return result; } + /** + * POSTIMAGE + * + * @param url url + * @param bitmap bitmap + * @param name name + * @param xml xml + * @return POSTIMAGE + */ public String POSTIMAGE(String url, PixelMap bitmap, String name, String xml) { if (this.debug) { System.out.println("POST: " + url); @@ -1257,7 +1392,6 @@ public class SDKConnection { String result = ""; try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); //===================== byte[] byte_arr = stream.toByteArray(); ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); @@ -1291,7 +1425,16 @@ public class SDKConnection { } return result; } - + + /** + * POSTHDIMAGE + * + * @param url url + * @param file file + * @param name name + * @param xml xml + * @return POSTHDIMAGE + */ public String POSTHDIMAGE(String url, String file, String name, String xml) { if (this.debug) { System.out.println("POST: " + url); @@ -1299,44 +1442,18 @@ public class SDKConnection { System.out.println("XML: " + xml); } String result = ""; - try { -// Bitmap bitmap = loadImage(file, 600, 600); //===================== -// ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); -// byte[] byte_arr = stream.toByteArray(); -// ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); -// -// MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); -// -// multipartEntity.addPart("file", fileBody); -// multipartEntity.addPart("xml", new StringBody(xml)); -// -// HttpClient httpclient = new DefaultHttpClient(); -// HttpResponse response = null; -// -// HttpPost httppost = new HttpPost(url); -// httppost.setEntity(multipartEntity); -// response = httpclient.execute(httppost); -// -// HttpEntity entity = response.getEntity(); -// if (entity != null) { -// result = EntityUtils.toString(entity, HTTP.UTF_8); -// } -// -// if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { -// this.exception = new SDKException("" -// + response.getStatusLine().getStatusCode() -// + " : " + result); -// throw this.exception; -// } - - } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } return result; } - + + /** + * POSTFILE + * + * @param url url + * @param path path + * @param name name + * @param xml xml + * @return POSTFILE + */ public String POSTFILE(String url, String path, String name, String xml) { if (this.debug) { System.out.println("POST: " + url); @@ -1388,35 +1505,11 @@ public class SDKConnection { return result; } - public PixelMap loadImage(String path, int reqWidth, int reqHeight) { -// BitmapFactory.Options options = new BitmapFactory.Options(); //===================== -// options.inJustDecodeBounds = true; -// BitmapFactory.decodeFile(path, options); -// -// int height = options.outHeight; -// int width = options.outWidth; -// options.inPreferredConfig = Bitmap.Config.RGB_565; -// int inSampleSize = 1; -// -// if (height > reqHeight) { -// inSampleSize = Math.round((float)height / (float)reqHeight); -// } -// -// int expectedWidth = width / inSampleSize; -// -// if (expectedWidth > reqWidth) { -// inSampleSize = Math.round((float)width / (float)reqWidth); -// } -// -// options.inSampleSize = inSampleSize; -// options.inJustDecodeBounds = false; -// -// return BitmapFactory.decodeFile(path, options); - return null; - } - /** * Return the forum's bot configuration. + * + * @param config config + * @return Return the forum's bot configuration. */ public BotModeConfig getForumBotMode(ForumConfig config) { config.addCredentials(this); @@ -1434,9 +1527,12 @@ public class SDKConnection { throw this.exception; } } - + /** * Return the bot's voice configuration. + * + * @param config config + * @return Return the bot's voice configuration. */ public VoiceConfig getVoice(InstanceConfig config) { config.addCredentials(this); @@ -1454,9 +1550,12 @@ public class SDKConnection { throw this.exception; } } - + /** * Return the bot's default responses. + * + * @param config config + * @return Return the bot's default responses. */ public List getDefaultResponses(InstanceConfig config) { config.addCredentials(this); @@ -1471,26 +1570,12 @@ public class SDKConnection { } return defaultResponses; } - - /** - * Return the bot's greetings. - */ - public List getGreetings(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-greetings", config.toXML()); - List greetings = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return greetings; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - greetings.add(((Element)root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); - } - return greetings; - } - + /** * Search the bot's responses. + * + * @param config config + * @return Search the bot's responses. */ public List getResponses(ResponseSearchConfig config) { config.addCredentials(this); @@ -1507,9 +1592,12 @@ public class SDKConnection { } return responses; } - + /** * Search the bot's conversations. + * + * @param config config + * @return Search the bot's conversations. */ public List getConversations(ResponseSearchConfig config) { config.addCredentials(this); @@ -1526,9 +1614,12 @@ public class SDKConnection { } return conversations; } - + /** * Return the bot's learning configuration. + * + * @param config config + * @return Return the bot's learning configuration. */ public LearningConfig getLearning(InstanceConfig config) { config.addCredentials(this); @@ -1546,10 +1637,14 @@ public class SDKConnection { throw this.exception; } } - + /** * Return the list of content for the browse criteria. * The type defines the content type (one of Bot, Forum, Channel, Domain). + * + * @param ability ability + * @param config config + * @return browse */ public List browse(Ability ability,BrowseConfig config) { config.addCredentials(this); @@ -1587,9 +1682,12 @@ public class SDKConnection { } return instances; } - + /** * Return the list of media for the avatar. + * + * @param config config + * @return Return the list of media for the avatar. */ public List getAvatarMedia(AvatarConfig config) { config.addCredentials(this); @@ -1606,9 +1704,12 @@ public class SDKConnection { } return instances; } - + /** * Return the script source + * + * @param config config + * @return Return the script source */ public ScriptSourceConfig getScriptSource(ScriptConfig config) { config.addCredentials(this); @@ -1626,17 +1727,22 @@ public class SDKConnection { throw this.exception; } } - + /** * Create or update script - Save the script source + * + * @param config config */ public void saveScriptSource(ScriptSourceConfig config) { config.addCredentials(this); POST(this.url + "/save-script-source", config.toXML()); } - + /** * Return the source code for a single bot script + * + * @param config config + * @return Return the source code for a single bot script */ public ScriptSourceConfig getBotScriptSource(ScriptSourceConfig config) { config.addCredentials(this); @@ -1654,9 +1760,12 @@ public class SDKConnection { throw this.exception; } } - + /** * Return a list of the bots scripts + * + * @param config config + * @return Return a list of the bots scripts */ public List getBotScripts(InstanceConfig config) { config.addCredentials(this); @@ -1673,123 +1782,118 @@ public class SDKConnection { } return botScripts; } + /** * import a script to the bot + * + * @param config config */ public void importBotScript(ScriptConfig config) { config.addCredentials(this); POST(this.url + "/import-bot-script", config.toXML()); } - + /** * import a chatlog/response list to the bot + * + * @param config config */ public void importBotLog(ScriptConfig config) { config.addCredentials(this); POST(this.url + "/import-bot-log", config.toXML()); } - - + + /** * Save the bot script source + * + * @param config config */ public void saveBotScriptSource(ScriptSourceConfig config) { config.addCredentials(this); POST(this.url + "/save-bot-script-source", config.toXML()); } - + /** * Delete selected bot script + * + * @param config config */ public void deleteBotScript(ScriptSourceConfig config) { config.addCredentials(this); POST(this.url + "/delete-bot-script", config.toXML()); } - + /** * Move up one bot script + * + * @param config config */ public void upBotScript(ScriptSourceConfig config) { config.addCredentials(this); POST(this.url + "/up-bot-script", config.toXML()); } - + /** * Move down one bot script + * + * @param config config */ public void downBotScript(ScriptSourceConfig config) { config.addCredentials(this); POST(this.url + "/down-bot-script", config.toXML()); } - + /** * Return the list of content types. + * + * @return Return the list of content types. */ public String[] getTypes() { return types; } - - /** - * Return the channel types. - */ - public String[] getChannelTypes() { - return channelTypes; - } - + /** * Return the access mode types. + * + * @return Return the access mode types. */ public String[] getAccessModes() { return accessModes; } - + /** * Return the media access mode types. + * + * @return Return the media access mode types. */ public String[] getMediaAccessModes() { return mediaAccessModes; } - - /** - * Return the learning mode types. - */ - public String[] getLearningModes() { - return learningModes; - } - - /** - * Return the correction mode types. - */ - public String[] getCorrectionModes() { - return correctionModes; - } - - /** - * Return the bot mode types. - */ - public String[] getBotModes() { - return botModes; - } - + /** * Return the current connected user. + * + * @return Return the current connected user. */ public UserConfig getUser() { return user; } - + /** * Set the current connected user. - * connect() should be used to validate and connect a user. + * + * @param user */ public void setUser(UserConfig user) { this.user = user; } - + /** * Return the current domain. - * A domain is an isolated content space. + * + * @return Return the current domain. */ public DomainConfig getDomain() { return domain; @@ -1797,44 +1901,45 @@ public class SDKConnection { /** * Set the current domain. - * A domain is an isolated content space. - * connect() should be used to validate and connect a domain. + * + * @param domain domain */ public void setDomain(DomainConfig domain) { this.domain = domain; } - + /** * Return the current application credentials. + * + * @return getCredentials */ public Credentials getCredentials() { return credentials; } - + /** * Set the application credentials. + * + * @param credentials credentials */ public void setCredentials(Credentials credentials) { this.credentials = credentials; this.url = credentials.url; } - - /** - * Return is debugging has been enabled. - */ - public boolean isDebug() { - return debug; - } - + /** * Enable debugging, debug messages will be logged to System.out. + * + * @param debug debug */ public void setDebug(boolean debug) { this.debug = debug; } - + /** * Return the last thrown exception. + * + * @return Return the last thrown exception. */ public SDKException getException() { return exception; @@ -1844,6 +1949,12 @@ public class SDKConnection { this.exception = exception; } + /** + * GET + * + * @param url url + * @return GET string + */ public String GET(String url) { if (this.debug) { System.out.println("GET: " + url); @@ -1873,6 +1984,13 @@ public class SDKConnection { return xml; } + /** + * POST + * + * @param url url + * @param xml xml + * @return POST + */ public String POST(String url, String xml) { if (this.debug) { System.out.println("POST: " + url); @@ -1910,6 +2028,14 @@ public class SDKConnection { return result; } + /** + * POSTUpdate + * + * @param ability ability + * @param url url + * @param xml xml + * @return POSTUpdate + */ public String POSTUpdate(Ability ability,String url, String xml) { if (this.debug) { System.out.println("POST: " + url); @@ -1940,10 +2066,12 @@ public class SDKConnection { } /** - * This method is used to get cookies from response + * getResponse * - * @param client OkHttpClient to get cookies from response - * @param url Http URL + * @param client client + * @param url url + * @param xml xml + * @return getResponse */ public Response getResponse(OkHttpClient client, String url, String xml) { // code request code here @@ -1960,46 +2088,19 @@ public class SDKConnection { } catch (IOException e) { e.printStackTrace(); } -// call.enqueue(new Callback() { -// @Override -// public void onFailure(Call call, IOException exception) { -// } -// -// @Override -// public void onResponse(Call call, Response response) { -// if (response != null && response.body() != null) { -// List cookieList = response.headers("Set-Cookie"); -// StringBuilder stringBuilder = new StringBuilder(); -// if (cookieList.size() > 0) { -// for (String cookie : cookieList) { -// stringBuilder.append(cookie).append(","); -// } -// } -// content[0] = response.body().toString(); -// } -// } -// }); return null; } - + + /** + * parse + * + * @param xml xml + * @return parse + */ public Element parse(String xml) { if (this.debug) { System.out.println(xml); } - Document dom = null; - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource source = new InputSource(); - source.setCharacterStream(new StringReader(xml)); - dom = builder.parse(source); - return dom.getDocumentElement(); - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception.getMessage(), exception); - throw this.exception; - } + return (Element) new ShapeElement(); } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BaseAbility.java similarity index 85% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BaseAbility.java index 974e7041f5a8b8f9d1120d99d79dfbaa4907e0b4..c659c6a66288d1f3dd8b6623b662c74d8d26148d 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BaseAbility.java @@ -1,4 +1,4 @@ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/BotSearchAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/BotSearchAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java index fb325e52b0c6a6ae7a3240f806bb52ed2b3d1067..a113dbe2de311c50161407295b3e6911e3a34f63 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/BotSearchAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java @@ -16,9 +16,9 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.listener.SelectListener; import ohos.aafwk.content.Intent; import ohos.agp.components.Text; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java similarity index 79% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index 3b9c8fa624a2b0a01f689edde6dc3cb2081bdd49..102e0e7bcb8517574e4939f7de5ca61d30645592 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java @@ -16,11 +16,11 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.*; +import org.botlibre.sdk.ability.actions.*; import org.botlibre.sdk.config.*; import org.botlibre.sdk.provider.ChatListProvicer; import org.botlibre.sdk.util.*; @@ -339,7 +339,7 @@ public class ChatAbility extends LibreAbility { @Override public void onError(int error) { debug("onError:" + error); - LogUtils.sop("ChatActivity on error executes here!"); + LogUtils.sop(" on error executes here!"); try { isRecording = false; @@ -431,15 +431,7 @@ public class ChatAbility extends LibreAbility { protected void onStart(Intent intent) { super.onStart(intent); LogUtils.sop("进入ChatAbility"); -// if (MainAbility.current == null) { -// terminateAbility(); -// return; -// } -// if (MainAbility.instance == null || !(MainAbility.instance instanceof InstanceConfig)) { -// terminateAbility(); -// return; -// } - super.setUIContent(ResourceTable.Layout_activity_chat); + super.setUIContent(ResourceTable.Layout_ability_chat); ability = this; //clear the messages from the listView - messages.clear(); @@ -451,15 +443,10 @@ public class ChatAbility extends LibreAbility { micLastStat = MainAbility.listenInBackground; getWindow().addFlags(WindowManager.LayoutConfig.MARK_SCREEN_ON_ALWAYS); - //this.instance = (InstanceConfig) MainAbility.instance; - tvTitle = ((Text) findComponentById(ResourceTable.Id_title)); imAvatar = (Image) findComponentById(ResourceTable.Id_icon); tvTitle.setText("Pizza Bot"); imAvatar.setPixelMap(ResourceTable.Media_bot); -// if (MainAbility.online) { -// HttpGetImageAction.fetchImage(this, this.instance.avatar, (Image) findComponentById(ResourceTable.Id_icon)); -// } ttsClient = TtsClient.getInstance(); ttsClient.create(this, ttsListener); @@ -544,18 +531,6 @@ public class ChatAbility extends LibreAbility { microphoneThread(thread); stopListening(); } - } else { -// Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainAbility.voice.language); -// try { -// startAbilityForResult(intent, RESULT_SPEECH); -// textView.setText(""); -// } catch (AbilityNotFoundException exception) { -// Toast toast = Toast.makeText(getApplicationContext(), -// "Your device doesn't support Speech to Text", -// Toast.LENGTH_SHORT); -// toast.show(); -// } } }); @@ -669,16 +644,6 @@ public class ChatAbility extends LibreAbility { } }); - if (!MainAbility.online) { - HttpGetImageAction.setImage(MainAbility.offlineSelectedImage, this.bigImage); - HttpGetImageAction.setImage(MainAbility.offlineSelectedImage, (Image) findComponentById(ResourceTable.Id_responseImageView)); - HttpGetImageAction.setImage(MainAbility.offlineSelectedImage, findComponentById(ResourceTable.Id_icon)); - } else { - //HttpGetImageAction.fetchImage(this, this.instance.avatar, imAvatar); - //HttpGetImageAction.fetchImage(this, instance.avatar, this.bigImage); - //HttpGetImageAction.fetchImage(this, instance.avatar, (Image) findComponentById(ResourceTable.Id_responseImageView)); - } - final ChatConfig config = new ChatConfig(); //config.instance = instance.id; config.avatar = this.avatarId; @@ -724,7 +689,7 @@ public class ChatAbility extends LibreAbility { threadIsOn = false; active = false; try { - thread.stop(); + thread.interrupt(); } catch (Exception ignore) { } return thread; @@ -834,24 +799,8 @@ public class ChatAbility extends LibreAbility { menuComponent.findComponentById(ResourceTable.Id_menuItem6).setClickedListener(listener); menuComponent.findComponentById(ResourceTable.Id_menuItem7).setClickedListener(listener); -// Checkbox checkBox1 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox1); -// Checkbox checkBox2 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox2); -// Checkbox checkBox3 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox3); -// Checkbox checkBox4 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox4); -// Checkbox checkBox5 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox5); -// Checkbox checkBox6 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox6); -// Checkbox checkBox7 = (Checkbox) menuComponent.findComponentById(ResourceTable.Id_checkBox7); -// setCheckBoxShape(checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6); menuDialog.setAlignment(LayoutAlignment.LEFT | LayoutAlignment.BOTTOM); menuDialog.show(); -// statistics.setClickedListener(new Component.ClickedListener() { -// @Override -// public void onClick(Component component) { -// -// menuDialog.hide(); -// menuDialog.remove(); -// } -// }); } private void setCheckBoxShape(Checkbox... checkBoxs) { @@ -864,14 +813,6 @@ public class ChatAbility extends LibreAbility { } public void resetVideoErrorListener() { -// videoView.setOnErrorListener(new OnErrorListener() { -// @Override -// public boolean onError(MediaPlayer mp, int what, int extra) { -// Log.wtf("Video error", "what:" + what + " extra:" + extra); -// videoError = true; -// return true; -// } -// }); } @Override @@ -880,51 +821,9 @@ public class ChatAbility extends LibreAbility { switch (requestCode) { case CAPTURE_IMAGE: { - -// if (resultCode == RESULT_OK) { -// //TODO Make camera intent stop app from reseting -// //Uri photoUri = data.getData(); -// //Do what we like with the photo - send to bot, etc -// -// } else if (resultCode == RESULT_CANCELED) { -// textView.setText("Cancelled"); -// submitChat(); -// } - - break; - } - case CAPTURE_VIDEO: { -// if (resultCode == RESULT_OK) { -// Uri videoUri = data.getData(); -// //Do what we would like with the video -// -// } else if (resultCode == RESULT_CANCELED) { -// textView.setText("Cancelled"); -// submitChat(); -// } - break; - } - case RESULT_SPEECH: { -// if (resultCode == RESULT_OK && data != null) { -// -// ArrayList text = data.getStringArrayListParam(RecognizerIntent.EXTRA_RESULTS); -// -// -// textView.setText(text.get(0)); -// submitChat(); -// } break; } } -// IntentResult scanResult = IntentIntegrator.parseAbilityResult(requestCode, resultCode, data); -// if (scanResult != null) { -// textView.setText("lookup " + scanResult.getContents()); -// submitChat(); -// if (scanResult.getContents().startsWith("http")) { -// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(scanResult.getContents())); -// startAbility(intent); -// } -// } } public void flagResponse() { @@ -974,11 +873,8 @@ public class ChatAbility extends LibreAbility { public void submitCorrection() { final TextField text = new TextField(this); MainAbility.prompt("Enter correction to the bot's response (what it should have said)", this, text, (iDialog, i) -> { -// if (instance == null) { -// return; -// } ChatConfig config = new ChatConfig(); - //config.instance = instance.id; + // config.instance = instance.id; config.conversation = MainAbility.conversation; config.speak = !MainAbility.deviceVoice; config.avatar = avatarId; @@ -1000,15 +896,6 @@ public class ChatAbility extends LibreAbility { config.correction = true; -// Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin); -// config.emote = emoteSpin.getSelectedItem().toString(); -// -// HttpChatAction action = new HttpChatAction(ChatAbility.this, config); -// action.execute(); -// -// TextField v = (TextField) findComponentById(ResourceTable.Id_messageText); -// v.setText(""); -// emoteSpin.setSelection(0); resetToolbar(); webView.load(null, "thinking...", "text/html", "utf-8", null); @@ -1169,7 +1056,7 @@ public class ChatAbility extends LibreAbility { this.videoLayout.setVisibility(Component.HIDE); } - HttpGetImageAction.fetchImage(this, this.avatar.avatar, this.bigImage); +// HttpGetImageAction.fetchImage(this, this.avatar.avatar, this.bigImage); AvatarConfig avatarConfig = (AvatarConfig) this.avatar.credentials(); HttpFetchChatAvatarAction action = new HttpFetchChatAvatarAction(this, avatarConfig); @@ -1206,8 +1093,8 @@ public class ChatAbility extends LibreAbility { } public void resetAvatar(AvatarConfig config) { - HttpGetImageAction.fetchImage(this, config.avatar, this.bigImage); - HttpGetImageAction.fetchImage(this, config.avatar, (Image) findComponentById(ResourceTable.Id_responseImageView)); +// HttpGetImageAction.fetchImage(this, config.avatar, this.bigImage); +// HttpGetImageAction.fetchImage(this, config.avatar, (Image) findComponentById(ResourceTable.Id_responseImageView)); } public void MicConfiguration() { @@ -1278,6 +1165,9 @@ public class ChatAbility extends LibreAbility { /** * Add JavaScript to the HTML to raise postback events to send messages to the bot. + * + * @param html html + * @return String html */ public String linkPostbacks(String html) { if (html.contains("button")) { @@ -1369,19 +1259,11 @@ public class ChatAbility extends LibreAbility { final String text = response.message; if (text == null) { - //listContainer.invalidateViews(); -// if (listContainer.getChildCount() > 2) { -// listContainer.setSelection(list.getCount() - 2); -// } beginListening(); return; } messages.add(response); listContainer.getItemProvider().notifyDataChanged(); -// listContainer.invalidateViews(); -// if (listContainer.getCount() > 2) { -// listContainer.setSelection(list.getCount() - 2); -// } String html = Utils.linkHTML(text); if (stateLayouts == 3 || stateLayouts == 4) { @@ -1395,76 +1277,10 @@ public class ChatAbility extends LibreAbility { boolean talk = (text.trim().length() > 0) && (MainAbility.deviceVoice || (this.response.speech != null && this.response.speech.length() > 0)); if (MainAbility.sound && talk) { if (!MainAbility.disableVideo && !videoError && this.response.isVideo() && this.response.isVideoTalk()) { - -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// try { -// mp.setLooping(true); -// if (!MainAbility.deviceVoice) { -// // Voice audio -// if (MainAbility.online) { -// speechPlayer = playAudio(response.speech, false, false, false); -// speechPlayer.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// mp.release(); -// videoView.post(new Runnable() { -// public void run() { -// cycleVideo(response); -// } -// }); -// runOnUiThread(new Runnable() { -// public void run() { -// if (!music) { -// beginListening(); -// } -// } -// }); -// } -// }); -// -// speechPlayer.play(); -// } -// } else { -// HashMap params = new HashMap(); -// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); -// -// tts.speakText(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); -// } -// } catch (Exception exception) { -// LogUtils.sop(exception.getMessage()); -// } -// } -// }); playVideo(this.response.avatarTalk, false); } else if (talk) { -// if (!MainAbility.deviceVoice) { -// // Voice audio -// if (MainAbility.online) { -// playAudio(this.response.speech, false, false, true); -// } -// } else { -// HashMap params = new HashMap(); -// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); -// -// this.tts.speakText(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); -// } } } else if (talk && (!MainAbility.disableVideo && !videoError && this.response.isVideo() && this.response.avatarTalk != null)) { -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// videoView.setOnCompletionListener(null); -// cycleVideo(response); -// } -// }); playVideo(this.response.avatarTalk, false); handler.sendEvent(BEGIN_LISTENING); @@ -1488,84 +1304,15 @@ public class ChatAbility extends LibreAbility { public void playVideo(String video, boolean loop) { -// if (loop) { -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(true); -// } -// }); -// } -// try { -// Uri videoUri = HttpGetVideoAction.fetchVideo(this, video); -// if (videoUri == null) { -// if (MainAbility.online) { -// videoUri = Uri.parse(MainAbility.connection.fetchImage(video).toURI().toString()); -// } -// } -// videoView.setVideoURI(videoUri); -// videoView.start(); -// } catch (Exception exception) { -// Log.wtf(exception.toString(), exception); -// } } public void cycleVideo(final ChatResponse response) { -// if ((response.avatar2 == null || response.avatar3 == null || response.avatar4 == null || response.avatar5 == null) -// || (response.avatar2.isEmpty() || response.avatar3.isEmpty() || response.avatar4.isEmpty() || response.avatar5.isEmpty()) -// || (response.avatar.equals(response.avatar2) && response.avatar2.equals(response.avatar3) -// && response.avatar3.equals(response.avatar4) && response.avatar4.equals(response.avatar5))) { -// playVideo(response.avatar, true); -// return; -// } -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// cycleVideo(response); -// } -// }); -// int value = random.nextInt(5); -// String avatar = response.avatar; -// switch (value) { -// case 1: -// avatar = response.avatar2; -// break; -// case 2: -// avatar = response.avatar3; -// break; -// case 3: -// avatar = response.avatar5; -// break; -// case 14: -// avatar = response.avatar4; -// break; -// } -// -// try { -// Uri videoUri = HttpGetVideoAction.fetchVideo(this, avatar); -// if (videoUri == null) { -// if (MainAbility.online) { -// videoUri = Uri.parse(MainAbility.connection.fetchImage(avatar).toURI().toString()); -// } -// } -// videoView.setVideoURI(videoUri); -// videoView.start(); -// } catch (Exception exception) { -// LogUtils.sop(exception.toString()); -// } } public Player playAudio(String audio, boolean loop, boolean cache, boolean start) { try { Uri audioUri = null; if (cache) { - audioUri = HttpGetVideoAction.fetchVideo(this, audio); } if (audioUri == null) { audioUri = Uri.parse(MainAbility.connection.fetchImage(audio).toURI().toString()); @@ -1700,8 +1447,6 @@ public class ChatAbility extends LibreAbility { } public void scanBarcode(Component v) { -// IntentIntegrator integrator = new IntentIntegrator(this); -// integrator.initiateScan(); } private void setMicIcon(boolean on, boolean recording) { @@ -1727,10 +1472,6 @@ public class ChatAbility extends LibreAbility { ready.message = text; messages.add(ready); listContainer.getItemProvider().notifyDataChanged(); -// listContainer.invalidateViews(); -// if (listContainer.getCount() > 2) { -// listContainer.setSelection(list.getCount() - 2); -// } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java index 0fbafdfde93430b234ed7a2b82d0ce7d4ae7cd58..a27cd18b1299f79d087d4d640da74ea508ca3cc2 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java @@ -16,10 +16,10 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpCreateUserAction; +import org.botlibre.sdk.ability.actions.HttpCreateUserAction; import org.botlibre.sdk.config.UserConfig; import org.botlibre.sdk.util.ResUtil; import ohos.aafwk.content.Intent; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java similarity index 96% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java index 867233c8dcd3a0c90f17c57333ca6f8f7c46862f..6482acb8bedd2ecf15941cb13b60b6e39e441ea2 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; /** * A convenience enum of different emotional states. diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/HelpAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java similarity index 95% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/HelpAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index 4d34816546b125835bef140d490e966018b9d0c5..3fe761758467de39c6a7641b848c68d56e6431c3 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/HelpAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java @@ -16,13 +16,13 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpFetchAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; -import org.botlibre.sdk.activityy.actions.HttpResultAction; +import org.botlibre.sdk.ability.actions.HttpFetchAction; +import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; +import org.botlibre.sdk.ability.actions.HttpResultAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.ChannelConfig; import org.botlibre.sdk.config.ForumConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/IntentResult.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/IntentResult.java similarity index 91% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/IntentResult.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/IntentResult.java index 5f5641ed1e2840598e5a9a3eafebf5d774d5bb18..84975dbe742d15b6742aab0aff97996b998f9bd2 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/IntentResult.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/IntentResult.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; /** *

Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.

@@ -47,6 +47,8 @@ public final class IntentResult { /** * @return raw content of barcode + * + * @return getContents */ public String getContents() { return contents; @@ -54,6 +56,8 @@ public final class IntentResult { /** * @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names. + * + * @return getFormatName */ public String getFormatName() { return formatName; @@ -61,6 +65,8 @@ public final class IntentResult { /** * @return raw bytes of the barcode content, if applicable, or null otherwise + * + * @return getRawBytes */ public byte[] getRawBytes() { return rawBytes; @@ -68,6 +74,8 @@ public final class IntentResult { /** * @return rotation of the image, in degrees, which resulted in a successful scan. May be null. + * + * @return getOrientation */ public Integer getOrientation() { return orientation; @@ -75,11 +83,18 @@ public final class IntentResult { /** * @return name of the error correction level used in the barcode, if applicable + * + * @return getErrorCorrectionLevel */ public String getErrorCorrectionLevel() { return errorCorrectionLevel; } - + + /** + * toString + * + * @return toString + */ @Override public String toString() { StringBuilder dialogText = new StringBuilder(100); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java similarity index 85% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index 3f4a3e6c2b1004a047aecd33c9cd7dc848067756..cc2503cb58a20a10f3880a5fab22de148bdac1e0 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; @@ -28,18 +28,14 @@ import ohos.aafwk.content.Operation; public abstract class LibreAbility extends Ability { public void help() { -// Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(this.getBundleName()) -// .withAbilityName(HelpAbility.class.getName()) -// .build(); -// intent.setOperation(operation); -// startAbility(intent); + } /** - * 启动activity + * 启动ability + * + * @param ability ability + * @param name name */ public void startOpenAbility(Ability ability,String name){ Intent intent = new Intent(); @@ -53,7 +49,12 @@ public abstract class LibreAbility extends Ability { } /** - * 启动activity + * 启动ability + * + * @param ability ability + * @param name name + * @param key key + * @param param param */ public void startOpenAbility(Ability ability,String name,String key,String param){ Intent intent = new Intent(); @@ -69,6 +70,10 @@ public abstract class LibreAbility extends Ability { /** * getIntent + * + * @param ability ability + * @param name name + * @return getIntent */ public Intent getIntent(Ability ability, String name) { Intent intent = new Intent(); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/ListTagAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/ListTagAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java index e814749e036ef2314b2198511bbc2de5f1d50960..2e63481df90ce4d100c1796fc34d733d0c10213c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/ListTagAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.content.Intent; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java similarity index 99% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index ea8b83bcee1072d56b1f90f0b2ad9d0c30db6b2c..8a30f5710b4f81b71b087f51bfbd8ddbc3784d12 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java @@ -15,7 +15,7 @@ * limitations under the License. * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import java.util.ArrayList; import java.util.List; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 3185099d6ec5187c8bb6e00699b21b68a700fb6c..33443529161e668bbe4b0c7cd5cdf6fbe1282b9d 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -16,10 +16,10 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpConnectAction; +import org.botlibre.sdk.ability.actions.HttpConnectAction; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/SearchAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/SearchAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java index 99b1d2a3d0ec4e8759fa553873d2b51c09474f04..53b5eb2bedcaa0b5c52d97a08a6c3849d8f5e81e 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/SearchAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java @@ -16,14 +16,14 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpBrowseCategoriesAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; -import org.botlibre.sdk.activityy.dialog.SearchDialogBuilder; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.actions.HttpBrowseCategoriesAction; +import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; +import org.botlibre.sdk.ability.dialog.SearchDialogBuilder; +import org.botlibre.sdk.ability.listener.SelectListener; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.util.PreferencesUtils; import org.botlibre.sdk.util.ResUtil; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java similarity index 91% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java index 4b4c8bac5aa4055ca9f9fb3037aa2f396a5028f8..684bfb07544698f1546c89819d18a192d0aec04f 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.util.AsyncTask; import ohos.aafwk.ability.Ability; @@ -40,7 +40,10 @@ public abstract class HttpAction extends AsyncTask { } /** - * 启动activity + * 启动ability + * + * @param ability ability + * @param name name */ public void startOpenAbility(Ability ability, String name) { Intent intent = new Intent(); @@ -65,7 +68,11 @@ public abstract class HttpAction extends AsyncTask { } /** - * 启动activity + * 启动ability + * + * @param ability ability + * @param name name + * @param requestCode requestCode */ public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { Intent intent = new Intent(); diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAddAvatarMediaAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAddAvatarMediaAction.java index c83873af7985cd5cf6ac35ddc8fb4e46e5fb47e3..e0bd534a7d4f157665a028ecc4c3a55db39d99e4 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAddAvatarMediaAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAvatarMessageAction.java similarity index 99% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAvatarMessageAction.java index 448e34a0de096fde5991bacc9a4c66d3d0700d83..116f84d7f4eea5164aebb62da52a1105b6c571e2 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAvatarMessageAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpBrowseCategoriesAction.java similarity index 99% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpBrowseCategoriesAction.java index 152e8a24ad71348b0b977d1ba08be986da5c9a00..5882f9dc42fb074c2d7ee44c57caf44f0185ed9b 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpBrowseCategoriesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import ohos.aafwk.ability.Ability; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChangeIconAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChangeIconAction.java index ea62e54ec97744105480b532ddb5cfd1f8edcec2..bd6514f4d8a4b49aedd544e35b3cbc674dc4b5e4 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChangeIconAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChangeUserIconAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChangeUserIconAction.java index d1896c134c2a1f85081b043a0f55f36604a89ba6..3639e3c93c4ebe8789200490ea3c2cdb330d1602 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChangeUserIconAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java similarity index 99% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java index b25925b039326e4a8be5960200c3a1a1887613b5..f74982ea2616e4eb7e4b5bd1f78e9fe4291119ef 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java index 1b518dcc54796500362c502bf60ceaae5438362c..dd3efc61703b320507273886cd2cc06efa6ad289 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java similarity index 98% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java index cd19265d3126450c04e4f83cffc38a7261debd9a..07ab9d620cf25e2d854134a7a68e484704c519c4 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.WebMediumConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelFileAttachmentAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelFileAttachmentAction.java index 075e27d04afc91bdaa00e48dae011b509fef58bc..10d8ba353dc581e6ba82f998e130cd3b97c8d051 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelFileAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelImageAttachmentAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelImageAttachmentAction.java index cf874a13752d47400679af080a94b9ccd29a08cd..52f21351d8c71453369dfb422041544acca447df 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelImageAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateForumPostAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateForumPostAction.java index c452ff0f9df95e9f895e81ad192ed7213492f4f7..6bdb577e7ef3ded32caed03bd1ff0cce17e63d9a 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueAction.java index 4893832d1dcc10063bf074880eb26b74b4d0ad72..8c64794dff7311162b5a93259fa93c38ad1ee6b0 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java index f67cdd55bc47111f5f6fdcd0f181c4c9a68552f2..9a62ce614d0c85347b230f20d7109e2152162c23 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerFileAttachmentAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerFileAttachmentAction.java index 5aa47a9e544067a0fce951ab5dcfb5c1f6a0ce9b..18f8c053134ddcec820b4da8a35dae99b4a92bd1 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerFileAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerImageAttachmentAction.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerImageAttachmentAction.java index 5a02f496400c43e900b6bbcc23d26a615b647ef7..dd17bfa37ed020c91d86d206a3cab2a91abc3dc9 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerImageAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.MediaConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateReplyAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateReplyAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateReplyAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateReplyAction.java index f39570cf3c34986ea6af0ffa9559f5578d469e64..e89e3eac48b21b985561744383b4f1b63899e34b 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateReplyAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateReplyAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java index 0b94d353ea519d0f02506a6594146a2876aa19ab..18ff0673a175067bbddea811b127bb7fe77e792a 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserMessageAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserMessageAction.java index b4e9a82d1eeb2b498226a3ee9d84f08083d047f7..e8b75f39a5126fbbedb71cb42d651a587d98c981 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserMessageAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAction.java index 96c1a4f2640ac21fa5cf7650a1e3a3a34fb08299..13a3dd1994f1b862f1819167c1192eb113241e65 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarBackgroundAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAvatarBackgroundAction.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarBackgroundAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAvatarBackgroundAction.java index 85ebd7d08395534df2d3294cde7d8d8b46ab30eb..0eee4bdd0f23de23e237adb617237ae4e259b768 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarBackgroundAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAvatarBackgroundAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAvatarMediaAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAvatarMediaAction.java index 3ab854bdaf1593140f1403ad73108934507495e5..7c70b8f70ed0a082275cda7c755b751b6288deda 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteAvatarMediaAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteBotScriptAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteBotScriptAction.java index e516361666951b2838f11f84958294129463073d..ff496dac9a805e29df2d846eac6a173344a035b7 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteBotScriptAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ScriptSourceConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteForumPostAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteForumPostAction.java index c2b719f086169b95e0c9bd7fb34dcd6870970c91..2064883e58e361555e972249f0858c1056857ba6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ForumPostConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteIssueAction.java index 70c8ca32b44967c1f65154ccd2a1e47b749b2611..57408fea9f88b4aea9900bf5e87a846588f929a4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.IssueConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteResponseAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteResponseAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteResponseAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteResponseAction.java index a2bdc5e0c21fad0bcaf45dbe92c0cbb71dbc313e..9c00c2ff9a16a9f026f245eda6edeb3f41152735 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteResponseAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteResponseAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ResponseConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDownBotScriptAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDownBotScriptAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDownBotScriptAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDownBotScriptAction.java index 6e98c941e21d3c73f3dd98dc2360aee06c6ee4df..a7165d948a6f1c8d3ec94143a1c9125005f3dc56 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDownBotScriptAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDownBotScriptAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ScriptSourceConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java index d4206382290eaa75312de99f37911362d68f56b7..b81fb314524d65f247b86ecbd653202bceed3e92 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.*; @@ -80,7 +80,7 @@ public class HttpFetchAction extends HttpUIResultAction { cookies.putString(this.config.getType(), this.config.name); cookies.flushSync(); - Class childAbility = MainAbility.getActivity(this.config); + Class childAbility = MainAbility.getAbility(this.config); if (this.launch && !this.config.isExternal) { if (this.config instanceof ChannelConfig) { // childAbility = LiveChatAbility.class; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java similarity index 31% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java index 47d182f66999a35d8b57e030816f13f2475d5e28..250fd5afcc3740eab4c25e40af0f499b7a6292d9 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright 2014 Paphus Solutions Inc. + * Copyright 2017 Paphus Solutions Inc. * * Licensed under the Eclipse Public License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,49 +16,103 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.ability.ChatAbility; +import org.botlibre.sdk.ability.ListTemplateView; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.WebMediumConfig; +import org.botlibre.sdk.micro.MicroConnection; +import org.botlibre.sdk.util.LogUtils; import ohos.aafwk.ability.Ability; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayAttributes; +import ohos.agp.window.service.DisplayManager; -public class HttpFetchIssueAction extends HttpUIAction { - IssueConfig config; +import java.util.Optional; - public HttpFetchIssueAction(Ability ability, IssueConfig config) { +public class HttpFetchActionOffline extends HttpUIAction { + WebMediumConfig config; + MicroConnection microConnection = new MicroConnection(); + boolean launch; + + public HttpFetchActionOffline(Ability ability, WebMediumConfig config) { + super(ability); + this.config = config; + } + + + public HttpFetchActionOffline(Ability ability, WebMediumConfig config, boolean launch) { super(ability); this.config = config; + this.launch = launch; + } + + @Override + protected void onPreExecute() { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + Text title = (Text) layout.findComponentById(ResourceTable.Id_title); + title.setText("Initializing Bot"); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); } @Override protected String doInBackground(Void... params) { + try { - this.config = MainAbility.connection.fetch(this.config); + //switch connections. + MainAbility.setOnline(false); + microConnection = (MicroConnection) MainAbility.connection; + this.config = microConnection.fetch(this.config); } catch (Exception exception) { this.exception = exception; + LogUtils.e("HttpFetchAction", exception.toString()); + return ""; } - return ""; - } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); + if (this.ability instanceof ListTemplateView) { + this.ability.terminateAbility(); + } if (this.exception != null) { - return; + return ""; } try { - MainAbility.issue = this.config; - -// if (this.ability instanceof IssueAbility) { -// this.ability.terminateAbility(); -// } -// -// startOpenAbility(this.ability, IssueAbility.class.getName()); + MainAbility.instance = this.config; + Class childAbility = MainAbility.getAbility(this.config); + if (this.launch && !this.config.isExternal) { + if (this.config instanceof InstanceConfig) { + childAbility = ChatAbility.class; + HttpAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig) MainAbility.instance.credentials()); + action.execute(); + } + } + startOpenAbility(this.ability, childAbility.getName()); } catch (Exception error) { this.exception = error; MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; + return ""; } + return ""; } + @SuppressWarnings("rawtypes") + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchBotAvatarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchBotAvatarAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchBotAvatarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchBotAvatarAction.java index 450488df8f5e8a014bd3f351003a115c7935bf66..d8f79f1dbf399cfecdaa73ee416ee7ebf77d14fb 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchBotAvatarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchBotAvatarAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java index 213bebc6abf9f7f8fceeb894f4c730a055e388a0..fa0b984363739d8ad83de0e2db0f4b0312d6a1ed 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchForumPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchForumPostAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchForumPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchForumPostAction.java index b723aacb1a676648f1a01c859c4fa8aaa2019c92..80792158bc52a62b67810af0e99d8ec99f57ef6b 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchForumPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ForumPostConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchIssueAction.java index 47d182f66999a35d8b57e030816f13f2475d5e28..60cdcae54bd5981feb4fca0d74a0c4dc01c6a124 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.IssueConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java index e0ef846b3a366a15c2f7175e0d617dbf16ac78d6..60e055ff9652220789ea2f35446a833013264940 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchUserAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchUserAction.java index 7fe3d6bdc3ed27fc56041b2525a5e99bb339a420..309cb81618e3a61c587edbcd9e4bff39b57a892e 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchUserAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java index 5a4108c949a93a6fb987985b978d061f95e7cc16..26381dcf81a52e9020890c1944b5598ec9386f13 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.config.WebMediumConfig; import ohos.aafwk.ability.Ability; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagAction.java index 92293cf14d773a4088d7d6b5c162cab10dc7b691..6be6e121b9890d159431f3a5ec817768277d725d 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.WebMediumConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagForumPostAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagForumPostAction.java index 8782d8d0e169254356caab4fb9a9c54c17b0a599..1f2bb643445b9aaa71d0b39f16f0450dd7434ab6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ForumPostConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java index ba7ee1b6a02bac03af0bc1b692089738deffc7fe..1accaa47641a1ff71684b3ddffbe7b2aff3b1294 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.IssueConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java index 876e4f00d97462425debd6f85421e70f670742cc..6222aeb7081223e23c9b016988fd98557e0e34ea 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAdminsAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAdminsAction.java index fb9f238d0892a499b5ce12aa9ce7bd9b2d38b5c4..e108044bc02e311f0c7187d32eadf23ec73165b6 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAdminsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java index 7859eeab096d36455c99abd8029e5de02cfec841..9e2aff1ba6938c2632039624bd30bdbd13535388 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptSourceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetBotScriptSourceAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptSourceAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetBotScriptSourceAction.java index 2e1f0d485d25c88bcf9345524b4e2737d63a2b9e..136e788c80c3bb456ebf074b820c33631bb085e8 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptSourceAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetBotScriptSourceAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ScriptSourceConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetBotScriptsAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetBotScriptsAction.java index 6702275bc375bb36b7890dcb9615be7dbf9ccd8a..b1876b7a2688c2a4a826701ace799e3eb2910981 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetBotScriptsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.InstanceConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetCategoriesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetCategoriesAction.java similarity index 98% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetCategoriesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetCategoriesAction.java index eea8e1fbe9cdf31c4114d20f96a81b013eb74697..150ed0856d28f2686e9d483e1d1d3bbad19295ff 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetCategoriesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetCategoriesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ContentConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetChannelBotModeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetChannelBotModeAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetChannelBotModeAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetChannelBotModeAction.java index 54ce4a48090960bc13514419d93e41bb8d7cf3a4..8a33f9465dae904fd7193700d907ff2fec990d5e 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetChannelBotModeAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetChannelBotModeAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetConversationsAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetConversationsAction.java index 8405db85144d1a04de0662c6c208df09284acff4..ca2e164715300266566a94378ba22a2937f24660 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetConversationsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ConversationConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetForumBotModeAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetForumBotModeAction.java index 7aeccc1f7248492df6cd3d373236ced01e6c105d..097da16513869b0cd5b59cc503e1a0d59ee2a2c0 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetForumBotModeAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.BotModeConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java similarity index 99% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java index 710b66f9925d214f033f207c1ee90d339fbc801d..d9eb94280adbd2a4b22908c51895ae16ff014009 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.BrowseConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetIssuesAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetIssuesAction.java index 70a0f3dce20f49072019b2fb0a7f00ff06639e3c..8ddd1cda98d4e5ac00c3fe334b9e42a0f4246fc4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetIssuesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.BrowseConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java index 078f1ed08c11e1be3798303dfe8282dd59983108..40e01a437282e334daf74a2f3f02e0b1d7225302 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.InstanceConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLiveChatUsersAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLiveChatUsersAction.java index 2c9566f93726186856ca3f2f79218b05902dc1a6..4a32049f9eb652222593df49d9d35c14da193db3 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLiveChatUsersAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java similarity index 98% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java index 8162d98286151a7c0727c06c60b44a218dcf6ed5..09f2164cca848c27379a0ee2fcad425fd34291e4 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetResponsesAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetResponsesAction.java index 560b4892c062ea316c871140714f2882df993625..ace1bddabe60b30a6d10c736164922c06c81b8f7 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetResponsesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetScriptSourceAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetScriptSourceAction.java index a9dff7cd95d68685028b6350f19153281d3c6977..a45af42c1bf33b311770beb8a3aa59e18b41469f 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetScriptSourceAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ScriptConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTagsAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTagsAction.java index b3a658f477c801e9aa4ce2de9ed20de10044954f..94a0ebf70202bf89b2b69bb152c04ed0beb3faed 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTagsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java index 2a8e59efd665ad22441d81beda15829da0519229..cf41f9c81aefcfb292699e84e16057d6138f270b 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetUsersAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetUsersAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetUsersAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetUsersAction.java index 0b1eb32bf7b02b5e1fd40edd01abb83994444de7..e29ada173abe363352db32fdce3d9f859a55bfff 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetUsersAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetUsersAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetVoiceAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetVoiceAction.java index 6e8cbe4941bc973d30568267d0333cea0d2494bf..c35f9dbb565b916d489148f6d47d574c968a1113 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetVoiceAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotLogAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpImportBotLogAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotLogAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpImportBotLogAction.java index 2de192312807f618aa88b9147b9a9e89ddd7a8de..890a120e3847753bb3f5d342e75582bb7703885e 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotLogAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpImportBotLogAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ScriptConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpImportBotScriptAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpImportBotScriptAction.java index c984d17e2436d7149cbf1d4baf108c85af6fa5aa..1c1efd6390481be1291094f1cf928713f976ee7f 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpImportBotScriptAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPageInstancesAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPageInstancesAction.java index 0431d849bd37355817bf8f6a6a03c9994f5db279..1cdbe1ba8c0d0e2c8adc8811f57ee86854ffc8b0 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPageInstancesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageIssuesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPageIssuesAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageIssuesAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPageIssuesAction.java index 74aef5d5a0035f65043618cc78f922f1f71d7c35..3af4248a8de15f9c6d1ae33f6bea9579965a1eee 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageIssuesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPageIssuesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPagePostsAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPagePostsAction.java index 2d5fdea8ad00f43bd4d6a19e8b1980afa53d00f6..cffe81b03f37193e3ff912eaa513cde88fcf96cf 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpPagePostsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpRefreshAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpRefreshAction.java index db5535421227d2c23a13a850106d620e6a845a3f..ac80bcc174553a3c140aefcf74e05e8ea8ced10c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpRefreshAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ - package org.botlibre.sdk.activityy.actions; + package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java similarity index 89% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java index 22af1fed73d6fef34c004eb62b44ee19fbd64fd8..c19fac43f39271c9d2bff736e6f170c20cc34f26 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; @@ -39,7 +39,10 @@ public abstract class HttpResultAction{ } /** - * 启动activity + * 启动ability + * + * @param ability ability + * @param name name */ public void startOpenAbility(Ability ability, String name) { Intent intent = new Intent(); @@ -53,7 +56,11 @@ public abstract class HttpResultAction{ } /** - * 启动activity + * 启动ability + * + * @param ability ability + * @param name name + * @param requestCode requestCode */ public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { Intent intent = new Intent(); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarBackgroundAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveAvatarBackgroundAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarBackgroundAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveAvatarBackgroundAction.java index 587c7257adf18e8ff6152b619796f1b5d5758fe6..5dbe144d9c587df14629658b65d70234761c5100 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarBackgroundAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveAvatarBackgroundAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarMedia; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveAvatarMediaAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveAvatarMediaAction.java index 18ee6f3a64b78423e963651d94399f2fc612f5d6..9d2f34f17d18d21cbe719b8446ae5b3294d75591 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveAvatarMediaAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarMedia; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveBotAvatarAction.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveBotAvatarAction.java index 7031146ac6d3001f5e4daa85e1c1986f65c0f267..6b9a1ffcb3ddfc224a34908caa057120eab03829 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveBotAvatarAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotScriptSourceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveBotScriptSourceAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotScriptSourceAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveBotScriptSourceAction.java index 08122ddf48e99870f10fd153798c5951a92de145..757f22710477b641a2347e95aee2339c3e513aa3 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotScriptSourceAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveBotScriptSourceAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveChannelBotModeAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveChannelBotModeAction.java index c8b6665c06a055ea9b1bd3a3c68cfd635fd63fcc..d68cb564a3f48ab9190720e96737e781bc10bde1 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveChannelBotModeAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveForumBotModeAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveForumBotModeAction.java index a03999fb83df6d6e0ec3247eeb18647c37ffffe0..e543c5335d36dfd3c6f41966c49f7607da4573d6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveForumBotModeAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveLearningAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveLearningAction.java index 1e8b761a241003d8c0f132817940ac94fe6913ef..02dbde72f791c2e0cbb16a0a3d7af20f451f890e 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveLearningAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveResponseAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveResponseAction.java index e075572af1516334f9c6aac798a261e712b7361d..4cd099a42926ddb86cd7e7776021eefa071e021d 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveResponseAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveScriptSourceAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveScriptSourceAction.java index 9c636ff8ab32cb8be007c0e09b2319c60bbb7fbc..1bdb6bfba89c4cebbbbb72a2200c5cc5259c69e2 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveScriptSourceAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveVoiceAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveVoiceAction.java index 1a1228828e020c531e56dfdddf61517feb88193a..e0029f3152d3363f756075c69a6a8686ad69d1eb 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSaveVoiceAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSpeechAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSpeechAction.java index eeed3b90239cadccad6791df57c85f8a2f706458..4713af14569d81a40780a40e8d7d5a044a2311c9 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSpeechAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarAction.java index 3cf693ce0e206042caef81d3a9caf9cf2e92f485..fa4dd010d160e8993c0d95eecc4f03c11c0eed43 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarIssueAction.java index 8d06013cea0c233e4b17f01bb3fb03260a3b6de7..37f42a6e21e6f75669e4f29b71a33616a16ac035 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarPostAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarPostAction.java index c8156298a108b82394309f8727bb2d6d445cb5b6..362254f33d49f9cb754f79ff070217b410625268 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpStarPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeAction.java index fd20173aafdf9c5f44e249b6f933a32fae571d50..0e8d6becef2d1f80820a308c5b70fe21ad60cb6e 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeForumAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeForumAction.java index 0031ff92da6c9fbb2fde53ec00b864349c57142a..5596e5e9b8cbd9dae95b99ec593be4044f774e39 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeForumAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeIssueAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeIssueAction.java index 78dd4d46c6e5158d26570ee9bf76e3096f906b2c..39c23eb175bc36235dd9b8a93eb273f343748093 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpSubscribeIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownAction.java index dc358e874865654b88dd5c2c8edaf594cb7dc68e..a86ba055c262814625aba8e215a36a587ec2712b 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownIssueAction.java index ee2348f437b3b5608dbf8f529715d1e34dbbb790..7a7e0f428f8c211ec0cc19bafd991bf90dc1b0c6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownPostAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownPostAction.java index fa19590eace83bb6798d6257e8f09ddb393cfb23..7a59fbba011d88e10e503643608314f64ce86b8b 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsDownPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpAction.java index b030c09091b9bc65b168e203d139a5b621c96ecc..b0126f3043fd292d91f49a385c5cf0eaf44da196 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpIssueAction.java index 0c34c41412887316a1229c8c9190268a3c160ce3..da56faca17c9ec29891f829a935ba9c1d9b93657 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.IssueConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpPostAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpPostAction.java index a843d0794353081e9ad62d22b70c06a53f0825d9..6e37aabe120c4c4cb5ce83ab2aef921b429884eb 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpThumbsUpPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java index 272969d74471a4ceaf9f84ee2d50d2d06850d58b..f0093abe4928264a0e779a964ff7c836f7cbb33c 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java similarity index 98% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java index 364bee86c2792588d97d9e6be34525b4b4d93301..db20c9023af46e0008fb620fd18187d4a867c22d 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeAction.java index 938262e5f1cdd51b81a07b885856a86257a2b382..dad3fbad1d8b2330d35b0cebeb9268c22d862333 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeForumAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeForumAction.java index 7c4c9179fc335c1d23f6a5099660e1c5e1c3fafc..77dc0015f06fafcf47268aa4e2f425b77f7fa89e 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeForumAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeIssueAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeIssueAction.java index 229fa929e0a4c2cd33972f85edb50cf78ba973ec..8123b845b3e61bfa8492912f373d4168b91cbb79 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUnsubscribeIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpBotScriptAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpBotScriptAction.java index 9d456711443e3bfd3b84c96a1eb8d04098a2c05c..ee4c2d3549ac156c03023e1a18663589784c0d13 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpBotScriptAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ScriptSourceConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateAction.java index cafad9bad01c877f74826c37c25ac8307af9a2ad..77ec1d84c42616aa7415302fbea0547a089b99aa 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateForumPostAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateForumPostAction.java index 846ae93004bdb99f9e7051145baca1504d0cee32..b325daba805a9c907a7f79137b1f8a8346b0bec1 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateIssueAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateIssueAction.java index 2374b85e68a40b26560ca137f780c2ec40d12af3..3723641a016e8714ce69ad40b6595ff4ad2af623 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateIssueAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateUserAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateUserAction.java index 2a412260e4c52dc1da04735e66f99bf698569930..0097bbc6e66a2ef6905f9bcc60944694863849f8 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUpdateUserAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUploadGraphicMediaAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUploadGraphicMediaAction.java index b7b7065c55055ee1590601dea625bf7559aa69ad..63419c8d226e769376b37cbbefd0002b6ba38f0c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUploadGraphicMediaAction.java @@ -15,7 +15,7 @@ * limitations under the License. * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUserAdminAction.java similarity index 98% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUserAdminAction.java index 2124ff3c5497c51f6400e661949cadd76313d638..cff08c49b2ecdc816029eb2c01c7092b699cca28 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUserAdminAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserMessageAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUserMessageAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserMessageAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUserMessageAction.java index 76cd86884ffbabae44d1f09483764a44036ee87a..4b23f23180e69ff3a39b179709851310d790f9ae 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserMessageAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUserMessageAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/WarAction.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/WarAction.java index 01215f2ed60eea3d5a4d4c6fccc2078af443ef93..ef0a8257460de4c558d8dd401cf4903b653756dc 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/WarAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.config.ChatResponse; diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java similarity index 96% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java index 0a708de062101d0f440fbab96dd0eb7051bd493d..6b6e5f7a5b4508551fdbe969d3169da9981da5e5 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.adapter; +package org.botlibre.sdk.ability.adapter; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; @@ -30,7 +30,7 @@ import ohos.agp.components.Text; * @since 2021-05-10 */ public class SpinnerAdapter extends BaseItemProvider { - private final Ability mActivity; + private final Ability mAbility; private final LayoutScatter mInflater; private final String[] types; @@ -41,7 +41,7 @@ public class SpinnerAdapter extends BaseItemProvider { * @param types types */ public SpinnerAdapter(Ability ability, String[] types) { - mActivity = ability; + mAbility = ability; this.types = types; mInflater = LayoutScatter.getInstance(ability); } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java similarity index 74% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java index 1ba617525f7f0225dbdb153a853e35ffcc005dd1..a75ead36800635748095bc8f89239222aa9e7517 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.avatar; +package org.botlibre.sdk.ability.avatar; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; @@ -31,14 +31,13 @@ import ohos.data.preferences.Preferences; import java.util.ArrayList; /** - * Activity used for selecting an offline avatar. + * used for selecting an offline avatar. */ public class AvatarSelection extends Ability { @Override public void onStart(Intent intent) { super.onStart(intent); -// setContentView(R.layout.activity_list_view); super.setUIContent(ResourceTable.Layout_ability_list_view); final int [] imges = {}; final String [] names = {}; @@ -48,16 +47,7 @@ public class AvatarSelection extends Ability { for (int i = 0; i < names.length; i++) { items.add(new OfflineTemplateConfig(imges[i],names[i],null,null)); } -// CustomListViewAdapter adapter = new CustomListViewAdapter(this, R.layout.list_item_imager, items); -// listView.setAdapter(adapter); -// listView.setOnItemClickListener(new OnItemClickListener(){ -// @Override -// public void onItemClick(AdapterView parent, View view, int position, long id) { -// OfflineTemplateConfig template = (OfflineTemplateConfig) (listView.getItemAtPosition(position)); -// saveSelectedAvatar(template.getTitle()); -// MainActivity.readZipAvatars(AvatarSelection.this, MainActivity.nameOfAvatar); -// finish(); -// }}); + } public static void saveSelectedAvatar(String nameOfAvatar) { diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java index c15fc3a71ee6f86d77cbb6fcd913ea40914d24b5..b14752da2ad09c11c8ac78699949724ab1af4531 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java @@ -13,12 +13,12 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.LanguageListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.LanguageListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SearchDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SearchDialogBuilder.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java index a1f99136eee7867944196c488934bdfef0482374..34c67053c103c3e2a87c24dca243287ed1c7ee15 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SearchDialogBuilder.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java @@ -13,11 +13,11 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.SelectListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java similarity index 96% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java index 929116aa9dc948e3e73c7225d35bcad2c4b79efe..d8caef1fa97f65a4d41c50e0c281907e74135f3d 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java @@ -13,12 +13,12 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.SelectListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java similarity index 93% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java index 776ecddd89448fdd01e97b8cd024a4ce6736c227..3523cf20581e7e5363540572e970d9c6d79fe278 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.listener; +package org.botlibre.sdk.ability.listener; /** * Listener interface for a LiveChatConnection. @@ -25,6 +25,8 @@ package org.botlibre.sdk.activityy.listener; public interface LanguageListener { /** * A user message was received from the channel. + * + * @param select select */ void selectLanguageItem(String select); } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java similarity index 93% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java index 237a4130230d4315b6104d3b10fd8da115e72fed..60077f9e5814e5ac0274ab168b026d2a972c7e6a 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.listener; +package org.botlibre.sdk.ability.listener; /** * Listener interface for a LiveChatConnection. @@ -25,6 +25,8 @@ package org.botlibre.sdk.activityy.listener; public interface SelectListener { /** * A user message was received from the channel. + * + * @param select select */ void selectItem(String select); } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/war/ChatWarConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java similarity index 95% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/war/ChatWarConfig.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java index f943da9e2cbeee5b38c510ba220f2c56237be175..7d0c9ee38abd0e72dae4d758dbfb3b6108be35eb 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/war/ChatWarConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java @@ -1,4 +1,4 @@ -package org.botlibre.sdk.activityy.war; +package org.botlibre.sdk.ability.war; import org.botlibre.sdk.config.Config; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/war/HttpChatWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java similarity index 80% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/war/HttpChatWarAction.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java index ac0405d955ae27c6ef32f219ba714625c676f441..1c0419f9a72e8569c22923923a87c3b55b740012 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/war/HttpChatWarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java @@ -1,7 +1,7 @@ -package org.botlibre.sdk.activityy.war; +package org.botlibre.sdk.ability.war; import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.actions.HttpUIAction; +import org.botlibre.sdk.ability.actions.HttpUIAction; import org.botlibre.sdk.config.InstanceConfig; import ohos.aafwk.ability.Ability; @@ -9,8 +9,8 @@ public class HttpChatWarAction extends HttpUIAction { ChatWarConfig config; InstanceConfig instance; - public HttpChatWarAction(Ability activity, ChatWarConfig config) { - super(activity); + public HttpChatWarAction(Ability ability, ChatWarConfig config) { + super(ability); this.config = config; } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/StartWarAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java similarity index 96% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/StartWarAbility.java rename to BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index 0e3bb78a893e66f9befea773c0a0eb53c5276bda..b1c3f9e0f139105b7da0ae2041ae5c33c51607d3 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/StartWarAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -16,14 +16,14 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.war; +package org.botlibre.sdk.ability.war; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.LibreAbility; -import org.botlibre.sdk.activityy.actions.HttpFetchWarAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; +import org.botlibre.sdk.ability.LibreAbility; +import org.botlibre.sdk.ability.actions.HttpFetchWarAction; +import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java deleted file mode 100644 index c83873af7985cd5cf6ac35ddc8fb4e46e5fb47e3..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; -import ohos.agp.window.dialog.CommonDialog; - -public class HttpAddAvatarMediaAction extends HttpUIResultAction { - - AvatarMedia config; - String file; - - public HttpAddAvatarMediaAction(Ability ability, String file, AvatarMedia config) { - super(ability); - this.config = config; - this.file = file; - } - -// @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createAvatarMedia(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - -// @Override - protected void onPreExecute() { - this.dialog = new CommonDialog(this.ability); - //this.dialog.setCancelable(false); - this.dialog.setContentText("Uploading..."); - this.dialog.show(); - } - -// @Override - protected void onPostExecute(String xml) { -// super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - HttpGetAvatarMediaAction action = new HttpGetAvatarMediaAction(this.ability, (AvatarConfig)MainAbility.instance.credentials(), true); -// action.execute(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java deleted file mode 100644 index d1896c134c2a1f85081b043a0f55f36604a89ba6..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpChangeUserIconAction extends HttpUIAction { - - UserConfig config; - String file; - - public HttpChangeUserIconAction(Ability ability, String file, UserConfig config) { - super(ability); - this.config = config; - this.file = file; - } - -// @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.updateIcon(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - -// @Override - public void onPostExecute(String xml) { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.user = this.config; - MainAbility.viewUser = this.config; -// ((ViewUserAbility) this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java deleted file mode 100644 index 70c8ca32b44967c1f65154ccd2a1e47b749b2611..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; -public class HttpDeleteIssueAction extends HttpUIAction { - - IssueConfig config; - - public HttpDeleteIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issues.remove(this.config); - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java deleted file mode 100644 index 0ad3a44c5ad61463e081e9ae487eee39ab225787..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** - * - * Copyright 2017 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.activityy.ListTemplateView; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.micro.MicroConnection; -import org.botlibre.sdk.util.LogUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.components.Text; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public class HttpFetchActionOffline extends HttpUIAction { - WebMediumConfig config; - MicroConnection microConnection = new MicroConnection(); - boolean launch; - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - } - - @Override - protected void onPreExecute() { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - Text title = (Text)layout.findComponentById(ResourceTable.Id_title); - title.setText("Initializing Bot"); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } - - @Override - protected String doInBackground(Void... params) { - - try { - //switch connections. - MainAbility.setOnline(false); - microConnection = (MicroConnection) MainAbility.connection; - this.config = microConnection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - LogUtils.e("HttpFetchAction", exception.toString()); - return ""; - } - - if(this.ability instanceof ListTemplateView){ - this.ability.terminateAbility(); - } - if (this.exception != null) { - return ""; - } - try { - MainAbility.instance = this.config; - Class childAbility = MainAbility.getActivity(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof InstanceConfig) { - childAbility = ChatAbility.class; - HttpAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); - action.execute(); - } - } - startOpenAbility(this.ability,childAbility.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return ""; - } - return ""; - } - - @SuppressWarnings("rawtypes") - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); -// if(this.ability instanceof ListTemplateView){ -// this.ability.terminateAbility(); -// } -// if (this.exception != null) { -// return; -// } -// try { -// MainAbility.instance = this.config; -// Class childAbility = MainAbility.getActivity(this.config); -// if (this.launch && !this.config.isExternal) { -// if (this.config instanceof InstanceConfig) { -// childAbility = ChatAbility.class; -// HttpAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); -// action.execute(); -// } -// } -// startOpenAbility(this.ability,childAbility.getName()); -// } catch (Exception error) { -// this.exception = error; -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// return; -// } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java deleted file mode 100644 index 213bebc6abf9f7f8fceeb894f4c730a055e388a0..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchChatAvatarAction extends HttpUIAction { - AvatarConfig config; - - public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((ChatAbility)this.ability).resetAvatar(this.config); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java deleted file mode 100644 index 7fe3d6bdc3ed27fc56041b2525a5e99bb339a420..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchUserAction extends HttpUIAction { - UserConfig config; - boolean launch; - - public HttpFetchUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.viewUser = this.config; -// startOpenAbility(this.ability, ViewUserAbility.class.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java deleted file mode 100644 index 5a4108c949a93a6fb987985b978d061f95e7cc16..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchWarAction extends HttpFetchAction { - - public HttpFetchWarAction(Ability ability, WebMediumConfig config) { - super(ability, config); - } - -// @Override - public void onPostExecute(String xml) { -// super.superOnPostExecute(xml); -// StartWarAbility.bot1 = (InstanceConfig)this.config; -// ((StartWarAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java deleted file mode 100644 index 8782d8d0e169254356caab4fb9a9c54c17b0a599..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; -public class HttpFlagForumPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpFlagForumPostAction(Ability ability, ForumPostConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.isFlagged = true; -// this.ability.findComponentById(ResourceTable.flaggedLabel).setVisibility(VISIBLE); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java deleted file mode 100644 index ba7ee1b6a02bac03af0bc1b692089738deffc7fe..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFlagIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpFlagIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.isFlagged = true; -// this.ability.findComponentById(ResourceTable.flaggedLabel).setVisibility(VISIBLE); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java deleted file mode 100644 index fb9f238d0892a499b5ce12aa9ce7bd9b2d38b5c4..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpGetAdminsAction extends HttpUIAction { - - WebMediumConfig config; - List users; - - public HttpGetAdminsAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.users = MainAbility.connection.getAdmins(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((WebMediumUsersAbility)this.ability).admins = this.users; -// ((WebMediumUsersAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java deleted file mode 100644 index 6702275bc375bb36b7890dcb9615be7dbf9ccd8a..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2016 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.ScriptConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetBotScriptsAction extends HttpUIAction { - - InstanceConfig config; - List scripts; - - public HttpGetBotScriptsAction(Ability ability, InstanceConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.scripts = MainAbility.connection.getBotScripts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((BotScriptsAbility)this.ability).setScriptList(this.scripts); -// ((BotScriptsAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java deleted file mode 100644 index 95951bbd27859e768e4d9e9dd3198f68146c9f2e..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java +++ /dev/null @@ -1,287 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.lang.ref.SoftReference; -import java.net.URL; -import java.util.Hashtable; -import java.util.Map; - -import org.botlibre.sdk.MainAbility; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.Component; -import ohos.agp.components.Image; -import ohos.app.Context; -import ohos.media.image.PixelMap; - -public class HttpGetImageAction extends HttpAction { - public static int MAX_HEIGHT = 1200; - public static int MAX_WIDTH = 600; - public static int MAX_FILES = 100; - - public static volatile boolean downloading; - - public static File cacheDir; - public static Map> imageCache = new Hashtable>(); - - String image; - PixelMap bmp; - Image view; - - - - public static void setImage(int imageId, Component view){ - if(view instanceof Image){ -// ((Image) view).setImageResource(imageId); - } - } - - public static void clearFileCache(Context context) { - try { - File[] files = getFileCacheDir(context).listFiles(); - if (files == null) { - return; - } - for (File file : files) { - if (file.isDirectory()) { - File[] nested = file.listFiles(); - for (File nestedFile : nested) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } else { - file.delete(); - } - } - } catch (Exception failed) { -// Log.wtf(failed.toString(), failed); - } - } - - public static File getFileCacheDir(Context context) { - if (cacheDir == null) { - try { - - cacheDir = context.getCacheDir(); - if (!cacheDir.exists()) { - cacheDir.mkdirs(); - } - } catch (Exception failed) { - failed.printStackTrace(); - return null; - } - } - return cacheDir; - } - - public static File getFile(String filename, Context context) { - File dir = getFileCacheDir(context); - if (dir == null) { - return null; - } - - File file = new File(dir.getAbsolutePath() + "/" + filename); - dir = new File(file.getParent()); - if (!dir.exists()) { - dir.mkdir(); - } else { - File[] files = dir.listFiles(); - if (files.length > MAX_FILES) { - for (File nestedFile : files) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } - } - return file; - } - - public static File getFile(String dirName, String filename, Context context) { - File dir = getFileCacheDir(context); - if (dir == null) { - return null; - } - - File file = new File(dir.getAbsolutePath() + "/" + dirName + "/" + filename); - dir = new File(file.getParent()); - if (!dir.exists()) { - dir.mkdir(); - } else { - File[] files = dir.listFiles(); - if (files.length > MAX_FILES) { - for (File nestedFile : files) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } - } - return file; - } - - public static void fetchImage(Ability Ability, String image, Image view) { - if (image == null) { - return; - } - SoftReference ref = imageCache.get(image); - if (ref != null) { - PixelMap bmp = ref.get(); - if (bmp != null) { - if (view instanceof Image) { - view.setPixelMap(bmp); - } - return; - } - } - HttpGetImageAction action = new HttpGetImageAction(Ability, image, view); - try { - action.execute().get(); - action.postExecute(); - if (action.getException() != null) { - throw action.getException(); - } - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - return; - } - } - - public HttpGetImageAction(Ability Ability) { - super(Ability); - } - - public HttpGetImageAction(Ability Ability, String image, Image view) { - super(Ability); - this.image = image; - this.view = view; - } - - @Override - protected String doInBackground(Void... params) { - try { - URL url = MainAbility.connection.fetchImage(this.image); - - /*BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - long start = System.currentTimeMillis(); - InputStream stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream, null, options); - stream.close(); - System.out.println("decodeStream1:" + (System.currentTimeMillis() - start)); - - int height = options.outHeight; - int width = options.outWidth; - options.inPreferredConfig = Bitmap.Config.RGB_565; - int inSampleSize = 1; - - if (height > MAX_HEIGHT) { - inSampleSize = Math.round((float)height / (float)MAX_HEIGHT); - } - - int expectedWidth = width / inSampleSize; - - if (expectedWidth > MAX_WIDTH) { - inSampleSize = Math.round((float)width / (float)MAX_WIDTH); - } - - options.inSampleSize = inSampleSize; - options.inJustDecodeBounds = false; - - start = System.currentTimeMillis(); - stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream, null, options).recycle(); - stream.close(); - System.out.println("decodeStream2:" + (System.currentTimeMillis() - start)); - - start = System.currentTimeMillis(); - stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream).recycle(); - stream.close(); - System.out.println("decodeStream-full:" + (System.currentTimeMillis() - start));*/ - - File file = getFile(this.image, this.ability); - if (!file.exists()) { - downloading = true; - file.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(file); - InputStream stream = url.openConnection().getInputStream(); - byte[] bytes= new byte[1024]; - int count = 0; - while (count != -1) { - count = stream.read(bytes, 0, 1024); - if (count == -1) { - break; - } - outputStream.write(bytes, 0, count); - } - stream.close(); - outputStream.close(); - downloading = false; - } - -// BitmapFactory.Options options = new BitmapFactory.Options(); -// options.inJustDecodeBounds = true; -// InputStream stream = new FileInputStream(file); -// BitmapFactory.decodeStream(stream, null, options); -// stream.close(); -// -// int height = options.outHeight; -// int width = options.outWidth; -// options.inPreferredConfig = Bitmap.Config.RGB_565; -// int inSampleSize = 1; -// if (height > MAX_HEIGHT) { -// inSampleSize = Math.round((float)height / (float)MAX_HEIGHT); -// } -// int expectedWidth = width / inSampleSize; -// if (expectedWidth > MAX_WIDTH) { -// inSampleSize = Math.round((float)width / (float)MAX_WIDTH); -// } -// options.inSampleSize = inSampleSize; -// options.inJustDecodeBounds = false; -// -// stream = new FileInputStream(file); -// this.bmp = BitmapFactory.decodeStream(stream, null, options); -// stream.close(); -// -// imageCache.put(this.image, new SoftReference(this.bmp)); - return ""; - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - } - return null; - } - - protected void postExecute() { - if (view instanceof Image) { -// ((Image)view).setImageBitmap(bmp); - } -// else if (view instanceof Button) { -//// ((Button)view).setBackgroundDrawable(new BitmapDrawable(view.getResources(), bmp)); -// } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java deleted file mode 100644 index 70a0f3dce20f49072019b2fb0a7f00ff06639e3c..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; - -import java.util.List; - -public class HttpGetIssuesAction extends HttpUIAction { - BrowseConfig config; - List issues; - boolean finish = false; - - public HttpGetIssuesAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - public HttpGetIssuesAction(Ability Ability, BrowseConfig config, boolean finish) { - super(Ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.issues = MainAbility.connection.getIssues(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issues = this.issues; - - if (this.finish) { - this.ability.terminateAbility(); - } - MainAbility.browseIssues = this.config; - Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(this.ability.getBundleName()) -// .withAbilityName(BrowseIssueAbility.class.getName()) -// .build(); -// intent.setOperation(operation); - this.ability.startAbility(intent); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java deleted file mode 100644 index 2c9566f93726186856ca3f2f79218b05902dc1a6..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetLiveChatUsersAction extends HttpAction { - String csv; - List users; - - public HttpGetLiveChatUsersAction(Ability Ability, String csv) { - super(Ability); - this.csv = csv; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.users = MainAbility.connection.getUsers(this.csv); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((LiveChatAbility)this.ability).setUsers(this.users); - - } catch (Exception error) { - this.exception = error; - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java deleted file mode 100644 index 560b4892c062ea316c871140714f2882df993625..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ResponseConfig; -import org.botlibre.sdk.config.ResponseSearchConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpGetResponsesAction extends HttpUIAction { - - ResponseSearchConfig config; - List responses; - - public HttpGetResponsesAction(Ability Ability, ResponseSearchConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.responses = MainAbility.connection.getResponses(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// try { -// ((TrainingAbility)this.ability).setResponses(this.responses); -// ((TrainingAbility)this.ability).resetView(); -// } catch (Exception error) { -// this.exception = error; -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// return; -// } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java deleted file mode 100644 index a9dff7cd95d68685028b6350f19153281d3c6977..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2016 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetScriptSourceAction extends HttpUIAction { - ScriptConfig config; - ScriptSourceConfig script; - - public HttpGetScriptSourceAction(Ability Ability, ScriptConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.script = MainAbility.connection.getScriptSource(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.script = this.script; - -// ((ScriptEditorAbility)this.ability).resetView(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java deleted file mode 100644 index fa59737fed7c834f60f88e4b4b0b9925aad5ca5a..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.net.URL; - -import org.botlibre.sdk.MainAbility; - -import ohos.aafwk.ability.Ability; -import ohos.utils.net.Uri; - -public class HttpGetVideoAction extends HttpGetImageAction { - - String video; - - public static Uri fetchVideo(Ability Ability, String video) { -// if(!MainAbility.online){ -// File file = getFile(GetAvatarAction.nameOfFile,video, Ability); -// return Uri.getUriFromFile(file); -// } - - if (video == null) { - return null; - } - - if (downloading) { - return null; - } - File file = getFile(video, Ability); - if (file.exists()) { - if (downloading) { - return null; - } - return Uri.getUriFromFile(file); - } - HttpGetVideoAction action = new HttpGetVideoAction(Ability, video); - try { - action.execute().get(); - if (action.getException() != null) { - throw action.getException(); - } - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - } - return Uri.getUriFromFile(file); - } - - public HttpGetVideoAction(Ability Ability, String video) { - super(Ability); - this.video = video; - } - - @Override - protected String doInBackground(Void... params) { - try { - URL url = MainAbility.connection.fetchImage(this.video); - - File file = getFile(this.video, this.ability); - if (!file.exists()) { - downloading = true; - file.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(file); - InputStream stream = url.openConnection().getInputStream(); - byte[] bytes= new byte[1024]; - int count = 0; - while (count != -1) { - count = stream.read(bytes, 0, 1024); - if (count == -1) { - break; - } - outputStream.write(bytes, 0, count); - } - stream.close(); - outputStream.close(); - downloading = false; - } - return ""; - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - downloading = false; - } - return null; - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java deleted file mode 100644 index 2d5fdea8ad00f43bd4d6a19e8b1980afa53d00f6..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpPagePostsAction extends HttpUIAction { - BrowseConfig config; - List posts; - - public HttpPagePostsAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.posts = MainAbility.connection.getPosts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.posts = this.posts; - MainAbility.browsePosts = this.config; -// ((BrowsePostAbility)this.ability).instances = this.posts; -// ((BrowsePostAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java deleted file mode 100644 index c8b6665c06a055ea9b1bd3a3c68cfd635fd63fcc..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BotModeConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveChannelBotModeAction extends HttpUIAction { - - BotModeConfig config; - - public HttpSaveChannelBotModeAction(Ability Ability, BotModeConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveChannelBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.botMode = this.config; - - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java deleted file mode 100644 index 1e8b761a241003d8c0f132817940ac94fe6913ef..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.LearningConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveLearningAction extends HttpUIAction { - - LearningConfig config; - - public HttpSaveLearningAction(Ability Ability, LearningConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveLearning(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.learning = this.config; - - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java deleted file mode 100644 index e075572af1516334f9c6aac798a261e712b7361d..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ResponseConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpSaveResponseAction extends HttpUIAction { - - public ResponseConfig config; - public static ResponseConfig response; - public static ResponseConfig oldResponse; - - public HttpSaveResponseAction(Ability Ability, ResponseConfig config) { - super(Ability); - this.config = config; - oldResponse = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.saveResponse(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// if (this.ability instanceof TrainingAbility) { -// ((TrainingAbility)this.ability).resetView(this.config); -// } else { -// response = this.config; -// this.ability.terminateAbility(); -// } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java deleted file mode 100644 index 9c636ff8ab32cb8be007c0e09b2319c60bbb7fbc..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * - * Copyright 2016 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveScriptSourceAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpSaveScriptSourceAction(Ability Ability, ScriptSourceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveScriptSource(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java deleted file mode 100644 index 8d06013cea0c233e4b17f01bb3fb03260a3b6de7..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpStarIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpStarIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.star(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.stars = config.stars; -// ((IssueAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java deleted file mode 100644 index 78dd4d46c6e5158d26570ee9bf76e3096f906b2c..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSubscribeIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpSubscribeIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.subscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java deleted file mode 100644 index b030c09091b9bc65b168e203d139a5b621c96ecc..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsUpAction extends HttpUIAction { - WebMediumConfig config; - - public HttpThumbsUpAction(Ability Ability, WebMediumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsUp(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instance.thumbsUp++; -// ((WebMediumAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java deleted file mode 100644 index 0c34c41412887316a1229c8c9190268a3c160ce3..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsUpIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpThumbsUpIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsUp(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.thumbsUp++; -// ((IssueAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java deleted file mode 100644 index a843d0794353081e9ad62d22b70c06a53f0825d9..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpThumbsUpPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpThumbsUpPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsUp(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.thumbsUp++; -// ((ForumPostAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java deleted file mode 100644 index 938262e5f1cdd51b81a07b885856a86257a2b382..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUnsubscribeAction extends HttpUIAction { - ForumPostConfig config; - - public HttpUnsubscribeAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.unsubscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java deleted file mode 100644 index 9d456711443e3bfd3b84c96a1eb8d04098a2c05c..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * - * Copyright 2016 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpBotScriptAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpUpBotScriptAction(Ability Ability, ScriptSourceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.upBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - -// ((BotScriptsAbility)this.ability).resetView(); - - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java deleted file mode 100644 index 2374b85e68a40b26560ca137f780c2ec40d12af3..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateIssueAction extends HttpUIAction { - - IssueConfig config; - - public HttpUpdateIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.issue = this.config; - - this.ability.terminateAbility(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index 275ea4125ece92822879c086888206de39df99bb..b2c8052f5f46643001184499e517b466d1496cd2 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java @@ -197,9 +197,15 @@ public class AvatarConfig extends WebMediumConfig { public void parseXML(Element element) { super.parseXML(element); } - + /** * Find any media that match the emotion, action, and pose, or the best matches. + * + * @param emotion emotion + * @param action action + * @param pose pose + * @param pose2 pose2 + * @return */ public List getMedia(String emotion, String action, String pose, String pose2) { if (emotion == null || emotion.isEmpty()) { @@ -461,9 +467,13 @@ public class AvatarConfig extends WebMediumConfig { } return matches; } - + /** * Find an audio media that matches the action or pose. + * + * @param action action + * @param pose pose + * @return getAudio */ public List getAudio(String action, String pose) { if (action == null) { diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java index a1b9b74dea95e217b4796f98f0bd08244835032d..5c8e4d83fc0b8525af07dec03f739936e6d02f8f 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java @@ -1,7 +1,7 @@ package org.botlibre.sdk.micro; import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.actions.HttpUIAction; +import org.botlibre.sdk.ability.actions.HttpUIAction; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.ScriptConfig; import org.botlibre.sdk.config.ScriptSourceConfig; @@ -171,6 +171,9 @@ public class BootstrapAsync extends HttpUIAction { /** * Load, compile, and add the state machine from the Self source code. + * + * @param bot bot + * @param text text */ public void loadSelf(Bot bot, String text) { diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java index 99f6becf8c7da40392c4bfa2c329e330a36842d3..d8c26ab63134370d42b0282926bcb658e56861f6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java @@ -18,18 +18,12 @@ package org.botlibre.sdk.micro; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.botlibre.sdk.SDKConnection; -import org.botlibre.sdk.SDKException; import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.VoiceConfig; import org.botlibre.sdk.config.WebMediumConfig; @@ -43,7 +37,6 @@ import org.botlibre.knowledge.micro.MicroMemory; import org.botlibre.self.SelfCompiler; import org.botlibre.sense.http.Wiktionary; import org.botlibre.sense.text.TextEntry; -import org.botlibre.sense.text.TextInput; import org.botlibre.sense.text.TextListener; import org.botlibre.sense.text.TextOutput; import org.botlibre.thought.consciousness.Consciousness; @@ -72,6 +65,8 @@ public class MicroConnection extends SDKConnection implements TextListener { /** * Create a micro/offline SDK connection. * Use the credentials to enable online support. + * + * @param credentials credentials */ public MicroConnection(Credentials credentials) { this.credentials = credentials; @@ -90,70 +85,12 @@ public class MicroConnection extends SDKConnection implements TextListener { return bot; } - /** - * Process the bot chat message and return the bot's response. - * The ChatConfig should contain the conversation id if part of a conversation. - * If a new conversation the conversation id is returned in the response. - */ - public synchronized ChatResponse chat(ChatConfig config) { - if (config.instance == null) { - config.instance = "default"; - } - // this method will return a Bot with the default instance - Bot bot = getBot(this.config.id); - try { - int i = 0; - while (i <= 4) { - if (bot == null) { - wait(1000); - bot = this.activeBots.get(config.instance); - } else if (bot != null) { - break; - } - i++; - } - } catch (Exception e) {} - - if (bot == null) { - this.exception = new SDKException("Bot doesn't exists!"); - throw this.exception; - } - - TextEntry sense = bot.awareness().getSense(TextEntry.class); - // setting the user admin for the BOT. - sense.setUser(reInitialize(bot)); - bot.setFilterProfanity(false); - - sense.setTextListener(this); - this.message = null; - TextInput textInput = new TextInput(config.message); - textInput.setCorrection(config.correction); - textInput.setOffended(config.offensive); - - sense.input(textInput); - ChatResponse response = new ChatResponse(); - - try { - if (this.message == null) { - wait(5000); - } - if (this.message != null) { - response.message = this.message.getMessage(); - response.command = bot.avatar().getCommand(); - try { - avatarConfig.chatReply(response); - } catch (Exception e) { - } - } - } catch (InterruptedException exception) { - this.exception = new SDKException("Timeout waiting for response"); - throw this.exception; - } - return response; - } - /** * Fetch the local object. + * + * @param config config + * @param + * @return Fetch the local object */ public T fetch(T config) { this.config = config; @@ -166,9 +103,12 @@ public class MicroConnection extends SDKConnection implements TextListener { } return config; } - + /** * Return the bot's voice configuration. + * + * @param config config + * @return Return the bot's voice configuration. */ public VoiceConfig getVoice(InstanceConfig config) { VoiceConfig voice = new VoiceConfig(); @@ -176,13 +116,25 @@ public class MicroConnection extends SDKConnection implements TextListener { voice.language = "en"; return voice; } - + + /** + * sendMessage + * + * @param message sendMessage + */ public synchronized void sendMessage(TextOutput message) { this.message = message; notifyAll(); } - - public synchronized Bot loadBot(String name, int id) { + + /** + * loadBot + * + * @param name name + * @param id id + * @return loadBot + */ + public Bot loadBot(String name, int id) { boolean exists = MicroMemory.checkExists(); Bot.CONFIG_FILE = "config.xml"; Bot bot = Bot.createInstance(Bot.CONFIG_FILE, name, true); @@ -213,24 +165,34 @@ public class MicroConnection extends SDKConnection implements TextListener { } return bot; } - - public void loadAIMLScript(Language lang,InputStream source){ - lang.loadAIMLFile(source, config.id, false, false, true,"",10000000); - } - + + /** + * loadResScript + * + * @param bot bot + * @param fileName fileName + */ public void loadResScript(Bot bot, String fileName) { URL url = getClass().getResource(fileName); bot.awareness().getSense(TextEntry.class).loadChatFile(url, "Response List", "", false, true); } - public void loadResScript(Bot bot, File file) { - bot.awareness().getSense(TextEntry.class).loadChatFile(file, "Response List", "", false, true); - } - + /** + * loadSelfScript + * + * @param bot bot + * @param fileName fileName + */ public void loadSelfScript(Bot bot, String fileName) { loadSelfScript(bot, getClass().getResource(fileName)); } + /** + * loadSelfScript + * + * @param bot bot + * @param url url + */ public void loadSelfScript(Bot bot, URL url) { Network network = bot.memory().getShortTermMemory(); Vertex language = network.createVertex(new Primitive(Language.class.getName())); @@ -239,36 +201,4 @@ public class MicroConnection extends SDKConnection implements TextListener { language.addRelationship(Primitive.STATE, stateMachine); SelfCompiler.getCompiler().pin(stateMachine); } - - public void loadSelfScript(Bot bot, File file) { - Network network = bot.memory().getShortTermMemory(); - Vertex language = network.createVertex(new Primitive(Language.class.getName())); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(file, "", false, network); - language.addRelationship(Primitive.STATE, stateMachine); - SelfCompiler.getCompiler().pin(stateMachine); - } - - public void renameMemory(Bot bot, String name) { - bot.memory().getShortTermMemory().createVertex(Primitive.SELF).addRelationship(Primitive.NAME, bot.memory().getShortTermMemory().createVertex(name)); - - } - - public Vertex reInitialize(Bot bot) { - Network memory = bot.memory().newMemory(); - Vertex user = memory.createSpeaker("Admin"); - user.addRelationship(Primitive.ASSOCIATE, Primitive.ADMINISTRATOR); - memory.save(); - return user; - } - - public static void copyStream(InputStream input) throws IOException { -// FileOutputStream output = MainAbility.current.openFileOutput(MicroMemory.storageFileName, -// Ability.MODE_PRIVATE); -// byte[] buffer = new byte[1024]; // Adjust if you want -// int bytesRead; -// while ((bytesRead = input.read(buffer)) != -1) { -// output.write(buffer, 0, bytesRead); -// } - } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java index 66d558f2128ec4a3b619ba4abaaa29680b0d1c29..c364cd21a4ddf239d018cdfbcd6da41d51807e50 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java @@ -1,10 +1,7 @@ package org.botlibre.sdk.provider; -import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.SDKConnection; -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.activityy.actions.HttpGetImageAction; +import org.botlibre.sdk.ability.ChatAbility; import org.botlibre.sdk.config.ChatConfig; import org.botlibre.sdk.config.ChatResponse; import ohos.aafwk.ability.Ability; @@ -53,24 +50,10 @@ public class ChatListProvicer extends BaseItemProvider { if (message instanceof ChatConfig) { ChatConfig config = (ChatConfig) message; messageView.setText(config.message); - if (MainAbility.user != null && MainAbility.user.avatar != null) { - if (MainAbility.online) { - HttpGetImageAction.fetchImage(slice, MainAbility.user.avatar, userView); - } else { - HttpGetImageAction.setImage(MainAbility.offlineSelectedImage, userView); - } - } else { - HttpGetImageAction.fetchImage(slice, SDKConnection.defaultUserImage(), userView); - } } else if (message instanceof ChatResponse) { ChatResponse config = (ChatResponse) message; messageView.setText(Utils.stripTags(config.message)); String avatar = ((ChatAbility) this.slice).getAvatarIcon(config); - if (MainAbility.online) { - HttpGetImageAction.fetchImage(slice, avatar, userView); - } else { - HttpGetImageAction.setImage(MainAbility.offlineSelectedImage, userView); - } } return cpt; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java index e2667554458cf4b39b09db6f45618ae95b08168b..70462fcc327c7c2c6db32a63dd2248dd0cf83e78 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java @@ -18,14 +18,8 @@ package org.botlibre.sdk.util; -import org.botlibre.BotException; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.StringWriter; import java.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; @@ -45,8 +39,10 @@ public class Utils { public static Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); /** - * Replace links with HTML links. * Includes http, www, images, video, audio, email address. + * + * @param text text + * @return Includes http, www, images, video, audio, email address. */ public static String linkHTML(String text) { if (text == null || text.length() == 0) { @@ -102,10 +98,13 @@ public class Utils { } return text; } - + /** * Replace reserved HTML character with their HTML escape codes. + * + * @param html html + * @return Replace reserved HTML character with their HTML escape codes. */ public static String escapeHTML(String html) { return html.replace("&", "&") @@ -118,6 +117,9 @@ public class Utils { /** * Strip the HTML tags from the text. + * + * @param html html + * @return Strip the HTML tags from the text. */ public static String stripTags(String html) { if (html == null) { @@ -165,187 +167,11 @@ public class Utils { } /** - * Format the text that may be HTML, or may be text, or markup, or a mix. + * displayTimestamp + * + * @param date date + * @return displayTimestamp */ - public static String formatHTMLOutput(String text) { - if (text == null) { - return ""; - } - int index = text.indexOf('<'); - int index2 = text.indexOf('>'); - boolean isHTML = (index != -1) && (index2 > index); - boolean isMixed = isHTML && text.contains("[code]"); - if (isHTML && !isMixed) { - return text; - } - if (!isMixed && ((index != -1) || (index2 != -1))) { - text = text.replace("<", "<"); - text = text.replace(">", ">"); - } - TextStream stream = new TextStream(text); - StringWriter writer = new StringWriter(); - boolean bullet = false; - boolean nbullet = false; - while (!stream.atEnd()) { - String line = stream.nextLine(); - if (!isMixed && (line.contains("http://") || line.contains("https://"))) { - line = Utils.linkHTML(line); - } - TextStream lineStream = new TextStream(line); - boolean firstWord = true; - boolean span = false; - boolean cr = true; - while (!lineStream.atEnd()) { - while (!isMixed && firstWord && lineStream.peek() == ' ') { - lineStream.next(); - writer.write(" "); - } - String whitespace = lineStream.nextWhitespace(); - writer.write(whitespace); - if (lineStream.atEnd()) { - break; - } - String word = lineStream.nextWord(); - if (!isMixed && nbullet && firstWord && !word.equals("#")) { - writer.write("\n"); - nbullet = false; - } else if (!isMixed && bullet && firstWord && !word.equals("*")) { - writer.write("\n"); - bullet = false; - } - if (firstWord && word.equals("[")) { - String peek = lineStream.peekWord(); - if ("code".equals(peek)) { - lineStream.nextWord(); - String next = lineStream.nextWord(); - String lang = "javascript"; - int lines = 20; - if ("lang".equals(next)) { - lineStream.skip(); - lang = lineStream.nextWord(); - if ("\"".equals(lang)) { - lang = lineStream.nextWord(); - lineStream.skip(); - } - next = lineStream.nextWord(); - } - if ("lines".equals(next)) { - lineStream.skip(); - String value = lineStream.nextWord(); - if ("\"".equals(value)) { - value = lineStream.nextWord(); - lineStream.skip(); - } - lineStream.skip(); - try { - lines = Integer.valueOf(value); - } catch (NumberFormatException ignore) {} - } - String id = "code" + stream.getPosition(); - writer.write("
"); - String code = lineStream.upToAll("[code]"); - if (code.indexOf('<') != -1) { - code = code.replace("<", "<"); - } - if (code.indexOf('>') != -1) { - code = code.replace(">", ">"); - } - writer.write(code); - while (lineStream.atEnd() && !stream.atEnd()) { - line = stream.nextLine(); - lineStream = new TextStream(line); - while (lineStream.peek() == ':') { - lineStream.next(); - writer.write("    "); - } - code = lineStream.upToAll("[code]"); - if (code.indexOf('<') != -1) { - code = code.replace("<", "<"); - } - if (code.indexOf('>') != -1) { - code = code.replace(">", ">"); - } - writer.write(code); - } - lineStream.skip("[code]".length()); - writer.write("
\n"); - - writer.write("\n"); - } else { - writer.write(word); - } - } else if (!isMixed && firstWord && word.equals("=")) { - int count = 2; - String token = word; - while (!lineStream.atEnd() && lineStream.peek() == '=') { - lineStream.skip(); - count++; - token = token + "="; - } - String header = lineStream.upToAll(token); - if (lineStream.atEnd()) { - writer.write(token); - writer.write(header); - } else { - lineStream.skip(token.length()); - writer.write(""); - writer.write(header); - writer.write(""); - cr = false; - } - } else if (!isMixed && firstWord && word.equals(":")) { - span = true; - int indent = 1; - while (!lineStream.atEnd() && lineStream.peek() == ':') { - lineStream.skip(); - indent++; - } - writer.write(""); - } else if (!isMixed && firstWord && word.equals("*")) { - if (!bullet) { - writer.write("
    "); - bullet = true; - } - writer.write("
  • "); - cr = false; - } else if (!isMixed && firstWord && word.equals("#")) { - if (!nbullet) { - writer.write("
      "); - nbullet = true; - } - writer.write("
    1. "); - cr = false; - } else { - writer.write(word); - } - firstWord = false; - } - if (!isMixed && span) { - writer.write(""); - } - if (!isMixed && cr) { - writer.write("
      \n"); - } - } - if (!isMixed && bullet) { - writer.write("
"); - } - if (!isMixed && nbullet) { - writer.write(""); - } - return writer.toString(); - } - public static String displayTimestamp(Date date) { if (date == null) { return ""; @@ -379,7 +205,13 @@ public class Utils { return writer.toString(); } - + + /** + * displayTime + * + * @param date date + * @return displayTime + */ public static String displayTime(Date date) { if (date == null) { return ""; @@ -401,7 +233,13 @@ public class Utils { return writer.toString(); } - + + /** + * displayDate + * + * @param date date + * @return displayDate + */ public static String displayDate(Date date) { if (date == null) { return ""; @@ -428,9 +266,12 @@ public class Utils { return writer.toString(); } - + /** * Capitalize the first character of the string. + * + * @param text text + * @return Capitalize the first character of the string. */ public static String capitalize(String text) { if (text.length() == 0) { @@ -438,80 +279,4 @@ public class Utils { } return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); } - - public static Random random() { - return random; - } - - public static int random(int max) { - return random().nextInt(max); - } - - public static T random(List list) { - if ((list == null) || list.isEmpty()) { - return null; - } - return list.get(random().nextInt(list.size())); - } - /** - * Get the contents of the stream to a .self file and parse it. - */ - public static String loadTextFile(InputStream stream, String encoding, int maxSize, boolean finish) { - if (encoding.trim().isEmpty()) { - encoding = "UTF-8"; - } - - // FEFF because this is the Unicode char represented by the UTF-8 byte order mark (EF BB BF). - String UTF8_BOM = "\uFEFF"; - - StringWriter writer = new StringWriter(); - InputStreamReader reader = null; - try { - reader = new InputStreamReader(stream, encoding); - int size = 0; - int next = reader.read(); - boolean first = true; - while (next >= 0) { - if (first && next == UTF8_BOM.charAt(0)) { - // skip - } else { - writer.write(next); - } - next = reader.read(); - if (size > maxSize) { - throw new BotException("File size limit exceeded: " + size + " > " + maxSize + " token: " + next); - } - size++; - } - } catch (IOException exception) { - throw new BotException("IO Error: " + exception.getMessage(), exception); - } finally { - if (reader != null && finish) { - try { - reader.close(); - } catch (IOException ignore) {} - } - if (stream != null && finish) { - try { - stream.close(); - } catch (IOException ignore) {} - } - } - return writer.toString(); - } - - public static T random(Collection collection) { - if ((collection == null) || collection.isEmpty()) { - return null; - } - int value = random().nextInt(collection.size()); - int index = 0; - for (T element : collection) { - if (index == value) { - return element; - } - index++; - } - return null; - } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/resources/base/layout/activity_chat.xml b/BotLibre/entry/src/main/resources/base/layout/ability_chat.xml similarity index 99% rename from BotLibre/entry/src/main/resources/base/layout/activity_chat.xml rename to BotLibre/entry/src/main/resources/base/layout/ability_chat.xml index c62ff63acfe676b3fae0889d109695c4f836bcff..a95efef03611e17b5b588986536c37ef20590afe 100644 --- a/BotLibre/entry/src/main/resources/base/layout/activity_chat.xml +++ b/BotLibre/entry/src/main/resources/base/layout/ability_chat.xml @@ -1,7 +1,7 @@ instances = new ConcurrentHashMap(); - private static Queue instancesQueue = new ConcurrentLinkedQueue(); - - public static Bot systemCache; - - public Bot parent; - - private Memory memory; - private Mind mind; - private Mood mood; - private Avatar avatar; - private Awareness awareness; - private boolean filterProfanity = true; - private String name; - private ActiveState state = ActiveState.INIT; - - public enum ActiveState {INIT, ACTIVE, POOLED, SHUTDOWN} - - private Set logListeners = new HashSet(); - private Level debugLevel = DEFAULT_DEBUG_LEVEL; - private Stats stats; - - public static Bot getSystemCache() { - return systemCache; - } - - public static void setSystemCache(Bot systemCache) { - Bot.systemCache = systemCache; - } - - public static Bot createInstance() { - return createInstance(CONFIG_FILE, "", false); - } - - public static Bot createInstance(String configFile, String memory, boolean isSchema) { - Bot Bot = new Bot(); - Bot.parseConfigFile(configFile); - Bot.setState(ActiveState.ACTIVE); - Bot.log(Bot, "Creating instance:", Level.INFO, configFile, memory, isSchema); - Bot.memory().restore(memory, isSchema); - Bot.memory().awake(); - Bot.mind().awake(); - Bot.mood().awake(); - Bot.avatar().awake(); - Bot.awareness().awake(); - return Bot; - } - - public static Bot fastCreateInstance(String configFile, String memory, boolean isSchema) { - Bot bot = new Bot(); - long start = System.currentTimeMillis(); - bot.parseConfigFile(configFile); - long time = System.currentTimeMillis() - start; - if (time > 500) { - System.out.println("Connect parseConfigFile time: " + time); - } - bot.setState(ActiveState.ACTIVE); - bot.log(bot, "Fast creating instance:", Level.INFO, configFile, memory, isSchema); - start = System.currentTimeMillis(); - bot.memory().fastRestore(memory, isSchema); - time = System.currentTimeMillis() - start; - if (time > 500) { - System.out.println("Connect fastRestore time: " + time); - } - start = System.currentTimeMillis(); - bot.memory().awake(); - bot.mind().awake(); - bot.mood().awake(); - bot.avatar().awake(); - bot.awareness().awake(); - time = System.currentTimeMillis() - start; - if (time > 500) { - System.out.println("Connect awake time: " + time); - } - return bot; - } - - /** - * Return the cached instance from the pool if available, otherwise create a new instance. - */ - public static Bot createInstanceFromPool(String instanceName, boolean isSchema) { - Bot instance = instances.remove(instanceName); - if (instance != null) { - instancesQueue.remove(instanceName); - if (instance.getState() != ActiveState.POOLED) { - instance.log(instance, "Invalid instance in pool", Level.INFO); - instance = null; - } else { - instance.setState(ActiveState.ACTIVE); - instance.log(instance, "Creating instance from pool, cache size:", Level.INFO, instanceName, instance.memory().cacheSize()); - } - } - if (instance == null) { - //instance = createInstance(CONFIG_FILE, instanceName); - long start = System.currentTimeMillis(); - instance = fastCreateInstance(CONFIG_FILE, instanceName, isSchema); - long time = System.currentTimeMillis() - start; - instance.log(instance, "Creating new instance, time, cache size:", Level.INFO, instanceName, time, instance.memory().cacheSize()); - } - return instance; - } - - public Bot() { - this.parent = systemCache; - } - - /** - * Raise the statistic event. - */ - public void stat(String stat) { - if (this.stats != null) { - this.stats.stat(stat); - ; - } - } - - public Stats getStats() { - return stats; - } - - public void setStats(Stats stats) { - this.stats = stats; - } - - public ActiveState getState() { - return state; - } - - public void setState(ActiveState state) { - this.state = state; - } - - public Bot getParent() { - return parent; - } - - public void setParent(Bot parent) { - this.parent = parent; - } - - public boolean getFilterProfanity() { - return filterProfanity; - } - - public void setFilterProfanity(boolean filterProfanity) { - this.filterProfanity = filterProfanity; - } - - /** - * Return the debugging level. - */ - public Level getDebugLevel() { - return this.debugLevel; - } - - public boolean isDebug() { - return this.debugLevel.intValue() < Level.OFF.intValue(); - } - - public boolean isDebugFine() { - return this.debugLevel.intValue() <= Level.FINE.intValue(); - } - - public boolean isDebugFiner() { - return this.debugLevel.intValue() <= Level.FINER.intValue(); - } - - public boolean isDebugFinest() { - return this.debugLevel.intValue() <= Level.FINEST.intValue(); - } - - public boolean isDebugWarning() { - return this.debugLevel.intValue() <= Level.WARNING.intValue(); - } - - public boolean isDebugSever() { - return this.debugLevel.intValue() <= Level.SEVERE.intValue(); - } - - /** - * Log the message if the debug level is greater or equal to the level. - */ - public void log(Object source, String message, Level level, Object... arguments) { - try { - if (this.debugLevel.intValue() <= level.intValue()) { - for (LogListener listener : getLogListeners()) { - listener.log(source, message, level, arguments); - } - StringWriter writer = new StringWriter(); - writer.write(level + ": " + getName() - + " - " + Thread.currentThread() - + " -- " + source + ":" + message); - for (Object argument : arguments) { - writer.write(" - " + argument); - } - System.out.println(writer.toString()); - } - } catch (Exception exception) { - System.out.println(exception); - } - } - - /** - * Log the message if the debug level is greater or equal to the level. - * - public void log(Object source, String message, int level) { - log(source, message, int level); - }*/ - - /** - * Log the exception. - */ - public void log(Object source, Throwable error) { - try { - if (isDebug()) { - for (LogListener listener : getLogListeners()) { - listener.log(error); - } - log(source, error.getMessage(), WARNING); - if (!(error instanceof BotException)) { - error.printStackTrace(); - StringWriter writer = new StringWriter(); - PrintWriter printer = new PrintWriter(writer); - error.printStackTrace(printer); - printer.flush(); - String stack = writer.toString(); - log(source, stack.substring(0, Math.max(100, stack.length() - 1)), Level.WARNING); - } - } - } catch (Exception exception) { - System.out.println(exception); - } - } - - /** - * Set the debugging level. - */ - public void setDebugLevel(Level level) { - this.debugLevel = level; - for (LogListener listener : getLogListeners()) { - listener.logLevelChange(level); - } - } - - /** - * Return the awareness. - * The awareness defines the senses. - */ - public Awareness awareness() { - return awareness; - } - - /** - * Set the awareness. - * The awareness defines the senses. - */ - public void setAwareness(Awareness awareness) { - awareness.setBot(this); - this.awareness = awareness; - } - - /** - * Return the mind. - * The mind defines the thoughts. - */ - public Mind mind() { - return mind; - } - - /** - * Return the mood. - * The mood defines emotional states. - */ - public Mood mood() { - return mood; - } - - /** - * Return the Avatar. - * The Avatar expresses the emotional states. - */ - public Avatar avatar() { - return avatar; - } - - /** - * Set the mind. - * The mind defines the thoughts. - */ - public void setMind(Mind mind) { - mind.setBot(this); - this.mind = mind; - } - - /** - * Set the mood. - * The mood defines emotional states. - */ - public void setMood(Mood mood) { - mood.setBot(this); - this.mood = mood; - } - - /** - * Set the Avatar. - * The Avatar expresses the emotional state. - */ - public void setAvatar(Avatar avatar) { - avatar.setBot(this); - this.avatar = avatar; - } - - /** - * Return the memory. - * The memory defines the knowledge networks. - */ - public Memory memory() { - return memory; - } - - /** - * Set the memory. - * The memory defines the knowledge networks. - */ - public void setMemory(Memory memory) { - memory.setBot(this); - this.memory = memory; - } - - /** - * Return a Map of the property elements. - */ - protected Map getProperties(Element element) { - NodeList properties = element.getElementsByTagName("property"); - Map propertyValues = new HashMap(); - for (int index = 0; index < properties.getLength(); index++) { - Element property = (Element) properties.item(index); - propertyValues.put(property.getAttribute("name"), property.getAttribute("value")); - } - return propertyValues; - } - - /** - * Parses the config.xml files using the xerces xml dom parser. - * Loads the module implementors into the Bot system. - */ - @SuppressWarnings("unchecked") - protected void parseConfigFile(String configFile) { - // Read config xml to initialize plugins. - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder parser = factory.newDocumentBuilder(); - - ResourceManager resManager = MyApplication.getAppContext().getResourceManager(); - RawFileEntry rawFile = resManager.getRawFileEntry("resources/rawfile/config.xml"); - Document document = parser.parse(rawFile.openRawFile()); - Element root = document.getDocumentElement(); - - // Parse and initialize memory. - Element memoryElement = (Element) root.getElementsByTagName("memory").item(0); - Element implementationClassElement = (Element) memoryElement.getElementsByTagName("implementation-class").item(0); - Class memoryImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - setMemory(memoryImplementor.newInstance()); - memory().initialize(getProperties(memoryElement)); - - // Parse and initialize mind. - Element mindElement = (Element) root.getElementsByTagName("mind").item(0); - implementationClassElement = (Element) mindElement.getElementsByTagName("implementation-class").item(0); - Class mindImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - setMind(mindImplementor.newInstance()); - mind().initialize(getProperties(mindElement)); - - NodeList thoughtElements = ((Element) mindElement.getElementsByTagName("thoughts").item(0)).getElementsByTagName("thought"); - for (int index = 0; index < thoughtElements.getLength(); index++) { - Element thoughtElement = (Element) thoughtElements.item(index); - implementationClassElement = (Element) thoughtElement.getElementsByTagName("implementation-class").item(0); - Class thoughtImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - Thought thought = thoughtImplementor.newInstance(); - mind().addThought(thought); - thought.initialize(getProperties(thoughtElement)); - } - - // Parse and initialize mood. - Element moodElement = (Element) root.getElementsByTagName("mood").item(0); - if (moodElement != null) { - implementationClassElement = (Element) moodElement.getElementsByTagName("implementation-class").item(0); - Class moodImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - setMood(moodImplementor.newInstance()); - mood().initialize(getProperties(moodElement)); - NodeList emotionElements = ((Element) moodElement.getElementsByTagName("emotions").item(0)).getElementsByTagName("emotion"); - for (int index = 0; index < emotionElements.getLength(); index++) { - Element emotionElement = (Element) emotionElements.item(index); - implementationClassElement = (Element) emotionElement.getElementsByTagName("implementation-class").item(0); - Class emotionImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - Emotion emotion = emotionImplementor.newInstance(); - mood().addEmotion(emotion); - emotion.initialize(getProperties(emotionElement)); - } - } - - // Parse and initialize avatar. - Element avatarElement = (Element) root.getElementsByTagName("avatar").item(0); - implementationClassElement = (Element) avatarElement.getElementsByTagName("implementation-class").item(0); - Class avatarImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - setAvatar(avatarImplementor.newInstance()); - avatar().initialize(getProperties(avatarElement)); - - // Parse and initialize awareness. - Element awarenessElement = (Element) root.getElementsByTagName("awareness").item(0); - implementationClassElement = (Element) awarenessElement.getElementsByTagName("implementation-class").item(0); - Class awarenessImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - setAwareness(awarenessImplementor.newInstance()); - NodeList senseElements = ((Element) awarenessElement.getElementsByTagName("senses").item(0)).getElementsByTagName("sense"); - for (int index = 0; index < senseElements.getLength(); index++) { - Element senseElement = (Element) senseElements.item(index); - implementationClassElement = (Element) senseElement.getElementsByTagName("implementation-class").item(0); - Class senseImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - Sense sense = senseImplementor.newInstance(); - awareness().addSense(sense); - sense.initialize(getProperties(senseElement)); - } - NodeList toolElements = ((Element) awarenessElement.getElementsByTagName("tools").item(0)).getElementsByTagName("tool"); - for (int index = 0; index < toolElements.getLength(); index++) { - Element toolElement = (Element) toolElements.item(index); - implementationClassElement = (Element) toolElement.getElementsByTagName("implementation-class").item(0); - Class toolImplementor = (Class) Class.forName(implementationClassElement.getFirstChild().getNodeValue()); - Tool tool = toolImplementor.newInstance(); - awareness().addTool(tool); - tool.initialize(getProperties(toolElement)); - } - } catch (Exception exception) { - throw new InitializationException(exception); - } - } - - /** - * Shutdown the system gracefully, persist memory and terminate thoughts. - */ - public synchronized void shutdown() { - if (this.state == ActiveState.SHUTDOWN) { - log(this, "Already shutdown", Level.INFO); - return; - } - this.state = ActiveState.SHUTDOWN; - log(this, "Shutting down", Level.INFO); - try { - awareness().shutdown(); - mind().shutdown(); - mood().shutdown(); - avatar().shutdown(); - memory().shutdown(); - } catch (Exception exception) { - log(this, exception); - } - getLogListeners().clear(); - } - - /** - * Shutdown the pooled instance. - */ - public static void forceShutdown(String name) { - Bot instance = instances.remove(name); - if (instance != null) { - instancesQueue.remove(name); - instance.log(instance, "Forced shutdown", Level.WARNING); - instance.shutdown(); - } - Utils.sleep(1000); - } - - public static void clearPool() { - while (instances.size() > 0) { - try { - String oldest = instancesQueue.remove(); - Bot instance = instances.remove(oldest); - if (instance != null) { - instance.shutdown(); - } - } catch (Exception exception) { - new Bot().log(instancesQueue, exception); - } - } - } - - /** - * Return the instance to the pool, or shutdown if too many instances pooled. - */ - public synchronized void pool() { - if (this.state == ActiveState.SHUTDOWN) { - log(this, "Already shutdown", Level.INFO); - return; - } - if (this.state == ActiveState.POOLED) { - log(this, "Already pooled", Level.INFO); - return; - } - String name = memory().getMemoryName(); - log(this, "Pooling instance", Level.INFO, name); - synchronized (memory()) { - memory().getShortTermMemory().clear(); - } - if (Utils.checkLowMemory()) { - log(this, "Low memory - clearing server cache", Level.WARNING); - memory().freeMemory(); - } - if ((Utils.checkLowMemory(0.2) && (memory().cacheSize() > MIN_CACHE)) || memory().cacheSize() > MAX_CACHE) { - log(this, "Cache too big - clearing server cache", Level.WARNING, memory().cacheSize(), MIN_CACHE, MAX_CACHE); - memory().freeMemory(); - } - if (instances.containsKey(name)) { - shutdown(); - return; - } - while (instances.size() >= POOL_SIZE) { - try { - String oldest = instancesQueue.remove(); - Bot instance = instances.remove(oldest); - if (instance != null) { - instance.shutdown(); - } - } catch (Exception exception) { - log(instancesQueue, exception); - } - } - try { - awareness().pool(); - mind().pool(); - mood().pool(); - avatar().pool(); - memory().pool(); - } catch (Exception exception) { - log(this, exception); - } - // Shutdown if put not successful. - setState(ActiveState.POOLED); - setDebugLevel(Level.INFO); - if (null != instances.putIfAbsent(name, this)) { - shutdown(); - return; - } else { - instancesQueue.add(name); - } - } - - /** - * Return the instance's name. - * This is the real name, but defaults to the database name. - */ - public String getName() { - if (this.name == null) { - return memory().getMemoryName(); - } - return this.name; - } - - /** - * Set the instance's name. - * This is the real name, but defaults to the database name. - */ - public void setName(String name) { - this.name = name; - } - - public String toString() { - return "Bot(" + getName() + ")"; - } - - public String fullToString() { - StringWriter writer = new StringWriter(); - writer.write("Bot(\n"); - - writer.write("\tmemory: "); - writer.write(memory().toString()); - writer.write("\n"); - - writer.write("\tmind: "); - writer.write(mind().toString()); - writer.write("\n"); - - for (Iterator thoughtsIterator = mind().getThoughts().values().iterator(); thoughtsIterator.hasNext(); ) { - writer.write("\t\tthought: "); - writer.write(thoughtsIterator.next().toString()); - writer.write("\n"); - } - - writer.write("\tmood: "); - writer.write(mood().toString()); - writer.write("\n"); - - writer.write("\tavatar: "); - writer.write(avatar().toString()); - writer.write("\n"); - - writer.write("\tawareness: "); - writer.write(awareness().toString()); - writer.write("\n"); - - for (Iterator sensesIterator = awareness().getSenses().values().iterator(); sensesIterator.hasNext(); ) { - writer.write("\t\tsense: "); - writer.write(sensesIterator.next().toString()); - writer.write("\n"); - } - - for (Iterator toolsIterator = awareness().getTools().values().iterator(); toolsIterator.hasNext(); ) { - writer.write("\t\ttool: "); - writer.write(toolsIterator.next().toString()); - writer.write("\n"); - } - - writer.write(")"); - return writer.toString(); - } - - public void addLogListener(LogListener listener) { - getLogListeners().add(listener); - } - - public void removeLogListener(LogListener listener) { - getLogListeners().remove(listener); - } - - public Set getLogListeners() { - return logListeners; - } - - public void setLogListeners(Set logListeners) { - this.logListeners = logListeners; - } - - public static ConcurrentMap getInstances() { - return instances; - } - -} - diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BotLibreForBusinessCredentials.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BotLibreForBusinessCredentials.java deleted file mode 100644 index 1e1d448311846cd9c833cf825c23215b0e9c6c99..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BotLibreForBusinessCredentials.java +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk; - -/** - * Credentials for use with hosted services on the Bot Libre for Business website, - * a commercial bot, live chat, chatroom, and forum hosting service. - * https://www.botlibre.biz - */ -public class BotLibreForBusinessCredentials extends Credentials { - public static String DOMAIN = "www.botlibre.biz"; - //public static String DOMAIN = "192.168.0.11:9080"; - public static String APP = ""; - //public static String APP = "/livechat"; - public static String PATH = "/rest/api"; - - public BotLibreForBusinessCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "https://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/Credentials.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/Credentials.java index 4846f048f602de4b9a59d0382110e6640dd9237a..b9f826e378fab51e6b362995f5805d95902b0fa9 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/Credentials.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/Credentials.java @@ -24,71 +24,90 @@ package org.botlibre.sdk; * You can obtain your application id from your user details page on the hosting website. */ public class Credentials { - public String host = ""; - public String app = ""; - public String url = ""; - /** - * Your application's unique identifier. - * You can obtain your application id from your user details page on the hosting website. - */ - public String applicationId = ""; + public String host = ""; + public String app = ""; + public String url = ""; + /** + * Your application's unique identifier. + * You can obtain your application id from your user details page on the hosting website. + */ + public String applicationId = ""; - public Credentials() { - } + /** + * Credentials + */ + public Credentials() { + } - /** - * Creates a new credentials for the service host url, and the application id. - */ - public Credentials(String url, String applicationId) { - this.url = url; - this.applicationId = applicationId; - } + /** + * getUrl + * + * @return url + */ + public String getUrl() { + return url; + } - public String getUrl() { - return url; - } - - /** - * Sets the hosted service server url, i.e. http://www.paphuslivechat.com - */ - public void setUrl(String url) { - this.url = url; - } + /** + * setUrl + * + * @param url + */ + public void setUrl(String url) { + this.url = url; + } - public String getHost() { - return host; - } + /** + * getHost + * + * @return host + */ + public String getHost() { + return host; + } - /** - * Sets the server host name, i.e. www.paphuslivechat.com - */ - public void setHost(String host) { - this.host = host; - } + /** + * setHost + * + * @param host + */ + public void setHost(String host) { + this.host = host; + } - public String getApp() { - return app; - } + /** + * getApp + * + * @return app + */ + public String getApp() { + return app; + } - /** - * Sets an app url postfix, this is normally not required, i.e. "". - */ - public void setApp(String app) { - this.app = app; - } + /** + * setApp + * + * @param app + */ + public void setApp(String app) { + this.app = app; + } - /** - * Returns your application's unique identifier. - */ - public String getApplicationId() { - return applicationId; - } + /** + * getApplicationId + * + * @return applicationId + */ + public String getApplicationId() { + return applicationId; + } - /** - * Sets your application's unique identifier. - * You can obtain your application id from your user details page on the hosting website. - */ - public void setApplicationId(String applicationId) { - this.applicationId = applicationId; - } + /** + * setApplicationId + * + * @param applicationId + */ + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/FORUMSlibreCredentials.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/FORUMSlibreCredentials.java deleted file mode 100644 index 59a8d17a0721977c6761cfceca527b62df494259..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/FORUMSlibreCredentials.java +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk; - -/** - * Credentials for use with hosted services on the FORUMS libre website, a free embeddable forum hosting service. - * http://www.forumslibre.com - */ -public class FORUMSlibreCredentials extends Credentials { - public static String DOMAIN = "www.forumslibre.com"; - //public static String DOMAIN = "192.168.0.15:9080"; - public static String APP = ""; - //public static String APP = "/forumslibre"; - public static String PATH = "/rest/api"; - - public FORUMSlibreCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "http://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/LiveChatConnection.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/LiveChatConnection.java deleted file mode 100644 index 97b136983accbc0132b1729ced2df22fef4f3f2e..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/LiveChatConnection.java +++ /dev/null @@ -1,293 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk; - -import org.botlibre.sdk.config.ChannelConfig; -import org.botlibre.sdk.config.UserConfig; - -import de.tavendo.autobahn.WebSocketConnection; -import de.tavendo.autobahn.WebSocketConnectionHandler; - -/** - * Connection class for a Live Chat, or chatroom connection. - * A live chat connection is different than an SDKConnection as it is asynchronous, - * and uses web sockets for communication. - */ -public class LiveChatConnection { - protected boolean debug = false; - protected ChannelConfig channel; - protected UserConfig user; - protected Credentials credentials; - protected WebSocketConnection socket; - protected LiveChatListener listener; - protected boolean keepAlive = false; - protected Thread keepAliveThread; - - /** - * Create a new connection with the application credentials and the listener. - * The listener will be notified asynchronously of messages and events. - */ - public LiveChatConnection(Credentials credentials, LiveChatListener listener) { - this.credentials = credentials; - this.listener = listener; - } - - /** - * Connection to the live chat server channel. - * Validate the user credentials. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void connect(ChannelConfig channel, UserConfig user) { - this.channel = channel; - this.user = user; - try { - this.socket = new WebSocketConnection(); - this.socket.connect("ws://" + this.credentials.host + this.credentials.app - + "/live/chat", new WebSocketConnectionHandler() { - @Override - public void onOpen() { - if (LiveChatConnection.this.user == null) { - LiveChatConnection.this.socket.sendTextMessage("connect " + LiveChatConnection.this.channel.id + " " + LiveChatConnection.this.credentials.applicationId); - } else { - LiveChatConnection.this.socket.sendTextMessage( - "connect " + LiveChatConnection.this.channel.id + " " + LiveChatConnection.this.user.user - + " " + LiveChatConnection.this.user.token + " " + LiveChatConnection.this.credentials.applicationId); - } - } - - @Override - public void onTextMessage(String text) { - String user = ""; - String message = text; - int index = text.indexOf(':'); - if (index != -1) { - user = text.substring(0, index); - message = text.substring(index + 2, text.length()); - } - if (user.equals("Online-xml")) { - return; - } - if (user.equals("Online")) { - LiveChatConnection.this.listener.updateUsers(message); - return; - } - - if (LiveChatConnection.this.keepAlive && user.equals("Info") && text.contains("pong")) { - return; - } - if (user.equals("Info")) { - LiveChatConnection.this.listener.info(text); - return; - } - if (user.equals("Error")) { - LiveChatConnection.this.listener.error(text); - return; - } - LiveChatConnection.this.listener.message(text); - } - - @Override - public void onClose(int code, String reason) { - LiveChatConnection.this.listener.message("Info: Closed"); - LiveChatConnection.this.listener.closed(); - } - }); - } catch (Exception exception) { - throw new SDKException(exception); - } - } - - /** - * Sent a text message to the channel. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - * Note, the listener will receive its own messages. - */ - public void sendMessage(String message) { - checkSocket(); - if (message == null) { - return; - } - this.socket.sendTextMessage(message); - } - - /** - * Accept a private request. - * This is also used by an operator to accept the top of the waiting queue. - * This can also be used by a user to chat with the channel bot. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void accept() { - checkSocket(); - this.socket.sendTextMessage("accept"); - } - - /** - * Test the connection. - * A pong message will be returned, this message will not be broadcast to the channel. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void ping() { - checkSocket(); - this.socket.sendTextMessage("ping"); - } - - /** - * Exit from the current private channel. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void exit() { - checkSocket(); - this.socket.sendTextMessage("exit"); - } - - /** - * Request a private chat session with a user. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void pvt(String user) { - checkSocket(); - this.socket.sendTextMessage("pvt: " + user); - } - - /** - * Boot a user from the channel. - * You must be a channel administrator to boot a user. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void boot(String user) { - checkSocket(); - this.socket.sendTextMessage("boot: " + user); - } - - /** - * Send a private message to a user. - * This call is asynchronous, any error or success with be sent as a separate message to the listener. - */ - public void whisper(String user, String message) { - checkSocket(); - this.socket.sendTextMessage("whisper:" + user + ": " + message); - } - - /** - * Disconnect from the channel. - */ - public void disconnect() { - this.keepAlive = false; - if (this.keepAliveThread != null) { - this.keepAliveThread.interrupt(); - } - if (this.socket != null) { - this.socket.disconnect(); - } - } - - protected void runKeepAlive() { - this.keepAliveThread = new Thread() { - public void run() { - while (keepAlive) { - sendMessage("ping"); - try { - Thread.sleep(600000); - } catch (InterruptedException exception) { - return; - } - } - } - }; - this.keepAliveThread.start(); - } - - public boolean isDebug() { - return debug; - } - - /** - * Enable debugging messages (logged to System.out). - */ - public void setDebug(boolean debug) { - this.debug = debug; - } - - /** - * Return the current channel. - */ - public ChannelConfig getChannel() { - return channel; - } - - protected void setChannel(ChannelConfig channel) { - this.channel = channel; - } - - /** - * Return the current user. - */ - public UserConfig getUser() { - return user; - } - - protected void setUser(UserConfig user) { - this.user = user; - } - - /** - * Return the current application credentials. - */ - public Credentials getCredentials() { - return credentials; - } - - protected void setCredentials(Credentials credentials) { - this.credentials = credentials; - } - - public LiveChatListener getListener() { - return listener; - } - - public void setListener(LiveChatListener listener) { - this.listener = listener; - } - - /** - * Return if the connection will be kept alive, and not allowed to timeout due to inAbility. - */ - public boolean isKeepAlive() { - return keepAlive; - } - - /** - * Set if the connection should be kept alive, and not allowed to timeout due to inAbility. - */ - public void setKeepAlive(boolean keepAlive) { - this.keepAlive = keepAlive; - if (this.keepAlive) { - runKeepAlive(); - } else if (this.keepAliveThread != null) { - this.keepAliveThread.interrupt(); - this.keepAliveThread = null; - } - } - - protected void checkSocket() { - if (this.socket == null) { - throw new SDKException("Not connected"); - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/LiveChatListener.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/LiveChatListener.java deleted file mode 100644 index 725be7495ee51c357a0837dba02d312337dbabe5..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/LiveChatListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk; - -/** - * Listener interface for a LiveChatConnection. - * This gives asynchronous notification when a channel receives a message, or notice. - */ -public interface LiveChatListener { - /** - * A user message was received from the channel. - */ - void message(String message); - - /** - * An informational message was received from the channel. - * Such as a new user joined, private request, etc. - */ - void info(String message); - - /** - * An error message was received from the channel. - * This could be an access error, or message failure. - */ - void error(String message); - - /** - * Notification that the connection was closed. - */ - void closed(); - - /** - * The channels users changed (user joined, left, etc.) - * This contains a comma separated values (CSV) list of the current channel users. - * It can be passed to the SDKConnection.getUsers() API to obtain the UserConfig info for the users. - */ - void updateUsers(String usersCSV); -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MainAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MainAbility.java index c2a34ee40a39003dedf6443d30164e49e45994ae..05b3b368551c29af8a61b281a923ad9a1db138fd 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MainAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MainAbility.java @@ -1,44 +1,5 @@ package org.botlibre.sdk; -import org.botlibre.sdk.activityy.BotSearchAbility; -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.activityy.ChatAbility2; -import org.botlibre.sdk.activityy.CreateUserAbility; -import org.botlibre.sdk.activityy.HelpAbility; -import org.botlibre.sdk.activityy.LibreAbility; -import org.botlibre.sdk.activityy.ListTemplateView; -import org.botlibre.sdk.activityy.LoginAbility; -import org.botlibre.sdk.activityy.actions.HttpConnectAction; -import org.botlibre.sdk.activityy.actions.HttpFetchAction; -import org.botlibre.sdk.activityy.actions.HttpFetchOrCreateAction; -import org.botlibre.sdk.activityy.actions.HttpGetImageAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; -import org.botlibre.sdk.activityy.actions.HttpGetTemplatesAction; -import org.botlibre.sdk.activityy.dialog.SpinnerDialogBuilder; -import org.botlibre.sdk.activityy.listener.LanguageListener; -import org.botlibre.sdk.activityy.listener.SelectListener; -import org.botlibre.sdk.activityy.war.StartWarAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; -import org.botlibre.sdk.config.BotModeConfig; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChannelConfig; -import org.botlibre.sdk.config.DomainConfig; -import org.botlibre.sdk.config.ForumConfig; -import org.botlibre.sdk.config.ForumPostConfig; -import org.botlibre.sdk.config.GraphicConfig; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.IssueConfig; -import org.botlibre.sdk.config.LearningConfig; -import org.botlibre.sdk.config.OfflineTemplateConfig; -import org.botlibre.sdk.config.ResponseConfig; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import org.botlibre.sdk.config.UserConfig; -import org.botlibre.sdk.config.VoiceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.micro.MicroConnection; -import org.botlibre.sdk.util.PreferencesUtils; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; @@ -66,8 +27,41 @@ import ohos.multimodalinput.event.TouchEvent; import ohos.security.SystemPermission; import ohos.utils.net.Uri; import org.botlibre.knowledge.micro.MicroMemory; +import org.botlibre.sdk.ability.BotSearchAbility; +import org.botlibre.sdk.ability.ChatAbility; +import org.botlibre.sdk.ability.ChatAbility2; +import org.botlibre.sdk.ability.CreateUserAbility; +import org.botlibre.sdk.ability.HelpAbility; +import org.botlibre.sdk.ability.LibreAbility; +import org.botlibre.sdk.ability.ListTemplateView; +import org.botlibre.sdk.ability.LoginAbility; +import org.botlibre.sdk.ability.actions.HttpGetTemplatesAction; +import org.botlibre.sdk.ability.dialog.SpinnerDialogBuilder; +import org.botlibre.sdk.ability.listener.LanguageListener; +import org.botlibre.sdk.ability.listener.SelectListener; +import org.botlibre.sdk.ability.war.StartWarAbility; +import org.botlibre.sdk.config.AvatarConfig; +import org.botlibre.sdk.config.AvatarMedia; +import org.botlibre.sdk.config.BotModeConfig; +import org.botlibre.sdk.config.BrowseConfig; +import org.botlibre.sdk.config.ChannelConfig; +import org.botlibre.sdk.config.DomainConfig; +import org.botlibre.sdk.config.ForumConfig; +import org.botlibre.sdk.config.ForumPostConfig; +import org.botlibre.sdk.config.GraphicConfig; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.IssueConfig; +import org.botlibre.sdk.config.LearningConfig; +import org.botlibre.sdk.config.OfflineTemplateConfig; +import org.botlibre.sdk.config.ResponseConfig; +import org.botlibre.sdk.config.ScriptConfig; +import org.botlibre.sdk.config.ScriptSourceConfig; +import org.botlibre.sdk.config.UserConfig; +import org.botlibre.sdk.config.VoiceConfig; +import org.botlibre.sdk.config.WebMediumConfig; +import org.botlibre.sdk.micro.MicroConnection; +import org.botlibre.sdk.util.PreferencesUtils; -import javax.swing.text.View; import java.awt.*; import java.io.File; import java.util.ArrayList; @@ -128,7 +122,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag /** * If you are building a single instance app, then you can set the instance id or name here, - * and use this activity to launch it. + * and use this to launch it. */ public static String launchInstanceId = ""; // i.e. "171" public static String launchInstanceName = "Bot Libre!"; // i.e. "Help Bot" @@ -362,80 +356,27 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag super.onActive(); } - // // @TargetApi(Build.VERSION_CODES.KITKAT) -//// @SuppressLint("NewApi") -// public static String getFilePathFromURI(Context context, Uri uri) { -// // DocumentProvider -// if (DocumentsContract.isDocumentUri(context, uri)) { -// -// // ExternalStorageProvider -// if (ohos(uri)) { -// final String docId = DocumentsContract.getDocumentId(uri); -// final String[] split = docId.split(":"); -// final String type = split[0]; -// -// if ("primary".equalsIgnoreCase(type)) { -// return Environment.getExternalStorageDirectory() + "/" + split[1]; -// } -// // TODO handle non-primary volumes -// } -// // DownloadsProvider -// else if (isDownloadsDocument(uri)) { -// final String id = DocumentsContract.getDocumentId(uri); -// final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), -// Long.valueOf(id)); -// return getDataColumn(context, contentUri, null, null); -// } -// // MediaProvider -// else if (isMediaDocument(uri)) { -// final String docId = DocumentsContract.getDocumentId(uri); -// final String[] split = docId.split(":"); -// final String type = split[0]; -// Uri contentUri = null; -// if ("image".equals(type)) { -// contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; -// } else if ("video".equals(type)) { -// contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; -// -// } else if ("audio".equals(type)) { -// contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; -// } -// final String selection = "_id=?"; -// final String[] selectionArgs = new String[]{split[1]}; -// return getDataColumn(context, contentUri, selection, selectionArgs); -// } -// } -// // MediaStore (and general) -// else if ("content".equalsIgnoreCase(uri.getScheme())) { -// // Return the remote address -// if (isGooglePhotosUri(uri)) -// return uri.getLastPathSegment(); -// return getDataColumn(context, uri, null, null); -// } -// // File -// else if ("file".equalsIgnoreCase(uri.getScheme())) { -// return uri.getPath(); -// } -// return null; -// } - + /** + * getDataColumn + * + * @param context + * @param uri + * @param selection + * @param selectionArgs + * @return + */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { -// Cursor cursor = null; -// final String column = "_data"; -// final String[] projection = {column}; -// try { -// cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); -// if (cursor != null && cursor.moveToFirst()) { -// final int index = cursor.getColumnIndexOrThrow(column); -// return cursor.getString(index); -// } -// } finally { -// if (cursor != null) -// cursor.close(); -// } + return null; } + /** + * getFileSize + * + * @param q + * @param a + * @return + */ public static Boolean getFileSize(String q, Context a) { if (q == null || q.equals("")) { return true; @@ -457,70 +398,42 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } /** - * @param uri The Uri to check. - * @return Whether the Uri authority is DownloadsProvider. - */ - public static boolean isDownloadsDocument(Uri uri) { - return "com.ohos.providers.downloads.documents".equals(uri.getDecodedAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is MediaProvider. - */ - public static boolean isMediaDocument(Uri uri) { - return "com.ohos.providers.media.documents".equals(uri.getDecodedAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is Google Photos. + * isTablet + * + * @param context + * @return ds */ - - public static boolean isGooglePhotosUri(Uri uri) { - return "com.google.ohos.apps.photos.content".equals(uri.getDecodedAuthority()); - } - - public static String getFileNameFromPath(String path) { - int index = path.lastIndexOf("/"); - return path.substring(index + 1, path.length()); - } - -// public static String getFileTypeFromPath(String path) { -// int index = path.lastIndexOf("."); -// String ext = path.substring(index + 1, path.length()); -// if (ext.equalsIgnoreCase("webm")) { -// return "video/webm"; -// } -// return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext); -// } - public static boolean isTablet(Context context) { // return (context.getResourceManager().getConfiguration().isLayoutRTL // & Configuration.AUTO_MODE) >= Configuration.AUTO_MODE; return true; } - @SuppressWarnings("rawtypes") + /** + * getActivity + * + * @param config + * @return + */ public static Class getActivity(WebMediumConfig config) { if (config instanceof ChannelConfig) { -// return ChannelAbility.class; //==================== } else if (config instanceof ForumConfig) { -// return ForumAbility.class; //==================== } else if (config instanceof InstanceConfig) { -// return BotAbility.class; //==================== } else if (config instanceof DomainConfig) { -// return DomainAbility.class; //==================== } else if (config instanceof AvatarConfig) { -// return AvatarAbility.class; //==================== } else if (config instanceof ScriptConfig) { -// return ScriptAbility.class; //==================== } else if (config instanceof GraphicConfig) { -// return GraphicAbility.class; //==================== } return null; } + /** + * error + * + * @param message + * @param exception + * @param activity + */ public static void error(String message, Exception exception, Ability activity) { try { if (DEBUG) { @@ -541,6 +454,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * errorInfo + * + * @param type + * @param message + * @param exception + * @param activity + */ public static void errorInfo(int type, String message, Exception exception, Ability activity) { try { if (DEBUG) { @@ -561,6 +482,13 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * showMessage + * + * @param title + * @param message + * @param activity + */ public static void showMessage(String title, String message, Ability activity) { CommonDialog mCommonDialog = new CommonDialog(activity); Optional @@ -589,6 +517,13 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } + /** + * showLogin + * + * @param title + * @param message + * @param activity + */ public void showLogin(String title, String message, Ability activity) { CommonDialog mCommonDialog = new CommonDialog(activity); Optional @@ -620,6 +555,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag public static Text execcontentinfo; + /** + * showMessageInfo + * + * @param type + * @param title + * @param message + * @param activity + */ public static void showMessageInfo(int type, String title, String message, Ability activity) { CommonDialog mCommonDialog = new CommonDialog(activity); Optional @@ -655,10 +598,24 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } + /** + * showMessage + * + * @param message + * @param activity + */ public static void showMessage(String message, Ability activity) { showMessage(null, message, activity); } + /** + * prompt + * + * @param message + * @param activity + * @param text + * @param listener + */ public static void prompt(String message, Ability activity, TextField text, IDialog.ClickedListener listener) { CommonDialog dialog = new CommonDialog(activity); dialog.setContentText(message); @@ -673,32 +630,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag dialog.show(); } - public void contentRatingList() { - CommonDialog builder = new CommonDialog(this); - builder.setTitleText("Content Rating"); - - builder.setContentText("Select Content Rating: "); - builder.setButton(1, "Cancel", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int id) { - // save data -// Preferences editor = MainAbility.current.getp.getPreferences(Context.MODE_PRIVATE) -// .edit(); -// editor.putString("contentRating", (String) spin.getSelectedItem()); -// contentRating = (String) spin.getSelectedItem(); -// editor.flush(); - } - }); - - builder.setButton(1, "Cancel", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - - } - }); - builder.show(); - } - + /** + * confirm + * + * @param message + * @param activity + * @param cancelable + * @param listener + */ public static void confirm(String message, Ability activity, Boolean cancelable, IDialog.ClickedListener listener) { CommonDialog dialog = new CommonDialog(activity); dialog.setTitleText("Bot Libre!"); @@ -711,6 +650,12 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag dialog.show(); } + /** + * getAllTemplates + * + * @param activity + * @return ds + */ public static List getAllTemplates(Ability activity) { if (templates == null) { try { @@ -725,7 +670,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag return templates; } - public static final int REQ_PERMISSION_CODE = 1003; private final List mPermissions = new LinkedList<>( Arrays.asList( @@ -734,7 +678,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag @Override public void onStart(Intent intent) { super.onStart(intent); -// super.setMainRoute(MainAbilitySlice.class.getName()); searching = false; browsing = false; searchingPosts = false; @@ -764,16 +707,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag loadMemoryByBot(); -// WebMediumConfig config1 = new InstanceConfig(); -// OfflineTemplateConfig templates = new OfflineTemplateConfig(); -// config1.id = "1"; -// config1.name = "Empty"; -// MicroConnection connection = new MicroConnection(new BOTlibreCredentials("applicationId")); -// connection.fetch(config1); - - - // Checking and making sure that the mic is turned off to start - // configuring the microphone. micConfig = cookies.getBoolean("miconfig", micConfig); if (user == null) { @@ -796,8 +729,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag UserConfig config = new UserConfig(); config.user = user; config.token = token; - HttpConnectAction action = new HttpConnectAction(this, config, false); -// action.execute(); } String voice = cookies.getString("voice", null); @@ -847,6 +778,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * initChat + */ public void initChat() { chatButton = (Button) findComponentById(ResourceTable.Id_chatButton); // chat chatButton.setClickedListener(new Component.ClickedListener() { @@ -857,6 +791,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } + /** + * initMain + */ public void initMain() { spin = (Button) findComponentById(ResourceTable.Id_selectButton); // 底部类型选择 spin.setClickedListener(new Component.ClickedListener() { @@ -918,6 +855,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } + /** + * initBrowse + */ public void initBrowse() { chatButton = (Button) findComponentById(ResourceTable.Id_chatButton); chatButton.setClickedListener(new Component.ClickedListener() { @@ -954,17 +894,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - //动态权限 - private void reqPermissions() { - mPermissions.removeIf(perM -> verifySelfPermission(perM) == PERMISSION_GRANTED || !canRequestPermission(perM)); - if (!mPermissions.isEmpty()) { - requestPermissionsFromUser( - mPermissions.toArray(new String[0]), MainAbility.REQ_PERMISSION_CODE); - } else { - // 功能调用 - } - } - /** * 权限回调 * @@ -988,9 +917,11 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * resetView + */ public void loadMemoryByBot() { MicroMemory.storageDir = getFilesDir(); - //MicroMemory.storageDir = getExternalFilesDir(null); List items = new ArrayList(); items = ListTemplateView.retriveTemplates(); OfflineTemplateConfig oneItem; @@ -1002,7 +933,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag launchInstanceId = oneItem.getId(); } - @SuppressWarnings({"unchecked", "rawtypes"}) + /** + * resetView + */ public void resetView() { menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); // 菜单选择 menuButton.setClickedListener(new Component.ClickedListener() { @@ -1013,38 +946,18 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); - if (domain != null) { -// setTitle(Utils.stripTags(domain.name)); - HttpGetImageAction.fetchImage(this, domain.avatar, null); //----------------- -// HttpGetImageAction.fetchImage(this, domain.avatar, (Image) findComponentById(ResourceTable.Id_splash)); } -// if (MainAbility.user == null) { -// findComponentById(ResourceTable.Id_viewUserButton).setVisibility(HIDE); -// //findViewById(R.id.logoutButton).setVisibility(View.GONE); -// //findViewById(R.id.loginButton).setVisibility(View.VISIBLE); -// } else { -// //findViewById(R.id.logoutButton).setVisibility(View.VISIBLE); -// //findViewById(R.id.loginButton).setVisibility(View.GONE); -// findComponentById(ResourceTable.Id_viewUserButton).setVisibility(VISIBLE); -// //HttpGetImageAction.fetchImage(this, MainActivity.user.avatar, findViewById(R.id.viewUserButton)); -// } + resetMenu(this.menu); resetLast(); } + /** + * resetLast + */ public void resetLast() { -// String type = MainAbility.defaultType; -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); // 需要放入 adapter中做判断 -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// if (type.equals("Chat Bot Wars")) { -// spin.setSelection(0); -// war(null); -// return; -// } -// } if (type.equals("Chat Bot Wars")) { war(); return; @@ -1082,12 +995,10 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } + /** + * openLast + */ public void openLast() { - -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); // 适配器中做了选择赋值 -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } @@ -1131,11 +1042,13 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config = new InstanceConfig(); } config.name = last; - - HttpFetchAction action = new HttpFetchAction(this, config); -// action.execute(); } + /** + * resetMenu + * + * @param menu + */ public void resetMenu(Menu menu) { if (menu == null) { return; @@ -1143,65 +1056,32 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag for (int index = 0; index < menu.getItemCount(); index++) { menu.getItem(index).setEnabled(true); } - if (MainAbility.user == null) { - //menu.findItem(R.id.menuMyBots).setEnabled(false); - //menu.findItem(R.id.menuSignOut).setEnabled(false); - //menu.findItem(R.id.menuViewUser).setEnabled(false); - //menu.findItem(R.id.menuEditUser).setEnabled(false); - } else { - //menu.findItem(R.id.menuSignIn).setEnabled(false); - //menu.findItem(R.id.menuSignUp).setEnabled(false); - } - /*if (MicroMemory.checkExists()) { - menu.findItem(R.id.menuDeleteExistingBot).setEnabled(true); - } else { - menu.findItem(R.id.menuDeleteExistingBot).setEnabled(false); - }*/ - -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } - // MenuItem item = menu.findItem(R.id.menuMyBots); - // if (type.equals("Bots")) { - // item.setTitle("My Bots"); - // } else if (type.equals("Forums")) { - // item.setTitle("My Forums"); - // } else if (type.equals("Live Chat")) { - // item.setTitle("My Channels"); - // } else if (type.equals("Domains")) { - // item.setTitle("My Domains"); - // } else if (type.equals("Avatars")) { - // item.setTitle("My Avatars"); - // } else if (type.equals("Scripts")){ - // item.setTitle("My Scripts"); - // }else if (type.equals("Graphics")){ - // item.setTitle("My Graphics"); - // } + } + /** + * war + */ public void war() { startOpenAbility(this, StartWarAbility.class.getName()); } + /** + * login + */ public void login() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } - startOpenAbility(this, LoginAbility.class.getName()); } + /** + * logout + */ public void logout() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } + connection.disconnect(); user = null; instance = null; @@ -1237,13 +1117,15 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag editor.delete("deviceVoice"); editor.flushSync(); - HttpGetImageAction.clearFileCache(this); Intent intent = getIntent(); terminateAbility(); startAbility(intent); } + /** + * menu + */ public void menu() { Optional display = DisplayManager.getInstance().getDefaultDisplay(this); @@ -1285,28 +1167,18 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } + /** + * createUser + */ public void createUser() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// -// Intent intent = new Intent(this, CreateUserActivity.class); -// startActivity(intent); startOpenAbility(this, CreateUserAbility.class.getName()); } - public void editUser() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// -// Intent intent = new Intent(this, EditUserActivity.class); -// startActivity(intent); -// startOpenAbility(this, EditUserAbility.class.getName()); //================ - } - + /** + * setOnline + * + * @param result + */ public static void setOnline(boolean result) { if (result) { connection = remoteConnection; @@ -1317,27 +1189,23 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } + /** + * help + */ public void help() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// super.help(view); startOpenAbility(this, HelpAbility.class.getName()); } + /** + * viewUser + */ public void viewUser() { viewUser = user; -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } - -// Intent intent = new Intent(this, ViewUserActivity.class); -// startActivity(intent); -// startOpenAbility(this, ViewUserAbility.class.getName()); //================ } + /** + * openWebsite + */ public void openWebsite() { try { Intent intent2 = new Intent(); @@ -1351,94 +1219,38 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * createInstance + */ public void createInstance() { if (user == null) { showLogin("", "You must sign in first", this); return; } -// Spinner spin = (Spinner) findViewById(getResources().getIdentifier("typeSpin", "id", getPackageName())); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } if (type.equals("Bots")) { MainAbility.template = ""; -// Intent intent = new Intent(this, CreateBotActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateBotAbility.class.getName()); //================ - } else if (type.equals("Forums")) { -// Intent intent = new Intent(this, CreateForumActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateForumAbility.class.getName()); //================ - } else if (type.equals("Live Chat")) { -// Intent intent = new Intent(this, CreateChannelActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateChannelAbility.class.getName()); //================ - } else if (type.equals("Domains")) { -// Intent intent = new Intent(this, CreateDomainActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateDomainAbility.class.getName()); //================ - } else if (type.equals("Avatars")) { -// Intent intent = new Intent(this, CreateAvatarActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateAvatarAbility.class.getName()); //================ - } else if (type.equals("Scripts")) { -// Intent intent = new Intent(this, CreateScriptActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateScriptAbility.class.getName()); //================ - } else if (type.equals("Graphics")) { -// Intent intent = new Intent(this, CreateGraphicActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateGraphicAbility.class.getName()); //================ } } + /** + * search + */ public void search() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } if (type.equals("Bots")) { -// Intent intent = new Intent(this, BotSearchActivity.class); -// startActivity(intent); startOpenAbility(this, BotSearchAbility.class.getName()); - } else if (type.equals("Forums")) { -// Intent intent = new Intent(this, ForumSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, ForumSearchAbility.class.getName()); //================ - } else if (type.equals("Live Chat")) { -// Intent intent = new Intent(this, ChannelSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, ChannelSearchAbility.class.getName()); //================ - } else if (type.equals("Domains")) { -// Intent intent = new Intent(this, DomainSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, DomainSearchAbility.class.getName()); //================ - } else if (type.equals("Avatars")) { -// Intent intent = new Intent(this, AvatarSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, AvatarSearchAbility.class.getName()); //================ - } else if (type.equals("Scripts")) { -// Intent intent = new Intent(this, ScriptSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, ScriptSearchAbility.class.getName()); //================ - } else if (type.equals("Graphics")) { -// Intent intent = new Intent(this, GraphicSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, GraphicSearchAbility.class.getName()); //================ } } + /** + * browseMyBots + */ public void browseMyBots() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } @@ -1460,15 +1272,12 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config.type = "Graphic"; } config.contentRating = "Mature"; - HttpGetInstancesAction action = new HttpGetInstancesAction(this, config); -// action.execute(); } + /** + * browse + */ public void browse() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } @@ -1490,8 +1299,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config.type = "Graphic"; } config.contentRating = MainAbility.contentRating; - HttpGetInstancesAction action = new HttpGetInstancesAction(this, config); -// action.execute(); } /** @@ -1508,23 +1315,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } config.id = launchInstanceId; config.name = launchInstanceName; - - HttpFetchAction action = new HttpFetchAction(this, config, false); -// action.execute(); } /** - * Start a chat session with the hard coded instance. - */ - - /* - * This method will have a list of 8 empty bot, basic, AI, julie, eddie, - * alice, personal assistance, juile assistance. before attaching the ID and - * Name of the bot make sure that its selecetd thro the list. + * launch */ public void launch() { setOnline(false); - WebMediumConfig config = null; + WebMediumConfig config = null; // the launch type is bot. if (MainAbility.launchType == LaunchType.Bot) { if (null == instance || null == this.instance.name || this.instance.name.equals("")) { @@ -1539,19 +1337,13 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config.name = MainAbility.launchInstanceName; MicroConnection microConnection = (MicroConnection) MainAbility.getConnection(); microConnection.fetch(config); - if(MainAbility.launchInstanceName.contains("Assistance")){ + if (MainAbility.launchInstanceName.contains("Assistance")) { startOpenAbility(MainAbility.this, ChatAbility2.class.getName()); - }else{ + } else { startOpenAbility(MainAbility.this, ChatAbility.class.getName()); } } } else { -// config = new InstanceConfig(); -// readZipAvatars(this, this.nameOfAvatar); -// config.name = MainAbility.launchInstanceName; -// config.id = MainAbility.launchInstanceId; -// HttpFetchActionOffline action = new HttpFetchActionOffline(this, config, true); -// action.execute(); } } else if (MainAbility.launchType == LaunchType.Forum) { config = new ForumConfig(); @@ -1560,8 +1352,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * saveAllData + * + * @param instanceId + * @param instanceName + * @param id + */ public void saveAllData(String instanceId, String instanceName, int id) { -// Preferences cookies = MainAbility.current.getPreferences(Context.MODE_PRIVATE).edit(); Preferences cookies = PreferencesUtils.getPreferences(this); cookies.putString("instanceID", instanceId); cookies.putString("instanceName", instanceName); @@ -1569,55 +1367,11 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag cookies.flushSync(); } - /** - * View the user's personal instance. - */ - public void browseMyBot() { - if (user == null) { - CommonDialog dialog = new CommonDialog(this); - dialog.setContentText("You must sign in first"); - dialog.setButton(1, "OK", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - login(); - } - }); - dialog.show(); - return; - } - WebMediumConfig config = new InstanceConfig(); - config.name = "Bot " + MainAbility.user.user; - - HttpFetchOrCreateAction action = new HttpFetchOrCreateAction(this, config, false); -// action.execute(); - } + public static String selectInfo = ""; /** - * Start a chat session with the user's personal instance. + * changeLanguage */ - public void launchMyBot(View view) { - if (user == null) { - CommonDialog dialog = new CommonDialog(this); - dialog.setContentText("You must sign in first"); - dialog.setButton(1, "OK", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - login(); - } - }); - dialog.show(); - return; - } - WebMediumConfig config = new InstanceConfig(); - config.name = "Bot " + MainAbility.user.user; - - HttpFetchOrCreateAction action = new HttpFetchOrCreateAction(this, config, true); -// action.execute(); - } - - public static String selectInfo = ""; - - @SuppressWarnings({"rawtypes", "unchecked"}) public void changeLanguage() { Optional display = DisplayManager.getInstance().getDefaultDisplay(this); @@ -1654,20 +1408,13 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } + /** + * readZipAvatars + * + * @param activity + * @param fileName + */ public static void readZipAvatars(Ability activity, String fileName) { - // this is only for letting Julie Assistance Avatar works, since there - // is only one file called - // "Julie" I will have to take this name and read the file from the - // method @readZipAvatars. String args[] = fileName.split("\\s+"); - // ex: Julie = Julie - // Julie Assistant = Julie - // Its only going to take one name - try { -// GetAvatarAction avatar = new GetAvatarAction(activity); -// avatar.readZipFile(args[0] + ".zip"); -// MicroConnection.avatarConfig = avatar.instance; - } catch (Exception ignore) { - } } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/PaphusCredentials.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/PaphusCredentials.java deleted file mode 100644 index f895330e85d994cd02f5c2330396fbd149fa6c8f..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/PaphusCredentials.java +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk; - -/** - * Credentials for use with hosted services on the Bot Libre for Business website, - * a commercial bot, live chat, chatroom, and forum hosting service. - * https://www.botlibre.biz - */ -public class PaphusCredentials extends Credentials { - public static String DOMAIN = "www.botlibre.biz"; - //public static String DOMAIN = "192.168.0.11:9080"; - public static String APP = ""; - //public static String APP = "/livechat"; - public static String PATH = "/rest/api"; - - public PaphusCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "https://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java index a3e843091663cecbf38b86252de1c82cfa547778..266e751905b7cd4ca071ec34d7e2cbdc03d1f156 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java @@ -31,6 +31,7 @@ import com.franmontiel.persistentcookiejar.ClearableCookieJar; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; +import ohos.agp.components.element.ShapeElement; import org.botlibre.sdk.config.AvatarConfig; import org.botlibre.sdk.config.AvatarMedia; import org.botlibre.sdk.config.AvatarMessage; @@ -92,1916 +93,1693 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; /** - * Connection class for a REST service connection. - * The SDK connection gives you access to the paphus or libre server services using a REST API. - *

- * The services include: - *

    - *
  • User management (account creation, validation) - *
  • Bot access, chat, and administration - *
  • Forum access, posting, and administration - *
  • Live chat access, chat, and administration - *
  • Domain access, and administration - *
+ * HttpConnectAction + * + * @since 2021-04-16 */ public class SDKConnection { - protected static String[] types = new String[]{"Bots", "Forums", "Graphics", "Live Chat", "Domains", "Scripts", "IssueTracker"}; - protected static String[] channelTypes = new String[]{"ChatRoom", "OneOnOne"}; - protected static String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; - protected static String[] mediaAccessModes = new String[]{"Everyone", "Users", "Members", "Administrators", "Disabled"}; - protected static String[] learningModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; - protected static String[] correctionModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; - protected static String[] botModes = new String[]{"ListenOnly", "AnswerOnly", "AnswerAndListen"}; - protected static String[] priorities = new String[]{"Low", "Medium", "High", "Sever"}; - - protected String url; - protected UserConfig user; - protected DomainConfig domain; - protected Credentials credentials; - protected boolean debug = false; - - protected SDKException exception; - - /** - * Return the name of the default user image. - */ - public static String defaultUserImage() { - return "images/user-thumb.jpg"; - } - - /** - * Create an SDK connection. - */ - public SDKConnection() { - } - - /** - * Create an SDK connection with the credentials. - * Use the Credentials subclass specific to your server. - */ - public SDKConnection(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - /** - * Validate the user credentials (password, or token). - * The user details are returned (with a connection token, password removed). - * The user credentials are soted in the connection, and used on subsequent calls. - * An SDKException is thrown if the connect failed. - */ - public UserConfig connect(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - this.user = null; - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - return this.user; - } - - /** - * Execute the custom API. - */ - public Config custom(String api, Config config, Config result) { - config.addCredentials(this); - String xml = POST(this.url + "/" + api, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - result.parseXML(root); - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - return result; - } - - /** - * Connect to the live chat channel and return a LiveChatConnection. - * A LiveChatConnection is separate from an SDKConnection and uses web sockets for - * asynchronous communication. - * The listener will be notified of all messages. - */ - public LiveChatConnection openLiveChat(ChannelConfig channel, LiveChatListener listener) { - LiveChatConnection connection = new LiveChatConnection(this.credentials, listener); - connection.connect(channel, this.user); - return connection; - } - - /** - * Connect to the domain. - * A domain is an isolated content space. - * Any browse or query request will be specific to the domain's content. - */ - public DomainConfig connect(DomainConfig config) { - this.domain = fetch(config); - return this.domain; - } - - /** - * Disconnect from the connection. - * An SDKConnection does not keep a live connection, but this resets its connected user and domain. - */ - public void disconnect() { - this.user = null; - this.domain = null; - } - - /** - * Fetch the user details. - */ - public UserConfig fetch(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/view-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Fetch the URL for the image from the server. - */ - public URL fetchImage(String image) { - try { - return new URL("http://" + this.credentials.host + this.credentials.app + "/" + image); - } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - } - - /** - * Fetch the forum post details for the forum post id. - */ - public ForumPostConfig fetch(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-forum-post", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML(root); - return post; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Fetch the issue details for the issue id. - */ - public IssueConfig fetch(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-issue", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - IssueConfig issue = new IssueConfig(); - issue.parseXML(root); - return issue; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new user. - */ - public UserConfig create(Ability ability,UserConfig config) { - config.addCredentials(this); - String xml = POSTUpdate(ability,this.url + "/create-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new forum post. - * You must set the forum id for the post. - */ - public ForumPostConfig create(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-forum-post", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML(root); - return post; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new issue. - * You must set the issue tracker id for the issue. - */ - public IssueConfig create(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-issue", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - IssueConfig issue = new IssueConfig(); - issue.parseXML(root); - return issue; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new file/image/media attachment for a chat channel. - */ - public MediaConfig createChannelFileAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTFILE(this.url + "/create-channel-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new image attachment for a chat channel. - */ - public MediaConfig createChannelImageAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/create-channel-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new file/image/media attachment for an issue tracker. - */ - public MediaConfig createIssueTrackerFileAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTFILE(this.url + "/create-issuetracker-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new image attachment for an issue tracker. - */ - public MediaConfig createIssueTrackerImageAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/create-issuetracker-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new image attachment for an issue tracker. - */ - public MediaConfig createIssueTrackerImageAttachment(PixelMap bitmap, MediaConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/create-issuetracker-attachment", bitmap, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a reply to a forum post. - * You must set the parent id for the post replying to. - */ - public ForumPostConfig createReply(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-reply", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ForumPostConfig reply = new ForumPostConfig(); - reply.parseXML(root); - return reply; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a user message. - * This can be used to send a user a direct message. - * SPAM will cause your account to be deleted. - */ - public void createUserMessage(UserMessageConfig config) { - config.addCredentials(this); - POST(this.url + "/create-user-message", config.toXML()); - } - - /** - * Fetch the content details from the server. - * The id or name and domain of the object must be set. - */ - @SuppressWarnings("unchecked") - public T fetch(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-" + config.getType(), config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create the new content. - * The content will be returned with its new id. - */ - @SuppressWarnings("unchecked") - public T create(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-" + config.getType(), config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the content. - */ - @SuppressWarnings("unchecked") - public T update(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-" + config.getType(), config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the forum post. - */ - public ForumPostConfig update(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-forum-post", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = new ForumPostConfig(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the issue. - */ - public IssueConfig update(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-issue", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = new IssueConfig(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create or update the response. - * This can also be used to flag, unflag, validate, or invalidate a response. - */ - public ResponseConfig saveResponse(ResponseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/save-response", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ResponseConfig response = new ResponseConfig(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the user details. - * The password must be passed to allow the update. - */ - public UserConfig update(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Permanently delete the content with the id. - */ - public void delete(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-" + config.getType(), config.toXML()); - if(this.domain!=null && this.domain.id.equals(config.id) && config.getType().equals("domain") ){ - domain=null; - } - } - - /** - * Permanently delete the forum post with the id. - */ - public void delete(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-forum-post", config.toXML()); - } - - /** - * Permanently delete the issue with the id. - */ - public void delete(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-issue", config.toXML()); - } - - /** - * Permanently delete the response, greetings, or default response with the response id (and question id). - */ - public void delete(ResponseConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-response", config.toXML()); - } - - /** - * Permanently delete the avatar media. - */ - public void delete(AvatarMedia config) { - config.addCredentials(this); - POST(this.url + "/delete-avatar-media", config.toXML()); - } - - /** - * Permanently delete the avatar background. - */ - public void deleteAvatarBackground(AvatarConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-avatar-background", config.toXML()); - } - - /** - * Save the avatar media tags. - */ - public void saveAvatarMedia(AvatarMedia config) { - config.addCredentials(this); - POST(this.url + "/save-avatar-media", config.toXML()); - } - - /** - * Flag the content as offensive, a reason is required. - */ - public void flag(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-" + config.getType(), config.toXML()); - } - - /** - * Subscribe for email updates for the post. - */ - public void subscribe(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-post", config.toXML()); - } - - /** - * Subscribe for email updates for the issue. - */ - public void subscribe(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-issue", config.toXML()); - } - - /** - * Subscribe for email updates for the forum. - */ - public void subscribe(ForumConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-forum", config.toXML()); - } - - /** - * Unsubscribe from email updates for the post. - */ - public void unsubscribe(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-post", config.toXML()); - } - - /** - * Unsubscribe from email updates for the issue. - */ - public void unsubscribe(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-issue", config.toXML()); - } - - /** - * Unsubscribe from email updates for the forum. - */ - public void unsubscribe(ForumConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-forum", config.toXML()); - } - - /** - * Thumbs up the content. - */ - public void thumbsUp(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-" + config.getType(), config.toXML()); - } - - /** - * Thumbs down the content. - */ - public void thumbsDown(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-" + config.getType(), config.toXML()); - } - - /** - * Rate the content. - */ - public void star(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/star-" + config.getType(), config.toXML()); - } - - /** - * Thumbs up the content. - */ - public void thumbsUp(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-post", config.toXML()); - } - - /** - * Thumbs down the content. - */ - public void thumbsDown(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-post", config.toXML()); - } - - /** - * Rate the content. - */ - public void star(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/star-post", config.toXML()); - } - - /** - * Flag the forum post as offensive, a reason is required. - */ - public void flag(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-forum-post", config.toXML()); - } - - /** - * Thumbs up the content. - */ - public void thumbsUp(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-issue", config.toXML()); - } - - /** - * Thumbs down the content. - */ - public void thumbsDown(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-issue", config.toXML()); - } - - /** - * Rate the content. - */ - public void star(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/star-issue", config.toXML()); - } - - /** - * Flag the forum post as offensive, a reason is required. - */ - public void flag(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-issue", config.toXML()); - } - - /** - * Flag the user post as offensive, a reason is required. - */ - public void flag(UserConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-user", config.toXML()); - } - - /** - * Process the bot chat message and return the bot's response. - * The ChatConfig should contain the conversation id if part of a conversation. - * If a new conversation the conversation id is returned in the response. - */ - public ChatResponse chat(ChatConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/post-chat", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ChatResponse response = new ChatResponse(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Process the avatar message and return the avatars response. - * This allows the speech and video animation for an avatar to be generated for the message. - */ - public ChatResponse avatarMessage(AvatarMessage config) { - config.addCredentials(this); - String xml = POST(this.url + "/avatar-message", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ChatResponse response = new ChatResponse(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Process the speech message and return the server generate text-to-speech audio file. - * This allows for server-side speech generation. - */ - public String tts(Speech config) { - config.addCredentials(this); - return POST(this.url + "/speak", config.toXML()); - } - - /** - * Return the administrators of the content. - */ - public List getAdmins(WebMediumConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-" + config.getType() + "-admins", config.toXML()); - List users = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return users; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - UserConfig user = new UserConfig(); - user.parseXML((Element)root.getChildNodes().item(index)); - users.add(user.user); - } - return users; - } - - /** - * Return the list of user details for the comma separated values list of user ids. - */ - public List getUsers(String usersCSV) { - UserConfig config = new UserConfig(); - config.user = usersCSV; - config.addCredentials(this); - String xml = POST(this.url + "/get-users", config.toXML()); - List users = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return users; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - Element child = (Element)root.getChildNodes().item(index); - UserConfig userConfig = new UserConfig(); - userConfig.parseXML(child); - users.add(userConfig); - } - return users; - } - - /** - * Return the list of forum posts for the forum browse criteria. - */ - public List getPosts(BrowseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-forum-posts", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML((Element)root.getChildNodes().item(index)); - instances.add(post); - } - return instances; - } - - /** - * Return the list of issues for the issue tracker browse criteria. - */ - public List getIssues(BrowseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-issues", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - IssueConfig issue = new IssueConfig(); - issue.parseXML((Element)root.getChildNodes().item(index)); - instances.add(issue); - } - return instances; - } - - /** - * Return the list of categories for the type, and domain. - */ - public List getCategories(ContentConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-categories", config.toXML()); - List categories = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return categories; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ContentConfig category = new ContentConfig(); - category.parseXML((Element)root.getChildNodes().item(index)); - categories.add(category); - } - return categories; - } - - /** - * Return the list of tags for the type, and domain. - */ - public List getTags(ContentConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-tags", config.toXML()); - List tags = new ArrayList(); - tags.add(""); - Element root = parse(xml); - if (root == null) { - return tags; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - tags.add(((Element)root.getChildNodes().item(index)).getAttribute("name")); - } - return tags; - } - - /** - * Return the list of bot templates. - */ - - //return the list of templates with the pictures. - public List getTemplates() { - String xml = GET(this.url + "/get-all-templates"); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - InstanceConfig instance = new InstanceConfig(); - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - - /** - * Return the users for the content. - */ - public List getUsers(WebMediumConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-" + config.getType() + "-users", config.toXML()); - List users = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return users; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - UserConfig user = new UserConfig(); - user.parseXML((Element)root.getChildNodes().item(index)); - users.add(user.user); - } - return users; - } - - /** - * Return the channel's bot configuration. - */ - public BotModeConfig getChannelBotMode(ChannelConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-channel-bot-mode", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - BotModeConfig botMode = new BotModeConfig(); - botMode.parseXML(root); - return botMode; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Save the channel's bot configuration. - */ - public void saveChannelBotMode(BotModeConfig config) { - config.addCredentials(this); - POST(this.url + "/save-channel-bot-mode", config.toXML()); - } - - /** - * Save the forum's bot configuration. - */ - public void saveForumBotMode(BotModeConfig config) { - config.addCredentials(this); - POST(this.url + "/save-forum-bot-mode", config.toXML()); - } - - /** - * Save the bot's learning configuration. - */ - public void saveLearning(LearningConfig config) { - config.addCredentials(this); - POST(this.url + "/save-learning", config.toXML()); - } - - /** - * Save the bot's voice configuration. - */ - public void saveVoice(VoiceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-voice", config.toXML()); - } - - /** - * Save the bot's avatar configuration. - */ - public void saveBotAvatar(InstanceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-bot-avatar", config.toXML()); - } - - /** - * Train the bot with a new question/response pair. - */ - public void train(TrainingConfig config) { - config.addCredentials(this); - POST(this.url + "/train-instance", config.toXML()); - } - - /** - * Perform the user administration task (add or remove users, or administrators). - */ - public void userAdmin(UserAdminConfig config) { - config.addCredentials(this); - POST(this.url + "/user-admin", config.toXML()); - } - - /** - * Save the image as the avatar's background. - */ - public void saveAvatarBackground(String file, AvatarMedia config) { - config.addCredentials(this); - POSTIMAGE(this.url + "/save-avatar-background", file, config.name, config.toXML()); - } - - /** - * Add the avatar media file to the avatar. - */ - public void createAvatarMedia(String file, AvatarMedia config) { - config.addCredentials(this); - if ((file.indexOf(".jpg") != -1) || (file.indexOf(".jpeg") != -1)) { - if (config.hd) { - POSTHDIMAGE(this.url + "/create-avatar-media", file, config.name, config.toXML()); - } else { - POSTIMAGE(this.url + "/create-avatar-media", file, config.name, config.toXML()); - } - } else { - POSTFILE(this.url + "/create-avatar-media", file, config.name, config.toXML()); - } - } - /** - * Add the graphic media file to the graphic. - */ - public void createGraphicMedia(String file, GraphicConfig config) { - config.addCredentials(this); - if ((file.indexOf(".jpg") != -1) || (file.indexOf(".jpeg") != -1)) { - POSTIMAGE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); - } else { - POSTFILE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); - } - } - /** - * Update the contents icon. - * The file will be uploaded to the server. - */ - @SuppressWarnings("unchecked") - public T updateIcon(String file, T config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/update-" + config.getType() + "-icon", file, "image.jpg", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the user's icon. - * The file will be uploaded to the server. - */ - public UserConfig updateIcon(String file, UserConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/update-user-icon", file, "image.jpg", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = new UserConfig(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - public String POSTIMAGE(String url, String file, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("file: " + file); - System.out.println("XML: " + xml); - } - String result = ""; -// try { //===================== -// Bitmap bitmap = loadImage(file, 600, 600); -// ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); -// byte[] byte_arr = stream.toByteArray(); -// ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); -// -// MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); -// -// multipartEntity.addPart("file", fileBody); -// multipartEntity.addPart("xml", new StringBody(xml)); -// -// HttpClient httpclient = new DefaultHttpClient(); -// HttpResponse response = null; -// -// HttpPost httppost = new HttpPost(url); -// httppost.setEntity(multipartEntity); -// response = httpclient.execute(httppost); -// -// HttpEntity entity = response.getEntity(); -// if (entity != null) { -// result = EntityUtils.toString(entity, HTTP.UTF_8); -// } -// -// if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { -// this.exception = new SDKException("" -// + response.getStatusLine().getStatusCode() -// + " : " + result); -// throw this.exception; -// } -// -// } catch (Exception exception) { -// this.exception = new SDKException(exception); -// throw this.exception; -// } - return result; - } - - public String POSTIMAGE(String url, PixelMap bitmap, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - try { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); + protected static String[] types = new String[]{"Bots", "Forums", "Graphics", "Live Chat", "Domains", "Scripts", "IssueTracker"}; + protected static String[] channelTypes = new String[]{"ChatRoom", "OneOnOne"}; + protected static String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; + protected static String[] mediaAccessModes = new String[]{"Everyone", "Users", "Members", "Administrators", "Disabled"}; + protected static String[] learningModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; + protected static String[] correctionModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; + protected static String[] botModes = new String[]{"ListenOnly", "AnswerOnly", "AnswerAndListen"}; + protected static String[] priorities = new String[]{"Low", "Medium", "High", "Sever"}; + + protected String url; + protected UserConfig user; + protected DomainConfig domain; + protected Credentials credentials; + protected boolean debug = false; + + protected SDKException exception; + + /** + * Return the name of the default user image. + */ + public static String defaultUserImage() { + return "images/user-thumb.jpg"; + } + + /** + * Create an SDK connection. + */ + public SDKConnection() { + } + + /** + * Create an SDK connection with the credentials. + * Use the Credentials subclass specific to your server. + */ + public SDKConnection(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + /** + * connect + * + * @param config + * @return + */ + public UserConfig connect(UserConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-user", config.toXML()); + Element root = parse(xml); + if (root == null) { + this.user = null; + return null; + } + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + this.user = user; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + return this.user; + } + + /** + * custom + * + * @param api + * @param config + * @param result + * @return dd + */ + public Config custom(String api, Config config, Config result) { + config.addCredentials(this); + String xml = POST(this.url + "/" + api, config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + result.parseXML(root); + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + return result; + } + + + /** + * connect + * + * @param config + * @return dd + */ + public DomainConfig connect(DomainConfig config) { + this.domain = fetch(config); + return this.domain; + } + + /** + * disconnect + */ + public void disconnect() { + this.user = null; + this.domain = null; + } + + /** + * fetch + * + * @param config + * @return dsd + */ + public UserConfig fetch(UserConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/view-user", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + return user; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * fetchImage + * + * @param image + * @return dd + */ + public URL fetchImage(String image) { + try { + return new URL("http://" + this.credentials.host + this.credentials.app + "/" + image); + } catch (Exception exception) { + this.exception = new SDKException(exception); + throw this.exception; + } + } + + /** + * fetch + * + * @param config + * @return dd + */ + public ForumPostConfig fetch(ForumPostConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-forum-post", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ForumPostConfig post = new ForumPostConfig(); + post.parseXML(root); + return post; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * fetch + * + * @param config + * @return dd + */ + public IssueConfig fetch(IssueConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-issue", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + IssueConfig issue = new IssueConfig(); + issue.parseXML(root); + return issue; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * create + * + * @param ability + * @param config + * @return df + */ + public UserConfig create(Ability ability, UserConfig config) { + config.addCredentials(this); + String xml = POSTUpdate(ability, this.url + "/create-user", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + this.user = user; + return user; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * create + * + * @param config + * @return dd + */ + public ForumPostConfig create(ForumPostConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-forum-post", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ForumPostConfig post = new ForumPostConfig(); + post.parseXML(root); + return post; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * create + * + * @param config + * @return dd + */ + public IssueConfig create(IssueConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-issue", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + IssueConfig issue = new IssueConfig(); + issue.parseXML(root); + return issue; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * createChannelFileAttachment + * + * @param file + * @param config + * @return + */ + public MediaConfig createChannelFileAttachment(String file, MediaConfig config) { + config.addCredentials(this); + String xml = POSTFILE(this.url + "/create-channel-attachment", file, config.name, config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + MediaConfig media = new MediaConfig(); + media.parseXML(root); + return media; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * createChannelImageAttachment + * + * @param file + * @param config + * @return dd + */ + public MediaConfig createChannelImageAttachment(String file, MediaConfig config) { + config.addCredentials(this); + String xml = POSTIMAGE(this.url + "/create-channel-attachment", file, config.name, config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + MediaConfig media = new MediaConfig(); + media.parseXML(root); + return media; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * createIssueTrackerFileAttachment + * + * @param file + * @param config + * @return dd + */ + public MediaConfig createIssueTrackerFileAttachment(String file, MediaConfig config) { + config.addCredentials(this); + String xml = POSTFILE(this.url + "/create-issuetracker-attachment", file, config.name, config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + MediaConfig media = new MediaConfig(); + media.parseXML(root); + return media; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * createIssueTrackerImageAttachment + * + * @param file + * @param config + * @return dd + */ + public MediaConfig createIssueTrackerImageAttachment(String file, MediaConfig config) { + config.addCredentials(this); + String xml = POSTIMAGE(this.url + "/create-issuetracker-attachment", file, config.name, config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + MediaConfig media = new MediaConfig(); + media.parseXML(root); + return media; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * createIssueTrackerImageAttachment + * + * @param bitmap + * @param config + * @return dd + */ + public MediaConfig createIssueTrackerImageAttachment(PixelMap bitmap, MediaConfig config) { + config.addCredentials(this); + String xml = POSTIMAGE(this.url + "/create-issuetracker-attachment", bitmap, config.name, config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + MediaConfig media = new MediaConfig(); + media.parseXML(root); + return media; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * createReply + * + * @param config + * @return dd + */ + public ForumPostConfig createReply(ForumPostConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-reply", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ForumPostConfig reply = new ForumPostConfig(); + reply.parseXML(root); + return reply; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * fetch + * + * @param config + * @param + * @return dd + */ + public T fetch(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-" + config.getType(), config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * create + * + * @param config + * @param + * @return + */ + public T create(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-" + config.getType(), config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * update + * + * @param config + * @param + * @return + */ + public T update(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/update-" + config.getType(), config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + + /** + * saveResponse + * + * @param config + * @return + */ + public ResponseConfig saveResponse(ResponseConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/save-response", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ResponseConfig response = new ResponseConfig(); + response.parseXML(root); + return response; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + + /** + * delete + * + * @param config + */ + public void delete(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-" + config.getType(), config.toXML()); + if (this.domain != null && this.domain.id.equals(config.id) && config.getType().equals("domain")) { + domain = null; + } + } + + /** + * delete + * + * @param config + */ + public void delete(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-forum-post", config.toXML()); + } + + /** + * delete + * + * @param config + */ + public void delete(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-issue", config.toXML()); + } + + /** + * delete + * + * @param config + */ + public void delete(ResponseConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-response", config.toXML()); + } + + /** + * delete + * + * @param config + */ + public void delete(AvatarMedia config) { + config.addCredentials(this); + POST(this.url + "/delete-avatar-media", config.toXML()); + } + + /** + * deleteAvatarBackground + * + * @param config + */ + public void deleteAvatarBackground(AvatarConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-avatar-background", config.toXML()); + } + + /** + * saveAvatarMedia + * + * @param config + */ + public void saveAvatarMedia(AvatarMedia config) { + config.addCredentials(this); + POST(this.url + "/save-avatar-media", config.toXML()); + } + + + /** + * subscribe + * + * @param config + */ + public void subscribe(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/subscribe-post", config.toXML()); + } + + /** + * subscribe + * + * @param config + */ + public void subscribe(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/subscribe-issue", config.toXML()); + } + + /** + * subscribe + * + * @param config + */ + public void subscribe(ForumConfig config) { + config.addCredentials(this); + POST(this.url + "/subscribe-forum", config.toXML()); + } + + + /** + * thumbsUp + * + * @param config + */ + public void thumbsUp(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-up-" + config.getType(), config.toXML()); + } + + /** + * thumbsDown + * + * @param config + */ + public void thumbsDown(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-down-" + config.getType(), config.toXML()); + } + + /** + * star + * + * @param config + */ + public void star(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/star-" + config.getType(), config.toXML()); + } + + /** + * thumbsUp + * + * @param config + */ + public void thumbsUp(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-up-post", config.toXML()); + } + + /** + * thumbsDown + * + * @param config + */ + public void thumbsDown(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-down-post", config.toXML()); + } + + /** + * star + * + * @param config + */ + public void star(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/star-post", config.toXML()); + } + + + /** + * thumbsUp + * + * @param config + */ + public void thumbsUp(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-up-issue", config.toXML()); + } + + /** + * thumbsDown + * + * @param config + */ + public void thumbsDown(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-down-issue", config.toXML()); + } + + /** + * star + * + * @param config + */ + public void star(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/star-issue", config.toXML()); + } + + + /** + * flag + * + * @param config + */ + public void flag(UserConfig config) { + config.addCredentials(this); + POST(this.url + "/flag-user", config.toXML()); + } + + /** + * chat + * + * @param config + * @return + */ + public ChatResponse chat(ChatConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/post-chat", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ChatResponse response = new ChatResponse(); + response.parseXML(root); + return response; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * avatarMessage + * + * @param config + * @return + */ + public ChatResponse avatarMessage(AvatarMessage config) { + config.addCredentials(this); + String xml = POST(this.url + "/avatar-message", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ChatResponse response = new ChatResponse(); + response.parseXML(root); + return response; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * getAdmins + * + * @param config + * @return + */ + public List getAdmins(WebMediumConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-" + config.getType() + "-admins", config.toXML()); + List users = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return users; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + UserConfig user = new UserConfig(); + user.parseXML((Element) root.getChildNodes().item(index)); + users.add(user.user); + } + return users; + } + + /** + * getUsers + * + * @param usersCSV + * @return + */ + public List getUsers(String usersCSV) { + UserConfig config = new UserConfig(); + config.user = usersCSV; + config.addCredentials(this); + String xml = POST(this.url + "/get-users", config.toXML()); + List users = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return users; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + Element child = (Element) root.getChildNodes().item(index); + UserConfig userConfig = new UserConfig(); + userConfig.parseXML(child); + users.add(userConfig); + } + return users; + } + + /** + * getPosts + * + * @param config + * @return + */ + public List getPosts(BrowseConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-forum-posts", config.toXML()); + List instances = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return instances; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + ForumPostConfig post = new ForumPostConfig(); + post.parseXML((Element) root.getChildNodes().item(index)); + instances.add(post); + } + return instances; + } + + /** + * getIssues + * + * @param config + * @return + */ + public List getIssues(BrowseConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-issues", config.toXML()); + List instances = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return instances; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + IssueConfig issue = new IssueConfig(); + issue.parseXML((Element) root.getChildNodes().item(index)); + instances.add(issue); + } + return instances; + } + + /** + * getCategories + * + * @param config + * @return + */ + public List getCategories(ContentConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-categories", config.toXML()); + List categories = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return categories; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + ContentConfig category = new ContentConfig(); + category.parseXML((Element) root.getChildNodes().item(index)); + categories.add(category); + } + return categories; + } + + /** + * getTags + * + * @param config + * @return + */ + public List getTags(ContentConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-tags", config.toXML()); + List tags = new ArrayList(); + tags.add(""); + Element root = parse(xml); + if (root == null) { + return tags; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + tags.add(((Element) root.getChildNodes().item(index)).getAttribute("name")); + } + return tags; + } + + /** + * getTemplates + * + * @return + */ + public List getTemplates() { + String xml = GET(this.url + "/get-all-templates"); + List instances = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return instances; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + InstanceConfig instance = new InstanceConfig(); + instance.parseXML((Element) root.getChildNodes().item(index)); + instances.add(instance); + } + return instances; + } + + /** + * getUsers + * + * @param config + * @return + */ + public List getUsers(WebMediumConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-" + config.getType() + "-users", config.toXML()); + List users = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return users; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + UserConfig user = new UserConfig(); + user.parseXML((Element) root.getChildNodes().item(index)); + users.add(user.user); + } + return users; + } + + /** + * saveChannelBotMode + * + * @param config + */ + public void saveChannelBotMode(BotModeConfig config) { + config.addCredentials(this); + POST(this.url + "/save-channel-bot-mode", config.toXML()); + } + + /** + * saveForumBotMode + * + * @param config + */ + public void saveForumBotMode(BotModeConfig config) { + config.addCredentials(this); + POST(this.url + "/save-forum-bot-mode", config.toXML()); + } + + + /** + * saveVoice + * + * @param config + */ + public void saveVoice(VoiceConfig config) { + config.addCredentials(this); + POST(this.url + "/save-voice", config.toXML()); + } + + /** + * saveBotAvatar + * + * @param config + */ + public void saveBotAvatar(InstanceConfig config) { + config.addCredentials(this); + POST(this.url + "/save-bot-avatar", config.toXML()); + } + + /** + * saveAvatarBackground + * + * @param file + * @param config + */ + public void saveAvatarBackground(String file, AvatarMedia config) { + config.addCredentials(this); + POSTIMAGE(this.url + "/save-avatar-background", file, config.name, config.toXML()); + } + + /** + * createAvatarMedia + * + * @param file + * @param config + */ + public void createAvatarMedia(String file, AvatarMedia config) { + config.addCredentials(this); + if ((file.indexOf(".jpg") != -1) || (file.indexOf(".jpeg") != -1)) { + if (config.hd) { + POSTHDIMAGE(this.url + "/create-avatar-media", file, config.name, config.toXML()); + } else { + POSTIMAGE(this.url + "/create-avatar-media", file, config.name, config.toXML()); + } + } else { + POSTFILE(this.url + "/create-avatar-media", file, config.name, config.toXML()); + } + } + + /** + * createGraphicMedia + * + * @param file + * @param config + */ + public void createGraphicMedia(String file, GraphicConfig config) { + config.addCredentials(this); + if ((file.indexOf(".jpg") != -1) || (file.indexOf(".jpeg") != -1)) { + POSTIMAGE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); + } else { + POSTFILE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); + } + } + + /** + * updateIcon + * + * @param file + * @param config + * @param + * @return + */ + public T updateIcon(String file, T config) { + config.addCredentials(this); + String xml = POSTIMAGE(this.url + "/update-" + config.getType() + "-icon", file, "image.jpg", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * updateIcon + * + * @param file + * @param config + * @return + */ + public UserConfig updateIcon(String file, UserConfig config) { + config.addCredentials(this); + String xml = POSTIMAGE(this.url + "/update-user-icon", file, "image.jpg", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = new UserConfig(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * POSTIMAGE + * + * @param url + * @param file + * @param name + * @param xml + * @return + */ + public String POSTIMAGE(String url, String file, String name, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("file: " + file); + System.out.println("XML: " + xml); + } + String result = ""; + return result; + } + + /** + * POSTIMAGE + * + * @param url + * @param bitmap + * @param name + * @param xml + * @return + */ + public String POSTIMAGE(String url, PixelMap bitmap, String name, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + try { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); //===================== - byte[] byte_arr = stream.toByteArray(); - ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); - - MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); - - multipartEntity.addPart("file", fileBody); - multipartEntity.addPart("xml", new StringBody(xml)); - - HttpClient httpclient = new DefaultHttpClient(); - HttpResponse response = null; - - HttpPost httppost = new HttpPost(url); - httppost.setEntity(multipartEntity); - response = httpclient.execute(httppost); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } - - } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public String POSTHDIMAGE(String url, String file, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("file: " + file); - System.out.println("XML: " + xml); - } - String result = ""; - try { -// Bitmap bitmap = loadImage(file, 600, 600); //===================== -// ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); -// byte[] byte_arr = stream.toByteArray(); -// ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); -// -// MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); -// -// multipartEntity.addPart("file", fileBody); -// multipartEntity.addPart("xml", new StringBody(xml)); -// -// HttpClient httpclient = new DefaultHttpClient(); -// HttpResponse response = null; -// -// HttpPost httppost = new HttpPost(url); -// httppost.setEntity(multipartEntity); -// response = httpclient.execute(httppost); -// -// HttpEntity entity = response.getEntity(); -// if (entity != null) { -// result = EntityUtils.toString(entity, HTTP.UTF_8); -// } -// -// if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { -// this.exception = new SDKException("" -// + response.getStatusLine().getStatusCode() -// + " : " + result); -// throw this.exception; -// } + byte[] byte_arr = stream.toByteArray(); + ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); + + MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); + + multipartEntity.addPart("file", fileBody); + multipartEntity.addPart("xml", new StringBody(xml)); + + HttpClient httpclient = new DefaultHttpClient(); + HttpResponse response = null; + + HttpPost httppost = new HttpPost(url); + httppost.setEntity(multipartEntity); + response = httpclient.execute(httppost); + + HttpEntity entity = response.getEntity(); + if (entity != null) { + result = EntityUtils.toString(entity, HTTP.UTF_8); + } + + if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + result); + throw this.exception; + } + + } catch (Exception exception) { + this.exception = new SDKException(exception); + throw this.exception; + } + return result; + } + + /** + * POSTHDIMAGE + * + * @param url + * @param file + * @param name + * @param xml + * @return + */ + public String POSTHDIMAGE(String url, String file, String name, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("file: " + file); + System.out.println("XML: " + xml); + } + String result = ""; + try { } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public String POSTFILE(String url, String path, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("file: " + path); - System.out.println("XML: " + xml); - } - String result = ""; - try { - File file = new File(path); - FileInputStream stream = new FileInputStream(file); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - int read = 0; - byte[] buffer = new byte[4096]; - while ((read = stream.read(buffer)) != -1 ) { - output.write(buffer, 0, read); - } - byte[] byte_arr = output.toByteArray(); - stream.close(); - ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); - - MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); - - multipartEntity.addPart("file", fileBody); - multipartEntity.addPart("xml", new StringBody(xml)); - - HttpClient httpclient = new DefaultHttpClient(); - HttpResponse response = null; + this.exception = new SDKException(exception); + throw this.exception; + } + return result; + } + + /** + * POSTFILE + * + * @param url + * @param path + * @param name + * @param xml + * @return + */ + public String POSTFILE(String url, String path, String name, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("file: " + path); + System.out.println("XML: " + xml); + } + String result = ""; + try { + File file = new File(path); + FileInputStream stream = new FileInputStream(file); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + int read = 0; + byte[] buffer = new byte[4096]; + while ((read = stream.read(buffer)) != -1) { + output.write(buffer, 0, read); + } + byte[] byte_arr = output.toByteArray(); + stream.close(); + ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); + + MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); + + multipartEntity.addPart("file", fileBody); + multipartEntity.addPart("xml", new StringBody(xml)); + + HttpClient httpclient = new DefaultHttpClient(); + HttpResponse response = null; HttpPost httppost = new HttpPost(url); httppost.setEntity(multipartEntity); response = httpclient.execute(httppost); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } + HttpEntity entity = response.getEntity(); + if (entity != null) { + result = EntityUtils.toString(entity, HTTP.UTF_8); + } + + if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + result); + throw this.exception; + } + + } catch (Exception exception) { + this.exception = new SDKException(exception); + throw this.exception; + } + return result; + } + + /** + * loadImage + * + * @param path + * @param reqWidth + * @param reqHeight + * @return + */ + public PixelMap loadImage(String path, int reqWidth, int reqHeight) { + return null; + } + + /** + * getVoice + * + * @param config + * @return + */ + public VoiceConfig getVoice(InstanceConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-voice", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + VoiceConfig voice = new VoiceConfig(); + voice.parseXML(root); + return voice; } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public PixelMap loadImage(String path, int reqWidth, int reqHeight) { -// BitmapFactory.Options options = new BitmapFactory.Options(); //===================== -// options.inJustDecodeBounds = true; -// BitmapFactory.decodeFile(path, options); -// -// int height = options.outHeight; -// int width = options.outWidth; -// options.inPreferredConfig = Bitmap.Config.RGB_565; -// int inSampleSize = 1; -// -// if (height > reqHeight) { -// inSampleSize = Math.round((float)height / (float)reqHeight); -// } -// -// int expectedWidth = width / inSampleSize; -// -// if (expectedWidth > reqWidth) { -// inSampleSize = Math.round((float)width / (float)reqWidth); -// } -// -// options.inSampleSize = inSampleSize; -// options.inJustDecodeBounds = false; -// -// return BitmapFactory.decodeFile(path, options); - return null; - } - - /** - * Return the forum's bot configuration. - */ - public BotModeConfig getForumBotMode(ForumConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-forum-bot-mode", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - BotModeConfig botMode = new BotModeConfig(); - botMode.parseXML(root); - return botMode; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the bot's voice configuration. - */ - public VoiceConfig getVoice(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-voice", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - VoiceConfig voice = new VoiceConfig(); - voice.parseXML(root); - return voice; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the bot's default responses. - */ - public List getDefaultResponses(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-default-responses", config.toXML()); - List defaultResponses = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return defaultResponses; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - defaultResponses.add(((Element)root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); - } - return defaultResponses; - } - - /** - * Return the bot's greetings. - */ - public List getGreetings(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-greetings", config.toXML()); - List greetings = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return greetings; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - greetings.add(((Element)root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); - } - return greetings; - } - - /** - * Search the bot's responses. - */ - public List getResponses(ResponseSearchConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-responses", config.toXML()); - List responses = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return responses; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ResponseConfig response = new ResponseConfig(); - response.parseXML((Element)root.getChildNodes().item(index)); - responses.add(response); - } - return responses; - } - - /** - * Search the bot's conversations. - */ - public List getConversations(ResponseSearchConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-conversations", config.toXML()); - List conversations = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return conversations; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ConversationConfig response = new ConversationConfig(); - response.parseXML((Element)root.getChildNodes().item(index)); - conversations.add(response); - } - return conversations; - } - - /** - * Return the bot's learning configuration. - */ - public LearningConfig getLearning(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-learning", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - LearningConfig learning = new LearningConfig(); - learning.parseXML(root); - return learning; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the list of content for the browse criteria. - * The type defines the content type (one of Bot, Forum, Channel, Domain). - */ - public List browse(Ability ability,BrowseConfig config) { - config.addCredentials(this); - String type = ""; - if (config.type.equals("Bot")) { - type = "/get-instances"; - } else { - type = "/get-" + config.type.toLowerCase() + "s"; - } - String xml = POSTUpdate(ability,this.url + type, config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - WebMediumConfig instance = null; - if (config.type.equals("Bot")) { - instance = new InstanceConfig(); - } else if (config.type.equals("Forum")) { - instance = new ForumConfig(); - } else if (config.type.equals("Channel")) { - instance = new ChannelConfig(); - } else if (config.type.equals("Domain")) { - instance = new DomainConfig(); - } else if (config.type.equals("Avatar")) { - instance = new AvatarConfig(); - } else if (config.type.equals("Script")) { - instance = new ScriptConfig(); - }else if (config.type.equals("Graphic")) { - instance = new GraphicConfig(); - } - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - - /** - * Return the list of media for the avatar. - */ - public List getAvatarMedia(AvatarConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-avatar-media", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - AvatarMedia instance = new AvatarMedia(); - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - - /** - * Return the script source - */ - public ScriptSourceConfig getScriptSource(ScriptConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-script-source", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ScriptSourceConfig script = new ScriptSourceConfig(); - script.parseXML(root); - return script; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create or update script - Save the script source - */ - public void saveScriptSource(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-script-source", config.toXML()); - } - - /** - * Return the source code for a single bot script - */ - public ScriptSourceConfig getBotScriptSource(ScriptSourceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-bot-script-source", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ScriptSourceConfig botScript = new ScriptSourceConfig(); - botScript.parseXML(root); - return botScript; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return a list of the bots scripts - */ - public List getBotScripts(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-bot-scripts", config.toXML()); - List botScripts = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return botScripts; - } - for (int i = 0; i < root.getChildNodes().getLength(); i++) { - ScriptConfig script = new ScriptConfig(); - script.parseXML((Element)root.getChildNodes().item(i)); - botScripts.add(script); - } - return botScripts; - } - /** - * import a script to the bot - */ - - public void importBotScript(ScriptConfig config) { - config.addCredentials(this); - POST(this.url + "/import-bot-script", config.toXML()); - } - - /** - * import a chatlog/response list to the bot - */ - public void importBotLog(ScriptConfig config) { - config.addCredentials(this); - POST(this.url + "/import-bot-log", config.toXML()); - } - - - /** - * Save the bot script source - */ - public void saveBotScriptSource(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-bot-script-source", config.toXML()); - } - - /** - * Delete selected bot script - */ - public void deleteBotScript(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-bot-script", config.toXML()); - } - - /** - * Move up one bot script - */ - public void upBotScript(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/up-bot-script", config.toXML()); - } - - /** - * Move down one bot script - */ - public void downBotScript(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/down-bot-script", config.toXML()); - } - - /** - * Return the list of content types. - */ - public String[] getTypes() { - return types; - } - - /** - * Return the channel types. - */ - public String[] getChannelTypes() { - return channelTypes; - } - - /** - * Return the access mode types. - */ - public String[] getAccessModes() { - return accessModes; - } - - /** - * Return the media access mode types. - */ - public String[] getMediaAccessModes() { - return mediaAccessModes; - } - - /** - * Return the learning mode types. - */ - public String[] getLearningModes() { - return learningModes; - } - - /** - * Return the correction mode types. - */ - public String[] getCorrectionModes() { - return correctionModes; - } - - /** - * Return the bot mode types. - */ - public String[] getBotModes() { - return botModes; - } - - /** - * Return the current connected user. - */ - public UserConfig getUser() { - return user; - } - - /** - * Set the current connected user. - * connect() should be used to validate and connect a user. - */ - public void setUser(UserConfig user) { - this.user = user; - } - - /** - * Return the current domain. - * A domain is an isolated content space. - */ - public DomainConfig getDomain() { - return domain; - } - - /** - * Set the current domain. - * A domain is an isolated content space. - * connect() should be used to validate and connect a domain. - */ - public void setDomain(DomainConfig domain) { - this.domain = domain; - } - - /** - * Return the current application credentials. - */ - public Credentials getCredentials() { - return credentials; - } - - /** - * Set the application credentials. - */ - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - /** - * Return is debugging has been enabled. - */ - public boolean isDebug() { - return debug; - } - - /** - * Enable debugging, debug messages will be logged to System.out. - */ - public void setDebug(boolean debug) { - this.debug = debug; - } - - /** - * Return the last thrown exception. - */ - public SDKException getException() { - return exception; - } - - protected void setException(SDKException exception) { - this.exception = exception; - } - - public String GET(String url) { - if (this.debug) { - System.out.println("GET: " + url); - } - String xml = null; - try { - HttpClient httpClient = new DefaultHttpClient(); - HttpContext localContext = new BasicHttpContext(); - HttpGet httpGet = new HttpGet(url); - HttpResponse response = httpClient.execute(httpGet, localContext); - HttpEntity entity = response.getEntity(); - xml = EntityUtils.toString(entity, HTTP.UTF_8); - - if (response.getStatusLine().getStatusCode() != 200) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + xml); - return ""; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return xml; - } - - public String POST(String url, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - try { - HttpClient httpClient = new DefaultHttpClient(); - HttpContext localContext = new BasicHttpContext(); - HttpPost httpPost = new HttpPost(url); - - StringEntity content = new StringEntity(xml, "utf-8"); - content.setContentType("application/xml"); - httpPost.setEntity(content); - - HttpResponse response = httpClient.execute(httpPost, localContext); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public String POSTUpdate(Ability ability,String url, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - Response response = null; - try { - ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), - new SharedPrefsCookiePersistor(ability)); - OkHttpClient okHttpClient = new OkHttpClient.Builder() - .cookieJar(cookieJar) - .build(); - response = getResponse(okHttpClient, url,xml); - - if ((response.code() != 200) && (response.code() != 204)) { - this.exception = new SDKException(response.code()+""); - throw this.exception; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * getDefaultResponses + * + * @param config + * @return + */ + public List getDefaultResponses(InstanceConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-default-responses", config.toXML()); + List defaultResponses = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return defaultResponses; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + defaultResponses.add(((Element) root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); + } + return defaultResponses; + } + + + /** + * getLearning + * + * @param config + * @return + */ + public LearningConfig getLearning(InstanceConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-learning", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + LearningConfig learning = new LearningConfig(); + learning.parseXML(root); + return learning; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * browse + * + * @param ability + * @param config + * @return + */ + public List browse(Ability ability, BrowseConfig config) { + config.addCredentials(this); + String type = ""; + if (config.type.equals("Bot")) { + type = "/get-instances"; + } else { + type = "/get-" + config.type.toLowerCase() + "s"; + } + String xml = POSTUpdate(ability, this.url + type, config.toXML()); + List instances = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return instances; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + WebMediumConfig instance = null; + if (config.type.equals("Bot")) { + instance = new InstanceConfig(); + } else if (config.type.equals("Forum")) { + instance = new ForumConfig(); + } else if (config.type.equals("Channel")) { + instance = new ChannelConfig(); + } else if (config.type.equals("Domain")) { + instance = new DomainConfig(); + } else if (config.type.equals("Avatar")) { + instance = new AvatarConfig(); + } else if (config.type.equals("Script")) { + instance = new ScriptConfig(); + } else if (config.type.equals("Graphic")) { + instance = new GraphicConfig(); + } + instance.parseXML((Element) root.getChildNodes().item(index)); + instances.add(instance); + } + return instances; + } + + /** + * getAvatarMedia + * + * @param config + * @return + */ + public List getAvatarMedia(AvatarConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-avatar-media", config.toXML()); + List instances = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return instances; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + AvatarMedia instance = new AvatarMedia(); + instance.parseXML((Element) root.getChildNodes().item(index)); + instances.add(instance); + } + return instances; + } + + + /** + * saveScriptSource + * + * @param config + */ + public void saveScriptSource(ScriptSourceConfig config) { + config.addCredentials(this); + POST(this.url + "/save-script-source", config.toXML()); + } + + + /** + * getBotScripts + * + * @param config + * @return + */ + public List getBotScripts(InstanceConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-bot-scripts", config.toXML()); + List botScripts = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return botScripts; + } + for (int i = 0; i < root.getChildNodes().getLength(); i++) { + ScriptConfig script = new ScriptConfig(); + script.parseXML((Element) root.getChildNodes().item(i)); + botScripts.add(script); + } + return botScripts; + } + + + /** + * downBotScript + * + * @param config + */ + public void downBotScript(ScriptSourceConfig config) { + config.addCredentials(this); + POST(this.url + "/down-bot-script", config.toXML()); + } + + /** + * getTypes + * + * @return + */ + public String[] getTypes() { + return types; + } + + /** + * getChannelTypes + * + * @return + */ + public String[] getChannelTypes() { + return channelTypes; + } + + /** + * getAccessModes + * + * @return + */ + public String[] getAccessModes() { + return accessModes; + } + + /** + * getMediaAccessModes + * + * @return + */ + public String[] getMediaAccessModes() { + return mediaAccessModes; + } + + /** + * getUser + * + * @return + */ + public UserConfig getUser() { + return user; + } + + /** + * setUser + * + * @param user + */ + public void setUser(UserConfig user) { + this.user = user; + } + + /** + * getDomain + * + * @return + */ + public DomainConfig getDomain() { + return domain; + } + + /** + * setDomain + * + * @param domain + */ + public void setDomain(DomainConfig domain) { + this.domain = domain; + } + + /** + * getCredentials + * + * @return + */ + public Credentials getCredentials() { + return credentials; + } + + /** + * setCredentials + * + * @param credentials + */ + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + /** + * setDebug + * + * @param debug + */ + public void setDebug(boolean debug) { + this.debug = debug; + } + + /** + * getException + * + * @return + */ + public SDKException getException() { + return exception; + } + + /** + * setException + * + * @param exception + */ + protected void setException(SDKException exception) { + this.exception = exception; + } + + /** + * GET + * + * @param url + * @return + */ + public String GET(String url) { + if (this.debug) { + System.out.println("GET: " + url); + } + String xml = null; + try { + HttpClient httpClient = new DefaultHttpClient(); + HttpContext localContext = new BasicHttpContext(); + HttpGet httpGet = new HttpGet(url); + HttpResponse response = httpClient.execute(httpGet, localContext); + HttpEntity entity = response.getEntity(); + xml = EntityUtils.toString(entity, HTTP.UTF_8); + + if (response.getStatusLine().getStatusCode() != 200) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + xml); + return ""; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + throw this.exception; + } + return xml; + } + + /** + * POST + * + * @param url + * @param xml + * @return + */ + public String POST(String url, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + try { + HttpClient httpClient = new DefaultHttpClient(); + HttpContext localContext = new BasicHttpContext(); + HttpPost httpPost = new HttpPost(url); + + StringEntity content = new StringEntity(xml, "utf-8"); + content.setContentType("application/xml"); + httpPost.setEntity(content); + + HttpResponse response = httpClient.execute(httpPost, localContext); + + HttpEntity entity = response.getEntity(); + if (entity != null) { + result = EntityUtils.toString(entity, HTTP.UTF_8); + } + if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + result); + throw this.exception; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + throw this.exception; + } + return result; + } + + /** + * POSTUpdate + * + * @param ability + * @param url + * @param xml + * @return + */ + public String POSTUpdate(Ability ability, String url, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + Response response = null; + try { + ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), + new SharedPrefsCookiePersistor(ability)); + OkHttpClient okHttpClient = new OkHttpClient.Builder() + .cookieJar(cookieJar) + .build(); + response = getResponse(okHttpClient, url, xml); + + if ((response.code() != 200) && (response.code() != 204)) { + this.exception = new SDKException(response.code() + ""); + throw this.exception; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } // this.exception = new SDKException(exception); // throw this.exception; - } - return response.body().toString(); - } - - /** - * This method is used to get cookies from response - * - * @param client OkHttpClient to get cookies from response - * @param url Http URL - */ - public Response getResponse(OkHttpClient client, String url, String xml) { - // code request code here - MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); - String requestBody = xml; - Request request = new Request.Builder() - .url(url) - .post(RequestBody.create(mediaType, requestBody)) - .build(); - Call call = client.newCall(request); - try { - Response response = call.execute(); - return response; - } catch (IOException e) { - e.printStackTrace(); - } -// call.enqueue(new Callback() { -// @Override -// public void onFailure(Call call, IOException exception) { -// } -// -// @Override -// public void onResponse(Call call, Response response) { -// if (response != null && response.body() != null) { -// List cookieList = response.headers("Set-Cookie"); -// StringBuilder stringBuilder = new StringBuilder(); -// if (cookieList.size() > 0) { -// for (String cookie : cookieList) { -// stringBuilder.append(cookie).append(","); -// } -// } -// content[0] = response.body().toString(); -// } -// } -// }); - return null; - } - - public Element parse(String xml) { - if (this.debug) { - System.out.println(xml); - } - Document dom = null; - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource source = new InputSource(); - source.setCharacterStream(new StringReader(xml)); - dom = builder.parse(source); - return dom.getDocumentElement(); - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } -// this.exception = new SDKException(exception.getMessage(), exception); -// throw this.exception; - return null; - } - } + } + return response.body().toString(); + } + + /** + * This method is used to get cookies from response + * + * @param client OkHttpClient to get cookies from response + * @param url Http URL + */ + public Response getResponse(OkHttpClient client, String url, String xml) { + // code request code here + MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); + String requestBody = xml; + Request request = new Request.Builder() + .url(url) + .post(RequestBody.create(mediaType, requestBody)) + .build(); + Call call = client.newCall(request); + try { + Response response = call.execute(); + return response; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * parse + * + * @param xml + * @return + */ + public Element parse(String xml) { + if (this.debug) { + System.out.println(xml); + } + return (Element) new ShapeElement(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BaseAbility.java similarity index 85% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BaseAbility.java index 974e7041f5a8b8f9d1120d99d79dfbaa4907e0b4..c659c6a66288d1f3dd8b6623b662c74d8d26148d 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BaseAbility.java @@ -1,4 +1,4 @@ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/BotSearchAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/BotSearchAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java index fb325e52b0c6a6ae7a3240f806bb52ed2b3d1067..a113dbe2de311c50161407295b3e6911e3a34f63 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/BotSearchAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java @@ -16,9 +16,9 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.listener.SelectListener; import ohos.aafwk.content.Intent; import ohos.agp.components.Text; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java similarity index 86% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index f4747945713e38ac9c3c0959a28c4f5c90e5bbcc..94c3ae08cb982e617360bf18c89f16dd70405113 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java @@ -16,28 +16,8 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpGetImageAction; -import org.botlibre.sdk.activityy.actions.HttpGetVideoAction; -import org.botlibre.sdk.activityy.adapter.EmoteAdapter; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.VoiceConfig; -import org.botlibre.sdk.provider.ChatListProvicer; -import org.botlibre.sdk.util.FileUtils; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.PreferencesUtils; -import org.botlibre.sdk.util.ResUtils; -import org.botlibre.sdk.util.ShapeUtils; -import org.botlibre.sdk.util.TextStream; -import org.botlibre.sdk.util.ToastUtils; -import org.botlibre.sdk.util.Utils; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; @@ -78,15 +58,30 @@ import ohos.media.audio.AudioCapturerInfo; import ohos.media.audio.AudioManager; import ohos.media.audio.AudioRemoteException; import ohos.media.audio.AudioStreamInfo; -import ohos.media.common.Source; import ohos.media.image.PixelMap; import ohos.media.player.Player; import ohos.multimodalinput.event.TouchEvent; import ohos.security.SystemPermission; import ohos.utils.PacMap; -import ohos.utils.net.Uri; import ohos.utils.zson.ZSONArray; import ohos.utils.zson.ZSONObject; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.ability.adapter.EmoteAdapter; +import org.botlibre.sdk.config.AvatarConfig; +import org.botlibre.sdk.config.BrowseConfig; +import org.botlibre.sdk.config.ChatConfig; +import org.botlibre.sdk.config.ChatResponse; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.VoiceConfig; +import org.botlibre.sdk.provider.ChatListProvicer; +import org.botlibre.sdk.util.FileUtils; +import org.botlibre.sdk.util.LogUtils; +import org.botlibre.sdk.util.PreferencesUtils; +import org.botlibre.sdk.util.ResUtils; +import org.botlibre.sdk.util.ShapeUtils; +import org.botlibre.sdk.util.TextStream; +import org.botlibre.sdk.util.ToastUtils; import java.io.IOException; import java.io.StringWriter; @@ -1370,8 +1365,6 @@ public class ChatAbility extends LibreAbility { } public void resetAvatar(AvatarConfig config) { - HttpGetImageAction.fetchImage(this, config.avatar, this.bigImage); - HttpGetImageAction.fetchImage(this, config.avatar, (Image) findComponentById(ResourceTable.Id_responseImageView)); } public void micConfiguration() { @@ -1497,8 +1490,6 @@ public class ChatAbility extends LibreAbility { LogUtils.sop("Error: " + ignore.getMessage()); } } - //needs when calling "sleep" or the its not going to let the mic off - //also to stop the mic until the bot finish the sentence try { stopListening(); this.response = response; @@ -1529,21 +1520,13 @@ public class ChatAbility extends LibreAbility { final String text = response.message; if (text == null) { - //listContainer.invalidateViews(); -// if (listContainer.getChildCount() > 2) { -// listContainer.setSelection(list.getCount() - 2); -// } + beginListening(); return; } messages.add(response); chatProvider.notifyDataChanged(); -// listContainer.invalidateViews(); -// if (listContainer.getCount() > 2) { -// listContainer.setSelection(list.getCount() - 2); -// } - - String html = Utils.linkHTML(text); + String html =""; if (stateLayouts == 3 || stateLayouts == 4) { ToastUtils.show(ability, html); } @@ -1554,78 +1537,11 @@ public class ChatAbility extends LibreAbility { boolean talk = (text.trim().length() > 0) && (MainAbility.deviceVoice || (this.response.speech != null && this.response.speech.length() > 0)); if (MainAbility.sound && talk) { if (!MainAbility.disableVideo && !videoError && this.response.isVideo() && this.response.isVideoTalk()) { - -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// try { -// mp.setLooping(true); -// if (!MainAbility.deviceVoice) { -// // Voice audio -// if (MainAbility.online) { -// speechPlayer = playAudio(response.speech, false, false, false); -// speechPlayer.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// mp.release(); -// videoView.post(new Runnable() { -// public void run() { -// cycleVideo(response); -// } -// }); -// runOnUiThread(new Runnable() { -// public void run() { -// if (!music) { -// beginListening(); -// } -// } -// }); -// } -// }); -// -// speechPlayer.play(); -// } -// } else { -// HashMap params = new HashMap(); -// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); -// -// tts.speakText(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); -// } -// } catch (Exception exception) { -// LogUtils.sop(exception.getMessage()); -// } -// } -// }); - playVideo(this.response.avatarTalk, false); } else if (talk) { -// if (!MainAbility.deviceVoice) { -// // Voice audio -// if (MainAbility.online) { -// playAudio(this.response.speech, false, false, true); -// } -// } else { -// HashMap params = new HashMap(); -// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); -// -// this.tts.speakText(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); -// } + } } else if (talk && (!MainAbility.disableVideo && !videoError && this.response.isVideo() && this.response.avatarTalk != null)) { -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// videoView.setOnCompletionListener(null); -// cycleVideo(response); -// } -// }); - playVideo(this.response.avatarTalk, false); - //handler.sendEvent(BEGIN_LISTENING); + } else { //handler.sendEvent(BEGIN_LISTENING); @@ -1649,152 +1565,8 @@ public class ChatAbility extends LibreAbility { } - public void playVideo(String video, boolean loop) { -// if (loop) { -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(true); -// } -// }); -// } -// try { -// Uri videoUri = HttpGetVideoAction.fetchVideo(this, video); -// if (videoUri == null) { -// if (MainAbility.online) { -// videoUri = Uri.parse(MainAbility.connection.fetchImage(video).toURI().toString()); -// } -// } -// videoView.setVideoURI(videoUri); -// videoView.start(); -// } catch (Exception exception) { -// Log.wtf(exception.toString(), exception); -// } - } - public void cycleVideo(final ChatResponse response) { -// if ((response.avatar2 == null || response.avatar3 == null || response.avatar4 == null || response.avatar5 == null) -// || (response.avatar2.isEmpty() || response.avatar3.isEmpty() || response.avatar4.isEmpty() || response.avatar5.isEmpty()) -// || (response.avatar.equals(response.avatar2) && response.avatar2.equals(response.avatar3) -// && response.avatar3.equals(response.avatar4) && response.avatar4.equals(response.avatar5))) { -// playVideo(response.avatar, true); -// return; -// } -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// cycleVideo(response); -// } -// }); -// int value = random.nextInt(5); -// String avatar = response.avatar; -// switch (value) { -// case 1: -// avatar = response.avatar2; -// break; -// case 2: -// avatar = response.avatar3; -// break; -// case 3: -// avatar = response.avatar5; -// break; -// case 14: -// avatar = response.avatar4; -// break; -// } -// -// try { -// Uri videoUri = HttpGetVideoAction.fetchVideo(this, avatar); -// if (videoUri == null) { -// if (MainAbility.online) { -// videoUri = Uri.parse(MainAbility.connection.fetchImage(avatar).toURI().toString()); -// } -// } -// videoView.setVideoURI(videoUri); -// videoView.start(); -// } catch (Exception exception) { -// LogUtils.sop(exception.toString()); -// } - } - - public Player playAudio(String audio, boolean loop, boolean cache, boolean start) { - try { - Uri audioUri = null; - if (cache) { - audioUri = HttpGetVideoAction.fetchVideo(this, audio); - } - if (audioUri == null) { - audioUri = Uri.parse(MainAbility.connection.fetchImage(audio).toURI().toString()); - } - final Player audioPlayer = new Player(ability); - audioPlayer.setSource(new Source(String.valueOf(audioUri))); - audioPlayer.setPlayerCallback(new Player.IPlayerCallback() { - @Override - public void onPrepared() { - - } - - @Override - public void onMessage(int i, int i1) { - - } - - @Override - public void onError(int errorType, int errorCode) { - LogUtils.sop("errorCode" + errorCode); - audioPlayer.stop(); - audioPlayer.release(); - } - @Override - public void onResolutionChanged(int i, int i1) { - - } - - @Override - public void onPlayBackComplete() { - audioPlayer.release(); - //handler.sendEvent(BEGIN_LISTENING); - - } - - @Override - public void onRewindToComplete() { - - } - - @Override - public void onBufferingChange(int i) { - - } - - @Override - public void onNewTimedMetaData(Player.MediaTimedMetaData mediaTimedMetaData) { - - } - - @Override - public void onMediaTimeIncontinuity(Player.MediaTimeInfo mediaTimeInfo) { - - } - }); - audioPlayer.prepare(); - audioPlayer.enableSingleLooping(loop); - if (start) { - audioPlayer.play(); - } - return audioPlayer; - } catch (Exception exception) { - LogUtils.sop(exception.toString()); - return null; - } - } public ChatResponse getResponse() { return response; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility2.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility2.java similarity index 88% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility2.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility2.java index daf3b452709c6af4f4f58230f7de33ee42f6b5fb..2424bd3a447a0689e380236d2031810655964ef0 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility2.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility2.java @@ -16,30 +16,8 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpGetImageAction; -import org.botlibre.sdk.activityy.actions.HttpGetVideoAction; -import org.botlibre.sdk.activityy.adapter.CommandAdapter; -import org.botlibre.sdk.activityy.adapter.EmoteAdapter; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.VoiceConfig; -import org.botlibre.sdk.provider.ChatListProvicer; -import org.botlibre.sdk.util.ApplicationJumpUtil; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.PreferencesUtils; -import org.botlibre.sdk.util.ResUtils; -import org.botlibre.sdk.util.ShapeUtils; -import org.botlibre.sdk.util.StringUtils; -import org.botlibre.sdk.util.TextStream; -import org.botlibre.sdk.util.ToastUtils; -import org.botlibre.sdk.util.Utils; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; @@ -78,16 +56,33 @@ import ohos.media.audio.AudioCapturerInfo; import ohos.media.audio.AudioManager; import ohos.media.audio.AudioRemoteException; import ohos.media.audio.AudioStreamInfo; -import ohos.media.common.Source; import ohos.media.image.PixelMap; import ohos.media.player.Player; import ohos.multimodalinput.event.TouchEvent; import ohos.security.SystemPermission; import ohos.utils.IntentConstants; import ohos.utils.PacMap; -import ohos.utils.net.Uri; import ohos.utils.zson.ZSONArray; import ohos.utils.zson.ZSONObject; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.ability.adapter.CommandAdapter; +import org.botlibre.sdk.ability.adapter.EmoteAdapter; +import org.botlibre.sdk.config.AvatarConfig; +import org.botlibre.sdk.config.BrowseConfig; +import org.botlibre.sdk.config.ChatConfig; +import org.botlibre.sdk.config.ChatResponse; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.VoiceConfig; +import org.botlibre.sdk.provider.ChatListProvicer; +import org.botlibre.sdk.util.ApplicationJumpUtil; +import org.botlibre.sdk.util.LogUtils; +import org.botlibre.sdk.util.PreferencesUtils; +import org.botlibre.sdk.util.ResUtils; +import org.botlibre.sdk.util.ShapeUtils; +import org.botlibre.sdk.util.StringUtils; +import org.botlibre.sdk.util.TextStream; +import org.botlibre.sdk.util.ToastUtils; import java.io.StringWriter; import java.util.ArrayList; @@ -437,49 +432,6 @@ public class ChatAbility2 extends LibreAbility { //ApplicationJumpUtil.startAppFromPackageName(this,"com.example.recyclerviewswipedismiss"); // 通过包名调用应用 ApplicationJumpUtil.startAppFromPackageName(this,"com.example.summaryjs"); // 通过包名调用应用 break; - case "instagram": - case "snapchat": - case "youtube": - case "facebook": - case "messenger": - case "whatsapp": - case "chrome": - case "opera": - case "drive": - case "outlook": - case "yahoo": - case "gmail": - case "inbox": - case "shopify": - case "flashlight": - case "uber": - case "uber eats": - case "ubereats": - case "pinterest": - case "etsy": - case "shazam": - case "flipp": - case "urban spoon": - case "urbanspoon": - case "yelp": - case "trip advisor": - case "tripadvisor": - case "zomato": - case "amazon": - case "kindle": - case "paypal": - case "pay pal": - case "audible": - case "aliexpress": - case "ali express": - case "groupon": - case "group on": - case "acrobat": - case "photoshop": - case "lightroom": - case "candy crush": - reply = "Opening " + StringUtils.toUpperFirstCode(msg); - break; default: reply = msg; break; @@ -1751,8 +1703,6 @@ public class ChatAbility2 extends LibreAbility { } public void resetAvatar(AvatarConfig config) { - HttpGetImageAction.fetchImage(this, config.avatar, this.bigImage); - HttpGetImageAction.fetchImage(this, config.avatar, (Image) findComponentById(ResourceTable.Id_responseImageView)); } public void micConfiguration() { @@ -1924,7 +1874,7 @@ public class ChatAbility2 extends LibreAbility { // listContainer.setSelection(list.getCount() - 2); // } - String html = Utils.linkHTML(text); + String html = "";//Utils.linkHTML(text) if (stateLayouts == 3 || stateLayouts == 4) { ToastUtils.show(ability, html); } @@ -1935,81 +1885,11 @@ public class ChatAbility2 extends LibreAbility { boolean talk = (text.trim().length() > 0) && (MainAbility.deviceVoice || (this.response.speech != null && this.response.speech.length() > 0)); if (MainAbility.sound && talk) { if (!MainAbility.disableVideo && !videoError && this.response.isVideo() && this.response.isVideoTalk()) { - -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// try { -// mp.setLooping(true); -// if (!MainAbility.deviceVoice) { -// // Voice audio -// if (MainAbility.online) { -// speechPlayer = playAudio(response.speech, false, false, false); -// speechPlayer.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// mp.release(); -// videoView.post(new Runnable() { -// public void run() { -// cycleVideo(response); -// } -// }); -// runOnUiThread(new Runnable() { -// public void run() { -// if (!music) { -// beginListening(); -// } -// } -// }); -// } -// }); -// -// speechPlayer.play(); -// } -// } else { -// HashMap params = new HashMap(); -// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); -// -// tts.speakText(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); -// } -// } catch (Exception exception) { -// LogUtils.sop(exception.getMessage()); -// } -// } -// }); - playVideo(this.response.avatarTalk, false); } else if (talk) { -// if (!MainAbility.deviceVoice) { -// // Voice audio -// if (MainAbility.online) { -// playAudio(this.response.speech, false, false, true); -// } -// } else { -// HashMap params = new HashMap(); -// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); -// -// this.tts.speakText(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); -// } } } else if (talk && (!MainAbility.disableVideo && !videoError && this.response.isVideo() && this.response.avatarTalk != null)) { -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// videoView.setOnCompletionListener(null); -// cycleVideo(response); -// } -// }); - playVideo(this.response.avatarTalk, false); - //handler.sendEvent(BEGIN_LISTENING); } else { - //handler.sendEvent(BEGIN_LISTENING); } } catch (Exception exception) { LogUtils.sop(exception.getMessage()); @@ -2029,154 +1909,6 @@ public class ChatAbility2 extends LibreAbility { super.onInactive(); } - - public void playVideo(String video, boolean loop) { -// if (loop) { -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(true); -// } -// }); -// } -// try { -// Uri videoUri = HttpGetVideoAction.fetchVideo(this, video); -// if (videoUri == null) { -// if (MainAbility.online) { -// videoUri = Uri.parse(MainAbility.connection.fetchImage(video).toURI().toString()); -// } -// } -// videoView.setVideoURI(videoUri); -// videoView.start(); -// } catch (Exception exception) { -// Log.wtf(exception.toString(), exception); -// } - } - - public void cycleVideo(final ChatResponse response) { -// if ((response.avatar2 == null || response.avatar3 == null || response.avatar4 == null || response.avatar5 == null) -// || (response.avatar2.isEmpty() || response.avatar3.isEmpty() || response.avatar4.isEmpty() || response.avatar5.isEmpty()) -// || (response.avatar.equals(response.avatar2) && response.avatar2.equals(response.avatar3) -// && response.avatar3.equals(response.avatar4) && response.avatar4.equals(response.avatar5))) { -// playVideo(response.avatar, true); -// return; -// } -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// cycleVideo(response); -// } -// }); -// int value = random.nextInt(5); -// String avatar = response.avatar; -// switch (value) { -// case 1: -// avatar = response.avatar2; -// break; -// case 2: -// avatar = response.avatar3; -// break; -// case 3: -// avatar = response.avatar5; -// break; -// case 14: -// avatar = response.avatar4; -// break; -// } -// -// try { -// Uri videoUri = HttpGetVideoAction.fetchVideo(this, avatar); -// if (videoUri == null) { -// if (MainAbility.online) { -// videoUri = Uri.parse(MainAbility.connection.fetchImage(avatar).toURI().toString()); -// } -// } -// videoView.setVideoURI(videoUri); -// videoView.start(); -// } catch (Exception exception) { -// LogUtils.sop(exception.toString()); -// } - } - - public Player playAudio(String audio, boolean loop, boolean cache, boolean start) { - try { - Uri audioUri = null; - if (cache) { - audioUri = HttpGetVideoAction.fetchVideo(this, audio); - } - if (audioUri == null) { - audioUri = Uri.parse(MainAbility.connection.fetchImage(audio).toURI().toString()); - } - final Player audioPlayer = new Player(ability); - audioPlayer.setSource(new Source(String.valueOf(audioUri))); - audioPlayer.setPlayerCallback(new Player.IPlayerCallback() { - @Override - public void onPrepared() { - - } - - @Override - public void onMessage(int i, int i1) { - - } - - @Override - public void onError(int errorType, int errorCode) { - LogUtils.sop("errorCode" + errorCode); - audioPlayer.stop(); - audioPlayer.release(); - } - - @Override - public void onResolutionChanged(int i, int i1) { - - } - - @Override - public void onPlayBackComplete() { - audioPlayer.release(); - //handler.sendEvent(BEGIN_LISTENING); - - } - - @Override - public void onRewindToComplete() { - - } - - @Override - public void onBufferingChange(int i) { - - } - - @Override - public void onNewTimedMetaData(Player.MediaTimedMetaData mediaTimedMetaData) { - - } - - @Override - public void onMediaTimeIncontinuity(Player.MediaTimeInfo mediaTimeInfo) { - - } - }); - audioPlayer.prepare(); - audioPlayer.enableSingleLooping(loop); - if (start) { - audioPlayer.play(); - } - return audioPlayer; - } catch (Exception exception) { - LogUtils.sop(exception.toString()); - return null; - } - } - public ChatResponse getResponse() { return response; } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java index 0fbafdfde93430b234ed7a2b82d0ce7d4ae7cd58..a27cd18b1299f79d087d4d640da74ea508ca3cc2 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java @@ -16,10 +16,10 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpCreateUserAction; +import org.botlibre.sdk.ability.actions.HttpCreateUserAction; import org.botlibre.sdk.config.UserConfig; import org.botlibre.sdk.util.ResUtil; import ohos.aafwk.content.Intent; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java index 867233c8dcd3a0c90f17c57333ca6f8f7c46862f..6482acb8bedd2ecf15941cb13b60b6e39e441ea2 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; /** * A convenience enum of different emotional states. diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/HelpAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java similarity index 95% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/HelpAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index 4d34816546b125835bef140d490e966018b9d0c5..3fe761758467de39c6a7641b848c68d56e6431c3 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/HelpAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java @@ -16,13 +16,13 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpFetchAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; -import org.botlibre.sdk.activityy.actions.HttpResultAction; +import org.botlibre.sdk.ability.actions.HttpFetchAction; +import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; +import org.botlibre.sdk.ability.actions.HttpResultAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.ChannelConfig; import org.botlibre.sdk.config.ForumConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java similarity index 63% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index d9f23297624c7aa0919fae53bc5e722999b24c6b..772f19f30b127edc6d52ddded8306a817a90ab11 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -16,31 +16,24 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.util.AsyncTask; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; -public abstract class HttpAction extends AsyncTask { - protected Ability ability; - protected Exception exception; - - public HttpAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } +/** + * Generic Ability for common behavior. + */ +public abstract class LibreAbility extends Ability { /** - * 启动activity + * reInitialize + * + * @param ability + * @param name */ public void startOpenAbility(Ability ability, String name) { Intent intent = new Intent(); @@ -50,9 +43,16 @@ public abstract class HttpAction extends AsyncTask { .withAbilityName(name) .build(); intent.setOperation(operation); - ability.startAbility(intent); + startAbility(intent); } + /** + * reInitialize + * + * @param ability + * @param name + * @return intent + */ public Intent getIntent(Ability ability, String name) { Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder() @@ -65,16 +65,26 @@ public abstract class HttpAction extends AsyncTask { } /** - * 启动activity + * runUI + * + * @param runnable */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); + public static void runUI(Runnable runnable) { + EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); + eventHandler.postSyncTask(runnable); + + } + + /** + * 子线程执行任务 + * + * @param runnable + */ + public static void runWork(Runnable runnable) { + //开启线程 + EventRunner runner = EventRunner.create(true); + EventHandler eventHandler = new EventHandler(runner); + eventHandler.postTask(runnable, 0, EventHandler.Priority.IMMEDIATE); + } -} \ No newline at end of file +} diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index e17e777adae6bd2db8058318775c2eb32db774df..33a4ee3074e9c89fa4f42ef1d7ad0ef8cc1c4637 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java @@ -15,16 +15,16 @@ * limitations under the License. * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import java.util.ArrayList; import java.util.List; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpAction; -import org.botlibre.sdk.activityy.actions.HttpGetTemplatesAction; -import org.botlibre.sdk.activityy.avatar.AvatarSelection; +import org.botlibre.sdk.ability.actions.HttpAction; +import org.botlibre.sdk.ability.actions.HttpGetTemplatesAction; +import org.botlibre.sdk.ability.avatar.AvatarSelection; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; import org.botlibre.sdk.micro.MicroConnection; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java similarity index 92% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 3185099d6ec5187c8bb6e00699b21b68a700fb6c..24ff09cab077a0aae4e07087baf3860e46e49c14 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -16,15 +16,14 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpConnectAction; -import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.TextField; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.config.UserConfig; /** * Ability for user login. @@ -55,8 +54,6 @@ public class LoginAbility extends LibreAbility implements Component.ClickedListe UserConfig config = new UserConfig(); config.user = user; config.password = password; - HttpConnectAction action = new HttpConnectAction(this, config, true); -// action.execute(); } public void signUp() { diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/MicConfigAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java similarity index 99% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/MicConfigAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java index f647130764e407e0672e229f52c498a3ac1db824..4b92cafe10fd7743ff631fcdb55de3ec1d562d5e 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/MicConfigAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java @@ -15,7 +15,7 @@ * limitations under the License. * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import com.czt.mp3recorder.MP3Recorder; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/SearchAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/SearchAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java index 2eecf1a58e97f54b3842f35846a22cd9744d213e..e116182a62d837c446d1da56b49f6bcc61471cf6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/SearchAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java @@ -16,17 +16,8 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpBrowseCategoriesAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; -import org.botlibre.sdk.activityy.dialog.SearchDialogBuilder; -import org.botlibre.sdk.activityy.listener.SelectListener; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import org.botlibre.sdk.util.ResUtil; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Checkbox; @@ -45,6 +36,14 @@ import ohos.agp.window.service.Display; import ohos.agp.window.service.DisplayAttributes; import ohos.agp.window.service.DisplayManager; import ohos.data.preferences.Preferences; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; +import org.botlibre.sdk.ability.dialog.SearchDialogBuilder; +import org.botlibre.sdk.ability.listener.SelectListener; +import org.botlibre.sdk.config.BrowseConfig; +import org.botlibre.sdk.util.PreferencesUtils; +import org.botlibre.sdk.util.ResUtil; import java.util.Optional; @@ -356,8 +355,6 @@ public abstract class SearchAbility extends LibreAbility implements SelectListen } public void browseCategories() { - HttpBrowseCategoriesAction action = new HttpBrowseCategoriesAction(this, getType(), MainAbility.browsing); -// action.execute(); } @Override diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java similarity index 90% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java index ea8995994363c7013c6660b7e822e3534dc72fb1..f1ebad2573fdfdf6731837f15f1601afbb4532f1 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java @@ -1,11 +1,11 @@ -/* +/** * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain an copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -13,14 +13,14 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.util.AsyncTask; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; -public abstract class HttpAction extends AsyncTask { +public abstract class HttpAction extends AsyncTask { protected Ability ability; protected Exception exception; @@ -37,7 +37,10 @@ public abstract class HttpAction extends AsyncTask { } /** - * 启动activity + * startOpenAbility + * + * @param ability + * @param name */ public void startOpenAbility(Ability ability, String name) { Intent intent = new Intent(); @@ -62,7 +65,11 @@ public abstract class HttpAction extends AsyncTask { } /** - * 启动activity + * startOpenAbilityForResult + * + * @param ability + * @param name + * @param requestCode */ public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { Intent intent = new Intent(); diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java index cd19265d3126450c04e4f83cffc38a7261debd9a..07ab9d620cf25e2d854134a7a68e484704c519c4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.WebMediumConfig; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelFileAttachmentAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelFileAttachmentAction.java index 075e27d04afc91bdaa00e48dae011b509fef58bc..10d8ba353dc581e6ba82f998e130cd3b97c8d051 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelFileAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelImageAttachmentAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelImageAttachmentAction.java index cf874a13752d47400679af080a94b9ccd29a08cd..52f21351d8c71453369dfb422041544acca447df 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateChannelImageAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateForumPostAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateForumPostAction.java index c452ff0f9df95e9f895e81ad192ed7213492f4f7..6bdb577e7ef3ded32caed03bd1ff0cce17e63d9a 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java index f67cdd55bc47111f5f6fdcd0f181c4c9a68552f2..9a62ce614d0c85347b230f20d7109e2152162c23 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerFileAttachmentAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerFileAttachmentAction.java index 5aa47a9e544067a0fce951ab5dcfb5c1f6a0ce9b..18f8c053134ddcec820b4da8a35dae99b4a92bd1 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerFileAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerImageAttachmentAction.java similarity index 96% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerImageAttachmentAction.java index 5a02f496400c43e900b6bbcc23d26a615b647ef7..dd17bfa37ed020c91d86d206a3cab2a91abc3dc9 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateIssueTrackerImageAttachmentAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.MediaConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java index 0b94d353ea519d0f02506a6594146a2876aa19ab..18ff0673a175067bbddea811b127bb7fe77e792a 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteForumPostAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteForumPostAction.java index c2b719f086169b95e0c9bd7fb34dcd6870970c91..2064883e58e361555e972249f0858c1056857ba6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpDeleteForumPostAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.ForumPostConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java similarity index 86% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java index e3a08dd0f73f2478d254d17929132dcd7eff3971..d0e27b9e029e0249592174751b19031cbe9352f1 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java @@ -16,13 +16,18 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.*; -import org.botlibre.sdk.util.PreferencesUtils; import ohos.aafwk.ability.Ability; import ohos.data.preferences.Preferences; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.config.BrowseConfig; +import org.botlibre.sdk.config.ChannelConfig; +import org.botlibre.sdk.config.DomainConfig; +import org.botlibre.sdk.config.ForumConfig; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.WebMediumConfig; +import org.botlibre.sdk.util.PreferencesUtils; public class HttpFetchAction extends HttpUIResultAction { WebMediumConfig config; @@ -86,8 +91,6 @@ public class HttpFetchAction extends HttpUIResultAction { // childAbility = LiveChatAbility.class; } else if (this.config instanceof InstanceConfig) { // childAbility = ChatAbility.class; - HttpGetVoiceAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); -// action.execute(); } else if (this.config instanceof DomainConfig) { MainAbility.connection.setDomain((DomainConfig)this.config); MainAbility.domain = (DomainConfig)this.config; @@ -103,10 +106,7 @@ public class HttpFetchAction extends HttpUIResultAction { MainAbility.graphicCategories = null; MainAbility.type = MainAbility.defaultType; -// Intent intent = new Intent(this.ability, MainAbility.class); -// intent.setFlags(Intent.FLAG_Ability_NEW_TASK); -// intent.setFlags(Intent.FLAG_Ability_CLEAR_TOP); -// this.ability.startAbility(intent); + startOpenAbility(this.ability,MainAbility.class.getName()); return; } else if (this.config instanceof ForumConfig) { @@ -123,8 +123,6 @@ public class HttpFetchAction extends HttpUIResultAction { } } else { if (this.config instanceof InstanceConfig) { - HttpGetVoiceAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); -// action.execute(); } } startOpenAbility(this.ability,childAbility.getName()); diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java index e0ef846b3a366a15c2f7175e0d617dbf16ac78d6..60e055ff9652220789ea2f35446a833013264940 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java index 876e4f00d97462425debd6f85421e70f670742cc..6222aeb7081223e23c9b016988fd98557e0e34ea 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java similarity index 97% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java index 7859eeab096d36455c99abd8029e5de02cfec841..9e2aff1ba6938c2632039624bd30bdbd13535388 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java similarity index 99% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java index 710b66f9925d214f033f207c1ee90d339fbc801d..d9eb94280adbd2a4b22908c51895ae16ff014009 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.BrowseConfig; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java similarity index 97% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java index 078f1ed08c11e1be3798303dfe8282dd59983108..40e01a437282e334daf74a2f3f02e0b1d7225302 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.InstanceConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java index 8162d98286151a7c0727c06c60b44a218dcf6ed5..09f2164cca848c27379a0ee2fcad425fd34291e4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import java.util.List; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java similarity index 97% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java index 2a8e59efd665ad22441d81beda15829da0519229..cf41f9c81aefcfb292699e84e16057d6138f270b 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java similarity index 98% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java index 489c48c588cf8d894814ccf66f708bbcb309620e..715858b5a3395021ca730f3bda01a5cd45ab8a27 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java similarity index 98% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java index 272969d74471a4ceaf9f84ee2d50d2d06850d58b..f0093abe4928264a0e779a964ff7c836f7cbb33c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java similarity index 98% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java index 364bee86c2792588d97d9e6be34525b4b4d93301..db20c9023af46e0008fb620fd18187d4a867c22d 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/CommandAdapter.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/CommandAdapter.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/CommandAdapter.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/CommandAdapter.java index e4f067311ab6af489e7f21709b2ff02ad91ee599..5220844068684f8f28760fb46ecf3de7ff6f0a36 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/CommandAdapter.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/CommandAdapter.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.adapter; +package org.botlibre.sdk.ability.adapter; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; @@ -33,7 +33,7 @@ import java.util.List; * @since 2021-05-10 */ public class CommandAdapter extends BaseItemProvider { - private final Ability mActivity; + private final Ability mAbility; private final LayoutScatter mInflater; private final List item; @@ -44,7 +44,7 @@ public class CommandAdapter extends BaseItemProvider { * @param item item */ public CommandAdapter(Ability ability, List item) { - mActivity = ability; + mAbility = ability; this.item = item; mInflater = LayoutScatter.getInstance(ability); } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/EmoteAdapter.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/EmoteAdapter.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/EmoteAdapter.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/EmoteAdapter.java index 1ba73463a272792bc13fd564f5e46402ea66f455..b73f21ae2a337f4bab77739657562e47c3297abb 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/EmoteAdapter.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/EmoteAdapter.java @@ -13,10 +13,10 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.adapter; +package org.botlibre.sdk.ability.adapter; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.EmotionalState; +import org.botlibre.sdk.ability.EmotionalState; import ohos.aafwk.ability.Ability; import ohos.agp.components.BaseItemProvider; import ohos.agp.components.Component; @@ -35,7 +35,7 @@ import java.util.Locale; * @since 2021-05-10 */ public class EmoteAdapter extends BaseItemProvider { - private final Ability mActivity; + private final Ability mability; private final LayoutScatter mInflater; private final List item; @@ -46,7 +46,7 @@ public class EmoteAdapter extends BaseItemProvider { * @param item item */ public EmoteAdapter(Ability ability, List item) { - mActivity = ability; + mability = ability; this.item = item; mInflater = LayoutScatter.getInstance(ability); } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java index 0a708de062101d0f440fbab96dd0eb7051bd493d..6b6e5f7a5b4508551fdbe969d3169da9981da5e5 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.adapter; +package org.botlibre.sdk.ability.adapter; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; @@ -30,7 +30,7 @@ import ohos.agp.components.Text; * @since 2021-05-10 */ public class SpinnerAdapter extends BaseItemProvider { - private final Ability mActivity; + private final Ability mAbility; private final LayoutScatter mInflater; private final String[] types; @@ -41,7 +41,7 @@ public class SpinnerAdapter extends BaseItemProvider { * @param types types */ public SpinnerAdapter(Ability ability, String[] types) { - mActivity = ability; + mAbility = ability; this.types = types; mInflater = LayoutScatter.getInstance(ability); } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java similarity index 74% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java index 1ba617525f7f0225dbdb153a853e35ffcc005dd1..a75ead36800635748095bc8f89239222aa9e7517 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.avatar; +package org.botlibre.sdk.ability.avatar; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; @@ -31,14 +31,13 @@ import ohos.data.preferences.Preferences; import java.util.ArrayList; /** - * Activity used for selecting an offline avatar. + * used for selecting an offline avatar. */ public class AvatarSelection extends Ability { @Override public void onStart(Intent intent) { super.onStart(intent); -// setContentView(R.layout.activity_list_view); super.setUIContent(ResourceTable.Layout_ability_list_view); final int [] imges = {}; final String [] names = {}; @@ -48,16 +47,7 @@ public class AvatarSelection extends Ability { for (int i = 0; i < names.length; i++) { items.add(new OfflineTemplateConfig(imges[i],names[i],null,null)); } -// CustomListViewAdapter adapter = new CustomListViewAdapter(this, R.layout.list_item_imager, items); -// listView.setAdapter(adapter); -// listView.setOnItemClickListener(new OnItemClickListener(){ -// @Override -// public void onItemClick(AdapterView parent, View view, int position, long id) { -// OfflineTemplateConfig template = (OfflineTemplateConfig) (listView.getItemAtPosition(position)); -// saveSelectedAvatar(template.getTitle()); -// MainActivity.readZipAvatars(AvatarSelection.this, MainActivity.nameOfAvatar); -// finish(); -// }}); + } public static void saveSelectedAvatar(String nameOfAvatar) { diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java similarity index 96% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java index c15fc3a71ee6f86d77cbb6fcd913ea40914d24b5..b14752da2ad09c11c8ac78699949724ab1af4531 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java @@ -13,12 +13,12 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.LanguageListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.LanguageListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SearchDialogBuilder.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SearchDialogBuilder.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java index a1f99136eee7867944196c488934bdfef0482374..34c67053c103c3e2a87c24dca243287ed1c7ee15 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SearchDialogBuilder.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java @@ -13,11 +13,11 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.SelectListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java similarity index 96% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java index 929116aa9dc948e3e73c7225d35bcad2c4b79efe..d8caef1fa97f65a4d41c50e0c281907e74135f3d 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java @@ -13,12 +13,12 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.SelectListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java similarity index 74% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java index 776ecddd89448fdd01e97b8cd024a4ce6736c227..4891ad77f15c789b234f6b0f7b565c994856f54e 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java @@ -16,15 +16,18 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.listener; +package org.botlibre.sdk.ability.listener; /** - * Listener interface for a LiveChatConnection. - * This gives asynchronous notification when a channel receives a message, or notice. + * HttpConnectAction + * + * @since 2021-04-16 */ public interface LanguageListener { - /** - * A user message was received from the channel. - */ - void selectLanguageItem(String select); + /** + * selectLanguageItem + * + * @param select + */ + void selectLanguageItem(String select); } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java similarity index 95% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java index 237a4130230d4315b6104d3b10fd8da115e72fed..8196de407603a5e68a3766dcf063c0bc1faedeff 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java @@ -16,7 +16,7 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.listener; +package org.botlibre.sdk.ability.listener; /** * Listener interface for a LiveChatConnection. diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/ChatWarConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java similarity index 95% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/ChatWarConfig.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java index f943da9e2cbeee5b38c510ba220f2c56237be175..7d0c9ee38abd0e72dae4d758dbfb3b6108be35eb 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/ChatWarConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java @@ -1,4 +1,4 @@ -package org.botlibre.sdk.activityy.war; +package org.botlibre.sdk.ability.war; import org.botlibre.sdk.config.Config; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/HttpChatWarAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java similarity index 80% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/HttpChatWarAction.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java index ac0405d955ae27c6ef32f219ba714625c676f441..1c0419f9a72e8569c22923923a87c3b55b740012 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/war/HttpChatWarAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java @@ -1,7 +1,7 @@ -package org.botlibre.sdk.activityy.war; +package org.botlibre.sdk.ability.war; import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.actions.HttpUIAction; +import org.botlibre.sdk.ability.actions.HttpUIAction; import org.botlibre.sdk.config.InstanceConfig; import ohos.aafwk.ability.Ability; @@ -9,8 +9,8 @@ public class HttpChatWarAction extends HttpUIAction { ChatWarConfig config; InstanceConfig instance; - public HttpChatWarAction(Ability activity, ChatWarConfig config) { - super(activity); + public HttpChatWarAction(Ability ability, ChatWarConfig config) { + super(ability); this.config = config; } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/war/StartWarAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java similarity index 95% rename from BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/war/StartWarAbility.java rename to BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index 0e3bb78a893e66f9befea773c0a0eb53c5276bda..b6be798ad96564bc3cf0c82b461dad5c727471ba 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/war/StartWarAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -16,24 +16,23 @@ * ******************************************************************************/ -package org.botlibre.sdk.activityy.war; +package org.botlibre.sdk.ability.war; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.LibreAbility; -import org.botlibre.sdk.activityy.actions.HttpFetchWarAction; -import org.botlibre.sdk.activityy.actions.HttpGetInstancesAction; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.Text; import ohos.agp.components.TextField; import ohos.data.preferences.Preferences; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.ability.LibreAbility; +import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; +import org.botlibre.sdk.config.BrowseConfig; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.WebMediumConfig; +import org.botlibre.sdk.util.PreferencesUtils; import java.util.ArrayList; import java.util.List; @@ -71,8 +70,6 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi if (last != null && !last.isEmpty()) { InstanceConfig config = new InstanceConfig(); config.name = last; - HttpFetchWarAction action = new HttpFetchWarAction(this, config); -// action.execute(); } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java deleted file mode 100644 index 4ec832b535342111beaf7bffa7ab9b86ba105703..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java +++ /dev/null @@ -1,92 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; -import ohos.eventhandler.EventHandler; -import ohos.eventhandler.EventRunner; - -/** - * Generic Ability for common behavior. - */ -public abstract class LibreAbility extends Ability { - - public void help() { -// Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(this.getBundleName()) -// .withAbilityName(HelpAbility.class.getName()) -// .build(); -// intent.setOperation(operation); -// startAbility(intent); - } - - /** - * 启动activity - */ - public void startOpenAbility(Ability ability,String name){ - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - startAbility(intent); - } - - /** - * getIntent - */ - public Intent getIntent(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - return intent; - } - - /** - * 主线程执行任务 - * @param runnable - */ - public static void runUI(Runnable runnable){ - EventHandler eventHandler=new EventHandler(EventRunner.getMainEventRunner()); - eventHandler.postSyncTask(runnable); - - } - - /** - * 子线程执行任务 - * @param runnable - */ - public static void runWork(Runnable runnable){ - //开启线程 - EventRunner runner=EventRunner.create(true); - EventHandler eventHandler=new EventHandler(runner); - eventHandler.postTask(runnable,0, EventHandler.Priority.IMMEDIATE); - - } -} diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java deleted file mode 100644 index 29908b218bfe4750d35e4c029d610e48d10aebf7..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java +++ /dev/null @@ -1,141 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarMessage; -import org.botlibre.sdk.config.ChatResponse; -import ohos.aafwk.ability.Ability; - -public class HttpAvatarMessageAction extends HttpAction { - AvatarMessage config; - ChatResponse response; - - public HttpAvatarMessageAction(Ability ability, AvatarMessage config) { - super(ability); - this.config = config; - } - - protected String doInBackground(Void... params) { - try { - this.response = MainAbility.connection.avatarMessage(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - protected void onPostExecute(String xml) { - if (this.exception != null) { - MainAbility.errorInfo(1,this.exception.getMessage(), this.exception, this.ability); - return; - } - try { -// final AvatarTestAbility ability = (AvatarTestAbility)this.ability; -// -// Image imageView = (Image)ability.findViewById(R.id.imageView); -// final VideoView videoView = (VideoView)Ability.findViewById(R.id.videoView); -// View videoLayout = Ability.findViewById(R.id.videoLayout); -// -// if (MainAbility.sound && this.response.avatarActionAudio != null && this.response.avatarActionAudio.length() > 0) { -// // Action audio -// Ability.playAudio(this.response.avatarActionAudio, false, true, true); -// } -// if (MainAbility.sound && this.response.avatarAudio != null && this.response.avatarAudio.length() > 0) { -// // Background audio -// if (!this.response.avatarAudio.equals(Ability.currentAudio)) { -// if (Ability.audioPlayer != null) { -// Ability.audioPlayer.stop(); -// Ability.audioPlayer.release(); -// } -// Ability.audioPlayer = Ability.playAudio(this.response.avatarAudio, true, true, true); -// } -// } else if (Ability.audioPlayer != null) { -// Ability.audioPlayer.stop(); -// Ability.audioPlayer.release(); -// Ability.audioPlayer = null; -// } -// -// if (!MainAbility.disableVideo && !Ability.videoError && this.response.isVideo()) { -// // Video avatar -// if (imageView.getVisibility() != View.GONE || videoLayout.getVisibility() != View.GONE) { -// if (imageView.getVisibility() == View.VISIBLE) { -// imageView.setVisibility(View.GONE); -// } -// if (videoLayout.getVisibility() == View.GONE) { -// videoLayout.setVisibility(View.VISIBLE); -// } -// } -// if (this.response.avatarAction != null && this.response.avatarAction.length() > 0) { -// // Action video -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// Ability.resetVideoErrorListener(); -// videoView.setOnCompletionListener(null); -// Ability.playVideo(response.avatar, true); -// Ability.response(response); -// } -// }); -// videoView.setOnErrorListener(new OnErrorListener() { -// @Override -// public boolean onError(MediaPlayer mp, int what, int extra) { -// Ability.resetVideoErrorListener(); -// Ability.playVideo(response.avatar, true); -// Ability.response(response); -// return true; -// } -// }); -// Ability.playVideo(this.response.avatarAction, false); -// return; -// } else { -// Ability.playVideo(this.response.avatar, true); -// } -// } else { -// // Image avatar -// if (imageView.getVisibility() != View.GONE || videoLayout.getVisibility() != View.GONE) { -// if (imageView.getVisibility() == View.GONE) { -// imageView.setVisibility(View.VISIBLE); -// } -// if (videoLayout.getVisibility() == View.VISIBLE) { -// videoLayout.setVisibility(View.GONE); -// } -// } -// if (response.isVideo()) { -// HttpGetImageAction.fetchImage(this.ability, MainAbility.instance.avatar, imageView); -// } else { -// HttpGetImageAction.fetchImage(this.ability, this.response.avatar, imageView); -// } -// } -// -// Ability.response(this.response); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java deleted file mode 100644 index 8f69368d93b07ec97733b14bb5fc6aee7b245456..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java +++ /dev/null @@ -1,117 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import ohos.aafwk.ability.Ability; -import org.botlibre.sdk.config.ContentConfig; - - -public class HttpBrowseCategoriesAction extends HttpUIResultAction { - ContentConfig config; - Object[] categories; - boolean finish; - - public HttpBrowseCategoriesAction(Ability ability, String type, boolean finish) { - super(ability); - this.config = new ContentConfig(); - this.config.type = type; - this.finish = finish; - doInBackground(); - } - - public void doInBackground(){ - loadingDialog(); - if (this.config.type.equals("Bot") && MainAbility.categories != null) { - this.categories = MainAbility.categories; - } else if (this.config.type.equals("Forum") && MainAbility.forumCategories != null) { - this.categories = MainAbility.forumCategories; - } else if (this.config.type.equals("Channel") && MainAbility.channelCategories != null) { - this.categories = MainAbility.channelCategories; - } else if (this.config.type.equals("Avatar") && MainAbility.avatarCategories != null) { - this.categories = MainAbility.avatarCategories; - } else if (this.config.type.equals("Script") && MainAbility.scriptCategories != null) { - this.categories = MainAbility.scriptCategories; - } else if (this.config.type.equals("Domain")) { - this.categories = new Object[0]; - } else { - try { - this.categories = MainAbility.connection.getCategories(this.config).toArray(); - } catch (Exception exception) { - this.exception = exception; - this.categories = new Object[0]; - removeDialog(); - } - } - } -// @Override -// protected String doInBackground(Void... params) { -// if (this.config.type.equals("Bot") && MainAbility.categories != null) { -// this.categories = MainAbility.categories; -// } else if (this.config.type.equals("Forum") && MainAbility.forumCategories != null) { -// this.categories = MainAbility.forumCategories; -// } else if (this.config.type.equals("Channel") && MainAbility.channelCategories != null) { -// this.categories = MainAbility.channelCategories; -// } else if (this.config.type.equals("Avatar") && MainAbility.avatarCategories != null) { -// this.categories = MainAbility.avatarCategories; -// } else if (this.config.type.equals("Script") && MainAbility.scriptCategories != null) { -// this.categories = MainAbility.scriptCategories; -// } else if (this.config.type.equals("Domain")) { -// this.categories = new Object[0]; -// } else { -// try { -// this.categories = MainAbility.connection.getCategories(this.config).toArray(); -// } catch (Exception exception) { -// this.exception = exception; -// this.categories = new Object[0]; -// } -// } -// return ""; -// } - - - - @SuppressWarnings("unchecked") -// @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - return; - } - if (this.config.type.equals("Bot")) { - MainAbility.categories = this.categories; - } else if (this.config.type.equals("Forum")) { - MainAbility.forumCategories = this.categories; - } else if (this.config.type.equals("Channel")) { - MainAbility.channelCategories = this.categories; - } else if (this.config.type.equals("Avatar")) { - MainAbility.avatarCategories = this.categories; - } else if (this.config.type.equals("Script")) { - MainAbility.scriptCategories = this.categories; - } - if (this.finish) { - this.ability.terminateAbility(); - } - -// BrowseCategoriesAbility.type = this.config.type; -// BrowseCategoriesAbility.instances = (List)(Object)Arrays.asList(this.categories); -// startOpenAbility(this.ability,); -// Intent intent = new Intent(this.ability, BrowseCategoriesAbility.class); -// this.ability.startAbility(intent); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java deleted file mode 100644 index ea62e54ec97744105480b532ddb5cfd1f8edcec2..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpChangeIconAction extends HttpUIAction { - - WebMediumConfig config; - String file; - - public HttpChangeIconAction(Ability ability, String file, WebMediumConfig config) { - super(ability); - this.config = config; - this.file = file; - } - -// @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.updateIcon(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - -// @Override - public void onPostExecute(String xml) { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; -// ((WebMediumAdminAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java deleted file mode 100644 index ebe30d723709f462d054cc84ae0a765562260f0e..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import ohos.aafwk.ability.Ability; - - -public class HttpChatAction extends HttpAction { - ChatConfig config; - ChatResponse response; - - public HttpChatAction(Ability ability, ChatConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - - - @Override - protected String doInBackground(Void... voids) { - try { - this.response = MainAbility.connection.chat(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - - protected void onPostExecute(String xml) { - if (this.config.disconnect) { - return; - } - if (this.exception != null) { - MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); - return; - } - try { - MainAbility.conversation = this.response.conversation; - final ChatAbility ability = (ChatAbility) this.ability; - - ability.response(this.response); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java deleted file mode 100644 index 887de2ed158e3731e4593a769acbc8973dbf7bd6..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java +++ /dev/null @@ -1,86 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpConnectAction extends HttpUIResultAction { - UserConfig config; - boolean finish; - - public HttpConnectAction(Ability ability, UserConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - doInBackground(); - } - -// @Override - public void doInBackground() { - loadingDialog(); - try { - this.config = MainAbility.connection.connect(config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - } - onPostExecute(); - } - -// @Override - protected void onPostExecute() { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.user = this.config; - if (this.ability instanceof MainAbility) { - ((MainAbility) this.ability).resetView(); - } - - if (this.finish) { - - Preferences cookies = PreferencesUtils.getPreferences(ability); - cookies.putString("user", MainAbility.user.user); - cookies.putString("token", MainAbility.user.token); - cookies.flushSync(); - - this.ability.terminateAbility(); - } - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - - Preferences cookies=PreferencesUtils.getPreferences(this.ability); - cookies.putString("user", null); - cookies.putString("token", null); - cookies.flushSync(); - return; - } - } - - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java deleted file mode 100644 index 4893832d1dcc10063bf074880eb26b74b4d0ad72..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateIssueAction extends HttpUIAction { - - IssueConfig config; - - public HttpCreateIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.create(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.issue = this.config; - MainAbility.issues.add(0, this.config); - - this.ability.terminateAbility(); - - //Intent intent = new Intent(this.ability, IssueAbility.class); - //this.ability.startAbility(intent); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java deleted file mode 100644 index b4e9a82d1eeb2b498226a3ee9d84f08083d047f7..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserMessageConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateUserMessageAction extends HttpUIAction { - - UserMessageConfig config; - - public HttpCreateUserMessageAction(Ability ability, UserMessageConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createUserMessage(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java deleted file mode 100644 index 96c1a4f2640ac21fa5cf7650a1e3a3a34fb08299..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpDeleteAction extends HttpUIAction { - WebMediumConfig config; - - public HttpDeleteAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.wasDelete = true; - MainAbility.instances.remove(this.config); - - Preferences cookies= PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), null); - cookies.flushSync(); - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java deleted file mode 100644 index 3ab854bdaf1593140f1403ad73108934507495e5..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; - -import ohos.aafwk.ability.Ability; - -public class HttpDeleteAvatarMediaAction extends HttpUIAction { - - AvatarMedia config; - - public HttpDeleteAvatarMediaAction(Ability ability, AvatarMedia config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - HttpAction action = new HttpGetAvatarMediaAction(this.ability, (AvatarConfig)MainAbility.instance.credentials(), true); - action.execute(); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java deleted file mode 100644 index e516361666951b2838f11f84958294129463073d..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpDeleteBotScriptAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpDeleteBotScriptAction(Ability ability, ScriptSourceConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.deleteBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - -// ((BotScriptsAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java deleted file mode 100644 index cada6fec28e004811db166f830e9d8bf3874940a..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java +++ /dev/null @@ -1,85 +0,0 @@ -/****************************************************************************** - * - * Copyright 2017 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.activityy.ListTemplateView; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.micro.MicroConnection; -import ohos.aafwk.ability.Ability; - -public class HttpFetchActionOffline extends HttpUIResultAction { - WebMediumConfig config; - MicroConnection microConnection = new MicroConnection(); - boolean launch; - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - doInBackground(); - } - - protected void doInBackground() { - try { - MainAbility.setOnline(false); - microConnection = (MicroConnection) MainAbility.connection; - this.config = microConnection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - return; - } - - onPostExecute(); - } - - public void onPostExecute() { - if(this.ability instanceof ListTemplateView){ - this.ability.terminateAbility(); - } - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - Class childAbility = MainAbility.getActivity(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof InstanceConfig) { - childAbility = ChatAbility.class; -// HttpGetVoiceAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); -// action.execute(); - } - } - startOpenAbility(this.ability,childAbility.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java deleted file mode 100644 index 92293cf14d773a4088d7d6b5c162cab10dc7b691..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpFlagAction extends HttpUIAction { - WebMediumConfig config; - - public HttpFlagAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instance.isFlagged = true; -// this.ability.findComponentById(ResourceTable.flaggedLabel).setVisibility(View.VISIBLE); - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java deleted file mode 100644 index 8405db85144d1a04de0662c6c208df09284acff4..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ConversationConfig; -import org.botlibre.sdk.config.ResponseSearchConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetConversationsAction extends HttpUIAction { - - ResponseSearchConfig config; - List conversations; - - public HttpGetConversationsAction(Ability ability, ResponseSearchConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.conversations = MainAbility.connection.getConversations(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((TrainingAbility)this.ability).setConversations(this.conversations); -// ((TrainingAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java deleted file mode 100644 index 7aeccc1f7248492df6cd3d373236ced01e6c105d..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BotModeConfig; -import org.botlibre.sdk.config.ForumConfig; -import ohos.aafwk.ability.Ability; -public class HttpGetForumBotModeAction extends HttpUIAction { - ForumConfig config; - BotModeConfig botMode; - - public HttpGetForumBotModeAction(Ability ability, ForumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.botMode = MainAbility.connection.getForumBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.botMode = this.botMode; - -// ((ForumBotAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java deleted file mode 100644 index 12cd38a8ac1c9176d7d0b12465ac434b423393d0..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java +++ /dev/null @@ -1,286 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.lang.ref.SoftReference; -import java.net.URL; -import java.util.Hashtable; -import java.util.Map; - -import org.botlibre.sdk.MainAbility; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.Component; -import ohos.agp.components.Image; -import ohos.app.Context; -import ohos.media.image.PixelMap; - -public class HttpGetImageAction extends HttpAction { - public static int MAX_HEIGHT = 1200; - public static int MAX_WIDTH = 600; - public static int MAX_FILES = 100; - - public static volatile boolean downloading; - - public static File cacheDir; - public static Map> imageCache = new Hashtable>(); - - String image; - PixelMap bmp; - Image view; - - - - public static void setImage(int imageId, Component view){ - if(view instanceof Image){ -// ((Image) view).setImageResource(imageId); - } - } - - public static void clearFileCache(Context context) { - try { - File[] files = getFileCacheDir(context).listFiles(); - if (files == null) { - return; - } - for (File file : files) { - if (file.isDirectory()) { - File[] nested = file.listFiles(); - for (File nestedFile : nested) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } else { - file.delete(); - } - } - } catch (Exception failed) { -// Log.wtf(failed.toString(), failed); - } - } - - public static File getFileCacheDir(Context context) { - if (cacheDir == null) { - try { - cacheDir = context.getCacheDir(); - if (!cacheDir.exists()) { - cacheDir.mkdirs(); - } - } catch (Exception failed) { - failed.printStackTrace(); - return null; - } - } - return cacheDir; - } - - public static File getFile(String filename, Context context) { - File dir = getFileCacheDir(context); - if (dir == null) { - return null; - } - - File file = new File(dir.getAbsolutePath() + "/" + filename); - dir = new File(file.getParent()); - if (!dir.exists()) { - dir.mkdir(); - } else { - File[] files = dir.listFiles(); - if (files.length > MAX_FILES) { - for (File nestedFile : files) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } - } - return file; - } - - public static File getFile(String dirName, String filename, Context context) { - File dir = getFileCacheDir(context); - if (dir == null) { - return null; - } - - File file = new File(dir.getAbsolutePath() + "/" + dirName + "/" + filename); - dir = new File(file.getParent()); - if (!dir.exists()) { - dir.mkdir(); - } else { - File[] files = dir.listFiles(); - if (files.length > MAX_FILES) { - for (File nestedFile : files) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } - } - return file; - } - - public static void fetchImage(Ability Ability, String image, Image view) { - if (image == null) { - return; - } - SoftReference ref = imageCache.get(image); - if (ref != null) { - PixelMap bmp = ref.get(); - if (bmp != null) { - if (view instanceof Image) { - view.setPixelMap(bmp); - } - return; - } - } - HttpGetImageAction action = new HttpGetImageAction(Ability, image, view); - try { - action.execute().get(); - action.postExecute(); - if (action.getException() != null) { - throw action.getException(); - } - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - return; - } - } - - public HttpGetImageAction(Ability Ability) { - super(Ability); - } - - public HttpGetImageAction(Ability Ability, String image, Image view) { - super(Ability); - this.image = image; - this.view = view; - } - - @Override - protected String doInBackground(Void... params) { - try { - URL url = MainAbility.connection.fetchImage(this.image); - - /*BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - long start = System.currentTimeMillis(); - InputStream stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream, null, options); - stream.close(); - System.out.println("decodeStream1:" + (System.currentTimeMillis() - start)); - - int height = options.outHeight; - int width = options.outWidth; - options.inPreferredConfig = Bitmap.Config.RGB_565; - int inSampleSize = 1; - - if (height > MAX_HEIGHT) { - inSampleSize = Math.round((float)height / (float)MAX_HEIGHT); - } - - int expectedWidth = width / inSampleSize; - - if (expectedWidth > MAX_WIDTH) { - inSampleSize = Math.round((float)width / (float)MAX_WIDTH); - } - - options.inSampleSize = inSampleSize; - options.inJustDecodeBounds = false; - - start = System.currentTimeMillis(); - stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream, null, options).recycle(); - stream.close(); - System.out.println("decodeStream2:" + (System.currentTimeMillis() - start)); - - start = System.currentTimeMillis(); - stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream).recycle(); - stream.close(); - System.out.println("decodeStream-full:" + (System.currentTimeMillis() - start));*/ - - File file = getFile(this.image, this.ability); - if (!file.exists()) { - downloading = true; - file.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(file); - InputStream stream = url.openConnection().getInputStream(); - byte[] bytes= new byte[1024]; - int count = 0; - while (count != -1) { - count = stream.read(bytes, 0, 1024); - if (count == -1) { - break; - } - outputStream.write(bytes, 0, count); - } - stream.close(); - outputStream.close(); - downloading = false; - } - -// BitmapFactory.Options options = new BitmapFactory.Options(); -// options.inJustDecodeBounds = true; -// InputStream stream = new FileInputStream(file); -// BitmapFactory.decodeStream(stream, null, options); -// stream.close(); -// -// int height = options.outHeight; -// int width = options.outWidth; -// options.inPreferredConfig = Bitmap.Config.RGB_565; -// int inSampleSize = 1; -// if (height > MAX_HEIGHT) { -// inSampleSize = Math.round((float)height / (float)MAX_HEIGHT); -// } -// int expectedWidth = width / inSampleSize; -// if (expectedWidth > MAX_WIDTH) { -// inSampleSize = Math.round((float)width / (float)MAX_WIDTH); -// } -// options.inSampleSize = inSampleSize; -// options.inJustDecodeBounds = false; -// -// stream = new FileInputStream(file); -// this.bmp = BitmapFactory.decodeStream(stream, null, options); -// stream.close(); -// -// imageCache.put(this.image, new SoftReference(this.bmp)); - return ""; - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - } - return null; - } - - protected void postExecute() { - if (view instanceof Image) { -// ((Image)view).setImageBitmap(bmp); - } -// else if (view instanceof Button) { -//// ((Button)view).setBackgroundDrawable(new BitmapDrawable(view.getResources(), bmp)); -// } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java deleted file mode 100644 index b3a658f477c801e9aa4ce2de9ed20de10044954f..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ContentConfig; -import ohos.aafwk.ability.Ability; - -import javax.swing.text.html.ListView; - -public class HttpGetTagsAction extends HttpAction { - ContentConfig config; - Object[] tags; - ListView llview; - - public HttpGetTagsAction(Ability Ability, String type) { - super(Ability); - this.config = new ContentConfig(); - this.config.type = type; - } - - @Override - protected String doInBackground(Void... params) { - if (this.config.type.equals("Bot") && MainAbility.tags != null) { - this.tags = MainAbility.tags; - } else if (this.config.type.equals("Forum") && MainAbility.forumTags != null) { - this.tags = MainAbility.forumTags; - } else if (this.config.type.equals("Post") && MainAbility.forumPostTags != null) { - this.tags = MainAbility.forumPostTags; - } else if (this.config.type.equals("Channel") && MainAbility.channelTags != null) { - this.tags = MainAbility.channelTags; - } else if (this.config.type.equals("Avatar") && MainAbility.avatarTags != null) { - this.tags = MainAbility.avatarTags; - } else if (this.config.type.equals("Script") && MainAbility.scriptTags != null) { - this.tags = MainAbility.scriptTags; - } else if (this.config.type.equals("Domain") && MainAbility.domainTags != null) { -//------- //it's not passing anything -// this.tags = new Object[0]; - //Clean up the domain - this.config.domain = null; - this.tags = MainAbility.domainTags; - } else { - try { - this.tags = MainAbility.connection.getTags(this.config).toArray(); - } catch (Exception exception) { - this.exception = exception; - } - } - return ""; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - return; - } - if (this.config.type.equals("Bot")) { - MainAbility.tags = this.tags; - } else if (this.config.type.equals("Forum")) { - MainAbility.forumTags = this.tags; - } else if (this.config.type.equals("Post")) { - MainAbility.forumPostTags = this.tags; - } else if (this.config.type.equals("Channel")) { - MainAbility.channelTags = this.tags; - } else if (this.config.type.equals("Avatar")) { - MainAbility.avatarTags = this.tags; - } else if (this.config.type.equals("Script")) { - MainAbility.scriptTags = this.tags; - }else if(this.config.type.equals("Domain")){ - - //added domainTags - MainAbility.domainTags = this.tags; - } - - - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java deleted file mode 100644 index fa59737fed7c834f60f88e4b4b0b9925aad5ca5a..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.net.URL; - -import org.botlibre.sdk.MainAbility; - -import ohos.aafwk.ability.Ability; -import ohos.utils.net.Uri; - -public class HttpGetVideoAction extends HttpGetImageAction { - - String video; - - public static Uri fetchVideo(Ability Ability, String video) { -// if(!MainAbility.online){ -// File file = getFile(GetAvatarAction.nameOfFile,video, Ability); -// return Uri.getUriFromFile(file); -// } - - if (video == null) { - return null; - } - - if (downloading) { - return null; - } - File file = getFile(video, Ability); - if (file.exists()) { - if (downloading) { - return null; - } - return Uri.getUriFromFile(file); - } - HttpGetVideoAction action = new HttpGetVideoAction(Ability, video); - try { - action.execute().get(); - if (action.getException() != null) { - throw action.getException(); - } - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - } - return Uri.getUriFromFile(file); - } - - public HttpGetVideoAction(Ability Ability, String video) { - super(Ability); - this.video = video; - } - - @Override - protected String doInBackground(Void... params) { - try { - URL url = MainAbility.connection.fetchImage(this.video); - - File file = getFile(this.video, this.ability); - if (!file.exists()) { - downloading = true; - file.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(file); - InputStream stream = url.openConnection().getInputStream(); - byte[] bytes= new byte[1024]; - int count = 0; - while (count != -1) { - count = stream.read(bytes, 0, 1024); - if (count == -1) { - break; - } - outputStream.write(bytes, 0, count); - } - stream.close(); - outputStream.close(); - downloading = false; - } - return ""; - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - downloading = false; - } - return null; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java deleted file mode 100644 index d3382aa6186f7bd29f9e88ffc14f2058bf162f3f..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java +++ /dev/null @@ -1,64 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.VoiceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetVoiceAction extends HttpResultAction { - InstanceConfig config; - VoiceConfig voice; - - public HttpGetVoiceAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - doInBackground(); - } - - protected void doInBackground() { - try { - this.voice = MainAbility.connection.getVoice(this.config); - } catch (Exception exception) { - this.exception = exception; - } - - onPostExecute(); - } - - public void onPostExecute() { - if (this.exception != null) { - return; - } - try { - if (!MainAbility.customVoice) { - MainAbility.voice = this.voice; - MainAbility.deviceVoice = this.voice.nativeVoice; -// if (this.ability instanceof VoiceAbility) { -// ((VoiceAbility) this.ability).resetView(); -// } - } - } catch (Exception error) { - this.exception = error; - return; - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java deleted file mode 100644 index c984d17e2436d7149cbf1d4baf108c85af6fa5aa..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2016 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpImportBotScriptAction extends HttpUIAction { - ScriptConfig config; - ScriptSourceConfig script; - - public HttpImportBotScriptAction(Ability Ability, ScriptConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - //this.script = MainAbility.connection.getScriptSource(this.config); - - MainAbility.connection.importBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java deleted file mode 100644 index 0431d849bd37355817bf8f6a6a03c9994f5db279..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpPageInstancesAction extends HttpUIAction { - BrowseConfig config; - List instances; - - public HttpPageInstancesAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.instances = MainAbility.connection.browse(ability,config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instances = this.instances; - - MainAbility.browse = this.config; -// ((BrowseAbility)this.ability).instances = this.instances; -// ((BrowseAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java deleted file mode 100644 index db5535421227d2c23a13a850106d620e6a845a3f..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * - * Copyright 2017 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - - package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.GraphicConfig; -import ohos.aafwk.ability.Ability; - -public class HttpRefreshAction extends HttpFetchAction { - - - GraphicConfig instance; - - - public HttpRefreshAction(Ability Ability, GraphicConfig config) { - super(Ability, config); - instance = config; - } - -// @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - -// @Override - public void onPostExecute(String xml) { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java deleted file mode 100644 index 18ee6f3a64b78423e963651d94399f2fc612f5d6..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; - -public class HttpSaveAvatarMediaAction extends HttpUIAction { - - AvatarMedia config; - - public HttpSaveAvatarMediaAction(Ability Ability, AvatarMedia config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveAvatarMedia(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - this.ability.terminateAbility(); - MainAbility.wasDelete = true; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java deleted file mode 100644 index 7031146ac6d3001f5e4daa85e1c1986f65c0f267..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveBotAvatarAction extends HttpUIAction { - - InstanceConfig config; - - public HttpSaveBotAvatarAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveBotAvatar(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java deleted file mode 100644 index a03999fb83df6d6e0ec3247eeb18647c37ffffe0..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BotModeConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveForumBotModeAction extends HttpUIAction { - - BotModeConfig config; - - public HttpSaveForumBotModeAction(Ability Ability, BotModeConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveForumBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.botMode = this.config; - - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java deleted file mode 100644 index 1a1228828e020c531e56dfdddf61517feb88193a..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.VoiceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveVoiceAction extends HttpUIAction { - - VoiceConfig config; - - public HttpSaveVoiceAction(Ability Ability, VoiceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveVoice(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.voice = this.config; - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java deleted file mode 100644 index eeed3b90239cadccad6791df57c85f8a2f706458..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.Speech; -import ohos.aafwk.ability.Ability; - -public class HttpSpeechAction extends HttpAction { - Speech config; - String response; - - public HttpSpeechAction(Ability Ability, Speech config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.response = MainAbility.connection.tts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } -// try { -// final VoiceAbility Ability = (VoiceAbility)this.ability; -// Ability.playAudio(this.response, false, true, true); -// } catch (Exception error) { -// this.exception = error; -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// return; -// } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java deleted file mode 100644 index c8156298a108b82394309f8727bb2d6d445cb5b6..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpStarPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpStarPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.star(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.stars = config.stars; -// ((ForumPostAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java deleted file mode 100644 index fd20173aafdf9c5f44e249b6f933a32fae571d50..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSubscribeAction extends HttpUIAction { - ForumPostConfig config; - - public HttpSubscribeAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.subscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java deleted file mode 100644 index 0031ff92da6c9fbb2fde53ec00b864349c57142a..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSubscribeForumAction extends HttpUIAction { - ForumConfig config; - - public HttpSubscribeForumAction(Ability Ability, ForumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.subscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java deleted file mode 100644 index ee2348f437b3b5608dbf8f529715d1e34dbbb790..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsDownIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpThumbsDownIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsDown(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.thumbsDown++; -// ((IssueAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java deleted file mode 100644 index 7c4c9179fc335c1d23f6a5099660e1c5e1c3fafc..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUnsubscribeForumAction extends HttpUIAction { - ForumConfig config; - - public HttpUnsubscribeForumAction(Ability Ability, ForumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.unsubscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java deleted file mode 100644 index 846ae93004bdb99f9e7051145baca1504d0cee32..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateForumPostAction extends HttpUIAction { - - ForumPostConfig config; - - public HttpUpdateForumPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.post = this.config; - - this.ability.terminateAbility(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java deleted file mode 100644 index 2a412260e4c52dc1da04735e66f99bf698569930..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateUserAction extends HttpUIAction { - UserConfig config; - - public HttpUpdateUserAction(Ability Ability, UserConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.user = this.config; - - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java deleted file mode 100644 index b7b7065c55055ee1590601dea625bf7559aa69ad..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.GraphicConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUploadGraphicMediaAction extends HttpUIAction{ - - GraphicConfig config; - String file; - - public HttpUploadGraphicMediaAction(Ability Ability, String file, GraphicConfig config) { - super(Ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createGraphicMedia(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - this.ability.terminateAbility(); - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - HttpRefreshAction refresh = new HttpRefreshAction(this.ability,config); -// refresh.execute(); - } -} diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java deleted file mode 100644 index 2124ff3c5497c51f6400e661949cadd76313d638..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.UserAdminConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUserAdminAction extends HttpUIAction { - - UserAdminConfig config; - - public HttpUserAdminAction(Ability Ability, UserAdminConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.userAdmin(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// if (this.config.operation.equals("AddUser")) { -// ((WebMediumUsersAbility)this.ability).users.add(this.config.operationUser); -// } else if (this.config.operation.equals("RemoveUser")) { -// ((WebMediumUsersAbility)this.ability).users.remove(this.config.operationUser); -// } else if (this.config.operation.equals("AddAdmin")) { -// ((WebMediumUsersAbility)this.ability).admins.add(this.config.operationUser); -// } else if (this.config.operation.equals("RemoveAdmin")) { -// ((WebMediumUsersAbility)this.ability).admins.remove(this.config.operationUser); -// } -// TextField text = (TextField) this.ability.findComponentById(ResourceTable.Id_adminText); -// text.setText(""); -// text = (TextField) this.ability.findComponentById(ResourceTable.Id_userText); -// text.setText(""); -// ((WebMediumUsersAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java deleted file mode 100644 index 01215f2ed60eea3d5a4d4c6fccc2078af443ef93..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.config.ChatResponse; - -public class WarAction extends HttpAction { - ChatResponse config; - - public WarAction(ohos.aafwk.ability.Ability Ability, ChatResponse config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - Thread.sleep(4000); - } catch (InterruptedException exception) {} - return ""; - } - - @Override - protected void onPostExecute(String xml) { -// ((WarAbility)this.ability).switchBots(); -// ((WarAbility)this.ability).submitChat(this.config.message); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index 275ea4125ece92822879c086888206de39df99bb..0f1252ae5aa30f7321148eb629cb4240a7a8b59f 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java @@ -29,564 +29,561 @@ import org.botlibre.util.Utils; import org.w3c.dom.Element; /** - * DTO for XML avatar config. + * HttpConnectAction + * + * @since 2021-04-16 */ public class AvatarConfig extends WebMediumConfig { - public Map mediaConfig; - private String avatarFormat; - private boolean avatarHD; - public String background; - public String icon; - - public String getType() { - return "avatar"; - } - public AvatarConfig(){ - mediaConfig = new HashMap(); - } - - public ChatResponse chatReply(ChatResponse chat) { - String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); - String action = MicroConnection.getBot().avatar().getAction(); - String pose = MicroConnection.getBot().avatar().getPose(); - if (this.getBackground() != null) { - String background = this.getBackground(); - chat.avatarBackground = background; - } - List matching = null; - - // Audio - if (action != null) { - matching = this.getAudio(action, pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String [] array = media.media.split("\\."); - chat.avatarActionAudio = media.mediaId + "." + array[1]; - chat.avatarActionAudioType = media.getType(); - } - } - matching = this.getAudio("", pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String [] array = media.media.split("\\."); - chat.avatarAudio = media.mediaId + "." + array[1]; - chat.avatarAudioType = media.getType(); - } - // Image/video - if (action != null) { - matching = this.getMedia(emotion, action, pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatarAction = media.mediaId+"."+array[1]; - } - } - matching = this.getMedia(emotion, "", pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatar = media.mediaId+"."+array[1]; - chat.avatar2 = null; - chat.avatar3 = null; - chat.avatar4 = null; - chat.avatar5 = null; - if (matching.size() > 1) { - AvatarMedia media2 = randomMatch(matching); - AvatarMedia media3 = randomMatch(matching); - AvatarMedia media4 = randomMatch(matching); - AvatarMedia media5 = randomMatch(matching); - if (media != media2 || media != media3 || media != media4 || media != media5) { - array = media2.media.split("\\."); - chat.avatar2 = media2.mediaId+"."+array[1]; - array = media3.media.split("\\."); - chat.avatar3 = media3.mediaId+"."+array[1]; - array = media4.media.split("\\."); - chat.avatar4 = media4.mediaId+"."+array[1]; - array = media5.media.split("\\."); - chat.avatar5 = media5.mediaId+"."+array[1]; - } - } - chat.avatarType = media.getType(); - } - matching = this.getMedia(emotion, "", pose, "talking"); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String [] array = media.media.split("\\."); - chat.avatarTalk = media.mediaId +"." +array[1]; - chat.avatarTalkType = media.getType(); - } - return chat; - } + public Map mediaConfig; + private String avatarFormat; + private boolean avatarHD; + public String background; + public String icon; + + /** + * getType + * + * @return ss + */ + public String getType() { + return "avatar"; + } + + /** + * AvatarConfig + */ + public AvatarConfig() { + mediaConfig = new HashMap(); + } + + /** + * chatReply + * + * @param chat + * @return chat + */ + public ChatResponse chatReply(ChatResponse chat) { + String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); + String action = MicroConnection.getBot().avatar().getAction(); + String pose = MicroConnection.getBot().avatar().getPose(); + if (this.getBackground() != null) { + String background = this.getBackground(); + chat.avatarBackground = background; + } + List matching = null; + + // Audio + if (action != null) { + matching = this.getAudio(action, pose); + if (!matching.isEmpty()) { + AvatarMedia media = Utils.random(matching); + String[] array = media.media.split("\\."); + chat.avatarActionAudio = media.mediaId + "." + array[1]; + chat.avatarActionAudioType = media.getType(); + } + } + matching = this.getAudio("", pose); + if (!matching.isEmpty()) { + AvatarMedia media = Utils.random(matching); + String[] array = media.media.split("\\."); + chat.avatarAudio = media.mediaId + "." + array[1]; + chat.avatarAudioType = media.getType(); + } + // Image/video + if (action != null) { + matching = this.getMedia(emotion, action, pose, ""); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatarAction = media.mediaId + "." + array[1]; + } + } + matching = this.getMedia(emotion, "", pose, ""); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatar = media.mediaId + "." + array[1]; + chat.avatar2 = null; + chat.avatar3 = null; + chat.avatar4 = null; + chat.avatar5 = null; + if (matching.size() > 1) { + AvatarMedia media2 = randomMatch(matching); + AvatarMedia media3 = randomMatch(matching); + AvatarMedia media4 = randomMatch(matching); + AvatarMedia media5 = randomMatch(matching); + if (media != media2 || media != media3 || media != media4 || media != media5) { + array = media2.media.split("\\."); + chat.avatar2 = media2.mediaId + "." + array[1]; + array = media3.media.split("\\."); + chat.avatar3 = media3.mediaId + "." + array[1]; + array = media4.media.split("\\."); + chat.avatar4 = media4.mediaId + "." + array[1]; + array = media5.media.split("\\."); + chat.avatar5 = media5.mediaId + "." + array[1]; + } + } + chat.avatarType = media.getType(); + } + matching = this.getMedia(emotion, "", pose, "talking"); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatarTalk = media.mediaId + "." + array[1]; + chat.avatarTalkType = media.getType(); + } + return chat; + } + + /** + * credentials + * + * @return config + */ + public WebMediumConfig credentials() { + AvatarConfig config = new AvatarConfig(); + config.id = this.id; + return config; + } + + /** + * toXML + * + * @return ss + */ + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + + /** + * parseXML + * + * @param element + */ + public void parseXML(Element element) { + super.parseXML(element); + } + + /** + * getMedia + * + * @param emotion + * @param action + * @param pose + * @param pose2 + * @return dd + */ + public List getMedia(String emotion, String action, String pose, String pose2) { + if (emotion == null || emotion.isEmpty()) { + emotion = "NONE"; + } else { + emotion = emotion.toUpperCase(); + } + if (action == null) { + action = ""; + } + if (pose == null) { + pose = ""; + } + if (pose2 == null) { + pose2 = ""; + } + boolean talking = pose2.equals("talking"); + List matches = new ArrayList(); + boolean none = emotion.equals("NONE"); + + boolean[][] matching = new boolean[this.mediaConfig.size()][4]; + int index = 0; + // All match. + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean emotionMatch = media.getEmotions().contains(emotion) || (none && media.getEmotions().isEmpty()); + if (emotionMatch && emotion.equals("RAGE") && media.getEmotions().contains("COURAGE")) { + // Both contain "rage". + emotionMatch = false; + } + if (emotionMatch && emotion.equals("LIKE") && media.getEmotions().contains("DISLIKE")) { + // Both contain "like". + emotionMatch = false; + } + boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); + boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); + boolean pose2Match = (!pose2.isEmpty() && media.getPoses().contains(pose2)) || pose2.isEmpty(); + if (!pose2Match && pose2.equals("talking")) { + pose2Match = media.getTalking(); + } else if (media.getTalking() && !talking) { + pose2Match = false; + } + matching[index][0] = emotionMatch; + matching[index][1] = actionMatch; + matching[index][2] = poseMatch; + matching[index][3] = pose2Match; + index++; + if (emotionMatch && actionMatch && poseMatch && pose2Match) { + matches.add(media); + } + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 and pose matches. + if (!pose2.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean poseMatch = matching[index][2]; + boolean pose2Match = matching[index][3]; + if (poseMatch && pose2Match) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 and emotion matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + boolean pose2Match = matching[index][3]; + if (emotionMatch && pose2Match) { + if (!media.getPoses().isEmpty()) { + index++; + continue; + } + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean pose2Match = matching[index][3]; + if (pose2Match) { + if (!media.getPoses().isEmpty()) { + index++; + continue; + } + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 any matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean pose2Match = matching[index][3]; + if (pose2Match) { + matches.add(media); + } + index++; + } + // For pose2, the pose is required (i.e. talking). + return matches; + } + // Action and pose matches. + if (!action.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean actionMatch = matching[index][1]; + boolean poseMatch = matching[index][2]; + if (actionMatch && poseMatch) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Action matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean actionMatch = matching[index][1]; + if (actionMatch + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + // For actions, the action is required. + return matches; + } + // Pose and emotion matches. + if (!pose.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + boolean poseMatch = matching[index][2]; + if (poseMatch && emotionMatch && media.getActions().isEmpty()) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean poseMatch = matching[index][2]; + if (poseMatch && media.getActions().isEmpty() + && (media.getEmotions().isEmpty() || media.getEmotions().contains("NONE"))) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + } + // Emotion matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + if (emotionMatch + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Default matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + return matches; + } + + /** + * getAudio + * + * @param action + * @param pose + * @return ss + */ + public List getAudio(String action, String pose) { + if (action == null) { + action = ""; + } + if (pose == null) { + pose = ""; + } + List matches = new ArrayList(); -// public String getDefaultAvatarMediaOne(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.poses.equals("") && media.emotions.equals("")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// public String getDefaultAvatarMediaTwo(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.emotions.contains("HAPPY")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// -// public String getDefaultAvatarMediaThree(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.emotions.contains("ANGER")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// public String getDefaultAvatarMediaFour(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.emotions.equals("") && media.poses.contains("sleeping")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// public String getTalkingAvatarMedia(){ -// String name = null; -// for(AvatarMedia media : mediaConfig.values()){ -// if(media.talking && media.hd && media.name.contains("talk")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId +"."+ array[1]; -// type = media.type; -// } -// } -// return name; -// } -// -// public String getTypeAvatarMedia(){ -// return type; -// } - - public WebMediumConfig credentials() { - AvatarConfig config = new AvatarConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - - public void parseXML(Element element) { - super.parseXML(element); - } - - /** - * Find any media that match the emotion, action, and pose, or the best matches. - */ - public List getMedia(String emotion, String action, String pose, String pose2) { - if (emotion == null || emotion.isEmpty()) { - emotion = "NONE"; - } else { - emotion = emotion.toUpperCase(); - } - if (action == null) { - action = ""; - } - if (pose == null) { - pose = ""; - } - if (pose2 == null) { - pose2 = ""; - } - boolean talking = pose2.equals("talking"); - List matches = new ArrayList(); - boolean none = emotion.equals("NONE"); - - boolean[][] matching = new boolean[this.mediaConfig.size()][4]; - int index = 0; - // All match. - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean emotionMatch = media.getEmotions().contains(emotion) || (none && media.getEmotions().isEmpty()); - if (emotionMatch && emotion.equals("RAGE") && media.getEmotions().contains("COURAGE")) { - // Both contain "rage". - emotionMatch = false; - } - if (emotionMatch && emotion.equals("LIKE") && media.getEmotions().contains("DISLIKE")) { - // Both contain "like". - emotionMatch = false; - } - boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); - boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); - boolean pose2Match = (!pose2.isEmpty() && media.getPoses().contains(pose2)) || pose2.isEmpty(); - if (!pose2Match && pose2.equals("talking")) { - pose2Match = media.getTalking(); - } else if (media.getTalking() && !talking) { - pose2Match = false; - } - matching[index][0] = emotionMatch; - matching[index][1] = actionMatch; - matching[index][2] = poseMatch; - matching[index][3] = pose2Match; - index++; - if (emotionMatch && actionMatch && poseMatch && pose2Match) { - matches.add(media); - } - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 and pose matches. - if (!pose2.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean poseMatch = matching[index][2]; - boolean pose2Match = matching[index][3]; - if (poseMatch && pose2Match) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 and emotion matches. - index = 0; - for (AvatarMedia media :this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - boolean pose2Match = matching[index][3]; - if (emotionMatch && pose2Match) { - if (!media.getPoses().isEmpty()) { - index++; - continue; - } - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean pose2Match = matching[index][3]; - if (pose2Match) { - if (!media.getPoses().isEmpty()) { - index++; - continue; - } - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 any matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean pose2Match = matching[index][3]; - if (pose2Match) { - matches.add(media); - } - index++; - } - // For pose2, the pose is required (i.e. talking). - return matches; - } - // Action and pose matches. - if (!action.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean actionMatch = matching[index][1]; - boolean poseMatch = matching[index][2]; - if (actionMatch && poseMatch) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Action matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean actionMatch = matching[index][1]; - if (actionMatch - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - // For actions, the action is required. - return matches; - } - // Pose and emotion matches. - if (!pose.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - boolean poseMatch = matching[index][2]; - if (poseMatch && emotionMatch && media.getActions().isEmpty()) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean poseMatch = matching[index][2]; - if (poseMatch && media.getActions().isEmpty() - && (media.getEmotions().isEmpty() || media.getEmotions().contains("NONE"))) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - } - // Emotion matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - if (emotionMatch - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Default matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - return matches; - } - - /** - * Find an audio media that matches the action or pose. - */ - public List getAudio(String action, String pose) { - if (action == null) { - action = ""; - } - if (pose == null) { - pose = ""; - } - List matches = new ArrayList(); - - boolean[][] matching = new boolean[this.mediaConfig.size()][2]; - int index = 0; - // All match. - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); - boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); - matching[index][0] = actionMatch; - matching[index][1] = poseMatch; - index++; - if (actionMatch && poseMatch) { - matches.add(media); - } - } - if (!matches.isEmpty()) { - return matches; - } - // Action matches. - if (!action.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean actionMatch = matching[index][0]; - if (actionMatch && media.getPoses().isEmpty()) { - matches.add(media); - } - index++; - } - // For actions, the action is required. - return matches; - } - // Pose matches. - if (!pose.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean poseMatch = matching[index][1]; - if (poseMatch && media.getActions().isEmpty()) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - } - // Default matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - return matches; - } + boolean[][] matching = new boolean[this.mediaConfig.size()][2]; + int index = 0; + // All match. + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); + boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); + matching[index][0] = actionMatch; + matching[index][1] = poseMatch; + index++; + if (actionMatch && poseMatch) { + matches.add(media); + } + } + if (!matches.isEmpty()) { + return matches; + } + // Action matches. + if (!action.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean actionMatch = matching[index][0]; + if (actionMatch && media.getPoses().isEmpty()) { + matches.add(media); + } + index++; + } + // For actions, the action is required. + return matches; + } + // Pose matches. + if (!pose.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean poseMatch = matching[index][1]; + if (poseMatch && media.getActions().isEmpty()) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + } + // Default matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + return matches; + } - public AvatarMedia randomMatch(List matches) { - List formatMatches = new ArrayList(); - String format = "mp4"; - if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { - format = this.avatarFormat; - } - for (AvatarMedia media : matches) { - if (media.getType().indexOf(format) != -1) { - formatMatches.add(media); - } - } - if (formatMatches.isEmpty()) { - List hdMatches = new ArrayList(); - for (AvatarMedia media : matches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(matches); - } else { - List hdMatches = new ArrayList(); - for (AvatarMedia media : formatMatches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(formatMatches); - } - } + /** + * randomMatch + * + * @param matches + * @return ss + */ + public AvatarMedia randomMatch(List matches) { + List formatMatches = new ArrayList(); + String format = "mp4"; + if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { + format = this.avatarFormat; + } + for (AvatarMedia media : matches) { + if (media.getType().indexOf(format) != -1) { + formatMatches.add(media); + } + } + if (formatMatches.isEmpty()) { + List hdMatches = new ArrayList(); + for (AvatarMedia media : matches) { + if (this.avatarHD && media.getHD()) { + hdMatches.add(media); + } else if (!this.avatarHD && !media.getHD()) { + hdMatches.add(media); + } + } + if (!hdMatches.isEmpty()) { + return Utils.random(hdMatches); + } + return Utils.random(matches); + } else { + List hdMatches = new ArrayList(); + for (AvatarMedia media : formatMatches) { + if (this.avatarHD && media.getHD()) { + hdMatches.add(media); + } else if (!this.avatarHD && !media.getHD()) { + hdMatches.add(media); + } + } + if (!hdMatches.isEmpty()) { + return Utils.random(hdMatches); + } + return Utils.random(formatMatches); + } + } - public String getBackground(){ - return background; - } + /** + * getBackground + * + * @return background + */ + public String getBackground() { + return background; + } - public String getIcon(){ - return icon; - } + /** + * getIcon + * + * @return icon + */ + public String getIcon() { + return icon; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java index e947ee2599b4c2b3956c1a891aa3b24495c7071e..0078f540f6c6ab788ccc638bc9a92f519a49cadf 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java @@ -18,7 +18,6 @@ package org.botlibre.sdk.config; -import org.botlibre.sdk.util.Utils; import java.io.StringWriter; @@ -71,7 +70,6 @@ public class AvatarMessage extends Config { if (this.message != null) { writer.write(""); - writer.write(Utils.escapeHTML(this.message)); writer.write(""); } writer.write(""); diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java index dc2b363caa5cdff7ea26f35508506ccabf8f9c72..58a11bcdb65b62b99a6043e53e8ef2d1e1996719 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java @@ -24,7 +24,6 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import org.botlibre.sdk.util.Utils; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -60,7 +59,7 @@ public class ConversationConfig extends Config { try { SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); + return ""; } catch (Exception exception) { return creationDate; } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java index 50ed66a264cf38d85254c5d1ab3390b0a1ed6788..283beaeb0d6742abe781061087bf8596b0e3d6e6 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import org.botlibre.sdk.util.Utils; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -97,13 +96,11 @@ public class ForumPostConfig extends Config { writer.write(">"); if (this.topic != null) { writer.write(""); - writer.write(Utils.escapeHTML(this.topic)); writer.write(""); } if (this.details != null) { String text = this.details; writer.write("

"); - writer.write(Utils.escapeHTML(text)); writer.write("
"); } if (this.tags != null) { @@ -113,7 +110,6 @@ public class ForumPostConfig extends Config { } if (this.flaggedReason != null) { writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); writer.write(""); } writer.write(""); @@ -192,7 +188,7 @@ public class ForumPostConfig extends Config { try { SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); + return ""; } catch (Exception exception) { return creationDate; } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java index 6e2324f4aab4c99d82c91c539df79ba343f37f9b..8254fedb5fa75880d65d7c16fc1b25dd10107edc 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java @@ -18,16 +18,11 @@ package org.botlibre.sdk.config; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - import org.botlibre.sdk.SDKConnection; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.botlibre.sdk.util.Utils; +import java.io.StringWriter; /** * DTO for XML user creation config. @@ -61,25 +56,7 @@ public class UserConfig extends Config { public boolean isFlagged; public String flaggedReason; - public String displayJoined() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(joined); - return Utils.displayDate(date); - } catch (Exception exception) { - return joined; - } - } - - public String displayLastConnect() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(lastConnect); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return lastConnect; - } - } + public void addCredentials(SDKConnection connection) { this.application = connection.getCredentials().getApplicationId(); @@ -167,7 +144,6 @@ public class UserConfig extends Config { if (this.bio != null) { writer.write(""); - writer.write(Utils.escapeHTML(this.bio)); writer.write(""); } writer.write(""); diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java deleted file mode 100644 index e9e6524542f7192fc29177ef448e735559a82848..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java +++ /dev/null @@ -1,189 +0,0 @@ -package org.botlibre.sdk.micro; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.actions.HttpUIAction; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; -import org.botlibre.Bot; -import org.botlibre.api.knowledge.Network; -import org.botlibre.api.knowledge.Vertex; -import org.botlibre.api.sense.Sense; -import org.botlibre.knowledge.Primitive; -import org.botlibre.knowledge.micro.MicroMemory; -import org.botlibre.self.SelfCompiler; -import org.botlibre.sense.http.Wiktionary; -import org.botlibre.sense.text.TextEntry; -import org.botlibre.thought.consciousness.Consciousness; -import org.botlibre.thought.language.Comprehension; -import org.botlibre.thought.language.Language; -import org.botlibre.thought.language.Language.LearningMode; - -/** - * Bootstrap the bot the first time from an online response list file or script. - */ -public class BootstrapAsync extends HttpUIAction { - public BootstrapAsync(Ability Ability) { - super(Ability); - } - - protected String aimlScriptId; - protected String selfScriptId; - protected String greetingScriptId; - InstanceConfig config; - MicroConnection connection; - Bot bot=null; - boolean noInternet = false; - - //passing InstanceConfig and the Scripts Versions. - public synchronized void bootstrapBot(InstanceConfig config, String aimlScriptId, String greetingScriptId) { - this.greetingScriptId = greetingScriptId; - this.aimlScriptId = aimlScriptId; - this.config = config; - this.execute(); - } - - protected boolean isResetRequired() { - // Check if bot memory exists. - if (!MicroMemory.checkExists()) { - return true; - } - try{ - // Check if version is changed. - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.current); - String aimlVersion = cookies.getString(this.aimlScriptId, null); - String greetingVersion = cookies.getString(this.greetingScriptId, null); - if (aimlVersion == null || aimlVersion.isEmpty() || greetingVersion == null || greetingVersion.isEmpty()) { - return true; - } - ScriptConfig aimlScript = new ScriptConfig(); - aimlScript.id = this.aimlScriptId; - aimlScript = MainAbility.connection.fetch(aimlScript); - if (!aimlVersion.equals(aimlScript.version)) { - return true; - } - ScriptConfig greetingScript = new ScriptConfig(); - greetingScript.id = this.greetingScriptId; - greetingScript = MainAbility.connection.fetch(greetingScript); - if (!greetingVersion.equals(greetingScript.version)) { - return true; - } - } catch (Exception ignore) { - return false; - } - return false; - } - - @Override - protected String doInBackground(Void... params) { - try { - MicroMemory.storageFileName = this.config.id; - this.connection = (MicroConnection) MainAbility.connection; - // Check if bot is already loaded first. - if (connection.getBot(this.config.id) != null) { - return ""; - } - // Check if bot memory exists. - boolean resetRequired = isResetRequired(); - - // If no reset is required, just load the bot. - if (!resetRequired) { - try { - this.bot = Bot.createInstance(Bot.CONFIG_FILE, this.config.id, true); - Language language = bot.mind().getThought(Language.class); - language.setLearningMode(LearningMode.Disabled); - language.setLearnGrammar(false); - Comprehension comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - Consciousness consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - Sense sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - } catch (Exception failed) { - // If the load fails, then reset the bot. - resetRequired = true; - } - } - // If a reset is required the bot must be rebuilt from scratch and reimport the AIML and greeting files. - if (resetRequired) { - // Delete the old file if exists. - MicroMemory.reset(); - // Fetch the scripts source code. - ScriptConfig aimlScript = new ScriptConfig(); - aimlScript.id = this.aimlScriptId; - ScriptSourceConfig aimlSource = connection.getScriptSource(aimlScript); - ScriptConfig greetingScript = new ScriptConfig(); - greetingScript.id = this.greetingScriptId; - ScriptSourceConfig greetingSource = connection.getScriptSource(greetingScript); - - MicroMemory.reset(); - // Create new bot. - bot = Bot.createInstance(Bot.CONFIG_FILE, this.config.id, true); - Language language = bot.mind().getThought(Language.class); - language.setLearningMode(LearningMode.Disabled); - language.setLearnGrammar(false); - Comprehension comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - Consciousness consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - Sense sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - //if bootstrapSystem was true, it will load the default script. - // Do not need to bootstrap, as only uses AIML. - //new Bootstrap().bootstrapSystem(bot, false); - // Load AIML file. - language.loadAIML(aimlSource.source, "ami", true, false, false); - // Load greeting response list. - bot.awareness().getSense(TextEntry.class).loadChat(greetingSource.source, "Response List", false, true); - - // Shutdown will save the file. - bot.shutdown(); - // Reload the bot from the file. - bot = Bot.createInstance(Bot.CONFIG_FILE, this.config.id, true); - language = bot.mind().getThought(Language.class); - language.setLearningMode(LearningMode.Disabled); - language.setLearnGrammar(false); - comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.current); - cookies.putString(this.aimlScriptId, aimlSource.versionName); - cookies.putString(this.greetingScriptId, greetingSource.versionName); - cookies.flush(); - } - // Finally, add the bot to the connections active bots. - connection.addBot(this.config.id, bot); - } catch (Exception exception) { - noInternet = true; -// MicroMemory.reset(); - return null; - } - return null; - } - - /** - * Load, compile, and add the state machine from the Self source code. - */ - public void loadSelf(Bot bot, String text) { - - Network network = bot.memory().newMemory(); - Vertex language = network.createVertex(bot.mind().getThought(Language.class).getPrimitive()); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(text, false, network); - SelfCompiler.getCompiler().pin(stateMachine); - language.addRelationship(Primitive.STATE, stateMachine); - network.save(); - } - - @Override - protected void onPostExecute(String result) { - super.onPostExecute(result); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java index b19fa4a065b658ee10ccb5f4df2d98afb1ffa0a4..8b7b2c60217d081159efbfd013b560880ca605d8 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java @@ -55,8 +55,9 @@ import java.util.HashMap; import java.util.Map; /** - * The MicroConnection replaces the normal SDK remote connection with one that creates - * and accessed bots locally. + * HttpConnectAction + * + * @since 2021-04-16 */ public class MicroConnection extends SDKConnection implements TextListener { private WebMediumConfig config; @@ -72,32 +73,51 @@ public class MicroConnection extends SDKConnection implements TextListener { } /** - * Create a micro/offline SDK connection. - * Use the credentials to enable online support. + * MicroConnection + * + * @param credentials */ public MicroConnection(Credentials credentials) { this.credentials = credentials; this.url = credentials.url; } + /** + * addBot + * + * @param id + * @param bot + */ public void addBot(String id, Bot bot) { activeBots.put(id, bot); } + /** + * getBot + * + * @param id + * @return + */ public Bot getBot(String id) { return activeBots.get(id); } + /** + * getBot + * + * @return + */ public static Bot getBot() { return bot; } /** - * Process the bot chat message and return the bot's response. - * The ChatConfig should contain the conversation id if part of a conversation. - * If a new conversation the conversation id is returned in the response. + * chat + * + * @param config + * @return */ - public synchronized ChatResponse chat(ChatConfig config) { + public ChatResponse chat(ChatConfig config) { if (config.instance == null) { config.instance = "default"; } @@ -135,28 +155,27 @@ public class MicroConnection extends SDKConnection implements TextListener { sense.input(textInput); ChatResponse response = new ChatResponse(); - - try { - if (this.message == null) { - wait(5000); - } - if (this.message != null) { - response.message = this.message.getMessage(); - response.command = bot.avatar().getCommand(); - try { - avatarConfig.chatReply(response); - } catch (Exception e) { - } + if (this.message == null) { + //wait(5000); + } + if (this.message != null) { + response.message = this.message.getMessage(); + response.command = bot.avatar().getCommand(); + try { + avatarConfig.chatReply(response); + } catch (Exception e) { } - } catch (InterruptedException exception) { -// this.exception = new SDKException("Timeout waiting for response"); -// throw this.exception; } + return response; } /** - * Fetch the local object. + * fetch + * + * @param config + * @param + * @return */ public T fetch(T config) { this.config = config; @@ -171,7 +190,10 @@ public class MicroConnection extends SDKConnection implements TextListener { } /** - * Return the bot's voice configuration. + * getVoice + * + * @param config + * @return */ public VoiceConfig getVoice(InstanceConfig config) { VoiceConfig voice = new VoiceConfig(); @@ -180,13 +202,25 @@ public class MicroConnection extends SDKConnection implements TextListener { return voice; } - public synchronized void sendMessage(TextOutput message) { - LogUtils.e("[MicroConnection]---->output-sendMessage",message.getMessage()); + /** + * sendMessage + * + * @param message + */ + public void sendMessage(TextOutput message) { + LogUtils.e("[MicroConnection]---->output-sendMessage", message.getMessage()); this.message = message; notifyAll(); } - public synchronized Bot loadBot(String name, int id) { + /** + * loadBot + * + * @param name + * @param id + * @return + */ + public Bot loadBot(String name, int id) { boolean exists = MicroMemory.checkExists(); ResourceManager resManager = MyApplication.getAppContext().getResourceManager(); RawFileEntry rawFile; @@ -226,46 +260,34 @@ public class MicroConnection extends SDKConnection implements TextListener { return bot; } - public void loadAIMLScript(Language lang, InputStream source) { - lang.loadAIMLFile(source, config.id, false, false, true, "", 10000000); - } + /** + * loadResScript + * + * @param bot + * @param fileName + */ public void loadResScript(Bot bot, String fileName) { URL url = getClass().getResource(fileName); bot.awareness().getSense(TextEntry.class).loadChatFile(url, "Response List", "", false, true); } + /** + * loadResScript + * + * @param bot + * @param file + */ public void loadResScript(Bot bot, File file) { bot.awareness().getSense(TextEntry.class).loadChatFile(file, "Response List", "", false, true); } - public void loadSelfScript(Bot bot, String fileName) { - loadSelfScript(bot, getClass().getResource(fileName)); - } - - public void loadSelfScript(Bot bot, URL url) { - Network network = bot.memory().getShortTermMemory(); - Vertex language = network.createVertex(new Primitive(Language.class.getName())); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(url, "", false, network); - language.addRelationship(Primitive.STATE, stateMachine); - SelfCompiler.getCompiler().pin(stateMachine); - } - - public void loadSelfScript(Bot bot, File file) { - Network network = bot.memory().getShortTermMemory(); - Vertex language = network.createVertex(new Primitive(Language.class.getName())); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(file, "", false, network); - language.addRelationship(Primitive.STATE, stateMachine); - SelfCompiler.getCompiler().pin(stateMachine); - } - - public void renameMemory(Bot bot, String name) { - bot.memory().getShortTermMemory().createVertex(Primitive.SELF).addRelationship(Primitive.NAME, bot.memory().getShortTermMemory().createVertex(name)); - - } - + /** + * reInitialize + * + * @param bot + * @return + */ public Vertex reInitialize(Bot bot) { Network memory = bot.memory().newMemory(); Vertex user = memory.createSpeaker("Admin"); @@ -274,6 +296,12 @@ public class MicroConnection extends SDKConnection implements TextListener { return user; } + /** + * copyStream + * + * @param input + * @throws IOException + */ public static void copyStream(InputStream input) throws IOException { File file = new File(MicroMemory.storageDir, MicroMemory.storageFileName); FileOutputStream output = new FileOutputStream(file); diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/Utils.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/Utils.java deleted file mode 100644 index e2667554458cf4b39b09db6f45618ae95b08168b..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/Utils.java +++ /dev/null @@ -1,517 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.util; - -import org.botlibre.BotException; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Random; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -/** - * Utility class. - */ -public class Utils { - public static Random random = new Random(); - - public static Pattern httpRegex = Pattern.compile("\\b(?:https?|ftp|file):\\/\\/[a-z0-9-+&@#\\/%?=~_|!:,.;]*[a-z0-9-+&@#\\/%=~_|]", Pattern.CASE_INSENSITIVE); - public static Pattern wwwRegex = Pattern.compile("((www\\.)[^\\s]+)", Pattern.CASE_INSENSITIVE); - public static Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); - - /** - * Replace links with HTML links. - * Includes http, www, images, video, audio, email address. - */ - public static String linkHTML(String text) { - if (text == null || text.length() == 0) { - return ""; - } - boolean http = text.indexOf("http") != -1; - boolean www = text.indexOf("www.") != -1; - boolean email = text.indexOf("@") != -1; - if (!http && !www && !email) { - return text; - } - if (text.indexOf("<") != -1 && text.indexOf(">") != -1) { - return text; - } - if (http) { - Matcher matcher = httpRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - if (url.indexOf(".png") != -1 || url.indexOf(".jpg") != -1 || url.indexOf(".jpeg") != -1 || url.indexOf(".gif") != -1) { - url = ""; - } else if (url.indexOf(".mp4") != -1 || url.indexOf(".webm") != -1 || url.indexOf(".ogg") != -1) { - url = ""; - } else if (url.indexOf(".wav") != -1 || url.indexOf(".mp3") != -1) { - url = ""; - } else { - url = "" + url + ""; - } - matcher.appendReplacement(sb, url); - } - matcher.appendTail(sb); - text = sb.toString(); - } else if (www) { - Matcher matcher = wwwRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - matcher.appendReplacement(sb, "" + url + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - - if (email) { - Matcher matcher = emailRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String address = matcher.group(); - matcher.appendReplacement(sb, "" + address + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - return text; - } - - - /** - * Replace reserved HTML character with their HTML escape codes. - */ - public static String escapeHTML(String html) { - return html.replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """) - .replace("`", "`") - .replace("'", "'"); - } - - /** - * Strip the HTML tags from the text. - */ - public static String stripTags(String html) { - if (html == null) { - return ""; - } - String result = html; - if ((html.indexOf('<') != -1) && (html.indexOf('>') != -1)) { - StringWriter writer = new StringWriter(); - TextStream stream = new TextStream(html); - while (!stream.atEnd()) { - String text = stream.upTo('<'); - writer.write(text); - int position = stream.getPosition(); - stream.skip(); - String word = stream.nextWord(); - if (word != null) { - if (word.equals("p")) { - writer.write("\n\n"); - } else if (word.equals("br")) { - writer.write("\n"); - } else if (word.equals("div")) { - writer.write("\n"); - } - stream.skipTo('>'); - if (stream.atEnd()) { - stream.setPosition(position); - writer.write(stream.upToEnd()); - } else { - stream.skip(); - } - } - } - result = writer.toString(); - } - if (result.contains("&")) { - result = result.replace(""", "\""); - result = result.replace("`", "`"); - result = result.replace("'", "'"); - result = result.replace("@", "@"); - result = result.replace("=", "="); - result = result.replace("<", "<"); - result = result.replace(">", ">"); - } - return result; - } - - /** - * Format the text that may be HTML, or may be text, or markup, or a mix. - */ - public static String formatHTMLOutput(String text) { - if (text == null) { - return ""; - } - int index = text.indexOf('<'); - int index2 = text.indexOf('>'); - boolean isHTML = (index != -1) && (index2 > index); - boolean isMixed = isHTML && text.contains("[code]"); - if (isHTML && !isMixed) { - return text; - } - if (!isMixed && ((index != -1) || (index2 != -1))) { - text = text.replace("<", "<"); - text = text.replace(">", ">"); - } - TextStream stream = new TextStream(text); - StringWriter writer = new StringWriter(); - boolean bullet = false; - boolean nbullet = false; - while (!stream.atEnd()) { - String line = stream.nextLine(); - if (!isMixed && (line.contains("http://") || line.contains("https://"))) { - line = Utils.linkHTML(line); - } - TextStream lineStream = new TextStream(line); - boolean firstWord = true; - boolean span = false; - boolean cr = true; - while (!lineStream.atEnd()) { - while (!isMixed && firstWord && lineStream.peek() == ' ') { - lineStream.next(); - writer.write(" "); - } - String whitespace = lineStream.nextWhitespace(); - writer.write(whitespace); - if (lineStream.atEnd()) { - break; - } - String word = lineStream.nextWord(); - if (!isMixed && nbullet && firstWord && !word.equals("#")) { - writer.write("\n"); - nbullet = false; - } else if (!isMixed && bullet && firstWord && !word.equals("*")) { - writer.write("\n"); - bullet = false; - } - if (firstWord && word.equals("[")) { - String peek = lineStream.peekWord(); - if ("code".equals(peek)) { - lineStream.nextWord(); - String next = lineStream.nextWord(); - String lang = "javascript"; - int lines = 20; - if ("lang".equals(next)) { - lineStream.skip(); - lang = lineStream.nextWord(); - if ("\"".equals(lang)) { - lang = lineStream.nextWord(); - lineStream.skip(); - } - next = lineStream.nextWord(); - } - if ("lines".equals(next)) { - lineStream.skip(); - String value = lineStream.nextWord(); - if ("\"".equals(value)) { - value = lineStream.nextWord(); - lineStream.skip(); - } - lineStream.skip(); - try { - lines = Integer.valueOf(value); - } catch (NumberFormatException ignore) {} - } - String id = "code" + stream.getPosition(); - writer.write("
"); - String code = lineStream.upToAll("[code]"); - if (code.indexOf('<') != -1) { - code = code.replace("<", "<"); - } - if (code.indexOf('>') != -1) { - code = code.replace(">", ">"); - } - writer.write(code); - while (lineStream.atEnd() && !stream.atEnd()) { - line = stream.nextLine(); - lineStream = new TextStream(line); - while (lineStream.peek() == ':') { - lineStream.next(); - writer.write("    "); - } - code = lineStream.upToAll("[code]"); - if (code.indexOf('<') != -1) { - code = code.replace("<", "<"); - } - if (code.indexOf('>') != -1) { - code = code.replace(">", ">"); - } - writer.write(code); - } - lineStream.skip("[code]".length()); - writer.write("
\n"); - - writer.write("\n"); - } else { - writer.write(word); - } - } else if (!isMixed && firstWord && word.equals("=")) { - int count = 2; - String token = word; - while (!lineStream.atEnd() && lineStream.peek() == '=') { - lineStream.skip(); - count++; - token = token + "="; - } - String header = lineStream.upToAll(token); - if (lineStream.atEnd()) { - writer.write(token); - writer.write(header); - } else { - lineStream.skip(token.length()); - writer.write(""); - writer.write(header); - writer.write(""); - cr = false; - } - } else if (!isMixed && firstWord && word.equals(":")) { - span = true; - int indent = 1; - while (!lineStream.atEnd() && lineStream.peek() == ':') { - lineStream.skip(); - indent++; - } - writer.write(""); - } else if (!isMixed && firstWord && word.equals("*")) { - if (!bullet) { - writer.write("
    "); - bullet = true; - } - writer.write("
  • "); - cr = false; - } else if (!isMixed && firstWord && word.equals("#")) { - if (!nbullet) { - writer.write("
      "); - nbullet = true; - } - writer.write("
    1. "); - cr = false; - } else { - writer.write(word); - } - firstWord = false; - } - if (!isMixed && span) { - writer.write(""); - } - if (!isMixed && cr) { - writer.write("
      \n"); - } - } - if (!isMixed && bullet) { - writer.write("
"); - } - if (!isMixed && nbullet) { - writer.write(""); - } - return writer.toString(); - } - - public static String displayTimestamp(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - writer.write(", "); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - - return writer.toString(); - } - - public static String displayTime(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - writer.write(":"); - if (calendar.get(Calendar.SECOND) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.SECOND))); - - return writer.toString(); - } - - public static String displayDate(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - - return writer.toString(); - } - - /** - * Capitalize the first character of the string. - */ - public static String capitalize(String text) { - if (text.length() == 0) { - return text; - } - return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); - } - - public static Random random() { - return random; - } - - public static int random(int max) { - return random().nextInt(max); - } - - public static T random(List list) { - if ((list == null) || list.isEmpty()) { - return null; - } - return list.get(random().nextInt(list.size())); - } - /** - * Get the contents of the stream to a .self file and parse it. - */ - public static String loadTextFile(InputStream stream, String encoding, int maxSize, boolean finish) { - if (encoding.trim().isEmpty()) { - encoding = "UTF-8"; - } - - // FEFF because this is the Unicode char represented by the UTF-8 byte order mark (EF BB BF). - String UTF8_BOM = "\uFEFF"; - - StringWriter writer = new StringWriter(); - InputStreamReader reader = null; - try { - reader = new InputStreamReader(stream, encoding); - int size = 0; - int next = reader.read(); - boolean first = true; - while (next >= 0) { - if (first && next == UTF8_BOM.charAt(0)) { - // skip - } else { - writer.write(next); - } - next = reader.read(); - if (size > maxSize) { - throw new BotException("File size limit exceeded: " + size + " > " + maxSize + " token: " + next); - } - size++; - } - } catch (IOException exception) { - throw new BotException("IO Error: " + exception.getMessage(), exception); - } finally { - if (reader != null && finish) { - try { - reader.close(); - } catch (IOException ignore) {} - } - if (stream != null && finish) { - try { - stream.close(); - } catch (IOException ignore) {} - } - } - return writer.toString(); - } - - public static T random(Collection collection) { - if ((collection == null) || collection.isEmpty()) { - return null; - } - int value = random().nextInt(collection.size()); - int index = 0; - for (T element : collection) { - if (index == value) { - return element; - } - index++; - } - return null; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sense/BasicAwareness.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sense/BasicAwareness.java deleted file mode 100644 index 07d430a96dba27084ee73eb6e1e005be92b6d199..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sense/BasicAwareness.java +++ /dev/null @@ -1,216 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -package org.botlibre.sense; - -import java.util.HashMap; -import java.util.Map; - -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.Bot; -import org.botlibre.api.knowledge.Vertex; -import org.botlibre.api.sense.Awareness; -import org.botlibre.api.sense.Sense; -import org.botlibre.api.sense.Tool; - -/** - * Controls and manages the senses. - */ - -public class BasicAwareness implements Awareness { - - protected Bot bot; - protected Map senses; - protected Map sensesByShortName; - - protected Map tools; - protected Map toolsByShortName; - - public BasicAwareness() { - this.senses = new HashMap(); - this.sensesByShortName = new HashMap(); - this.tools = new HashMap(); - this.toolsByShortName = new HashMap(); - } - - /** - * Return Bot. - */ - public Bot getBot() { - return bot; - } - - /** - * Set Bot. - */ - public void setBot(Bot bot) { - this.bot = bot; - } - - /** - * Initialize any configurable settings from the properties. - */ - @Override - public void initialize(Map properties) { - return; - } - - /** - * Reset state when instance is pooled. - */ - @Override - public void pool() { - getBot().log(this, "Pool", Bot.FINE); - for (Sense sense : getSenses().values()) { - try { - sense.pool(); - } catch (Exception exception) { - getBot().log(this, exception); - } - } - for (Tool tool : getTools().values()) { - try { - tool.pool(); - } catch (Exception exception) { - getBot().log(this, exception); - } - } - } - - @Override - public void shutdown() { - getBot().log(this, "Shutdown", Bot.FINE); - for (Sense sense : getSenses().values()) { - try { - sense.shutdown(); - } catch (Exception exception) { - getBot().log(this, exception); - } - } - for (Tool tool : getTools().values()) { - try { - tool.shutdown(); - } catch (Exception exception) { - getBot().log(this, exception); - } - } - } - - @Override - public void awake() { - getBot().log(this, "Awake", Bot.FINE); - for (Sense sense : getSenses().values()) { - try { - sense.awake(); - } catch (Exception exception) { - getBot().log(sense, exception); - } - } - for (Tool tool : getTools().values()) { - try { - tool.awake(); - } catch (Exception exception) { - getBot().log(tool, exception); - } - } - } - - public Map getSenses() { - return senses; - } - - @SuppressWarnings("unchecked") - public T getSense(Class type) { - return (T)getSense(type.getName()); - } - - public Sense getSense(String senseName) { - Sense sense = getSenses().get(senseName); - if (sense == null) { - sense = this.sensesByShortName.get(senseName); - } - return sense; - } - - public void addSense(Sense sense) { - sense.setBot(getBot()); - getSenses().put(sense.getName(), sense); - // Also index simple name. - this.sensesByShortName.put(sense.getClass().getSimpleName(), sense); - this.sensesByShortName.put(sense.getClass().getSimpleName().toLowerCase(), sense); - } - - public void removeSense(Sense sense) { - getSenses().remove(sense.getName()); - // Also index simple name. - this.sensesByShortName.remove(sense.getClass().getSimpleName()); - this.sensesByShortName.remove(sense.getClass().getSimpleName().toLowerCase()); - } - - public Map getTools() { - return tools; - } - - @SuppressWarnings("unchecked") - public T getTool(Class type) { - return (T)getTool(type.getName()); - } - - public Tool getTool(String name) { - Tool tool = getTools().get(name); - if (tool == null) { - tool = this.toolsByShortName.get(name); - } - return tool; - } - - public void addTool(Tool tool) { - tool.setBot(getBot()); - getTools().put(tool.getName(), tool); - // Also index simple name. - this.toolsByShortName.put(tool.getClass().getSimpleName(), tool); - this.toolsByShortName.put(tool.getClass().getSimpleName().toLowerCase(), tool); - } - - public void removeTool(Tool tool) { - getTools().remove(tool.getName()); - // Also index simple name. - this.toolsByShortName.remove(tool.getClass().getSimpleName()); - this.toolsByShortName.remove(tool.getClass().getSimpleName().toLowerCase()); - } - - public String toString() { - return getClass().getSimpleName(); - } - - /** - * Allow the sense to output the response. - */ - public void output(Vertex output) { - getBot().mood().evaluateOutput(output); - getBot().avatar().evaluateOutput(output); - for (Sense sense : getSenses().values()) { - try { - sense.output(output); - LogUtils.e("[BasicAwareness]---->output-output",output.printString()); - } catch (Throwable ignore) { - getBot().log(this, ignore); - } - } - } -} - diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sense/text/TextEntry.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sense/text/TextEntry.java deleted file mode 100644 index db08e4292879d583be7a63b3e865fd35b1badd7f..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sense/text/TextEntry.java +++ /dev/null @@ -1,954 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -package org.botlibre.sense.text; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.Writer; -import java.net.URL; -import java.util.logging.Level; - -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.BotException; -import org.botlibre.api.knowledge.Network; -import org.botlibre.api.knowledge.Vertex; -import org.botlibre.emotion.EmotionalState; -import org.botlibre.knowledge.Primitive; -import org.botlibre.self.SelfCompiler; -import org.botlibre.self.SelfParseException; -import org.botlibre.sense.BasicSense; -import org.botlibre.thought.language.Language; -import org.botlibre.thought.language.Language.LanguageState; -import org.botlibre.thought.language.Language.LearningMode; -import org.botlibre.util.TextStream; -import org.botlibre.util.Utils; - -/** - * Process text to and from networks and - * stimulates natural language thoughts. - */ - -public class TextEntry extends BasicSense { - public static int LOG_SLEEP = 5000; - - /** - * Keeps track of the user involved in the conversation. - */ - protected Long userId; - - /** - * Keeps track of the current conversation. - */ - protected Long conversationId; - - /** - * The writer is the stream, text-box or chat client to output text to. - */ - protected Writer writer; - - protected TextListener textListener; - - /** Allows contact info to be passed to sense. */ - protected String info; - - public TextEntry() { - } - - public TextListener getTextListener() { - return textListener; - } - - public void setTextListener(TextListener textListener) { - this.textListener = textListener; - } - - /** - * Return the user involved in the conversation. - */ - public Vertex getUser(Network network) { - if (this.userId == null) { - return null; - } - return network.findById(this.userId); - } - - /** - * Set the user involved in the conversation. - */ - public void setUser(Vertex user) { - if (user == null) { - this.userId = null; - } else { - this.userId = user.getId(); - } - } - - public String getInfo() { - return info; - } - - public void setInfo(String info) { - this.info = info; - } - - /** - * Return the writer used to output text to. - */ - public Writer getWriter() { - return this.writer; - } - - /** - * Set the writer used to output text to. - */ - public void setWriter(Writer writer) { - this.writer = writer; - } - - /** - * Process the text input. - */ - @Override - public void input(Object inputText, Network network) { - if (!isEnabled()) { - return; - } - TextInput text = null; - if (inputText instanceof TextInput) { - text = (TextInput)inputText; - } else { - text = new TextInput((String)inputText); - } - log("Input", Level.INFO, text.text, getUser(network), getConversation(network)); - inputSentence(text, network); - } - - /** - * Process the text sentence. - */ - public void inputSentence(TextInput text, Network network) { - Vertex input = null; - boolean newConversation = text.getText() == null; - if (newConversation) { - // Null input is used to get greeting. - input = network.createInstance(Primitive.INPUT); - input.addRelationship(Primitive.SENSE, getPrimitive()); - input.addRelationship(Primitive.INSTANTIATION, Primitive.CHAT); - input.addRelationship(Primitive.INPUT, Primitive.NULL); - } else { - input = createInputSentence(text.getText().trim(), network); - input.addRelationship(Primitive.INSTANTIATION, Primitive.CHAT); - } - if (text.isCorrection()) { - input.addRelationship(Primitive.ASSOCIATED, Primitive.CORRECTION); - } - if (text.isOffended()) { - input.addRelationship(Primitive.ASSOCIATED, Primitive.OFFENDED); - } - input.addRelationship(Primitive.TARGET, Primitive.SELF); - // Process speaker. - Vertex speaker = getUser(network); - if (speaker == null) { - speaker = network.createSpeaker(DEFAULT_SPEAKER); - speaker.addRelationship(Primitive.ASSOCIATED, Primitive.ANONYMOUS); - if (this.info != null && !this.info.isEmpty()) { - String name = new TextStream(this.info).nextWord(); - speaker.addRelationship(Primitive.NAME, network.createName(name)); - } - setUser(speaker); - } - - Language language = this.bot.mind().getThought(Language.class); - boolean applyEmote = language.shouldLearn(input, speaker) || (text.isCorrection() && language.shouldCorrect(input, speaker)); - - input.addRelationship(Primitive.SPEAKER, speaker); - speaker.addRelationship(Primitive.INPUT, input); - if (this.emotionalState != null && this.emotionalState != EmotionalState.NONE) { - this.emotionalState.apply(input); - if (applyEmote) { - this.emotionalState.apply(input.getRelationship(Primitive.INPUT)); - } - } - if (this.action != null) { - input.addRelationship(Primitive.ACTION, new Primitive(this.action)); - if (applyEmote) { - input.getRelationship(Primitive.INPUT).addRelationship(Primitive.ACTION, new Primitive(this.action)); - } - } - // Process conversation. - Vertex conversation = getConversation(network); - if (newConversation || (conversation == null)) { - conversation = network.createInstance(Primitive.CONVERSATION); - conversation.addRelationship(Primitive.TYPE, Primitive.CHAT); - setConversation(conversation); - conversation.addRelationship(Primitive.SPEAKER, speaker); - conversation.addRelationship(Primitive.SPEAKER, Primitive.SELF); - if (this.info != null && !this.info.isEmpty()) { - Vertex infoInput = createInputSentence("Info: " + this.info.trim(), network); - infoInput.addRelationship(Primitive.INSTANTIATION, Primitive.CHAT); - Language.addToConversation(infoInput, conversation); - } - } - if (!newConversation) { - Language.addToConversation(input, conversation); - } else { - input.addRelationship(Primitive.CONVERSATION, conversation); - } - - network.save(); - this.bot.memory().addActiveMemory(input); - } - - /** - * Output the vertex to text. - */ - @Override - public synchronized void output(Vertex output) { - if (!isEnabled()) { - return; - } - Vertex sense = output.mostConscious(Primitive.SENSE); - // If not output to Text, ignore. - if (sense == null || (!getPrimitive().equals(sense.getData()))) { - return; - } - if (this.textListener != null) { - TextOutput text = new TextOutput(); - text.setMessage(printInput(output)); - this.textListener.sendMessage(text); - LogUtils.e("[TextEntry]---->output-output",text.getMessage()); - } else { - if (this.writer == null) { - log("Missing writer", Level.WARNING); - return; - } - try { - this.writer.write(printInput(output)); - } catch (Exception failed) { - log(failed); - } - } - } - - /** - * Return the current conversation. - */ - public Long getConversationId() { - return this.conversationId; - } - - /** - * Return the current conversation. - */ - public Vertex getConversation(Network network) { - if (this.conversationId == null) { - return null; - } - return network.findById(this.conversationId); - } - - public void clearConversation() { - this.conversationId = null; - this.userId = null; - this.action = null; - this.emotionalState = EmotionalState.NONE; - this.info = null; - } - - /** - * Stop sensing. - */ - @Override - public void shutdown() { - super.shutdown(); - clearConversation(); - } - - /** - * Reset state when instance is pooled. - */ - @Override - public void pool() { - clearConversation(); - } - - /** - * Set the current conversation. - */ - public void setConversation(Vertex conversation) { - this.conversationId = conversation.getId(); - } - - /** - * Process the log file from a URL. - */ - public void loadChatFile(URL file, String format, String encoding, boolean processUnderstanding, boolean pin) { - try { - loadChatFile(Utils.openStream(file), format, encoding, MAX_FILE_SIZE, processUnderstanding, pin); - } catch (Exception exception) { - throw new BotException(exception); - } - } - - /** - * Process the log file. - */ - public void loadChatFile(File file, String format, String encoding, boolean processUnderstanding, boolean pin) { - try { - loadChatFile(new FileInputStream(file), format, encoding, MAX_FILE_SIZE, processUnderstanding, pin); - } catch (Exception exception) { - throw new BotException(exception); - } - } - - /** - * Process the log file for a chat conversation. - * Input each message, in a listening only mode. - */ - public void loadChatFile(InputStream stream, String format, String encoding, int maxSize, boolean processUnderstanding, boolean pin) { - try { - String text = Utils.loadTextFile(stream, encoding, maxSize); - loadChat(text, format, processUnderstanding, pin); - } catch (BotException exception) { - throw exception; - } catch (Exception exception) { - throw new BotException(exception); - } - } - - /** - * Process the log file for a chat conversation. - * Input each message, in a listening only mode. - */ - public void loadChat(String text, String format, boolean processUnderstanding, boolean pin) { - try { - if ("Response List".equalsIgnoreCase(format)) { - processResponseLog(text, pin); - } else if ("Chat Log".equalsIgnoreCase(format)) { - processChatLog(text, processUnderstanding, pin); - } else if ("CSV List".equalsIgnoreCase(format)) { - processCSVLog(text, pin); - } else { - throw new BotException("Invalid chat log format '" + format + "'"); - } - } catch (BotException exception) { - throw exception; - } catch (Exception exception) { - throw new BotException(exception); - } - } - - /** - * Process the log file for a chat conversation. - * Input each message, in a listening only mode. - */ - public void processChatLog(String log, boolean comprehension, boolean pin) { - log("Loading chat log", Level.INFO, log.length()); - TextStream stream = new TextStream(log); - Vertex lastSpeaker = null; - LanguageState oldState = getLanguageState(); - Language languageThought = this.bot.mind().getThought(Language.class); - LearningMode oldMode = languageThought.getLearningMode(); - if (comprehension) { - setLanguageState(LanguageState.ListeningOnly); - if (languageThought.getLearningMode() == LearningMode.Disabled) { - languageThought.setLearningMode(LearningMode.Everyone); - } - } - Vertex conversation = null; - Vertex question = null; - Vertex previous = null; - boolean wasAdmin = false; - boolean first = true; - boolean cycle = false; - int count = 0; - try { - while (!stream.atEnd()) { - count++; - int marker = stream.getPosition(); - String line = stream.nextLine().trim(); - if (first && line.indexOf("'); - if (lineStream.atEnd()) { - stream.setPosition(marker); - throw new SelfParseException("Expected '' in chat text", stream); - } - lineStream.skip(); - try { - state = EmotionalState.valueOf(emotion.toUpperCase()); - } catch (Exception exception) { - stream.setPosition(marker); - throw new SelfParseException("Invalid '' in chat text", stream); - } - } - setEmotionalState(state); - String message = lineStream.upToEnd().trim(); - if (speakerName.equalsIgnoreCase("default")) { - Vertex language = network.createVertex(Language.class); - input = network.createSentence(message); - input.setPinned(true); - language.addRelationship(Primitive.RESPONSE, input); - } else if (speakerName.equalsIgnoreCase("greeting")) { - Vertex language = network.createVertex(Language.class); - input = network.createSentence(message); - input.setPinned(true); - language.addRelationship(Primitive.GREETING, input); - } else if (speakerName.equalsIgnoreCase("script")) { - input = SelfCompiler.getCompiler().evaluateExpression( - message, network.createVertex(Primitive.SELF), network.createVertex(Primitive.SELF), false, network); - } else { - if (comprehension) { - input = createInputSentence(message, network); - input.addRelationship(Primitive.INSTANTIATION, Primitive.CHAT); - if (this.emotionalState != EmotionalState.NONE) { - this.emotionalState.apply(input); - this.emotionalState.apply(input.getRelationship(Primitive.INPUT)); - } - if (lastSpeaker != null) { - lastSpeaker = network.createVertex(lastSpeaker); - input.addRelationship(Primitive.TARGET, lastSpeaker); - } - Vertex speaker = null; - if (speakerName.toLowerCase().equals("self")) { - speaker = network.createVertex(Primitive.SELF); - wasAdmin = true; - } else { - speaker = network.createSpeaker(speakerName); - if (speakerName.equals("admin")) { - speaker.addRelationship(Primitive.ASSOCIATED, Primitive.ADMINISTRATOR); - wasAdmin = true; - } - } - input.addRelationship(Primitive.SPEAKER, speaker); - speaker.addRelationship(Primitive.INPUT, input); - conversation.addRelationship(Primitive.SPEAKER, speaker); - Language.addToConversation(input, conversation); - lastSpeaker = speaker; - } - Vertex sentence = network.createSentence(message); - if (pin) { - sentence.setPinned(true); - } - if (question != null) { - question = network.createVertex(question); - if (pin) { - question.setPinned(true); - } - Language.addResponse(question, sentence, null, null, null, languageThought.getLearningRate(), network); - if (previous != null) { - previous = network.createVertex(previous); - Language.addSentencePreviousMeta(question, sentence, previous, false, network); - } - } - previous = question; - question = sentence; - } - network.save(); - break; - } catch (SelfParseException failed) { - failed.printStackTrace(); - log(failed); - network.clear(); - throw failed; - } catch (Exception failed) { - failed.printStackTrace(); - log(failed); - network.clear(); - } - } - if (comprehension) { - if (input == null) { - return; - } - this.bot.memory().addActiveMemory(input); - int abort = 0; - while ((abort < 20) && !input.hasRelationship(Primitive.CONTEXT)) { - Utils.sleep(100); - Network memory = this.bot.memory().newMemory(); - input = memory.createVertex(input); - abort++; - } - if (count == 100) { - log("Chat log import exceeds 100 lines, offloading to background task", Level.WARNING); - } - if (abort >= 20 || count > 100) { - Utils.sleep(LOG_SLEEP); - } - } - } - if (languageThought.getLearningMode() == LearningMode.Administrators && !wasAdmin) { - throw new SelfParseException("Expected 'admin:' speaker in chat text when learning mode is administrators only", stream); - } - } finally { - setLanguageState(oldState); - languageThought.setLearningMode(oldMode); - } - } - - /** - * Process the log file for a list of question/answers. - * Input each message, in a listening only mode. - */ - public void processResponseLog(String log, boolean pin) { - log("Loading response log", Level.INFO, log.length()); - TextStream stream = new TextStream(log); - Network network = this.bot.memory().newMemory(); - Vertex question = null; - Vertex answer = null; - boolean first = true; - boolean isDefault = false; - while (!stream.atEnd()) { - String line = stream.nextLine().trim(); - if (first && line.indexOf(" loadedStates = new HashSet(); - - /** - * Defines the various language conversational states. - */ - public enum LanguageState { - Associate, Conversational, Listening, ListeningOnly, Discussion, Answering - } - /** - * Defines who the bot will learn from. - */ - public enum LearningMode { - Disabled, Administrators, Users, Everyone - } - /** - * Defines who the bot will allow corrections from. - */ - public enum CorrectionMode { - Disabled, Administrators, Users, Everyone - } - - /** - * Add the input to the conversation. - */ - public static void addToConversation(Vertex input, Vertex conversation) { - input.addRelationship(Primitive.CONVERSATION, conversation); - Vertex previous = conversation.lastRelationship(Primitive.INPUT); - if (previous != null) { - previous.addRelationship(Primitive.NEXT, input); - input.addRelationship(Primitive.PREVIOUS, previous); - } - conversation.addRelationship(Primitive.INPUT, input, Integer.MAX_VALUE); - Vertex sentence = input.getRelationship(Primitive.INPUT); - if (sentence != null && sentence.instanceOf(Primitive.SENTENCE)) { - // Also track sentences used in the conversation. - conversation.addRelationship(Primitive.SENTENCE, sentence); - } - } - - /** - * Add the sentence from the previous input to the relationships response meta info. - */ - public static void addSentencePreviousMeta(Relationship relationship, Vertex previousQuestionInput, Network network) { - // Associate previous question as meta info. - if (previousQuestionInput != null) { - Vertex previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - if (previousQuestion != null) { - Vertex meta = network.createMeta(relationship); - meta.addRelationship(Primitive.PREVIOUS, previousQuestion); - } - } - } - - /** - * Add the keywords as required keywords for a response match to the question meta. - */ - public static void addSentenceKeyWordsMeta(Vertex question, Vertex answer, String keywords, Network network) { - if (keywords == null || keywords.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.KEYWORD, network); - } else { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.KEYWORD); - List words = Utils.getWords(keywords); - for (String keyword : words) { - Vertex word = network.createWord(keyword); - meta.addRelationship(Primitive.KEYWORD, word); - word.addRelationship(Primitive.INSTANTIATION, Primitive.KEYWORD); - word.addRelationship(Primitive.KEYQUESTION, question); - - Vertex lowercase = network.createWord(keyword.toLowerCase()); - if (lowercase != word) { - meta.addRelationship(Primitive.KEYWORD, lowercase); - lowercase.addRelationship(Primitive.INSTANTIATION, Primitive.KEYWORD); - lowercase.addRelationship(Primitive.KEYQUESTION, question); - } - } - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.KEYWORD); - List words = Utils.getWords(keywords); - for (String keyword : words) { - Vertex word = network.createWord(keyword); - meta.addRelationship(Primitive.KEYWORD, word); - word.addRelationship(Primitive.KEYQUESTION, question); - - Vertex lowercase = network.createWord(keyword.toLowerCase()); - if (lowercase != word) { - meta.addRelationship(Primitive.KEYWORD, lowercase); - lowercase.addRelationship(Primitive.KEYQUESTION, question); - } - } - - } - } - } - } - } - - /** - * Add the emotes to the response. - */ - public static void addSentenceEmotesMeta(Vertex question, Vertex answer, String emotes, Network network) { - if (emotes == null || emotes.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.EMOTION, network); - } else { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.EMOTION); - List words = Utils.getWords(emotes); - for (String emote : words) { - EmotionalState.valueOf(emote.toUpperCase()).apply(meta); - } - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.EMOTION); - List words = Utils.getWords(emotes); - for (String emote : words) { - EmotionalState.valueOf(emote.toUpperCase()).apply(meta); - } - } - } - } - } - } - - /** - * Add the actions to the response. - */ - public static void addSentenceActionMeta(Vertex question, Vertex answer, String actions, Network network) { - if (actions == null || actions.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.ACTION, network); - } else { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.ACTION); - List words = Utils.getWords(actions); - for (String action : words) { - if (!action.equals("none")) { - meta.addRelationship(Primitive.ACTION, new Primitive(action)); - } - } - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.ACTION); - List words = Utils.getWords(actions); - for (String action : words) { - if (!action.equals("none")) { - meta.addRelationship(Primitive.ACTION, new Primitive(action)); - } - } - } - } - } - } - } - - /** - * Add the actions to the response. - */ - public static void addSentencePoseMeta(Vertex question, Vertex answer, String poses, Network network) { - if (poses == null || poses.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.POSE, network); - } else { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.POSE); - List words = Utils.getWords(poses); - for (String pose : words) { - if (!pose.equals("none")) { - meta.addRelationship(Primitive.POSE, new Primitive(pose)); - } - } - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.POSE); - List words = Utils.getWords(poses); - for (String pose : words) { - if (!pose.equals("none")) { - meta.addRelationship(Primitive.POSE, new Primitive(pose)); - } - } - } - } - } - } - } - - /** - * Add the previous for a response match to the question meta. - */ - public static void addSentencePreviousMeta(Vertex question, Vertex answer, Vertex previous, boolean require, Network network) { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = relationship.getMeta(); - if (previous != null) { - meta = network.createMeta(relationship); - meta.addRelationship(Primitive.PREVIOUS, previous); - } - if (meta != null) { - if (require) { - meta.addRelationship(Primitive.REQUIRE, Primitive.PREVIOUS); - } else { - Relationship required = meta.getRelationship(Primitive.REQUIRE, Primitive.PREVIOUS); - if (required != null) { - relationship.getMeta().internalRemoveRelationship(required); - } - } - } - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = relationship.getMeta(); - if (previous != null) { - meta = network.createMeta(relationship); - meta.addRelationship(Primitive.PREVIOUS, previous); - } - if (meta != null) { - if (require) { - meta.addRelationship(Primitive.REQUIRE, Primitive.PREVIOUS); - } else { - Relationship required = meta.getRelationship(Primitive.REQUIRE, Primitive.PREVIOUS); - if (required != null) { - relationship.getMeta().internalRemoveRelationship(required); - } - } - } - } - } - } - } - - /** - * Add the keywords as required keywords for a response match to the question meta. - */ - public static void addSentenceRequiredMeta(Vertex question, Vertex answer, String required, Network network) { - if (required == null || required.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.REQUIRED, network); - } else { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.REQUIRED); - List words = Utils.getWords(required); - for (String keyword : words) { - Vertex word = network.createWord(keyword); - meta.addRelationship(Primitive.REQUIRED, word); - word.addRelationship(Primitive.QUESTION, question); - } - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.internalRemoveRelationships(Primitive.REQUIRED); - List words = Utils.getWords(required); - for (String keyword : words) { - meta.addRelationship(Primitive.REQUIRED, network.createWord(keyword)); - } - } - } - } - } - } - - /** - * Add the topic as a desired topic for a response match to the question meta. - */ - public static void addSentenceTopicMeta(Vertex question, Vertex answer, String topic, Network network) { - if (topic == null || topic.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.TOPIC, network); - } else { - Vertex topicFragment = network.createFragment(topic); - topicFragment.addRelationship(Primitive.INSTANTIATION, Primitive.TOPIC); - network.createVertex(Primitive.TOPIC).addRelationship(Primitive.INSTANCE, topicFragment); - topicFragment.addRelationship(Primitive.QUESTION, question); - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.TOPIC, topicFragment); - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.TOPIC, topicFragment); - } - } - } - } - } - - /** - * Add the new response. - */ - public static void addResponse(Vertex question, Vertex answer, Network network) { - addResponse(question, answer, null, null, null, 0.5f, network); - } - - /** - * Add the new response. - */ - public static void addResponse(Vertex question, Vertex answer, String topic, String keywords, String required, Network network) { - addResponse(question, answer, topic, keywords, required, 0.5f, network); - } - - /** - * Add the new response. - */ - public static void addResponse(Vertex question, Vertex answer, String topic, String keywords, String required, float correctness, Network network) { - question.addWeakRelationship(Primitive.RESPONSE, answer, correctness); - question.associateAll(Primitive.WORD, question, Primitive.QUESTION); - network.checkReduction(question); - question.weakAssociateAll(Primitive.SYNONYM, answer, Primitive.RESPONSE, correctness); - if (topic != null && !topic.isEmpty()) { - Language.addSentenceTopicMeta(question, answer, topic, network); - } - if (keywords != null && !keywords.isEmpty()) { - Language.addSentenceKeyWordsMeta(question, answer, keywords, network); - } - if (required != null && !required.isEmpty()) { - Language.addSentenceRequiredMeta(question, answer, required, network); - } - } - - /** - * Add the command as the command for a response match to the question meta. - */ - public static void addSentenceCommandMeta(Vertex question, Vertex answer, String command, Network network) { - if (command == null || command.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.COMMAND, network); - } else { - Vertex expression = network.createTemplate("Template(\"{Http.toJSON(" + command + ")}\")"); - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.COMMAND, expression); - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.COMMAND, expression); - } - } - } - } - } - - /** - * Add the script as the think for a response match to the question meta. - */ - public static void addSentenceThinkMeta(Vertex question, Vertex answer, String think, Network network) { - if (think == null || think.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.THINK, network); - } else { - Vertex expression = network.createTemplate("Template(\"{think {" + think + "}}\")"); - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.THINK, expression); - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.THINK, expression); - } - } - } - } - } - - /** - * Add the script as the condition for a response match to the question meta. - */ - public static void addSentenceConditionMeta(Vertex question, Vertex answer, String condition, Network network) { - if (condition == null || condition.trim().isEmpty()) { - clearSentenceMeta(question, answer, Primitive.CONDITION, network); - } else { - Vertex expression = network.createTemplate("Template(\"{if (true == (" + condition + ")) { \"true\" } else { \"false\" }}\")"); - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.CONDITION, expression); - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null) { - Vertex meta = network.createMeta(relationship); - meta.setRelationship(Primitive.CONDITION, expression); - } - } - } - } - } - - /** - * Clear any relations in the meta of the type. - */ - public static void clearSentenceMeta(Vertex question, Vertex answer, Primitive type, Network network) { - Relationship relationship = question.getRelationship(Primitive.RESPONSE, answer); - if (relationship != null && relationship.hasMeta()) { - relationship.getMeta().internalRemoveRelationships(type); - } - network.checkReduction(question); - Collection synonyms = question.getRelationships(Primitive.SYNONYM); - if (synonyms != null) { - for (Relationship synonym : synonyms) { - relationship = synonym.getTarget().getRelationship(Primitive.RESPONSE, answer); - if (relationship != null && relationship.hasMeta()) { - relationship.getMeta().internalRemoveRelationships(type); - } - } - } - } - - /** - * Add the sentence from the previous input to the relationships response meta info. - */ - public static boolean addCorrection(Vertex originalQuestionInput, Vertex originalQuestion, Vertex wrongResponseInput, Vertex correction, Vertex previousQuestionInput, Network network) { - boolean wasCorrect= false; - Relationship relationship = null; - if (wrongResponseInput != null) { - Vertex wrongResponse = wrongResponseInput.mostConscious(Primitive.INPUT); - // If correcting with same answer, then don't uncorrect. - if (wrongResponse != correction) { - relationship = originalQuestion.getRelationship(Primitive.RESPONSE, wrongResponse); - // Could be a wrong response, or just a wrong response in the context. - // First mark wrong in context, then mark wrong in general. - if ((relationship == null) || (relationship.getCorrectness() < 0.5)) { - originalQuestion.removeRelationship(Primitive.RESPONSE, wrongResponse); - network.checkReduction(originalQuestion); - originalQuestion.inverseAssociateAll(Primitive.SYNONYM, wrongResponse, Primitive.RESPONSE); - } else { - relationship.setCorrectness(relationship.getCorrectness() / 2); - originalQuestionInput.removeRelationship(Primitive.RESPONSE, wrongResponseInput); - // Dissociate previous question as meta info. - removeSentencePreviousMeta(relationship, previousQuestionInput, network); - } - } else { - wasCorrect = true; - } - Vertex input = wrongResponseInput.copy(); - input.addRelationship(Primitive.ASSOCIATED, Primitive.CORRECTION); - input.setRelationship(Primitive.INPUT, correction); - relationship = network.getBot().mind().getThought(Comprehension.class).checkTemplate(input, network); - if (relationship != null) { - correction = relationship.getTarget(); - } - } - relationship = originalQuestion.addRelationship(Primitive.RESPONSE, correction); - if (!originalQuestion.instanceOf(Primitive.PATTERN)) { - originalQuestion.associateAll(Primitive.WORD, originalQuestion, Primitive.QUESTION); - } - network.checkReduction(originalQuestion); - originalQuestion.associateAll(Primitive.SYNONYM, correction, Primitive.RESPONSE); - correction.addRelationship(Primitive.QUESTION, originalQuestion); - originalQuestion.setPinned(true); - correction.setPinned(true); - // Associate previous question as meta info. - addSentencePreviousMeta(relationship, previousQuestionInput, network); - return wasCorrect; - } - - /** - * Remove the sentence from the previous input to the relationships response meta info. - */ - public static void removeSentencePreviousMeta(Relationship relationship, Vertex previousQuestionInput, Network network) { - // Associate previous question as meta info. - if (previousQuestionInput != null) { - Vertex previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - if (previousQuestion != null) { - Vertex meta = network.createMeta(relationship); - meta.removeRelationship(Primitive.PREVIOUS, previousQuestion); - } - } - } - - /** - * Create a new thought. - */ - public Language() { - } - - @Override - public void awake() { - String property = this.bot.memory().getProperty("Language.enableEmote"); - if (property != null) { - setEnableEmote(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.language"); - if (property != null) { - setLanguage(property); - } - property = this.bot.memory().getProperty("Language.learningMode"); - if (property != null) { - setLearningMode(LearningMode.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.maxResponseMatchProcess"); - if (property != null) { - setMaxResponseMatchProcess(Integer.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.maxStateProcess"); - if (property != null) { - setMaxStateProcess(Integer.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.conversationMatchPercentage"); - if (property != null) { - setConversationMatchPercentage(Float.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.discussionMatchPercentage"); - if (property != null) { - setDiscussionMatchPercentage(Float.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.learningRate"); - if (property != null) { - setLearningRate(Float.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.checkExactMatchFirst"); - if (property != null) { - setCheckExactMatchFirst(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.enableResponseMatch"); - if (property != null) { - setEnableResponseMatch(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.learnGrammar"); - if (property != null) { - setLearnGrammar(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.splitParagraphs"); - if (property != null) { - setSplitParagraphs(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.synthesizeResponse"); - if (property != null) { - setSynthesizeResponse(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.fixFormulaCase"); - if (property != null) { - setFixFormulaCase(Boolean.valueOf(property)); - } - property = this.bot.memory().getProperty("Language.correctionMode"); - if (property != null) { - setCorrectionMode(CorrectionMode.valueOf(property)); - } - } - - /** - * Migrate to new properties system. - */ - public void migrateProperties() { - Network memory = getBot().memory().newMemory(); - Vertex language = memory.createVertex(getPrimitive()); - Vertex property = language.getRelationship(Primitive.EMOTE); - if (property != null) { - setEnableEmote((Boolean)property.getData()); - } - property = language.getRelationship(Primitive.LANGUAGE); - if (property != null) { - setLanguage((String)property.getData()); - } - property = language.getRelationship(Primitive.LEARNING); - if (property != null) { - setLearningMode(LearningMode.valueOf((String)property.getData())); - } - property = language.getRelationship(Primitive.MAXRESPONSEMATCHPROCESS); - if (property != null) { - setMaxResponseMatchProcess((Integer)property.getData()); - } - property = language.getRelationship(Primitive.MAXSTATEPROCESS); - if (property != null) { - setMaxStateProcess((Integer)property.getData()); - } - property = language.getRelationship(Primitive.CONVERSATIONMATCHPERCENTAGE); - if (property != null) { - setConversationMatchPercentage((Float)property.getData()); - } - property = language.getRelationship(Primitive.DISCUSSIONMATCHPERCENTAGE); - if (property != null) { - setDiscussionMatchPercentage((Float)property.getData()); - } - property = language.getRelationship(Primitive.LEARNINGRATE); - if (property != null) { - setLearningRate((Float)property.getData()); - } - property = language.getRelationship(Primitive.CHECKEXACTMATCHFIRST); - if (property != null) { - setCheckExactMatchFirst((Boolean)property.getData()); - } - property = language.getRelationship(Primitive.ENABLERESPONSEMATCH); - if (property != null) { - setEnableResponseMatch((Boolean)property.getData()); - } - property = language.getRelationship(Primitive.LEARNGRAMMAR); - if (property != null) { - setLearnGrammar((Boolean)property.getData()); - } - property = language.getRelationship(Primitive.FIXFORMULACASE); - if (property != null) { - setFixFormulaCase((Boolean)property.getData()); - } - property = language.getRelationship(Primitive.CORRECTION); - if (property != null) { - if (property.getData() instanceof Boolean) { - if ((Boolean)property.getData()) { - setCorrectionMode(CorrectionMode.Everyone); - } else { - setCorrectionMode(CorrectionMode.Administrators); - } - } else { - setCorrectionMode(CorrectionMode.valueOf((String)property.getData())); - } - } - - // Remove old properties. - language.internalRemoveRelationships(Primitive.EMOTE); - language.internalRemoveRelationships(Primitive.LANGUAGE); - language.internalRemoveRelationships(Primitive.LEARNING); - language.internalRemoveRelationships(Primitive.MAXRESPONSEMATCHPROCESS); - language.internalRemoveRelationships(Primitive.MAXSTATEPROCESS); - language.internalRemoveRelationships(Primitive.CONVERSATIONMATCHPERCENTAGE); - language.internalRemoveRelationships(Primitive.DISCUSSIONMATCHPERCENTAGE); - language.internalRemoveRelationships(Primitive.LEARNINGRATE); - language.internalRemoveRelationships(Primitive.CHECKEXACTMATCHFIRST); - language.internalRemoveRelationships(Primitive.ENABLERESPONSEMATCH); - language.internalRemoveRelationships(Primitive.LEARNGRAMMAR); - language.internalRemoveRelationships(Primitive.FIXFORMULACASE); - language.internalRemoveRelationships(Primitive.CORRECTION); - - memory.save(); - - saveProperties(); - } - - public CorrectionMode getCorrectionMode() { - return correctionMode; - } - - public void setCorrectionMode(CorrectionMode correctionMode) { - this.correctionMode = correctionMode; - } - - public LearningMode getLearningMode() { - return learningMode; - } - - public void setLearningMode(LearningMode learningMode) { - this.learningMode = learningMode; - } - - public boolean getEnableResponseMatch() { - return enableResponseMatch; - } - - public void setEnableResponseMatch(boolean enableResponseMatch) { - this.enableResponseMatch = enableResponseMatch; - } - - public boolean getCheckExactMatchFirst() { - return checkExactMatchFirst; - } - - public void setCheckExactMatchFirst(boolean checkExactMatchFirst) { - this.checkExactMatchFirst = checkExactMatchFirst; - } - - public float getConversationMatchPercentage() { - return conversationMatchPercentage; - } - - public void setConversationMatchPercentage(float conversationMatchPercentage) { - this.conversationMatchPercentage = conversationMatchPercentage; - } - - public boolean getSynthesizeResponse() { - return synthesizeResponse; - } - - public void setSynthesizeResponse(boolean synthesizeResponse) { - this.synthesizeResponse = synthesizeResponse; - } - - public float getLearningRate() { - return learningRate; - } - - public void setLearningRate(float learningRate) { - this.learningRate = learningRate; - } - - public float getDiscussionMatchPercentage() { - return discussionMatchPercentage; - } - - public void setDiscussionMatchPercentage(float discussionMatchPercentage) { - this.discussionMatchPercentage = discussionMatchPercentage; - } - - public int getMaxStateProcess() { - return maxStateProcess; - } - - public void setMaxStateProcess(int maxStateProcess) { - this.maxStateProcess = maxStateProcess; - } - - public int getMaxResponseMatchProcess() { - return maxResponseMatchProcess; - } - - public void setMaxResponseMatchProcess(int maxResponseMatchProcess) { - this.maxResponseMatchProcess = maxResponseMatchProcess; - } - - public boolean getFixFormulaCase() { - return fixFormulaCase; - } - - public void setFixFormulaCase(boolean fixFormulaCase) { - this.fixFormulaCase = fixFormulaCase; - } - - public boolean getLearnGrammar() { - return learnGrammar; - } - - public void setLearnGrammar(boolean learnGrammar) { - this.learnGrammar = learnGrammar; - } - - public void saveProperties() { - Network memory = getBot().memory().newMemory(); - - memory.saveProperty("Language.correctionMode", getCorrectionMode().name(), true); - memory.saveProperty("Language.enableEmote", String.valueOf(getEnableEmote()), true); - memory.saveProperty("Language.language", getLanguage(), true); - memory.saveProperty("Language.learningMode", getLearningMode().name(), true); - memory.saveProperty("Language.maxResponseMatchProcess", String.valueOf(getMaxResponseMatchProcess()), true); - memory.saveProperty("Language.maxStateProcess", String.valueOf(getMaxStateProcess()), true); - memory.saveProperty("Language.discussionMatchPercentage", String.valueOf(getDiscussionMatchPercentage()), true); - memory.saveProperty("Language.learningRate", String.valueOf(getLearningRate()), true); - memory.saveProperty("Language.conversationMatchPercentage", String.valueOf(getConversationMatchPercentage()), true); - memory.saveProperty("Language.enableResponseMatch", String.valueOf(getEnableResponseMatch()), true); - memory.saveProperty("Language.checkExactMatchFirst", String.valueOf(getCheckExactMatchFirst()), true); - memory.saveProperty("Language.learnGrammar", String.valueOf(getLearnGrammar()), true); - memory.saveProperty("Language.splitParagraphs", String.valueOf(getSplitParagraphs()), true); - memory.saveProperty("Language.synthesizeResponse", String.valueOf(getSynthesizeResponse()), true); - memory.saveProperty("Language.fixFormulaCase", String.valueOf(getFixFormulaCase()), true); - - memory.save(); - } - - public Map clearVoiceProperties() { - Map properties = new HashMap(); - Network memory = getBot().memory().newMemory(); - Vertex language = memory.createVertex(getPrimitive()); - Vertex property = language.getRelationship(Primitive.VOICE); - if (property != null) { - properties.put(Primitive.VOICE, property.getData()); - property.setPinned(false); - } - property = language.getRelationship(Primitive.NATIVEVOICE); - if (property != null) { - properties.put(Primitive.NATIVEVOICE, property.getData()); - property.setPinned(false); - } - property = language.getRelationship(Primitive.NATIVEVOICENAME); - if (property != null) { - properties.put(Primitive.NATIVEVOICENAME, property.getData()); - property.setPinned(false); - } - property = language.getRelationship(Primitive.PITCH); - if (property != null) { - properties.put(Primitive.PITCH, property.getData()); - property.setPinned(false); - } - property = language.getRelationship(Primitive.SPEECHRATE); - if (property != null) { - properties.put(Primitive.SPEECHRATE, property.getData()); - property.setPinned(false); - } - property = language.getRelationship(Primitive.LANGUAGE); - if (property != null) { - properties.put(Primitive.LANGUAGE, property.getData()); - } - - language.internalRemoveRelationships(Primitive.VOICE); - language.internalRemoveRelationships(Primitive.NATIVEVOICE); - language.internalRemoveRelationships(Primitive.NATIVEVOICENAME); - language.internalRemoveRelationships(Primitive.PITCH); - language.internalRemoveRelationships(Primitive.SPEECHRATE); - - memory.save(); - return properties; - } - - /** - * Stop analysing network. - */ - public void stop() { - pool(); - } - - /** - * Reset state when instance is pooled. - */ - @Override - public void pool() { - this.allowLearning = null; - } - - public Boolean getAllowLearning() { - return allowLearning; - } - - public void setAllowLearning(Boolean allowLearning) { - this.allowLearning = allowLearning; - } - - public boolean getSplitParagraphs() { - return splitParagraphs; - } - - public void setSplitParagraphs(boolean splitParagraphs) { - this.splitParagraphs = splitParagraphs; - } - - /** - * Analyse the active memory for language. - */ - public void think() { - if (isStopped() || !isEnabled()) { - return; - } - Network network = getShortTermMemory(); - List activeMemory = getBot().memory().getActiveMemory(); - for (int i = 0; i < activeMemory.size(); i++) { - Vertex vertex = network.createVertex(activeMemory.get(i)); - log("Processing", Level.FINER, vertex); - try { - if (vertex.instanceOf(Primitive.INPUT)) { - Vertex input = vertex; - List sentences = new ArrayList(); - List responses = new ArrayList(); - Vertex inputValue = input.getRelationship(Primitive.INPUT); - if (inputValue != null) { - for (Vertex sentence : input.orderedRelations(Primitive.INPUT)) { - if (sentence.instanceOf(Primitive.SENTENCE)) { - if (getSplitParagraphs()) { - // Check if the input is a paragraph. - Vertex paragraph = network.createParagraph(sentence); - if (paragraph.instanceOf(Primitive.PARAGRAPH)) { - sentences.addAll(paragraph.orderedRelations(Primitive.SENTENCE)); - } else { - sentences.add(paragraph); - } - } else { - sentences.add(sentence); - } - } else if (sentence.instanceOf(Primitive.PARAGRAPH)) { - sentences.addAll(sentence.orderedRelations(Primitive.SENTENCE)); - } - } - } - List targets = vertex.orderedRelationships(Primitive.TARGET); - Vertex target = null; - if (targets != null && (targets.size() == 1)) { - target = targets.get(0).getTarget(); - } - Vertex speaker = input.mostConscious(Primitive.SPEAKER); - Vertex self = network.createVertex(Primitive.SELF); - Vertex inputSense = input.mostConscious(Primitive.SENSE); - Vertex conversation = input.mostConscious(Primitive.CONVERSATION); - boolean correction = input.hasRelationship(Primitive.ASSOCIATED, Primitive.CORRECTION); - boolean offended = input.hasRelationship(Primitive.ASSOCIATED, Primitive.OFFENDED); - boolean newConversation = (inputValue != null) && (inputValue.is(Primitive.NULL)); - LanguageState state = LanguageState.Answering; - Sense sense = null; - if (inputSense != null) { - sense = getBot().awareness().getSense(((Primitive)inputSense.getData()).getIdentity()); - if (sense != null) { - state = sense.getLanguageState(); - } - } - // Create output. - Vertex output = network.createInstance(Primitive.INPUT); - try { - Vertex response = null; - int index = 0; - Map variables = new HashMap(); - SelfCompiler.addGlobalVariables(input, null, network, variables); - getBot().avatar().reset(); - if (newConversation) { - // If Correcting then this is a response to that previous question. - response = processGreeting(input, conversation, network, state, variables); - if (response != null) { - this.bot.mood().evaluateResponse(response, null); - this.bot.avatar().evaluateResponse(output, response, null, variables, network); - responses.add(response); - } - } else { - for (Vertex sentence : sentences) { - checkQuestion(sentence, network); - if (PROCESS_HTTP) { - // TODO make this occur in discovery - //processHttp(sentence, network); - } - log("Processing sentence", Level.FINE, sentence, speaker, targets); - if (offended) { - // If offensive then remove the last sentence. - processOffensive(input, speaker, target, conversation, network); - } - if (correction) { - // If Correcting then this is a response to that previous question. - response = processCorrection(input, sentence, speaker, target, conversation, network); - } else if (state == LanguageState.Associate) { - // Associate the context selection with the sentence. - response = processAssociation(sentence, network); - } else if ((state == LanguageState.Listening) || (state == LanguageState.ListeningOnly)) { - processListening(input, sentence, speaker, conversation, targets, network, state); - // If target is self, then give an answer. - if ((state == LanguageState.Listening) && (target == self)) { - response = processConversational(input, sentence, conversation, variables, network, state); - } else { - // Associate response, process understanding, but don't respond. - processUnderstanding(input, sentence, this.conversationMatchPercentage, variables, network); - return; - } - } else if (state == LanguageState.Discussion) { - processListening(input, sentence, speaker, conversation, targets, network, state); - // If target is self, then give an answer. - if (target == self) { - response = processConversational(input, sentence, conversation, variables, network, state); - } else if ((targets == null) || targets.isEmpty() || (targets.size() > 1)) { - // Process anything to a group, or to no one as a discussion. - response = processDiscussion(input, sentence, conversation, variables, network); - } else { - processUnderstanding(input, sentence, this.conversationMatchPercentage, variables, network); - log("Discussion response to other", Level.FINE, targets); - } - } else if (state == LanguageState.Conversational) { - processListening(input, sentence, speaker, conversation, targets, network, state); - response = processConversational(input, sentence, conversation, variables, network, state); - } else if (state == LanguageState.Answering) { - processListening(input, sentence, speaker, conversation, targets, network, state); - response = processConversational(input, sentence, conversation, variables, network, state); - } - // Check for label - if ((response != null) && response.instanceOf(Primitive.LABEL)) { - response = response.mostConscious(Primitive.RESPONSE); - } - // Check for formula and transpose - if ((response != null) && response.instanceOf(Primitive.FORMULA)) { - log("Response is template formula", Level.FINE, response); - Vertex result = evaluateFormula(response, variables, network); - if (result == null) { - log("Template formula cannot be evaluated", Level.FINE, response); - response = null; - } else { - response = getWord(result, network); - } - } - if ((response != null) && !(response.getData() instanceof String)) { - response = getWord(response, network); - } - if (response == null || (!(response.getData() instanceof String) && !response.instanceOf(Primitive.PARAGRAPH))) { - // Answering must respond. - if (state == LanguageState.Answering) { - response = sentence; - } else { - continue; - } - } - log("Response", Level.INFO, response, speaker, conversation); - index++; - if ((sentences.size() == 1) || sentence.instanceOf(Primitive.QUESTION) || (index == sentences.size())) { - - if (!response.hasRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE)) { - Vertex meta = null; - if (this.lastResponseMetaId != null) { - meta = network.findById(this.lastResponseMetaId); - this.lastResponseMetaId = null; - } - this.bot.mood().evaluateResponse(response, meta); - this.bot.avatar().evaluateResponse(output, response, meta, variables, network); - responses.add(response); - } else { - response = checkDuplicateOrOffensiveResponse(response, sentence, conversation, input, variables, network, true, false); - if (!response.hasRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE)) { - Vertex meta = null; - if (this.lastResponseMetaId != null) { - meta = network.findById(this.lastResponseMetaId); - this.lastResponseMetaId = null; - } - this.bot.mood().evaluateResponse(response, meta); - this.bot.avatar().evaluateResponse(output, response, meta, variables, network); - responses.add(response); - } - } - } - } - } - if (responses.isEmpty()) { - if (sense != null) { - sense.notifyExceptionListeners(new BotException("No response")); - } - return; - } - if (inputSense != null) { - // Associate input sense with output. - output.addRelationship(Primitive.SENSE, inputSense); - } - if (speaker != null) { - output.addRelationship(Primitive.TARGET, speaker); - } - Vertex topic = input.mostConscious(Primitive.TOPIC); - if (topic != null) { - output.addRelationship(Primitive.TOPIC, topic); - } - if (input.hasRelationship(Primitive.ASSOCIATED, Primitive.WHISPER)) { - output.addRelationship(Primitive.ASSOCIATED, Primitive.WHISPER); - } - if (!newConversation) { - output.addRelationship(Primitive.QUESTION, input); - input.addRelationship(Primitive.RESPONSE, output); - } - output.addRelationship(Primitive.SPEAKER, self); - //self.addRelationship(Primitive.INPUT, output); - if (responses.get(0).getData() != null) { - output.setName(responses.get(0).getData().toString()); - } - if (responses.size() == 1) { - if (this.wasMimic) { - output.addRelationship(Primitive.MIMIC, input); - } - response = responses.get(0); - output.addRelationship(Primitive.INPUT, response); - } else { - Vertex paragraph = network.createInstance(Primitive.PARAGRAPH); - index = 0; - for (Vertex each : responses) { - paragraph.addRelationship(Primitive.SENTENCE, each, index); - index++; - } - output.addRelationship(Primitive.INPUT, paragraph); - } - if (conversation != null) { - Language.addToConversation(output, conversation); - } - this.wasMimic = false; - // Record response time. - output.setCreationDate(new Date()); - getBot().memory().save(); - // Allow the sense to output the response. - LogUtils.e("[Language]---->output-think",output.printString()); - getBot().awareness().output(output); - } catch (RuntimeException exception) { - if (sense != null) { - sense.notifyExceptionListeners(exception); - } - throw exception; - } - } - } finally { - this.recursiveInputDepth = 0; - this.recursiveFormulaDepth = 0; - this.startTime = 0; - this.abort = false; - } - } - } - - /** - * Process the input and return the response. - */ - public Vertex input(Vertex input, Vertex sentence, Map variables, Network network) { - log("REDIRECT", Level.FINE, sentence, this.recursiveInputDepth); - if (this.recursiveInputDepth >= MAX_DEPTH) { - if (this.recursiveInputDepth == MAX_DEPTH) { - this.recursiveInputDepth++; - log("Input", Level.WARNING, "Max recursive depth exceeded", this.recursiveInputDepth, sentence); - } - return null; - } - this.recursiveInputDepth++; - // Check for formula and transpose - if (sentence.instanceOf(Primitive.FORMULA)) { - Vertex result = evaluateFormula(sentence, variables, network); - if (result == null) { - log("Template formula cannot be evaluated", Level.FINE, sentence); - return null; - } else { - sentence = getWord(result, network); - } - } - if (sentence.hasRelationship(Primitive.INSTANTIATION, Primitive.SENTENCE) && (sentence.getData() == null)) { - sentence = createSentenceText(sentence, network); - } else if (!sentence.hasRelationship(Primitive.INSTANTIATION, Primitive.SENTENCE) && (sentence.getData() instanceof String)) { - sentence = network.createSentence((String)sentence.getData(), true, false, false); - } - Vertex conversation = input.getRelationship(Primitive.CONVERSATION); - Vertex response = processConversational(input, sentence, conversation, variables, network, LanguageState.Answering); - if ((response != null) && response.instanceOf(Primitive.FORMULA)) { - log("Response is template formula", Level.FINE, response); - SelfCompiler.addGlobalVariables(input, sentence, network, variables); - Vertex result = evaluateFormula(response, variables, network); - if (result == null) { - log("Template formula cannot be evaluated", Level.FINE, response); - response = null; - } else { - response = getWord(result, network); - } - } - this.wasMimic = false; - return response; - } - - /** - * Evaluate the sentence formula/template in the context of the input. - */ - public Vertex evaluateFormula(Vertex formula, Map variables, Network network) { - return evaluateFormulaTemplate(formula, variables, System.currentTimeMillis(), network); - } - - /** - * Evaluate the sentence formula/template in the context of the input. - */ - public Vertex evaluateFormulaTemplate(Vertex formula, Map variables, long startTime, Network network) { - try { - //sentence.addRelationship(Primitive.FORMULA, formula); - List relationships = formula.orderedRelations(Primitive.WORD); - if (relationships == null) { - return null; - } - List words = new ArrayList(relationships.size()); - boolean caseSensitive = false; - long processTime = Math.min(this.maxStateProcess, MAX_PROCCESS_TIME); - if (getBot().isDebugFiner()) { - processTime = processTime * 10; - } - for (Vertex word : relationships) { - if ((System.currentTimeMillis() - startTime) > processTime) { - throw new SelfExecutionException(formula, "Max formula processing time exceeded"); - } - Vertex result = null; - if (word.is(Primitive.WILDCARD)) { - Vertex value = variables.get(word); - if (value == null) { - return null; - } - result = value; - } else if (word.instanceOf(Primitive.VARIABLE)) { - Vertex value = variables.get(word); - if (value == null) { - if (word.hasName()) { - value = variables.get(word.getName()); - } - if (value == null) { - return null; - } - } - result = value; - } else if (word.instanceOf(Primitive.EXPRESSION) || word.instanceOf(Primitive.EQUATION)) { - Vertex quotient = SelfInterpreter.getInterpreter().evaluateExpression(word, variables, network, startTime, processTime, 0); - variables.remove(network.createVertex(Primitive.RETURN)); - if (quotient == null) { - return null; - } - while (quotient.instanceOf(Primitive.FORMULA)) { - this.recursiveFormulaDepth++; - if (this.recursiveFormulaDepth > MAX_DEPTH) { - throw new SelfExecutionException(word, "Max recursive template formula execution"); - } - quotient = evaluateFormulaTemplate(quotient, variables, startTime, network); - this.recursiveFormulaDepth--; - if (quotient == null) { - return null; - } - } - if (quotient.is(Primitive.NULL)) { - return null; - } else if (quotient.is(Primitive.RETURN)) { - // think: just execute the equation. - } else { - result = quotient; - } - if (result != null && result.hasRelationship(Primitive.TYPE, Primitive.CASESENSITVE)) { - caseSensitive = true; - } - } else { - result = word; - } - if (result != null) { - if (result.instanceOf(Primitive.WORD)) { - words.add(result); - } else if (result.instanceOf(Primitive.SENTENCE) || result.instanceOf(Primitive.FRAGMENT)) { - if (relationships.size() == 1 && (result.instanceOf(Primitive.SENTENCE))) { - return result; - } - Vertex space = null; - Vertex sentenceWithSpaces = result; - // Check if sentence has text or not. - if (result.getData() instanceof String) { - // It is has text, and doesn't contain any spaces, then it must be reparsed with spaces. - if (!result.hasRelationship(Primitive.TYPE, Primitive.SPACE) && !result.hasRelationship(Primitive.WORD, Primitive.SPACE) - && ((result.getRelationships(Primitive.WORD) == null) || (result.getRelationships(Primitive.WORD).size() > 1))) { - sentenceWithSpaces = network.createSentence((String)result.getData(), true, false, true); - } - } else { - // It is a dynamic sentence, may need to add spaces. - if (!result.hasRelationship(Primitive.TYPE, Primitive.SPACE) && !result.hasRelationship(Primitive.WORD, Primitive.SPACE)) { - space = network.createVertex(Primitive.SPACE); - } - } - List nestedWords = sentenceWithSpaces.orderedRelations(Primitive.WORD); - if (nestedWords != null) { - for (int index = 0; index < nestedWords.size(); index++) { - Vertex nestedWord = nestedWords.get(index); - words.add(nestedWord); - if ((space != null) && (index < (nestedWords.size() - 1))) { - words.add(space); - } - } - } - } else { - words.add(result); - } - } - } - Vertex sentence = network.createTemporyVertex(); - sentence.addRelationship(Primitive.INSTANTIATION, Primitive.SENTENCE); - if (formula.hasRelationship(Primitive.TYPE, Primitive.SPACE) || formula.hasRelationship(Primitive.WORD, Primitive.SPACE)) { - sentence.addRelationship(Primitive.TYPE, Primitive.SPACE); - } - if (caseSensitive) { - sentence.addRelationship(Primitive.TYPE, Primitive.CASESENSITVE); - } - Vertex previous = network.createVertex(Primitive.NULL); - for (int index = 0; index < words.size(); index++) { - if ((System.currentTimeMillis() - startTime) > processTime) { - throw new SelfExecutionException(formula, "Max formula processing time exceeded"); - } - Vertex word = words.get(index); - if (word.is(Primitive.SPACE)) { - sentence.addRelationship(Primitive.WORD, word, index); - continue; - } - Vertex next = null; - if (words.size() > (index + 1)) { - next = words.get(index + 1); - int nextIndex = index + 2; - while (next.is(Primitive.SPACE) && (nextIndex < words.size())) { - next = words.get(nextIndex); - nextIndex++; - } - } else { - next = network.createVertex(Primitive.NULL); - } - word = getWordFollowing(word, previous, next, network); - sentence.addRelationship(Primitive.WORD, word, index); - previous = word; - } - return createSentenceText(sentence, network); - } catch (Exception exception) { - log(exception); - return null; - } - } - - /** - * Determine if the pattern matches the sentence. - */ - public static boolean evaluatePattern(Vertex pattern, Vertex sentence, Primitive variable, Map variables, Network network) { - List elements = pattern.orderedRelations(Primitive.WORD); - List words = sentence.orderedRelations(Primitive.WORD); - if (words == null && (sentence.getData() instanceof String) && (!((String)sentence.getData()).isEmpty())) { - // Sentence may not have been parsed. - sentence = network.createSentence(sentence.getDataValue()); - words = sentence.orderedRelations(Primitive.WORD); - } - if (elements == null && (pattern.getData() instanceof String) && (!((String)pattern.getData()).isEmpty()) && (!((String)pattern.getData()).startsWith("Pattern"))) { - // Sentence may not have been parsed. - sentence = network.createSentence(pattern.getDataValue()); - elements = sentence.orderedRelations(Primitive.WORD); - } - if (elements == null || words == null) { - return false; - } - boolean result = evaluatePattern(pattern, sentence, variable, variables, network, elements, words, 0); - return result; - } - - public static boolean isPunctuation(Vertex word) { - if (word.instanceOf(Primitive.PUNCTUATION)) { - return true; - } - if (!(word.getData() instanceof String)) { - return false; - } - if (word.getDataValue().length() != 1) { - return false; - } - char character = word.getDataValue().charAt(0); - if (!Character.isLetterOrDigit(character)) { - return true; - } - return false; - } - - /** - * Determine if the pattern matches the sentence. - */ - public static boolean evaluatePattern(Vertex pattern, Vertex sentence, Primitive variable, Map variables, Network network, - List elements, List words, int wildcardSkip) { - boolean wasWildcard = false; - int elementIndex = 0; - int wildcardSkips = 0; - boolean end = false; - boolean hadMatchAfterWildcard = false; - List> star = new ArrayList>(); - List currentStar = null; - for (int index = 0; index < words.size(); index++) { - if (elementIndex >= elements.size()) { - if (!wasWildcard) { - // Ignore trailing punctuation. - while (index < words.size()) { - Vertex word = words.get(index); - if (!isPunctuation(word)) { - if (hadMatchAfterWildcard) { - return evaluatePattern(pattern, sentence, variable, variables, network, elements, words, wildcardSkip + 1); - } - return false; - } - index++; - } - recordStar(star, variable, variables, network); - return true; - } - end = true; - } - Vertex element = null; - if (!end) { - element = elements.get(elementIndex); - } - Vertex word = words.get(index); - boolean required = true; - if (element != null) { - boolean found = false; - if (element == word || element.equals(word)) { - found = true; - } - if (!found && (element.is(Primitive.WILDCARD) || element.is(Primitive.UNDERSCORE) || element.is(Primitive.HATWILDCARD) || element.is(Primitive.POUNDWILDCARD))) { - wasWildcard = true; - if (currentStar != null) { - star.add(currentStar); - } - currentStar = new ArrayList(); - elementIndex++; - // * must match at least one word. - if (element.is(Primitive.WILDCARD) || element.is(Primitive.UNDERSCORE) || elementIndex >= elements.size()) { - currentStar.add(word); - continue; - } - if (elementIndex < elements.size()) { - element = elements.get(elementIndex); - } - while (((elementIndex + 1) < elements.size()) && element.is(Primitive.HATWILDCARD) || element.is(Primitive.POUNDWILDCARD)) { - elementIndex++; - element = elements.get(elementIndex); - } - } - if (!found) { - if (element.instanceOf(Primitive.ARRAY)) { - required = (element.hasRelationship(Primitive.TYPE, Primitive.REQUIRED)); - Collection values = element.getRelationships(Primitive.ELEMENT); - if (values != null) { - for (Relationship value : values) { - if (value.getTarget().getData() instanceof String && word.getData() instanceof String) { - if (((String)value.getTarget().getData()).equalsIgnoreCase((String)word.getData())) { - found = true; - } - } else if (value.getTarget().hasRelationship(Primitive.WORD, word)) { - found = true; - } - if (found) { - break; - } - } - } - } else if (element.instanceOf(Primitive.LIST)) { - required = (element.hasRelationship(Primitive.TYPE, Primitive.REQUIRED)); - Collection values = element.getRelationships(Primitive.SEQUENCE); - if (values != null) { - for (Relationship value : values) { - if (value.getTarget().getData() instanceof String && word.getData() instanceof String) { - if (((String)value.getTarget().getData()).equalsIgnoreCase((String)word.getData())) { - found = true; - } - } else if (value.getTarget().hasRelationship(Primitive.WORD, word)) { - found = true; - } - if (found) { - break; - } - } - } - } - } - if (!found) { - if (element.instanceOf(Primitive.EXPRESSION) || element.instanceOf(Primitive.EQUATION)) { - element = SelfInterpreter.getInterpreter().evaluateExpression(element, variables, network, System.currentTimeMillis(), MAX_RESPONSE_PROCESS, 0); - } - if (element.instanceOf(Primitive.VARIABLE) - && !(element.is(Primitive.WILDCARD) || element.is(Primitive.UNDERSCORE) - || element.is(Primitive.HATWILDCARD) || element.is(Primitive.POUNDWILDCARD))) { - found = element.matches(word, variables) == Boolean.TRUE; - currentStar = new ArrayList(); - currentStar.add(word); - star.add(currentStar); - currentStar = null; - wasWildcard = false; - } - } - if (!found && (element == word || element.equals(word))) { - found = true; - } - if (!found && element.getData() instanceof String && word.getData() instanceof String) { - if (((String)element.getData()).equalsIgnoreCase((String)word.getData())) { - found = true; - } - } else if (!found) { - // Element is an object, check all words for match. - if (element.hasRelationship(Primitive.WORD, word)) { - found = true; - } - } - if (found) { - // Must skip matching words to check for other matches if the same word is in the phrase twice. - if (wasWildcard && (wildcardSkips < wildcardSkip)) { - wildcardSkips++; - currentStar.add(word); - continue; - } else { - hadMatchAfterWildcard = hadMatchAfterWildcard || (wasWildcard && elementIndex < elements.size()); - elementIndex++; - wasWildcard = false; - if (currentStar != null) { - star.add(currentStar); - } - currentStar = null; - continue; - } - } - } - if ("<".equals(word.getDataValue())) { - boolean foundEndTag = false; - int tagIndex = index; - tagIndex++; - // Ignore HTML tags - while (tagIndex < words.size()) { - Vertex next = words.get(tagIndex); - if (">".equals(next.getDataValue())) { - foundEndTag = true; - break; - } - tagIndex++; - } - if (foundEndTag) { - index = tagIndex; - continue; - } - } - if (word.instanceOf(Primitive.PUNCTUATION)) { - continue; // Only ignore real punctuation. - } - if (wasWildcard) { - if (!required) { - elementIndex++; - index--; - continue; - } - currentStar.add(word); - continue; - } - if (isPunctuation(word)) { - continue; - } - if (!required) { - elementIndex++; - index--; - continue; - } - if (hadMatchAfterWildcard) { - return evaluatePattern(pattern, sentence, variable, variables, network, elements, words, wildcardSkip + 1); - } - return false; - } - while (elementIndex < elements.size()) { - Vertex element = elements.get(elementIndex); - if (element.instanceOf(Primitive.ARRAY) && !element.hasRelationship(Primitive.TYPE, Primitive.REQUIRED)) { - elementIndex++; - } else if (element.is(Primitive.HATWILDCARD) || element.is(Primitive.POUNDWILDCARD)) { - elementIndex++; - if (currentStar != null) { - star.add(currentStar); - currentStar = null; - } else { - star.add(new ArrayList()); - } - } else { - break; - } - } - if (elementIndex >= elements.size()) { - if (currentStar != null) { - star.add(currentStar); - } - recordStar(star, variable, variables, network); - return true; - } - if (hadMatchAfterWildcard) { - return evaluatePattern(pattern, sentence, variable, variables, network, elements, words, wildcardSkip + 1); - } - return false; - } - - public static void recordStar(List> star, Primitive variable, Map variables, Network network) { - if (star.isEmpty()) { - return; - } else if (star.size() == 1) { - variables.put(network.createVertex(variable), buildStar(star.get(0), variables, network)); - return; - } - Vertex starValue = network.createInstance(Primitive.FRAGMENT); - int index = 0; - for (List words : star) { - starValue.addRelationship(Primitive.WORD, buildStar(words, variables, network), index); - index++; - } - variables.put(network.createVertex(variable), starValue); - } - - public static Vertex buildStar(List star, Map variables, Network network) { - if (star.isEmpty()) { - return network.createWord(""); - } else if (star.size() == 1) { - return star.get(0); - } - Vertex starValue = network.createInstance(Primitive.FRAGMENT); - int index = 0; - for (Vertex word : star) { - starValue.addRelationship(Primitive.WORD, word, index); - index++; - } - return starValue; - } - - /** - * Associate the word to the current context selection. - */ - public Vertex processAssociation(Vertex text, Network network) { - Vertex meaning = ((Context)getBot().awareness().getSense(Context.class)).top(network); - if (meaning == null) { - return null; - } - text.addRelationship(Primitive.MEANING, meaning); - List words = text.orderedRelationships(Primitive.WORD); - // Associate as single word or define as compound word. - if (words.size() == 1) { - Vertex word = words.get(0).getTarget(); - word.addRelationship(Primitive.MEANING, meaning); - meaning.addRelationship(Primitive.WORD, word); - } else if (words.size() > 1) { - text.addRelationship(Primitive.INSTANTIATION, Primitive.COMPOUND_WORD); - text.addRelationship(Primitive.INSTANTIATION, Primitive.WORD); - meaning.addRelationship(Primitive.WORD, text); - Vertex word = words.get(0).getTarget(); - word.addRelationship(Primitive.COMPOUND_WORD, text); - } - Vertex response = meaning.mostConscious(Primitive.WORD); - return response; - } - - /** - * Mark the sentence as a question. - */ - public void checkQuestion(Vertex sentence, Network network) { - if (sentence.instanceOf(Primitive.QUESTION)) { - log("Sentence is a question", Level.FINE, sentence); - return; - } - Collection words = sentence.getRelationships(Primitive.WORD); - if (words != null) { - for (Relationship word : words) { - Vertex meaning = word.getTarget().mostConscious(Primitive.MEANING); - if (meaning != null) { - if (meaning.instanceOf(Primitive.QUESTION)) { - sentence.addRelationship(Primitive.INSTANTIATION, Primitive.QUESTION); - log("Sentence is a question", Level.FINE, sentence, meaning); - break; - } - } - } - } - } - - /** - * Lookup any urls in the text. - */ - public void processHttp(Vertex sentence, Network network) { - Collection words = sentence.getRelationships(Primitive.WORD); - if (words != null) { - Sense http = getBot().awareness().getSense(Http.class); - for (Relationship word : words) { - Vertex meaning = word.getTarget().mostConscious(Primitive.MEANING); - if (meaning != null) { - if (meaning.instanceOf(Primitive.URL)) { - log("Prcoessing URL", Level.FINE, meaning); - http.input(meaning.getData()); - } - } - } - } - } - - /** - * Process the correction to the last question. - */ - public Vertex processCorrection(Vertex input, Vertex correction, Vertex speaker, Vertex target, Vertex conversation, Network network) { - if (!shouldCorrect(input, speaker)) { - throw new BotException("You do not have permission to correct"); - } - Vertex originalQuestion = null; - Vertex originalQuestionInput = null; - if (target != null) { - // Get last input said by speaker. - originalQuestionInput = getLastInputInConversation(conversation, speaker, 2); - if (originalQuestionInput != null) { - originalQuestion = originalQuestionInput.mostConscious(Primitive.INPUT); - } - } - if (originalQuestion == null) { - log("Correction missing question", Level.FINE, correction); - return correction; - } - // Get last input said by target. - Vertex wrongResponseInput = originalQuestionInput.mostConscious(Primitive.RESPONSE); - Vertex previousQuestionInput = originalQuestionInput.getRelationship(Primitive.QUESTION); - boolean wasCorrect = addCorrection(originalQuestionInput, originalQuestion, wrongResponseInput, correction, previousQuestionInput, network); - originalQuestionInput.addRelationship(Primitive.RESPONSE, input); - input.addRelationship(Primitive.QUESTION, originalQuestionInput); - log("Correction question", Level.FINE, originalQuestion); - log("Correction response", Level.FINE, correction); - // Check if last response was from understanding and correct state machine. - // Do not remove pinned quotients. - Vertex quotient = getLastQuotient(network); - if (!wasCorrect && (quotient != null) && !quotient.isPinned()) { - Vertex state = getLastState(network); - log("Correcting quotient", Level.FINE, quotient, state); - Relationship relationship = state.getRelationship(Primitive.QUOTIENT, quotient); - // Could be a wrong response, or just a wrong response in the context. - // First mark wrong in context, then mark wrong in general. - if ((relationship == null) || (relationship.getCorrectness() < 0.5)) { - originalQuestion.removeRelationship(Primitive.RESPONSE, quotient); - network.checkReduction(originalQuestion); - originalQuestion.inverseAssociateAll(Primitive.SYNONYM, quotient, Primitive.RESPONSE); - } else { - relationship.setCorrectness(relationship.getCorrectness() / 2); - // Dissociate previous question as meta info. - removeSentencePreviousMeta(relationship, previousQuestionInput, network); - } - } - return correction; - } - - /** - * Process a offensive response. - * Remove the sentence. - */ - public void processOffensive(Vertex input, Vertex speaker, Vertex target, Vertex conversation, Network network) { - Vertex originalQuestion = null; - Vertex originalQuestionInput = null; - if (target != null) { - // Get last input said by speaker. - originalQuestionInput = getLastInputInConversation(conversation, speaker, 2); - if (originalQuestionInput != null) { - originalQuestion = originalQuestionInput.mostConscious(Primitive.INPUT); - } - } - if (originalQuestion == null) { - log("Offensive missing question", Level.FINE); - return; - } - // Get last input said by target. - Vertex wrongResponseInput = originalQuestionInput.mostConscious(Primitive.RESPONSE); - if (wrongResponseInput == null) { - log("Offensive missing response", Level.FINE); - return; - } - Vertex wrongResponse = wrongResponseInput.mostConscious(Primitive.INPUT); - if (wrongResponse == null) { - log("Offensive missing response input", Level.FINE); - return; - } - if (wrongResponse.hasInverseRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE)) { - throw new BotException("The response has been marked as not offensive by the bot's admin, so cannot be flagged as offensive."); - } - log("Offensive response flagged", Bot.WARNING, wrongResponse); - // Remove this as a response from all questions. - Collection relationships = network.findAllRelationshipsTo(wrongResponse); - for (Relationship relationship : relationships) { - if (relationship.getType().is(Primitive.RESPONSE)) { - relationship.getSource().removeRelationship(relationship.getType(), relationship.getTarget()); - } - } - wrongResponseInput.addRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE); - wrongResponse.addRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE); - network.checkReduction(wrongResponse); - wrongResponse.associateAll(Primitive.SYNONYM, network.createVertex(Primitive.OFFENSIVE), Primitive.ASSOCIATED); - // Check if last response was from understanding and correct state machine. - // Do not remove pinned quotients. - Vertex quotient = getLastQuotient(network); - if ((quotient != null) && !quotient.isPinned()) { - Vertex state = getLastState(network); - log("Correcting quotient", Level.FINE, quotient, state); - state.removeRelationship(Primitive.QUOTIENT, quotient); - } - } - - /** - * Process the discussion sentence. - * Only response if a question and understood, - * or has an exact known response. - */ - public Vertex processDiscussion(Vertex input, Vertex sentence, Vertex conversation, Map variables, Network network) { - boolean checkUnderstanding = true; - Vertex response = null; - if (!this.checkExactMatchFirst) { - // Try to understand first. - response = processUnderstanding(input, sentence, this.discussionMatchPercentage, variables, network); - checkUnderstanding = false; - if (response != null) { - if (sentence.instanceOf(Primitive.QUESTION)) { - log("Discussion sentence understood", Level.FINE, sentence, response); - } else { - response = null; - log("Discussion sentence understood, but not a question", Level.FINE, sentence, response); - } - } - } - boolean hadResponse = response != null; - Relationship relationship = null; - if (response == null) { - // Check if the sentence has a known response. - relationship = bestResponse(this.discussionMatchPercentage, input, sentence, null, null, variables, network); - if (relationship != null) { - response = relationship.getTarget(); - } - if (response == null && this.checkExactMatchFirst) { - // Try to understand first. - response = processUnderstanding(input, sentence, this.discussionMatchPercentage, variables, network); - checkUnderstanding = false; - if (response != null) { - if (sentence.instanceOf(Primitive.QUESTION)) { - log("Discussion sentence understood", Level.FINE, sentence, response); - } else { - response = null; - log("Discussion sentence understood, but not a question", Level.FINE, sentence, response); - } - } - } - hadResponse = response != null; - if (response != null) { - log("Question known response", Level.FINE, response); - } else { - Relationship mostConsciousRelationship = sentence.mostConsciousRelationship(Primitive.RESPONSE); - hadResponse = mostConsciousRelationship != null; - if (mostConsciousRelationship != null) { - log("Question known response was not certain", Level.FINE, mostConsciousRelationship, this.discussionMatchPercentage); - response = null; - } else { - log("No known response, checking question patterns", Level.FINE, sentence); - // Try to find a pattern match. - relationship = matchPattern(sentence, null, input, variables, network, this.discussionMatchPercentage); - if (relationship != null) { - response = relationship.getTarget(); - log("Question pattern match", Level.FINE, response); - } else { - log("No known response, checking similar questions", Level.FINE, sentence); - // Try to find a good match. - relationship = findResponseMatch(sentence, null, input, variables, network, this.discussionMatchPercentage); - if (relationship != null) { - response = relationship.getTarget(); - log("Discussion similar question match", Level.FINE, response); - } else { - // Find the best match for logging. - relationship = findResponseMatch(sentence, null, input, variables, network, 0); - if (relationship != null) { - log("Discussion question match response was not valid", Level.FINE, relationship, this.discussionMatchPercentage); - response = null; - } - } - } - } - } - } - if (response == null) { - return null; - } - // Pause to avoid rapid responses, if someone else responds, then don't - Vertex lastInput = conversation.lastRelationship(Primitive.INPUT); - if (lastInput != null) { - Vertex lastSentence = lastInput.mostConscious(Primitive.INPUT); - if (lastSentence != sentence) { - log("Sentence was already responded to", Level.FINE, sentence, lastSentence); - return null; - } - try { - getBot().memory().wait(COVERSATIONAL_RESPONSE_DELAY); - } catch (InterruptedException ignore) {} - if (getBot().memory().getActiveMemory().size() > 1) { - log("New active memory", Level.FINE, getBot().memory().getActiveMemory().size()); - // Use a new memory to access new input. - Network tempMemory = getBot().memory().newMemory(); - Vertex tempConversation = tempMemory.createVertex(conversation); - Vertex tempSentence = tempMemory.createVertex(sentence); - lastInput = tempConversation.lastRelationship(Primitive.INPUT); - lastSentence = lastInput.mostConscious(Primitive.INPUT); - if (lastSentence != tempSentence) { - log("Sentence was already responded to", Level.FINE, sentence, lastSentence); - return null; - } - } - } - // Avoid responding the same way twice in a row. - if (response != null && conversation != null) { - Vertex newResponse = checkDuplicateOrOffensiveResponse(response, sentence, conversation, input, variables, network, !hadResponse, checkUnderstanding); - if (response == newResponse && relationship != null && relationship.hasMeta()) { - Vertex topic = relationship.getMeta().getRelationship(Primitive.TOPIC); - if (topic != null && !topic.instanceOf(Primitive.PATTERN)) { - log("Conversation topic", Level.FINE, topic); - conversation.setRelationship(Primitive.TOPIC, topic); - } - Vertex think = relationship.getMeta().getRelationship(Primitive.THINK); - if (think != null && !think.instanceOf(Primitive.FORMULA)) { - log("Conversation think", Level.FINE, think); - evaluateFormula(think, variables, network); - } - } - response = newResponse; - } - return response; - } - - /** - * Check if the response has already been used, and if it has an ONREPEAT response. - */ - public Vertex checkOnRepeat(Vertex response, Vertex conversation, int depth) { - if (!response.hasRelationship(Primitive.ONREPEAT) || (depth == 0 && !conversation.hasRelationship(Primitive.SENTENCE, response))) { - return null; - } - if (depth > MAX_DEPTH) { - return null; - } - Collection repeats = response.getRelationships(Primitive.ONREPEAT); - // Find unused repeat. - for (Relationship repeat : repeats) { - if (!conversation.hasRelationship(Primitive.SENTENCE, repeat.getTarget())) { - return repeat.getTarget(); - } - } - // Find chained repeat. - for (Relationship repeat : repeats) { - Vertex newResponse = checkOnRepeat(repeat.getTarget(), conversation, depth++); - if (newResponse != null) { - return newResponse; - } - } - // Find repeat that allows repeats. - for (Relationship repeat : repeats) { - if (!response.hasRelationship(Primitive.REQUIRE, Primitive.NOREPEAT)) { - return repeat.getTarget(); - } - } - return null; - } - - /** - * Check if the previous response was the same and try to find a new one. - */ - public Vertex checkDuplicateOrOffensiveResponse(Vertex response, Vertex sentence, Vertex conversation, Vertex input, Map variables, Network network, boolean allowMatch, boolean checkUnderstanding) { - Vertex self = network.createVertex(Primitive.SELF); - Vertex previousOutput = getLastInputInConversation(conversation, self, 1); - Vertex previousResponse = null; - if (previousOutput != null) { - previousResponse = previousOutput.mostConscious(Primitive.INPUT); - } - Vertex newResponse = checkOnRepeat(response, conversation, 0); - if (newResponse == null) { - newResponse = response; - } - boolean offensive = newResponse.hasRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE); - boolean repeat = newResponse.hasRelationship(Primitive.REQUIRE, Primitive.NOREPEAT) && conversation.hasRelationship(Primitive.SENTENCE, newResponse); - if ((previousResponse == newResponse) || offensive || repeat) { - if (offensive) { - log("Response was offensive", Level.FINE, response); - } else if (repeat) { - log("Response was repeat", Level.FINE, response); - } else { - log("Response was same as previous", Level.FINE, previousResponse); - } - newResponse = null; - if (checkUnderstanding) { - // Try to understand first. - newResponse = processUnderstanding(input, sentence, this.conversationMatchPercentage, variables, network); - } - if (newResponse == null) { - // Try to find another response. - Relationship nextBest = bestResponse(this.conversationMatchPercentage, input, sentence, null, response, variables, network); - if (nextBest != null) { - newResponse = nextBest.getTarget(); - } - if ((newResponse == null) && allowMatch) { - // Try to find a good match. - Relationship relationship = matchPattern(sentence, response, input, variables, network, this.conversationMatchPercentage); - if (relationship != null) { - newResponse = relationship.getTarget(); - } else { - // Try to find a good match. - relationship = findResponseMatch(sentence, response, input, variables, network, this.conversationMatchPercentage); - if (relationship != null) { - newResponse = relationship.getTarget(); - } - } - } - } - if (newResponse == null) { - if (offensive) { - log("Response was offensive, no other response available", Level.FINE, response); - return null; - } - log("Response is duplicate, but no other response available", Level.FINE, previousResponse); - // No other response, go with previous one. - newResponse = response; - } else { - if (newResponse.hasRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE)) { - log("New response was also offensive", Level.FINE, response); - return null; - } - Vertex onRepeat = checkOnRepeat(newResponse, conversation, 0); - if (onRepeat != null) { - newResponse = onRepeat; - } - log("Response was duplicate, found another response", Level.FINE, newResponse); - } - } - return newResponse; - } - - /** - * Return the best response to the question, taking into account the input history. - */ - public Relationship bestResponse(float percentage, Vertex input, Vertex sentence, Vertex question, Vertex previousResponse, Map variables, Network network) { - return bestResponse(percentage, input, sentence, question, previousResponse, true, true, null, null, null, variables, network); - } - - /** - * Return the best response to the question, taking into account the input history. - */ - public Relationship bestResponse(float percentage, Vertex input, Vertex sentence, Vertex question, Vertex previousResponse, boolean cascade, - boolean init, Vertex previousQuestion, Set questionWords, Vertex currentTopic, Map variables, Network network) { - Collection responses = sentence.getRelationships(Primitive.RESPONSE); - Relationship bestResponse = null; - if (responses != null) { - if (init) { - Vertex previousQuestionInput = input.getRelationship(Primitive.QUESTION); - if (previousQuestionInput != null) { - previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - } - Vertex conversation = input.getRelationship(Primitive.CONVERSATION); - if (conversation != null) { - currentTopic = conversation.mostConscious(Primitive.TOPIC); - } - if (question != null) { - questionWords = new HashSet(); - Collection relationships = question.getRelationships(Primitive.WORD); - if (relationships != null) { - for (Relationship relationship : relationships) { - questionWords.add(relationship.getTarget().getDataValue().toLowerCase()); - } - } - } - } - List best = new ArrayList(); - List bestWithCondition = new ArrayList(); - List bestWithTopic = new ArrayList(); - List bestWithPrevious = new ArrayList(); - List bestWithTopicPrevious = new ArrayList(); - for (Relationship response : responses) { - if ((response.getCorrectness() >= percentage) && (response.getTarget() != previousResponse)) { - if (response.getTarget().hasRelationship(Primitive.ASSOCIATED, Primitive.OFFENSIVE)) { - continue; - } - Vertex meta = response.getMeta(); - if (meta != null) { - if ((previousQuestion == null) && meta.hasRelationship(Primitive.REQUIRE, Primitive.PREVIOUS)) { - continue; - } - Vertex topic = meta.getRelationship(Primitive.TOPIC); - if (!bestWithTopic.isEmpty() && topic == null) { - continue; - } - Collection required = meta.getRelationships(Primitive.REQUIRED); - if ((required != null) && (!required.isEmpty()) && (question != null)) { - // Ensure all required words are in the matched question. - //TODO also check synonyms - boolean found = true; - for (Relationship word : required) { - if (!questionWords.contains(word.getTarget().getDataValue().toLowerCase())) { - found = false; - log("Missing required word", Level.FINER, word.getTarget()); - break; - } - } - if (!found) { - continue; - } - } else { - Collection keywords = meta.getRelationships(Primitive.KEYWORD); - if ((keywords != null) && (!keywords.isEmpty()) && (question != null)) { - // Ensure any keywords are in the matched question. - //TODO also check synonyms - boolean found = false; - for (Relationship keyword : keywords) { - if (questionWords.contains(keyword.getTarget().getDataValue().toLowerCase())) { - found = true; - break; - } - } - if (!found) { - log("Missing keyword", Level.FINER, keywords); - continue; - } - } - } - if (topic != null) { - boolean requireTopic = meta.hasRelationship(Primitive.REQUIRE, Primitive.TOPIC); - if (currentTopic == null && requireTopic) { - continue; - } - if (currentTopic != null) { - boolean match = topic == currentTopic; - if (!match && topic.instanceOf(Primitive.PATTERN)) { - match = evaluatePattern(topic, currentTopic, Primitive.TOPICWILDCARD, new HashMap(), network); - } - if (!match && requireTopic) { - continue; - } - if (match && (bestWithTopic.isEmpty() || (response.getCorrectness() >= bestWithTopic.get(0).getCorrectness()))) { - if (previousQuestion != null) { - Vertex label = previousQuestion.getRelationship(Primitive.LABEL); - if (meta.hasRelationship(Primitive.PREVIOUS, previousQuestion) - || (label != null && meta.hasRelationship(Primitive.PREVIOUS, label))) { - if (checkCondition(response, variables, network) != Boolean.FALSE) { - if (!bestWithTopicPrevious.isEmpty() && (response.getCorrectness() > bestWithTopicPrevious.get(0).getCorrectness())) { - bestWithTopicPrevious.clear(); - } - bestWithTopicPrevious.add(response); - } - } else { - if (meta.hasInverseRelationship(Primitive.PREVIOUS, previousQuestion) - || (label != null && meta.hasInverseRelationship(Primitive.PREVIOUS, label))) { - continue; - } - Collection previous = meta.getRelationships(Primitive.PREVIOUS); - if (previous != null) { - for (Relationship relationship : previous) { - match = evaluatePattern(relationship.getTarget(), previousQuestion, Primitive.THATWILDCARD, new HashMap(), network); - if (match) { - if (checkCondition(response, variables, network) != Boolean.FALSE) { - if (!bestWithTopicPrevious.isEmpty() && (response.getCorrectness() > bestWithTopicPrevious.get(0).getCorrectness())) { - bestWithTopicPrevious.clear(); - } - bestWithTopicPrevious.add(response); - } - } - } - } - } - } - if (meta.hasRelationship(Primitive.REQUIRE, Primitive.PREVIOUS)) { - continue; - } - if (checkCondition(response, variables, network) != Boolean.FALSE) { - if (!bestWithTopic.isEmpty() && (response.getCorrectness() > bestWithTopic.get(0).getCorrectness())) { - bestWithTopic.clear(); - } - bestWithTopic.add(response); - } - } - } - } - if ((bestWithTopic.isEmpty()) && (previousQuestion != null) && ((bestWithPrevious.isEmpty()) || (response.getCorrectness() >= bestWithPrevious.get(0).getCorrectness()))) { - boolean match = false; - Vertex label = previousQuestion.getRelationship(Primitive.LABEL); - if (meta.hasRelationship(Primitive.PREVIOUS, previousQuestion) - || (label != null && meta.hasRelationship(Primitive.PREVIOUS, label))) { - if (checkCondition(response, variables, network) != Boolean.FALSE) { - if (!bestWithPrevious.isEmpty() && (response.getCorrectness() > bestWithPrevious.get(0).getCorrectness())) { - bestWithPrevious.clear(); - } - bestWithPrevious.add(response); - } - } else { - if (meta.hasInverseRelationship(Primitive.PREVIOUS, previousQuestion) - || (label != null && meta.hasInverseRelationship(Primitive.PREVIOUS, label))) { - continue; - } - Collection previous = meta.getRelationships(Primitive.PREVIOUS); - if (previous != null) { - for (Relationship relationship : previous) { - match = evaluatePattern(relationship.getTarget(), previousQuestion, Primitive.THATWILDCARD, new HashMap(), network); - if (match) { - if (checkCondition(response, variables, network) != Boolean.FALSE) { - if (!bestWithPrevious.isEmpty() && (response.getCorrectness() > bestWithPrevious.get(0).getCorrectness())) { - bestWithPrevious.clear(); - } - bestWithPrevious.add(response); - break; - } - } - } - } - } - } - if (meta.hasRelationship(Primitive.REQUIRE, Primitive.PREVIOUS)) { - continue; - } - } - if ((best.isEmpty()) || (response.getCorrectness() >= best.get(0).getCorrectness())) { - Boolean condition = checkCondition(response, variables, network); - if (condition != Boolean.FALSE) { - if (condition == Boolean.TRUE) { - if (!bestWithCondition.isEmpty() && (response.getCorrectness() > bestWithCondition.get(0).getCorrectness())) { - bestWithCondition.clear(); - } - bestWithCondition.add(response); - } - if (!best.isEmpty() && (response.getCorrectness() > best.get(0).getCorrectness())) { - best.clear(); - } - best.add(response); - } - } - } - } - if (!bestWithTopicPrevious.isEmpty()) { - bestResponse = Utils.random(bestWithTopicPrevious); - } else if (!bestWithTopic.isEmpty()) { - bestResponse = Utils.random(bestWithTopic); - } else if (!bestWithPrevious.isEmpty()) { - bestResponse = Utils.random(bestWithPrevious); - } else if (!bestWithCondition.isEmpty()) { - bestResponse = Utils.random(bestWithCondition); - } else if (!best.isEmpty()) { - bestResponse = Utils.random(best); - } - if (bestResponse != null) { - if (bestResponse.hasMeta()) { - this.lastResponseMetaId = bestResponse.getMeta().getId(); - } - return bestResponse; - } - } - if (cascade) { - network.checkReduction(sentence); - Collection meanings = sentence.getRelationships(Primitive.SYNONYM); - if (meanings != null) { - for (Relationship meaning : meanings) { - bestResponse = bestResponse(percentage, input, meaning.getTarget(), question, previousResponse, false, - init, previousQuestion, questionWords, currentTopic, variables, network); - if (bestResponse != null) { - return bestResponse; - } - } - } - } - return bestResponse; - } - - /** - * Process the start of a new conversation and output the greeting. - */ - public Vertex processGreeting(Vertex input, Vertex conversation, Network network, LanguageState state, Map variables) { - Vertex language = network.createVertex(getPrimitive()); - Collection greetings = language.getRelationships(Primitive.GREETING); - if (greetings == null) { - log("No greeting", Level.FINE); - return null; - } - Vertex greeting = Utils.random(greetings).getTarget(); - log("Greeting", Level.FINE, greeting); - // Check for formula and transpose - if ((greeting != null) && greeting.instanceOf(Primitive.LABEL)) { - greeting = greeting.mostConscious(Primitive.RESPONSE); - } - if ((greeting != null) && greeting.instanceOf(Primitive.FORMULA)) { - log("Greeting is template formula", Level.FINE, greeting); - Vertex result = evaluateFormula(greeting, variables, network); - if (result == null) { - log("Template formula cannot be evaluated", Level.FINE, greeting); - greeting = null; - // Find non formula. - for (Relationship relationship : greetings) { - if (!relationship.getTarget().instanceOf(Primitive.FORMULA)) { - greeting = relationship.getTarget(); - } - } - } else { - greeting = getWord(result, network); - } - } - return greeting; - } - - /** - * Process the conversational sentence. - * Try to understand, otherwise, - * determine the best know response, if there is no known - * response, then resort to mimicry. - */ - public Vertex processConversational(Vertex input, Vertex sentence, Vertex conversation, Map variables, Network network, LanguageState state) { - Vertex response = null; - boolean checkUnderstanding = true; - if (!this.checkExactMatchFirst) { - // Try to understand first. - response = processUnderstanding(input, sentence, this.conversationMatchPercentage, variables, network); - checkUnderstanding = false; - } - Relationship relationship = null; - if (response == null) { - // Check if the sentence has a known response. - relationship = bestResponse(0.1f, input, sentence, null, null, variables, network); - if (relationship != null) { - response = relationship.getTarget(); - } - } - if ((response == null) && this.checkExactMatchFirst) { - // Try to understand first. - response = processUnderstanding(input, sentence, this.conversationMatchPercentage, variables, network); - checkUnderstanding = false; - } - boolean hadResponse = response != null; - if (response != null) { - log("Question known response", Level.FINE, response); - } else { - log("No known response, checking question patterns", Level.FINE, sentence); - // Try to find a pattern that matches. - relationship = matchPattern(sentence, null, input, variables, network, this.conversationMatchPercentage); - if (relationship != null) { - response = relationship.getTarget(); - log("Question pattern match", Level.FINE, response); - } else { - log("No known response, checking similar questions", Level.FINE, sentence); - // Try to find a good match. - relationship = findResponseMatch(sentence, null, input, variables, network, this.conversationMatchPercentage); - if (relationship != null) { - response = relationship.getTarget(); - log("Conversation similar question match response", Level.FINE, response); - } else if ((state == LanguageState.Answering) || (state == LanguageState.Discussion)) { - Vertex language = network.createVertex(getPrimitive()); - List defaultResponses = language.orderedRelationships(Primitive.RESPONSE); - if (defaultResponses == null) { - if (this.synthesizeResponse) { - response = synthesizeResponse(input, sentence, conversation, false, variables, network); - } - if (response == null) { - this.wasMimic = true; - // Mimic. - log("Conversation mimic", Level.FINE, sentence); - response = sentence; - } - } else { - this.wasMimic = true; - response = getDefaultResponse(defaultResponses, input, sentence, conversation, variables, network); - } - } - } - } - // Avoid responding the same way twice in a row. - if ((response != null) && (conversation != null)) { - Vertex newResponse = checkDuplicateOrOffensiveResponse(response, sentence, conversation, input, variables, network, !hadResponse, checkUnderstanding); - if (response == newResponse && relationship != null && relationship.hasMeta()) { - Vertex topic = relationship.getMeta().getRelationship(Primitive.TOPIC); - if (topic != null && !topic.instanceOf(Primitive.PATTERN)) { - log("Conversation topic", Level.FINE, topic); - conversation.setRelationship(Primitive.TOPIC, topic); - } - Vertex think = relationship.getMeta().getRelationship(Primitive.THINK); - if (think != null && think.instanceOf(Primitive.FORMULA)) { - log("Conversation think", Level.FINE, think); - evaluateFormula(think, variables, network); - } - } - response = newResponse; - } - return response; - } - - /** - * Return a synthesized response from linguistic patterns. - */ - public Vertex synthesizeResponse(Vertex input, Vertex sentence, Vertex conversation, boolean random, Map variables, Network network) { - // Find sentence topic. - Vertex topic = null; //conversation.getRelationship(Primitive.TOPIC); - if (topic == null && sentence != null) { - if (sentence.instanceOf(Primitive.WORD)) { - topic = sentence; - } else { - Collection words = sentence.getRelationships(Primitive.WORD); - if (words != null && !words.isEmpty()) { - for (Relationship relationship : words) { - Vertex word = relationship.getTarget(); - Vertex meaning = word.mostConscious(Primitive.MEANING); - if (meaning != null && meaning.instanceOf(Primitive.THING)) { - if (topic == null || (meaning.getConsciousnessLevel() > topic.getConsciousnessLevel())) { - topic = word; - } - } - } - if (topic == null) { - for (Relationship relationship : words) { - Vertex word = relationship.getTarget(); - Vertex meaning = word.mostConscious(Primitive.MEANING); - if (meaning != null && meaning.instanceOf(Primitive.DESCRIPTION)) { - if (topic == null || (meaning.getConsciousnessLevel() > topic.getConsciousnessLevel())) { - topic = word; - } - } - } - } - if (topic == null) { - for (Relationship relationship : words) { - Vertex word = relationship.getTarget(); - Vertex meaning = word.mostConscious(Primitive.MEANING); - if (meaning != null && meaning.instanceOf(Primitive.ACTION)) { - if (topic == null || (meaning.getConsciousnessLevel() > topic.getConsciousnessLevel())) { - topic = word; - } - } - } - } - if (topic == null) { - for (Relationship relationship : words) { - Vertex word = relationship.getTarget(); - if (topic == null || (word.getConsciousnessLevel() > topic.getConsciousnessLevel())) { - topic = word; - } - } - } - } - } - } - List words = new ArrayList(); - Set usedWords = new HashSet(); - if (topic != null && !topic.instanceOf(Primitive.WORD)) { - topic = topic.mostConscious(Primitive.WORD); - } - boolean loop = false; - if (topic != null) { - // Generate sentence start from topic. - int count = 0; - words.add(topic); - usedWords.add(topic); - Vertex current = topic; - while (count < 5) { - Vertex previous = null; - if (random) { - Collection relationships = current.getRelationships(Primitive.PREVIOUS); - if (relationships != null) { - previous = Utils.random(relationships).getTarget(); - if (loop && usedWords.contains(previous)) { - previous = Utils.random(relationships).getTarget(); - } - } - } else { - if (loop) { - previous = current.nextMostConscious(Primitive.PREVIOUS, usedWords); - } else { - previous = current.mostConscious(Primitive.PREVIOUS); - } - } - if (previous == null || previous.is(Primitive.NULL)) { - break; - } - if (usedWords.contains(previous)) { - loop = true; - } else { - usedWords.add(previous); - } - words.add(0, previous); - current = previous; - count++; - } - if (count == 5) { - count = 0; - while (count < 5) { - if (current.hasRelationship(Primitive.PREVIOUS, Primitive.NULL)) { - break; - } - Vertex previous = null; - if (random) { - Collection relationships = current.getRelationships(Primitive.PREVIOUS); - if (relationships != null) { - previous = Utils.random(relationships).getTarget(); - if (loop && usedWords.contains(previous)) { - previous = Utils.random(relationships).getTarget(); - } - } - } else { - previous = current.nextMostConscious(Primitive.PREVIOUS, usedWords); - } - if (previous == null || previous.is(Primitive.NULL)) { - break; - } - words.add(0, previous); - usedWords.add(previous); - current = previous; - count++; - } - } - - } - if (topic == null) { - topic = network.createVertex(Primitive.NULL); - } - // Generate sentence end from topic. - int count = 0; - Vertex current = topic; - while (count < 5) { - Vertex next = null; - if (random) { - Collection relationships = current.getRelationships(Primitive.NEXT); - if (relationships != null) { - next = Utils.random(relationships).getTarget(); - if (loop && usedWords.contains(next)) { - next = Utils.random(relationships).getTarget(); - } - } - } else { - if (loop) { - next = current.nextMostConscious(Primitive.NEXT, usedWords); - } else { - next = current.mostConscious(Primitive.NEXT); - } - } - if (next == null || next.is(Primitive.NULL)) { - break; - } - if (usedWords.contains(next)) { - loop = true; - } else { - usedWords.add(next); - } - words.add(next); - current = next; - count++; - } - if (count == 5) { - count = 0; - while (count < 5) { - if (current.hasRelationship(Primitive.PREVIOUS, Primitive.NULL)) { - break; - } - Vertex next = null; - if (random) { - Collection relationships = current.getRelationships(Primitive.NEXT); - if (relationships != null) { - next = Utils.random(relationships).getTarget(); - if (loop && usedWords.contains(next)) { - next = Utils.random(relationships).getTarget(); - } - } - } else { - next = current.nextMostConscious(Primitive.NEXT, usedWords); - } - if (next == null || next.is(Primitive.NULL)) { - break; - } - words.add(next); - usedWords.add(next); - current = next; - count++; - } - } - if (words.isEmpty()) { - return null; - } - Vertex response = network.createInstance(Primitive.SENTENCE); - int index = 0; - for (Vertex word: words) { - response.addRelationship(Primitive.WORD, word, index); - index++; - } - return response; - } - - /** - * Check if the response has a condition, and if it evaluates to true. - */ - public Boolean checkCondition(Relationship relationship, Map variables, Network network) { - if (!relationship.hasMeta()) { - return null; - } - Vertex condition = relationship.getMeta().getRelationship(Primitive.CONDITION); - if (condition == null || !condition.instanceOf(Primitive.FORMULA)) { - return null; - } - Vertex result = evaluateFormula(condition, variables, network); - if (result != null && result.printString().toLowerCase().equals("true")) { - return Boolean.TRUE; - } - return Boolean.FALSE; - } - - /** - * Return a random default response for the topic or context. - */ - public Vertex getDefaultResponse(List defaultResponses, Vertex input, Vertex sentence, Vertex conversation, Map variables, Network network) { - Vertex response = null; - Relationship relationship = null; - variables.put(network.createVertex(Primitive.WILDCARD), sentence); - Vertex previousQuestionInput = input.getRelationship(Primitive.QUESTION); - Vertex previousQuestion = null; - if (previousQuestionInput != null) { - previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - } - // Check topic - if (conversation != null) { - Vertex topic = conversation.getRelationship(Primitive.TOPIC); - if (topic != null) { - Vertex topicMatch = null; - Vertex previousMatch = null; - Relationship topicMatchRelationship = null; - Relationship previousMatchRelationship = null; - for (Relationship defaultResponse : defaultResponses) { - if (defaultResponse.hasMeta()) { - Vertex defaultTopic = defaultResponse.getMeta().getRelationship(Primitive.TOPIC); - if (defaultTopic != null) { - boolean match = topic == defaultTopic; - if (!match && defaultTopic.instanceOf(Primitive.PATTERN)) { - match = evaluatePattern(defaultTopic, topic, Primitive.TOPIC, new HashMap(), network); - } - if (match) { - if (defaultResponse.getMeta().hasRelationship(Primitive.PREVIOUS)) { - boolean previousMatches = defaultResponse.getMeta().hasRelationship(Primitive.PREVIOUS, previousQuestion); - if (!previousMatches) { - Vertex label = previousQuestion.getRelationship(Primitive.LABEL); - if (label != null && defaultResponse.getMeta().hasRelationship(Primitive.PREVIOUS, label)) { - previousMatches = true; - } - } - if (!previousMatches) { - // Check for patterns. - Collection previousResponses = defaultResponse.getMeta().getRelationships(Primitive.PREVIOUS); - if (previousResponses != null) { - for (Relationship previousResponse : previousResponses) { - if (!previousResponse.isInverse() && previousResponse.getTarget().instanceOf(Primitive.PATTERN)) { - previousMatches = evaluatePattern(previousResponse.getTarget(), previousQuestion, Primitive.PREVIOUS, new HashMap(), network); - if (previousMatches) { - previousMatch = defaultResponse.getTarget(); - previousMatchRelationship = defaultResponse; - log("Conversation topic and previous default response", Level.FINE, defaultTopic, previousMatch); - previousMatch = checkDefaultResponseFormula(previousMatch, input, network, variables); - if (previousMatch != null) { - break; - } - } - } - } - } - } - } else if (topicMatch == null) { - topicMatch = defaultResponse.getTarget(); - topicMatchRelationship = defaultResponse; - log("Conversation topic default response", Level.FINE, defaultTopic, topicMatch); - topicMatch = checkDefaultResponseFormula(topicMatch, input, network, variables); - } - } - } - } - } - if (previousMatch != null) { - response = previousMatch; - relationship = previousMatchRelationship; - } else if (topicMatch != null) { - response = topicMatch; - relationship = topicMatchRelationship; - } - } - } - if (response == null) { - // Check previous. - if (previousQuestion != null) { - for (Relationship defaultResponse : defaultResponses) { - if (defaultResponse.hasMeta() && defaultResponse.getMeta().hasRelationship(Primitive.PREVIOUS) && !defaultResponse.getMeta().hasRelationship(Primitive.TOPIC)) { - boolean match = defaultResponse.getMeta().hasRelationship(Primitive.PREVIOUS, previousQuestion); - if (!match) { - // Check for patterns. - Collection previousResponses = defaultResponse.getMeta().getRelationships(Primitive.PREVIOUS); - if (previousResponses != null) { - for (Relationship previousResponse : previousResponses) { - if (!previousResponse.isInverse() && previousResponse.getTarget().instanceOf(Primitive.PATTERN)) { - match = evaluatePattern(previousResponse.getTarget(), previousQuestion, Primitive.PREVIOUS, new HashMap(), network); - if (match) { - break; - } - } - } - } - } - if (match) { - response = defaultResponse.getTarget(); - relationship = defaultResponse; - log("Conversation previous default response", Level.FINE, previousQuestion, response); - response = checkDefaultResponseFormula(response, input, network, variables); - if (response != null) { - break; - } - } - } - } - } - } - if (response == null) { - // Check conditions. - for (Relationship defaultResponse : defaultResponses) { - if (checkCondition(defaultResponse, variables, network) == Boolean.TRUE) { - response = defaultResponse.getTarget(); - relationship = defaultResponse; - log("Conversation condition default response", Level.FINE, response); - response = checkDefaultResponseFormula(response, input, network, variables); - if (response != null) { - break; - } - } - } - } - if (response == null) { - List candidates = new ArrayList(); - for (Relationship defaultResponse : defaultResponses) { - if (!defaultResponse.hasMeta() && !conversation.hasRelationship(Primitive.SENTENCE, defaultResponse.getTarget())) { - candidates.add(defaultResponse); - } - } - if (candidates.isEmpty()) { - for (Relationship defaultResponse : defaultResponses) { - if (!defaultResponse.hasMeta() - && (!defaultResponse.getTarget().hasRelationship(Primitive.REQUIRE, Primitive.NOREPEAT) - || !conversation.hasRelationship(Primitive.SENTENCE, defaultResponse.getTarget()))) { - candidates.add(defaultResponse); - } - } - } - if (!candidates.isEmpty()) { - relationship = Utils.random(candidates); - response = relationship.getTarget(); - log("Conversation default response", Level.FINE, sentence, response); - response = checkDefaultResponseFormula(response, input, network, variables); - } - if (response == null) { - // Find non formula. - for (Relationship defaultResponse : candidates) { - if (!defaultResponse.getTarget().instanceOf(Primitive.FORMULA)) { - response = defaultResponse.getTarget(); - relationship = defaultResponse; - } - } - if (response == null && !candidates.isEmpty()) { - // Try once more. - relationship = Utils.random(candidates); - response = relationship.getTarget(); - response = checkDefaultResponseFormula(response, input, network, variables); - } - if (response == null) { - // Mimic. - log("Conversation mimic, failed to find default response", Level.FINE, sentence); - response = sentence; - relationship = null; - } - } else { - response = getWord(response, network); - } - } - if (relationship != null && relationship.hasMeta()) { - Vertex topic = relationship.getMeta().getRelationship(Primitive.TOPIC); - if (topic != null && !topic.instanceOf(Primitive.PATTERN)) { - log("Conversation topic", Level.FINE, topic); - conversation.setRelationship(Primitive.TOPIC, topic); - } - Vertex think = relationship.getMeta().getRelationship(Primitive.THINK); - if (think != null && !think.instanceOf(Primitive.FORMULA)) { - log("Conversation think", Level.FINE, think); - evaluateFormula(think, variables, network); - } - } - return response; - } - - public Vertex checkDefaultResponseFormula(Vertex response, Vertex input, Network network, Map variables) { - if ((response != null) && response.instanceOf(Primitive.LABEL)) { - response = response.mostConscious(Primitive.RESPONSE); - } - if ((response != null) && response.instanceOf(Primitive.FORMULA)) { - log("Default response is template formula", Level.FINE, response); - Vertex result = evaluateFormula(response, variables, network); - if (result == null) { - log("Template formula cannot be evaluated", Level.FINE, response); - } - return result; - } - return response; - } - - /** - * Return the last thing the speaker said in the conversation. - */ - public Vertex getLastInputInConversation(Vertex conversation, Vertex speaker, int last) { - if (conversation == null) { - return null; - } - List allInput = conversation.orderedRelations(Primitive.INPUT); - if (allInput != null) { - int count = 0; - for (int index = allInput.size() - 1; index >= 0; index--) { - Vertex previousInput = allInput.get(index); - if (previousInput.mostConscious(Primitive.SPEAKER) == speaker) { - count++; - if (count >= last) { - return previousInput; - } - } - } - } - return null; - } - - /** - * Return if learning should be used for the input. - */ - public boolean shouldLearn(Vertex input, Vertex speaker) { - if (this.allowLearning == Boolean.TRUE) { - return true; - } else if (this.allowLearning == Boolean.FALSE) { - return false; - } - boolean isAdmin = false; - boolean isAnonymous = true; - if (speaker != null) { - isAdmin = speaker.hasRelationship(Primitive.ASSOCIATED, Primitive.ADMINISTRATOR); - isAnonymous = speaker.hasRelationship(Primitive.ASSOCIATED, Primitive.ANONYMOUS); - } - if (this.learningMode == LearningMode.Disabled) { - return false; - } else if (!isAdmin && (this.learningMode == LearningMode.Administrators)) { - if (speaker.is(Primitive.SELF)) { - return true; - } - return false; - } else if (isAnonymous && (this.learningMode == LearningMode.Users)) { - return false; - } - return true; - } - - /** - * Return if learning should be used for the input. - */ - public boolean shouldCorrect(Vertex input, Vertex speaker) { - boolean isAdmin = false; - boolean isAnonymous = true; - if (speaker != null) { - isAdmin = speaker.hasRelationship(Primitive.ASSOCIATED, Primitive.ADMINISTRATOR); - isAnonymous = speaker.hasRelationship(Primitive.ASSOCIATED, Primitive.ANONYMOUS); - } - if (this.correctionMode == CorrectionMode.Disabled) { - return false; - } else if (!isAdmin && (this.correctionMode == CorrectionMode.Administrators)) { - return false; - } else if (isAnonymous && (this.correctionMode == CorrectionMode.Users)) { - return false; - } - return true; - } - - /** - * Self API for checking is a user is trusted and should allow correction. - */ - public Vertex allowCorrection(Vertex source, Vertex user) { - if (shouldCorrect(null, user)) { - return source.getNetwork().createVertex(Primitive.TRUE); - } - return source.getNetwork().createVertex(Primitive.FALSE); - } - - /** - * Self API for learning a new response. - */ - public Vertex learn(Vertex source, Vertex question, Vertex response) { - log("learn", Level.FINE, question, response); - addResponse(question, response, source.getNetwork()); - return source; - } - - /** - * Self API for learning a new response. - */ - public Vertex learn(Vertex source, Vertex question, Vertex response, Vertex topic) { - log("learn", Level.FINE, question, response); - addResponse(question, response, topic.printString(), null, null, source.getNetwork()); - return source; - } - - /** - * Self API for synthesizing a new response from a phrase. - */ - public Vertex synthesize(Vertex source, Vertex phrase) { - log("synthesize", Level.FINE, phrase); - return synthesizeResponse(null, phrase, null, false, null, phrase.getNetwork()); - } - - /** - * Self API for synthesizing a new response. - */ - public Vertex synthesize(Vertex source) { - log("synthesize", Level.FINE); - return synthesizeResponse(null, null, null, false, null, source.getNetwork()); - } - - /** - * Self API for synthesizing a new response from a phrase. - */ - public Vertex randomSynthesize(Vertex source, Vertex phrase) { - log("random synthesize", Level.FINE, phrase); - return synthesizeResponse(null, phrase, null, true, null, phrase.getNetwork()); - } - - /** - * Self API for synthesizing a new response. - */ - public Vertex randomSynthesize(Vertex source) { - log("random synthesize", Level.FINE); - return synthesizeResponse(null, null, null, true, null, source.getNetwork()); - } - - /** - * Self API to print the details of an object. - */ - public Vertex details(Vertex source, Vertex object) { - Network network = source.getNetwork(); - Vertex paragraph = network.createInstance(Primitive.PARAGRAPH); - Vertex text = network.createInstance(Primitive.FRAGMENT); - Vertex cr = network.createVertex("\n"); - Vertex bold = network.createVertex(""); - Vertex boldEnd = network.createVertex(""); - Vertex ul = network.createVertex("
    "); - Vertex ulEnd = network.createVertex("
"); - Vertex li = network.createVertex("
  • "); - Vertex liEnd = network.createVertex("
  • "); - Vertex dash = network.createVertex("-"); - int index = 0; - int paraIndex = 0; - text.addRelationship(Primitive.WORD, bold, index++); - text.addRelationship(Primitive.WORD, getWord(object, network), index++); - text.addRelationship(Primitive.WORD, boldEnd, index++); - text.addRelationship(Primitive.WORD, cr, index++); - paragraph.addRelationship(Primitive.SENTENCE, text, paraIndex++); - text = network.createInstance(Primitive.FRAGMENT); - index = 0; - text.addRelationship(Primitive.WORD, ul, index++); - text.addRelationship(Primitive.WORD, cr, index++); - paragraph.addRelationship(Primitive.SENTENCE, text, paraIndex++); - for (Iterator iterator = object.orderedAllRelationships(); iterator.hasNext(); ) { - if (paraIndex > 100) { - break; - } - Relationship relationship = iterator.next(); - if (relationship.isInverse()) { - continue; - } - Vertex type = getWord(relationship.getType(), network); - Vertex value = getWord(relationship.getTarget(), network); - if (!(value.getData() instanceof String) || ((String)value.getData()).isEmpty()) { - //continue; - } - text = network.createInstance(Primitive.FRAGMENT); - index = 0; - text.addRelationship(Primitive.WORD, li, index++); - text.addRelationship(Primitive.WORD, type, index++); - text.addRelationship(Primitive.WORD, dash, index++); - text.addRelationship(Primitive.WORD, value, index++); - text.addRelationship(Primitive.WORD, liEnd, index++); - text.addRelationship(Primitive.WORD, cr, index++); - paragraph.addRelationship(Primitive.SENTENCE, text, paraIndex++); - } - text = network.createInstance(Primitive.FRAGMENT); - index = 0; - text.addRelationship(Primitive.WORD, ulEnd, index++); - paragraph.addRelationship(Primitive.SENTENCE, text, paraIndex++); - return paragraph; - } - - /** - * Self API to create a compound word. - * Language.word("very", "nice") - * Create a compound word from the arguments. - */ - public Vertex word(Vertex source, Vertex[] arguments) { - Network network = source.getNetwork(); - Vertex nil = network.createVertex(Primitive.NULL); - if (arguments.length == 0) { - return nil; - } - StringWriter writer = new StringWriter(); - List words = new ArrayList(); - for (Vertex argument : arguments) { - if (argument.instanceOf(Primitive.ARRAY)) { - List elements = argument.orderedRelations(Primitive.ELEMENT); - if (elements != null) { - words.addAll(elements); - } - } else if (argument.instanceOf(Primitive.LIST)) { - List elements = argument.orderedRelations(Primitive.SEQUENCE); - if (elements != null) { - words.addAll(elements); - } - } else { - words.add(argument); - } - } - Vertex previousWord = nil; - for (int index = 0; index < words.size(); index++) { - Vertex word = words.get(index); - Vertex nextWord = nil; - if (words.size() > (index + 1)) { - nextWord = words.get(index + 1); - } - word = Language.getWordFollowing(word, previousWord, nextWord, network); - writer.write(String.valueOf(word.getData())); - if ((index + 1) < words.size()) { - writer.write(" "); - } - previousWord = word; - } - return network.createWord(writer.toString()); - } - - /** - * Self API to define a word. - * Language.define("hello", #hello) - */ - public Vertex define(Vertex source, Vertex word, Vertex meaning) { - word.addRelationship(Primitive.MEANING, meaning); - meaning.addRelationship(Primitive.WORD, word); - source.getNetwork().associateCaseInsensitivity((String)word.getData(), meaning); - return word; - } - - /** - * Self API to create a sentence. - * Language.sentence("hello", "world") - * Create a sentence from the arguments. - */ - public Vertex sentence(Vertex source, Vertex[] arguments) { - Network network = source.getNetwork(); - Vertex result = null; - Vertex nil = network.createVertex(Primitive.NULL); - if (arguments.length == 0) { - result = nil; - } else if (arguments.length == 1) { - result = arguments[0]; - if (!(result.getData() instanceof String)) { - StringWriter writer = new StringWriter(); - Vertex text = Language.getWordFollowing(result, nil, nil, network); - writer.write(text.getDataValue()); - result = network.createSentence(writer.toString()); - } else { - result = network.createSentence((String)result.getData()); - } - } else { - StringWriter writer = new StringWriter(); - List words = new ArrayList(); - for (Vertex argument : arguments) { - words.add(argument); - } - Vertex previousWord = nil; - for (int index = 0; index < words.size(); index++) { - Vertex word = words.get(index); - Vertex nextWord = nil; - if (words.size() > (index + 1)) { - nextWord = words.get(index + 1); - } - word = Language.getWordFollowing(word, previousWord, nextWord, network); - writer.write(String.valueOf(word.getData())); - if ((index + 1) < words.size()) { - writer.write(" "); - } - previousWord = word; - } - result = network.createSentence(writer.toString()); - } - return result; - } - - /** - * Self API to access last input of a speaker. - * Language.getLastInput(speaker) - * Get the last input from the conversation for the speaker. - */ - public Vertex getLastInput(Vertex source, Vertex conversation, Vertex speaker) { - return getLastInput(source, conversation, speaker, null, null); - } - - /** - * Self API to access last input of a speaker. - * Language.getLastInput(speaker, 1) - * Get the last input from the conversation for the speaker. - */ - public Vertex getLastInput(Vertex source, Vertex conversation, Vertex speaker, Vertex index) { - return getLastInput(source, conversation, speaker, index, null); - } - - /** - * Self API to access last input of a speaker. - * Language.getLastInput(speaker, 1, 2) - * Get the last input from the conversation for the speaker. - */ - public Vertex getLastInput(Vertex source, Vertex conversation, Vertex speaker, Vertex index, Vertex part) { - Network network = source.getNetwork(); - int partValue = 1; - if (part != null) { - try { - partValue = Integer.valueOf(String.valueOf(part.getData())); - } catch (Exception exception) { - // Ignore, use 1; - } - } - Vertex input = network.createVertex(Primitive.INPUT_VARIABLE); - if (conversation == null) { - return network.createVertex(Primitive.NULL); - } - int count = 0; - int value = 1; - if (index != null) { - try { - value = Integer.valueOf(String.valueOf(index.getData())); - } catch (Exception exception) { - // Ignore, use 1; - } - } - List inputs = conversation.orderedRelations(Primitive.INPUT); - int element = inputs.size() - 1; - while (count < value && element >= 0) { - input = inputs.get(element); - if (input.hasRelationship(Primitive.SPEAKER, speaker)) { - count++; - if (count == value) { - Vertex sentence = input.getRelationship(Primitive.INPUT); - if (part == null) { - return sentence; - } - if (!sentence.instanceOf(Primitive.PARAGRAPH)) { - if (partValue == 1) { - return sentence; - } - return network.createVertex(Primitive.NULL); - } - List sentences = sentence.orderedRelations(Primitive.SENTENCE); - if (partValue > sentences.size()) { - return network.createVertex(Primitive.NULL); - } - return sentences.get(partValue - 1); - } - } - element--; - } - return network.createVertex(Primitive.NULL); - } - - /** - * Associate the response, attempt to understand. - */ - public Vertex processListening(Vertex input, Vertex sentence, Vertex speaker, Vertex conversation, List targets, Network network, LanguageState state) { - if (targets != null) { - for (int index = 0; index < targets.size(); index++) { - Vertex target = targets.get(index).getTarget(); - // Get last input said by target. - Vertex lastInput = getLastInputInConversation(conversation, target, 1); - // Abort if is first question and talking to self. - if (input == lastInput) { - return sentence; - } - if (lastInput == null) { - continue; - } - Vertex lastSentence = lastInput.mostConscious(Primitive.INPUT); - Vertex mimic = lastInput.getRelationship(Primitive.MIMIC); - if (mimic != null) { - lastSentence = mimic.mostConscious(Primitive.INPUT); - } - if (lastSentence == null) { - continue; - } - float value = 1.0f/(index + (1/this.learningRate)); - if (!shouldLearn(input, speaker)) { - // Still maintain input state. - lastInput.addWeakRelationship(Primitive.RESPONSE, input, value); - input.addWeakRelationship(Primitive.QUESTION, lastInput, value); - } else { - // Associate response. - // Associate previous question as meta info. - Vertex previousQuestionInput = lastInput.getRelationship(Primitive.QUESTION); - sentence.addWeakRelationship(Primitive.QUESTION, lastSentence, value); - lastInput.addWeakRelationship(Primitive.RESPONSE, input, value); - lastSentence.associateAll(Primitive.WORD, lastSentence, Primitive.QUESTION); - input.addWeakRelationship(Primitive.QUESTION, lastInput, value); - Relationship relationship = null; - if (index == 0) { - relationship = getBot().mind().getThought(Comprehension.class).checkTemplate(input, network); - if (relationship == null) { - relationship = lastSentence.addWeakRelationship(Primitive.RESPONSE, sentence, value); - network.checkReduction(lastSentence); - lastSentence.weakAssociateAll(Primitive.SYNONYM, sentence, Primitive.RESPONSE, value); - } - } else { - relationship = lastSentence.addWeakRelationship(Primitive.RESPONSE, sentence, value); - } - addSentencePreviousMeta(relationship, previousQuestionInput, network); - } - log("Listening sentence", Level.FINE, lastSentence); - } - } - if (speaker != null) { - Vertex lastInput = getLastInputInConversation(speaker, conversation, 1); - if (lastInput != null) { - Vertex lastSentence = lastInput.mostConscious(Primitive.INPUT); - if (lastSentence != null) { - lastSentence.addRelationship(Primitive.NEXT, sentence); - sentence.addRelationship(Primitive.PREVIOUS, lastSentence); - } - } - } - return sentence; - } - - /** - * Compute the real value of the sentence. - */ - public int computeMaxSentenceValue(Vertex match, Vertex original, Network network) { - Collection words = match.getRelationships(Primitive.WORD); - int max = 0; - for (Relationship word : words) { - boolean found = false; - Vertex lowercase = invertWordCase(word.getTarget(), network); - if (original.hasRelationship(Primitive.WORD, word.getTarget())) { - found = true; - } else { - if ((lowercase != null) && (lowercase != word)) { - if (original.hasRelationship(Primitive.WORD, lowercase)) { - found = true; - } - } - // TODO synonyms, uppercase - } - if (found) { - int value = computeWordValue(word.getTarget()); - if ((lowercase != null) && (lowercase != word)) { - value = Math.max(value, computeWordValue(lowercase)); - } - max = max + value; - } - } - return max; - } - - /** - * Return the matching value for the word, some word types are worth more than others. - */ - public int computeWordValue(Vertex word) { - int value = 2; - int count = 0; - if (word.instanceOf(Primitive.NOUN)) { - value = value + 12; - count++; - } - if (word.instanceOf(Primitive.ADJECTIVE)) { - value = value + 6; - count++; - } - if (word.instanceOf(Primitive.INTERJECTION)) { - value = value + 6; - count++; - } - if (word.instanceOf(Primitive.VERB)) { - value = value + 4; - count++; - } - if (word.instanceOf(Primitive.QUESTION)) { - value = value + 3; - count++; - } - if (word.instanceOf(Primitive.ADVERB)) { - value = value + 2; - count++; - } - if (count == 0) { - // Check for meaning. - Collection meanings = word.getRelationships(Primitive.MEANING); - if (meanings != null) { - for (Relationship relation : meanings) { - Vertex meaning = relation.getTarget(); - // Value nouns and adjective over other words. - if (meaning.instanceOf(Primitive.THING)) { - value = value + 12; - } else if (meaning.instanceOf(Primitive.DESCRIPTION)) { - value = value + 6; - } else if (meaning.instanceOf(Primitive.INTERJECTION)) { - value = value + 6; - } else if (meaning.instanceOf(Primitive.ACTION)) { - value = value + 4; - } else if (meaning.instanceOf(Primitive.QUESTION)) { - value = value + 3; - } else { - value = value + 2; - } - // TODO consider consciousness level, number of relationships - } - value = value / meanings.size(); - } else { - // Unknown word, may not have discovered it yet, so give it a +4. - value = value + 4; - } - } else { - value = value / count; - } - if (word.instanceOf(Primitive.PUNCTUATION) || (word.instanceOf(Primitive.ARTICLE))) { - value = 1; - } - if (word.instanceOf(Primitive.KEYWORD)) { - value = 25; - } - return value; - } - - /** - * Add all of the sentences for the word with its value. - */ - public void recordSetenceValues(Vertex word, Vertex originalWord, Collection relationships, int value, Vertex sentence, - Map matches, Map> processed, Network network, List defer) { - if (relationships != null) { - if ((defer != null) && relationships.size() > 100) { - log("Deferring word", Level.FINER, word, relationships.size()); - defer.add(word); - return; - } - for (Relationship sentenceRelation : relationships) { - Vertex otherSentence = sentenceRelation.getTarget(); - if (sentence != otherSentence) { - // Only index sentences with responses. - if (otherSentence.hasAnyResponseRelationship()) { - Set processedWords = processed.get(otherSentence); - if (processedWords == null) { - processedWords = new HashSet(4); - processed.put(otherSentence, processedWords); - } - if (processedWords.contains(originalWord)) { - log("Already processed word for sentence", Level.FINEST, word, otherSentence); - } else { - processedWords.add(originalWord); - Integer count = matches.get(otherSentence); - if (count == null) { - count = 0; - } - matches.put(otherSentence, count + value); - log("Increasing question match value", Level.FINER, otherSentence, count + value, value); - } - } else { - log("Sentence has no responses", Level.FINEST, otherSentence); - } - } - } - } - } - - /** - * Add all of the patterns for the word with its value. - */ - public void recordPatternValues(Vertex word, Vertex sentence, Map matches, Network network, List defer) { - Collection sentenceRelations = word.getRelationships(Primitive.PATTERN); - if (sentenceRelations != null) { - if ((defer != null) && sentenceRelations.size() > 100) { - defer.add(word); - return; - } - int value = computeWordValue(word); - for (Relationship sentenceRelation : sentenceRelations) { - Vertex otherSentence = sentenceRelation.getTarget(); - if (sentence != otherSentence) { - // Only index sentences with responses. - if (otherSentence.hasAnyResponseRelationship()) { - Integer count = matches.get(otherSentence); - if (count == null) { - count = 0; - } - matches.put(otherSentence, count + value); - } - } - } - // Record max value. - Integer count = matches.get(sentence); - if (count == null) { - count = 0; - } - matches.put(sentence, count + value); - } - } - - public static Vertex invertWordCase(Vertex word, Network network) { - if (!(word.getData() instanceof String)) { - return null; - } - String text = (String)word.getData(); - if (Utils.isCaps(text) || Utils.isCapitalized(text)) { - return network.findByData(((String)word.getData()).toLowerCase()); - } else { - return network.findByData(Utils.capitalize((String)word.getData())); - } - } - - /** - * Add all of the questions for all of the words to the matching map. - */ - public void addQuestionMatches(Vertex sentence, Network network, long startTime, long processTime, List wordRelations, - Map matches, Map> processed, Primitive key, boolean keywords) { - List deferred = new ArrayList(); - for (Relationship wordRelation : wordRelations) { - Vertex word = wordRelation.getTarget(); - Vertex lowercase = invertWordCase(word, network); - Vertex uppercase = network.findByData(((String)word.getData()).toUpperCase()); - if (keywords && (!word.instanceOf(Primitive.KEYWORD) - && (lowercase == null || !lowercase.instanceOf(Primitive.KEYWORD)) - && (uppercase == null || !uppercase.instanceOf(Primitive.KEYWORD)))) { - continue; - } - long currentTime = System.currentTimeMillis(); - if ((currentTime - startTime) > processTime) { - log("Search time limit reached (time, matches)", Level.INFO, processTime, matches.size()); - break; - } - int value = computeWordValue(word); - if ((lowercase != null) && (lowercase != word)) { - value = Math.max(value, computeWordValue(lowercase)); - } - if ((uppercase != null) && (uppercase != word)) { - value = Math.max(value, computeWordValue(uppercase)); - } - if (key.equals(Primitive.KEYQUESTION)) { - value = value + 4; // Weight keyquestion more. - } - Collection questions = word.getRelationships(key); - if (questions != null) { - log("Finding similar questions for word (word, value, questions, keyword)", Level.FINER, word.getData(), value, questions.size(), keywords); - recordSetenceValues(word, word, questions, value, sentence, matches, processed, network, deferred); - } - if ((lowercase != null) && (lowercase != word)) { - questions = lowercase.getRelationships(key); - if (questions != null) { - log("Finding similar questions for word lowercase (word, value, questions, keyword)", Level.FINER, lowercase.getData(), value, questions.size(), keywords); - recordSetenceValues(lowercase, word, questions, value, sentence, matches, processed, network, deferred); - } - } - if ((uppercase != null) && (uppercase != word)) { - questions = uppercase.getRelationships(key); - if (questions != null) { - log("Finding similar questions for word uppercase (word, value, questions, keyword)", Level.FINER, uppercase.getData(), value, questions.size(), keywords); - recordSetenceValues(uppercase, word, questions, value, sentence, matches, processed, network, deferred); - } - } - // TODO synonyms, plurals, conjegations - } - // Process keywords with lots of sentences last. - for (Vertex word : deferred) { - long currentTime = System.currentTimeMillis(); - if ((currentTime - startTime) > processTime) { - log("Search time limit reached (time, matches)", Level.INFO, processTime, matches.size()); - break; - } - int value = computeWordValue(word); - Vertex lowercase = invertWordCase(word, network); - if ((lowercase != null) && (lowercase != word)) { - value = Math.max(value, computeWordValue(lowercase)); - } - Vertex uppercase = network.findByData(((String)word.getData()).toUpperCase()); - if ((uppercase != null) && (uppercase != word)) { - value = Math.max(value, computeWordValue(uppercase)); - } - Collection questions = word.getRelationships(key); - if (questions != null) { - log("Checking deferred word (word, value, questions)", Level.FINER, word.getData(), value, questions.size()); - recordSetenceValues(word, word, questions, value, sentence, matches, processed, network, null); - } - } - } - - /** - * Find the best match for the sentence. - * Traverse its words to find other sentences they are used in, - * and pick other sentence with the most words in common. - */ - @SuppressWarnings("unchecked") - public Relationship findResponseMatch(Vertex sentence, Vertex previousResponse, Vertex input, Map variables, Network network, float percentage) { - if (!this.enableResponseMatch) { - return null; - } - List wordRelations = sentence.orderedRelationships(Primitive.WORD); - if (wordRelations == null) { - return null; - } - long startTime = System.currentTimeMillis(); - log("Searching for similar questions", Level.FINE); - Map matches = new HashMap(); - Map> processed = new HashMap>(); - long processTime = Math.min(MAX_PROCCESS_TIME, this.maxResponseMatchProcess); - if (getBot().isDebugFine()) { - log("Increasing processing time to allow debugging", Level.INFO, getBot().getDebugLevel()); - processTime = processTime * 20; - } - // Record all keyword matches. - addQuestionMatches(sentence, network, startTime, processTime, wordRelations, matches, processed, Primitive.KEYQUESTION, true); - addQuestionMatches(sentence, network, startTime, processTime, wordRelations, matches, processed, Primitive.QUESTION, true); - Map keyWordsMatches = new HashMap(matches); - addQuestionMatches(sentence, network, startTime, processTime, wordRelations, matches, processed, Primitive.QUESTION, false); - if (this.learnGrammar) { - addQuestionMatches(sentence, network, startTime, processTime, wordRelations, matches, processed, Primitive.SENTENCE, false); - } - - // Find the best match. - int wordCount = wordRelations.size(); - double multiplier = (1.0 - percentage) * 15; - int tooBig = (int) (wordCount * multiplier) + 2; - int tooSmall = 0; - Map.Entry bestMatch = null; - int bestAbs = 0; - Relationship bestResponse = null; - Object[] best = new Object[3]; - best[0] = bestMatch; - best[1] = bestAbs; - best[2] = bestResponse; - startTime = System.currentTimeMillis(); - log("Searching for best question match (min words, max words, match size)", Level.FINE, tooSmall, tooBig, matches.size()); - if (!matches.isEmpty()) { - // Pre-compute data - Vertex previousQuestionInput = input.getRelationship(Primitive.QUESTION); - Vertex previousQuestion = null; - if (previousQuestionInput != null) { - previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - } - Vertex conversation = input.getRelationship(Primitive.CONVERSATION); - Vertex currentTopic = null; - if (conversation != null) { - currentTopic = conversation.mostConscious(Primitive.TOPIC); - } - Set questionWords = new HashSet(); - Collection wordRelationships = sentence.getRelationships(Primitive.WORD); - if (wordRelationships != null) { - for (Relationship relationship : wordRelationships) { - questionWords.add(relationship.getTarget().getDataValue().toLowerCase()); - } - } - // Search for best response - // First check the best value match - int bestValue = 0; - Map.Entry bestEntry = null; - Map.Entry secondBestEntry = null; - for (Map.Entry entry : matches.entrySet()) { - if (entry.getValue() > bestValue && (sentence != entry.getKey())) { - bestValue = entry.getValue(); - bestEntry = entry; - secondBestEntry = bestEntry; - } - } - if (bestEntry != null) { - checkBetterMatch(bestEntry, keyWordsMatches, best, tooBig, tooSmall, wordCount, - percentage, input, bestEntry.getKey(), sentence, previousResponse, true, false, previousQuestion, questionWords, currentTopic, variables, network); - } - if (best[0] == null && secondBestEntry != null) { - checkBetterMatch(secondBestEntry, keyWordsMatches, best, tooBig, tooSmall, wordCount, - percentage, input, secondBestEntry.getKey(), sentence, previousResponse, true, false, previousQuestion, questionWords, currentTopic, variables, network); - } - int count = 0; - for (Map.Entry entry : matches.entrySet()) { - long currentTime = System.currentTimeMillis(); - if ((currentTime - startTime) > processTime) { - log("Process time limit reached (time, matches, processed)", Level.INFO, processTime, matches.size(), count); - break; - } - count++; - checkBetterMatch(entry, keyWordsMatches, best, tooBig, tooSmall, wordCount, - percentage, input, entry.getKey(), sentence, previousResponse, true, false, previousQuestion, questionWords, currentTopic, variables, network); - } - } - bestMatch = (Map.Entry) best[0]; - bestAbs = (Integer) best[1]; - bestResponse= (Relationship) best[2]; - if (bestResponse == null) { - log("No valid question match", Level.FINE); - return null; - } - if (keyWordsMatches.containsKey(bestMatch.getKey())) { - log("Question keyword match", Level.FINE); - } else { - int max = computeMaxSentenceValue(bestMatch.getKey(), bestMatch.getKey(), network); - // If % then ok. - double required = max * percentage * 0.8; - // Recompute value using all words, as some words may not store relation to sentence. - int matchValue = computeMaxSentenceValue(bestMatch.getKey(), sentence, network); - log("Question best match (score, max score, required score, question)", Level.FINE, matchValue, max, required, bestMatch.getKey()); - if (matchValue < required) { - log("Question bad match, insufficient score (score, required score, question)", Level.FINE, matchValue, required, bestMatch.getKey()); - this.lastResponseMetaId = null; - return null; - } - int matchMax = computeMaxSentenceValue(bestMatch.getKey(), bestMatch.getKey(), network); - if (matchValue * multiplier < matchMax) { - log("Question bad match, too generic (score, multiplier, value, match max, question)", Level.FINE, matchValue, multiplier, matchValue * multiplier, matchMax, bestMatch.getKey()); - this.lastResponseMetaId = null; - return null; - } - } - log("Question match response", Level.FINE, bestResponse); - return bestResponse; - } - - @SuppressWarnings("unchecked") - public void checkBetterMatch(Map.Entry entry, Map keyWordsMatches, Object[] best, int tooBig, int tooSmall, int wordCount, - float percentage, Vertex input, Vertex sentence, Vertex question, Vertex previousResponse, boolean cascade, - boolean init, Vertex previousQuestion, Set questionWords, Vertex currentTopic, Map variables, Network network) { - Map.Entry bestMatch = (Map.Entry) best[0]; - int bestAbs = (Integer) best[1]; - if (bestMatch != null && (entry.getValue() < bestMatch.getValue())) { - return; - } - if (question == entry.getKey() || entry.getKey().instanceOf(Primitive.PATTERN)) { - return; - } - log("Processing (value, question)", Level.FINER, entry.getValue(), entry.getKey()); - Collection relationships = entry.getKey().getRelationships(Primitive.WORD); - if (relationships == null) { - return; - } - int entryWordCount = relationships.size(); - boolean hasKeyword = keyWordsMatches.containsKey(entry.getKey()); - // Ignore if too big or too small. - if (hasKeyword || (entryWordCount <= tooBig) && (entryWordCount >= tooSmall)) { - int entryAbs = Math.abs(wordCount - entryWordCount); - if (bestMatch == null || (entry.getValue() > bestMatch.getValue()) || (entryAbs < bestAbs)) { - Relationship response = null; - response = bestResponse(percentage, input, entry.getKey(), sentence, previousResponse, - false, false, previousQuestion, questionWords, currentTopic, variables, network); - if (response != null) { - log("Better question match (value, question)", Level.FINE, entry.getValue(), entry.getKey()); - best[0] = entry; - best[1] = entryAbs; - best[2] = response; - } - } - } - } - - /** - * Find the best pattern that matches the sentence. - */ - public Relationship matchPattern(Vertex sentence, Vertex previousResponse, Vertex input, Map variables, Network network, float percentage) { - List wordRelations = sentence.orderedRelationships(Primitive.WORD); - if (wordRelations == null) { - return null; - } - long startTime = System.currentTimeMillis(); - Map matches = new HashMap(); - long processTime = Math.min(MAX_PROCCESS_TIME, this.maxResponseMatchProcess); - // Record all of the matches. - List deferred = new ArrayList(); - for (Relationship wordRelation : wordRelations) { - long currentTime = System.currentTimeMillis(); - if ((currentTime - startTime) > processTime) { - log("Pattern search time limit reached", Level.INFO, processTime, matches.size()); - break; - } - Vertex word = wordRelation.getTarget(); - recordPatternValues(word, sentence, matches, network, deferred); - Vertex lowercase = null; - if (!(word.getData() instanceof String)) { - return null; - } - String text = (String)word.getData(); - if (Utils.isCaps(text) || Utils.isCapitalized(text)) { - lowercase = network.findByData(((String)word.getData()).toLowerCase()); - } else { - lowercase = network.findByData(Utils.capitalize((String)word.getData())); - } - if ((lowercase != null) && (lowercase != word)) { - recordPatternValues(lowercase, sentence, matches, network, deferred); - } - } - // Process words with lots of sentences last. - for (Vertex word : deferred) { - long currentTime = System.currentTimeMillis(); - if ((currentTime - startTime) > processTime) { - log("Pattern search time limit reached", Level.INFO, processTime, matches.size()); - break; - } - recordPatternValues(word, sentence, matches, network, null); - } - // Find the best match. - Map.Entry bestMatch = null; - Relationship bestResponse = null; - boolean bestHasUnderscore = false; - startTime = System.currentTimeMillis(); - log("Found possible patterns", Level.FINE, matches.size()); - if (!matches.isEmpty()) { - // Pre-compute data - Vertex previousQuestionInput = input.getRelationship(Primitive.QUESTION); - Vertex previousQuestion = null; - if (previousQuestionInput != null) { - previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - } - Vertex conversation = input.getRelationship(Primitive.CONVERSATION); - Vertex currentTopic = null; - if (conversation != null) { - currentTopic = conversation.mostConscious(Primitive.TOPIC); - } - Set questionWords = new HashSet(); - Collection wordRelationships = sentence.getRelationships(Primitive.WORD); - if (wordRelationships != null) { - for (Relationship relationship : wordRelationships) { - questionWords.add(relationship.getTarget().getDataValue().toLowerCase()); - } - } - for (Map.Entry entry : matches.entrySet()) { - long currentTime = System.currentTimeMillis(); - if ((currentTime - startTime) > processTime) { - log("Pattern process time limit reached", Level.INFO, processTime, matches.size()); - break; - } - if (sentence == entry.getKey()) { - continue; - } - if (bestMatch == null) { - if (!evaluatePattern(entry.getKey(), sentence, Primitive.WILDCARD, variables, network)) { - continue; - } - bestResponse = bestResponse(percentage, input, entry.getKey(), sentence, previousResponse, - false, false, previousQuestion, questionWords, currentTopic, variables, network); - if (bestResponse != null) { - bestMatch = entry; - bestHasUnderscore = entry.getKey().hasRelationship(Primitive.WORD, Primitive.UNDERSCORE) - || entry.getKey().hasRelationship(Primitive.WORD, Primitive.POUNDWILDCARD) - || entry.getKey().hasRelationship(Primitive.TYPE, Primitive.PRECEDENCE); - } - } else { - boolean hasUnderscore = entry.getKey().hasRelationship(Primitive.WORD, Primitive.UNDERSCORE) - || entry.getKey().hasRelationship(Primitive.WORD, Primitive.POUNDWILDCARD) - || entry.getKey().hasRelationship(Primitive.TYPE, Primitive.PRECEDENCE); - if (entry.getValue() > bestMatch.getValue() || (hasUnderscore && ! bestHasUnderscore)) { - if (!evaluatePattern(entry.getKey(), sentence, Primitive.WILDCARD, variables, network)) { - continue; - } - Relationship response = bestResponse(percentage, input, entry.getKey(), sentence, previousResponse, - false, false, previousQuestion, questionWords, currentTopic, variables, network); - if (response != null) { - bestResponse = response; - if (bestResponse != null) { - bestMatch = entry; - bestHasUnderscore = hasUnderscore; - } - } - } - } - } - } - if (bestResponse == null) { - log("No valid pattern", Level.FINE); - return null; - } - log("Pattern match", Level.FINE, bestMatch.getKey(), bestResponse); - return bestResponse; - } - - /** - * Attempt to understand the sentence using state machines. - */ - public Vertex processUnderstanding(Vertex input, Vertex sentence, float correctnessRequired, Map variables, Network network) { - if (!sentence.hasRelationship(Primitive.WORD)) { - return null; - } - // Lookup and apply language rules. - // Use read-only states to improve performance, as they will not be modified. - Network readOnlyMemory = getBot().memory().getLongTermMemory(); - Vertex language = readOnlyMemory.createVertex(getPrimitive()); - List states = language.orderedRelations(Primitive.STATE); - if (states == null || states.isEmpty()) { - return null; - } - List compoundWords = processCompoundWords(sentence.orderedRelationships(Primitive.WORD)); - Vertex compoundSentence = sentence; - // Check if the input has compound words. - if (compoundWords != null) { - if (compoundWords != null) { - // Sentence had compound words, so need to create new sentence and switch input. - compoundSentence = network.createInstance(Primitive.SENTENCE); - for (int index = 0; index < compoundWords.size(); index++) { - Vertex word = compoundWords.get(index); - compoundSentence.addRelationship(Primitive.WORD, word, index); - } - } - } - List inputs = new ArrayList(1); - inputs.add(input); - Vertex response = checkState(null, input, compoundSentence, states, 0, 0, inputs, variables, new ArrayList(), correctnessRequired, network); - if ((response == null) && (compoundWords != null)) { - // If had compound words, also check without them. - variables = new HashMap(); - SelfCompiler.addGlobalVariables(input, sentence, network, variables); - response = checkState(null, input, sentence, states, 0, 0, inputs, variables, new ArrayList(), correctnessRequired, network); - } - if (response != null) { - response = getWord(response, network); - if (response != null) { - log("Sentence understood", Level.FINE, sentence, response); - } else { - log("Sentence understood but no words", Level.FINE, sentence); - response = null; - } - } else { - log("Sentence not understood", Level.FINE, sentence); - } - return response; - } - - /** - * Transform the list of words, into a list of compound words. - */ - public List processCompoundWords(List words) { - List compoundedWords = new ArrayList(words.size()); - for (int index = 0; index < words.size(); index++) { - Vertex word = words.get(index).getTarget(); - // Get the compound words for each word. - Collection compoundWords = word.getRelationships(Primitive.COMPOUND_WORD); - if (compoundWords == null) { - // No compound words, so just add the single word. - compoundedWords.add(word); - } else { - boolean found = false; - // Check each compound word, to see if it follows the word. - for (Relationship compundWord : compoundWords) { - int compoundIndex = 1; - List wordParts = compundWord.getTarget().orderedRelationships(Primitive.WORD); - if ((wordParts == null) || (wordParts.size() <= 1)) { - // Avoid corrupt data (from forgetfullness). - break; - } - // Check that all the compound words are contained. - while (((index + compoundIndex) < words.size()) && (compoundIndex < wordParts.size())) { - Vertex wordPart = wordParts.get(compoundIndex).getTarget(); - Vertex nextWord = words.get(index + compoundIndex).getTarget(); - // If the words don't match, then stop checking and check the next compound word. - if (!wordPart.equals(nextWord)) { - break; - } - compoundIndex++; - } - // If the compound word is a match, the add it. - // TODO: What if multiple compound words match? Take longest, or most conscious? - if (compoundIndex == wordParts.size()) { - found = true; - log("Compound word found", Level.FINE, compundWord.getTarget()); - compoundedWords.add(compundWord.getTarget()); - index = index + compoundIndex - 1; - break; - } - } - if (!found) { - for (Relationship compundWord : compoundWords) { - int compoundIndex = 1; - List wordParts = compundWord.getTarget().orderedRelationships(Primitive.WORD); - if ((wordParts == null) || (wordParts.size() <= 1)) { - // Avoid corrupt data (from forgetfullness). - break; - } - // Check that all the compound words are contained. - while (((index + compoundIndex) < words.size()) && (compoundIndex < wordParts.size())) { - Vertex wordPart = wordParts.get(compoundIndex).getTarget(); - Vertex nextWord = words.get(index + compoundIndex).getTarget(); - // If the words don't match, then stop checking and check the next compound word. - if (!wordPart.equalsIgnoreCase(nextWord)) { - break; - } - compoundIndex++; - } - // If the compound word is a match, the add it. - // TODO: What if multiple compound words match? Take longest, or most conscious? - if (compoundIndex == wordParts.size()) { - found = true; - log("Compound word found", Level.FINE, compundWord.getTarget()); - compoundedWords.add(compundWord.getTarget()); - index = index + compoundIndex - 1; - break; - } - } - } - if (!found) { - compoundedWords.add(word); - } - } - } - if (words.size() == compoundedWords.size()) { - return null; - } - return compoundedWords; - } - - /** - * Apply each state machine vertex to the sentence of words. - * If the state machine finds a match, it will record the real vertices mapped to the state machine variables. - */ - public Vertex checkState(Vertex root, Vertex input, Vertex sentence, List states, int index, int recurse, List inputs, Map variables, List stateStack, float correctnessRequired, Network network) { - if (states == null || this.abort) { - return null; - } - if (this.startTime == 0) { - this.startTime = System.currentTimeMillis(); - } - long processTime = Math.min(this.maxStateProcess, MAX_PROCCESS_TIME); - if (getBot().isDebugFiner()) { - processTime = processTime * 10; - } - Vertex state = null; - try { - while (index <= inputs.size()) { - Vertex currentInput = null; - if (index < inputs.size()) { - currentInput = inputs.get(index); - } - // Check each state machine for a match. - for (ListIterator iterator = states.listIterator(); iterator.hasNext(); ) { - if (this.abort) { - return null; - } - if ((System.currentTimeMillis() - this.startTime) > processTime) { - log("State processing time limit reached", Level.WARNING, processTime, root, state); - this.abort = true; - return null; - } - if (stateStack.size() > MAX_STACK) { - log("State stack overflow", Level.WARNING, MAX_STACK, root, state); - this.abort = true; - return null; - } - // Record local variables so they can be discarded if there is no match. - Map localVariables = new HashMap(variables); - state = iterator.next(); - Vertex lastState = null; - if (!stateStack.isEmpty()) { - lastState = stateStack.get(stateStack.size() - 1); - } - stateStack.add(state); - Vertex newRoot = root; - Vertex decompiled = SelfDecompiler.getDecompiler().decompileState(state, state.getNetwork()); - if (root == null) { - newRoot = state; - log("STATE MACHINE", Level.FINE, state, currentInput); - if (!this.loadedStates.contains(state.getId()) && (stateStack.size() == 1) && this.loadedStates.size() < 20) { - this.loadedStates.add(state.getId()); - SelfCompiler.getCompiler().fastLoadChildren(state); - } - // Record root state variable. - localVariables.put(network.createVertex(Primitive.STATE), decompiled); - } else { - log("STATE", Level.FINER, state, currentInput); - } - Collection equations = decompiled.orderedRelationships(Primitive.DO); - Vertex response = null; - if (equations != null) { - for (Relationship equationRelationship : equations) { - if (this.abort) { - return null; - } - if ((System.currentTimeMillis() - this.startTime) > processTime) { - log("State processing time limit reached", Level.WARNING, processTime, root, state); - this.abort = true; - return null; - } - Vertex equation = equationRelationship.getTarget(); - if (equation.instanceOf(Primitive.CASE) || equation.hasRelationship(Primitive.PATTERN)) { - - List fors = equation.orderedRelationships(Primitive.FOR); - if (fors != null) { - fors = null; - } - Vertex pattern = equation.getRelationship(Primitive.PATTERN); - Vertex caseVariable = null; - Boolean match = false; - boolean anyOrNone = false; - boolean emptyMatch = false; - if (pattern != null) { - log("PATTERN", Level.FINER, pattern, currentInput); - caseVariable = pattern; - // Avoid checking pattern again if in recursive state. - if (lastState != state) { - match = evaluatePattern(pattern, sentence, Primitive.WILDCARD, localVariables, network); - } - } else { - caseVariable = equation.getRelationship(Primitive.CASE); - if (caseVariable != null && (!caseVariable.isVariable())) { - if ((caseVariable.instanceOf(Primitive.EXPRESSION) || caseVariable.instanceOf(Primitive.EQUATION))) { - caseVariable = SelfInterpreter.getInterpreter().evaluateExpression(caseVariable, localVariables, network, this.startTime, processTime, 0); - } else if (caseVariable.instanceOf(Primitive.FUNCTION)) { - caseVariable = SelfInterpreter.getInterpreter().evaluateFunction(caseVariable, localVariables, network, this.startTime, processTime, 0); - } - } - if (caseVariable != null) { - anyOrNone = (caseVariable.getName() != null && (caseVariable.getName().equals("poundstar") || caseVariable.getName().equals("hatstar"))) - || ((caseVariable.instanceOf(Primitive.ARRAY) || caseVariable.instanceOf(Primitive.LIST)) - && !caseVariable.hasRelationship(Primitive.TYPE, Primitive.REQUIRED)); - } - if (index >= inputs.size()) { - if (anyOrNone) { - emptyMatch = true; - match = Boolean.TRUE; - log("CASE", Level.FINER, caseVariable, currentInput); - } else { - continue; - } - } else { - currentInput = inputs.get(index); - log("CASE", Level.FINER, caseVariable, currentInput); - if (caseVariable != null) { - match = caseVariable.matches(currentInput, localVariables); - if (match != Boolean.TRUE && caseVariable.isPrimitive() && currentInput != null && currentInput.instanceOf(Primitive.WORD)) { - // Also allow primitive to match words meaning. - if (currentInput.hasRelationship(Primitive.MEANING, caseVariable)) { - match = true; - } - } - if (currentInput == input) { - Vertex sentenceVariable = caseVariable.getRelationship(Primitive.INPUT); - if (sentenceVariable != null) { - localVariables.put(sentenceVariable, sentence); - } - } - } - if (match != Boolean.TRUE && anyOrNone) { - emptyMatch = true; - match = Boolean.TRUE; - } - } - } - if (match == Boolean.TRUE) { - Vertex topic = equation.getRelationship(Primitive.TOPIC); - if (topic != null) { - match = false; - Vertex conversation = input.getRelationship(Primitive.CONVERSATION); - Vertex currentTopic = null; - if (conversation != null) { - currentTopic = conversation.getRelationship(Primitive.TOPIC); - } - log("Checking topic", Level.FINER, topic, currentTopic); - if (currentTopic != null) { - match = evaluatePattern(topic, currentTopic, Primitive.TOPICWILDCARD, localVariables, network); - } - } - Vertex that = equation.getRelationship(Primitive.THAT); - if (match && (that != null)) { - match = false; - Vertex questionInput = input.getRelationship(Primitive.QUESTION); - log("Checking that", Level.FINER, that, questionInput); - if (questionInput != null) { - Vertex question = questionInput.getRelationship(Primitive.INPUT); - if (question != null) { - match = evaluatePattern(that, question, Primitive.THATWILDCARD, localVariables, network); - if (!match) { - // Check if the question was a paragraph, then need to check eat part. - network.createParagraph(question); - if (question.instanceOf(Primitive.PARAGRAPH)) { - Collection relationships = question.getRelationships(Primitive.SENTENCE); - if (relationships != null) { - for (Relationship relationship : relationships) { - match = evaluatePattern(that, relationship.getTarget(), Primitive.THATWILDCARD, localVariables, network); - if (match) { - break; - } - } - } - } - } - } - } - } - } - // Check if the word matches the state machine variable. - if (match == Boolean.TRUE) { - if (pattern != null) { - log("PATTERN MATCH", Level.FINE, pattern, currentInput); - } else { - log("CASE MATCH", Level.FINER, caseVariable, currentInput); - } - // Check next state/word recursively. - Vertex template = equation.getRelationship(Primitive.TEMPLATE); - if (template != null) { - if (template.instanceOf(Primitive.EQUATION) || template.instanceOf(Primitive.EXPRESSION) - || template.instanceOf(Primitive.FUNCTION)) { - response = evaluateAnswerResponse(template, state, localVariables, network); - if (response != null) { - return response; - } - } else { - if (template.getNetwork() != network) { - template = network.createVertex(template); - } - if ((template != null) && template.instanceOf(Primitive.LABEL)) { - template = template.mostConscious(Primitive.RESPONSE); - } - if (template.instanceOf(Primitive.FORMULA)) { - log("Template is template formula", Level.FINE, template); - response = evaluateFormula(template, localVariables, network); - if (response == null) { - log("Template formula cannot be evaluated", Level.FINE, template); - } else { - return response; - } - } else if (template.instanceOf(Primitive.EQUATION) || template.instanceOf(Primitive.EXPRESSION) - || template.instanceOf(Primitive.FUNCTION)) { - response = evaluateAnswerResponse(template, state, localVariables, network); - if (response != null) { - return response; - } - } else { - return template; - } - } - } - // Check for AS, maps case variable into target variable. - Vertex as = equation.getRelationship(Primitive.AS); - if (as != null) { - localVariables.put(as, localVariables.get(caseVariable)); - } - List gotoStates = equation.orderedRelations(Primitive.GOTO); - if (gotoStates != null) { - if ((gotoStates.size() == 1) && gotoStates.get(0).is(Primitive.RETURN)) { - log("CASE RETURN", Level.FINER); - return null; - } - List arguments = equation.orderedRelationships(Primitive.FOR); - List newInputs = inputs; - int newIndex = index + 1; - if (arguments != null) { - Vertex variable = arguments.get(1).getTarget(); - Vertex value = arguments.get(0).getTarget(); - newInputs = new ArrayList(); - Vertex variableValue = SelfInterpreter.getInterpreter().evaluateExpression(variable, localVariables, network, this.startTime, processTime, 0); - List relationships = variableValue.orderedRelationships(value); - if (relationships != null) { - for (Relationship result : relationships) { - newInputs.add(result.getTarget()); - } - } - newIndex = 0; - } - log("CASE GOTO STATE", Level.FINER, gotoStates); - if (!emptyMatch) { - response = checkState(newRoot, input, sentence, gotoStates, newIndex, recurse, newInputs, localVariables, stateStack, correctnessRequired, network); - } - if (response != null) { - return response; - } - if (anyOrNone && (newIndex == index + 1) && !gotoStates.contains(state)) { - // Also check matching nothing. - response = checkState(newRoot, input, sentence, gotoStates, index, recurse, newInputs, localVariables, stateStack, correctnessRequired, network); - } - if (response != null) { - return response; - } - } - } else { - log("Case not matched", Level.FINER, caseVariable, currentInput); - } - } else if (equation.instanceOf(Primitive.DO)) { - log("DO", Level.FINER, state, currentInput); - SelfInterpreter.getInterpreter().evaluateExpression(equation.getRelationship(Primitive.DO), localVariables, network, this.startTime, processTime, 0); - localVariables.remove(network.createVertex(Primitive.RETURN)); - } else if (equation.instanceOf(Primitive.GOTO)) { - // May require terminal state. - if (!equation.hasRelationship(Primitive.FINALLY) || (index >= inputs.size())) { - List gotoStates = equation.orderedRelations(Primitive.GOTO); - log("GOTO", Level.FINER, state, gotoStates); - List arguments = equation.orderedRelations(Primitive.ARGUMENT); - if (arguments == null || arguments.isEmpty()) { - response = checkState(newRoot, input, sentence, gotoStates, index, recurse, inputs, localVariables, stateStack, correctnessRequired, network); - } else { - List newInputs = new ArrayList(); - for (Vertex argument : arguments) { - newInputs.add(SelfInterpreter.getInterpreter().evaluateExpression(argument, localVariables, network, this.startTime, processTime, 0)); - } - response = checkState(newRoot, input, sentence, gotoStates, 0, recurse, newInputs, localVariables, stateStack, correctnessRequired, network); - } - if (response != null) { - return response; - } - } - } else if (equation.instanceOf(Primitive.PUSH)) { - Vertex argument = equation.getRelationship(Primitive.ARGUMENT); - argument = SelfInterpreter.getInterpreter().evaluateExpression(argument, localVariables, network, this.startTime, processTime, 0); - log("PUSH", Level.FINER, state, argument); - inputs.add(index, argument); - } else if (equation.instanceOf(Primitive.RETURN)) { - log("RETURN", Level.FINER, state, currentInput); - List lastStates = new ArrayList(1); - Vertex current = stateStack.remove(stateStack.size() - 1); - Vertex last = stateStack.remove(stateStack.size() - 1); - lastStates.add(last); - Map newVariables = localVariables; - // Allow the return to clear the variable stack, or keep specific variables. - Collection arguments = equation.getRelationships(Primitive.ARGUMENT); - if (arguments != null) { - newVariables = new HashMap(variables); - for (Relationship variable : arguments) { - newVariables.put(variable.getTarget(), localVariables.get(variable.getTarget())); - } - } - // A return value is used as the next state value, (reruns the previous state with the new value). - Vertex value = equation.getRelationship(Primitive.RETURN); - if (value != null && value.isVariable()) { - value = localVariables.get(value); - if (value == null) { - value = network.createVertex(Primitive.NULL); - } - } - if (value != null) { - List newInputs = new ArrayList(inputs); - if (currentInput == null) { - newInputs.add(value); - } else { - index++; - newInputs.add(index, value); - } - recurse++; - if (recurse > MAX_DEPTH) { - stateStack.add(last); - stateStack.add(current); - throw new SelfExecutionException(current, "Max recursive state execution"); - } - response = checkState(newRoot, input, sentence, lastStates, index++, recurse, newInputs, newVariables, stateStack, correctnessRequired, network); - } else { - response = checkState(newRoot, input, sentence, lastStates, index++, recurse, inputs, newVariables, stateStack, correctnessRequired, network); - } - if (response != null) { - return response; - } - stateStack.add(last); - stateStack.add(current); - } - } - } - // Ignore punctuation. - if (currentInput != null && currentInput.instanceOf(Primitive.PUNCTUATION)) { - response = checkState(newRoot, input, sentence, states, index+1, recurse, inputs, localVariables, stateStack, correctnessRequired, network); - if (response != null) { - return response; - } - } - - // Check if the entire sentence was matched. - if ((index >= inputs.size())) { - Vertex[] pair = bestAnswer(correctnessRequired, decompiled, localVariables, input, sentence, network); - if (pair != null) { - response = pair[1]; - log("ANSWER", Level.FINER, state, response); - Vertex quotient = pair[0]; - setLastStateMachine(root); - setLastState(state); - setLastQuotient(quotient); - return response; - } - } - stateStack.remove(stateStack.size() - 1); - log("STATE DONE", Level.FINER, state, currentInput); - } - index++; - return null; - } - } catch (Exception failure) { - log("Error occured in processing state", Level.WARNING, root, state); - log(failure); - return null; - } finally { - if (root == null) { - log("State processing time", Level.FINE, System.currentTimeMillis() - startTime); - } - } - return null; - } - - /** - * Return the best response to the question, taking into account the input history. - */ - public Vertex[] bestAnswer(float percentage, Vertex state, Map localVariables, Vertex input, Vertex sentence, Network network) { - // Check if any response has the same previous question. - Vertex previousQuestionInput = input.getRelationship(Primitive.QUESTION); - Vertex previousQuestion = null; - if (previousQuestionInput != null) { - previousQuestion = previousQuestionInput.getRelationship(Primitive.INPUT); - if (previousQuestion != null) { - Collection quotients = state.getRelationships(Primitive.QUOTIENT); - if (quotients != null) { - Vertex bestResponse = null; - Relationship best = null; - Relationship bestWithPrevious = null; - for (Relationship quotient : quotients) { - if (quotient.getCorrectness() >= percentage) { - Vertex meta = quotient.getMeta(); - if (meta != null) { - if (hasPrevious(meta, previousQuestion, state, localVariables, network)) { - if ((bestWithPrevious == null) || (quotient.getCorrectness() > bestWithPrevious.getCorrectness())) { - Vertex response = evaluateAnswerResponse(quotient.getTarget(), state, localVariables, network); - if ((response == null) || sentence.hasInverseRelationship(Primitive.RESPONSE, response) - || sentence.hasAnyAssociatedInverseRelationship(Primitive.SYNONYM, response, Primitive.RESPONSE)) { - continue; - } else { - bestWithPrevious = quotient; - bestResponse = response; - } - } - } - Vertex label = previousQuestion.getRelationship(Primitive.LABEL); - if (meta.hasInverseRelationship(Primitive.PREVIOUS, previousQuestion) - || (label != null && meta.hasInverseRelationship(Primitive.PREVIOUS, label)) - || meta.hasRelationship(Primitive.REQUIRE, Primitive.PREVIOUS)) { - continue; - } - } - if ((bestWithPrevious == null) && ((best == null) || (quotient.getCorrectness() > best.getCorrectness()))) { - Vertex response = evaluateAnswerResponse(quotient.getTarget(), state, localVariables, network); - if ((response == null) || sentence.hasInverseRelationship(Primitive.RESPONSE, response) - || sentence.hasAnyAssociatedInverseRelationship(Primitive.SYNONYM, response, Primitive.RESPONSE)) { - continue; - } else { - best = quotient; - bestResponse = response; - } - } - } - } - if (bestWithPrevious != null) { - Vertex[] pair = new Vertex[2]; - pair[0] = bestWithPrevious.getTarget(); - pair[1] = bestResponse; - return pair; - } - if (bestResponse == null) { - return null; - } - Vertex[] pair = new Vertex[2]; - pair[0] = best.getTarget(); - pair[1] = bestResponse; - return pair; - } - } - } - Vertex quotient = state.mostConscious(Primitive.QUOTIENT, percentage); - if (quotient == null) { - return null; - } - Vertex response = evaluateAnswerResponse(quotient, state, localVariables, network); - if ((response == null) || sentence.hasInverseRelationship(Primitive.RESPONSE, response) - || sentence.hasAnyAssociatedInverseRelationship(Primitive.SYNONYM, response, Primitive.RESPONSE)) { - quotient = state.nextMostConscious(Primitive.QUOTIENT, quotient, percentage); - response = evaluateAnswerResponse(quotient, state, localVariables, network); - if ((response == null) || sentence.hasInverseRelationship(Primitive.RESPONSE, response) - || sentence.hasAnyAssociatedInverseRelationship(Primitive.SYNONYM, response, Primitive.RESPONSE)) { - return null; - } - } - Vertex[] pair = new Vertex[2]; - pair[0] = quotient; - pair[1] = response; - return pair; - } - - /** - * Return the best response to the question, taking into account the input history. - */ - public boolean hasPrevious(Vertex meta, Vertex sentence, Vertex state, Map localVariables, Network network) { - Collection relationship = meta.getRelationships(Primitive.PREVIOUS); - if (relationship == null) { - return false; - } - if (meta.hasRelationship(Primitive.PREVIOUS, sentence)) { - return true; - } - Vertex label = sentence.getRelationship(Primitive.LABEL); - if (label != null && meta.hasRelationship(Primitive.PREVIOUS, label)) { - return true; - } - for (Relationship previous : relationship) { - if (previous.getTarget().instanceOf(Primitive.FORMULA)) { - log("Previous is template formula", Level.FINE, previous.getTarget()); - Vertex result = evaluateFormula(previous.getTarget(), localVariables, network); - if (result == null) { - log("Template formula cannot be evaluated", Level.FINE, previous.getTarget()); - } else if (result.equals(sentence)) { - return true; - } - } - } - return false; - } - - /** - * Evaluate the quotient and possible formula response. - */ - public Vertex evaluateAnswerResponse(Vertex answer, Vertex state, Map localVariables, Network network) { - Vertex response = null; - if (answer != null) { - long processTime = Math.min(this.maxStateProcess, MAX_PROCCESS_TIME); - if (getBot().isDebugFiner()) { - processTime = processTime * 10; - } - log("Evaluating answer", Level.FINE, answer, state); - response = SelfInterpreter.getInterpreter().evaluateExpression(answer, localVariables, network, this.startTime, processTime, 0); - localVariables.remove(network.createVertex(Primitive.RETURN)); - log("Answer result", Level.FINE, response); - // Check for formula and transpose - if ((response != null) && response.instanceOf(Primitive.LABEL)) { - response = response.mostConscious(Primitive.RESPONSE); - } - if ((response != null) && response.instanceOf(Primitive.FORMULA)) { - log("Answer is template formula", Level.FINE, response); - response = evaluateFormula(response, localVariables, network); - if (response == null) { - log("Template formula cannot be evaluated", Level.FINE, response); - } - } else if ((response != null) && !response.hasData() && (response.instanceOf(Primitive.SENTENCE) || response.instanceOf(Primitive.FRAGMENT)) - && !response.instanceOf(Primitive.PARAGRAPH)) { - response = createSentenceText(response, network); - } - if ((response != null) && response.is(Primitive.NULL)) { - response = null; - } - } - return response; - } - - /** - * Create the text for the sentence. - */ - public Vertex createSentenceText(Vertex vertex, Network network) { - StringWriter writer = new StringWriter(); - List relationships = vertex.orderedRelationships(Primitive.WORD); - Vertex previous = network.createVertex(Primitive.NULL); - boolean inferWhitespace = !vertex.hasRelationship(Primitive.TYPE, Primitive.SPACE) && !vertex.hasRelationship(Primitive.WORD, Primitive.SPACE); - boolean caseSensitive = !this.fixFormulaCase || vertex.hasRelationship(Primitive.TYPE, Primitive.CASESENSITVE); - if (relationships != null) { - boolean first = true; - String last = null; - for (int index = 0; index < relationships.size(); index++) { - Relationship relationship = relationships.get(index); - Vertex next = network.createVertex(Primitive.NULL); - if (relationships.size() > (index + 1)) { - next = relationships.get(index + 1).getTarget(); - } - Vertex word = relationship.getTarget(); - if (word.is(Primitive.SPACE)) { - writer.write(" "); - continue; - } - if (!(word.getData() instanceof String)) { - word = getWordFollowing(word, relationship, previous, next, network); - } - String text = word.printString(); - if (!caseSensitive) { - if (first) { - text = Utils.capitalize(text); - } else if (text.equals("i") || text.equals("I")) { - text = text.toUpperCase(); - } else { - boolean isName = word.instanceOf(Primitive.NAME); - boolean isNoun = word.instanceOf(Primitive.NOUN); - boolean isVerb = word.instanceOf(Primitive.VERB) || word.instanceOf(Primitive.ARTICLE) - || word.instanceOf(Primitive.PRONOUN) || word.instanceOf(Primitive.QUESTION); - if (isName && !isVerb) { - text = Utils.capitalize(text); - } else if (isVerb && !isName && !isNoun) { - text = text.toLowerCase(); - } - } - } - if (inferWhitespace) { - if (!first && !text.equals("'") && !text.equals(")") && !"(".equals(last) && !"'".equals(last) && !text.equals("^") && !"^".equals(last) && (!(word.instanceOf(Primitive.PUNCTUATION)))) { - writer.write(" "); - } - } - writer.write(text); - first = text.equals("."); - previous = word; - last = text; - } - } - String text = writer.toString(); - Vertex sentence = network.createSentence(text.trim(), true); - if (vertex.hasRelationship(Primitive.TYPE, Primitive.CASESENSITVE)) { - sentence.addRelationship(Primitive.TYPE, Primitive.CASESENSITVE); - } - return sentence; - } - - /** - * Return the sentence or word for the vertex. - */ - public Vertex getWord(Vertex vertex, Network network) { - if (vertex.instanceOf(Primitive.SENTENCE) || vertex.instanceOf(Primitive.WORD)) { - if (!vertex.hasData()) { - // If it was a self created sentence it may not have text. - vertex = createSentenceText(vertex, network); - } - if (!vertex.instanceOf(Primitive.SENTENCE)) { - vertex.addRelationship(Primitive.INSTANTIATION, Primitive.SENTENCE); - } - return vertex; - } - // May be a string that needs to be converted to a sentence. - if (vertex.hasData() && (vertex.getData() instanceof String)) { - return network.createSentence((String)vertex.getData()); - } - if (vertex.instanceOf(Primitive.PARAGRAPH)) { - return vertex; - } - Vertex previous = network.createVertex(Primitive.NULL); - return getWordFollowing(vertex, previous, previous, network); - } - - /** - * Return the sentence or word for the vertex. - */ - public static Vertex getWordFollowing(Vertex vertex, Vertex previousWord, Vertex nextWord, Network network) { - return getWordFollowing(vertex, null, previousWord, nextWord, network); - } - - /** - * Return the sentence or word for the vertex. - */ - public static Vertex getWordFollowing(Vertex vertex, Relationship relationship, Vertex previousWord, Vertex nextWord, Network network) { - if (vertex.instanceOf(Primitive.WORD)) { - if (!vertex.hasData()) { - // Check if it is a newly create compound word that needs the text. - if (vertex.instanceOf(Primitive.COMPOUND_WORD)) { - Collection wordParts = vertex.orderedRelationships(Primitive.WORD); - if (wordParts != null) { - StringWriter writer = new StringWriter(); - boolean first = true; - for (Relationship wordPart : wordParts) { - if (!first) { - writer.write(" "); - } else { - first = false; - } - writer.write(wordPart.getTarget().getDataValue()); - } - return network.createWord(writer.toString()); - } - } - } - return vertex; - } - if (vertex.instanceOf(Primitive.FRAGMENT)) { - if (!vertex.hasData()) { - return network.createFragment(printFragment(vertex, previousWord, nextWord, network)); - } - return vertex; - } - if (vertex.instanceOf(Primitive.SENTENCE)) { - if (!vertex.hasData()) { - return network.createSentence(printFragment(vertex, previousWord, nextWord, network)); - } - return vertex; - } - if (vertex.instanceOf(Primitive.PARAGRAPH)) { - return vertex; - } - if (vertex.instanceOf(Primitive.ARRAY)) { - if (!vertex.hasData()) { - // Print the list. - Collection values = vertex.orderedRelationships(Primitive.ELEMENT); - if (values != null) { - StringWriter writer = new StringWriter(); - int index = 0; - for (Relationship value : values) { - if (!value.isInverse()) { - if (index != 0) { - writer.write(", "); - if (index == (values.size() - 1)) { - writer.write("and "); - } - } - writer.write(getWordFollowing(value.getTarget(), previousWord, nextWord, network).getDataValue()); - index++; - } - } - return network.createFragment(writer.toString()); - } else { - return network.createWord("empty"); - } - } - } else if (vertex.instanceOf(Primitive.LIST)) { - if (!vertex.hasData()) { - // Print the list. - Collection values = vertex.orderedRelationships(Primitive.SEQUENCE); - if (values != null) { - StringWriter writer = new StringWriter(); - int index = 0; - for (Relationship value : values) { - if (!value.isInverse()) { - if (index != 0) { - writer.write(", "); - if (index == (values.size() - 1)) { - writer.write("and "); - } - } - writer.write(getWordFollowing(value.getTarget(), previousWord, nextWord, network).getDataValue()); - index++; - } - } - return network.createFragment(writer.toString()); - } else { - return network.createWord("empty"); - } - } - } - // Verb conjugation - Vertex tense = null; - if (relationship != null && relationship.hasMeta()) { - tense = relationship.getMeta().getRelationship(Primitive.TENSE); - } - Vertex word = null; - if (vertex.instanceOf(Primitive.ACTION)) { - word = vertex.getAssoiate(network.createVertex(Primitive.WORD), - previousWord, network.createVertex(Primitive.CONJUGATION), - tense, network.createVertex(Primitive.TENSE), - previousWord, network.createVertex(Primitive.PREVIOUS)); - } - if (word == null) { - // Pronoun subjuction - Collection types = null; - if (relationship != null && relationship.hasMeta()) { - types = relationship.getMeta().getRelationships(Primitive.TYPE); - } - if (types == null) { - word = vertex.mostConscious(Primitive.NAME); - } - if (word == null) { - // What sounds right - if (nextWord != null && !nextWord.instanceOf(Primitive.WORD)) { - word = vertex.getAssoiate(network.createVertex(Primitive.WORD), - previousWord, network.createVertex(Primitive.PREVIOUS), - nextWord.getRelationships(Primitive.WORD), network.createVertex(Primitive.NEXT), - types, network.createVertex(Primitive.TYPE), null); - nextWord = nextWord.getRelationship(Primitive.WORD); - } else { - word = vertex.getAssoiate(network.createVertex(Primitive.WORD), - previousWord, network.createVertex(Primitive.PREVIOUS), - nextWord, network.createVertex(Primitive.NEXT), - types, network.createVertex(Primitive.TYPE), null); - } - } - } - if (word == null) { - word = vertex.mostConscious(Primitive.WORD); - } - if ((word == null) && (vertex.instanceOf(Primitive.SEQUENCE))) { - // TODO assume digits for now, should probably change to sequence - List digits = vertex.orderedRelationships(Primitive.DIGIT); - if (digits != null) { - StringWriter writer = new StringWriter(); - for (int index = digits.size() - 1; index >= 0; index--) { - Relationship digit = digits.get(index); - writer.write(String.valueOf(digit.getTarget().getData())); - } - word = network.createWord(writer.toString()); - } - } - if (word == null) { - if (!vertex.hasData()) { - word = vertex.mostConscious(Primitive.SENTENCE); - if (word != null) { - return word; - } - // If no word, call it what it is. - Collection classifications = vertex.getRelationships(Primitive.INSTANTIATION); - if (classifications != null) { - Vertex mostSpecialized = null; - for (Relationship classification : classifications) { - if (mostSpecialized == null) { - mostSpecialized = classification.getTarget(); - } else if (classification.getTarget().hasRelationship(Primitive.SPECIALIZATION, mostSpecialized)) { - mostSpecialized = classification.getTarget(); - } - } - word = mostSpecialized.mostConscious(Primitive.WORD); - } - if (word == null) { - word = network.createVertex(""); - } - } else if (vertex.isPrimitive()) { - word = network.createWord(vertex.getDataValue()); - } else if (vertex.getData() instanceof Time) { - word = network.createWord(Utils.printTime((Time)vertex.getData(), "h:mm:ss a z")); - } else { - word = network.createFragment(vertex.getDataValue()); - } - } - return word; - } - - public static String printFragment(Vertex fragment, Vertex previousWord, Vertex nextWord, Network network) { - List values = fragment.orderedRelationships(Primitive.WORD); - StringWriter writer = new StringWriter(); - int index = 0; - if (values != null) { - for (Relationship value : values) { - if (index != 0) { - writer.write(" "); - } - Vertex next = nextWord; - if (index < values.size()) { - next = values.get(index).getTarget(); - } - Vertex word = getWordFollowing(value.getTarget(), previousWord, next, network); - writer.write(word.printString()); - index++; - previousWord = word; - } - } - return writer.toString(); - } - - public Vertex getLastStateMachine(Network network) { - if (this.lastStateMachineId == null) { - return null; - } - return network.findById(this.lastStateMachineId); - } - - public void setLastStateMachine(Vertex lastStateMachine) { - if (lastStateMachine == null) { - this.lastStateMachineId = null; - } else { - this.lastStateMachineId = lastStateMachine.getId(); - } - } - - public Vertex getLastState(Network network) { - if (this.lastStateId == null) { - return null; - } - return network.findById(this.lastStateId); - } - - public void setLastState(Vertex lastState) { - if (lastState == null) { - this.lastStateId = null; - } else { - this.lastStateId = lastState.getId(); - } - } - - public Vertex getLastQuotient(Network network) { - if (this.lastQuotientId == null) { - return null; - } - return network.findById(this.lastQuotientId); - } - - public void setLastQuotient(Vertex lastQuotient) { - if (lastQuotient == null) { - this.lastQuotientId = null; - } else { - this.lastQuotientId = lastQuotient.getId(); - } - } - - public boolean getEnableEmote() { - return enableEmote; - } - - public void setEnableEmote(boolean enableEmote) { - this.enableEmote = enableEmote; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - /** - * Load, compile, and add the state machine from the .self file. - */ - public void loadSelfFile(File file, String encoding, boolean debug) { - try { - loadSelfFile(new FileInputStream(file), encoding, MAX_FILE_SIZE, debug, true); - } catch (IOException exception) { - throw new SelfParseException("Parsing error occurred", exception); - } - } - - /** - * Load, compile, and add the state machine from the .self file. - */ - public void loadSelfFile(URL url, String encoding, boolean debug) { - try { - loadSelfFile(Utils.openStream(url), encoding, MAX_FILE_SIZE, debug, true); - } catch (IOException exception) { - throw new SelfParseException("Parsing error occurred", exception); - } - } - - /** - * Load, compile, and add the state machine from the .self file stream. - */ - public void loadSelfFile(InputStream stream, String encoding, int maxSize, boolean debug, boolean optimize) { - Network network = getBot().memory().newMemory(); - Vertex language = network.createVertex(getPrimitive()); - SelfCompiler compiler = SelfCompiler.getCompiler(); - if (!optimize) { - compiler = new SelfCompiler(); - } - Vertex stateMachine = compiler.parseStateMachine(stream, debug, network, encoding, maxSize); - SelfCompiler.getCompiler().pin(stateMachine); - language.addRelationship(Primitive.STATE, stateMachine); - network.save(); - } - - /** - * Load, parse, the aiml file as a chat log. - */ - public void loadAIMLFileAsLog(File file, String encoding, boolean pin) { - try { - loadAIMLFileAsLog(new FileInputStream(file), encoding, MAX_FILE_SIZE, pin); - } catch (IOException exception) { - throw new SelfParseException("Parsing error occurred", exception); - } - } - - /** - * Load, parse, the aiml file as a script. - */ - public void loadAIMLFile(File file, boolean createStates, boolean indexStatic, String encoding) { - try { - loadAIMLFile(new FileInputStream(file), file.getName(), createStates, false, indexStatic, encoding, MAX_FILE_SIZE); - } catch (IOException exception) { - throw new SelfParseException("Parsing error occurred", exception); - } - } - - /** - * Load, parse, the aiml file as a chat log. - */ - public void loadAIMLFileAsLog(InputStream stream, String encoding, int maxSize, boolean pin) { - String text = Utils.loadTextFile(stream, encoding, MAX_FILE_SIZE); - loadAIMLAsLog(text, pin); - } - - /** - * Load, parse, the aiml as a chat log. - */ - public void loadAIMLAsLog(String text, boolean pin) { - long start = System.currentTimeMillis(); - Network network = getBot().memory().newMemory(); - AIMLParser.parser().parseAIML(text, false, false, pin, false, null, network); - network.save(); - log("AIML parsing time", Level.INFO, System.currentTimeMillis() - start); - } - - /** - * Load, parse, the aiml file as a state machine. - */ - public void loadAIMLFile(InputStream stream, String name, boolean createStates, boolean mergeState, boolean indexStatic, String encoding, int maxSize) { - String text = Utils.loadTextFile(stream, encoding, MAX_FILE_SIZE); - loadAIML(text, name, createStates, mergeState, indexStatic); - } - - /** - * Load, parse, the aiml file as a state machine. - */ - public void loadAIML(String text, String name, boolean createStates, boolean mergeState, boolean indexStatic) { - long start = System.currentTimeMillis(); - Network network = getBot().memory().newMemory(); - Vertex stateMachine = null; - Vertex language = network.createVertex(getPrimitive()); - if (mergeState) { - stateMachine = language.lastRelationship(Primitive.STATE); - } - if (stateMachine == null) { - stateMachine = network.createInstance(Primitive.STATE); - stateMachine.addRelationship(Primitive.LANGUAGE, network.createVertex(Primitive.AIML)); - stateMachine.addRelationship(Primitive.LANGUAGE, network.createVertex(Primitive.SELF4)); - stateMachine.setName(name); - language.addRelationship(Primitive.STATE, stateMachine); - // Avoid setting source code to reduce file size. - /*TextData data = new TextData(); - data.setText(text); - stateMachine.addRelationship(Primitive.SOURCECODE, network.createVertex(data)); - Vertex sourceCode = stateMachine.getRelationship(Primitive.SOURCECODE); - if (sourceCode != null) { - sourceCode.setPinned(true); - }*/ - } - stateMachine = AIMLParser.parser().parseAIML(text, true, createStates, false, indexStatic, stateMachine, network); - SelfCompiler.getCompiler().pin(stateMachine); - network.save(); - log("AIML parsing time", Level.INFO, System.currentTimeMillis() - start); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/resources/base/layout/activity_chat.xml b/BotLibreOffline/entry/src/main/resources/base/layout/activity_chat.xml index 48c81b0f258cc7c34fbb3c5afde58c0453ac155d..379dc9df7f3bdbbf35f45349a84cc82aad2e8c9c 100644 --- a/BotLibreOffline/entry/src/main/resources/base/layout/activity_chat.xml +++ b/BotLibreOffline/entry/src/main/resources/base/layout/activity_chat.xml @@ -1,7 +1,7 @@ templates; + /** + * tags + */ public static Object[] tags; + /** + * categories + */ public static Object[] categories; - public static Object[] forumTags; - public static Object[] forumPostTags; - public static Object[] forumCategories; + /** + * channelTags + */ public static Object[] channelTags; - public static Object[] channelCategories; - public static Object[] avatarTags; - public static Object[] scriptTags; - public static Object[] scriptCategories; - public static Object[] avatarCategories; + /** + * volume + */ public static int volume; - + /** + * contentRating + */ public static String contentRating; - public static Object[] domainTags; - public static Object[] domainCategories; - + /** + * nameOfAvatar + */ public static String nameOfAvatar; - - public static Object[] graphicTags; - public static Object[] graphicCategories; - public static boolean showImages = true; - public static BrowseConfig browse = null; - public static BrowseConfig browsePosts = null; - public static BrowseConfig browseIssues = null; + /** + * instances + */ public static List instances = new ArrayList(); + /** + * posts + */ public static List posts = new ArrayList(); - public static List issues = new ArrayList(); - public static List avatarMedias = new ArrayList(); + /** + * current + */ public static MainAbility current; + /** + * browsing + */ public static boolean browsing; + /** + * searching + */ public static boolean searching; + /** + * searchingPosts + */ public static boolean searchingPosts; - public static boolean searchingIssues; - public static boolean wasDelete; + /** + * importingBotScript + */ public static boolean importingBotScript = false; + /** + * importingBotLog + */ public static boolean importingBotLog = false; + /** + * languages + */ public static String[] languages = new String[]{ "Default", "af - Afrikaans", "sq - Albanian", "ar - Arabic", "hy - Armenian", "az - Azerbaijani", @@ -249,278 +348,98 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag "tl - Tagalog", "tg - Tajik", "ta - Tamil", "tt - Tatar", "th - Thai", "tr - Turkish", "udm - Udmurt", "uk - Ukrainian", "ur - Urdu", "uz - Uzbek", "vi - Vietnamese", "cy - Welsh" }; + /** + * servers + */ public static String[] servers = new String[]{"www.botlibre.com", "twitter.botlibre.com", "www.botlibre.biz", "www.livechatlibre.com", "www.forumslibre.com"}; + /** + * servers + */ public static String[] types = new String[]{"Bots", "Avatars", "Scripts", "Forums", "Live Chat", "Graphics", "Domains", "Chat Bot Wars"}; - public static String[] channelTypes = new String[]{"ChatRoom", "OneOnOne"}; - public static String[] priorities = new String[]{"Low", "Medium", "High", "Sever"}; - public static String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; - public static String[] contentRatings = new String[]{"Everyone", "Teen", "Mature"}; - public static String[] forkAccMode = new String[]{"Administrators", "Members", "Users", "Disabled"}; - public static String[] mediaAccessModes = new String[]{"Administrators", "Everyone", "Members", "Users", "Disabled"}; - public static String[] learningModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; - public static String[] correctionModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; - public static String[] scriptLanguages = new String[]{"Self", "AIML", "Response List", "Chat Log", "CVS"}; - public static String[] botModes = new String[]{"ListenOnly", "AnswerOnly", "AnswerAndListen"}; - public static String[] responseTypes = new String[]{"conversations", "responses", "greetings", "default", "flagged"}; - public static String[] durations = new String[]{"all", "day", "week", "month"}; - public static String[] inputTypes = new String[]{"all", "chat", "tweet", "post", "directmessage", "email"}; - public static String[] responseRestrictions = new String[]{"", "exact", "keyword", "required", "topic", "label", "previous", - "repeat", "missing-keyword", "missing-required", "missing-topic", "patterns", "templates", "flagged", "corrections", - "emotions", "actions", "poses"}; - public static String[] voices = new String[]{ - "cmu-slt", - "cmu-slt-hsmm", - "cmu-bdl-hsmm", - "cmu-rms-hsmm", - "dfki-prudence", - "dfki-prudence-hsmm", - "dfki-spike", - "dfki-spike-hsmm", - "dfki-obadiah", - "dfki-obadiah-hsmm", - "dfki-poppy", - "dfki-poppy-hsmm", - "bits1-hsmm", - "bits3", - "bits3-hsmm", - "dfki-pavoque-neutral-hsmm", - "camille", - "camille-hsmm-hsmm", - "jessica_voice-hsmm", - "pierre-voice-hsmm", - "enst-dennys-hsmm", - "istc-lucia-hsmm", - "voxforge-ru-nsh", - "dfki-ot", - "dfki-ot-hsmm", - "cmu-nk", - "cmu-nk-hsmm" - }; - public static String[] voiceMods = new String[]{ - "default", "child", "whisper", "echo", "robot" - }; - public static String[] voiceNames = new String[]{ - "English : US : Female : SLT", - "English : US : Female : SLT (hsmm)", - "English : US : Male : BDL (hsmm)", - "English : US : Male : RMS (hsmm)", - "English : GB : Female : Prudence", - "English : GB : Female : Prudence (hsmm)", - "English : GB : Male : Spike", - "English : GB : Male : Spike (hsmm)", - "English : GB : Male : Obadiah", - "English : GB : Male : Obadiah (hsmm)", - "English : GB : Female : Poppy", - "English : GB : Female : Poppy (hsmm)", - "German : DE : Female : Bits1 (hsmm)", - "German : DE : Male : Bits3", - "German : DE : Male : Bits3 (hsmm)", - "German : DE : Male : Pavoque (hsmm)", - "French : FR : Female : Camille", - "French : FR : Female : Camille (hsmm)", - "French : FR : Female : Jessica (hsmm)", - "French : FR : Male : Pierre (hsmm)", - "French : FR : Male : Dennys (hsmm)", - "Italian : IT : Male : Lucia (hsmm)", - "Russian : RU : Male : NSH (hsmm)", - "Turkish : TR : Male : OT", - "Turkish : TR : Male : OT (hsmm)", - "Telugu : TE : Female : NK", - "Telugu : TE : Female : NK (hsmm)" - }; Menu menu; + /** + * templateID + */ public static int templateID; + /** + * spin + */ public Button spin; + /** + * createInstanceButton + */ public Button createInstanceButton; + /** + * browseButton + */ public Button browseButton; + /** + * menuButton + */ public Button menuButton; + /** + * loginButton + */ public Button loginButton; + /** + * chatButton + */ public Button chatButton; + /** + * logoutButton + */ public Button logoutButton; + /** + * viewUserButton + */ public Button viewUserButton; + /** + * helpButton + */ public Button helpButton; -// // @TargetApi(Build.VERSION_CODES.KITKAT) -//// @SuppressLint("NewApi") -// public static String getFilePathFromURI(Context context, Uri uri) { -// // DocumentProvider -// if (DocumentsContract.isDocumentUri(context, uri)) { -// -// // ExternalStorageProvider -// if (isExternalStorageDocument(uri)) { -// final String docId = DocumentsContract.getDocumentId(uri); -// final String[] split = docId.split(":"); -// final String type = split[0]; -// -// if ("primary".equalsIgnoreCase(type)) { -// return Environment.getExternalStorageDirectory() + "/" + split[1]; -// } -// // TODO handle non-primary volumes -// } -// // DownloadsProvider -// else if (isDownloadsDocument(uri)) { -// final String id = DocumentsContract.getDocumentId(uri); -// final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), -// Long.valueOf(id)); -// return getDataColumn(context, contentUri, null, null); -// } -// // MediaProvider -// else if (isMediaDocument(uri)) { -// final String docId = DocumentsContract.getDocumentId(uri); -// final String[] split = docId.split(":"); -// final String type = split[0]; -// Uri contentUri = null; -// if ("image".equals(type)) { -// contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; -// } else if ("video".equals(type)) { -// contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; -// -// } else if ("audio".equals(type)) { -// contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; -// } -// final String selection = "_id=?"; -// final String[] selectionArgs = new String[]{split[1]}; -// return getDataColumn(context, contentUri, selection, selectionArgs); -// } -// } -// // MediaStore (and general) -// else if ("content".equalsIgnoreCase(uri.getScheme())) { -// // Return the remote address -// if (isGooglePhotosUri(uri)) -// return uri.getLastPathSegment(); -// return getDataColumn(context, uri, null, null); -// } -// // File -// else if ("file".equalsIgnoreCase(uri.getScheme())) { -// return uri.getPath(); -// } -// return null; -// } - - public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { -// Cursor cursor = null; -// final String column = "_data"; -// final String[] projection = {column}; -// try { -// cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); -// if (cursor != null && cursor.moveToFirst()) { -// final int index = cursor.getColumnIndexOrThrow(column); -// return cursor.getString(index); -// } -// } finally { -// if (cursor != null) -// cursor.close(); -// } - return null; - } - - public static Boolean getFileSize(String q, Context a) { - if (q == null || q.equals("")) { + /** + * reInitialize + * + * @param qq + * @param aa + * @return true + */ + public static Boolean getFileSize(String qq, Context aa) { + if (qq == null || qq.equals("")) { return true; } - File file = new File(q); + File file = new File(qq); long fileSizeInBytes = file.length(); long fileSizeInKB = fileSizeInBytes / 1024; long fileSizeInMB = fileSizeInKB / 1024; if (fileSizeInMB >= 5) { - showMessage("The file exceeded the maximum size limit!", (Ability) a); + showMessage("The file exceeded the maximum size limit!", (Ability) aa); return false; } else { return true; } } - public static boolean isExternalStorageDocument(Uri uri) { - return "com.ohos.externalstorage.documents".equals(uri.getDecodedAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is DownloadsProvider. - */ - public static boolean isDownloadsDocument(Uri uri) { - return "com.ohos.providers.downloads.documents".equals(uri.getDecodedAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is MediaProvider. - */ - public static boolean isMediaDocument(Uri uri) { - return "com.ohos.providers.media.documents".equals(uri.getDecodedAuthority()); - } - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is Google Photos. + * reInitialize + * + * @param context + * @return true */ - - public static boolean isGooglePhotosUri(Uri uri) { - return "com.google.ohos.apps.photos.content".equals(uri.getDecodedAuthority()); - } - - public static String getFileNameFromPath(String path) { - int index = path.lastIndexOf("/"); - return path.substring(index + 1, path.length()); - } - -// public static String getFileTypeFromPath(String path) { -// int index = path.lastIndexOf("."); -// String ext = path.substring(index + 1, path.length()); -// if (ext.equalsIgnoreCase("webm")) { -// return "video/webm"; -// } -// return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext); -// } - public static boolean isTablet(Context context) { -// return (context.getResourceManager().getConfiguration().isLayoutRTL -// & Configuration.AUTO_MODE) >= Configuration.AUTO_MODE; return true; } - @SuppressWarnings("rawtypes") - public static Class getActivity(WebMediumConfig config) { - if (config instanceof ChannelConfig) { -// return ChannelAbility.class; //==================== - } else if (config instanceof ForumConfig) { -// return ForumAbility.class; //==================== - } else if (config instanceof InstanceConfig) { -// return BotAbility.class; //==================== - } else if (config instanceof DomainConfig) { -// return DomainAbility.class; //==================== - } else if (config instanceof AvatarConfig) { -// return AvatarAbility.class; //==================== - } else if (config instanceof ScriptConfig) { -// return ScriptAbility.class; //==================== - } else if (config instanceof GraphicConfig) { -// return GraphicAbility.class; //==================== - } - return null; - } - - public static void error(String message, Exception exception, Ability activity) { - try { - if (DEBUG) { - System.out.println(String.valueOf(message)); - if (exception != null) { - exception.printStackTrace(); - } - } - if (message == null) { - message = ""; - } - if (message.contains("")) { - message = "Server Error, ensure you are connected to the Internet"; - } - MainAbility.showMessage(message, activity); - } catch (Throwable error) { - error.printStackTrace(); - } - } - - public static void errorInfo(int type,String message, Exception exception, Ability activity) { + /** + * reInitialize + * + * @param message + * @param exception + * @param ability + */ + public static void error(String message, Exception exception, Ability ability) { try { if (DEBUG) { System.out.println(String.valueOf(message)); @@ -534,15 +453,22 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag if (message.contains("")) { message = "Server Error, ensure you are connected to the Internet"; } - MainAbility.showMessageInfo(type,null,message, activity); + MainAbility.showMessage(message, ability); } catch (Throwable error) { error.printStackTrace(); } } - public static void showMessage(String title, String message, Ability activity) { + /** + * showMessage + * + * @param title + * @param message + * @param ability + */ + public static void showMessage(String title, String message, Ability ability) { try { - CommonDialog dialog = new CommonDialog(activity); + CommonDialog dialog = new CommonDialog(ability); dialog.setContentText(message); if (title != null) { dialog.setTitleText(title); @@ -564,114 +490,20 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag super.onActive(); } - public static Text execcontentinfo; - public static void showMessageInfo(int type,String title, String message, Ability activity) { - CommonDialog mCommonDialog = new CommonDialog(activity); - Optional - display = DisplayManager.getInstance().getDefaultDisplay(activity); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(activity). - parse(ResourceTable.Layout_exception_dialog, - null, false); - mCommonDialog.setContentCustomComponent(layout) - .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width - 100,displayAttributes.height - 200) - .setAutoClosable(false) - .setTransparent(false) - .show(); - - Text ok = (Text)layout.findComponentById(ResourceTable.Id_ok); - execcontentinfo = (Text)layout.findComponentById(ResourceTable.Id_execcontentinfo); - if (message != null) { - execcontentinfo.setText(message); - } - - new EventHandler(EventRunner.getMainEventRunner()).postTask(new Runnable() { - @Override - public void run() { - execcontentinfo.scrollTo(0, 0); - } - }, 20); - - execcontentinfo.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING); - ok.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - mCommonDialog.destroy(); - } - }); - } - - public static void showMessage(String message, Ability activity) { - showMessage(null, message, activity); - } - - public static void prompt(String message, Ability activity, TextField text, IDialog.ClickedListener listener) { - CommonDialog dialog = new CommonDialog(activity); - dialog.setContentText(message); - dialog.setContentCustomComponent(text); - dialog.setButton(0, "OK", listener); - dialog.setButton(1, "Cancel", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - - } - }); - dialog.show(); - } - - public void contentRatingList() { - CommonDialog builder = new CommonDialog(this); - builder.setTitleText("Content Rating"); - - builder.setContentText("Select Content Rating: "); - builder.setButton(1, "Cancel", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int id) { - // save data -// Preferences editor = MainAbility.current.getp.getPreferences(Context.MODE_PRIVATE) -// .edit(); -// editor.putString("contentRating", (String) spin.getSelectedItem()); -// contentRating = (String) spin.getSelectedItem(); -// editor.flush(); - } - }); - - builder.setButton(1, "Cancel", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - - } - }); - builder.show(); - } - - public static void confirm(String message, Ability activity, Boolean cancelable, IDialog.ClickedListener listener) { - CommonDialog dialog = new CommonDialog(activity); - dialog.setTitleText("Pizza Bot"); - dialog.setContentText(message); - dialog.setButton(0, "Yes", listener); - dialog.setButton(1, "NO", listener); - if (cancelable) { - dialog.setButton(1, "Cancel", listener); - } - dialog.show(); + /** + * showMessage + * + * @param message + * @param ability + */ + public static void showMessage(String message, Ability ability) { + showMessage(null, message, ability); } - public static List getAllTemplates(Ability activity) { - if (templates == null) { - try { -// HttpGetTemplatesAction action = new HttpGetTemplatesAction(activity); -// action.postExecute(action.execute().get()); -// if (action.getException() != null) { -// templates = new ArrayList(); -// } - } catch (Exception ignore) { - } - } - return templates; - } + /** + * REQ_PERMISSION_CODE + */ public static final int REQ_PERMISSION_CODE = 1003; private final List mPermissions = new LinkedList<>( @@ -681,7 +513,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag @Override public void onStart(Intent intent) { super.onStart(intent); -// super.setMainRoute(MainAbilitySlice.class.getName()); searching = false; browsing = false; searchingPosts = false; @@ -694,7 +525,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag cookies.flushSync(); } -// startOpenAbility(this, ChatAbility.class.getName()); current = this; Preferences cookies = PreferencesUtils.getPreferences(this); @@ -781,7 +611,10 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag hd = isTablet(this); } - public void initChat(){ + /** + * showMessage + */ + public void initChat() { chatButton = (Button) findComponentById(ResourceTable.Id_chatButton); // chat chatButton.setClickedListener(new Component.ClickedListener() { @Override @@ -791,7 +624,10 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag }); } - public void initMain(){ + /** + * showMessage + */ + public void initMain() { spin = (Button) findComponentById(ResourceTable.Id_selectButton); // 底部类型选择 spin.setClickedListener(new Component.ClickedListener() { @Override @@ -847,12 +683,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag helpButton.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { - help(); } }); } - public void initBrowse(){ + /** + * showMessage + */ + public void initBrowse() { chatButton = (Button) findComponentById(ResourceTable.Id_chatButton); chatButton.setClickedListener(new Component.ClickedListener() { @Override @@ -887,22 +725,12 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } }); } - //动态权限 - private void reqPermissions() { - mPermissions.removeIf(perM -> verifySelfPermission(perM) == PERMISSION_GRANTED || !canRequestPermission(perM)); - if (!mPermissions.isEmpty()) { - requestPermissionsFromUser( - mPermissions.toArray(new String[0]), MainAbility.REQ_PERMISSION_CODE); - } else { - // 功能调用 - } - } /** * 权限回调 * - * @param requestCode requestCode - * @param ss ss + * @param requestCode requestCode + * @param ss ss * @param grantResults grantResults */ @Override @@ -921,6 +749,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * showMessage + */ public void loadMemoryByBot() { MicroMemory.storageDir = getFilesDir(); List items = new ArrayList(); @@ -934,7 +765,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag launchInstanceId = oneItem.getId(); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + /** + * showMessage + */ public void resetView() { menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); // 菜单选择 menuButton.setClickedListener(new Component.ClickedListener() { @@ -943,42 +776,16 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag menu(); } }); - - - - if (domain != null) { -// setTitle(Utils.stripTags(domain.name)); -// HttpGetImageAction.fetchImage(this, domain.avatar, null); //----------------- -// HttpGetImageAction.fetchImage(this, domain.avatar, (Image) findComponentById(ResourceTable.Id_splash)); - } - - if (MainAbility.user == null) { - //findViewById(R.id.viewUserButton).setVisibility(View.GONE); - //findViewById(R.id.logoutButton).setVisibility(View.GONE); - //findViewById(R.id.loginButton).setVisibility(View.VISIBLE); - } else { - //findViewById(R.id.logoutButton).setVisibility(View.VISIBLE); - //findViewById(R.id.loginButton).setVisibility(View.GONE); - //findViewById(R.id.viewUserButton).setVisibility(View.VISIBLE); - //HttpGetImageAction.fetchImage(this, MainActivity.user.avatar, findViewById(R.id.viewUserButton)); - } resetMenu(this.menu); resetLast(); } + /** + * showMessage + */ public void resetLast() { -// String type = MainAbility.defaultType; -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); // 需要放入 adapter中做判断 -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// if (type.equals("Chat Bot Wars")) { -// spin.setSelection(0); -// war(null); -// return; -// } -// } + if (type.equals("Chat Bot Wars")) { - war(); return; } if (type == null) { @@ -1014,12 +821,11 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } + /** + * showMessage + */ public void openLast() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); // 适配器中做了选择赋值 -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } @@ -1064,10 +870,13 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } config.name = last; -// HttpAction action = new HttpFetchAction(this, config); -// action.execute(); } + /** + * showMessage + * + * @param menu + */ public void resetMenu(Menu menu) { if (menu == null) { return; @@ -1075,65 +884,25 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag for (int index = 0; index < menu.getItemCount(); index++) { menu.getItem(index).setEnabled(true); } - if (MainAbility.user == null) { - //menu.findItem(R.id.menuMyBots).setEnabled(false); - //menu.findItem(R.id.menuSignOut).setEnabled(false); - //menu.findItem(R.id.menuViewUser).setEnabled(false); - //menu.findItem(R.id.menuEditUser).setEnabled(false); - } else { - //menu.findItem(R.id.menuSignIn).setEnabled(false); - //menu.findItem(R.id.menuSignUp).setEnabled(false); - } - - /*if (MicroMemory.checkExists()) { - menu.findItem(R.id.menuDeleteExistingBot).setEnabled(true); - } else { - menu.findItem(R.id.menuDeleteExistingBot).setEnabled(false); - }*/ -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String) spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } - // MenuItem item = menu.findItem(R.id.menuMyBots); - // if (type.equals("Bots")) { - // item.setTitle("My Bots"); - // } else if (type.equals("Forums")) { - // item.setTitle("My Forums"); - // } else if (type.equals("Live Chat")) { - // item.setTitle("My Channels"); - // } else if (type.equals("Domains")) { - // item.setTitle("My Domains"); - // } else if (type.equals("Avatars")) { - // item.setTitle("My Avatars"); - // } else if (type.equals("Scripts")){ - // item.setTitle("My Scripts"); - // }else if (type.equals("Graphics")){ - // item.setTitle("My Graphics"); - // } - } - public void war() { -// startOpenAbility(this,StartWarAbility.class.getName()); //===================== } + /** + * login + */ public void login() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } - startOpenAbility(this, LoginAbility.class.getName()); } + /** + * login + */ public void logout() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } + connection.disconnect(); user = null; instance = null; @@ -1169,13 +938,15 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag editor.delete("deviceVoice"); editor.flushSync(); - HttpGetImageAction.clearFileCache(this); Intent intent = getIntent(); terminateAbility(); startAbility(intent); } + /** + * menu + */ public void menu() { Optional display = DisplayManager.getInstance().getDefaultDisplay(this); @@ -1185,11 +956,11 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) .parse(ResourceTable.Layout_menu_main, null, false); menuDialog.setCustomComponent(menuComponent); - menuDialog.showOnCertainPosition(1,displayAttributes.width,-displayAttributes.width + 230); + menuDialog.showOnCertainPosition(1, displayAttributes.width, -displayAttributes.width + 230); menuDialog.setAutoClosable(true); Text statistics = (Text) menuComponent.findComponentById(ResourceTable.Id_title); Text changelanguage = (Text) menuComponent.findComponentById(ResourceTable.Id_changelanguage); - menuDialog.setAlignment(LayoutAlignment.RIGHT|LayoutAlignment.TOP); + menuDialog.setAlignment(LayoutAlignment.RIGHT | LayoutAlignment.TOP); menuDialog.show(); Text loginButton = (Text) menuComponent.findComponentById(ResourceTable.Id_loginButton); @@ -1224,7 +995,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag editprofile.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { - editUser(); } }); statistics.setClickedListener(new Component.ClickedListener() { @@ -1239,65 +1009,44 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag changelanguage.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { - changeLanguage(MainAbility.this,null); + changeLanguage(MainAbility.this, null); menuDialog.hide(); menuDialog.remove(); } }); } + /** + * login + */ public void createUser() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// -// Intent intent = new Intent(this, CreateUserActivity.class); -// startActivity(intent); startOpenAbility(this, CreateUserAbility.class.getName()); //================ } - public void editUser() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// -// Intent intent = new Intent(this, EditUserActivity.class); -// startActivity(intent); -// startOpenAbility(this, EditUserAbility.class.getName()); //================ - } - - public static void setOnline(boolean result){ - if(result){ + /** + * setOnline + * + * @param result + */ + public static void setOnline(boolean result) { + if (result) { connection = remoteConnection; - }else{ + } else { connection = localConnection; } online = result; } - public void help() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } -// super.help(view); -// startOpenAbility(this, HelpAbility.class.getName()); //================ - } - + /** + * setOnline + */ public void viewUser() { viewUser = user; -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } - -// Intent intent = new Intent(this, ViewUserActivity.class); -// startActivity(intent); -// startOpenAbility(this, ViewUserAbility.class.getName()); //================ } + /** + * setOnline + */ public void openWebsite() { try { Intent intent2 = new Intent(); @@ -1311,6 +1060,9 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } + /** + * setOnline + */ public void createInstance() { if (user == null) { CommonDialog dialog = new CommonDialog(this); @@ -1324,119 +1076,29 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag dialog.show(); return; } -// Spinner spin = (Spinner) findViewById(getResources().getIdentifier("typeSpin", "id", getPackageName())); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } + if (type == null) { type = MainAbility.defaultType; } if (type.equals("Bots")) { MainAbility.template = ""; -// Intent intent = new Intent(this, CreateBotActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateBotAbility.class.getName()); //================ - } else if (type.equals("Forums")) { -// Intent intent = new Intent(this, CreateForumActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateForumAbility.class.getName()); //================ - } else if (type.equals("Live Chat")) { -// Intent intent = new Intent(this, CreateChannelActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateChannelAbility.class.getName()); //================ - } else if (type.equals("Domains")) { -// Intent intent = new Intent(this, CreateDomainActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateDomainAbility.class.getName()); //================ - } else if (type.equals("Avatars")) { -// Intent intent = new Intent(this, CreateAvatarActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateAvatarAbility.class.getName()); //================ - } else if (type.equals("Scripts")) { -// Intent intent = new Intent(this, CreateScriptActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateScriptAbility.class.getName()); //================ - } else if (type.equals("Graphics")) { -// Intent intent = new Intent(this, CreateGraphicActivity.class); -// startActivity(intent); -// startOpenAbility(this, CreateGraphicAbility.class.getName()); //================ } } + /** + * setOnline + */ public void search() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } if (type == null) { type = MainAbility.defaultType; } - if (type.equals("Bots")) { -// Intent intent = new Intent(this, BotSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, BotSearchAbility.class.getName()); //================ - } else if (type.equals("Forums")) { -// Intent intent = new Intent(this, ForumSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, ForumSearchAbility.class.getName()); //================ - } else if (type.equals("Live Chat")) { -// Intent intent = new Intent(this, ChannelSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, ChannelSearchAbility.class.getName()); //================ - } else if (type.equals("Domains")) { -// Intent intent = new Intent(this, DomainSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, DomainSearchAbility.class.getName()); //================ - } else if (type.equals("Avatars")) { -// Intent intent = new Intent(this, AvatarSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, AvatarSearchAbility.class.getName()); //================ - } else if (type.equals("Scripts")) { -// Intent intent = new Intent(this, ScriptSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, ScriptSearchAbility.class.getName()); //================ - } else if (type.equals("Graphics")) { -// Intent intent = new Intent(this, GraphicSearchActivity.class); -// startActivity(intent); -// startOpenAbility(this, GraphicSearchAbility.class.getName()); //================ - } - } - - public void browseMyBots() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } - if (type == null) { - type = MainAbility.defaultType; - } - BrowseConfig config = new BrowseConfig(); - config.typeFilter = "Personal"; - if (type.equals("Bots")) { - config.type = "Bot"; - } else if (type.equals("Forums")) { - config.type = "Forum"; - } else if (type.equals("Live Chat")) { - config.type = "Channel"; - } else if (type.equals("Domains")) { - config.type = "Domain"; - } else if (type.equals("Avatars")) { - config.type = "Avatar"; - } else if (type.equals("Scripts")) { - config.type = "Script"; - } else if (type.equals("Graphics")) { - config.type = "Graphic"; - } - config.contentRating = "Mature"; -// HttpGetInstancesAction action = new HttpGetInstancesAction(this, config); -// action.execute(); } + /** + * setOnline + */ public void browse() { -// Spinner spin = (Spinner) findViewById(R.id.typeSpin); -// if (spin != null) { -// type = (String)spin.getSelectedItem(); -// } + if (type == null) { type = MainAbility.defaultType; } @@ -1458,66 +1120,31 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config.type = "Graphic"; } config.contentRating = MainAbility.contentRating; -// HttpGetInstancesAction action = new HttpGetInstancesAction(this, config); -// action.execute(); } - /** - * Open the details screen. - */ - public void about() { - WebMediumConfig config = null; - if (launchType == LaunchType.Bot) { - config = new InstanceConfig(); - } else if (launchType == LaunchType.Forum) { - config = new ForumConfig(); - } else if (launchType == LaunchType.Channel) { - config = new ChannelConfig(); - } - config.id = launchInstanceId; - config.name = launchInstanceName; - -// HttpAction action = new HttpFetchAction(this, config, false); -// action.execute(); - } /** * Start a chat session with the hard coded instance. */ - - /* - * This method will have a list of 8 empty bot, basic, AI, julie, eddie, - * alice, personal assistance, juile assistance. before attaching the ID and - * Name of the bot make sure that its selecetd thro the list. - */ public void launch() { setOnline(false); WebMediumConfig config = null; // the launch type is bot. if (MainAbility.launchType == LaunchType.Bot) { if (!MicroMemory.checkExists()) { - //ListTemplateView.offlineTemplate = true; - //Intent intent = new Intent(MainActivity.this, ListTemplateView.class); - //startActivity(intent); - config = new InstanceConfig(); - OfflineTemplateConfig templates = new OfflineTemplateConfig(ResourceTable.Media_bot,"Pizza Bot","",""+0,0); + OfflineTemplateConfig templates = new OfflineTemplateConfig(ResourceTable.Media_bot, "Pizza Bot", "", "" + 0, 0); //saving a template number for getting the icons and pictures of the bot saveAllData(MainAbility.launchInstanceName = templates.getTitle(), MainAbility.launchInstanceId = templates.getId(), MainAbility.templateID = 0); config.id = MainAbility.launchInstanceId; config.name = MainAbility.launchInstanceName; AvatarSelection.saveSelectedAvatar(templates.getTitle()); //============================ - MainAbility.readZipAvatars(this, templates.getTitle()); MainAbility.offlineSelectedImage = templates.getImageId(); - HttpFetchActionOffline action = new HttpFetchActionOffline(this, config, true); -// action.execute(); + startOpenAbility(this, ChatAbility.class.getName()); } else { config = new InstanceConfig(); - readZipAvatars(this, this.nameOfAvatar); config.name = MainAbility.launchInstanceName; config.id = MainAbility.launchInstanceId; - HttpFetchActionOffline action = new HttpFetchActionOffline(this, config, true); -// action.execute(); } } else if (MainAbility.launchType == LaunchType.Forum) { config = new ForumConfig(); @@ -1526,8 +1153,14 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } } - public void saveAllData(String instanceId, String instanceName, int id){ -// Preferences cookies = MainAbility.current.getPreferences(Context.MODE_PRIVATE).edit(); + /** + * saveAllData + * + * @param instanceId + * @param instanceName + * @param id + */ + public void saveAllData(String instanceId, String instanceName, int id) { Preferences cookies = PreferencesUtils.getPreferences(this); cookies.putString("instanceID", instanceId); cookies.putString("instanceName", instanceName); @@ -1536,54 +1169,17 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } /** - * View the user's personal instance. + * selectInfo */ - public void browseMyBot() { - if (user == null) { - CommonDialog dialog = new CommonDialog(this); - dialog.setContentText("You must sign in first"); - dialog.setButton(1, "OK", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - login(); - } - }); - dialog.show(); - return; - } - WebMediumConfig config = new InstanceConfig(); - config.name = "Bot " + MainAbility.user.user; - -// HttpAction action = new HttpFetchOrCreateAction(this, config, false); -// action.execute(); - } + public static String selectInfo = ""; + Text languageselect; /** - * Start a chat session with the user's personal instance. + * reInitialize + * + * @param activty + * @param listener */ - public void launchMyBot(View view) { - if (user == null) { - CommonDialog dialog = new CommonDialog(this); - dialog.setContentText("You must sign in first"); - dialog.setButton(1, "OK", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - login(); - } - }); - dialog.show(); - return; - } - WebMediumConfig config = new InstanceConfig(); - config.name = "Bot " + MainAbility.user.user; - -// HttpAction action = new HttpFetchOrCreateAction(this, config, true); -// action.execute(); - } - - public static String selectInfo = ""; - Text languageselect; - @SuppressWarnings({ "rawtypes", "unchecked" }) public void changeLanguage(Ability activty, final IDialog.ClickedListener listener) { Optional display = DisplayManager.getInstance().getDefaultDisplay(this); @@ -1594,9 +1190,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag CommonDialog dialog = new CommonDialog(MainAbility.this); setOnline(true); -// dialog.setTitleText(" Languages"); - dialog.setSize(displayAttributes.width - 100,displayAttributes.width - 300); -// dialog.setContentText("Select your language"); + dialog.setSize(displayAttributes.width - 100, displayAttributes.width - 300); dialog.setContentCustomComponent(layout); dialog.show(); @@ -1604,7 +1198,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag Text ok = (Text) layout.findComponentById(ResourceTable.Id_ok); Text cancel = (Text) layout.findComponentById(ResourceTable.Id_cancel); - SpinnerAdapter spinnerAdapter = new SpinnerAdapter(this,MainAbility.languages); + SpinnerAdapter spinnerAdapter = new SpinnerAdapter(this, MainAbility.languages); languageselect.setClickedListener(new Component.ClickedListener() {//弹出选择语言对话框 @Override public void onClick(Component component) { @@ -1617,21 +1211,17 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag if (MainAbility.voice != null && MainAbility.voice.language != null) { index = Arrays.asList(MainAbility.languages).indexOf(MainAbility.voice.language); } -// spin.setSelection(index); - - if (MainAbility.voice != null && MainAbility.voice.language != null){ + if (MainAbility.voice != null && MainAbility.voice.language != null) { for (int i = 0; i < spinnerAdapter.getCount(); i++) { - if(MainAbility.languages[i].contains(MainAbility.voice.language + " - ")){ + if (MainAbility.languages[i].contains(MainAbility.voice.language + " - ")) { // spin.setSelection(i); selectInfo = MainAbility.languages[i]; } } } -// dialog.setView(spin); ok.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { - // String lang = (String)spin.getSelectedItem(); String lang = MainAbility.selectInfo; if (lang.equals("Default")) { MainAbility.translate = false; @@ -1661,9 +1251,6 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag cookies.putString("nativeVoice", String.valueOf(MainAbility.voice.nativeVoice)); cookies.flushSync(); } -// if (listener != null) { -// listener.onClick(dialog, i); -// } dialog.hide(); dialog.remove(); } @@ -1675,21 +1262,4 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } }); } - - public static void readZipAvatars(Ability activity, String fileName) { - // this is only for letting Julie Assistance Avatar works, since there - // is only one file called - // "Julie" I will have to take this name and read the file from the - // method @readZipAvatars. - String args[] = fileName.split("\\s+"); - // ex: Julie = Julie - // Julie Assistant = Julie - // Its only going to take one name - try { -// GetAvatarAction avatar = new GetAvatarAction(activity); -// avatar.readZipFile(args[0] + ".zip"); -// MicroConnection.avatarConfig = avatar.instance; - } catch (Exception ignore) { - } - } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/PaphusCredentials.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/PaphusCredentials.java deleted file mode 100644 index 80c9fa62353e0d93506cd00057426d6df67d96ab..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/PaphusCredentials.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk; - -/** - * Credentials for use with hosted services on the Bot Libre for Business website, - * a commercial bot, live chat, chatroom, and forum hosting service. - * https://www.botlibre.biz - */ -public class PaphusCredentials extends Credentials { - public static String DOMAIN = "www.botlibre.biz"; - //public static String DOMAIN = "192.168.0.11:9080"; - public static String APP = ""; - //public static String APP = "/livechat"; - public static String PATH = "/rest/api"; - - public PaphusCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "https://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java index 61386c622727af293cffe9564d65ada460e07d67..c27e8ba7f56f0d8dd7360095bcc201244c02d163 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKConnection.java @@ -15,51 +15,12 @@ package org.botlibre.sdk; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.StringReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - import com.franmontiel.persistentcookiejar.ClearableCookieJar; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; -import org.botlibre.sdk.config.AvatarMessage; -import org.botlibre.sdk.config.BotModeConfig; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChannelConfig; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import org.botlibre.sdk.config.Config; -import org.botlibre.sdk.config.ContentConfig; -import org.botlibre.sdk.config.ConversationConfig; -import org.botlibre.sdk.config.DomainConfig; -import org.botlibre.sdk.config.ForumConfig; -import org.botlibre.sdk.config.ForumPostConfig; -import org.botlibre.sdk.config.GraphicConfig; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.IssueConfig; -import org.botlibre.sdk.config.LearningConfig; -import org.botlibre.sdk.config.MediaConfig; -import org.botlibre.sdk.config.ResponseConfig; -import org.botlibre.sdk.config.ResponseSearchConfig; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import org.botlibre.sdk.config.Speech; -import org.botlibre.sdk.config.TrainingConfig; -import org.botlibre.sdk.config.UserAdminConfig; -import org.botlibre.sdk.config.UserConfig; -import org.botlibre.sdk.config.UserMessageConfig; -import org.botlibre.sdk.config.VoiceConfig; -import org.botlibre.sdk.config.WebMediumConfig; import ohos.aafwk.ability.Ability; -import ohos.media.image.PixelMap; +import ohos.agp.components.element.ShapeElement; import okhttp3.Call; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -69,1936 +30,537 @@ import okhttp3.Response; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; -import org.apache.http.entity.mime.HttpMultipartMode; -import org.apache.http.entity.mime.MultipartEntity; -import org.apache.http.entity.mime.content.ByteArrayBody; -import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; +import org.botlibre.sdk.config.AvatarConfig; +import org.botlibre.sdk.config.AvatarMedia; +import org.botlibre.sdk.config.DomainConfig; +import org.botlibre.sdk.config.ForumPostConfig; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.IssueConfig; +import org.botlibre.sdk.config.ResponseConfig; +import org.botlibre.sdk.config.UserConfig; +import org.botlibre.sdk.config.WebMediumConfig; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.xml.sax.InputSource; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** - * Connection class for a REST service connection. - * The SDK connection gives you access to the paphus or libre server services using a REST API. - *

    - * The services include: - *

      - *
    • User management (account creation, validation) - *
    • Bot access, chat, and administration - *
    • Forum access, posting, and administration - *
    • Live chat access, chat, and administration - *
    • Domain access, and administration - *
    + * SDKConnection + * + * @since 2021-04-16 */ public class SDKConnection { - protected static String[] types = new String[]{"Bots", "Forums", "Graphics", "Live Chat", "Domains", "Scripts", "IssueTracker"}; - protected static String[] channelTypes = new String[]{"ChatRoom", "OneOnOne"}; - protected static String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; - protected static String[] mediaAccessModes = new String[]{"Everyone", "Users", "Members", "Administrators", "Disabled"}; - protected static String[] learningModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; - protected static String[] correctionModes = new String[]{"Disabled", "Administrators", "Users", "Everyone"}; - protected static String[] botModes = new String[]{"ListenOnly", "AnswerOnly", "AnswerAndListen"}; - protected static String[] priorities = new String[]{"Low", "Medium", "High", "Sever"}; - - protected String url; - protected UserConfig user; - protected DomainConfig domain; - protected Credentials credentials; - protected boolean debug = false; - - protected SDKException exception; - - /** - * Return the name of the default user image. - */ - public static String defaultUserImage() { - return "images/user-thumb.jpg"; - } - - /** - * Create an SDK connection. - */ - public SDKConnection() { - } - - /** - * Create an SDK connection with the credentials. - * Use the Credentials subclass specific to your server. - */ - public SDKConnection(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - /** - * Validate the user credentials (password, or token). - * The user details are returned (with a connection token, password removed). - * The user credentials are soted in the connection, and used on subsequent calls. - * An SDKException is thrown if the connect failed. - */ - public UserConfig connect(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - this.user = null; - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - return this.user; - } - - /** - * Execute the custom API. - */ - public Config custom(String api, Config config, Config result) { - config.addCredentials(this); - String xml = POST(this.url + "/" + api, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - result.parseXML(root); - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - return result; - } - - /** - * Connect to the live chat channel and return a LiveChatConnection. - * A LiveChatConnection is separate from an SDKConnection and uses web sockets for - * asynchronous communication. - * The listener will be notified of all messages. - */ - public LiveChatConnection openLiveChat(ChannelConfig channel, LiveChatListener listener) { - LiveChatConnection connection = new LiveChatConnection(this.credentials, listener); - connection.connect(channel, this.user); - return connection; - } - - /** - * Connect to the domain. - * A domain is an isolated content space. - * Any browse or query request will be specific to the domain's content. - */ - public DomainConfig connect(DomainConfig config) { - this.domain = fetch(config); - return this.domain; - } - - /** - * Disconnect from the connection. - * An SDKConnection does not keep a live connection, but this resets its connected user and domain. - */ - public void disconnect() { - this.user = null; - this.domain = null; - } - - /** - * Fetch the user details. - */ - public UserConfig fetch(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/view-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Fetch the URL for the image from the server. - */ - public URL fetchImage(String image) { - try { - return new URL("http://" + this.credentials.host + this.credentials.app + "/" + image); - } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - } - - /** - * Fetch the forum post details for the forum post id. - */ - public ForumPostConfig fetch(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-forum-post", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML(root); - return post; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Fetch the issue details for the issue id. - */ - public IssueConfig fetch(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-issue", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - IssueConfig issue = new IssueConfig(); - issue.parseXML(root); - return issue; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new user. - */ - public UserConfig create(Ability ability,UserConfig config) { - config.addCredentials(this); - String xml = POSTUpdate(ability,this.url + "/create-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new forum post. - * You must set the forum id for the post. - */ - public ForumPostConfig create(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-forum-post", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML(root); - return post; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new issue. - * You must set the issue tracker id for the issue. - */ - public IssueConfig create(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-issue", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - IssueConfig issue = new IssueConfig(); - issue.parseXML(root); - return issue; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new file/image/media attachment for a chat channel. - */ - public MediaConfig createChannelFileAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTFILE(this.url + "/create-channel-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new image attachment for a chat channel. - */ - public MediaConfig createChannelImageAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/create-channel-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new file/image/media attachment for an issue tracker. - */ - public MediaConfig createIssueTrackerFileAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTFILE(this.url + "/create-issuetracker-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new image attachment for an issue tracker. - */ - public MediaConfig createIssueTrackerImageAttachment(String file, MediaConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/create-issuetracker-attachment", file, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new image attachment for an issue tracker. - */ - public MediaConfig createIssueTrackerImageAttachment(PixelMap bitmap, MediaConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/create-issuetracker-attachment", bitmap, config.name, config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - MediaConfig media = new MediaConfig(); - media.parseXML(root); - return media; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a reply to a forum post. - * You must set the parent id for the post replying to. - */ - public ForumPostConfig createReply(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-reply", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ForumPostConfig reply = new ForumPostConfig(); - reply.parseXML(root); - return reply; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a user message. - * This can be used to send a user a direct message. - * SPAM will cause your account to be deleted. - */ - public void createUserMessage(UserMessageConfig config) { - config.addCredentials(this); - POST(this.url + "/create-user-message", config.toXML()); - } - - /** - * Fetch the content details from the server. - * The id or name and domain of the object must be set. - */ - @SuppressWarnings("unchecked") - public T fetch(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-" + config.getType(), config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create the new content. - * The content will be returned with its new id. - */ - @SuppressWarnings("unchecked") - public T create(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-" + config.getType(), config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the content. - */ - @SuppressWarnings("unchecked") - public T update(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-" + config.getType(), config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the forum post. - */ - public ForumPostConfig update(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-forum-post", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = new ForumPostConfig(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the issue. - */ - public IssueConfig update(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-issue", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = new IssueConfig(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create or update the response. - * This can also be used to flag, unflag, validate, or invalidate a response. - */ - public ResponseConfig saveResponse(ResponseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/save-response", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ResponseConfig response = new ResponseConfig(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the user details. - * The password must be passed to allow the update. - */ - public UserConfig update(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-user", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Permanently delete the content with the id. - */ - public void delete(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-" + config.getType(), config.toXML()); - if(this.domain!=null && this.domain.id.equals(config.id) && config.getType().equals("domain") ){ - domain=null; - } - } - - /** - * Permanently delete the forum post with the id. - */ - public void delete(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-forum-post", config.toXML()); - } - - /** - * Permanently delete the issue with the id. - */ - public void delete(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-issue", config.toXML()); - } - - /** - * Permanently delete the response, greetings, or default response with the response id (and question id). - */ - public void delete(ResponseConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-response", config.toXML()); - } - - /** - * Permanently delete the avatar media. - */ - public void delete(AvatarMedia config) { - config.addCredentials(this); - POST(this.url + "/delete-avatar-media", config.toXML()); - } - - /** - * Permanently delete the avatar background. - */ - public void deleteAvatarBackground(AvatarConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-avatar-background", config.toXML()); - } - - /** - * Save the avatar media tags. - */ - public void saveAvatarMedia(AvatarMedia config) { - config.addCredentials(this); - POST(this.url + "/save-avatar-media", config.toXML()); - } - - /** - * Flag the content as offensive, a reason is required. - */ - public void flag(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-" + config.getType(), config.toXML()); - } - - /** - * Subscribe for email updates for the post. - */ - public void subscribe(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-post", config.toXML()); - } - - /** - * Subscribe for email updates for the issue. - */ - public void subscribe(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-issue", config.toXML()); - } - - /** - * Subscribe for email updates for the forum. - */ - public void subscribe(ForumConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-forum", config.toXML()); - } - - /** - * Unsubscribe from email updates for the post. - */ - public void unsubscribe(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-post", config.toXML()); - } - - /** - * Unsubscribe from email updates for the issue. - */ - public void unsubscribe(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-issue", config.toXML()); - } - - /** - * Unsubscribe from email updates for the forum. - */ - public void unsubscribe(ForumConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-forum", config.toXML()); - } - - /** - * Thumbs up the content. - */ - public void thumbsUp(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-" + config.getType(), config.toXML()); - } - - /** - * Thumbs down the content. - */ - public void thumbsDown(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-" + config.getType(), config.toXML()); - } - - /** - * Rate the content. - */ - public void star(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/star-" + config.getType(), config.toXML()); - } - - /** - * Thumbs up the content. - */ - public void thumbsUp(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-post", config.toXML()); - } - - /** - * Thumbs down the content. - */ - public void thumbsDown(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-post", config.toXML()); - } - - /** - * Rate the content. - */ - public void star(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/star-post", config.toXML()); - } - - /** - * Flag the forum post as offensive, a reason is required. - */ - public void flag(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-forum-post", config.toXML()); - } - - /** - * Thumbs up the content. - */ - public void thumbsUp(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-issue", config.toXML()); - } - - /** - * Thumbs down the content. - */ - public void thumbsDown(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-issue", config.toXML()); - } - - /** - * Rate the content. - */ - public void star(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/star-issue", config.toXML()); - } - - /** - * Flag the forum post as offensive, a reason is required. - */ - public void flag(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-issue", config.toXML()); - } - - /** - * Flag the user post as offensive, a reason is required. - */ - public void flag(UserConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-user", config.toXML()); - } - - /** - * Process the bot chat message and return the bot's response. - * The ChatConfig should contain the conversation id if part of a conversation. - * If a new conversation the conversation id is returned in the response. - */ - public ChatResponse chat(ChatConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/post-chat", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ChatResponse response = new ChatResponse(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Process the avatar message and return the avatars response. - * This allows the speech and video animation for an avatar to be generated for the message. - */ - public ChatResponse avatarMessage(AvatarMessage config) { - config.addCredentials(this); - String xml = POST(this.url + "/avatar-message", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ChatResponse response = new ChatResponse(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Process the speech message and return the server generate text-to-speech audio file. - * This allows for server-side speech generation. - */ - public String tts(Speech config) { - config.addCredentials(this); - return POST(this.url + "/speak", config.toXML()); - } - - /** - * Return the administrators of the content. - */ - public List getAdmins(WebMediumConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-" + config.getType() + "-admins", config.toXML()); - List users = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return users; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - UserConfig user = new UserConfig(); - user.parseXML((Element)root.getChildNodes().item(index)); - users.add(user.user); - } - return users; - } - - /** - * Return the list of user details for the comma separated values list of user ids. - */ - public List getUsers(String usersCSV) { - UserConfig config = new UserConfig(); - config.user = usersCSV; - config.addCredentials(this); - String xml = POST(this.url + "/get-users", config.toXML()); - List users = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return users; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - Element child = (Element)root.getChildNodes().item(index); - UserConfig userConfig = new UserConfig(); - userConfig.parseXML(child); - users.add(userConfig); - } - return users; - } - - /** - * Return the list of forum posts for the forum browse criteria. - */ - public List getPosts(BrowseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-forum-posts", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML((Element)root.getChildNodes().item(index)); - instances.add(post); - } - return instances; - } - - /** - * Return the list of issues for the issue tracker browse criteria. - */ - public List getIssues(BrowseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-issues", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - IssueConfig issue = new IssueConfig(); - issue.parseXML((Element)root.getChildNodes().item(index)); - instances.add(issue); - } - return instances; - } - - /** - * Return the list of categories for the type, and domain. - */ - public List getCategories(ContentConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-categories", config.toXML()); - List categories = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return categories; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ContentConfig category = new ContentConfig(); - category.parseXML((Element)root.getChildNodes().item(index)); - categories.add(category); - } - return categories; - } - - /** - * Return the list of tags for the type, and domain. - */ - public List getTags(ContentConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-tags", config.toXML()); - List tags = new ArrayList(); - tags.add(""); - Element root = parse(xml); - if (root == null) { - return tags; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - tags.add(((Element)root.getChildNodes().item(index)).getAttribute("name")); - } - return tags; - } - - /** - * Return the list of bot templates. - */ - - //return the list of templates with the pictures. - public List getTemplates() { - String xml = GET(this.url + "/get-all-templates"); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - InstanceConfig instance = new InstanceConfig(); - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - - /** - * Return the users for the content. - */ - public List getUsers(WebMediumConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-" + config.getType() + "-users", config.toXML()); - List users = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return users; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - UserConfig user = new UserConfig(); - user.parseXML((Element)root.getChildNodes().item(index)); - users.add(user.user); - } - return users; - } - - /** - * Return the channel's bot configuration. - */ - public BotModeConfig getChannelBotMode(ChannelConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-channel-bot-mode", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - BotModeConfig botMode = new BotModeConfig(); - botMode.parseXML(root); - return botMode; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Save the channel's bot configuration. - */ - public void saveChannelBotMode(BotModeConfig config) { - config.addCredentials(this); - POST(this.url + "/save-channel-bot-mode", config.toXML()); - } - - /** - * Save the forum's bot configuration. - */ - public void saveForumBotMode(BotModeConfig config) { - config.addCredentials(this); - POST(this.url + "/save-forum-bot-mode", config.toXML()); - } - - /** - * Save the bot's learning configuration. - */ - public void saveLearning(LearningConfig config) { - config.addCredentials(this); - POST(this.url + "/save-learning", config.toXML()); - } - - /** - * Save the bot's voice configuration. - */ - public void saveVoice(VoiceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-voice", config.toXML()); - } - - /** - * Save the bot's avatar configuration. - */ - public void saveBotAvatar(InstanceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-bot-avatar", config.toXML()); - } - - /** - * Train the bot with a new question/response pair. - */ - public void train(TrainingConfig config) { - config.addCredentials(this); - POST(this.url + "/train-instance", config.toXML()); - } - - /** - * Perform the user administration task (add or remove users, or administrators). - */ - public void userAdmin(UserAdminConfig config) { - config.addCredentials(this); - POST(this.url + "/user-admin", config.toXML()); - } - - /** - * Save the image as the avatar's background. - */ - public void saveAvatarBackground(String file, AvatarMedia config) { - config.addCredentials(this); - POSTIMAGE(this.url + "/save-avatar-background", file, config.name, config.toXML()); - } - - /** - * Add the avatar media file to the avatar. - */ - public void createAvatarMedia(String file, AvatarMedia config) { - config.addCredentials(this); - if ((file.indexOf(".jpg") != -1) || (file.indexOf(".jpeg") != -1)) { - if (config.hd) { - POSTHDIMAGE(this.url + "/create-avatar-media", file, config.name, config.toXML()); - } else { - POSTIMAGE(this.url + "/create-avatar-media", file, config.name, config.toXML()); - } - } else { - POSTFILE(this.url + "/create-avatar-media", file, config.name, config.toXML()); - } - } - /** - * Add the graphic media file to the graphic. - */ - public void createGraphicMedia(String file, GraphicConfig config) { - config.addCredentials(this); - if ((file.indexOf(".jpg") != -1) || (file.indexOf(".jpeg") != -1)) { - POSTIMAGE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); - } else { - POSTFILE(this.url + "/update-graphic-media", file, config.fileName, config.toXML()); - } - } - /** - * Update the contents icon. - * The file will be uploaded to the server. - */ - @SuppressWarnings("unchecked") - public T updateIcon(String file, T config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/update-" + config.getType() + "-icon", file, "image.jpg", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the user's icon. - * The file will be uploaded to the server. - */ - public UserConfig updateIcon(String file, UserConfig config) { - config.addCredentials(this); - String xml = POSTIMAGE(this.url + "/update-user-icon", file, "image.jpg", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - config = new UserConfig(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - public String POSTIMAGE(String url, String file, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("file: " + file); - System.out.println("XML: " + xml); - } - String result = ""; -// try { //===================== -// Bitmap bitmap = loadImage(file, 600, 600); -// ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); -// byte[] byte_arr = stream.toByteArray(); -// ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); -// -// MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); -// -// multipartEntity.addPart("file", fileBody); -// multipartEntity.addPart("xml", new StringBody(xml)); -// -// HttpClient httpclient = new DefaultHttpClient(); -// HttpResponse response = null; -// -// HttpPost httppost = new HttpPost(url); -// httppost.setEntity(multipartEntity); -// response = httpclient.execute(httppost); -// -// HttpEntity entity = response.getEntity(); -// if (entity != null) { -// result = EntityUtils.toString(entity, HTTP.UTF_8); -// } -// -// if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { -// this.exception = new SDKException("" -// + response.getStatusLine().getStatusCode() -// + " : " + result); -// throw this.exception; -// } -// -// } catch (Exception exception) { -// this.exception = new SDKException(exception); -// throw this.exception; -// } - return result; - } - - public String POSTIMAGE(String url, PixelMap bitmap, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - try { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); //===================== - byte[] byte_arr = stream.toByteArray(); - ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); - - MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); - - multipartEntity.addPart("file", fileBody); - multipartEntity.addPart("xml", new StringBody(xml)); - - HttpClient httpclient = new DefaultHttpClient(); - HttpResponse response = null; - - HttpPost httppost = new HttpPost(url); - httppost.setEntity(multipartEntity); - response = httpclient.execute(httppost); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } - - } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public String POSTHDIMAGE(String url, String file, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("file: " + file); - System.out.println("XML: " + xml); - } - String result = ""; - try { -// Bitmap bitmap = loadImage(file, 600, 600); //===================== -// ByteArrayOutputStream stream = new ByteArrayOutputStream(); -// bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream); -// byte[] byte_arr = stream.toByteArray(); -// ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); -// -// MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); -// -// multipartEntity.addPart("file", fileBody); -// multipartEntity.addPart("xml", new StringBody(xml)); -// -// HttpClient httpclient = new DefaultHttpClient(); -// HttpResponse response = null; -// -// HttpPost httppost = new HttpPost(url); -// httppost.setEntity(multipartEntity); -// response = httpclient.execute(httppost); -// -// HttpEntity entity = response.getEntity(); -// if (entity != null) { -// result = EntityUtils.toString(entity, HTTP.UTF_8); -// } -// -// if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { -// this.exception = new SDKException("" -// + response.getStatusLine().getStatusCode() -// + " : " + result); -// throw this.exception; -// } - + protected static String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; + protected static String[] mediaAccessModes = new String[]{"Everyone", "Users", "Members", "Administrators", "Disabled"}; + + protected String url; + protected UserConfig user; + protected DomainConfig domain; + protected Credentials credentials; + protected boolean debug = false; + + protected SDKException exception; + + + /** + * Create an SDK connection. + */ + public SDKConnection() { + } + + /** + * Create an SDK connection with the credentials. + * Use the Credentials subclass specific to your server. + * + * @param credentials + */ + public SDKConnection(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + /** + * Validate the user credentials (password, or token). + * The user details are returned (with a connection token, password removed). + * The user credentials are soted in the connection, and used on subsequent calls. + * An SDKException is thrown if the connect failed. + * + * @param config + * @return user + */ + public UserConfig connect(UserConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-user", config.toXML()); + Element root = parse(xml); + if (root == null) { + this.user = null; + return null; + } + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + this.user = user; } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public String POSTFILE(String url, String path, String name, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("file: " + path); - System.out.println("XML: " + xml); - } - String result = ""; - try { - File file = new File(path); - FileInputStream stream = new FileInputStream(file); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - int read = 0; - byte[] buffer = new byte[4096]; - while ((read = stream.read(buffer)) != -1 ) { - output.write(buffer, 0, read); - } - byte[] byte_arr = output.toByteArray(); - stream.close(); - ByteArrayBody fileBody = new ByteArrayBody(byte_arr, name); - - MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); - - multipartEntity.addPart("file", fileBody); - multipartEntity.addPart("xml", new StringBody(xml)); - - HttpClient httpclient = new DefaultHttpClient(); - HttpResponse response = null; - - HttpPost httppost = new HttpPost(url); - httppost.setEntity(multipartEntity); - response = httpclient.execute(httppost); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } - + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + return this.user; + } + + /** + * Connect to the domain. + * A domain is an isolated content space. + * Any browse or query request will be specific to the domain's content. + * + * @param config + * @return domain + */ + public DomainConfig connect(DomainConfig config) { + this.domain = fetch(config); + return this.domain; + } + + /** + * Disconnect from the connection. + * An SDKConnection does not keep a live connection, but this resets its connected user and domain. + */ + public void disconnect() { + this.user = null; + this.domain = null; + } + + /** + * reInitialize + * + * @param ability + * @param config + * @return user + */ + public UserConfig create(Ability ability, UserConfig config) { + config.addCredentials(this); + String xml = POSTUpdate(ability, this.url + "/create-user", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + this.user = user; + return user; } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public PixelMap loadImage(String path, int reqWidth, int reqHeight) { -// BitmapFactory.Options options = new BitmapFactory.Options(); //===================== -// options.inJustDecodeBounds = true; -// BitmapFactory.decodeFile(path, options); -// -// int height = options.outHeight; -// int width = options.outWidth; -// options.inPreferredConfig = Bitmap.Config.RGB_565; -// int inSampleSize = 1; -// -// if (height > reqHeight) { -// inSampleSize = Math.round((float)height / (float)reqHeight); -// } -// -// int expectedWidth = width / inSampleSize; -// -// if (expectedWidth > reqWidth) { -// inSampleSize = Math.round((float)width / (float)reqWidth); -// } -// -// options.inSampleSize = inSampleSize; -// options.inJustDecodeBounds = false; -// -// return BitmapFactory.decodeFile(path, options); - return null; - } - - /** - * Return the forum's bot configuration. - */ - public BotModeConfig getForumBotMode(ForumConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-forum-bot-mode", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - BotModeConfig botMode = new BotModeConfig(); - botMode.parseXML(root); - return botMode; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the bot's voice configuration. - */ - public VoiceConfig getVoice(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-voice", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - VoiceConfig voice = new VoiceConfig(); - voice.parseXML(root); - return voice; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the bot's default responses. - */ - public List getDefaultResponses(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-default-responses", config.toXML()); - List defaultResponses = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return defaultResponses; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - defaultResponses.add(((Element)root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); - } - return defaultResponses; - } - - /** - * Return the bot's greetings. - */ - public List getGreetings(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-greetings", config.toXML()); - List greetings = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return greetings; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - greetings.add(((Element)root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); - } - return greetings; - } - - /** - * Search the bot's responses. - */ - public List getResponses(ResponseSearchConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-responses", config.toXML()); - List responses = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return responses; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ResponseConfig response = new ResponseConfig(); - response.parseXML((Element)root.getChildNodes().item(index)); - responses.add(response); - } - return responses; - } - - /** - * Search the bot's conversations. - */ - public List getConversations(ResponseSearchConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-conversations", config.toXML()); - List conversations = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return conversations; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ConversationConfig response = new ConversationConfig(); - response.parseXML((Element)root.getChildNodes().item(index)); - conversations.add(response); - } - return conversations; - } - - /** - * Return the bot's learning configuration. - */ - public LearningConfig getLearning(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-learning", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - LearningConfig learning = new LearningConfig(); - learning.parseXML(root); - return learning; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the list of content for the browse criteria. - * The type defines the content type (one of Bot, Forum, Channel, Domain). - */ - public List browse(BrowseConfig config) { - config.addCredentials(this); - String type = ""; - if (config.type.equals("Bot")) { - type = "/get-instances"; - } else { - type = "/get-" + config.type.toLowerCase() + "s"; - } - String xml = POST(this.url + type, config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - WebMediumConfig instance = null; - if (config.type.equals("Bot")) { - instance = new InstanceConfig(); - } else if (config.type.equals("Forum")) { - instance = new ForumConfig(); - } else if (config.type.equals("Channel")) { - instance = new ChannelConfig(); - } else if (config.type.equals("Domain")) { - instance = new DomainConfig(); - } else if (config.type.equals("Avatar")) { - instance = new AvatarConfig(); - } else if (config.type.equals("Script")) { - instance = new ScriptConfig(); - }else if (config.type.equals("Graphic")) { - instance = new GraphicConfig(); - } - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - - /** - * Return the list of media for the avatar. - */ - public List getAvatarMedia(AvatarConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-avatar-media", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return instances; - } - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - AvatarMedia instance = new AvatarMedia(); - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - - /** - * Return the script source - */ - public ScriptSourceConfig getScriptSource(ScriptConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-script-source", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ScriptSourceConfig script = new ScriptSourceConfig(); - script.parseXML(root); - return script; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create or update script - Save the script source - */ - public void saveScriptSource(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-script-source", config.toXML()); - } - - /** - * Return the source code for a single bot script - */ - public ScriptSourceConfig getBotScriptSource(ScriptSourceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-bot-script-source", config.toXML()); - Element root = parse(xml); - if (root == null) { - return null; - } - try { - ScriptSourceConfig botScript = new ScriptSourceConfig(); - botScript.parseXML(root); - return botScript; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return a list of the bots scripts - */ - public List getBotScripts(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-bot-scripts", config.toXML()); - List botScripts = new ArrayList(); - Element root = parse(xml); - if (root == null) { - return botScripts; - } - for (int i = 0; i < root.getChildNodes().getLength(); i++) { - ScriptConfig script = new ScriptConfig(); - script.parseXML((Element)root.getChildNodes().item(i)); - botScripts.add(script); - } - return botScripts; - } - /** - * import a script to the bot - */ - - public void importBotScript(ScriptConfig config) { - config.addCredentials(this); - POST(this.url + "/import-bot-script", config.toXML()); - } - - /** - * import a chatlog/response list to the bot - */ - public void importBotLog(ScriptConfig config) { - config.addCredentials(this); - POST(this.url + "/import-bot-log", config.toXML()); - } - - - /** - * Save the bot script source - */ - public void saveBotScriptSource(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/save-bot-script-source", config.toXML()); - } - - /** - * Delete selected bot script - */ - public void deleteBotScript(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-bot-script", config.toXML()); - } - - /** - * Move up one bot script - */ - public void upBotScript(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/up-bot-script", config.toXML()); - } - - /** - * Move down one bot script - */ - public void downBotScript(ScriptSourceConfig config) { - config.addCredentials(this); - POST(this.url + "/down-bot-script", config.toXML()); - } - - /** - * Return the list of content types. - */ - public String[] getTypes() { - return types; - } - - /** - * Return the channel types. - */ - public String[] getChannelTypes() { - return channelTypes; - } - - /** - * Return the access mode types. - */ - public String[] getAccessModes() { - return accessModes; - } - - /** - * Return the media access mode types. - */ - public String[] getMediaAccessModes() { - return mediaAccessModes; - } - - /** - * Return the learning mode types. - */ - public String[] getLearningModes() { - return learningModes; - } - - /** - * Return the correction mode types. - */ - public String[] getCorrectionModes() { - return correctionModes; - } - - /** - * Return the bot mode types. - */ - public String[] getBotModes() { - return botModes; - } - - /** - * Return the current connected user. - */ - public UserConfig getUser() { - return user; - } - - /** - * Set the current connected user. - * connect() should be used to validate and connect a user. - */ - public void setUser(UserConfig user) { - this.user = user; - } - - /** - * Return the current domain. - * A domain is an isolated content space. - */ - public DomainConfig getDomain() { - return domain; - } - - /** - * Set the current domain. - * A domain is an isolated content space. - * connect() should be used to validate and connect a domain. - */ - public void setDomain(DomainConfig domain) { - this.domain = domain; - } - - /** - * Return the current application credentials. - */ - public Credentials getCredentials() { - return credentials; - } - - /** - * Set the application credentials. - */ - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - /** - * Return is debugging has been enabled. - */ - public boolean isDebug() { - return debug; - } - - /** - * Enable debugging, debug messages will be logged to System.out. - */ - public void setDebug(boolean debug) { - this.debug = debug; - } - - /** - * Return the last thrown exception. - */ - public SDKException getException() { - return exception; - } - - protected void setException(SDKException exception) { - this.exception = exception; - } - - public String GET(String url) { - if (this.debug) { - System.out.println("GET: " + url); - } - String xml = null; - try { - HttpClient httpClient = new DefaultHttpClient(); - HttpContext localContext = new BasicHttpContext(); - HttpGet httpGet = new HttpGet(url); - HttpResponse response = httpClient.execute(httpGet, localContext); - HttpEntity entity = response.getEntity(); - xml = EntityUtils.toString(entity, HTTP.UTF_8); - - if (response.getStatusLine().getStatusCode() != 200) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + xml); - return ""; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return xml; - } - - public String POST(String url, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - try { - HttpClient httpClient = new DefaultHttpClient(); - HttpContext localContext = new BasicHttpContext(); - HttpPost httpPost = new HttpPost(url); - - StringEntity content = new StringEntity(xml, "utf-8"); - content.setContentType("application/xml"); - httpPost.setEntity(content); - - HttpResponse response = httpClient.execute(httpPost, localContext); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - public String POSTUpdate(Ability ability,String url, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - Response response = null; - try { - ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), - new SharedPrefsCookiePersistor(ability)); - OkHttpClient okHttpClient = new OkHttpClient.Builder() - .cookieJar(cookieJar) - .build(); - response = getResponse(okHttpClient, url,xml); - - if ((response.code() != 200) && (response.code() != 204)) { - this.exception = new SDKException("" - + response.code() - + " : " + response.body().toString()); -// throw this.exception; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); -// throw this.exception; - } - return response.body().toString(); - } - - /** - * This method is used to get cookies from response - * - * @param client OkHttpClient to get cookies from response - * @param url Http URL - */ - public Response getResponse(OkHttpClient client, String url, String xml) { - // code request code here - MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); - String requestBody = xml; - Request request = new Request.Builder() - .url(url) - .post(RequestBody.create(mediaType, requestBody)) - .build(); - Call call = client.newCall(request); - try { - Response response = call.execute(); - return response; - } catch (IOException e) { - e.printStackTrace(); - } -// call.enqueue(new Callback() { -// @Override -// public void onFailure(Call call, IOException exception) { -// } -// -// @Override -// public void onResponse(Call call, Response response) { -// if (response != null && response.body() != null) { -// List cookieList = response.headers("Set-Cookie"); -// StringBuilder stringBuilder = new StringBuilder(); -// if (cookieList.size() > 0) { -// for (String cookie : cookieList) { -// stringBuilder.append(cookie).append(","); -// } -// } -// content[0] = response.body().toString(); -// } -// } -// }); - return null; - } - - public Element parse(String xml) { - if (this.debug) { - System.out.println(xml); - } - Document dom = null; - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource source = new InputSource(); - source.setCharacterStream(new StringReader(xml)); - dom = builder.parse(source); - return dom.getDocumentElement(); - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception.getMessage(), exception); - throw this.exception; - } - } + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * reInitialize + * + * @param config + * @return user + */ + public ForumPostConfig create(ForumPostConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-forum-post", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + ForumPostConfig post = new ForumPostConfig(); + post.parseXML(root); + return post; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * reInitialize + * + * @param config + * @return user + */ + public IssueConfig create(IssueConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-issue", config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + IssueConfig issue = new IssueConfig(); + issue.parseXML(root); + return issue; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Fetch the content details from the server. + * The id or name and domain of the object must be set. + * + * @param t + * @param config + * @return config + */ + @SuppressWarnings("unchecked") + public T fetch(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-" + config.getType(), config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Create the new content. + * The content will be returned with its new id. + * + * @param t + * @param config + * @return config + */ + @SuppressWarnings("unchecked") + public T create(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-" + config.getType(), config.toXML()); + Element root = parse(xml); + if (root == null) { + return null; + } + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Permanently delete the content with the id. + * + * @param config + */ + public void delete(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-" + config.getType(), config.toXML()); + if (this.domain != null && this.domain.id.equals(config.id) && config.getType().equals("domain")) { + domain = null; + } + } + + /** + * Permanently delete the forum post with the id. + * + * @param config + */ + public void delete(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-forum-post", config.toXML()); + } + + /** + * Permanently delete the issue with the id. + * + * @param config + */ + public void delete(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-issue", config.toXML()); + } + + /** + * Permanently delete the response, greetings, or default response with the response id (and question id). + * + * @param config + */ + public void delete(ResponseConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-response", config.toXML()); + } + + /** + * Permanently delete the avatar media. + * + * @param config + */ + public void delete(AvatarMedia config) { + config.addCredentials(this); + POST(this.url + "/delete-avatar-media", config.toXML()); + } + + /** + * Permanently delete the avatar background. + * + * @param config + */ + public void deleteAvatarBackground(AvatarConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-avatar-background", config.toXML()); + } + + /** + * Return the bot's default responses. + * + * @param config + * @return defaultResponses + */ + public List getDefaultResponses(InstanceConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-default-responses", config.toXML()); + List defaultResponses = new ArrayList(); + Element root = parse(xml); + if (root == null) { + return defaultResponses; + } + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + defaultResponses.add(((Element) root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); + } + return defaultResponses; + } + + + /** + * Return the bot's default responses. + * + * @return str + */ + public String[] getAccessModes() { + return accessModes; + } + + /** + * Return the bot's default responses. + * + * @return mediaAccessModes + */ + public String[] getMediaAccessModes() { + return mediaAccessModes; + } + + + /** + * Return the current connected user. + * + * @return user + */ + public UserConfig getUser() { + return user; + } + + /** + * Set the current connected user. + * connect() should be used to validate and connect a user. + * + * @param user + */ + public void setUser(UserConfig user) { + this.user = user; + } + + /** + * Return the current domain. + * A domain is an isolated content space. + * + * @return domain + */ + public DomainConfig getDomain() { + return domain; + } + + /** + * Set the current domain. + * A domain is an isolated content space. + * connect() should be used to validate and connect a domain. + * + * @param domain + */ + public void setDomain(DomainConfig domain) { + this.domain = domain; + } + + /** + * Return the current application credentials. + * + * @return credentials + */ + public Credentials getCredentials() { + return credentials; + } + + /** + * Set the application credentials. + * + * @param credentials + */ + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + + /** + * Enable debugging, debug messages will be logged to System.out. + * + * @param debug + */ + public void setDebug(boolean debug) { + this.debug = debug; + } + + /** + * Return the last thrown exception. + * + * @return exception + */ + public SDKException getException() { + return exception; + } + + /** + * POST + * + * @param url + * @param xml + * @return response + */ + public String POST(String url, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + try { + HttpClient httpClient = new DefaultHttpClient(); + HttpContext localContext = new BasicHttpContext(); + HttpPost httpPost = new HttpPost(url); + + StringEntity content = new StringEntity(xml, "utf-8"); + content.setContentType("application/xml"); + httpPost.setEntity(content); + + HttpResponse response = httpClient.execute(httpPost, localContext); + + HttpEntity entity = response.getEntity(); + if (entity != null) { + result = EntityUtils.toString(entity, HTTP.UTF_8); + } + if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + result); + throw this.exception; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + throw this.exception; + } + return result; + } + + /** + * reInitialize + * + * @param ability + * @param url + * @param xml + * @return response + */ + public String POSTUpdate(Ability ability, String url, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + Response response = null; + try { + ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), + new SharedPrefsCookiePersistor(ability)); + OkHttpClient okHttpClient = new OkHttpClient.Builder() + .cookieJar(cookieJar) + .build(); + response = getResponse(okHttpClient, url, xml); + + if ((response.code() != 200) && (response.code() != 204)) { + this.exception = new SDKException("" + + response.code() + + " : " + response.body().toString()); + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + } + return response.body().toString(); + } + + /** + * This method is used to get cookies from response + * + * @param client OkHttpClient to get cookies from response + * @param url Http URL + * @param xml + * @return response + */ + public Response getResponse(OkHttpClient client, String url, String xml) { + // code request code here + MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); + String requestBody = xml; + Request request = new Request.Builder() + .url(url) + .post(RequestBody.create(mediaType, requestBody)) + .build(); + Call call = client.newCall(request); + try { + Response response = call.execute(); + return response; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * parse + * + * @param xml + * @return user + */ + + public Element parse(String xml) { + if (this.debug) { + System.out.println(xml); + } + Document dom = null; + return (Element) new ShapeElement(); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java similarity index 96% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index 970f2a92749f7473abfbd8dc5d844b56a0f86545..47bfcd33e18f1f92a9ce21261dd9a14a90c4b9f4 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/ChatAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java @@ -13,21 +13,8 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.VoiceConfig; -import org.botlibre.sdk.provider.ChatListProvicer; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.PreferencesUtils; -import org.botlibre.sdk.util.ResUtils; -import org.botlibre.sdk.util.ShapeUtils; -import org.botlibre.sdk.util.ToastUtils; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; @@ -72,6 +59,19 @@ import ohos.security.SystemPermission; import ohos.utils.PacMap; import ohos.utils.zson.ZSONArray; import ohos.utils.zson.ZSONObject; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.config.AvatarConfig; +import org.botlibre.sdk.config.ChatConfig; +import org.botlibre.sdk.config.ChatResponse; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.VoiceConfig; +import org.botlibre.sdk.provider.ChatListProvicer; +import org.botlibre.sdk.util.LogUtils; +import org.botlibre.sdk.util.PreferencesUtils; +import org.botlibre.sdk.util.ResUtils; +import org.botlibre.sdk.util.ShapeUtils; +import org.botlibre.sdk.util.ToastUtils; import java.util.ArrayList; import java.util.Arrays; @@ -84,20 +84,26 @@ import static ohos.bundle.IBundleManager.PERMISSION_GRANTED; /** - * Ability for chatting with a bot. - * To launch this Ability from your app you can use the HttpFetchAction passing the bot id or name as a config, and launch=true. + * ChatAbility + * + * @since 2021-04-16 */ -@SuppressWarnings("deprecation") public class ChatAbility extends LibreAbility { + /** + * ability + */ + private static Ability ability; private static final int ASR_RESULT = 9; private static final int BEGIN_SPEECH = 10; private static final int END_SPEECH = 11; private static final int AUTO_RESPONSE = 12; - protected static boolean DEBUG; - public static Ability ability; - + /** + * videoLayout + */ + private Component videoLayout; + public Image bigImage; private DirectionalLayout directionYes; private DirectionalLayout directionSelect; private DirectionalLayout directionType; @@ -107,8 +113,8 @@ public class ChatAbility extends LibreAbility { private Button buttonBig; private Button buttonType; private Text textInfo; - private DirectionalLayout menuMLayout; - private DirectionalLayout chatCLayout; + private DirectionalLayout menuLayout; + private DirectionalLayout chatLayout; private DirectionalLayout responseLayout; private DirectionalLayout chatToolBar; private Button menuButton; @@ -119,8 +125,6 @@ public class ChatAbility extends LibreAbility { private WebView webView; private Button soundButton; private ListContainer scrollView; - public Component videoLayout; - public Image bigImage; protected TextField editText; @@ -327,7 +331,7 @@ public class ChatAbility extends LibreAbility { */ @Override public void onSpeechStart(String s) { - runUI(new Runnable() { + runUi(new Runnable() { @Override public void run() { micButton.setEnabled(false); @@ -351,7 +355,7 @@ public class ChatAbility extends LibreAbility { */ @Override public void onSpeechFinish(String s) { - runUI(new Runnable() { + runUi(new Runnable() { @Override public void run() { micButton.setEnabled(true); @@ -405,7 +409,7 @@ public class ChatAbility extends LibreAbility { */ @Override public void onEndOfSpeech() { - debug("onEndOfSpeech:"); + //debug("onEndOfSpeech:"); LogUtils.sop("onSpeechFinish"); mainHandler.sendEvent(END_SPEECH); } @@ -416,7 +420,7 @@ public class ChatAbility extends LibreAbility { */ @Override public void onError(int error) { - LogUtils.sop("ChatActivity on error executes here!"); + LogUtils.sop("ChatAbility on error executes here!"); try { if (error == AsrError.ERROR_AUDIO) { LogUtils.sop("Error: Audio Recording Error"); @@ -490,7 +494,7 @@ public class ChatAbility extends LibreAbility { @Override protected void onStart(Intent intent) { super.onStart(intent); - super.setUIContent(ResourceTable.Layout_activity_chat); + super.setUIContent(ResourceTable.Layout_ability_chat); ability = this; //clear the messages from the listView - messages.clear(); @@ -498,7 +502,7 @@ public class ChatAbility extends LibreAbility { //set/Save the current volume from the device. //setStreamVolume(); //Music Volume is Enabled. - audioManager=new AudioManager(this); + audioManager = new AudioManager(this); if (MainAbility.sound) { audioManager.setVolume(AudioManager.AudioVolumeType.STREAM_MUSIC, 5); } else { @@ -534,8 +538,8 @@ public class ChatAbility extends LibreAbility { //scrollVie added and stuff scrollView = (ListContainer) findComponentById(ResourceTable.Id_chatList); - menuMLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_menuMLayout); - chatCLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_chatCLayout); + menuLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_menuMLayout); + chatLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_chatCLayout); responseLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_responseLayout); chatToolBar = (DirectionalLayout) findComponentById(ResourceTable.Id_chatToolBar); listContainer = (ListContainer) findComponentById(ResourceTable.Id_chatList); @@ -653,8 +657,8 @@ public class ChatAbility extends LibreAbility { switch (stateLayouts) { case 0: scrollView.setVisibility(Component.VISIBLE); - chatCLayout.setVisibility(Component.VISIBLE); - menuMLayout.setVisibility(Component.VISIBLE); + chatLayout.setVisibility(Component.VISIBLE); + menuLayout.setVisibility(Component.VISIBLE); responseLayout.setVisibility(Component.VISIBLE); chatToolBar.setVisibility(Component.VISIBLE); break; @@ -666,8 +670,8 @@ public class ChatAbility extends LibreAbility { chatToolBar.setVisibility(Component.HIDE); break; case 3: - menuMLayout.setVisibility(Component.HIDE); - chatCLayout.setVisibility(Component.HIDE); + menuLayout.setVisibility(Component.HIDE); + chatLayout.setVisibility(Component.HIDE); break; } stateLayouts++; @@ -681,8 +685,8 @@ public class ChatAbility extends LibreAbility { switch (stateLayouts) { case 0: scrollView.setVisibility(Component.VISIBLE); - chatCLayout.setVisibility(Component.VISIBLE); - menuMLayout.setVisibility(Component.VISIBLE); + chatLayout.setVisibility(Component.VISIBLE); + menuLayout.setVisibility(Component.VISIBLE); responseLayout.setVisibility(Component.VISIBLE); chatToolBar.setVisibility(Component.VISIBLE); break; @@ -694,8 +698,8 @@ public class ChatAbility extends LibreAbility { chatToolBar.setVisibility(Component.HIDE); break; case 3: - menuMLayout.setVisibility(Component.HIDE); - chatCLayout.setVisibility(Component.HIDE); + menuLayout.setVisibility(Component.HIDE); + chatLayout.setVisibility(Component.HIDE); break; } stateLayouts++; @@ -1053,7 +1057,7 @@ public class ChatAbility extends LibreAbility { ttsClient = TtsClient.getInstance(); ttsClient.create(this, ttsListener); - if(asrClient!=null){ + if (asrClient != null) { asrClient.stopListening(); asrClient.cancel(); asrClient.destroy(); @@ -1135,7 +1139,7 @@ public class ChatAbility extends LibreAbility { protected void onInactive() { //stopListening(); //muteMicBeep(false); - if(asrClient!=null){ + if (asrClient != null) { asrClient.stopListening(); asrClient.cancel(); asrClient.destroy(); @@ -1153,7 +1157,7 @@ public class ChatAbility extends LibreAbility { private void stopListening() { - debug("stopListening"); + //debug("stopListening"); try { // muteMicBeep(false); isListening = false; @@ -1165,7 +1169,7 @@ public class ChatAbility extends LibreAbility { } private void restartListening() { - debug("restartListening"); + //debug("restartListening"); if (!MainAbility.listenInBackground) { return; } @@ -1187,9 +1191,6 @@ public class ChatAbility extends LibreAbility { } public void debug(final String text) { - if (!DEBUG) { - return; - } ChatResponse ready = new ChatResponse(); ready.message = text; messages.add(ready); @@ -1230,7 +1231,7 @@ public class ChatAbility extends LibreAbility { private void beginListening() { setStreamVolume(); - debug("beginListening:"); + //debug("beginListening:"); try { if (!MainAbility.handsFreeSpeech) { return; diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java similarity index 79% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java index 69900c2c8b8bb2f3e8d3e25a5e2c36890a09ee8c..63240aa8538946628a31a27f795a03b6cf0f66da 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/CreateUserAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java @@ -13,10 +13,10 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.actions.HttpCreateUserAction; +import org.botlibre.sdk.ability.actions.HttpCreateUserAction; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; @@ -25,30 +25,31 @@ import ohos.agp.components.Component; import ohos.agp.components.TextField; /** - * Ability for creating a new user. + * HttpConnectAction + * + * @since 2021-04-16 */ public class CreateUserAbility extends LibreAbility { @Override public void onStart(Intent intent) { super.onStart(intent); -// setContentView(R.layout.Ability_create_user); super.setUIContent(ResourceTable.Layout_ability_create_user); - Button createButton = (Button)findComponentById(ResourceTable.Id_createButton); + Button createButton = (Button) findComponentById(ResourceTable.Id_createButton); createButton.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { create(); } }); - } - + } + /** * Create the user. */ public void create() { - UserConfig config = new UserConfig(); - + UserConfig config = new UserConfig(); + TextField text = (TextField) findComponentById(ResourceTable.Id_userText); config.user = text.getText().toString().trim(); text = (TextField) findComponentById(ResourceTable.Id_passwordText); @@ -63,17 +64,17 @@ public class CreateUserAbility extends LibreAbility { config.website = text.getText().toString().trim(); text = (TextField) findComponentById(ResourceTable.Id_bioText); config.bio = text.getText().toString().trim(); - Checkbox checkbox = (Checkbox)findComponentById(ResourceTable.Id_showNameCheckBox); - config.showName = checkbox.isChecked(); - - HttpCreateUserAction action = new HttpCreateUserAction(getContext(),this, config); - action.execute(); + Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_showNameCheckBox); + config.showName = checkbox.isChecked(); + + HttpCreateUserAction action = new HttpCreateUserAction(getContext(), this, config); + action.execute(); } - + /** * Cancel */ public void cancel() { - terminateAbility(); + terminateAbility(); } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java similarity index 65% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index f4eb0b80dbffca796f6c7098f838927de0c061d3..d40cf6eb4d977b0c0eb3c2a95df0303cd46c3b10 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpResultAction.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -13,30 +13,26 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; -public abstract class HttpResultAction{ - protected Ability ability; - protected Exception exception; - - public HttpResultAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } +/** + * LibreAbility + * + * @since 2021-04-16 + */ +public abstract class LibreAbility extends Ability { /** - * 启动activity + * 启动ability + * + * @param ability + * @param name */ public void startOpenAbility(Ability ability, String name) { Intent intent = new Intent(); @@ -46,13 +42,17 @@ public abstract class HttpResultAction{ .withAbilityName(name) .build(); intent.setOperation(operation); - ability.startAbility(intent); + startAbility(intent); } /** - * 启动activity + * 启动ability + * + * @param ability + * @param name + * @return intent */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { + public Intent getIntent(Ability ability, String name) { Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder() .withDeviceId("") @@ -60,6 +60,18 @@ public abstract class HttpResultAction{ .withAbilityName(name) .build(); intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); + return intent; } -} \ No newline at end of file + + /** + * 主线程执行任务 + * + * @param runnable + */ + public static void runUi(Runnable runnable) { + EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); + eventHandler.postSyncTask(runnable); + + } + +} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java similarity index 99% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index 8f7300e4b2a285bd14aadfabd71c6eb19d8721fa..184f900a194a49a2eb00c60a1b96e20a87e5b975 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/ListTemplateView.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import java.util.ArrayList; import java.util.List; diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java similarity index 94% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index d6f8ac1e79231f3a9e991158893602fadb6d73a3..87dbbd6d63459b31cc92cdd5b50d351bbc2b4302 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/LoginAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -13,9 +13,9 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; -import org.botlibre.sdk.activityy.actions.HttpConnectAction; +import org.botlibre.sdk.ability.actions.HttpConnectAction; import org.botlibre.sdk.config.UserConfig; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.content.Intent; @@ -31,7 +31,6 @@ public class LoginAbility extends LibreAbility implements Component.ClickedListe @Override public void onStart(Intent intent) { super.onStart(intent); -// setContentView(R.layout.Ability_login); super.setUIContent(ResourceTable.Layout_ability_login); Button connectButton = (Button)findComponentById(ResourceTable.Id_connectButton); diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/MicConfigAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java similarity index 79% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/MicConfigAbility.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java index 9100d125d49906e5c398f35c6b153a3ae4a4e888..bd3933af1174f46c98eeffd8b462c73126f285e9 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/MicConfigAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability; import com.czt.mp3recorder.MP3Recorder; @@ -54,17 +54,13 @@ import static ohos.bundle.IBundleManager.PERMISSION_GRANTED; public class MicConfigAbility extends LibreAbility implements AsrListener { - //Name - used for Log.d(classname, "") private final String CLASSNAME = "MicConfiguration"; public boolean active; - private boolean isRecording; - private double lastReply = System.currentTimeMillis(); private Button nextButton; private Text txt; private boolean failedOfflineLanguage = false; - private int counter = 0; private TextField editTextForGoogle, editTextSpeech; private Image micButton; @@ -116,7 +112,7 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { textOption = (Text) findComponentById(ResourceTable.Id_textOption); ckOfflineSpeech.setChecked(MainAbility.offlineSpeech); - ckDebug.setChecked(ChatAbility.DEBUG); + ckDebug.setChecked(false); //disabling buttons for recording sound playButton.setEnabled(false); @@ -146,21 +142,17 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { ckDebug.setCheckedStateChangedListener((absButton, b) -> { Preferences cookies = PreferencesUtils.getPreferences(this); if (b) { - ChatAbility.DEBUG = true; cookies.putBoolean("debug", true); cookies.flushSync(); return; } //else - ChatAbility.DEBUG = false; cookies.putBoolean("debug", false); cookies.flushSync(); }); micButton.setClickedListener(component -> { if (txt.getText().equals("Status: Timeout!")) { - //Intent intent = getIntent(); terminateAbility(); - // startActivity(intent); return; } if (clicked) { @@ -169,7 +161,6 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { txt.setText("Status: Loading..."); micButton.setEnabled(false); active = true; - lastReply = System.currentTimeMillis(); } }); micButton1.setClickedListener(component -> { @@ -178,17 +169,6 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { micButton2.setClickedListener(component -> { txt.setText("Status: ON"); setMicIcon(true, false); -// Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); -// try { -// startActivityForResult(intent, 1); -// editTextForGoogle.setText(""); -// } catch (ActivityNotFoundException a) { -// Toast t = Toast.makeText(getApplicationContext(), -// "Your device doesn't support Speech to Text", -// Toast.LENGTH_SHORT); -// t.show(); -// } }); playButton.setClickedListener(component -> { try { @@ -423,7 +403,7 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { e.printStackTrace(); } if (volume != 0) { - LogUtils.e("ChatActivity", "The volume changed and saved to : " + volume); + LogUtils.e("ChatAbility", "The volume changed and saved to : " + volume); MainAbility.volume = volume; } } @@ -454,26 +434,6 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { return deleted; } - -// @Override -// protected void onActivityResult(int requestCode, int resultCode, Intent data) { -// super.onActivityResult(requestCode, resultCode, data); -// -// switch (requestCode) { -// -// case 1: { -// if (resultCode == RESULT_OK && data != null) { -// setMicIcon(false, false); -// ArrayList text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); -// editTextForGoogle.setText(text.get(0)); -// txt.setText("Status: Done!"); -// } -// break; -// } -// } -// } - - @Override public void onInit(PacMap pacMap) { @@ -482,10 +442,8 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { @Override public void onBeginningOfSpeech() { txt.setText("Status: Recording..."); - lastReply = System.currentTimeMillis(); - isRecording = true; - runUI(new Runnable() { + runUi(new Runnable() { @Override public void run() { setMicIcon(true, true); @@ -500,9 +458,7 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { @Override public void onEndOfSpeech() { txt.setText("Status: Done!"); - lastReply = System.currentTimeMillis(); - isRecording = false; - runUI(new Runnable() { + runUi(new Runnable() { @Override public void run() { setMicIcon(false, false); @@ -513,29 +469,11 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { muteMicBeep(false); } - private void restartListening() { - lastReply = System.currentTimeMillis(); - if (!active) { - setMicIcon(false, false); - return; - } - runUI(new Runnable() { - public void run() { - try { - beginListening(); - } catch (Exception e) { - } - } - }); - } @Override public void onError(int error) { - isRecording = false; - - lastReply = System.currentTimeMillis(); - runUI(new Runnable() { + runUi(new Runnable() { @Override public void run() { setMicIcon(false, false); @@ -605,46 +543,6 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { } } - private void beginListening() { - setStreamVolume(); - lastReply = System.currentTimeMillis(); - - muteMicBeep(true); -// Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); -// if (MainActivity.offlineSpeech) { -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); -// -// if (!this.failedOfflineLanguage) { -// //en-US will use the English in offline. -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US"); -// // intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true); -// } -// intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true); -// } else { -// if (MainActivity.voice.language != null && !MainActivity.voice.language.isEmpty()) { -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); -// if (!this.failedOfflineLanguage) { -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, MainActivity.voice.language); -// } -// } else { -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en"); -// if (!this.failedOfflineLanguage) { -// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en"); -// } -// } -// } -// -// try { -// LogUtils.e("BeginListening", "StartListening"); -// this.asrClient.startListening(intent); -// setMicIcon(true, false); -// } catch (ActivityNotFoundException a) { -// LogUtils.e("BeginListening", "CatchError: " + a.getMessage()); -// ToastUtils.show(this,"Your device doesn't support Speech to Text"); -// txt.setText("Status: Your device doesn't support Speech to text."); -// } - } - @Override protected void onStop() { super.onStop(); diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java similarity index 36% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java index 2d496ba8aa89d50db08635aad88c62c07416b3a0..a63963b00c9eae5907bcaf9920b846b56e28d05e 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/BaseAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java @@ -13,15 +13,54 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy; +package org.botlibre.sdk.ability.actions; +import org.botlibre.sdk.util.AsyncTask; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; -public class BaseAbility extends Ability { - @Override - public void onStart(Intent intent) { - super.onStart(intent); +/** + * HttpConnectAction + * + * @since 2021-04-16 + */ +public abstract class HttpAction extends AsyncTask { + protected Ability ability; + protected Exception exception; + + /** + * HttpAction + * + * @param ability + */ + public HttpAction(Ability ability) { + this.ability = ability; + } + + public Exception getException() { + return exception; + } + + public void setException(Exception exception) { + this.exception = exception; } -} + /** + * getIntent + * + * @param abilit + * @param name + * @param requestCode + */ + public void startOpenAbilityForResult(Ability abilit, String name, int requestCode) { + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(abilit.getBundleName()) + .withAbilityName(name) + .build(); + intent.setOperation(operation); + abilit.startAbilityForResult(intent, requestCode); + } +} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java similarity index 56% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java index ec1bb7b80b09686bf035ab5d730d38db2da668dd..951dd3fa42fe7a242a9671f5e4d4323c3683160e 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpConnectAction.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java @@ -13,8 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.actions; - +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; @@ -22,10 +21,22 @@ import org.botlibre.sdk.util.PreferencesUtils; import ohos.aafwk.ability.Ability; import ohos.data.preferences.Preferences; +/** + * HttpConnectAction + * + * @since 2021-04-16 + */ public class HttpConnectAction extends HttpUIAction { UserConfig config; boolean finish; + /** + * HttpConnectAction + * + * @param ability + * @param config + * @param finish + */ public HttpConnectAction(Ability ability, UserConfig config, boolean finish) { super(ability); this.config = config; @@ -34,11 +45,7 @@ public class HttpConnectAction extends HttpUIAction { @Override protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.connect(config); - } catch (Exception exception) { - this.exception = exception; - } + this.config = MainAbility.connection.connect(config); return ""; } @@ -48,31 +55,19 @@ public class HttpConnectAction extends HttpUIAction { if (this.exception != null) { return; } - try { - MainAbility.user = this.config; - if (this.ability instanceof MainAbility) { - ((MainAbility) this.ability).resetView(); - } - - if (this.finish) { - - Preferences cookies = PreferencesUtils.getPreferences(ability); - cookies.putString("user", MainAbility.user.user); - cookies.putString("token", MainAbility.user.token); - cookies.flushSync(); - - this.ability.terminateAbility(); - } + MainAbility.user = this.config; + if (this.ability instanceof MainAbility) { + ((MainAbility) this.ability).resetView(); + } - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + if (this.finish) { - Preferences cookies=PreferencesUtils.getPreferences(this.ability); - cookies.putString("user", null); - cookies.putString("token", null); + Preferences cookies = PreferencesUtils.getPreferences(ability); + cookies.putString("user", MainAbility.user.user); + cookies.putString("token", MainAbility.user.token); cookies.flushSync(); - return; + + this.ability.terminateAbility(); } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java similarity index 57% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java index 2ee16be891bfc11c254fbc70a3899e81d11ae153..0d8dac226f0c4e85c637ef5a06fed54b64b8c5fa 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeUserIconAction.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java @@ -13,48 +13,48 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.actions; - +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.ability.Ability; +import ohos.app.Context; -public class HttpChangeUserIconAction extends HttpUIAction { - +/** + * HttpConnectAction + * + * @since 2021-04-16 + */ +public class HttpCreateUserAction extends HttpUIAction { UserConfig config; - String file; - - public HttpChangeUserIconAction(Ability ability, String file, UserConfig config) { + private Context context; + + /** + * HttpCreateUserAction + * + * @param context + * @param ability + * @param config + */ + public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { super(ability); this.config = config; - this.file = file; + this.context = context; } @Override protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.updateIcon(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; + this.config = MainAbility.connection.create(ability, this.config); + if (this.exception != null) { + return ""; } + MainAbility.user = this.config; + this.ability.terminateAbility(); return ""; } @Override public void onPostExecute(String xml) { super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.user = this.config; - MainAbility.viewUser = this.config; -// ((ViewUserAbility) this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java similarity index 37% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java index 10a080c46ddb4ab0b94f51ba773a3eec5e1d3b36..7243c694826d95bc389a7e9b594136d52d2f1bff 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIAction.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.actions; +package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; @@ -28,57 +28,61 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; +/** + * HttpConnectAction + * + * @since 2021-04-16 + */ public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; + protected CommonDialog dialog; + + public HttpUIAction(Ability Ability) { + super(Ability); + } + + @Override + protected void onPreExecute() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.e("HttpUIAction.onPreExecute", exception.toString()); + } + } - public HttpUIAction(Ability Ability) { - super(Ability); - } - - @Override - protected void onPreExecute() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); -// this.dialog.setContentText("Processing..."); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.e("HttpUIAction.onPreExecute", exception.toString()); - } - } - - @Override - protected void onPostExecute(String result) { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.e("HttpUIAction.onPostExecute", exception.toString()); - } - } + @Override + protected void onPostExecute(String result) { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.e("HttpUIAction.onPostExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.e("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.e("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java similarity index 96% rename from SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java index 0a708de062101d0f440fbab96dd0eb7051bd493d..6b6e5f7a5b4508551fdbe969d3169da9981da5e5 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/activityy/adapter/SpinnerAdapter.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/adapter/SpinnerAdapter.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.adapter; +package org.botlibre.sdk.ability.adapter; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; @@ -30,7 +30,7 @@ import ohos.agp.components.Text; * @since 2021-05-10 */ public class SpinnerAdapter extends BaseItemProvider { - private final Ability mActivity; + private final Ability mAbility; private final LayoutScatter mInflater; private final String[] types; @@ -41,7 +41,7 @@ public class SpinnerAdapter extends BaseItemProvider { * @param types types */ public SpinnerAdapter(Ability ability, String[] types) { - mActivity = ability; + mAbility = ability; this.types = types; mInflater = LayoutScatter.getInstance(ability); } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java similarity index 40% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java index 4c9cba023915f8454dd1c3411f66ce16e41276d1..64bcfd24dbb3a4c9006e0de964875f1650ab191c 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/avatar/AvatarSelection.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.avatar; +package org.botlibre.sdk.ability.avatar; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.OfflineTemplateConfig; @@ -28,40 +28,36 @@ import ohos.data.preferences.Preferences; import java.util.ArrayList; /** - * Activity used for selecting an offline avatar. + * HttpConnectAction + * + * @since 2021-04-16 */ public class AvatarSelection extends Ability { - @Override - public void onStart(Intent intent) { - super.onStart(intent); -// setContentView(R.layout.activity_list_view); - super.setUIContent(ResourceTable.Layout_ability_list_view); - final int [] imges = {}; - final String [] names = {}; - ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); - final ListContainer listView = (ListContainer) findComponentById(ResourceTable.Id_theListView); - ArrayList items = new ArrayList(); - for (int i = 0; i < names.length; i++) { - items.add(new OfflineTemplateConfig(imges[i],names[i],null,null)); - } -// CustomListViewAdapter adapter = new CustomListViewAdapter(this, R.layout.list_item_imager, items); -// listView.setAdapter(adapter); -// listView.setOnItemClickListener(new OnItemClickListener(){ -// @Override -// public void onItemClick(AdapterView parent, View view, int position, long id) { -// OfflineTemplateConfig template = (OfflineTemplateConfig) (listView.getItemAtPosition(position)); -// saveSelectedAvatar(template.getTitle()); -// MainActivity.readZipAvatars(AvatarSelection.this, MainActivity.nameOfAvatar); -// finish(); -// }}); - } + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_list_view); + final int[] imges = {}; + final String[] names = {}; + ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); + final ListContainer listView = (ListContainer) findComponentById(ResourceTable.Id_theListView); + ArrayList items = new ArrayList(); + for (int ii = 0; ii < names.length; ii++) { + items.add(new OfflineTemplateConfig(imges[ii], names[ii], null, null)); + } + } - public static void saveSelectedAvatar(String nameOfAvatar) { - MainAbility.nameOfAvatar = nameOfAvatar; - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.current); - cookies.putString("nameOfAvatar", nameOfAvatar); - cookies.flushSync(); - } + /** + * saveSelectedAvatar + * + * @param nameOfAvatar + */ + public static void saveSelectedAvatar(String nameOfAvatar) { + MainAbility.nameOfAvatar = nameOfAvatar; + Preferences cookies = PreferencesUtils.getPreferences(MainAbility.current); + cookies.putString("nameOfAvatar", nameOfAvatar); + cookies.flushSync(); + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java similarity index 96% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java index 247c52b51d01f24612972abee126043ce59a0c4f..7401a593f358690bbbba93b1b49fb11847f72b61 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/dialog/LanguageDialogBuilder.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java @@ -13,11 +13,11 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.LanguageListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.LanguageListener; import org.botlibre.sdk.util.Constant; import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java similarity index 96% rename from BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java index 929116aa9dc948e3e73c7225d35bcad2c4b79efe..d8caef1fa97f65a4d41c50e0c281907e74135f3d 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/activityy/dialog/SpinnerDialogBuilder.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java @@ -13,12 +13,12 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.dialog; +package org.botlibre.sdk.ability.dialog; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.adapter.SpinnerAdapter; -import org.botlibre.sdk.activityy.listener.SelectListener; +import org.botlibre.sdk.ability.adapter.SpinnerAdapter; +import org.botlibre.sdk.ability.listener.SelectListener; import org.botlibre.sdk.util.Constant; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java similarity index 69% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java index bbbe5bd6556d2b1faa834fdd0c87f8264e653227..f9b7aa651450855ad7e9aa4dd089a9ffaaf4d600 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/LanguageListener.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java @@ -13,15 +13,18 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.listener; +package org.botlibre.sdk.ability.listener; /** - * Listener interface for a LiveChatConnection. - * This gives asynchronous notification when a channel receives a message, or notice. + * HttpConnectAction + * + * @since 2021-04-16 */ public interface LanguageListener { - /** - * A user message was received from the channel. - */ - void selectLanguageItem(String select); + /** + * A user message was received from the channel. + * + * @param select + */ + void selectLanguageItem(String select); } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java similarity index 70% rename from PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java rename to PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java index 06dc6d719e73d6f809445b91c3ab58aa688fbeb8..153393db1cedafa2c0a6eb1d5c3da881a5b631ee 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/listener/SelectListener.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java @@ -13,15 +13,18 @@ * limitations under the License. */ -package org.botlibre.sdk.activityy.listener; +package org.botlibre.sdk.ability.listener; /** - * Listener interface for a LiveChatConnection. - * This gives asynchronous notification when a channel receives a message, or notice. + * SelectListener + * + * @since 2021-04-16 */ public interface SelectListener { - /** - * A user message was received from the channel. - */ - void selectItem(String select); + /** + * A user message was received from the channel. + * + * @param select + */ + void selectItem(String select); } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java deleted file mode 100644 index 931ecd01195a82787a6fdebeb60865b99f78a0dd..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/EmotionalState.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy; - -/** - * A convenience enum of different emotional states. - */ - -public enum EmotionalState { - NONE, - LOVE, LIKE, DISLIKE, HATE, - RAGE, ANGER, CALM, SERENE, - ECSTATIC, HAPPY, SAD, CRYING, - PANIC, AFRAID, CONFIDENT, COURAGEOUS, - SURPRISE, BORED, - LAUGHTER, SERIOUS; -} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/IntentResult.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/IntentResult.java deleted file mode 100644 index ec31b8991fe6432404cb6138c13175f80213d3ff..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/IntentResult.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy; - -/** - *

    Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.

    - * - * @author Sean Owen - */ -public final class IntentResult { - - private final String contents; - private final String formatName; - private final byte[] rawBytes; - private final Integer orientation; - private final String errorCorrectionLevel; - - IntentResult() { - this(null, null, null, null, null); - } - - IntentResult(String contents, - String formatName, - byte[] rawBytes, - Integer orientation, - String errorCorrectionLevel) { - this.contents = contents; - this.formatName = formatName; - this.rawBytes = rawBytes; - this.orientation = orientation; - this.errorCorrectionLevel = errorCorrectionLevel; - } - - /** - * @return raw content of barcode - */ - public String getContents() { - return contents; - } - - /** - * @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names. - */ - public String getFormatName() { - return formatName; - } - - /** - * @return raw bytes of the barcode content, if applicable, or null otherwise - */ - public byte[] getRawBytes() { - return rawBytes; - } - - /** - * @return rotation of the image, in degrees, which resulted in a successful scan. May be null. - */ - public Integer getOrientation() { - return orientation; - } - - /** - * @return name of the error correction level used in the barcode, if applicable - */ - public String getErrorCorrectionLevel() { - return errorCorrectionLevel; - } - - @Override - public String toString() { - StringBuilder dialogText = new StringBuilder(100); - dialogText.append("Format: ").append(formatName).append('\n'); - dialogText.append("Contents: ").append(contents).append('\n'); - int rawBytesLength = rawBytes == null ? 0 : rawBytes.length; - dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n"); - dialogText.append("Orientation: ").append(orientation).append('\n'); - dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n'); - return dialogText.toString(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java deleted file mode 100644 index 9ea08abafdfcf1fe58c715e45becf77d86fb55f1..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/LibreAbility.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; -import ohos.eventhandler.EventHandler; -import ohos.eventhandler.EventRunner; - -/** - * Generic Ability for common behavior. - */ -public abstract class LibreAbility extends Ability { - - public void help() { -// Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(this.getBundleName()) -// .withAbilityName(HelpAbility.class.getName()) -// .build(); -// intent.setOperation(operation); -// startAbility(intent); - } - - /** - * 启动activity - */ - public void startOpenAbility(Ability ability,String name){ - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - startAbility(intent); - } - - /** - * getIntent - */ - public Intent getIntent(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - return intent; - } - - /** - * 主线程执行任务 - * @param runnable - */ - public static void runUI(Runnable runnable){ - EventHandler eventHandler=new EventHandler(EventRunner.getMainEventRunner()); - eventHandler.postSyncTask(runnable); - - } - -} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java deleted file mode 100644 index 91ba2177b49dc06a8c77b99db7570350cbce8f8d..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAddAvatarMediaAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; -import ohos.agp.window.dialog.CommonDialog; - -public class HttpAddAvatarMediaAction extends HttpUIAction { - - AvatarMedia config; - String file; - - public HttpAddAvatarMediaAction(Ability ability, String file, AvatarMedia config) { - super(ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createAvatarMedia(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPreExecute() { - this.dialog = new CommonDialog(this.ability); - //this.dialog.setCancelable(false); - this.dialog.setContentText("Uploading..."); - this.dialog.show(); - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - HttpAction action = new HttpGetAvatarMediaAction(this.ability, (AvatarConfig)MainAbility.instance.credentials(), true); - action.execute(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java deleted file mode 100644 index ae6b10cd53226c15a8500195747604ecfc70bf45..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpAvatarMessageAction.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarMessage; -import org.botlibre.sdk.config.ChatResponse; -import ohos.aafwk.ability.Ability; - -public class HttpAvatarMessageAction extends HttpAction { - AvatarMessage config; - ChatResponse response; - - public HttpAvatarMessageAction(Ability ability, AvatarMessage config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.response = MainAbility.connection.avatarMessage(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - try { -// final AvatarTestAbility ability = (AvatarTestAbility)this.ability; -// -// Image imageView = (Image)ability.findViewById(R.id.imageView); -// final VideoView videoView = (VideoView)Ability.findViewById(R.id.videoView); -// View videoLayout = Ability.findViewById(R.id.videoLayout); -// -// if (MainAbility.sound && this.response.avatarActionAudio != null && this.response.avatarActionAudio.length() > 0) { -// // Action audio -// Ability.playAudio(this.response.avatarActionAudio, false, true, true); -// } -// if (MainAbility.sound && this.response.avatarAudio != null && this.response.avatarAudio.length() > 0) { -// // Background audio -// if (!this.response.avatarAudio.equals(Ability.currentAudio)) { -// if (Ability.audioPlayer != null) { -// Ability.audioPlayer.stop(); -// Ability.audioPlayer.release(); -// } -// Ability.audioPlayer = Ability.playAudio(this.response.avatarAudio, true, true, true); -// } -// } else if (Ability.audioPlayer != null) { -// Ability.audioPlayer.stop(); -// Ability.audioPlayer.release(); -// Ability.audioPlayer = null; -// } -// -// if (!MainAbility.disableVideo && !Ability.videoError && this.response.isVideo()) { -// // Video avatar -// if (imageView.getVisibility() != View.GONE || videoLayout.getVisibility() != View.GONE) { -// if (imageView.getVisibility() == View.VISIBLE) { -// imageView.setVisibility(View.GONE); -// } -// if (videoLayout.getVisibility() == View.GONE) { -// videoLayout.setVisibility(View.VISIBLE); -// } -// } -// if (this.response.avatarAction != null && this.response.avatarAction.length() > 0) { -// // Action video -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// Ability.resetVideoErrorListener(); -// videoView.setOnCompletionListener(null); -// Ability.playVideo(response.avatar, true); -// Ability.response(response); -// } -// }); -// videoView.setOnErrorListener(new OnErrorListener() { -// @Override -// public boolean onError(MediaPlayer mp, int what, int extra) { -// Ability.resetVideoErrorListener(); -// Ability.playVideo(response.avatar, true); -// Ability.response(response); -// return true; -// } -// }); -// Ability.playVideo(this.response.avatarAction, false); -// return; -// } else { -// Ability.playVideo(this.response.avatar, true); -// } -// } else { -// // Image avatar -// if (imageView.getVisibility() != View.GONE || videoLayout.getVisibility() != View.GONE) { -// if (imageView.getVisibility() == View.GONE) { -// imageView.setVisibility(View.VISIBLE); -// } -// if (videoLayout.getVisibility() == View.VISIBLE) { -// videoLayout.setVisibility(View.GONE); -// } -// } -// if (response.isVideo()) { -// HttpGetImageAction.fetchImage(this.ability, MainAbility.instance.avatar, imageView); -// } else { -// HttpGetImageAction.fetchImage(this.ability, this.response.avatar, imageView); -// } -// } -// -// Ability.response(this.response); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java deleted file mode 100644 index 10fbd5362165a66563844dd79f5a4f894385e68a..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpBrowseCategoriesAction.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import ohos.aafwk.ability.Ability; -import org.botlibre.sdk.config.ContentConfig; - - -public class HttpBrowseCategoriesAction extends HttpAction { - ContentConfig config; - Object[] categories; - boolean finish; - - public HttpBrowseCategoriesAction(Ability ability, String type, boolean finish) { - super(ability); - this.config = new ContentConfig(); - this.config.type = type; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - if (this.config.type.equals("Bot") && MainAbility.categories != null) { - this.categories = MainAbility.categories; - } else if (this.config.type.equals("Forum") && MainAbility.forumCategories != null) { - this.categories = MainAbility.forumCategories; - } else if (this.config.type.equals("Channel") && MainAbility.channelCategories != null) { - this.categories = MainAbility.channelCategories; - } else if (this.config.type.equals("Avatar") && MainAbility.avatarCategories != null) { - this.categories = MainAbility.avatarCategories; - } else if (this.config.type.equals("Script") && MainAbility.scriptCategories != null) { - this.categories = MainAbility.scriptCategories; - } else if (this.config.type.equals("Domain")) { - this.categories = new Object[0]; - } else { - try { - this.categories = MainAbility.connection.getCategories(this.config).toArray(); - } catch (Exception exception) { - this.exception = exception; - this.categories = new Object[0]; - } - } - return ""; - } - - @SuppressWarnings("unchecked") - @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - return; - } - if (this.config.type.equals("Bot")) { - MainAbility.categories = this.categories; - } else if (this.config.type.equals("Forum")) { - MainAbility.forumCategories = this.categories; - } else if (this.config.type.equals("Channel")) { - MainAbility.channelCategories = this.categories; - } else if (this.config.type.equals("Avatar")) { - MainAbility.avatarCategories = this.categories; - } else if (this.config.type.equals("Script")) { - MainAbility.scriptCategories = this.categories; - } - if (this.finish) { - this.ability.terminateAbility(); - } - -// BrowseCategoriesAbility.type = this.config.type; -// BrowseCategoriesAbility.instances = (List)(Object)Arrays.asList(this.categories); -// startOpenAbility(this.ability,); -// Intent intent = new Intent(this.ability, BrowseCategoriesAbility.class); -// this.ability.startAbility(intent); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java deleted file mode 100644 index 58025e7ff4e1052c1ba5d09cdbeeec584944af8e..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChangeIconAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpChangeIconAction extends HttpUIAction { - - WebMediumConfig config; - String file; - - public HttpChangeIconAction(Ability ability, String file, WebMediumConfig config) { - super(ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.updateIcon(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; -// ((WebMediumAdminAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java deleted file mode 100644 index b31d24f12e56b9b531b27d7cd5da3ba434ad8252..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpChatAction.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.Component; -import ohos.agp.components.Image; - - -public class HttpChatAction extends HttpAction { - ChatConfig config; - ChatResponse response; - - public HttpChatAction(Ability ability, ChatConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.response = MainAbility.connection.chat(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPreExecute() { - if (!this.config.disconnect) { - super.onPreExecute(); - } - } - - @Override - protected void onPostExecute(String xml) { - if (this.config.disconnect) { - return; - } - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - try { - MainAbility.conversation = this.response.conversation; - final ChatAbility Ability = (ChatAbility)this.ability; - - Image imageView = (Image)Ability.bigImage; - //final VideoView videoView = Ability.videoView; - Component videoLayout = Ability.videoLayout; - - if (MainAbility.sound && this.response.avatarActionAudio != null && this.response.avatarActionAudio.length() > 0) { - // Action audio - if (MainAbility.online) { - } - } - if (MainAbility.sound && this.response.avatarAudio != null && this.response.avatarAudio.length() > 0) { - Ability.music = true; - // Background audio - if (!this.response.avatarAudio.equals(Ability.currentAudio)) { - if (Ability.audioPlayer != null) { - Ability.audioPlayer.stop(); - Ability.audioPlayer.release(); - } - if (MainAbility.online) { - } - //making sure the that mic is turned off while using the DeviceVoice. - ChatAbility.micLastStat = false; - } - } else if (Ability.audioPlayer != null) { - Ability.audioPlayer.stop(); - Ability.audioPlayer.release(); - Ability.audioPlayer = null; - Ability.music = false; - } - - if (!MainAbility.disableVideo && !Ability.videoError && this.response.isVideo()) { - // Video avatar - if (imageView.getVisibility() != Component.HIDE || videoLayout.getVisibility() != Component.HIDE) { - if (imageView.getVisibility() == Component.VISIBLE) { - imageView.setVisibility(Component.HIDE); - } - if (videoLayout.getVisibility() == Component.HIDE) { - videoLayout.setVisibility(Component.VISIBLE); - } - } - if (this.response.avatarAction != null && this.response.avatarAction.length() > 0) { - // Action video -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// Ability.resetVideoErrorListener(); -// videoView.setOnCompletionListener(null); -// Ability.cycleVideo(response); -// Ability.response(response); -// } -// }); -// videoView.setOnErrorListener(new OnErrorListener() { -// @Override -// public boolean onError(MediaPlayer mp, int what, int extra) { -// Ability.resetVideoErrorListener(); -// Ability.cycleVideo(response); -// Ability.response(response); -// return true; -// } -// }); - return; - } else { - } - } else { - // Image avatar - if (imageView.getVisibility() != Component.HIDE || videoLayout.getVisibility() != Component.HIDE) { - if (imageView.getVisibility() == Component.HIDE) { - imageView.setVisibility(Component.VISIBLE); - } - if (videoLayout.getVisibility() == Component.VISIBLE) { - videoLayout.setVisibility(Component.HIDE); - } - } - if (this.response.isVideo()) { - HttpGetImageAction.fetchImage(this.ability, ((ChatAbility)this.ability).getAvatarIcon(this.response), imageView); - } else { - HttpGetImageAction.fetchImage(this.ability, this.response.avatar, imageView); - } - } - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java deleted file mode 100644 index deb18edc0046c1f2cbd533a50344abe79a6a75a2..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateAction.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpCreateAction extends HttpUIAction { - - WebMediumConfig config; - boolean finish; - - public HttpCreateAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - this.finish = true; - } - - public HttpCreateAction(Ability ability, WebMediumConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.create(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @SuppressWarnings("rawtypes") - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - - if (this.finish) { - this.ability.terminateAbility(); - } - - Preferences cookies= PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); - -// Class childAbility = MainAbility.getAbility(this.config); -// startOpenAbility(this.ability,childAbility.getName()); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java deleted file mode 100644 index 31747bd744db1471168b6bb39f237f4e29857992..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelFileAttachmentAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.MediaConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateChannelFileAttachmentAction extends HttpUIAction { - - MediaConfig config; - String file; - - public HttpCreateChannelFileAttachmentAction(Ability ability, String file, MediaConfig config) { - super(ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.createChannelFileAttachment(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// ((LiveChatAbility)this.ability).sendFile(config); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java deleted file mode 100644 index 7c50c369684a08cb0eaa5e1b1b4956a7dbfe3f59..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateChannelImageAttachmentAction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.MediaConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateChannelImageAttachmentAction extends HttpCreateChannelFileAttachmentAction { - - public HttpCreateChannelImageAttachmentAction(Ability ability, String file, MediaConfig config) { - super(ability, file, config); - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.createChannelImageAttachment(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java deleted file mode 100644 index 4aadc32482e277fffa2c6588c8b6052916a39cc3..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateForumPostAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateForumPostAction extends HttpUIAction { - - ForumPostConfig config; - - public HttpCreateForumPostAction(Ability ability, ForumPostConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.create(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.post = this.config; - MainAbility.posts.add(0, this.config); - - this.ability.terminateAbility(); -// startOpenAbility(this.ability,ForumPostAbility.class.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java deleted file mode 100644 index 1ca20f634c0e636251d408d37fc16e9eecbe02a0..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateIssueAction extends HttpUIAction { - - IssueConfig config; - - public HttpCreateIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.create(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.issue = this.config; - MainAbility.issues.add(0, this.config); - - this.ability.terminateAbility(); - - //Intent intent = new Intent(this.ability, IssueAbility.class); - //this.ability.startAbility(intent); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java deleted file mode 100644 index 8b07d432b3609657dd23ecdb115b446250928c0c..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerBitmapAttachmentAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.MediaConfig; -import ohos.aafwk.ability.Ability; -import ohos.media.image.PixelMap; - -public class HttpCreateIssueTrackerBitmapAttachmentAction extends HttpCreateIssueTrackerFileAttachmentAction { - PixelMap bitmap; - - public HttpCreateIssueTrackerBitmapAttachmentAction(Ability ability, PixelMap bitmap, MediaConfig config) { - super(ability, "", config); - this.bitmap = bitmap; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.createIssueTrackerImageAttachment(this.bitmap, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java deleted file mode 100644 index 71e098b5264c2e7ec88e722fabe6f496a0e52e78..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerFileAttachmentAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.MediaConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateIssueTrackerFileAttachmentAction extends HttpUIAction { - - MediaConfig config; - String file; - - public HttpCreateIssueTrackerFileAttachmentAction(Ability ability, String file, MediaConfig config) { - super(ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.createIssueTrackerFileAttachment(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// ((IssueEditorAbility)this.ability).appendFile(config); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java deleted file mode 100644 index d7a7e45a3310f6d7457d12d42c9fd62d949961c5..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateIssueTrackerImageAttachmentAction.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.MediaConfig; -import ohos.aafwk.ability.Ability; -public class HttpCreateIssueTrackerImageAttachmentAction extends HttpCreateIssueTrackerFileAttachmentAction { - - public HttpCreateIssueTrackerImageAttachmentAction(Ability ability, String file, MediaConfig config) { - super(ability, file, config); - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.createIssueTrackerImageAttachment(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateReplyAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateReplyAction.java deleted file mode 100644 index 3f2f5731af5305dd296f3d26f7a07c353fcda1bf..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateReplyAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; -public class HttpCreateReplyAction extends HttpUIAction { - - ForumPostConfig config; - - public HttpCreateReplyAction(Ability ability, ForumPostConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.createReply(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.post = this.config; - - this.ability.terminateAbility(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java deleted file mode 100644 index 41575b9ceb6ce123956ab394d166f77f36fdb4ef..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; -import ohos.app.Context; - -public class HttpCreateUserAction extends HttpUIAction { - UserConfig config; - private Context context; - - public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { - super(ability); - this.config = config; - this.context = context; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.create(ability,this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - } - - if (this.exception != null) { - return ""; - } - try { - MainAbility.user = this.config; - - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return ""; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java deleted file mode 100644 index f120c4929e484565c788a2020ae6a039b96414e8..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpCreateUserMessageAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserMessageConfig; -import ohos.aafwk.ability.Ability; - -public class HttpCreateUserMessageAction extends HttpUIAction { - - UserMessageConfig config; - - public HttpCreateUserMessageAction(Ability ability, UserMessageConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createUserMessage(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java deleted file mode 100644 index 944e7ba278e226a8d26dc8b9b2bc756e708f874d..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpDeleteAction extends HttpUIAction { - WebMediumConfig config; - - public HttpDeleteAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.wasDelete = true; - MainAbility.instances.remove(this.config); - - Preferences cookies= PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), null); - cookies.flushSync(); - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarBackgroundAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarBackgroundAction.java deleted file mode 100644 index 90b7d71078fa02c85293ca5906759ac67349aaa9..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarBackgroundAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import ohos.aafwk.ability.Ability; -public class HttpDeleteAvatarBackgroundAction extends HttpUIAction { - - AvatarConfig config; - - public HttpDeleteAvatarBackgroundAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.deleteAvatarBackground(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java deleted file mode 100644 index a659bdab8845bcbbd098a59bd778613987bbefaf..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteAvatarMediaAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; - -import ohos.aafwk.ability.Ability; - -public class HttpDeleteAvatarMediaAction extends HttpUIAction { - - AvatarMedia config; - - public HttpDeleteAvatarMediaAction(Ability ability, AvatarMedia config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - HttpAction action = new HttpGetAvatarMediaAction(this.ability, (AvatarConfig)MainAbility.instance.credentials(), true); - action.execute(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java deleted file mode 100644 index 4a0f4c928d174327c12a6fda0b39d23fd25a0088..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteBotScriptAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpDeleteBotScriptAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpDeleteBotScriptAction(Ability ability, ScriptSourceConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.deleteBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - -// ((BotScriptsAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java deleted file mode 100644 index 4db525f7afb38c037ca5547d622534e6b9fe6b3d..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteForumPostAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpDeleteForumPostAction extends HttpUIAction { - - ForumPostConfig config; - - public HttpDeleteForumPostAction(Ability ability, ForumPostConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.posts.remove(this.config); - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java deleted file mode 100644 index 50788a84f8edf7ba5db50041ca2d203768689931..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteIssueAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; -public class HttpDeleteIssueAction extends HttpUIAction { - - IssueConfig config; - - public HttpDeleteIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issues.remove(this.config); - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteResponseAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteResponseAction.java deleted file mode 100644 index 42fc3d90244ffd23f39b5f76e6be172872e698bb..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDeleteResponseAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ResponseConfig; -import ohos.aafwk.ability.Ability; -public class HttpDeleteResponseAction extends HttpUIAction { - - ResponseConfig config; - - public HttpDeleteResponseAction(Ability ability, ResponseConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.delete(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// ((TrainingAbility)this.ability).getResponses().remove(this.config); -// ((TrainingAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDownBotScriptAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDownBotScriptAction.java deleted file mode 100644 index 81ea3b96207b831f1eec63f975febe082c98def2..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpDownBotScriptAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; -public class HttpDownBotScriptAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpDownBotScriptAction(Ability ability, ScriptSourceConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.downBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - -// ((BotScriptsAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java deleted file mode 100644 index d7ab7b479a22e4c8876aeba617bf7242ec90fc75..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchAction.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChannelConfig; -import org.botlibre.sdk.config.DomainConfig; -import org.botlibre.sdk.config.ForumConfig; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpFetchAction extends HttpUIAction { - WebMediumConfig config; - boolean launch; - - public HttpFetchAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - public HttpFetchAction(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - public void superOnPostExecute(String xml) { - super.onPostExecute(xml); - } - - @SuppressWarnings("rawtypes") - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - - Preferences cookies= PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); - - Class childAbility = MainAbility.getActivity(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof ChannelConfig) { -// childAbility = LiveChatAbility.class; - } else if (this.config instanceof InstanceConfig) { -// childAbility = ChatAbility.class; - HttpAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); - action.execute(); - } else if (this.config instanceof DomainConfig) { - MainAbility.connection.setDomain((DomainConfig)this.config); - MainAbility.domain = (DomainConfig)this.config; - MainAbility.tags = null; - MainAbility.categories = null; - MainAbility.forumTags = null; - MainAbility.forumCategories = null; - MainAbility.channelTags = null; - MainAbility.channelCategories = null; - MainAbility.domainTags=null; - MainAbility.domainCategories=null; - MainAbility.graphicTags = null; - MainAbility.graphicCategories = null; - - MainAbility.type = MainAbility.defaultType; -// Intent intent = new Intent(this.ability, MainAbility.class); -// intent.setFlags(Intent.FLAG_Ability_NEW_TASK); -// intent.setFlags(Intent.FLAG_Ability_CLEAR_TOP); -// this.ability.startAbility(intent); - startOpenAbility(this.ability,MainAbility.class.getName()); - return; - } else if (this.config instanceof ForumConfig) { - BrowseConfig config = new BrowseConfig(); - - config.typeFilter = "Public"; - config.type = "Post"; - config.instance = MainAbility.instance.id; - config.sort = "date"; - - HttpAction action = new HttpGetPostsAction(this.ability, config); - action.execute(); - return; - } - } else { - if (this.config instanceof InstanceConfig) { - HttpAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); - action.execute(); - } - } - startOpenAbility(this.ability,childAbility.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java deleted file mode 100644 index 098afea131556518725392932b08624805a3c80c..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchActionOffline.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.activityy.ChatAbility; -import org.botlibre.sdk.activityy.ListTemplateView; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.micro.MicroConnection; -import ohos.aafwk.ability.Ability; - -public class HttpFetchActionOffline extends HttpUIResultAction { - WebMediumConfig config; - MicroConnection microConnection = new MicroConnection(); - boolean launch; - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - doInBackground(); - } - - protected void doInBackground() { - try { - //switch connections. - MainAbility.setOnline(false); - microConnection = (MicroConnection) MainAbility.connection; - this.config = microConnection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - return; - } - - onPostExecute(); - } - - @SuppressWarnings("rawtypes") - public void onPostExecute() { - if(this.ability instanceof ListTemplateView){ - this.ability.terminateAbility(); - } - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - Class childAbility = MainAbility.getActivity(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof InstanceConfig) { - childAbility = ChatAbility.class; -// HttpAction action = new HttpGetVoiceAction(this.ability, (InstanceConfig)MainAbility.instance.credentials()); -// action.execute(); - } - } - startOpenAbility(this.ability,childAbility.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchBotAvatarAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchBotAvatarAction.java deleted file mode 100644 index 285104aada9f674eb523881ffaffadd47897f37c..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchBotAvatarAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchBotAvatarAction extends HttpUIAction { - AvatarConfig config; - - public HttpFetchBotAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((BotAvatarAbility)this.ability).resetAvatar(this.config); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java deleted file mode 100644 index 81d4dca97ec837472106ec80c47e09cffb18f690..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchChatAvatarAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchChatAvatarAction extends HttpUIAction { - AvatarConfig config; - - public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((ChatAbility)this.ability).resetAvatar(this.config); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchForumPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchForumPostAction.java deleted file mode 100644 index 1319a70b9624453bab238a309fa55d65ac598e37..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchForumPostAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchForumPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpFetchForumPostAction(Ability ability, ForumPostConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.post = this.config; - -// if (this.ability instanceof ForumPostAbility) { -// this.ability.terminateAbility(); -// } -// -// startOpenAbility(this.ability, ForumPostAbility.class.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java deleted file mode 100644 index 9b7d9275afebb3788980a578be19d0f92555b6b5..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchIssueAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpFetchIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.issue = this.config; - -// if (this.ability instanceof IssueAbility) { -// this.ability.terminateAbility(); -// } -// -// startOpenAbility(this.ability, IssueAbility.class.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java deleted file mode 100644 index aac3da2bcc8502d3eb63db9434964605cb9e332d..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchOrCreateAction.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchOrCreateAction extends HttpFetchAction { - - public HttpFetchOrCreateAction(Ability ability, WebMediumConfig config, boolean launch) { - super(ability, config, launch); - } - - @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - InstanceConfig instance = new InstanceConfig(); - instance.name = config.name; - instance.isPrivate = true; - instance.template = "template"; - - instance.categories = "Misc"; - instance.tags = ""; - - HttpCreateAction action = new HttpCreateAction(ability, instance); - action.execute(); - } else { - super.onPostExecute(xml); - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java deleted file mode 100644 index e604770428a57b814aead3ea19cfbfa9ba2bf711..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchUserAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchUserAction extends HttpUIAction { - UserConfig config; - boolean launch; - - public HttpFetchUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.viewUser = this.config; -// startOpenAbility(this.ability, ViewUserAbility.class.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java deleted file mode 100644 index dd83c40aaf9a9024a104f717f30fe75569a0af54..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFetchWarAction.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchWarAction extends HttpFetchAction { - - public HttpFetchWarAction(Ability ability, WebMediumConfig config) { - super(ability, config); - } - - @Override - public void onPostExecute(String xml) { - super.superOnPostExecute(xml); -// StartWarAbility.bot1 = (InstanceConfig)this.config; -// ((StartWarAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java deleted file mode 100644 index 810a29b9e25f6c0367b0d07f0d7fa22756603a03..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpFlagAction extends HttpUIAction { - WebMediumConfig config; - - public HttpFlagAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instance.isFlagged = true; -// this.ability.findComponentById(ResourceTable.flaggedLabel).setVisibility(View.VISIBLE); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java deleted file mode 100644 index fcdac1fc27e3c5041b42f7c4bb691358ff675397..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagForumPostAction.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; -public class HttpFlagForumPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpFlagForumPostAction(Ability ability, ForumPostConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.isFlagged = true; -// this.ability.findComponentById(ResourceTable.flaggedLabel).setVisibility(VISIBLE); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java deleted file mode 100644 index 39e8f88b58f0ded24da26f7834a291a5382917fe..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagIssueAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFlagIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpFlagIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.isFlagged = true; -// this.ability.findComponentById(ResourceTable.flaggedLabel).setVisibility(VISIBLE); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java deleted file mode 100644 index 89f9d995a60cf75b877f9537e9f33a5274be2015..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpFlagUserAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; -public class HttpFlagUserAction extends HttpUIAction { - UserConfig config; - - public HttpFlagUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - //MainAbility.viewUser.isFlagged = true; - //this.Ability.findViewById(R.id.flaggedLabel).setVisibility(View.VISIBLE); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java deleted file mode 100644 index f40e60adbfc36675d2c626feda5c9aa5a0e678dc..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAdminsAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpGetAdminsAction extends HttpUIAction { - - WebMediumConfig config; - List users; - - public HttpGetAdminsAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.users = MainAbility.connection.getAdmins(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((WebMediumUsersAbility)this.ability).admins = this.users; -// ((WebMediumUsersAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java deleted file mode 100644 index 40993f31451d6589beb7fd7ebc0cb1c3d2b622ce..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetAvatarMediaAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; - -public class HttpGetAvatarMediaAction extends HttpUIAction { - AvatarConfig config; - List instances; - boolean finish = false; - - public HttpGetAvatarMediaAction(Ability ability, AvatarConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.instances = MainAbility.connection.getAvatarMedia(config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.avatarMedias = this.instances; - if (this.finish) { - this.ability.terminateAbility(); - } -// startOpenAbility(this.ability, AvatarEditorAbility.class.getName()); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptSourceAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptSourceAction.java deleted file mode 100644 index 56cdbdd15fddce6689b8116e89faf37bb0370ba5..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptSourceAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; -public class HttpGetBotScriptSourceAction extends HttpUIAction { - ScriptSourceConfig config; - - public HttpGetBotScriptSourceAction(Ability ability, ScriptSourceConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.getBotScriptSource(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.script = this.config; - -// ((BotScriptEditorAbility)this.ability).resetView(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java deleted file mode 100644 index 148975249aa1d9bf28dfbafab5fe20721f760b83..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetBotScriptsAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.ScriptConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetBotScriptsAction extends HttpUIAction { - - InstanceConfig config; - List scripts; - - public HttpGetBotScriptsAction(Ability ability, InstanceConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.scripts = MainAbility.connection.getBotScripts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((BotScriptsAbility)this.ability).setScriptList(this.scripts); -// ((BotScriptsAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetCategoriesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetCategoriesAction.java deleted file mode 100644 index e0ff5c79f095018928b8df39d55a9111fc4d2e7d..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetCategoriesAction.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ContentConfig; -import ohos.aafwk.ability.Ability; - -import java.util.ArrayList; -import java.util.List; - -public class HttpGetCategoriesAction extends HttpAction { -// ListView llview; - ContentConfig config; - Object[] categories; - List listCategories; - - public HttpGetCategoriesAction(Ability Ability, String type) { - super(Ability); - this.config = new ContentConfig(); - this.config.type = type; - } - - @Override - protected String doInBackground(Void... params) { - if (this.config.type.equals("Bot") && MainAbility.categories != null) { - this.categories = MainAbility.categories; - } else if (this.config.type.equals("Forum") && MainAbility.forumCategories != null) { - this.categories = MainAbility.forumCategories; - } else if (this.config.type.equals("Channel") && MainAbility.channelCategories != null) { - this.categories = MainAbility.channelCategories; - } else if (this.config.type.equals("Avatar") && MainAbility.avatarCategories != null) { - this.categories = MainAbility.avatarCategories; - } else if (this.config.type.equals("Script") && MainAbility.scriptCategories != null) { - this.categories = MainAbility.scriptCategories; - } else if (this.config.type.equals("Domain")&&MainAbility.domainCategories != null) { - this.config.domain = null; - this.categories = MainAbility.domainCategories; - } else { - try { - this.categories = MainAbility.connection.getCategories(this.config).toArray(); - } catch (Exception exception) { - this.exception = exception; - this.categories = new Object[0]; - } - } - return ""; - } - - @SuppressWarnings({ "rawtypes" }) - @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - return; - } - if (this.config.type.equals("Bot")) { - MainAbility.categories = this.categories; - } else if (this.config.type.equals("Forum")) { - MainAbility.forumCategories = this.categories; - } else if (this.config.type.equals("Channel")) { - MainAbility.channelCategories = this.categories; - } else if (this.config.type.equals("Avatar")) { - MainAbility.avatarCategories = this.categories; - } else if (this.config.type.equals("Script")) { - MainAbility.scriptCategories = this.categories; - }else if(this.config.type.equals("Domain")) { - MainAbility.domainCategories = this.categories; - } - - //extracting everything from this.categories name,icon,description - listCategories = new ArrayList(); - for (int i = 0; i < categories.length; i++) { - listCategories.add((ContentConfig)this.categories[i]); - } - - //extracting the names from this.categories - Object[] names = new Object[this.categories.length]; - for (int index = 0; index < this.categories.length; index++) { - names[index] = (((ContentConfig)this.categories[index]).name); - } - -// llview = (ListView) this.ability.findViewById(R.id.theListView); -// if (llview != null) { -// ArrayAdapter adapter = new CategoryListAdapter(this.ability, -// R.layout.image_list, listCategories); -// llview.setAdapter(adapter); -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetChannelBotModeAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetChannelBotModeAction.java deleted file mode 100644 index c5384cec8dd183a2a28d18683177952fc7baa631..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetChannelBotModeAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BotModeConfig; -import org.botlibre.sdk.config.ChannelConfig; -import ohos.aafwk.ability.Ability; -public class HttpGetChannelBotModeAction extends HttpUIAction { - ChannelConfig config; - BotModeConfig botMode; - - public HttpGetChannelBotModeAction(Ability ability, ChannelConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.botMode = MainAbility.connection.getChannelBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.botMode = botMode; - -// ((ChannelBotAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java deleted file mode 100644 index cb81cfc56618683985328eba3f1d3c1009357eed..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetConversationsAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ConversationConfig; -import org.botlibre.sdk.config.ResponseSearchConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetConversationsAction extends HttpUIAction { - - ResponseSearchConfig config; - List conversations; - - public HttpGetConversationsAction(Ability ability, ResponseSearchConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.conversations = MainAbility.connection.getConversations(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((TrainingAbility)this.ability).setConversations(this.conversations); -// ((TrainingAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java deleted file mode 100644 index bda035a8bc96f6872104e935edaea357b80c13c5..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetForumBotModeAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BotModeConfig; -import org.botlibre.sdk.config.ForumConfig; -import ohos.aafwk.ability.Ability; -public class HttpGetForumBotModeAction extends HttpUIAction { - ForumConfig config; - BotModeConfig botMode; - - public HttpGetForumBotModeAction(Ability ability, ForumConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.botMode = MainAbility.connection.getForumBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.botMode = this.botMode; - -// ((ForumBotAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java deleted file mode 100644 index 1c4ec07a1982cc7b7a2abc6f7beb561d9969a267..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetImageAction.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.lang.ref.SoftReference; -import java.net.URL; -import java.util.Hashtable; -import java.util.Map; - -import org.botlibre.sdk.MainAbility; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.Component; -import ohos.agp.components.Image; -import ohos.app.Context; -import ohos.media.image.PixelMap; - -public class HttpGetImageAction extends HttpAction { - public static int MAX_HEIGHT = 1200; - public static int MAX_WIDTH = 600; - public static int MAX_FILES = 100; - - public static volatile boolean downloading; - - public static File cacheDir; - public static Map> imageCache = new Hashtable>(); - - String image; - PixelMap bmp; - Image view; - - - - public static void setImage(int imageId, Component view){ - if(view instanceof Image){ -// ((Image) view).setImageResource(imageId); - } - } - - public static void clearFileCache(Context context) { - try { - File[] files = getFileCacheDir(context).listFiles(); - if (files == null) { - return; - } - for (File file : files) { - if (file.isDirectory()) { - File[] nested = file.listFiles(); - for (File nestedFile : nested) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } else { - file.delete(); - } - } - } catch (Exception failed) { -// Log.wtf(failed.toString(), failed); - } - } - - public static File getFileCacheDir(Context context) { - if (cacheDir == null) { - try { - - cacheDir = context.getCacheDir(); - if (!cacheDir.exists()) { - cacheDir.mkdirs(); - } - } catch (Exception failed) { - failed.printStackTrace(); - return null; - } - } - return cacheDir; - } - - public static File getFile(String filename, Context context) { - File dir = getFileCacheDir(context); - if (dir == null) { - return null; - } - - File file = new File(dir.getAbsolutePath() + "/" + filename); - dir = new File(file.getParent()); - if (!dir.exists()) { - dir.mkdir(); - } else { - File[] files = dir.listFiles(); - if (files.length > MAX_FILES) { - for (File nestedFile : files) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } - } - return file; - } - - public static File getFile(String dirName, String filename, Context context) { - File dir = getFileCacheDir(context); - if (dir == null) { - return null; - } - - File file = new File(dir.getAbsolutePath() + "/" + dirName + "/" + filename); - dir = new File(file.getParent()); - if (!dir.exists()) { - dir.mkdir(); - } else { - File[] files = dir.listFiles(); - if (files.length > MAX_FILES) { - for (File nestedFile : files) { - if (!nestedFile.isDirectory()) { - nestedFile.delete(); - } - } - } - } - return file; - } - - public static void fetchImage(Ability Ability, String image, Image view) { - if (image == null) { - return; - } - SoftReference ref = imageCache.get(image); - if (ref != null) { - PixelMap bmp = ref.get(); - if (bmp != null) { - if (view instanceof Image) { - view.setPixelMap(bmp); - } - return; - } - } - HttpGetImageAction action = new HttpGetImageAction(Ability, image, view); - try { - action.execute().get(); - action.postExecute(); - if (action.getException() != null) { - throw action.getException(); - } - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - return; - } - } - - public HttpGetImageAction(Ability Ability) { - super(Ability); - } - - public HttpGetImageAction(Ability Ability, String image, Image view) { - super(Ability); - this.image = image; - this.view = view; - } - - @Override - protected String doInBackground(Void... params) { - try { - URL url = MainAbility.connection.fetchImage(this.image); - - /*BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - long start = System.currentTimeMillis(); - InputStream stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream, null, options); - stream.close(); - System.out.println("decodeStream1:" + (System.currentTimeMillis() - start)); - - int height = options.outHeight; - int width = options.outWidth; - options.inPreferredConfig = Bitmap.Config.RGB_565; - int inSampleSize = 1; - - if (height > MAX_HEIGHT) { - inSampleSize = Math.round((float)height / (float)MAX_HEIGHT); - } - - int expectedWidth = width / inSampleSize; - - if (expectedWidth > MAX_WIDTH) { - inSampleSize = Math.round((float)width / (float)MAX_WIDTH); - } - - options.inSampleSize = inSampleSize; - options.inJustDecodeBounds = false; - - start = System.currentTimeMillis(); - stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream, null, options).recycle(); - stream.close(); - System.out.println("decodeStream2:" + (System.currentTimeMillis() - start)); - - start = System.currentTimeMillis(); - stream = url.openConnection().getInputStream(); - BitmapFactory.decodeStream(stream).recycle(); - stream.close(); - System.out.println("decodeStream-full:" + (System.currentTimeMillis() - start));*/ - - File file = getFile(this.image, this.ability); - if (!file.exists()) { - downloading = true; - file.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(file); - InputStream stream = url.openConnection().getInputStream(); - byte[] bytes= new byte[1024]; - int count = 0; - while (count != -1) { - count = stream.read(bytes, 0, 1024); - if (count == -1) { - break; - } - outputStream.write(bytes, 0, count); - } - stream.close(); - outputStream.close(); - downloading = false; - } - -// BitmapFactory.Options options = new BitmapFactory.Options(); -// options.inJustDecodeBounds = true; -// InputStream stream = new FileInputStream(file); -// BitmapFactory.decodeStream(stream, null, options); -// stream.close(); -// -// int height = options.outHeight; -// int width = options.outWidth; -// options.inPreferredConfig = Bitmap.Config.RGB_565; -// int inSampleSize = 1; -// if (height > MAX_HEIGHT) { -// inSampleSize = Math.round((float)height / (float)MAX_HEIGHT); -// } -// int expectedWidth = width / inSampleSize; -// if (expectedWidth > MAX_WIDTH) { -// inSampleSize = Math.round((float)width / (float)MAX_WIDTH); -// } -// options.inSampleSize = inSampleSize; -// options.inJustDecodeBounds = false; -// -// stream = new FileInputStream(file); -// this.bmp = BitmapFactory.decodeStream(stream, null, options); -// stream.close(); -// -// imageCache.put(this.image, new SoftReference(this.bmp)); - return ""; - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - } - return null; - } - - protected void postExecute() { - if (view instanceof Image) { -// ((Image)view).setImageBitmap(bmp); - } -// else if (view instanceof Button) { -//// ((Button)view).setBackgroundDrawable(new BitmapDrawable(view.getResources(), bmp)); -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java deleted file mode 100644 index 3c8193f205833111f7f14917caac1b48fd9650ce..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetInstancesAction.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetInstancesAction extends HttpUIAction { - - BrowseConfig config; - List instances; - boolean finish = false; - boolean CustomAvatar = false; - - public HttpGetInstancesAction(Ability ability, BrowseConfig config) { - super(ability); - this.config = config; - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish, boolean CustomAvatar) { - super(ability); - this.config = config; - this.finish = finish; - this.CustomAvatar = CustomAvatar; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.instances = MainAbility.connection.browse(config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instances = this.instances; - - if (this.finish) { - this.ability.terminateAbility(); - } -// Intent intent = null; -// MainAbility.browse = this.config; -// if (config.type.equals("Forum")) { -// intent = getIntent(this.ability, BrowseForumAbility.class.getName()); -// } else if (config.type.equals("Channel")) { -// intent = getIntent(this.ability, BrowseChannelAbility.class.getName()); -// } else if (config.type.equals("Domain")) { -// intent = getIntent(this.ability, BrowseDomainAbility.class.getName()); -// } else if (config.type.equals("Avatar")) { -// intent = getIntent(this.ability, BrowseAvatarAbility.class.getName()); -// } else if (config.type.equals("Graphic")) { -// intent = getIntent(this.ability, BrowseGraphicAbility.class.getName()); -// if (this.CustomAvatar) { -// //only happens when CustomAvatar is called -// intent.setParam("dataName", "Custom Avatar"); -// intent.setParam("dataCustomAvatar", true); -// } else { -// intent.setParam("dataCustomAvatar", false); -// } -// -// } else if (config.type.equals("Script")) { -// if (MainAbility.importingBotScript) { -// List onlyScripts = new ArrayList(); -// -// for (int i = 0; i < MainAbility.instances.size(); i++) { -// ScriptConfig config = (ScriptConfig) MainAbility.instances.get(i); -// if (config.categories.contains("Self") || config.categories.contains("AIML")) { -// onlyScripts.add(config); -// } -// } -// MainAbility.instances = onlyScripts; -// } else if (MainAbility.importingBotLog) { -// List onlyScripts = new ArrayList(); -// -// for (int i = 0; i < MainAbility.instances.size(); i++) { -// ScriptConfig config = (ScriptConfig) MainAbility.instances.get(i); -// if (config.categories.contains("Log") || config.categories.contains("AIML") || config.categories.contains("Response")) { -// onlyScripts.add(config); -// } -// } -// MainAbility.instances = onlyScripts; -// } -// intent = getIntent(this.ability, BrowseScriptAbility.class.getName()); -// } else { -// intent = getIntent(this.ability, BrowseAbility.class.getName()); -// } -// -// //for result only happens when RequestAbility calls it. -// if (this.CustomAvatar) { -// this.ability.startAbilityForResult(intent, 1); -// } else { -// this.ability.startAbility(intent); -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java deleted file mode 100644 index b6dad790d98669004e941982a3219b054223c3a1..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetIssuesAction.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; - -import java.util.List; - -public class HttpGetIssuesAction extends HttpUIAction { - BrowseConfig config; - List issues; - boolean finish = false; - - public HttpGetIssuesAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - public HttpGetIssuesAction(Ability Ability, BrowseConfig config, boolean finish) { - super(Ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.issues = MainAbility.connection.getIssues(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issues = this.issues; - - if (this.finish) { - this.ability.terminateAbility(); - } - MainAbility.browseIssues = this.config; - Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(this.ability.getBundleName()) -// .withAbilityName(BrowseIssueAbility.class.getName()) -// .build(); -// intent.setOperation(operation); - this.ability.startAbility(intent); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java deleted file mode 100644 index 924140c98495c40c8d8820abb752656c41f3f849..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLearningAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.LearningConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetLearningAction extends HttpUIAction { - InstanceConfig config; - LearningConfig learning; - - public HttpGetLearningAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.learning = MainAbility.connection.getLearning(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.learning = this.learning; - -// ((LearningAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java deleted file mode 100644 index 110829bcca8e12cfd1b190174764bdcc8c65f126..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetLiveChatUsersAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetLiveChatUsersAction extends HttpAction { - String csv; - List users; - - public HttpGetLiveChatUsersAction(Ability Ability, String csv) { - super(Ability); - this.csv = csv; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.users = MainAbility.connection.getUsers(this.csv); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { -// ((LiveChatAbility)this.ability).setUsers(this.users); - - } catch (Exception error) { - this.exception = error; - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java deleted file mode 100644 index 45160f90d72e965d766063cd5684290e9c6ea238..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetPostsAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; - -public class HttpGetPostsAction extends HttpUIAction { - BrowseConfig config; - List posts; - boolean finish = false; - - public HttpGetPostsAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - public HttpGetPostsAction(Ability Ability, BrowseConfig config, boolean finish) { - super(Ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.posts = MainAbility.connection.getPosts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.posts = this.posts; - - if (this.finish) { - this.ability.terminateAbility(); - } - MainAbility.browsePosts = this.config; - Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(this.ability.getBundleName()) -// .withAbilityName(BrowsePostAbility.class.getName()) -// .build(); -// intent.setOperation(operation); - this.ability.startAbility(intent); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java deleted file mode 100644 index 3cecc102f6f3b49c4763d5d2aef16558e0021eb4..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetResponsesAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ResponseConfig; -import org.botlibre.sdk.config.ResponseSearchConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpGetResponsesAction extends HttpUIAction { - - ResponseSearchConfig config; - List responses; - - public HttpGetResponsesAction(Ability Ability, ResponseSearchConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.responses = MainAbility.connection.getResponses(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// try { -// ((TrainingAbility)this.ability).setResponses(this.responses); -// ((TrainingAbility)this.ability).resetView(); -// } catch (Exception error) { -// this.exception = error; -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// return; -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java deleted file mode 100644 index adfe1d1fba0de8d6895fce86b23313b7836016b5..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetScriptSourceAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetScriptSourceAction extends HttpUIAction { - ScriptConfig config; - ScriptSourceConfig script; - - public HttpGetScriptSourceAction(Ability Ability, ScriptConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.script = MainAbility.connection.getScriptSource(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.script = this.script; - -// ((ScriptEditorAbility)this.ability).resetView(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java deleted file mode 100644 index c2dec227ec6ccab052d4e335df5b41a543afedf2..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTagsAction.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ContentConfig; -import ohos.aafwk.ability.Ability; - -import javax.swing.text.html.ListView; - -public class HttpGetTagsAction extends HttpAction { - ContentConfig config; - Object[] tags; - ListView llview; - - public HttpGetTagsAction(Ability Ability, String type) { - super(Ability); - this.config = new ContentConfig(); - this.config.type = type; - } - - @Override - protected String doInBackground(Void... params) { - if (this.config.type.equals("Bot") && MainAbility.tags != null) { - this.tags = MainAbility.tags; - } else if (this.config.type.equals("Forum") && MainAbility.forumTags != null) { - this.tags = MainAbility.forumTags; - } else if (this.config.type.equals("Post") && MainAbility.forumPostTags != null) { - this.tags = MainAbility.forumPostTags; - } else if (this.config.type.equals("Channel") && MainAbility.channelTags != null) { - this.tags = MainAbility.channelTags; - } else if (this.config.type.equals("Avatar") && MainAbility.avatarTags != null) { - this.tags = MainAbility.avatarTags; - } else if (this.config.type.equals("Script") && MainAbility.scriptTags != null) { - this.tags = MainAbility.scriptTags; - } else if (this.config.type.equals("Domain") && MainAbility.domainTags != null) { -//------- //it's not passing anything -// this.tags = new Object[0]; - //Clean up the domain - this.config.domain = null; - this.tags = MainAbility.domainTags; - } else { - try { - this.tags = MainAbility.connection.getTags(this.config).toArray(); - } catch (Exception exception) { - this.exception = exception; - } - } - return ""; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - return; - } - if (this.config.type.equals("Bot")) { - MainAbility.tags = this.tags; - } else if (this.config.type.equals("Forum")) { - MainAbility.forumTags = this.tags; - } else if (this.config.type.equals("Post")) { - MainAbility.forumPostTags = this.tags; - } else if (this.config.type.equals("Channel")) { - MainAbility.channelTags = this.tags; - } else if (this.config.type.equals("Avatar")) { - MainAbility.avatarTags = this.tags; - } else if (this.config.type.equals("Script")) { - MainAbility.scriptTags = this.tags; - }else if(this.config.type.equals("Domain")){ - - //added domainTags - MainAbility.domainTags = this.tags; - } - - - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java deleted file mode 100644 index 1a72c3e9dca1f2b7938cca2c6bd5049a8de6d93e..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetTemplatesAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -import javax.swing.text.html.ListView; -import java.util.List; - -public class HttpGetTemplatesAction extends HttpAction { - ListView llview; - List templates; - - public HttpGetTemplatesAction(Ability Ability) { - super(Ability); - - } - - @Override - protected String doInBackground(Void... params) { - try { - this.templates = MainAbility.connection.getTemplates(); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - public void postExecute(String xml) { - if (this.exception != null) { - return; - } - - MainAbility.templates = this.templates; - - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetUsersAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetUsersAction.java deleted file mode 100644 index 587014504222cad8915be883e565474b6de2e100..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetUsersAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetUsersAction extends HttpUIAction { - - WebMediumConfig config; - List users; - - public HttpGetUsersAction(Ability Ability, WebMediumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.users = MainAbility.connection.getUsers(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// try { -// ((WebMediumUsersAbility)this.ability).users = this.users; -// ((WebMediumUsersAbility)this.ability).resetView(); -// } catch (Exception error) { -// this.exception = error; -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// return; -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java deleted file mode 100644 index d8814dc33356d7835bc5305e28fd6a0249ef5f95..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVideoAction.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.net.URL; - -import org.botlibre.sdk.MainAbility; - -import ohos.aafwk.ability.Ability; -import ohos.utils.net.Uri; - -public class HttpGetVideoAction extends HttpGetImageAction { - - String video; - - public static Uri fetchVideo(Ability Ability, String video) { -// if(!MainAbility.online){ -// File file = getFile(GetAvatarAction.nameOfFile,video, Ability); -// return Uri.getUriFromFile(file); -// } - - if (video == null) { - return null; - } - - if (downloading) { - return null; - } - File file = getFile(video, Ability); - if (file.exists()) { - if (downloading) { - return null; - } - return Uri.getUriFromFile(file); - } - HttpGetVideoAction action = new HttpGetVideoAction(Ability, video); - try { - action.execute().get(); - if (action.getException() != null) { - throw action.getException(); - } - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - } - return Uri.getUriFromFile(file); - } - - public HttpGetVideoAction(Ability Ability, String video) { - super(Ability); - this.video = video; - } - - @Override - protected String doInBackground(Void... params) { - try { - URL url = MainAbility.connection.fetchImage(this.video); - - File file = getFile(this.video, this.ability); - if (!file.exists()) { - downloading = true; - file.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(file); - InputStream stream = url.openConnection().getInputStream(); - byte[] bytes= new byte[1024]; - int count = 0; - while (count != -1) { - count = stream.read(bytes, 0, 1024); - if (count == -1) { - break; - } - outputStream.write(bytes, 0, count); - } - stream.close(); - outputStream.close(); - downloading = false; - } - return ""; - } catch (Exception exception) { - if (MainAbility.DEBUG) { - exception.printStackTrace(); - } - downloading = false; - } - return null; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java deleted file mode 100644 index 7b8cb9efdfd3757a5faebe5e299d2fd58243903b..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpGetVoiceAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.VoiceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetVoiceAction extends HttpAction { - InstanceConfig config; - VoiceConfig voice; - - public HttpGetVoiceAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.voice = MainAbility.connection.getVoice(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - return; - } - try { - if (!MainAbility.customVoice) { - MainAbility.voice = this.voice; - MainAbility.deviceVoice = this.voice.nativeVoice; - -// if (this.ability instanceof VoiceAbility) { -// ((VoiceAbility) this.ability).resetView(); -// } - } - } catch (Exception error) { - this.exception = error; - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotLogAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotLogAction.java deleted file mode 100644 index f3fb15e5b4e2e2d314d9611aa255f295dd016dab..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotLogAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpImportBotLogAction extends HttpUIAction { - ScriptConfig config; - ScriptSourceConfig script; - - public HttpImportBotLogAction(Ability Ability, ScriptConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - //this.script = MainAbility.connection.getScriptSource(this.config); - - MainAbility.connection.importBotLog(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java deleted file mode 100644 index de0a1832da18b3ef0400db46281dac24b23b6e20..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpImportBotScriptAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpImportBotScriptAction extends HttpUIAction { - ScriptConfig config; - ScriptSourceConfig script; - - public HttpImportBotScriptAction(Ability Ability, ScriptConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - //this.script = MainAbility.connection.getScriptSource(this.config); - - MainAbility.connection.importBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java deleted file mode 100644 index 004a10f9d277e511a32d1b447f89573f85faa585..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageInstancesAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpPageInstancesAction extends HttpUIAction { - BrowseConfig config; - List instances; - - public HttpPageInstancesAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.instances = MainAbility.connection.browse(config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instances = this.instances; - - MainAbility.browse = this.config; -// ((BrowseAbility)this.ability).instances = this.instances; -// ((BrowseAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageIssuesAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageIssuesAction.java deleted file mode 100644 index bf8ffdd9bf1383224820f4101b90e2a2c7f79675..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPageIssuesAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpPageIssuesAction extends HttpUIAction { - BrowseConfig config; - List issues; - - public HttpPageIssuesAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.issues = MainAbility.connection.getIssues(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issues = this.issues; - MainAbility.browseIssues = this.config; -// ((BrowseIssueAbility)this.ability).instances = this.issues; -// ((BrowseIssueAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java deleted file mode 100644 index 3f07575bc0b0c8e50310ed62a235d217271062e0..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpPagePostsAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpPagePostsAction extends HttpUIAction { - BrowseConfig config; - List posts; - - public HttpPagePostsAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.posts = MainAbility.connection.getPosts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.posts = this.posts; - MainAbility.browsePosts = this.config; -// ((BrowsePostAbility)this.ability).instances = this.posts; -// ((BrowsePostAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java deleted file mode 100644 index 7f5311c85400c2ddcfdb69b9bfab0d08e0f49c69..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpRefreshAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.GraphicConfig; -import ohos.aafwk.ability.Ability; - -public class HttpRefreshAction extends HttpFetchAction { - - - GraphicConfig instance; - - - public HttpRefreshAction(Ability Ability, GraphicConfig config) { - super(Ability, config); - instance = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarBackgroundAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarBackgroundAction.java deleted file mode 100644 index 2acfc985187fb5b839453e365abbf7090934fb27..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarBackgroundAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; -import ohos.agp.window.dialog.CommonDialog; - -public class HttpSaveAvatarBackgroundAction extends HttpUIAction { - - AvatarMedia config; - String file; - - public HttpSaveAvatarBackgroundAction(Ability Ability, String file, AvatarMedia config) { - super(Ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveAvatarBackground(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - @Override - protected void onPreExecute() { - this.dialog = new CommonDialog(this.ability); - this.dialog.setAutoClosable(false); - this.dialog.setContentText("Processing..."); - this.dialog.show(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java deleted file mode 100644 index b39334894985a70c42b5653529d6d9923ca10064..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveAvatarMediaAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; - -public class HttpSaveAvatarMediaAction extends HttpUIAction { - - AvatarMedia config; - - public HttpSaveAvatarMediaAction(Ability Ability, AvatarMedia config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveAvatarMedia(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - this.ability.terminateAbility(); - MainAbility.wasDelete = true; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java deleted file mode 100644 index bca36f1622afb78a476cdf2b07d33249ef0359c0..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotAvatarAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveBotAvatarAction extends HttpUIAction { - - InstanceConfig config; - - public HttpSaveBotAvatarAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveBotAvatar(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotScriptSourceAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotScriptSourceAction.java deleted file mode 100644 index 3c561c50bd7f5649cdb1728c3361fe85930d20ac..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveBotScriptSourceAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveBotScriptSourceAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpSaveBotScriptSourceAction(Ability Ability, ScriptSourceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveBotScriptSource(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// BotScriptEditorAbility didItCompile = (BotScriptEditorAbility)this.Ability; -// didItCompile.didCompile(); - MainAbility.script = this.config; - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java deleted file mode 100644 index f0dcffb3aca9c44b0c5411151fa67a89b6d2ef2d..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveChannelBotModeAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BotModeConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveChannelBotModeAction extends HttpUIAction { - - BotModeConfig config; - - public HttpSaveChannelBotModeAction(Ability Ability, BotModeConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveChannelBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.botMode = this.config; - - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java deleted file mode 100644 index 29b727eee5f6ab601a32002f44fa3f62cddd45ba..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveForumBotModeAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.BotModeConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveForumBotModeAction extends HttpUIAction { - - BotModeConfig config; - - public HttpSaveForumBotModeAction(Ability Ability, BotModeConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveForumBotMode(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.botMode = this.config; - - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java deleted file mode 100644 index 7dd40134bbef069fe4d55005fdbeb62f33e0411a..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveLearningAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.LearningConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveLearningAction extends HttpUIAction { - - LearningConfig config; - - public HttpSaveLearningAction(Ability Ability, LearningConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveLearning(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.learning = this.config; - - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java deleted file mode 100644 index e3d6b0d04452fb9b414fb165f8113534e5023104..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveResponseAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ResponseConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpSaveResponseAction extends HttpUIAction { - - public ResponseConfig config; - public static ResponseConfig response; - public static ResponseConfig oldResponse; - - public HttpSaveResponseAction(Ability Ability, ResponseConfig config) { - super(Ability); - this.config = config; - oldResponse = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.saveResponse(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// if (this.ability instanceof TrainingAbility) { -// ((TrainingAbility)this.ability).resetView(this.config); -// } else { -// response = this.config; -// this.ability.terminateAbility(); -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java deleted file mode 100644 index 1b6bb6e020943482cfeccca68f69c21c1300bbfa..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveScriptSourceAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveScriptSourceAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpSaveScriptSourceAction(Ability Ability, ScriptSourceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveScriptSource(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - - this.ability.terminateAbility(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java deleted file mode 100644 index 44019813ac76cd4c970509b24fb61cdf60931069..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSaveVoiceAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.VoiceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSaveVoiceAction extends HttpUIAction { - - VoiceConfig config; - - public HttpSaveVoiceAction(Ability Ability, VoiceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.saveVoice(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.voice = this.config; - this.ability.terminateAbility(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java deleted file mode 100644 index e29cda5412b7fe5fafd73cde401c9def111fc136..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSpeechAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.Speech; -import ohos.aafwk.ability.Ability; - -public class HttpSpeechAction extends HttpAction { - Speech config; - String response; - - public HttpSpeechAction(Ability Ability, Speech config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.response = MainAbility.connection.tts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } -// try { -// final VoiceAbility Ability = (VoiceAbility)this.ability; -// Ability.playAudio(this.response, false, true, true); -// } catch (Exception error) { -// this.exception = error; -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// return; -// } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarAction.java deleted file mode 100644 index 3084e0c356249d055168ef46ea8a379bc2cf0c82..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpStarAction extends HttpUIAction { - WebMediumConfig config; - - public HttpStarAction(Ability Ability, WebMediumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.star(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instance.stars = config.stars; -// ((WebMediumAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java deleted file mode 100644 index a0f6e357d89bf011fbccf064f8977b6328ff840a..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarIssueAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpStarIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpStarIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.star(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.stars = config.stars; -// ((IssueAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java deleted file mode 100644 index bda6f040b075a666ccf801bd55ac439906ca27d9..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpStarPostAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpStarPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpStarPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.star(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.stars = config.stars; -// ((ForumPostAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java deleted file mode 100644 index aadb205007a58a40dcd91cf6796e95308e292cf6..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSubscribeAction extends HttpUIAction { - ForumPostConfig config; - - public HttpSubscribeAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.subscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java deleted file mode 100644 index 6413c8886ab587ff5a9dc67355457bac2a731787..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeForumAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSubscribeForumAction extends HttpUIAction { - ForumConfig config; - - public HttpSubscribeForumAction(Ability Ability, ForumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.subscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java deleted file mode 100644 index 123cfad81c6a3ed8fccdbfec32d41b0f4517634f..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpSubscribeIssueAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpSubscribeIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpSubscribeIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.subscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownAction.java deleted file mode 100644 index 391196ef64021609758cdfb5fba6a328cc5488d6..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsDownAction extends HttpUIAction { - WebMediumConfig config; - - public HttpThumbsDownAction(Ability Ability, WebMediumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsDown(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instance.thumbsDown++; -// ((WebMediumAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java deleted file mode 100644 index de4aa6992c19bdf0a233eb368b372fa0bc9e5fbe..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownIssueAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsDownIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpThumbsDownIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsDown(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.thumbsDown++; -// ((IssueAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownPostAction.java deleted file mode 100644 index 32c0e7e3f26d1e356254c1ca149448aca3c9fc12..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsDownPostAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsDownPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpThumbsDownPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsDown(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.thumbsDown++; -// ((ForumPostAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java deleted file mode 100644 index a0e01cd81214cb27ad62f8932c90cf23a46eeae0..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsUpAction extends HttpUIAction { - WebMediumConfig config; - - public HttpThumbsUpAction(Ability Ability, WebMediumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsUp(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.instance.thumbsUp++; -// ((WebMediumAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java deleted file mode 100644 index 08afc81e6afbf349da8349ce6da0645fee3c5b3c..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpIssueAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpThumbsUpIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpThumbsUpIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsUp(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.issue.thumbsUp++; -// ((IssueAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java deleted file mode 100644 index 26c32755b30cf35f3560c3da5928e5bcc35d7d72..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpThumbsUpPostAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; - -import ohos.aafwk.ability.Ability; - -public class HttpThumbsUpPostAction extends HttpUIAction { - ForumPostConfig config; - - public HttpThumbsUpPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.thumbsUp(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.post.thumbsUp++; -// ((ForumPostAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java deleted file mode 100644 index 7f84fd925b4eac1dfb1feeb6b4e250f013a25c2f..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUIResultAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.ResUtils; -import org.botlibre.sdk.ResourceTable; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; - - public HttpUIResultAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.e("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { -// if(!exception.toString().equals("403")) { -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// } else { - MainAbility.errorInfo(1, ResUtils.getString(ability,ResourceTable.String_exception), this.exception, this.ability); -// } - } - } catch (Exception exception) { - LogUtils.e("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java deleted file mode 100644 index fbc8c448d92d8991b78b9ec2239d7f9ce6b44b66..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUnsubscribeAction extends HttpUIAction { - ForumPostConfig config; - - public HttpUnsubscribeAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.unsubscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java deleted file mode 100644 index ac1a1cf098bb18266254683efe8ae18bc65ae7e1..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeForumAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUnsubscribeForumAction extends HttpUIAction { - ForumConfig config; - - public HttpUnsubscribeForumAction(Ability Ability, ForumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.unsubscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeIssueAction.java deleted file mode 100644 index 391f004e2092e3ff61075edcb5d3d573a5443ecd..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUnsubscribeIssueAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUnsubscribeIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpUnsubscribeIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.unsubscribe(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java deleted file mode 100644 index 79d282bd8dce336d5eb41663866ae717bf3ad2cf..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpBotScriptAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpBotScriptAction extends HttpUIAction { - - ScriptSourceConfig config; - - public HttpUpBotScriptAction(Ability Ability, ScriptSourceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.upBotScript(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.script = this.config; - -// ((BotScriptsAbility)this.ability).resetView(); - - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateAction.java deleted file mode 100644 index a94f2d367c581cd3b11a6b76da9b7b7227161047..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateAction extends HttpUIAction { - WebMediumConfig config; - - public HttpUpdateAction(Ability Ability, WebMediumConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.instance = this.config; - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java deleted file mode 100644 index a90f1adb682f1e2fdc1c0db7a2ad8fed86e8c483..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateForumPostAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateForumPostAction extends HttpUIAction { - - ForumPostConfig config; - - public HttpUpdateForumPostAction(Ability Ability, ForumPostConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.post = this.config; - - this.ability.terminateAbility(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java deleted file mode 100644 index 98f115d9ab77b066b8c5e3c7eddbb993815cf8e0..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateIssueAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateIssueAction extends HttpUIAction { - - IssueConfig config; - - public HttpUpdateIssueAction(Ability Ability, IssueConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.issue = this.config; - - this.ability.terminateAbility(); - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java deleted file mode 100644 index 95f7c7f07734d25d71bfa9bf3df469d15b7acee4..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUpdateUserAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUpdateUserAction extends HttpUIAction { - UserConfig config; - - public HttpUpdateUserAction(Ability Ability, UserConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.connection.update(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.user = this.config; - - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java deleted file mode 100644 index 4f4193aedf526ac7cb28b298bc7c87066e2e78dd..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUploadGraphicMediaAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.GraphicConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUploadGraphicMediaAction extends HttpUIAction{ - - GraphicConfig config; - String file; - - public HttpUploadGraphicMediaAction(Ability Ability, String file, GraphicConfig config) { - super(Ability); - this.config = config; - this.file = file; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createGraphicMedia(this.file, this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - this.ability.terminateAbility(); - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - HttpRefreshAction refresh = new HttpRefreshAction(this.ability,config); - refresh.execute(); - } -} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java deleted file mode 100644 index dbdeb65e6948465c771f4e089a6cf259e39b58c5..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserAdminAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.UserAdminConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUserAdminAction extends HttpUIAction { - - UserAdminConfig config; - - public HttpUserAdminAction(Ability Ability, UserAdminConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.userAdmin(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } -// if (this.config.operation.equals("AddUser")) { -// ((WebMediumUsersAbility)this.ability).users.add(this.config.operationUser); -// } else if (this.config.operation.equals("RemoveUser")) { -// ((WebMediumUsersAbility)this.ability).users.remove(this.config.operationUser); -// } else if (this.config.operation.equals("AddAdmin")) { -// ((WebMediumUsersAbility)this.ability).admins.add(this.config.operationUser); -// } else if (this.config.operation.equals("RemoveAdmin")) { -// ((WebMediumUsersAbility)this.ability).admins.remove(this.config.operationUser); -// } -// TextField text = (TextField) this.ability.findComponentById(ResourceTable.Id_adminText); -// text.setText(""); -// text = (TextField) this.ability.findComponentById(ResourceTable.Id_userText); -// text.setText(""); -// ((WebMediumUsersAbility)this.ability).resetView(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserMessageAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserMessageAction.java deleted file mode 100644 index e455295af976c306d3d55f1210c889e6d3d238de..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/HttpUserMessageAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.UserMessageConfig; -import ohos.aafwk.ability.Ability; - -public class HttpUserMessageAction extends HttpAction { - - UserMessageConfig config; - - public HttpUserMessageAction(Ability Ability, UserMessageConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.connection.createUserMessage(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - /*AlertDialog dialog = new AlertDialog.Builder(Ability).create(); - dialog.setMessage("Chatlog sent."); - dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - Ability.finish(); - } - }); - dialog.show();*/ - } -} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java deleted file mode 100644 index 8c16391bfbac8c2821d5947a0314c81f267526de..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/activityy/actions/WarAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.activityy.actions; - -import org.botlibre.sdk.config.ChatResponse; - -public class WarAction extends HttpAction { - ChatResponse config; - - public WarAction(ohos.aafwk.ability.Ability Ability, ChatResponse config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - Thread.sleep(4000); - } catch (InterruptedException exception) {} - return ""; - } - - @Override - protected void onPostExecute(String xml) { -// ((WarAbility)this.ability).switchBots(); -// ((WarAbility)this.ability).submitChat(this.config.message); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index b39b01727624bff506417f57cedd360c9fc325b4..d998948edc540c7f36d5674994aeaf1f34f371ac 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java @@ -194,9 +194,15 @@ public class AvatarConfig extends WebMediumConfig { public void parseXML(Element element) { super.parseXML(element); } - + /** - * Find any media that match the emotion, action, and pose, or the best matches. + * debug + * + * @param emotion + * @param action + * @param pose + * @param pose2 + * @return list */ public List getMedia(String emotion, String action, String pose, String pose2) { if (emotion == null || emotion.isEmpty()) { @@ -458,9 +464,13 @@ public class AvatarConfig extends WebMediumConfig { } return matches; } - + /** - * Find an audio media that matches the action or pose. + * getAudio + * + * @param action + * @param pose + * @return list */ public List getAudio(String action, String pose) { if (action == null) { diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java deleted file mode 100644 index ea147c7ccf7671c82a510fdbf0dd1260ff151a24..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import org.botlibre.sdk.util.Utils; - -import java.io.StringWriter; - - -/** - * An avatar message can be used to have an avatar speak a message. - * The avatar message gives the avatar the text to speak, and returns a ChatResponse that includes the text-to-speech and video animation. - * This object can be converted to and from XML for usage with the web API. - */ -public class AvatarMessage extends Config { - public String message; - public String avatar; - public String emote; - public String action; - public String pose; - public boolean speak; - public String voice; - public String format; - public boolean hd; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java deleted file mode 100644 index d15bf0b7d816c5f7acbbfd47825aafc2da823c10..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; - - -/** - * DTO for XML bot mode config. - */ -public class BotModeConfig extends Config { - - public String mode; - public String bot; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mode = element.getAttribute("mode"); - this.bot = element.getAttribute("bot"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java deleted file mode 100644 index 603726b3d8e64309e24468a0abd14ed0ffc172b9..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * DTO for XML content config. - */ -public class ContentConfig extends Config { - - public String type; - public String name; - public String icon; - public String description; - - public void parseXML(Element element) { - super.parseXML(element); - - this.type = element.getAttribute("type"); - this.name = element.getAttribute("name"); - this.icon = element.getAttribute("icon"); - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java deleted file mode 100644 index a2008ffa53db7c08175f209af700c3e72be43d1f..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.botlibre.sdk.util.Utils; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - - -/** - * DTO for XML conversation config. - */ -public class ConversationConfig extends Config { - public String id; - public String creationDate; - public String type; - - public List input; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.type = element.getAttribute("type"); - - NodeList nodes = element.getElementsByTagName("input"); - if (nodes != null && nodes.getLength() > 0) { - this.input = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element node = (Element)nodes.item(index); - InputConfig config = new InputConfig(); - config.parseXML(node); - this.input.add(config); - } - } - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java index 715d6a73b07f58091066502685d41d31228bc219..5c2f8ec2484e3fcead083e350e1e2e1e0d549590 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java @@ -15,183 +15,167 @@ package org.botlibre.sdk.config; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.botlibre.sdk.util.Utils; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + /** * DTO for XML forum post config. */ -public class ForumPostConfig extends Config { - public String id; - public String topic; - public String summary; - public String details; - public String detailsText; - public String forum; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isFeatured; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String replyCount; - public String parent; - public String avatar; - public List replies; - - public boolean equals(Object object) { - if (object instanceof ForumPostConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((ForumPostConfig)object).id); - } - return false; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } +public class ForumPostConfig extends Config { + public String id; + public String topic; + public String summary; + public String details; + public String detailsText; + public String forum; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isFeatured; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String replyCount; + public String parent; + public String avatar; + public List replies; + + public boolean equals(Object object) { + if (object instanceof ForumPostConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((ForumPostConfig) object).id); + } + return false; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } + + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.topic != null) { + writer.write(""); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
    "); + writer.write("
    "); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.parent = element.getAttribute("parent"); + this.forum = element.getAttribute("forum"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.replyCount = element.getAttribute("replyCount"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.topic != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.topic)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
    "); - writer.write(Utils.escapeHTML(text)); - writer.write("
    "); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.parent = element.getAttribute("parent"); - this.forum = element.getAttribute("forum"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.replyCount = element.getAttribute("replyCount"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("topic").item(0); - if (node != null) { - this.topic = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - NodeList nodes = element.getElementsByTagName("replies"); - if (nodes != null && nodes.getLength() > 0) { - this.replies = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element reply = (Element)nodes.item(index); - ForumPostConfig config = new ForumPostConfig(); - config.parseXML(reply); - this.replies.add(config); - } - } - } - public ForumPostConfig credentials() { - ForumPostConfig config = new ForumPostConfig(); - config.id = this.id; - return config; - } + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("topic").item(0); + if (node != null) { + this.topic = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + NodeList nodes = element.getElementsByTagName("replies"); + if (nodes != null && nodes.getLength() > 0) { + this.replies = new ArrayList(); + for (int index = 0; index < nodes.getLength(); index++) { + Element reply = (Element) nodes.item(index); + ForumPostConfig config = new ForumPostConfig(); + config.parseXML(reply); + this.replies.add(config); + } + } + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public ForumPostConfig credentials() { + ForumPostConfig config = new ForumPostConfig(); + config.id = this.id; + return config; + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java deleted file mode 100644 index e65bb04805fb545001105d293f93ce0af2efbd45..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import org.botlibre.util.Utils; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - - -/** - * DTO for XML input config. - */ -public class InputConfig extends Config { - public String id; - public String creationDate; - public String speaker; - public String target; - public String value; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.speaker = element.getAttribute("speaker"); - this.target = element.getAttribute("target"); - - Node node = element.getElementsByTagName("value").item(0); - if (node != null) { - this.value = node.getTextContent(); - } - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTime(date); - } catch (Exception exception) { - return creationDate; - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java deleted file mode 100644 index 424935338607950fd57a2ebfd2fcd9749500b978..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import org.w3c.dom.Element; - -import java.io.StringWriter; - -/** - * DTO for XML issue tracker config. - */ -public class IssueTrackerConfig extends WebMediumConfig { - public String createAccessMode; - public String issues; - - public String getType() { - return "issuetracker"; - } - - @Override - public String stats() { - return this.issues + " issues"; - } - - public WebMediumConfig credentials() { - IssueTrackerConfig config = new IssueTrackerConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.createAccessMode = element.getAttribute("createAccessMode"); - this.issues = element.getAttribute("issues"); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java deleted file mode 100644 index 940cac71b62536ba171e43f09e56d7124613d0c6..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -/** - * DTO for XML response search options. - */ -public class ResponseSearchConfig extends Config { - public String responseType; - public String inputType; - public String filter; - public String duration; - public String restrict; - public String page; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java deleted file mode 100644 index b937640eb47c2ba88d695406159f72d97b68f0e6..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -/** - * A speech object can be used to invoke server-side text-to-speech. - * The object takes a message text, and a voice. - */ -public class Speech extends Config { - public String text; - public String voice; - public String mod; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java deleted file mode 100644 index 7352e1e29dd5d0967182152da94d08e9fd37c302..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import org.botlibre.util.Utils; - -import java.io.StringWriter; - - - -/** - * DTO for XML training config. - */ -public class TrainingConfig extends Config { - public String operation; - public String question; - public String response; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java deleted file mode 100644 index a8677318080b7468ecededc1f2b71c4121f3df5e..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; - - -/** - * DTO for XML user admin config. - */ -public class UserAdminConfig extends Config { - public String operation; - public String operationUser; - - public void parseXML(Element element) { - super.parseXML(element); - - this.operation = element.getAttribute("operation"); - this.operationUser = element.getAttribute("operationUser"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java index 38578b58704d3ad5fa5813f7078ba6c9edcd5601..885e8a63b0661ef12e76043ba4f9367767b54069 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java @@ -15,16 +15,12 @@ package org.botlibre.sdk.config; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - import org.botlibre.sdk.SDKConnection; -import org.botlibre.sdk.util.Utils; import org.w3c.dom.Element; import org.w3c.dom.Node; +import java.io.StringWriter; + /** * DTO for XML user creation config. */ @@ -56,27 +52,7 @@ public class UserConfig extends Config { public String type; public boolean isFlagged; public String flaggedReason; - - public String displayJoined() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(joined); - return Utils.displayDate(date); - } catch (Exception exception) { - return joined; - } - } - - public String displayLastConnect() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(lastConnect); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return lastConnect; - } - } - + public void addCredentials(SDKConnection connection) { this.application = connection.getCredentials().getApplicationId(); if (connection.getDomain() != null) { @@ -163,7 +139,6 @@ public class UserConfig extends Config { if (this.bio != null) { writer.write(""); - writer.write(Utils.escapeHTML(this.bio)); writer.write(""); } writer.write(""); diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java deleted file mode 100644 index 60a698640ceeaff7f39d75222a5b2264d16e5170..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/BootstrapAsync.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.micro; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.activityy.actions.HttpUIAction; -import org.botlibre.sdk.util.PreferencesUtils; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.ScriptConfig; -import org.botlibre.sdk.config.ScriptSourceConfig; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; -import org.botlibre.Bot; -import org.botlibre.api.knowledge.Network; -import org.botlibre.api.knowledge.Vertex; -import org.botlibre.api.sense.Sense; -import org.botlibre.knowledge.Bootstrap; -import org.botlibre.knowledge.Primitive; -import org.botlibre.knowledge.micro.MicroMemory; -import org.botlibre.self.SelfCompiler; -import org.botlibre.sense.http.Wiktionary; -import org.botlibre.sense.text.TextEntry; -import org.botlibre.thought.consciousness.Consciousness; -import org.botlibre.thought.language.Comprehension; -import org.botlibre.thought.language.Language; -import org.botlibre.thought.language.Language.LearningMode; - -/** - * Bootstrap the bot the first time from an online response list file or script. - */ -public class BootstrapAsync extends HttpUIAction { - public BootstrapAsync(Ability Ability) { - super(Ability); - } - - protected String aimlScriptId; - protected String selfScriptId; - protected String greetingScriptId; - InstanceConfig config; - MicroConnection connection; - Bot bot=null; - boolean noInternet = false; - - //passing InstanceConfig and the Scripts Versions. - public synchronized void bootstrapBot(InstanceConfig config, String aimlScriptId, String greetingScriptId) { - this.greetingScriptId = greetingScriptId; - this.aimlScriptId = aimlScriptId; - this.config = config; - this.execute(); - } - - protected boolean isResetRequired() { - // Check if bot memory exists. - if (!MicroMemory.checkExists()) { - return true; - } - try{ - // Check if version is changed. - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.current); - String aimlVersion = cookies.getString(this.aimlScriptId, null); - String greetingVersion = cookies.getString(this.greetingScriptId, null); - if (aimlVersion == null || aimlVersion.isEmpty() || greetingVersion == null || greetingVersion.isEmpty()) { - return true; - } - ScriptConfig aimlScript = new ScriptConfig(); - aimlScript.id = this.aimlScriptId; - aimlScript = MainAbility.connection.fetch(aimlScript); - if (!aimlVersion.equals(aimlScript.version)) { - return true; - } - ScriptConfig greetingScript = new ScriptConfig(); - greetingScript.id = this.greetingScriptId; - greetingScript = MainAbility.connection.fetch(greetingScript); - if (!greetingVersion.equals(greetingScript.version)) { - return true; - } - } catch (Exception ignore) { - return false; - } - return false; - } - - @Override - protected String doInBackground(Void... params) { - try { - MicroMemory.storageFileName = this.config.id; - this.connection = (MicroConnection) MainAbility.connection; - // Check if bot is already loaded first. - if (connection.getBot(this.config.id) != null) { - return ""; - } - // Check if bot memory exists. - boolean resetRequired = isResetRequired(); - - // If no reset is required, just load the bot. - if (!resetRequired) { - try { - this.bot = Bot.createInstance(Bot.CONFIG_FILE, this.config.id, true); - Language language = bot.mind().getThought(Language.class); - language.setLearningMode(LearningMode.Disabled); - language.setLearnGrammar(false); - Comprehension comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - Consciousness consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - Sense sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - } catch (Exception failed) { - // If the load fails, then reset the bot. - resetRequired = true; - } - } - // If a reset is required the bot must be rebuilt from scratch and reimport the AIML and greeting files. - if (resetRequired) { - // Delete the old file if exists. - MicroMemory.reset(); - // Fetch the scripts source code. - ScriptConfig aimlScript = new ScriptConfig(); - aimlScript.id = this.aimlScriptId; - ScriptSourceConfig aimlSource = connection.getScriptSource(aimlScript); - ScriptConfig greetingScript = new ScriptConfig(); - greetingScript.id = this.greetingScriptId; - ScriptSourceConfig greetingSource = connection.getScriptSource(greetingScript); - - MicroMemory.reset(); - // Create new bot. - bot = Bot.createInstance(Bot.CONFIG_FILE, this.config.id, true); - Language language = bot.mind().getThought(Language.class); - language.setLearningMode(LearningMode.Disabled); - language.setLearnGrammar(false); - Comprehension comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - Consciousness consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - Sense sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - //if bootstrapSystem was true, it will load the default script. - // Do not need to bootstrap, as only uses AIML. - new Bootstrap().bootstrapSystem(bot, false); - // Load AIML file. - language.loadAIML(aimlSource.source, "ami", true, false, false); - // Load greeting response list. - bot.awareness().getSense(TextEntry.class).loadChat(greetingSource.source, "Response List", false, true); - - // Shutdown will save the file. - bot.shutdown(); - // Reload the bot from the file. - bot = Bot.createInstance(Bot.CONFIG_FILE, this.config.id, true); - language = bot.mind().getThought(Language.class); - language.setLearningMode(LearningMode.Disabled); - language.setLearnGrammar(false); - comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.current); - cookies.putString(this.aimlScriptId, aimlSource.versionName); - cookies.putString(this.greetingScriptId, greetingSource.versionName); - cookies.flush(); - } - // Finally, add the bot to the connections active bots. - connection.addBot(this.config.id, bot); - } catch (Exception exception) { - noInternet = true; -// MicroMemory.reset(); - return null; - } - return null; - } - - /** - * Load, compile, and add the state machine from the Self source code. - */ - public void loadSelf(Bot bot, String text) { - - Network network = bot.memory().newMemory(); - Vertex language = network.createVertex(bot.mind().getThought(Language.class).getPrimitive()); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(text, false, network); - SelfCompiler.getCompiler().pin(stateMachine); - language.addRelationship(Primitive.STATE, stateMachine); - network.save(); - } - - @Override - protected void onPostExecute(String result) { - super.onPostExecute(result); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java index 623381f93a8aee66f239d2a7091e2c5aca363a64..a183e1306868ef0b0297301a572b6173d4419be1 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/micro/MicroConnection.java @@ -15,251 +15,80 @@ package org.botlibre.sdk.micro; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - +import org.botlibre.Bot; +import org.botlibre.knowledge.micro.MicroMemory; import org.botlibre.sdk.Credentials; import org.botlibre.sdk.SDKConnection; -import org.botlibre.sdk.SDKException; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.VoiceConfig; import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.Bot; -import org.botlibre.api.knowledge.Network; -import org.botlibre.api.knowledge.Vertex; -import org.botlibre.api.sense.Sense; -import org.botlibre.knowledge.Bootstrap; -import org.botlibre.knowledge.Primitive; -import org.botlibre.knowledge.micro.MicroMemory; -import org.botlibre.self.SelfCompiler; -import org.botlibre.sense.http.Wiktionary; -import org.botlibre.sense.text.TextEntry; -import org.botlibre.sense.text.TextInput; import org.botlibre.sense.text.TextListener; import org.botlibre.sense.text.TextOutput; -import org.botlibre.thought.consciousness.Consciousness; -import org.botlibre.thought.language.Comprehension; -import org.botlibre.thought.language.Language; -import org.botlibre.thought.language.Language.LearningMode; + +import java.util.HashMap; +import java.util.Map; + /** - * The MicroConnection replaces the normal SDK remote connection with one that creates - * and accessed bots locally. + * HttpConnectAction + * + * @since 2021-04-16 */ public class MicroConnection extends SDKConnection implements TextListener { - private WebMediumConfig config; - protected Map activeBots = new HashMap(); - public static AvatarConfig avatarConfig; - public TextOutput message; - public static Bot bot; - - /** - * Create a micro/offline SDK connection. - */ - public MicroConnection() { - } - - /** - * Create a micro/offline SDK connection. - * Use the credentials to enable online support. - */ - public MicroConnection(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - public void addBot(String id, Bot bot) { - activeBots.put(id, bot); - } - - public Bot getBot(String id) { - return activeBots.get(id); - } - - public static Bot getBot() { - return bot; - } - - /** - * Process the bot chat message and return the bot's response. - * The ChatConfig should contain the conversation id if part of a conversation. - * If a new conversation the conversation id is returned in the response. - */ - public synchronized ChatResponse chat(ChatConfig config) { - if (config.instance == null) { - config.instance = "default"; - } - // this method will return a Bot with the default instance - Bot bot = getBot(this.config.id); - try { - int i = 0; - while (i <= 4) { - if (bot == null) { - wait(1000); - bot = this.activeBots.get(config.instance); - } else if (bot != null) { - break; - } - i++; - } - } catch (Exception e) {} - - if (bot == null) { - this.exception = new SDKException("Bot doesn't exists!"); - throw this.exception; - } - - TextEntry sense = bot.awareness().getSense(TextEntry.class); - // setting the user admin for the BOT. - sense.setUser(reInitialize(bot)); - bot.setFilterProfanity(false); - - sense.setTextListener(this); - this.message = null; - TextInput textInput = new TextInput(config.message); - textInput.setCorrection(config.correction); - textInput.setOffended(config.offensive); - - sense.input(textInput); - ChatResponse response = new ChatResponse(); - - try { - if (this.message == null) { - wait(5000); - } - if (this.message != null) { - response.message = this.message.getMessage(); - response.command = bot.avatar().getCommand(); - try { - avatarConfig.chatReply(response); - } catch (Exception e) { - } - } - } catch (InterruptedException exception) { - this.exception = new SDKException("Timeout waiting for response"); - throw this.exception; - } - return response; - } - - /** - * Fetch the local object. - */ - public T fetch(T config) { - this.config = config; - MicroMemory.storageFileName = config.name; - int id = Integer.parseInt(config.id); -// bot = loadBot(config.name, id); -// addBot(config.id, bot); - if(!(config instanceof InstanceConfig)){ - return super.fetch(config); - } - return config; - } - - /** - * Return the bot's voice configuration. - */ - public VoiceConfig getVoice(InstanceConfig config) { - VoiceConfig voice = new VoiceConfig(); - voice.nativeVoice = true; - voice.language = "en"; - return voice; - } - - public synchronized void sendMessage(TextOutput message) { - this.message = message; - notifyAll(); - } - - public synchronized Bot loadBot(String name, int id) { - boolean exists = MicroMemory.checkExists(); - Bot.CONFIG_FILE = "config.xml"; - Bot bot = Bot.createInstance(Bot.CONFIG_FILE, name, true); - bot.setName(name); - - Language language = bot.mind().getThought(Language.class); - language.setLearnGrammar(false); - //if (id != 2) { - language.setLearningMode(LearningMode.Disabled); - Comprehension comprehension = bot.mind().getThought(Comprehension.class); - comprehension.setEnabled(false); - Consciousness consciousness = bot.mind().getThought(Consciousness.class); - consciousness.setEnabled(false); - Sense sense = bot.awareness().getSense(Wiktionary.class); - sense.setIsEnabled(false); - //} - - if (!exists) { - try { - new Bootstrap().bootstrapSystem(bot, false); - loadResScript(bot, "/assets/servicebot.res"); - loadResScript(bot, "/assets/farewells.res"); - loadResScript(bot, "/assets/pizza.res"); - loadSelfScript(bot, "/assets/pizza.self"); - bot.memory().shutdown(); - } catch (Exception exception) { - } - } - return bot; - } - - public void loadAIMLScript(Language lang,InputStream source){ - lang.loadAIMLFile(source, config.id, false, false, true,"",10000000); - } - - public void loadResScript(Bot bot, String fileName) { - URL url = getClass().getResource(fileName); - bot.awareness().getSense(TextEntry.class).loadChatFile(url, "Response List", "", false, true); - } - - public void loadResScript(Bot bot, File file) { - bot.awareness().getSense(TextEntry.class).loadChatFile(file, "Response List", "", false, true); - } - - public void loadSelfScript(Bot bot, String fileName) { - loadSelfScript(bot, getClass().getResource(fileName)); - } - - public void loadSelfScript(Bot bot, URL url) { - Network network = bot.memory().getShortTermMemory(); - Vertex language = network.createVertex(new Primitive(Language.class.getName())); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(url, "", false, network); - language.addRelationship(Primitive.STATE, stateMachine); - SelfCompiler.getCompiler().pin(stateMachine); - } - - public void loadSelfScript(Bot bot, File file) { - Network network = bot.memory().getShortTermMemory(); - Vertex language = network.createVertex(new Primitive(Language.class.getName())); - SelfCompiler compiler = SelfCompiler.getCompiler(); - Vertex stateMachine = compiler.parseStateMachine(file, "", false, network); - language.addRelationship(Primitive.STATE, stateMachine); - SelfCompiler.getCompiler().pin(stateMachine); - } - - public void renameMemory(Bot bot, String name) { - bot.memory().getShortTermMemory().createVertex(Primitive.SELF).addRelationship(Primitive.NAME, bot.memory().getShortTermMemory().createVertex(name)); - - } - - public Vertex reInitialize(Bot bot) { - Network memory = bot.memory().newMemory(); - Vertex user = memory.createSpeaker("Admin"); - user.addRelationship(Primitive.ASSOCIATE, Primitive.ADMINISTRATOR); - memory.save(); - return user; - } - - public static void copyStream(InputStream input) throws IOException { - - } + private WebMediumConfig config; + protected Map activeBots = new HashMap(); + /** + * message + */ + public TextOutput message; + /** + * bot + */ + public static Bot bot; + + /** + * Create a micro/offline SDK connection. + */ + public MicroConnection() { + } + + /** + * Create a micro/offline SDK connection. + * Use the credentials to enable online support. + * + * @param credentials + */ + public MicroConnection(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + public static Bot getBot() { + return bot; + } + + /** + * Fetch the local object. + * + * @param web + * @param config + * @return config + */ + public T fetch(T config) { + this.config = config; + MicroMemory.storageFileName = config.name; + if (!(config instanceof InstanceConfig)) { + return super.fetch(config); + } + return config; + } + + /** + * reInitialize + * + * @param message + */ + public void sendMessage(TextOutput message) { + this.message = message; + notifyAll(); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java index 3ed63fe8672c0d7adc97c3e956a8c65034deb75e..418951e5857fd1fbe0d6beb5f9c19a65b265df3b 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/provider/ChatListProvicer.java @@ -23,7 +23,11 @@ import ohos.agp.components.*; import java.util.List; - +/** + * HttpConnectAction + * + * @since 2021-04-16 + */ public class ChatListProvicer extends BaseItemProvider { private List list; diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/slice/MainAbilitySlice.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/slice/MainAbilitySlice.java deleted file mode 100644 index c89b43d68c7ca899588c9d3745206ef8f209ab12..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/slice/MainAbilitySlice.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.slice; - -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.ResourceTable; -import ohos.aafwk.ability.AbilitySlice; -import ohos.aafwk.content.Intent; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.dialog.IDialog; - -public class MainAbilitySlice extends AbilitySlice { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_main); - } - - @Override - public void onActive() { - super.onActive(); - } - - @Override - public void onForeground(Intent intent) { - super.onForeground(intent); - } - - - public static void showMessage(String title, String message, AbilitySlice Ability) { - try { - CommonDialog dialog = new CommonDialog(Ability); - dialog.setContentText(message); - if (title != null) { - dialog.setTitleText(title); - } - dialog.setButton(CommonDialog.BUTTON1, "OK", new IDialog.ClickedListener() { - @Override - public void onClick(IDialog iDialog, int i) { - } - }); - dialog.show(); - } catch (Exception exception) { - LogUtils.e("showMessage", exception.toString()); - } - } - - public static void showMessage(String message, AbilitySlice Ability) { - showMessage(null, message, Ability); - } -} diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/Utils.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/Utils.java deleted file mode 100644 index 1ef3aaa11962b8903118169f7ab94c934d6208ff..0000000000000000000000000000000000000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/Utils.java +++ /dev/null @@ -1,514 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain an copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.util; - -import org.botlibre.BotException; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Random; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -/** - * Utility class. - */ -public class Utils { - public static Random random = new Random(); - - public static Pattern httpRegex = Pattern.compile("\\b(?:https?|ftp|file):\\/\\/[a-z0-9-+&@#\\/%?=~_|!:,.;]*[a-z0-9-+&@#\\/%=~_|]", Pattern.CASE_INSENSITIVE); - public static Pattern wwwRegex = Pattern.compile("((www\\.)[^\\s]+)", Pattern.CASE_INSENSITIVE); - public static Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); - - /** - * Replace links with HTML links. - * Includes http, www, images, video, audio, email address. - */ - public static String linkHTML(String text) { - if (text == null || text.length() == 0) { - return ""; - } - boolean http = text.indexOf("http") != -1; - boolean www = text.indexOf("www.") != -1; - boolean email = text.indexOf("@") != -1; - if (!http && !www && !email) { - return text; - } - if (text.indexOf("<") != -1 && text.indexOf(">") != -1) { - return text; - } - if (http) { - Matcher matcher = httpRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - if (url.indexOf(".png") != -1 || url.indexOf(".jpg") != -1 || url.indexOf(".jpeg") != -1 || url.indexOf(".gif") != -1) { - url = ""; - } else if (url.indexOf(".mp4") != -1 || url.indexOf(".webm") != -1 || url.indexOf(".ogg") != -1) { - url = ""; - } else if (url.indexOf(".wav") != -1 || url.indexOf(".mp3") != -1) { - url = ""; - } else { - url = "" + url + ""; - } - matcher.appendReplacement(sb, url); - } - matcher.appendTail(sb); - text = sb.toString(); - } else if (www) { - Matcher matcher = wwwRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - matcher.appendReplacement(sb, "" + url + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - - if (email) { - Matcher matcher = emailRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String address = matcher.group(); - matcher.appendReplacement(sb, "" + address + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - return text; - } - - - /** - * Replace reserved HTML character with their HTML escape codes. - */ - public static String escapeHTML(String html) { - return html.replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """) - .replace("`", "`") - .replace("'", "'"); - } - - /** - * Strip the HTML tags from the text. - */ - public static String stripTags(String html) { - if (html == null) { - return ""; - } - String result = html; - if ((html.indexOf('<') != -1) && (html.indexOf('>') != -1)) { - StringWriter writer = new StringWriter(); - TextStream stream = new TextStream(html); - while (!stream.atEnd()) { - String text = stream.upTo('<'); - writer.write(text); - int position = stream.getPosition(); - stream.skip(); - String word = stream.nextWord(); - if (word != null) { - if (word.equals("p")) { - writer.write("\n\n"); - } else if (word.equals("br")) { - writer.write("\n"); - } else if (word.equals("div")) { - writer.write("\n"); - } - stream.skipTo('>'); - if (stream.atEnd()) { - stream.setPosition(position); - writer.write(stream.upToEnd()); - } else { - stream.skip(); - } - } - } - result = writer.toString(); - } - if (result.contains("&")) { - result = result.replace(""", "\""); - result = result.replace("`", "`"); - result = result.replace("'", "'"); - result = result.replace("@", "@"); - result = result.replace("=", "="); - result = result.replace("<", "<"); - result = result.replace(">", ">"); - } - return result; - } - - /** - * Format the text that may be HTML, or may be text, or markup, or a mix. - */ - public static String formatHTMLOutput(String text) { - if (text == null) { - return ""; - } - int index = text.indexOf('<'); - int index2 = text.indexOf('>'); - boolean isHTML = (index != -1) && (index2 > index); - boolean isMixed = isHTML && text.contains("[code]"); - if (isHTML && !isMixed) { - return text; - } - if (!isMixed && ((index != -1) || (index2 != -1))) { - text = text.replace("<", "<"); - text = text.replace(">", ">"); - } - TextStream stream = new TextStream(text); - StringWriter writer = new StringWriter(); - boolean bullet = false; - boolean nbullet = false; - while (!stream.atEnd()) { - String line = stream.nextLine(); - if (!isMixed && (line.contains("http://") || line.contains("https://"))) { - line = Utils.linkHTML(line); - } - TextStream lineStream = new TextStream(line); - boolean firstWord = true; - boolean span = false; - boolean cr = true; - while (!lineStream.atEnd()) { - while (!isMixed && firstWord && lineStream.peek() == ' ') { - lineStream.next(); - writer.write(" "); - } - String whitespace = lineStream.nextWhitespace(); - writer.write(whitespace); - if (lineStream.atEnd()) { - break; - } - String word = lineStream.nextWord(); - if (!isMixed && nbullet && firstWord && !word.equals("#")) { - writer.write("\n"); - nbullet = false; - } else if (!isMixed && bullet && firstWord && !word.equals("*")) { - writer.write("\n"); - bullet = false; - } - if (firstWord && word.equals("[")) { - String peek = lineStream.peekWord(); - if ("code".equals(peek)) { - lineStream.nextWord(); - String next = lineStream.nextWord(); - String lang = "javascript"; - int lines = 20; - if ("lang".equals(next)) { - lineStream.skip(); - lang = lineStream.nextWord(); - if ("\"".equals(lang)) { - lang = lineStream.nextWord(); - lineStream.skip(); - } - next = lineStream.nextWord(); - } - if ("lines".equals(next)) { - lineStream.skip(); - String value = lineStream.nextWord(); - if ("\"".equals(value)) { - value = lineStream.nextWord(); - lineStream.skip(); - } - lineStream.skip(); - try { - lines = Integer.valueOf(value); - } catch (NumberFormatException ignore) {} - } - String id = "code" + stream.getPosition(); - writer.write("
    "); - String code = lineStream.upToAll("[code]"); - if (code.indexOf('<') != -1) { - code = code.replace("<", "<"); - } - if (code.indexOf('>') != -1) { - code = code.replace(">", ">"); - } - writer.write(code); - while (lineStream.atEnd() && !stream.atEnd()) { - line = stream.nextLine(); - lineStream = new TextStream(line); - while (lineStream.peek() == ':') { - lineStream.next(); - writer.write("    "); - } - code = lineStream.upToAll("[code]"); - if (code.indexOf('<') != -1) { - code = code.replace("<", "<"); - } - if (code.indexOf('>') != -1) { - code = code.replace(">", ">"); - } - writer.write(code); - } - lineStream.skip("[code]".length()); - writer.write("
    \n"); - - writer.write("\n"); - } else { - writer.write(word); - } - } else if (!isMixed && firstWord && word.equals("=")) { - int count = 2; - String token = word; - while (!lineStream.atEnd() && lineStream.peek() == '=') { - lineStream.skip(); - count++; - token = token + "="; - } - String header = lineStream.upToAll(token); - if (lineStream.atEnd()) { - writer.write(token); - writer.write(header); - } else { - lineStream.skip(token.length()); - writer.write(""); - writer.write(header); - writer.write(""); - cr = false; - } - } else if (!isMixed && firstWord && word.equals(":")) { - span = true; - int indent = 1; - while (!lineStream.atEnd() && lineStream.peek() == ':') { - lineStream.skip(); - indent++; - } - writer.write(""); - } else if (!isMixed && firstWord && word.equals("*")) { - if (!bullet) { - writer.write("
      "); - bullet = true; - } - writer.write("
    • "); - cr = false; - } else if (!isMixed && firstWord && word.equals("#")) { - if (!nbullet) { - writer.write("
        "); - nbullet = true; - } - writer.write("
      1. "); - cr = false; - } else { - writer.write(word); - } - firstWord = false; - } - if (!isMixed && span) { - writer.write(""); - } - if (!isMixed && cr) { - writer.write("
        \n"); - } - } - if (!isMixed && bullet) { - writer.write("
    "); - } - if (!isMixed && nbullet) { - writer.write(""); - } - return writer.toString(); - } - - public static String displayTimestamp(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - writer.write(", "); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - - return writer.toString(); - } - - public static String displayTime(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - writer.write(":"); - if (calendar.get(Calendar.SECOND) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.SECOND))); - - return writer.toString(); - } - - public static String displayDate(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - - return writer.toString(); - } - - /** - * Capitalize the first character of the string. - */ - public static String capitalize(String text) { - if (text.length() == 0) { - return text; - } - return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); - } - - public static Random random() { - return random; - } - - public static int random(int max) { - return random().nextInt(max); - } - - public static T random(List list) { - if ((list == null) || list.isEmpty()) { - return null; - } - return list.get(random().nextInt(list.size())); - } - /** - * Get the contents of the stream to a .self file and parse it. - */ - public static String loadTextFile(InputStream stream, String encoding, int maxSize, boolean finish) { - if (encoding.trim().isEmpty()) { - encoding = "UTF-8"; - } - - // FEFF because this is the Unicode char represented by the UTF-8 byte order mark (EF BB BF). - String UTF8_BOM = "\uFEFF"; - - StringWriter writer = new StringWriter(); - InputStreamReader reader = null; - try { - reader = new InputStreamReader(stream, encoding); - int size = 0; - int next = reader.read(); - boolean first = true; - while (next >= 0) { - if (first && next == UTF8_BOM.charAt(0)) { - // skip - } else { - writer.write(next); - } - next = reader.read(); - if (size > maxSize) { - throw new BotException("File size limit exceeded: " + size + " > " + maxSize + " token: " + next); - } - size++; - } - } catch (IOException exception) { - throw new BotException("IO Error: " + exception.getMessage(), exception); - } finally { - if (reader != null && finish) { - try { - reader.close(); - } catch (IOException ignore) {} - } - if (stream != null && finish) { - try { - stream.close(); - } catch (IOException ignore) {} - } - } - return writer.toString(); - } - - public static T random(Collection collection) { - if ((collection == null) || collection.isEmpty()) { - return null; - } - int value = random().nextInt(collection.size()); - int index = 0; - for (T element : collection) { - if (index == value) { - return element; - } - index++; - } - return null; - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/resources/base/layout/activity_chat.xml b/PizzaBotOffline/entry/src/main/resources/base/layout/ability_chat.xml similarity index 99% rename from PizzaBotOffline/entry/src/main/resources/base/layout/activity_chat.xml rename to PizzaBotOffline/entry/src/main/resources/base/layout/ability_chat.xml index d64dedb4648323df0c3db2e30945b05df444b858..31fb652344cf158f0e215e115ac6d38c8d02279d 100644 --- a/PizzaBotOffline/entry/src/main/resources/base/layout/activity_chat.xml +++ b/PizzaBotOffline/entry/src/main/resources/base/layout/ability_chat.xml @@ -1,7 +1,7 @@ + + +