2013년 5월 30일 목요일

Android Property Animation

이전 블로그에서 이전 함 (원본 글 2013/05/30 작성)

특정 widget에 animation 효과를 주는 방법이 필요 했었는데
아래와 같이 간단한 방법(Property Animation)이 있었다.



Animation

The Android framework provides two animation systems: property animation (introduced in Android 3.0) and view animation. Both animation systems are viable options, but the property animation system, in general, is the preferred method to use, because it is more flexible and offers more features. In addition to these two systems, you can utilize Drawable animation, which allows you to load drawable resources and display them one frame after another.
Property Animation
Introduced in Android 3.0 (API level 11), the property animation system lets you animate properties of any object, including ones that are not rendered to the screen. The system is extensible and lets you animate properties of custom types as well.
View Animation
View Animation is the older system and can only be used for Views. It is relatively easy to setup and offers enough capabilities to meet many application's needs.
<dt style="color: rgb(34, 34, 34); font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px; background-color: rgb(249, 249, 249);">Drawable Animation</dt><dd style="margin: 0px 0px 10px 30px; color: rgb(34, 34, 34); font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px; background-color: rgb(249, 249, 249);">Drawable animation involves displaying Drawable resources one after another, like a roll of film. This method of animation is useful if you want to animate things that are easier to represent with Drawable resources, such as a progression of bitmaps.</dd>


Property Animation 예제 따라하기




Property 설명

http://underclub.tistory.com/351


안드로이드 API Demo 중에서 Layout Animation를 참고하는 것을 추천.

2013년 5월 29일 수요일

Smack library의 connection 관련 참고 사항

이전 블로그에서 이전 함 (원본 글 2013/05/29 작성)

Android에서 smack library (아마도 asmack https://github.com/Flowdalic/asmack)를 사용하다면
connection 시 암호화 관련 사항(SASL authentication )에서 exception이 발생하거나
connection 시 timeout 이 걸릴때가 많다.

SASL authentication에 대해서는 Android내부의 subsystem을 사용해서 처리하도록 하기도 하지만
별 소용이 없는 것 같고 connection timeout 관련해서는 reconnect에서 문제가 생기는 것으로 보이지만 정확한 원인을 찾지는 못하겠다.

그래서 일단 처리하는 방법은
connection timeout을 줄이고 SASL authentication을 disable 시키는 방법이다.
자세한 설명 및 코드는 아래 링크를 참고.


38        SmackConfiguration.setPacketReplyTimeout(packetReplyTimeout);
39         
40        config = new ConnectionConfiguration(server, port);
41        config.setSASLAuthenticationEnabled(false);
42        config.setSecurityMode(SecurityMode.disabled);
43         
44        connection = new XMPPConnection(config);
45        connection.connect();

2013년 5월 16일 목요일

Android Handler 관련 스크랩

이전 블로그에서 이전 함 (원본 글 2013/05/16 작성)

다중 Handler를 처리하다 보니 UI thread가 아닌 thread에서 handler를 생성할 필요가 있었음.





UI 쓰레드가 아닌 일반 쓰레드에서 UI 작업처리를 위해 new Handler() 를 통해 Handler를 사용할 경우 아래와 같은 에러가 발생합니다.

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

그럼 UI처리를 위한 Handler는 UI 쓰레드에서만 생성해야 한다고 생각할 수 있습니다.


그러나 그렇지 않습니다. 임의의 쓰레드에서도 UI작업용 Handler를 사용할 수 있습니다.


다만, UI 작업을 처리하기 위해서는 아래와 같이 UI쓰레드에 바인딩된 Handler를 만들어야 합니다.

Handler handler = new Handler(Looper.getMainLooper());



* 참고





안드로이드 Handler 이야기 - Handler 와 Looper  안드로이드
2011/08/09 23:19






UI thread에서 worker thread로 보낼때..

좀 복잡한 방법

2013년 5월 8일 수요일

Message pushing on Android without GCM

이전 블로그에서 이전 함 (원본 글 2013/05/08 작성)

[Using MQTT in Android mobile applications]


 - Persistent TCP/IP connection with ping request every 20mins (wake up by AlaramManager)
 - Message lost will be happen during connection closed situation.

 GCM 안 쓰고 하려면 이 방법 밖에 없나.. ?


[How to Implement Push Notifications for Android]

 - Made sample application with same MQTT approach with above

[XMPP messaging pushing related article]


 - 뭐 5분씩 heartbeat을 날려도 배터리 소모에는 별 지장은 없을 거라는 얘기..


 XMPP is a good solution. I have used it for a push enabled, realtime, Android application. XMPP is powerful, highly extensible and easy to integrate and use.
There are loads of free XMPP servers (though out of courtesy you shouldn't abuse them) and there are open source servers you can run on one of your own boxes. OpenFire is an excellent choice.
The library you want isn't Smack as noted above, it's aSmack. But note, this is a build environment - you will have to build the library.
This is a calculation I did on battery life impact of an XMPP solution:
The Android client must maintain a persistent TCP connection by waking up periodically to send a heartbeat to the XMPP server.
This clearly imposes a cost in terms of power usage. An estimate of this cost is provided below:
  • Using a 1400mAh battery (as supplied in the Nexus One and HTC Desire)
  • An idle device, connected to an 3G network, uses approximately 5mA
  • The wake-up, heartbeat, sleep cycle occurs every 5 minutes, takes three seconds to complete and uses 300mA
  • The cost in battery usage per hour is therefore:
    • 36 seconds 300mA = 3mAh sending heartbeat
    • 3600 seconds 5mA = 5mAh at idle
    • 4:95 + 3 = 7:95mAh combined
  • A 1400mAh battery lasts approximately 11.6 days at idle and 7.3 days when  running the application, which represents an approximate 37% reduction in  battery life.
  • However, a reduction in battery life of 37% represents the absolute worst case in practice given that devices are rarely completely idle.
share|improve this answer



 - smack을 사용할 경우 connection을 계속 유지해준다. 내부적으로 heartbeat 관련 사항은 소스를 봐야 할것 같은데.

By default Smack will try to reconnect the connection in case it was abruptly disconnected. Use ConnectionConfiguration#setReconnectionAllowed(boolean) to turn on/off this feature. The reconnection manager will try to immediately reconnect to the server and increase the delay between attempts as successive reconnections keep failing. 
In case you want to force a reconnection while the reconnetion manager is waiting for the next reconnection, you can just use Connection#connect() and a new attempt will be made. If the manual attempt also failed then the reconnection manager will still continue the reconnection job. 


org.jivesoftware.smack
Interface ConnectionListener

All Known Implementing Classes:
AbstractConnectionListenerReconnectionManager

<pre>public interface ConnectionListener</pre>
Interface that allows for implementing classes to listen for connection closing and reconnection events. Listeners are registered with Connection objects.


Author:
Matt Tucker
See Also:
Connection.addConnectionListener(org.jivesoftware.smack.ConnectionListener),Connection.removeConnectionListener(org.jivesoftware.smack.ConnectionListener)

Method Summary
 voidconnectionClosed()
          Notification that the connection was closed normally or that the reconnection process has been aborted.
 voidconnectionClosedOnError(Exception e)
          Notification that the connection was closed due to an exception.
 voidreconnectingIn(int seconds)
          The connection will retry to reconnect in the specified number of seconds.
 voidreconnectionFailed(Exception e)
          An attempt to connect to the server has failed.
 voidreconnectionSuccessful()
          The connection has reconnected successfully to the server.
 


[Android Push Server MQTT]
- 작성자 : 이광운 ultrakain엣gmail.com

scalibility를 고려한 push server 관련 자료.
근데 결론이 뭐지? PT 자료만으로는 모르겠다.
Asynchronous socket I/O를 지원하는 framework에서는 당연히 reactor, proactor를 사용하는 것은 당연할테고..

2013년 5월 7일 화요일

AMQP (Advanced Message Queuing Protocol)

이전 블로그에서 이전 함 (원본 글 2013/05/07 작성)

(작성중)

[Introduction]

AMQP is an open standard application layer protocol for messaging middleware.
AMQP is a standard wire-level protocol and semantic framework for high performance enterprise messaging.

- provides flow controlled, message-oriented communication with message-delivery guarantees.
 : at-most-once (where each message is delivered once or never)
 : at-least-once (where each message is certain to be delivered, but may do so multiple times) 
 : exactly-once (where the message will always certainly arrive and do so only once)
- Authentication / encryption based on SASL / TLS.
- It assumes an underlying reliable transport layer protocol such as Transmission Control Protocol (TCP).


[History]

- AMQP was originated in 2003 by John O'Hara at JPMorgan Chase & Co. in London, UK
- The version history of the AMQP 
  . 0-8, published in June 2006
  . 0-9, published in December 2006
  . 0-10 published in February 2008
  . 0-9-1, published in November 2008. 
   * These earlier releases are significantly different from the final 1.0 specification

AMQP 1.0 was released by the AMQP Working Group on 30 October 2011, at a conference in New York. 
- 1 November 2011, the formation of an OASIS Technical Committee was announced to advance this contributed AMQP version 1.0 through the international open standards process. 
  . The first draft from OASIS was released in February 2012 .
  . The second draft was released for public review on 20 June, 2012 .
  . AMQP was approved as an OASIS standard on the 31st October, 2012 .


[Transport Conceptual Model]

- An AMQP network consists of nodes connected via links. 
 : Nodes are named entities responsible for the safe storage and/or delivery of messages. 
 : Messages can originate from, terminate at, or be relayed by nodes.
- A link is a unidirectional route between two nodes.
- The link protocolmanages the transfer of responsibility between the source and target.

+------------+ +------------+ / Node A \ / Node B \ +----------------+ +--filter +----------------+ | | / | | | MSG_3 <MSG_1> | _/ _ | MSG_1 | | |(_)------------------>(_)| | | <MSG_2> MSG_4 | | | | MSG_2 | | | | Link(Src,Tgt) | | | +----------------+ | | +----------------+ | | Src Tgt Key: <MSG_n> = old location of MSG_n


Nodes exist within a container. 
- Examples of containers are brokers and client applications. 
 : Each container MAY hold many nodes. 
 : Producers and consumers are the elements within an application that generate and process messages. 
 : Queues are entities that store and forward messages.

+---------------+ +----------+ | <<Container>> | 1..1 0..n | <<Node>> | |---------------|<>-------------------->|----------| | container-id | | name | +---------------+ +----------+ /_\ /_\ | | | | +-----+-----+ +----------+----------+ | | | | | | | | | | +--------+ +--------+ +----------+ +----------+ +-------+ | Broker | | Client | | Producer | | Consumer | | Queue | |--------| |--------| |----------| |----------| |-------| | | | | | | | | | | +--------+ +--------+ +----------+ +----------+ +-------+


[Protocol Frames]

Frame Connection Session Link ======================================== open H begin I H attach I H flow I H transfer I H disposition I H detach I H end I H close H ---------------------------------------- Key: H: handled by the endpoint I: intercepted (endpoint examines the frame, but delegates further processing to another endpoint)

[Frame Layout]

REQUIRED OPTIONAL OPTIONAL
+--------------+-----------------+------------+ | frame header | extended header | frame body | +--------------+-----------------+------------+ 8 bytes *variable* *variable*

- General frame layout
+0 +1 +2 +3 +-----------------------------------+ -. 0 | SIZE | | +-----------------------------------+ |---> Frame Header 4 | DOFF | TYPE | <TYPE-SPECIFIC> | | (8 bytes) +-----------------------------------+ -' +-----------------------------------+ -. 8 | ... | | . . |---> Extended Header . <TYPE-SPECIFIC> . | (DOFF * 4-8) bytes | ... | | +-----------------------------------+ -' +-----------------------------------+ -. 4*DOFF | | | . . | . . | . . | . <TYPE-SPECIFIC> . |---> Frame Body . . | (SIZE-DOFF*4) bytes . . | . . | . ________| | | ... | | +--------------------------+ -'


- AMQP frame layout
type: 0x00 - AMQP frame +0 +1 +2 +3 +-----------------------------------+ -. 0 | SIZE | | +-----------------------------------+ |---> Frame Header 4 | DOFF | TYPE | CHANNEL | | (8 bytes) +-----------------------------------+ -' +-----------------------------------+ -. 8 | ... | | . . |---> Extended Header . <IGNORED> . | (DOFF*4-8)bytes | ... | | +-----------------------------------+ -' +-----------------------------------+ -. 4*DOFF | PERFORMATIVE: | | . Open / Begin / Attach . | . Flow / Transfer / Disposition . | . Detach / End / Close . | |-----------------------------------| | . . |---> Frame Body . . | (SIZE-DOFF*4)bytes . PAYLOAD . | . . | . ________| | | ... | | +--------------------------+ -'

[Messaging]
뭔소린지 모르겠다..


- Message format
Bare Message | .-------+-------. | | +---+---+---+---+---+---+---+
| h | d | m | p | a | a | f |
| e | e | e | r | p | p | o |
| a | l | s | o | p | p | o |
| d | i | s | p | l | l | t |
| e | v | a | e | i | i | e |
| r | e | g | r | c | c | r |
| | r | e | t | a | a | |
| | y | | i | t | t | |
| | - | - | e | i | i | |
| | a | a | s | o | o | |
| | n | n |  | n | n | |
| | n | n | | - | - | |
| | o | o | | p | d | |
| | t | t | | r | a | |
| | a | a | | o | t | |
| | t | t | | p | a | |
| | i | i | | e | | |
| | o | o | | t | | |
| | n | n | | i | | |
| | s | s | | e | | |
| | | | | s | | |
+---+---+---+---+---+---+---+
| | '-------------+-------------' | Annotated Message


* 자세한것은 스펙 다시 보는게 빠를듯..




- AMQP became the standard as the OASIS Advanced Message Queuing Protocol


AMQP Working Group License, OASIS copyright


- Advanced Message Queuing Protocol Protocol Specification, Version 0-9-1, 13 November 2008



모르겠다.. 쉽게 볼 수 있는게 아닌것 같다..
프로토콜도 복잡하고  option마다 message format이 다양해서..