本文整理汇总了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)
示例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
示例3: 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
示例4: 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])
示例5: 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)
示例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
示例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)
示例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
示例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
示例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)
示例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
示例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)
示例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()
示例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)
示例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)