2013年2月19日 星期二

單位換算api, ps to pt, dip to ps


public static int pixelsToPt(Context context, int sp) //context可傳入this.getApplicationContext()
{
        float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (sp*scaledDensity);
}
public float convertDipToPixels(int dips)
{
        Resources r = getResources();
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dips, r.getDisplayMetrics());
}

2013年2月18日 星期一

動態建立物件 還沒整理好


You can set ID's you'll use later in R.id class using an xml resource file, and let Android SDK give them unique values during compile time.
res/values/ids.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <item name="my_edit_text_1" type="id"/>
    <item name="my_button_1" type="id"/>
    <item name="my_time_picker_1" type="id"/>

</resources>
To use it in code:
myEditTextView.setId(R.id.my_edit_text_1);

2013年2月17日 星期日

建立包含EditText的AlertDialog


AlertDialog.Builder editDialog = new AlertDialog.Builder(CheckIt.this);
//CheckIt為本project class name
editDialog.setTitle("Please Input Title");
final EditText editText = new EditText(CheckIt.this);
editDialog.setView(editText);
editDialog.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
editDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
editDialog.show();

2013年2月14日 星期四

禁止android app休眠的方式

禁止APP休眠的方式

1、在Manifest.xml文件裡面用user-permission聲明。代码如下:
   <uses-permission android:name="android.permission.WAKE_LOCK"/>     

  这种方法,在安装apk时,系统会提示安装人是否允许使用禁止休眠功能。

2、在程序中用代码实现。代码如下:getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

  把这段代码加在setContentView(R.layout.main)之前即可
  这种方法,安装时,不会提示安装人是否允许使用禁止休眠功能

2013年2月9日 星期六

設定有外框的TextView


You can set a shape drawable (a rectangle) as background for the view.
<TextView android:text="Some text" android:background="@drawable/back"/>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" /><stroke android:width="1dip" android:color="#4fa5d5"/></shape>


方框
And rectangle drawable back.xml (put into res/drawable folder):
You can use #00000000 for the solid color to have a transparent background. You can also use padding to separate the text from the border. for more information see:http://developer.android.com/guide/topics/resources/drawable-resource.html
圓角框

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff" />
<corners android:radius="10dp" />
<padding android:left="5dp" android:top="5dp" 
android:right="5dp" android:bottom="5dp" />
</shape>

也可以將兩個合起來

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#404040" /><!-- 內部填充顏色 -->
<stroke android:width="3dip" android:color="#FFFFFF"/><!--外框顏色  -->
<corners android:radius="10dp" />
<padding android:left="5dp" android:top="5dp" 
android:right="5dp" android:bottom="5dp" />
</shape>

Android Layout常用的一些設定整理(持續更新)

value部分:
strings.xml
    給字串使用,使用方式@string/xxxx
dimens.xml
     給數值使用, 使用方式@dimen/xxxxx

android:gravity="center"
    控件內容物(字串)置中
android:textStyle="bold"
    文字粗體


2011年10月27日 星期四

ffmpge資料收集整理

[等待確認] 
與硬體相關的Code可能存放在 libavutil ; libavcodec


[已確認]
libavutil/bswap.h處理跟CPU相關的硬體問題 - endian
從代碼可看到

#include "config.h"
#if   ARCH_ARM
#   include "arm/bswap.h"
#elif ARCH_AVR32
#   include "avr32/bswap.h"
#elif ARCH_BFIN
#   include "bfin/bswap.h"
#elif ARCH_SH4
#   include "sh4/bswap.h"
#elif ARCH_X86
#   include "x86/bswap.h"
#endif


[已確認]
/doc/optimization.txt內描述了 最佳化相關的事項optimization Tips

[藍色部分待確認]
  • ffmpeg 是一個命令列工具,用來對視訊檔案轉換格式,也支援對電視卡即時編碼//ffmpeg.c
  • ffserver 是一個 HTTP 多媒體即時廣播串流伺服器,支援時光平移 //ffserver.c 
  • ffplay 是一個簡單的播放器,基於 SDL 與 FFmpeg 函式庫//ffplay.c 
  • libavcodec 包含了全部 FFmpeg 音訊/視訊 編解碼函式庫//對應同名稱資料夾
  • libavformat 包含 demuxers 和 muxer 函式庫//對應同名稱資料夾
  • libavutil 包含一些工具函式庫//對應同名稱資料夾
  • libpostproc 對於視訊做前處理的函式庫//對應同名稱資料夾
  • libswscale 對於影像作縮放的函式庫 //對應同名稱資料夾