Exemplo n.º 1
0
    def create(self):
        # DetailedList is not a specific widget on Android, so we build it out
        # of a few pieces.

        if self.native is None:
            self.native = android_widgets.LinearLayout(self._native_activity)
            self.native.setOrientation(android_widgets.LinearLayout.VERTICAL)
        else:
            # If create() is called a second time, clear the widget and regenerate it.
            self.native.removeAllViews()

        scroll_view = android_widgets.ScrollView(self._native_activity)
        scroll_view_layout_params = android_widgets.LinearLayout__LayoutParams(
            android_widgets.LinearLayout__LayoutParams.MATCH_PARENT,
            android_widgets.LinearLayout__LayoutParams.MATCH_PARENT)
        scroll_view_layout_params.gravity = android_widgets.Gravity.TOP
        swipe_refresh_wrapper = android_widgets.SwipeRefreshLayout(
            self._native_activity)
        swipe_refresh_wrapper.setOnRefreshListener(
            OnRefreshListener(self.interface))
        self._android_swipe_refresh_layout = android_widgets.SwipeRefreshLayout(
            __jni__=java.NewGlobalRef(swipe_refresh_wrapper))
        swipe_refresh_wrapper.addView(scroll_view)
        self.native.addView(swipe_refresh_wrapper, scroll_view_layout_params)
        dismissable_container = android_widgets.LinearLayout(
            self._native_activity)
        dismissable_container.setOrientation(
            android_widgets.LinearLayout.VERTICAL)
        dismissable_container_params = android_widgets.LinearLayout__LayoutParams(
            android_widgets.LinearLayout__LayoutParams.MATCH_PARENT,
            android_widgets.LinearLayout__LayoutParams.MATCH_PARENT)
        scroll_view.addView(dismissable_container,
                            dismissable_container_params)
        for i in range(len((self.interface.data or []))):
            self._make_row(dismissable_container, i)
Exemplo n.º 2
0
Arquivo: base.py Projeto: saroad2/toga
def _get_activity(_cache=[]):
    """
    Android Toga widgets need a reference to the current activity to pass it as `context` when creating
    Android native widgets. This may be useful at any time, so we retain a global JNI ref.

    :param _cache: List that is either empty or contains 1 item, the cached global JNI ref
    """
    if _cache:
        return _cache[0]
    # See MainActivity.onCreate() for initialization of .singletonThis:
    # https://github.com/beeware/briefcase-android-gradle-template/blob/3.7/%7B%7B%20cookiecutter.formal_name%20%7D%7D/app/src/main/java/org/beeware/android/MainActivity.java
    if MainActivity.singletonThis is None:
        raise ValueError(
            "Unable to find MainActivity.singletonThis from Python. This is typically set by "
            "org.beeware.android.MainActivity.onCreate().")
    _cache.append(
        MainActivity(__jni__=java.NewGlobalRef(MainActivity.singletonThis)))
    return _cache[0]