/**
* Returns a unique instance of the ViewServer. This method should only be called from the main thread of your application. The server will have the same lifetime as your process. If your application does not have the <code>android:debuggable</code> flag set in its manifest, the server returned by this method will be a dummy object that does not do anything. This allows you to use the same code in debug and release versions of your application.
* @param context A Context used to check whether the application is debuggable, this can be the application context
*/
public static ViewServer get(Context context){
ApplicationInfo info=context.getApplicationInfo();
if (BUILD_TYPE_USER.equals(Build.TYPE) && (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
if (sServer == null) {
sServer=new ViewServer(ViewServer.VIEW_SERVER_DEFAULT_PORT);
}
if (!sServer.isRunning()) {
try {
sServer.start();
}
catch ( IOException e) {
Log.d("LocalViewServer","Error:",e);
}
}
}
else {
sServer=new NoopViewServer();
}
return sServer;
}

Example 31

From project CheckIn4Me, under directory /src/com/davidivins/checkin4me/core/.

/**
* Returns a unique instance of the ViewServer. This method should only be called from the main thread of your application. The server will have the same lifetime as your process. If your application does not have the <code>android:debuggable</code> flag set in its manifest, the server returned by this method will be a dummy object that does not do anything. This allows you to use the same code in debug and release versions of your application.
* @param context A Context used to check whether the application isdebuggable, this can be the application context
*/
public static ViewServer get(Context context){
ApplicationInfo info=context.getApplicationInfo();
if (BUILD_TYPE_USER.equals(Build.TYPE) && (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
if (sServer == null) {
sServer=new ViewServer(ViewServer.VIEW_SERVER_DEFAULT_PORT);
}
if (!sServer.isRunning()) {
try {
sServer.start();
}
catch ( IOException e) {
Log.d("LocalViewServer","Error:",e);
}
}
}
else {
sServer=new NoopViewServer();
}
return sServer;
}

Example 38

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

/**
* This is where the bulk of our work is done. This function is called in a background thread and should generate a new set of data to be published by the loader.
*/
@Override public List<AppEntry> loadInBackground(){
List<ApplicationInfo> apps=mPm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
if (apps == null) {
apps=new ArrayList<ApplicationInfo>();
}
final Context context=getContext();
List<AppEntry> entries=new ArrayList<AppEntry>(apps.size());
for (int i=0; i < apps.size(); i++) {
AppEntry entry=new AppEntry(this,apps.get(i));
entry.loadLabel(context);
entries.add(entry);
}
Collections.sort(entries,ALPHA_COMPARATOR);
return entries;
}

Example 51

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/compat/.

/**
* This is where the bulk of our work is done. This function is called in a background thread and should generate a new set of data to be published by the loader.
*/
@Override public List<AppEntry> loadInBackground(){
List<ApplicationInfo> apps=mPm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
if (apps == null) {
apps=new ArrayList<ApplicationInfo>();
}
final Context context=getContext();
List<AppEntry> entries=new ArrayList<AppEntry>(apps.size());
for (int i=0; i < apps.size(); i++) {
AppEntry entry=new AppEntry(this,apps.get(i));
entry.loadLabel(context);
entries.add(entry);
}
Collections.sort(entries,ALPHA_COMPARATOR);
return entries;
}

Example 60

From project google-voice-tasker-plugin, under directory /src/com/ko/googlevoice/.

/**
* Best {@link ResolveInfo} when multiple found. Ties are broken byselecting first from the {@link QuickContactActivity#sPreferResolve} list ofpreferred packages, second by apps that live on the system partition, otherwise the app from the top of the list. This is <strong>only</strong> used for selecting a default icon for displaying in the track, and does not shortcut the system {@link Intent} disambiguation dialog.
*/
protected ResolveInfo getBestResolve(Intent intent,List<ResolveInfo> matches){
final ResolveInfo foundResolve=mPackageManager.resolveActivity(intent,PackageManager.MATCH_DEFAULT_ONLY);
final boolean foundDisambig=(foundResolve.match & IntentFilter.MATCH_CATEGORY_MASK) == 0;
if (!foundDisambig) {
return foundResolve;
}
ResolveInfo firstSystem=null;
for ( ResolveInfo info : matches) {
final boolean isSystem=(info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
final boolean isPrefer=sPreferResolve.contains(info.activityInfo.applicationInfo.packageName);
if (isPrefer) return info;
if (isSystem && firstSystem == null) firstSystem=info;
}
return firstSystem != null ? firstSystem : matches.get(0);
}

Example 71

From project Playlist, under directory /src/com/google/zxing/client/android/share/.