Skip to content

Instantly share code, notes, and snippets.

@isis
Created April 10, 2012 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isis/2355601 to your computer and use it in GitHub Desktop.
Save isis/2355601 to your computer and use it in GitHub Desktop.
main module class of Applist Module for Titanium mobile
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var applist = require('jp.isisredirect.applist');
var apps = applist.getApplist();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff'
});
var data = [];
for(var i = 0; i < apps.length; ++i) {
var labelapp = Titanium.UI.createLabel({
color : '#000',
text : apps[i],
font : {
fontSize : 20,
fontFamily : 'Helvetica Neue'
},
textAlign : 'left',
top : 7,
left : 60,
width : 'auto'
});
var row = Ti.UI.createTableViewRow({
className : "NomalCell",
height : 60
});
row.add(labelapp);
data.push(row);
}
var table = Titanium.UI.createTableView({
data : data
});
win1.add(table);
in1.open();
/**
*/
package jp.isisredirect.applist;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import java.util.List;
import java.util.ArrayList;
@Kroll.module(name = "Applist", id = "jp.isisredirect.applist")
public class ApplistModule extends KrollModule {
// Standard Debugging variables
private static final String LCAT = "ApplistModule";
private static final boolean DBG = TiConfig.LOGD;
// You can define constants with @Kroll.constant, for example:
// @Kroll.constant public static final String EXTERNAL_NAME = value;
public ApplistModule() {
super();
}
@Kroll.onAppCreate
public static void onAppCreate(TiApplication app) {
Log.d(LCAT, "inside onAppCreate");
// put module init code that needs to run when the application is
// created
}
// Methods
@Kroll.method
public Object[] getApplist() {
PackageManager packageManager = getActivity().getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appInfo = packageManager.queryIntentActivities(
intent, 0);
List<String> applist = new ArrayList<String>();
if (appInfo != null) {
for (ResolveInfo app : appInfo) {
applist.add(app.loadLabel(packageManager).toString());
}
}
return applist.toArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment