2015年4月8日 星期三

[Android]利用Bundle傳送Bitmap

傳送:
Intent intent = new Intent();
intent.setClass(A.this, B.class);
Bundle bundle = new Bundle();
bundle.putParcelable("bitmap", bitmap);
intent.putExtras( bundle);
startActivity(intent);

接收:
Bundle bundle = getIntent.getExtras();
Bitmap bitmap = bundle.getParcelable("bitmap");
bitmap.setImageBitmap(bitmap);

2015年2月3日 星期二

[Android]Android AppTheme 系統預設樣式android:Theme語法整理

在使用新版Eclipse開發Android程式時
創建Android Project後會多了res/values/styles.xml的樣式檔案
事實上這是讓Android讀取的預設的樣式定義檔
例如要讓整個程式的基本樣式為亮色系或暗色系~
或者要隱藏標題全螢幕等等, 皆可以在這個檔案上進行修改...

在/res/values/目錄下, 預設的styles.xml內容
<resources>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>

而相關語法參數如下

android:theme="Theme.Light"     背景為白色
android:theme="Theme.Light.NoTitleBar"     白色背景並無標題欄 
android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,無標題欄,全螢幕
android:theme="Theme.Black"     背景黑色
android:theme="Theme.Black.NoTitleBar"     黑色背景並無標題欄
android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,無標題欄,全螢幕
android:theme="Theme.Wallpaper"     用系統桌面為應用程式背景
android:theme="Theme.Wallpaper.NoTitleBar"     用系統桌面為應用程式背景,且無標題欄
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系統桌面為應用程式背景,無標題欄,全螢幕
android:theme="Translucent"
android:theme="Theme.Translucent.NoTitleBar"
android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
android:theme="@android:style/Theme.Dialog"     將一個Activity顯示為能話框模式
android:theme="@android:style/Theme.NoTitleBar" 不顯示應用程式標題欄
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不顯示應用程式標題欄,並全螢幕





來源:http://3q.9527.tw/modules/tadnews/index.php?nsn=34

2015年1月20日 星期二

[Android]android apps範例_camera

想要寫個android apps去開啟裝置本身的鏡頭, 以Acer Iconia B1 A71這個裝置來講, 它的鏡頭就只有一個:前置鏡頭(front-facing,自拍用,視訊會議用,用來拍自己的臉,鏡頭就跟螢幕在同一面,在背面的就叫後置鏡頭back-facing).

首先要搞清楚到底要用哪個鏡頭. 單單寫一行Camera.open();是不行的. 起初就是天真的整個拿書本上的例子來編譯執行,結果畫面空空如也,看不到預覽畫面,去看debug error,不斷的出現startpreview()或setpreviewdisplay(holder) nullpointexception, 換個例子try, 結果使用呼叫系統內建camera apps,竟然成功?!然後開始懷疑acer那台只允許透過呼叫系統內建的去打開camera.

打開camera有兩種方式一種是透過呼叫系統內建的camera介面(android系統的,在螢幕_應用程式集打開就會看到'照相機'),另外一種就是等會介紹的先建立一個Camera物件,然後開始預覽startpreview,用takepicture來拍照,

隔天不甘心去官網看,照著10個步驟去做還是不行,最後檢查到第一個步驟建立Camera物件,然後Camera.open(),他老兄竟然沒open,得到null,叫它怎麼繼續做底下的事情?!最後程式寫麻煩一點, 去掃一遍裝置底下到底有幾個鏡頭,每個的代號是多少, 打開那個front-facing的鏡頭就ok了!

拍照的步驟:
1.建立Camera物件(Camera.open();),詳細的code請參考底下網址.

2.得到目前鏡頭一些設定值(preview畫面的長寬)->getParameters();

3.必要的話可以用 setParameters(Camera.Parameters);來修改設定值,

4.也可呼叫 setDisplayOrientation(int);來改變螢幕畫面的方向,

5.想要有預覽畫面要先 setPreviewDisplay(SurfaceHolder).

6.然後呼叫 startPreview() 開始預覽.

7.想要真正的拍照時,呼叫 mCamera.takePicture(null, null, mPicture); 第三個參數是callback function會幫你處理後續的動作,被鏡頭抓進來的這個frame做何處理之類的,本例是將她轉成bitmap秀在imageView的區域內,若你想額外存檔也行.

8.拍照後,預覽畫面就停格了,再呼叫一次 startPreview() 就可以再繼續預覽畫面.

9.呼叫 stopPreview() 來停止預覽.

10.當關閉apps不想再使用camera這個裝置要記得呼叫 Camera.release();來釋放這個share resource不然整個camera就被佔住了,之後的其它apps想來使用都不行,除非重開機.

11.因為需要Camera的功能, 所以在AndroidMainfest.xml內要加入:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
第二行跟第三行的android:required="false"意思是在沒有鏡頭的裝置上跑此篇介紹的android apps也是可以的.沒加的話,去google play下載這個apps,檢查到你的裝置沒鏡頭是不給安裝的.
p.s.官網是這樣寫,實際上我沒試過!

12.layout就是一個linearlayout裡面包1個button,1個ImageView,1個framelayout,

所有程式碼下載連結:
https://docs.google.com/file/d/0B6EVEd5P2B9cODVYWVlUak9tZEk/edit?usp=sharing

2014年10月16日 星期四

[LTU]1016資料庫系統employee table

create table employee(
fname char(20) not null,
minit char(20) not null,
lname char(20) not null,
ssn int(10) not null primary key,
bdate date,
address varchar(50),
sex char(2) not null,
salary int(10) not null,
super_ssn int(10),
dno char(2));

insert into employee values
('John','B','Smith',123456789,'1965-01-09','731 Fondren Houston TX','M',30000,333445555,'5'),
('Franklin','T','Wong',333445555,'1955-12-08','638 Voss Houston TX','M',40000,888665555,'5'),
('Alicia','J','Zelaya',999887777,'1968-01-19','3321 Castle Spring TX','F',25000,987654321,'4'),
('Jennifer','S','Wallace',987654321,'1941-06-20','291 Berry Bellaire TX','F',43000,888665555,'4'),
('Ramesh','K','Narayan',666884444,'1962-09-15','975 Fire Oak Humble TX','M',38000,333445555,'5'),
('Joyce','A','English',463463463,'1972-07-31','5631 Rice Houston TX','F',25000,333445555,'5'),
('Ahmad','V','Jabbar',987987987,'1969-03-29','980 Dallas Houston TX','M',25000,987654321,'4'),
('James','E','Borg',888665555,'1937-11-10','450 Stone Houston TX','M',55000,NULL,'1'),
('Josh','B','Bush',234516789,'1963-10-28','722 Fondren Houston TX','F',35000,998765432,'1');


2014年10月9日 星期四

[LTU]1008資料庫系統test1

1.擷取所有主修'CS'的大四學生
mysql> select Name from STUDENT where Major='CS';
+-------+
| Name  |
+-------+
| Smith |
| Brown |
+-------+
2 rows in set (0.00 sec)


2.擷取所有在2007及2008年由King教授所開得課程名稱
mysql> select Course_name from COURSE,SECTION where COURSE.Course_number=SECTION.Course_number and Instructor='King' and Year between '07' and '08';
+----------------------+
| Course_name          |
+----------------------+
| Discrete Mathematics |
+----------------------+
1 row in set (0.02 sec)


3.對每一學期由king教授所開得課程擷取其課程編號, 學期(semester), 學年及修課的學生人數
mysql> select Course_number,Semester,Year,count(Student_number) as count from SECTION,GRADE_REPORT where SECTION.Section_identifier=GRADE_REPORT.Section_identifier and Instructor='King';
+---------------+----------+------+-------+
| Course_number | Semester | Year | count |
+---------------+----------+------+-------+
| MATH2410      | Fall     | 07   |     1 |
+---------------+----------+------+-------+
1 row in set (0.01 sec)

[LTU]1009資料庫系統5個table

create table STUDENT(
Name varchar(10),
Student_number int(3),
Class int(2),
Major varchar(20));

insert into STUDENT values('Smith',17,1,'CS'),('Brown',8,2,'CS');

create table COURSE(
Course_name varchar(50),
Course_number varchar(10),
Credit_hours int(3),
Department varchar(20));

insert into COURSE values('Intro to Computer Science','CS1310',4,'CS'),('Data Structures','CS3320',4,'CS'),('Discrete Mathematics','MATH2410',3,'MATH'),('Database','CS3380',3,'CS');

create table SECTION(
Section_identifier int(3),
Course_number varchar(10),
Semester varchar(10),
Year varchar(2),
Instructor varchar(20));

insert into SECTION values(85,'MATH2410','Fall','07','King'),(92,'CS1310','Fall','07','Anderson'),(102,'CS3320','Spring','08','Knuth'),(112,'Math2410','Fall','08','Chang'),(119,'CS1310','Fall','08','Anderson'),(135,'CS3380','Fall','08','Stone');

create table GRADE_REPORT(
Student_number int(3),
Section_identifier int(3),
Grade varchar(1));

insert into GRADE_REPORT values(17,112,'B'),(17,119,'C'),(8,85,'A'),(8,92,'A'),(8,102,'B'),(8,135,'A');

create table PREREQUISITE(
Course_number varchar(10),
Prerequisite_number varchar(10));

insert into PREREQUISITE values('CS3380','CS3320'),('CS3380','MATH2410'),('CS3320','CS1310');

2014年8月12日 星期二

[HTML]使用 Veiwport 設定手機網頁的螢幕解析度

<meta name="viewport" content="width=device-width; initial-scale=1.0;">


Viewport 其他屬性
width設定畫面寬度
height設定畫面高度
initial-scale設定畫面的初始縮放比例
minimum-scale設定畫面的最小縮放比例
maximum-scale設定畫面的最大縮放比例
user-scalable設定是否允許使用者改變縮放比例

根據W3C草案,在meta tag中viewport有以下屬性可設定

  • width:[數字] 或 device-width
  • height:[數字] 或 device-height
  • initial-scale:最小0.25,最大5
  • minimum-scale:最小0.25,最大5
  • maximum-scale:最小0.25,最大5
  • user-scalable:1 或 0 (yes 或 no)