반응형
반응형

파이썬을 이용한 단어모음파일에서  무작위로 단어 프린트하기

wordlist.txt : 단어모음 text 파일

wordlist.py : 단어장 스크립트 파일

 

Line.3 : getcwd()를 이용하여 알아낸 경로에 'sl4a'가 포함되어 있으면 경로를 지정해 주도록한다.

Line.4 : 파일을 읽는다.

Line.5 : 파일내용을 splitlines(위 이미지는 오타)로 한줄씩 분할한다.

            lambda 함수는 간단한 함수를 한줄로 줄여준다.

Line.8 : 사용자의 입력을 무한반복으로 기다린다.

 

 

 

 

 

 

반응형
반응형

예제 스크립트가 많아지면 파일및 폴더관리가 쉽지 않다.

+ADD 버튼 선택하여 Folder를 생성해서 Shell로 관리하면 된다.

물론 PC와 USB 연결해서 정리하면 훨씬 빠르겠다.

간단 명령어

pwd : 현재 위치를 보여준다.

cd scripts : scripts 폴더로 이동한다.

ls : 디렉토리내의 파일목록을 보여준다.

ls -l 또는 ll : 자세리 파일목록을 보여준다.

mv hello_android.py  scripts : scripts 폴더로 hello_android.py 파일을 이동시킨다.

rm hello_android.py: 파일 삭제

 

사진찍기, 연속 촬영하기

 

import android,time

 

a = android.Android()

 

def pic():

    return 'sdcard/sl4a/scripts/img/'\

         + time.strftime('%Y%m%d%H%M%S')\

         + '.jpg'

 

def say(it):

    a.ttsSpeak(it)

    a.makeToast(it)

 

food = 'Keeeemcheeeee!'

 

for i in range(3):

    for j in range(3,0,-1):

        say(str(j))

        time.sleep(3)

    say(food)

    a.cameraCapturePicture(pic())

 

 

 

 

 

 

 

* sleep 을 위해 time을 import 한다.

* 순차적 파일명 생성을 위해서 time.strftime을 사용한 파일명 구현

 

 

반응형
반응형

안드로이드폰에서 파이썬을 사용하려면 SL4A(Scripting Layer for Android),

 Python for Android를 설치해야 한다.

 

SL4A 설치 : http://code.google.com/p/android-scripting/


QR로 다운 받을 수 있다. : http://android-scripting.googlecode.com/files/sl4a_r6.apk

 

SL4A를 실행하고 Menu > View > Interpreters 를 선택하면 "SHELL"이라는 메뉴가 나타난다.

shell 을 통해서 안드로이드폰과 대화를 할 수 있다.

 

난 "SHELL"이 나오지 않아서 바로 Python for Android를 설치해버렸다.

 

Python for Android 설치 : http://code.google.com/p/android-scripting/downloads/detail?name=PythonForAndroid_r4.apk

File:
Description:
Latest Python release.

Note that Python for Android is now being hosted here:
http://code.google.com/p/python-for-android/

This is a copy of the lastest release, placed here for convenience.
SHA1 Checksum: ff4dfef760880fd1cdbc164045cc859947ecbe1d What's this?

 

설치하면 Install 메뉴가 나오는데, 바로 Install 터치.

몇 번의 다운로드와 설치가 끝나고, Install > UnInstall 로 변경된다.

 

그럼, 다시 SL4A를 실행하면  Script와 Shell이 대기중일 것이다.

스크립트 목록이 나오는데, shell화면으로 가고 싶으면 View > Interpreters 로 이동한다.

 

Interpreters에서 python을 선택하면 파이썬 shell로 들어간다. 안드로이드를 import해서 핸드폰 기능을 테스트 해 볼 수 있다.

 

안드로이드 모듈을 가져온다.

>>>import android

>>>droid = android.Android()

 

>>>droid.vibrate()

: 진동을 실행한다. 그런데, 한번밖에 되지 않는다.

 

>>>droid.ttsSpeak('anneung')

: '안녕'이라고 스피커에서 나온다.

 

>>>def ann(): droid.ttsSpeak('anneung')

>>>ann()

>>>ann()

 

 

 

 

 

 

 

 

 

 

스크립트 파일을 추가해서 파일을 실행 해 볼 수 있다.

파일을 생성하고, MENU > Save & Run을 선택하면 저장하면서 실행이 된다.

반응형
반응형

Scaloid - 오픈소스 안드로이드 라이브러리

 

https://github.com/pocorall/scaloid

 

스칼라 언어로 안드로이드 개발의 어려움을 줄여주고자 만들어졌다.

 

Less painful Android development with Scala

Scaloid is a library aimed to simplify your Android code. It makes your code easy to write and understand by leveraging Scala language.

For example, the code block shown below:

val button = new Button(context)
button.setText("Greet")
button.setOnClickListener(new OnClickListener() {
  def onClick(v: View) {
    Toast.makeText(context, "Hello!", Toast.LENGTH_SHORT).show()
  }
})
layout.addView(button)

is reduced to:

SButton("Greet", toast("Hello!"))

Benefits

  • Write elegant Android software
    Scaloid provides a concise and type-safe way of writing Android application.
  • Simple to use
    Check our quick start guide
  • Compatible with your legacy code
    You can use both Scaloid and plain-old Java Android API. You can gradually improve your legacy code.
  • Maintained actively
    Scaloid is a dogfooding software. This is originally created to be used for my own Android apps.

Demos

If you want to see how Scaloid can be used in action, check a Scala port of apidemos app.

Need help using Scala language on your Android project?

There is an out-of-the-box solution. Just fork this project and start your Scala-Android app.

Features

...and many other things! Check the official Scaloid blog for news and announcements.

 

반응형
반응형

FragmentLayoutMaps

https://github.com/petedoyle/android-support-v4-googlemaps/tree/dev-samples/src/samples/FragmentLayoutMaps

 

Activity LifeCycle

 * http://developer.android.com/guide/components/activities.html

Activity LifeCycleActivity LifeCycle

 

 

 

 

Fragment LifeCycle

* http://developer.android.com/guide/components/fragments.html

 

Fragment LifeCycleFragment LifeCycle

 

 

 

######  http://developer.android.com/  #####

 

 

 

반응형
반응형

안드로이드에서 webview가 fragment 로 만들어졌을 경우 웹페이지에서 <select> 태그가 작동하지 않을때가 있다.

액티비티로 만들면 바로 작동이 되지만 일부 디바이스에서 작동이 안될때가 있어서. 속터진다. ㅋㅋ

 

인터넷 검색하면 여러 답변이 있는데, 우리가 필요로 하는 건 없었다.

 

어플에서 수정이 필요하다.

 

 

==================================================================================

 

WebView into a Fragment (android.support.v4)

 

http://stackoverflow.com/questions/9279632/webview-into-a-fragment-android-support-v4

 

==================================================================================

 

[android] 2.2에서 fragment 사용하기

 

fragment 에 대한 설명 : http://androidhuman.tistory.com/469

예제 소스는 http://daddycat.blogspot.com/2011/08/android-30-fragments-example.html 에서 가져와서 약간 수정했음.

허니컴 이하에서 사용할 때 주의할 점 : http://www.androidpub.com/1432908

 

==================================================================================

 

Select dropdown in Android webview

 

The select tag just doesn’t work sometimes in Android, especially in an app using webview. This drove me nuts for a long long time. The main fix I found, even if your select is buried deep in divs and rows and what ever, is this css:


select {
  visibility: visible;
  -webkit-appearance: menulist-text;
}


 

The -webkit-appearance might be the only one actually needed and setting it to ‘listbox’ works too.

반응형

+ Recent posts