예제 #1
0
def test_GettersAndSetters():
    categories = set([Intent.CATEGORY_DEFAULT, Intent.CATEGORY_LAUNCHER])
    intent = Intent.Intent(Intent.ACTION_MAIN)
    intent.setPackage('com.example.app')
    map(intent.addCategory, categories)
    intent.setDataAndTypeAndNormalize(
        Uri.parse('content://com.example.app/users/1'), "text/x-vCard")
    intent.setComponent(ComponentName('package.name', 'class.name'))
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                    | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
    assert intent.getAction() == Intent.ACTION_MAIN
    assert intent.getPackage() == 'com.example.app'
    assert all(map(intent.hasCategory, categories))
    assert intent.getCategories() == categories
    assert intent.getData() == Uri.parse('content://com.example.app/users/1')
    assert intent.getDataString() == 'content://com.example.app/users/1'
    assert intent.getType() == 'text/x-vcard'
    assert intent.getComponent().equals(
        ComponentName('package.name', 'class.name'))
    assert intent.getScheme() == 'content'
    flags = (Intent.FLAG_ACTIVITY_CLEAR_TASK,
             Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY,
             Intent.FLAG_ACTIVITY_SINGLE_TOP)
    iflags = intent.getFlags()
    assert all(map(lambda x: bool(x & iflags), flags))
예제 #2
0
def test_ClassMethods():
    normalizeMimeType = Intent.Intent.normalizeMimeType
    assert normalizeMimeType("text/plain; charset=utf-8") == "text/plain"
    assert normalizeMimeType("text/x-vCard") == "text/x-vcard"

    intent = Intent.Intent.makeMainActivity(
        ComponentName('com.android.exanmple', '.MainActivity'))
    assert intent.getAction() == Intent.ACTION_MAIN
    assert intent.getCategories() == set([Intent.CATEGORY_LAUNCHER])
    assert intent.getComponent().equals(
        ComponentName('com.android.exanmple', '.MainActivity'))

    intent = Intent.Intent.makeMainSelectorActivity('com.android.example',
                                                    Intent.CATEGORY_APP_MAPS)
    assert intent.getSelector()
예제 #3
0
def test_classmethods():
    acname = ComponentName.createRelative(pck, cname.getShortClassName())
    assert cname.equals(acname), 'ERROR: createRelative'

    parcel = Parcel()
    parcel.writeString(pck)
    parcel.writeString(cls)

    parcel.setDataPosition(0)
    acname = ComponentName.readFromParcel(parcel)
    assert cname.equals(acname), 'ERROR: readFromParcel'

    astring = cname.flattenToShortString()
    acname = ComponentName.unflattenFromString(astring)
    assert cname.equals(acname), 'ERROR: unflattenFromString'
예제 #4
0
 def onOptionsItemSelected(self, menuitem):
     itemId = menuitem.getItemId()
     if itemId == R.id.create_new:
         component = ComponentName('TestActivity', '.FragmentTest')
         anIntent = Intent().setComponent(component)
         self.startActivity(anIntent)
     print self.getResources().getResourceName(itemId)
예제 #5
0
def test_getComponentInfo(provider):
    component = ComponentName.createRelative("com.AdroidApps.TestActivity",
                                             '.TestActivity')
    activityinfo = provider.getComponentInfo(component, 0)
    assert activityinfo.name == '.TestActivity'
    assert activityinfo.applicationInfo.name == 'mi aplicacion'
    pass
예제 #6
0
 def __init__(self, starterComponent=None, width=600, height=400):
     tk.Tk.__init__(self)
     self.config(width=width, height=height)
     self.pack_propagate(0)
     self.bind_all("<Control-q>", self.quit)
     self.activetask = None
     self.tasks = dict()
     starterComponent = ComponentName(*starterComponent)
     self.setGUI(starterComponent)
예제 #7
0
 def getAvailablePackages(self):
     intent = Intent.Intent(Intent.ACTION_MAIN)
     intent.addCategory(Intent.CATEGORY_LAUNCHER)
     pm = PackageManager()
     allapps = pm.queryIntentActivities(intent, 0)
     self.componentPackage = []
     packages = []
     for ri in allapps:
         ai = ri.activityInfo
         packages.append(ai.applicationInfo.name)
         self.componentPackage.append(ComponentName(ai.packageName,
                                                    ai.name))
     return packages
예제 #8
0
 def getComponentInfo(self, component, flags):
     package_name = component.getPackageName()
     rootid = self.getComponentRootIdForPackage(package_name)
     component_info = self.mOpenHelper.getAllDescendantsRecords(rootid,
                                                                inDepth=2)
     for item in component_info:
         ifilter = self._contentConverter(item)
         class_name = ifilter.get('name')
         if class_name and component.equals(
                 ComponentName.createRelative(package_name, class_name)):
             # return item[:-1] + (ifilter, )
             return self.getComponentIdInfo(item[0], flags)
     else:
         raise Exception('PackageManager.NameNotFoundException')
예제 #9
0
def test_parcelable():
    parcel = Parcel()

    cname.writeToParcel(parcel,0)
    parcel.setDataPosition(0)
    acname = ComponentName.readFromParcel(parcel)
    assert cname.equals(acname), 'ERROR: No correspondence between ' \
                                 'writeToParcel and readToParcel'
    npos = parcel.dataPosition()
    parcel.writeParcelable(cname, 0)
    parcel.setDataPosition(npos)
    fparcel = parcel.readParcelable(None)

    assert cname.equals(fparcel), 'ERROR: parcelable'
예제 #10
0
# -*- coding: utf-8 -*-
from Android.content.ComponentName import ComponentName
from Android.Os.Parcel import Parcel

pck = 'este.es.el.package'
cls = 'este.es.el.package.esta.es.la.clase'
cname = ComponentName(pck, cls)

def test_getters():
    assert pck == cname.getPackageName(), 'ERROR: getPackageName'
    assert cls == cname.getClassName(), 'ERROR: getClassName'
    assert cname.getShortClassName() == '.esta.es.la.clase', 'ERROR: getShortClassName'

def test_info():
    assert cname.equals(cname), 'ERROR: equals'
    assert cname.flattenToString() == '%s/%s' % (pck, cls), 'ERROR: flattenToString'
    assert cname.flattenToShortString() == '%s/%s' % (pck, '.esta.es.la.clase'), 'ERROR: flattenToShortString'

def test_classmethods():
    acname = ComponentName.createRelative(pck, cname.getShortClassName())
    assert cname.equals(acname), 'ERROR: createRelative'

    parcel = Parcel()
    parcel.writeString(pck)
    parcel.writeString(cls)

    parcel.setDataPosition(0)
    acname = ComponentName.readFromParcel(parcel)
    assert cname.equals(acname), 'ERROR: readFromParcel'

    astring = cname.flattenToShortString()