テキストの共有 - Kivy Advent Calendar 2013

風邪を引いてしまいました。
体調が復帰してから解説書きます。ごめんなさい...


(/sdcard/kivy/sender/)

android.txt お約束
main.py スクリプト本体
fonts_ja.py 使い回し

(android.txt)

title=sendere
author=cheeseshop
orientation=portrait

(main.py)

# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from android import action_send
import fonts_ja

SUBJECT = u'2013-12-16 休み'
BODY = (
    u'おはようございます。\n'
    u'cheeseshopです。本日は\n'
    u'風邪による体調不良のため\n'
    u'全日休をいただきたいと思います。\n'
    u'大変申し訳ありませんが\n'
    u'どうかよろしくお願い致します。'
)

class SenderApp(App):

    def do_send(self, instance):
        action_send(
            'text/plain',
            subject=self.subject.text.encode('utf-8'),
            text=self.body.text.encode('utf-8')
        )

    def build(self):
        root = BoxLayout(orientation='vertical')
        self.subject = TextInput(text=SUBJECT, size_hint=(1,0.1), multiline=False)
        self.body = TextInput(text=BODY, size_hint=(1,0.4))
        button = Button(text='send', size_hint=(1,0.5))
        button.bind(on_press=self.do_send)
        root.add_widget(self.subject)
        root.add_widget(self.body)
        root.add_widget(button)
        return root

    def on_pause(self):
        return True

if __name__ == '__main__':
     SenderApp().run()

解説

Androidのアプリデータ共有については、androidモジュールにすでにaction_sendが入っているのでそれを使います。定型文やWebページ抜粋などを加工して、Twitterやメールのクライアントに渡すだけでよければ簡単にできます。
ちなみに「image/png」とすればfilename引数の画像ファイルも送信できるので、写真の連携なんかもできそうです。