Categories
Android

Android播放gif格式图片

关于gif的播放,Android ApiDemos给出一个实例:

ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java

小的gif图片用Movie播放还行,大一点的就搞不定了。官方文档说不推荐使用gif格式的。解析gif要占很大的内存,不过你可以把gif分解成N张png格式的,用AnimationDrawable来播放。在MTK,展信平台上,一些连续动画的游戏,也是采用这样样的方法,分解gif为N多个Frame,做过Flash的网页设计师应该是很熟悉了。

在res/anim目录下创建相应的xml文件,举个例子: girl_kiss.xml:

<?xml version="1.0" encoding="UTF-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true" android:visible="true">
<item android:drawable="@drawable/kiss_frame00_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame01_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame02_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame03_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame04_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame05_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame06_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame07_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame08_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame09_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame10_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame11_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame12_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame13_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame14_160ms" android:duration="160" />
<item android:drawable="@drawable/kiss_frame15_0ms" android:duration="0" />
</animation-list>

然后在主程序通过AnimationDrawable来操作。

Categories
Android

android 字符串格式化

发现没啥好写的,提供个链接吧,查阅方便。

一般用到 String.format与Html.fromHtml
官方上有详细介绍:
http://developer.android.com/guide/topics/resources/string-resource.html

有段时间看了日历的代码,发现Plurals有 xliff 字样,搜索一下,小日本写的
http://linkyou-blog.blogspot.com/2010/02/previously-on-my-last-blog.html
终于弄明白了。

读一些代码,发现string.xml里还发现一些蛮有用的技巧,直接写Unicode码:
用 \u0020 表示空格。
用 \u2026 表示省略号。

android提供的android.text.format 也很有用,比如 Formatter 提供的
public static String formatFileSize(Context context, long number)
就很好用,很多人估计是不知道,自个儿写了这样的函数,重复造车轮。

Categories
Android

Android 反编译中的 $assertionsDisabled

很久以前看了一些apk经过反编译后得到的 .dex 格式文件,发现有assertionsDisabled, 不解记录之,今天翻看以前的工作日志,于是写个程序验证。

.field static final $assertionsDisabled Z

.method static <clinit>()V
.limit registers 1
.line 85
 16     const-class v0,org/lytsing/android/Assert
 17 ; v0 : Ljava/lang/Class;
 18     invoke-virtual  {v0},java/lang/Class/desiredAssertionStatus ; desiredAssertionStatus()Z
 19 ; v0 : Ljava/lang/Class;
 20     move-result v0
 21 ; v0 : single-length
 22     if-nez  v0,l1c6ac
 23 ; v0 : single-length
 24     const/4 v0,1
 25 ; v0 : single-length
 26 l1c6a6:
 27     sput-boolean    v0,org/lytsing/android/Assert$assertionsDisabled Z
 28 ; v0 : Z
 29     return-void
 30 l1c6ac:
 31     const/4 v0,0
 32 ; v0 : single-length
 33     goto    l1c6a6
 34 .end method

在某个函数调用:

110     .line 153
111     sget-boolean v0, Lorg/lytsing/android/Assert;->$assertionsDisabled:Z
112 
113     if-nez v0, :cond_0
114 
115     array-length v0, p2
116 
117     array-length v1, p4
118 
119     if-eq v0, v1, :cond_0
120 
121     new-instance v0, Ljava/lang/AssertionError;
122 
123     invoke-direct {v0}, Ljava/lang/AssertionError;-><init>()V
124 
125     throw v0

好像很复杂, 其实仅仅一行代码:

assert conIds.length == stringIds.length;

就产生了上面一坨的代码。

Categories
PHP

再说说代码风格

老掉牙的话题了,晚上bb给我发一段 php代码,别人写的taobao api,要修改一下cache,我看了,头都大了,代码缩进tab与空格并用,导致我用vim打开很乱。一般,代码写得很糟糕的,我都拒绝看,老朋友嘛,硬着头皮看看,用indent对齐一下,还算好。再看一些函数的命名,我又晕了一把。比如
public function SendCheng ($mode = 'GET',$format = 'xml')
还真的看不明白是什么意思。

在小的软件公司,很多新员工来上班第一天,领导拷贝一堆pdf技术文档给你自个儿看,公司压根儿没编码规范的文档,祸害从此开始。从另一个侧面来说,作为一个程序员,自己也有责任去看《程序设计实践》,网上流传的《华为编码规范》,林锐的《高质量C/C++编程指南》等。千万不要搞什么像Button1, Button2, Button3, xingbie(性别), jifen(积分, 这个的命名方式,害人害己。美工A进公司时也已经工作3年了,网页与图片都是随便的001.html, 002.html, 003.index,不明白是什么意思。我问她为什么不给它们起个有意思的名字,比如一张表示团队的图片,teamwork,jpg 与001.jpg,谁更容易管理,更容易让搜索引擎找到?她说以前没人要求她这么做过,文件随意放,老师没教过要这样做的。再者,搞网站3年,竟然不知道什么是w3c,我真的感到悲哀,同时也为我自己感到悲哀,没有做这方面的测试,以为这是基本的知识,大家都知道了。

良好的代码风格,是一个程序员的基本修养。

Categories
Android

小探 android版QQ空间(体验版)

STONE说tx早有android版 QQ空间了,于是下载看看,感觉还行,功能太少了。不甘心,看看里面有什么好玩的,不会是个wrapper web的吧,于是决定反编译看个究竟。虽然大家都在骂腾讯,但不可否认的是,他们产品的用户体验做的很好, 搞android开发,也可以看看他们产品,好的界面设计,我们也可以拿来用。前文已经介绍了一些反编译apk的工具,搞软件开发的,至少有那么一点hack精神,学会反编译apk是Android应用程序开发的一项基本技能。

UI

界面是淡蓝色风格,也是我比较喜欢的风格,美工图片作图比较到位。看看下边的Tab吧,跟web一样了.

android qzone 体验版

开始琢磨一下,到底用什么东东做的?原来是自定义的tabTextStyle,里面还有非常多自定义的view, style,正应那句话:“优秀的组件都是自定义的”。

personcenterheaderview.xml :

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    android:orientation="vertical"
    android:background="@drawable/homepageheadbg"
    android:focusable="false"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:orientation="horizontal"
        android:id="@id/LinearLayoutUserMood"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.0">
        <LinearLayout
            android:gravity="center"
            android:background="@drawable/personhead"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4.0px"
            android:layout_marginTop="5.0px">
            <ImageView
                android:id="@id/ImageViewUserIcon"
                android:layout_width="49.0dip"
                android:layout_height="49.0dip"
                android:scaleType="centerCrop" />
        </LinearLayout>
        <LinearLayout
            android:orientation="vertical"
            android:id="@id/saynamegroup"
            android:background="@drawable/saydialog"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8.0px"
            android:layout_marginRight="10.0px"
            android:layout_weight="1.0">
            <TextView
                android:textSize="14.0px"
                android:textColor="@color/black"
                android:ellipsize="end"
                android:id="@id/TextViewMood"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2.0px"
                android:layout_marginRight="2.0px"
                android:maxLines="2"
                android:layout_weight="1.0"
                />
            <TextView
                android:textSize="12.0px"
                android:id="@id/TextViewTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2.0px"
                android:layout_marginTop="2.0px"
                style="@style/unnoticeableTextStyle"
            />
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:gravity="center"
        android:orientation="horizontal"
        android:id="@id/LinearLayoutTabNav"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:gravity="center"
            android:id="@id/TextViewTabMood"
            android:layout_width="wrap_content"
            android:layout_height="36.0dip"
            android:text="心情"
            android:layout_weight="1.0"
            style="@style/tabTextStyle" />
        <TextView
            android:gravity="center"
            android:id="@id/TextViewTabBlog"
            android:layout_width="wrap_content"
            android:layout_height="36.0dip"
            android:text="日志"
            android:layout_weight="1.0"
            style="@style/tabTextStyle" />
        <TextView
            android:gravity="center"
            android:id="@id/TextViewTabAlbum"
            android:layout_width="wrap_content"
            android:layout_height="36.0dip"
            android:text="相册"
            android:layout_weight="1.0"
            style="@style/tabTextStyle" />
        <TextView
            android:gravity="center"
            android:id="@id/TextViewMessage"
            android:layout_width="wrap_content"
            android:layout_height="36.0dip"
            android:text="留言板"
            android:layout_weight="1.0"
            style="@style/tabTextStyle" />
    </LinearLayout>
</LinearLayout>

数据交换

采用对象序列化,那么提供api的服务端也是用java写的了。

代码组织

搞了很多封装,写了N多个组件,不过看起来还清晰。

命名规则

不知道tencent有没有公司内部的规范文档,但我看到

zhuye1.png
zhuye2.png
zhuye3.png

android:id=”@id/ImageView01″
android:id=”@id/ImageView02″

之类的,感到很失望,浪费我时间来翻尸体。

国际化

在layout xml文件还出现
android:text=”上传”,android:text=”取消” android:text=”请输入验证码” 之类的东西,为什么不用@string/xxx 呢?

res/values/strings.xml 里写了很多中文,已经有了values-zh目录,为什么不写到里面呢?

Pages: Prev 1 2 3 ... 12 13 14 15 16 17 18 19 20 21 22 Next