當前位置: 首頁>>代碼示例>>Python>>正文


Python jnius.autoclass方法代碼示例

本文整理匯總了Python中jnius.autoclass方法的典型用法代碼示例。如果您正苦於以下問題:Python jnius.autoclass方法的具體用法?Python jnius.autoclass怎麽用?Python jnius.autoclass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jnius的用法示例。


在下文中一共展示了jnius.autoclass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start_android_activity

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def start_android_activity(self, entry):
        self.log('starting activity')
        from jnius import autoclass
        PythonActivity = autoclass("org.kivy.android.PythonActivity")
        System = autoclass("java.lang.System")
        activity = PythonActivity.mActivity
        Intent = autoclass("android.content.Intent")
        String = autoclass("java.lang.String")

        j_entrypoint = String(entry.get("entrypoint"))
        j_orientation = String(entry.get("orientation"))

        self.log('creating intent')
        intent = Intent(
            activity.getApplicationContext(),
            PythonActivity
        )
        intent.putExtra("entrypoint", j_entrypoint)
        intent.putExtra("orientation", j_orientation)
        self.log(f'ready to start intent {j_entrypoint} {j_orientation}')
        activity.startActivity(intent)
        self.log(f'activity started')
        System.exit(0) 
開發者ID:kivy,項目名稱:kivy-launcher,代碼行數:25,代碼來源:app.py

示例2: fontscale

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def fontscale(self):
        '''Return the fontscale user preference. This value is 1 by default but
        can vary between 0.8 and 1.2.
        '''
        custom_fontscale = environ.get('KIVY_METRICS_FONTSCALE')
        if custom_fontscale:
            return float(custom_fontscale)

        if platform == 'android':
            from jnius import autoclass
            PythonActivity = autoclass('org.renpy.android.PythonActivity')
            config = PythonActivity.mActivity.getResources().getConfiguration()
            return config.fontScale

        return 1.0


#: Default instance of :class:`MetricsBase`, used everywhere in the code
#: .. versionadded:: 1.7.0 
開發者ID:BillBillBillBill,項目名稱:Tickeys-linux,代碼行數:21,代碼來源:metrics.py

示例3: scan_qr

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def scan_qr(on_complete):
    if platform != 'android':
        return
    from jnius import autoclass
    from android import activity
    PythonActivity = autoclass('org.kivy.android.PythonActivity')
    SimpleScannerActivity = autoclass(
        "org.pythonindia.qr.SimpleScannerActivity")
    Intent = autoclass('android.content.Intent')
    intent = Intent(PythonActivity.mActivity, SimpleScannerActivity)

    def on_qr_result(requestCode, resultCode, intent):
        try:
            if resultCode == -1:  # RESULT_OK:
                #  this doesn't work due to some bug in jnius:
                # contents = intent.getStringExtra("text")
                String = autoclass("java.lang.String")
                contents = intent.getStringExtra(String("text"))
                on_complete(contents)
        finally:
            activity.unbind(on_activity_result=on_qr_result)
    activity.bind(on_activity_result=on_qr_result)
    PythonActivity.mActivity.startActivityForResult(intent, 0) 
開發者ID:pythonindia,項目名稱:PyCon-Mobile-App,代碼行數:25,代碼來源:__init__.py

示例4: density

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def density(self):
        '''Return the density of the screen. This value is 1 by default
        on desktops but varies on android depending on the screen.
        '''
        custom_density = environ.get('KIVY_METRICS_DENSITY')
        if custom_density:
            return float(custom_density)

        if platform == 'android':
            import jnius
            Hardware = jnius.autoclass('org.renpy.android.Hardware')
            return Hardware.metrics.scaledDensity
        elif platform == 'ios':
            # 0.75 is for mapping the same density as android tablet
            import ios
            return ios.get_scale() * 0.75
        elif platform == 'macosx':
            from kivy.base import EventLoop
            EventLoop.ensure_window()
            return  EventLoop.window.dpi / 96.

        return 1.0 
開發者ID:BillBillBillBill,項目名稱:Tickeys-linux,代碼行數:24,代碼來源:metrics.py

示例5: build

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def build(self):
        self.log('start of log')
        if KIVYLAUNCHER_PATHS:
            self.paths.extend(KIVYLAUNCHER_PATHS.split(","))
        else:
            from jnius import autoclass
            Environment = autoclass('android.os.Environment')
            sdcard_path = Environment.getExternalStorageDirectory().getAbsolutePath()
            self.paths = [
                sdcard_path + "/kivy",
            ]

        self.root = Builder.load_string(KV)
        self.refresh_entries()

        if platform == 'android':
            from android.permissions import request_permissions, Permission
            request_permissions([Permission.READ_EXTERNAL_STORAGE]) 
開發者ID:kivy,項目名稱:kivy-launcher,代碼行數:20,代碼來源:app.py

示例6: user_dir

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def user_dir():
    if "HOME" in os.environ:
        return os.path.join(os.environ["HOME"], ".uwallet")
    elif "APPDATA" in os.environ:
        return os.path.join(os.environ["APPDATA"], "uwallet")
    elif "LOCALAPPDATA" in os.environ:
        return os.path.join(os.environ["LOCALAPPDATA"], "uwallet")
    elif 'ANDROID_DATA' in os.environ:
        try:
            import jnius
            env = jnius.autoclass('android.os.Environment')
            _dir = env.getExternalStorageDirectory().getPath()
            return _dir + '/uwallet/'
        except ImportError:
            pass
        return "/sdcard/uwallet/"
    else:
        # raise Exception("No home directory found in environment variables.")
        return 
開發者ID:UlordChain,項目名稱:Uwallet,代碼行數:21,代碼來源:util.py

示例7: open_url

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def open_url(url):
    if platform == 'android':
        ''' Open a webpage in the default Android browser.  '''
        from jnius import autoclass, cast
        context = autoclass('org.renpy.android.PythonActivity').mActivity
        Uri = autoclass('android.net.Uri')
        Intent = autoclass('android.content.Intent')

        intent = Intent()
        intent.setAction(Intent.ACTION_VIEW)
        intent.setData(Uri.parse(url))
        currentActivity = cast('android.app.Activity', context)
        currentActivity.startActivity(intent)
    else:
        import webbrowser
        webbrowser.open(url) 
開發者ID:metamarcdw,項目名稱:nowallet,代碼行數:18,代碼來源:main.py

示例8: share

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def share(self):
        if platform() == 'android': #check if the app is on Android
            # read more here: http://developer.android.com/training/sharing/send.html
            PythonActivity = autoclass('org.renpy.android.PythonActivity') #request the activity instance
            Intent = autoclass('android.content.Intent') # get the Android Intend class

            String = autoclass('java.lang.String') # get the Java object

            intent = Intent() # create a new Android Intent
            intent.setAction(Intent.ACTION_SEND) #set the action
            # to send a message, it need to be a Java char array. So we use the cast to convert and Java String to a Java Char array
            intent.putExtra(Intent.EXTRA_SUBJECT, cast('java.lang.CharSequence', String('Fast Perception')))
            intent.putExtra(Intent.EXTRA_TEXT, cast('java.lang.CharSequence', String('Wow, I just scored %d on Fast Perception. Check this game: https://play.google.com/store/apps/details?id=com.aronbordin.fastperception' % (self.best_score))))

            intent.setType('text/plain') #text message

            currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
            currentActivity.startActivity(intent) # show the intent in the game activity

    # will be called when our screen be displayed 
開發者ID:aron-bordin,項目名稱:Kivy-Tutorials,代碼行數:22,代碼來源:main.py

示例9: share

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def share(self):
        if platform() == 'android': #check if the app is on Android
            # read more here: http://developer.android.com/training/sharing/send.html
           
            PythonActivity = autoclass('org.renpy.android.PythonActivity') #request the Kivy activity instance
            Intent = autoclass('android.content.Intent') # get the Android Intend class

            String = autoclass('java.lang.String') # get the Java object

            intent = Intent() # create a new Android Intent
            intent.setAction(Intent.ACTION_SEND) #set the action

            # to send a message, it need to be a Java char array. So we use the cast to convert and Java String to a Java Char array
            intent.putExtra(Intent.EXTRA_SUBJECT, cast('java.lang.CharSequence', String('Byte::Debugger() Tutorial #7')))
            intent.putExtra(Intent.EXTRA_TEXT, cast('java.lang.CharSequence', String("Testing Byte::Debugger() Tutorial #7, with Python for Android")))

            intent.setType('text/plain') #text message

            currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
            currentActivity.startActivity(intent) # show the intent in the game activity 
開發者ID:aron-bordin,項目名稱:Kivy-Tutorials,代碼行數:22,代碼來源:main.py

示例10: set_reminder

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def set_reminder(self, title, time):
    intent = Intent()
    Calendar = autoclass('java.util.Calendar')
    calendar = Calendar.getInstance()
    calendar.setTimeInMillis(1480103863835)
    intent.setType("vnd.android.cursor.item/event")
    intent.putExtra(Events.DESCRIPTION, "Download Examples")
    intent.putExtra("title", "A Test Event from android app");
    intent.setAction(Intent.ACTION_VIEW)
    PythonActivity.mActivity.startActivity(intent) 
開發者ID:pythonindia,項目名稱:PyCon-Mobile-App,代碼行數:12,代碼來源:__init__.py

示例11: start_interpreter

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def start_interpreter(self, thread_name='default'):
        # if thread_name == 'interpreter':
        #     return
        print('trying to start interpreter', self.service_name)
        interpreter_script_path = join(dirname(realpath(__file__)),
                                       'interpreter_subprocess',
                                       'interpreter.py')

        # prepare settings to send to interpreter
        # throttle_output = '1' if App.get_running_app().setting__throttle_output else '0'
        throttle_output = '1' if self.throttle_output else '0'

        use_thread = '1' if self.use_thread else '0'

        argument = ('throttle_output={}:use_thread={}:'
                    'send_port={}:receive_port={}').format(
                        throttle_output, use_thread,
                        self.receive_port, self.interpreter_port)

        if platform == 'android':
            from jnius import autoclass
            service = autoclass('{}.Service{}'.format(package_name, self.service_name))
            mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
            # service.start(mActivity, argument, thread_name)
            service.start(mActivity, argument)
            print('did service start', service, mActivity)
        else:
            # This may not actually work everywhere, but let's assume it does
            print('starting subprocess')
            python_name = 'python{}'.format(sys.version_info.major)
            print('python name is', python_name)
            os.environ['PYTHON_SERVICE_ARGUMENT'] = argument
            s = subprocess.Popen([python_name, '{}'.format(interpreter_script_path)])
            App.get_running_app().subprocesses.append(s)
            self.subprocess = s
            pass 
開發者ID:inclement,項目名稱:Pyonic-interpreter,代碼行數:38,代碼來源:interpreterwrapper.py

示例12: restart

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def restart(self):
        if platform == 'android':
            from jnius import autoclass
            service = autoclass('{}.Service{}'.format(package_name, self.service_name))
            mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
            service.stop(mActivity)
            self.start_interpreter(self.thread_name)
        else:
            self.subprocess.kill()
            self.start_interpreter(self.thread_name)

        self.lock_input = True
        self.interpreter_state = 'restarting'
        Clock.unschedule
        Clock.schedule_interval(self.ping, 0.3) 
開發者ID:inclement,項目名稱:Pyonic-interpreter,代碼行數:17,代碼來源:interpreterwrapper.py

示例13: dispatch

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def dispatch():
    import os

    # desktop launch
    print("dispathc!")
    entrypoint = os.environ.get("KIVYLAUNCHER_ENTRYPOINT")
    if entrypoint is not None:
        return run_entrypoint(entrypoint)

    # try android
    try:
        from jnius import autoclass
        activity = autoclass("org.kivy.android.PythonActivity").mActivity
        intent = activity.getIntent()
        entrypoint = intent.getStringExtra("entrypoint")
        orientation = intent.getStringExtra("orientation")

        if orientation == "portrait":
            # SCREEN_ORIENTATION_PORTRAIT
            activity.setRequestedOrientation(0x1)
        elif orientation == "landscape":
            # SCREEN_ORIENTATION_LANDSCAPE
            activity.setRequestedOrientation(0x0)
        elif orientation == "sensor":
            # SCREEN_ORIENTATION_SENSOR
            activity.setRequestedOrientation(0x4)

        if entrypoint is not None:
            try:
                return run_entrypoint(entrypoint)
            except Exception:
                import traceback
                traceback.print_exc()
                return
    except Exception:
        import traceback
        traceback.print_exc()

    run_launcher() 
開發者ID:kivy,項目名稱:kivy-launcher,代碼行數:41,代碼來源:main.py

示例14: newObject

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def newObject(self, className, *args):
		from jnius import autoclass
		javaClass = autoclass(className)
		return javaClass(*args) 
開發者ID:jpmml,項目名稱:jpmml-evaluator-python,代碼行數:6,代碼來源:pyjnius.py

示例15: staticInvoke

# 需要導入模塊: import jnius [as 別名]
# 或者: from jnius import autoclass [as 別名]
def staticInvoke(self, className, methodName, *args):
		from jnius import autoclass
		javaClass = autoclass(className)
		javaMember = javaClass.__dict__[methodName]
		return javaMember(*args) 
開發者ID:jpmml,項目名稱:jpmml-evaluator-python,代碼行數:7,代碼來源:pyjnius.py


注:本文中的jnius.autoclass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。