/shell/src/com/google/marvin/shell/AppInfo.java
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 17package com.google.marvin.shell; 18 19import android.content.pm.ResolveInfo; 20 21/** 22 * Class for encapsulating the information needed to start up an application 23 * 24 * @author clchen@google.com (Charles L. Chen) 25 * @author credo@google.com (Tim Credo) 26 */ 27public class AppInfo implements Comparable<AppInfo> { 28 private String title; 29 30 private String packageName; 31 32 private String className; 33 34 AppInfo(String appTitle, String appPackageName, String appClassName) { 35 title = appTitle; 36 packageName = appPackageName; 37 className = appClassName; 38 } 39 40 AppInfo(String appTitle, ResolveInfo info) { 41 title = appTitle; 42 packageName = info.activityInfo.packageName; 43 className = info.activityInfo.name; 44 } 45 46 public String getTitle() { 47 return title; 48 } 49 50 public String getPackageName() { 51 return packageName; 52 } 53 54 public String getClassName() { 55 return className; 56 } 57 58 @Override 59 public int compareTo(AppInfo o) { 60 String title0 = this.getTitle().toLowerCase(); 61 String title1 = o.getTitle().toLowerCase(); 62 return title0.compareTo(title1); 63 } 64 65 /** 66 * Returns a String xml representation of this appInfo element. 67 * 68 * @return String xml representation of this appInfo object 69 */ 70 public String toXml() { 71 StringBuilder xmlBuilder = new StringBuilder(); 72 xmlBuilder.append("<appInfo"); 73 if (addToXml(getPackageName())) { 74 xmlBuilder.append(" package='" + MenuManager.escapeEntities(getPackageName()) + "'"); 75 } 76 if (addToXml(getClassName())) { 77 xmlBuilder.append(" class='" + MenuManager.escapeEntities(getClassName()) + "'"); 78 } 79 xmlBuilder.append("/>\n"); 80 return xmlBuilder.toString(); 81 } 82 83 private boolean addToXml(String str) { 84 return ((null != str) && (str.length() > 0)); 85 } 86}