/shell/src/com/google/marvin/shell/AppInfo.java

http://eyes-free.googlecode.com/ · Java · 86 lines · 47 code · 13 blank · 26 comment · 4 complexity · 25ba7135c6bad2027c0ebaab9caccde3 MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.marvin.shell;
  17. import android.content.pm.ResolveInfo;
  18. /**
  19. * Class for encapsulating the information needed to start up an application
  20. *
  21. * @author clchen@google.com (Charles L. Chen)
  22. * @author credo@google.com (Tim Credo)
  23. */
  24. public class AppInfo implements Comparable<AppInfo> {
  25. private String title;
  26. private String packageName;
  27. private String className;
  28. AppInfo(String appTitle, String appPackageName, String appClassName) {
  29. title = appTitle;
  30. packageName = appPackageName;
  31. className = appClassName;
  32. }
  33. AppInfo(String appTitle, ResolveInfo info) {
  34. title = appTitle;
  35. packageName = info.activityInfo.packageName;
  36. className = info.activityInfo.name;
  37. }
  38. public String getTitle() {
  39. return title;
  40. }
  41. public String getPackageName() {
  42. return packageName;
  43. }
  44. public String getClassName() {
  45. return className;
  46. }
  47. @Override
  48. public int compareTo(AppInfo o) {
  49. String title0 = this.getTitle().toLowerCase();
  50. String title1 = o.getTitle().toLowerCase();
  51. return title0.compareTo(title1);
  52. }
  53. /**
  54. * Returns a String xml representation of this appInfo element.
  55. *
  56. * @return String xml representation of this appInfo object
  57. */
  58. public String toXml() {
  59. StringBuilder xmlBuilder = new StringBuilder();
  60. xmlBuilder.append("<appInfo");
  61. if (addToXml(getPackageName())) {
  62. xmlBuilder.append(" package='" + MenuManager.escapeEntities(getPackageName()) + "'");
  63. }
  64. if (addToXml(getClassName())) {
  65. xmlBuilder.append(" class='" + MenuManager.escapeEntities(getClassName()) + "'");
  66. }
  67. xmlBuilder.append("/>\n");
  68. return xmlBuilder.toString();
  69. }
  70. private boolean addToXml(String str) {
  71. return ((null != str) && (str.length() > 0));
  72. }
  73. }