2012/12/13 0 コメント

Ruby on Rails 解説ブログ

Ruby in Rails 関連のブログも切ったので、そちらのほうも、是非宜しくお願いいたします。

2012/12/02 0 コメント

ソースコードの行数カウント

find ./ -type f | grep 'java\|xml' | xargs wc -l

こんなふうにすれば、ディレクトリを再帰で潜りながら、java と xml の行数の合計を出してくれます。
(ファイル名にjava,xmlを含むもの (厳密に拡張子で絞り込んでるわけではないですが。。))

メモメモ
2012/11/14 0 コメント

MongoDB を Mac OS X 10.7 Lion にインストール

ちょっと触ってみたかったので、Mac にインストールしてみた。
homebrewを使ってインストールします!!

sudo brew install mongodb

これをやればインストール完了なのですが、
「Cowardly refusing to `sudo brew install'」
 とErrorが出たので、まずこれを解決するために以下のコマンドを実行

sudo chown -R root /usr/local

このあとにさっきのコマンドを再び実行すればインストールできます。

<Mongodbを動かす>
# まず /data/db/ を作成 sudo mkdir -p /data/db/
sudo chown `id -u` /data/db # mongod で実行 mongod

この状態で、
mongo
とやれば、接続されるはずです。
2011/10/25 0 コメント

symfony2ブログ開設しました。

これからは、Symfony2に関してはSymfony2.GrAFRに書いてきます!
よろしくお願い致します。
2011/10/06 0 コメント

No input file specified.

Symfony2をさくらインターネットで動かそう!!とか思って phpのバージョンを 5.3.8 (CGI版) にした。
で、Symfony2 を動かした所、「No input file specified.」というエラーが。。。。

まぁ、エラーの内容はSymfony2とは関係ないんだけれど。。

これは、CGI版PHP環境でなんかのmoduleを使用する際に起こるらしい。
やっぱりVPSを契約してもらうべきだったか。。。と思ったけど、普通に解決できたので問題ないっぽい!!

ただ、php.iniに
cgi.fix_pathinfo = 1
を加えるだけでOKっぽいです。同時にタイムゾーンも指定しておきました。
date.timezone = Asia/Tokyo
2011/07/21 0 コメント

Cent OS (5.5) に MeCab をインストール

MeCab: Yet Another Part-of-Speech and Morphological Analyzer

MeCabで形態素解析!ってことで、CentOS (5.5) にさっそく MeCab0.98 を導入してみます。

① まず MeCabのインストール
[root@ ~]# wget 'http://downloads.sourceforge.net/project/mecab/mecab/0.98/mecab-0.98.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmecab%2Ffiles%2F&ts=1283097111&use_mirror=jaist'
[root@ ~]# tar xvfz mecab-0.98.tar.gz
[root@ ~]# cd mecab-0.98
[root@ ~]# ./configure
[root@ ~]# make
[root@ ~]# make install

② IPA 辞書をダウンロード
IPA 辞書, Juman 辞書 があるが、前者が推奨されていたので、それをダウンロードします。また, configureの際に文字コードを指定します(UTF-8とします)。
違う文字コードでインストールしてしまった場合は、make uninstall してからやり直せばOK
[root@ ~]# wget 'http://downloads.sourceforge.net/project/mecab/mecab-ipadic/2.7.0-20070801/mecab-ipadic-2.7.0-20070801.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmecab%2Ffiles%2F&ts=1283097195&use_mirror=jaist'
[root@ ~]# tar xvfz mecab-ipadic-2.7.0-20070801.tar.gz
[root@ ~]# cd mecab-ipadic-2.7.0-20070801
[root@ ~]# ./configure --with-charset=utf8
[root@ ~]# make
[root@ ~]# make install


※ これで終了。最後に何か文字列(明日は明日の風が吹く)を解析してみます。

[root@ ~]# mecab
明日は明日の風が吹く
明日 名詞,副詞可能,*,*,*,*,明日,アシタ,アシタ
は 助詞,係助詞,*,*,*,*,は,ハ,ワ
明日 名詞,副詞可能,*,*,*,*,明日,アシタ,アシタ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
風 名詞,一般,*,*,*,*,風,カゼ,カゼ
が 助詞,格助詞,一般,*,*,*,が,ガ,ガ
吹く 動詞,自立,*,*,五段・カ行イ音便,基本形,吹く,フク,フク
EOS


※ おまけとして、PHPからアクセスするために MeCab extension をインストールします。
http://d.hatena.ne.jp/yoshi-ken/20110621 の記事を参考にさせていただきました!
pear channel-discover pecl.opendogs.org
pear install opendogs/mecab-beta
echo "extension=mecab.so" > /etc/php.d/mecab.ini
php -m | fgrep mecab #インストールに成功していたら「mecab」という行が表示されます

<?php
$target_str = "明日は明日の風が吹く";
$result = mecab_split($target_str);
print_r($result);
?>

これで Array ( [0] => 明日 [1] => は [2] => 明日 [3] => の [4] => 風 [5] => が [6] => 吹く ) となります。
2011/07/13 0 コメント

iPhone - json-framework

jsonのパースをしたかったので、ちょっと調べてみたら、json-frameworkというのがヨサゲ。
ってことで導入してみました。

json-frameworkは Google Code にあります。http://code.google.com/p/json-framework/

① GitHubからダウンロード! (v3.0.1),
② Classesの中身をプロジェクトにインポート!(自分は, JSONというグループを作成し、そこにインポートしました。)


③ 利用したいクラスの先頭で
#import "SBJson.h"
とすれば、OK。

④ あとは NSString として jsonデータを与えパースすれば、配列として返ってくるっぽい
NSArray jsonArray = [json_str JSONValue];


ってことで json-framework についての簡単なメモでした。
2011/07/12 0 コメント

iPhone - 開発入門② IBを使用しない場合

Interface Builder を使用しないでアプリケーションを作成する場合は, 最初に以下の手順を行い, IBを使用しない設定に変更する。

① Window-based Application でプロジェクトを作成する。(プロジェクト名はHogeとする)

② Resouces 内の xibファイルである「MainWindow.xib」を削除する。

③ Resouces 内の「Hoge-Info.plist」を開き, 一番下の「Main nib file base name」のプロパティを削除

④ Other Sources 内の「main.m」を開き、以下の様変更を加える。(通常は, xibファイルがDelegateクラスを呼び出していたが、それを削除しため指定してやる必要がある。)

< 変更前 >
int main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

< 変更後 >
int main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"HogeAppDelegate");
    [pool release];
    return retVal;
}


⑤ Other Sources 内 のファイルで, @property や @ synthesize を削除してしまう。

_________________________________________________________

これで設定は完了です。あとは, HogeAppDelegateで自分でwindowの作成をし、viewをつくっていく感じ。

// HogeAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // windowを作成
    CGRect screenbounds = [[UIScreen mainScreen] bounds];
    window = [[UIWindow alloc] initWithFrame:screenbounds];

    /**
     * ここでwindow上にaddSubviewしていけば良い
     */

    [window makeKeyAndVisible];

    return YES;
}
0 コメント

iPhone - 開発入門① テンプレートの選択

※Xcodeのインストール等の環境構築の説明は行いません。

まず, Xcodeを起動して, テンプレートタイプを選ぶ。(以下の画面)



まず、どのテンプレートを使用すればいいかで困惑するはずです。
テンプレートは以下の物

  • Navigation-based Application
    リストの項目を選択したら、その項目について階層的に潜っていくような階層構造を持ったタイプ。
  • OpenGL ES Application
    3Dのグラフィックを使用したゲームなどのようなOpenGLを使用したタイプ
  • Split View-based Application
    iPadでSplit Viewを使うようなタイプ
  • Tab Bar Application
    下部にTabを生成しウィンドウを切り替えるタイプ
  • Utility Application
    iPhoneの天気アプリのような、フリップして裏画面で設定を行うようなタイプ
  • View-based Application
    ビューを1つだけ使用するタイプ
  • Window-based Application
    全ての基礎となるタイプ

しかし、音楽のための iPodアプリケーションのように、タブがあってナビゲーションもあるアプリを作りたい場合、どうすればよいか?という疑問が浮かぶはずです!

この場合は, Tab Bar Application の タブの1つとして Navigation-based のビューを生成すれば良い。


※ 基本的にInterface Builder(以下IB)を利用して画面を生成していくのですが、その方法だと裏側がどうなっているのかが理解できず、タブがあってナビゲーションもあるアプリのように複雑なものは理解しずらいのでは?と思います。そこで、IBを使用しないで作成する方法で記事を書いていきます。(個人的にIBはよくわからないっていうのが本音なんですけどね。笑) そのため、Window-based Application を使用していきます

次回は、その前提としてアプリケーションの画面の構成について自分なりにまとめてみます。
2011/05/30 0 コメント

Android - SQLiteでの複数レコード挿入

複数のレコードを追加するためのメソッドを作成しました。
conflictAlgorithm には, SQLiteDatabase.CONFLICT_NONE, SQLiteDatabase.CONFLICT_REPLACE などの, コンフリクトが発生した場合の処理を指定します。
また, transaction を true にした場合は, トランザクション処理を併用します。

/**
 * insert a lot of data
 *
 * @param nullColumnHack 
 * @param valueList 値のリスト
 * @param conflictAlgorithm コンフリクト発生時の処理
 * @param transaction トランザクション処理を併用するか否か
 * @return Boolean 成功 or 失敗
 */
public Boolean insertMany(SQLiteDatabase db , String table , String nullColumnHack, List<ContentValues> valueList, int conflictAlgorithm, Boolean transaction) {
    
    if(valueList != null && valueList.size() > 0){
        String[] CONFLICT_VALUES = new String[]{"", " OR ROLLBACK ", " OR ABORT ", " OR FAIL ", " OR IGNORE ", " OR REPLACE "};

        // At first, create sql statement
        ContentValues initialValues = valueList.get(0);
        
        // Measurements show most sql lengths <= 152
        StringBuilder sql_build = new StringBuilder(152);
        sql_build.append("INSERT");
        sql_build.append(CONFLICT_VALUES[conflictAlgorithm]);
        sql_build.append(" INTO ");
        sql_build.append(table);
        // Measurements show most values lengths < 40
        StringBuilder values = new StringBuilder(40);

        Set<Map.Entry<String, Object>> entrySet = null;
        
        if (initialValues != null && initialValues.size() > 0) {
            entrySet = initialValues.valueSet();
            Iterator<Map.Entry<String, Object>> entriesIter = entrySet.iterator();
            sql_build.append('(');

            boolean needSeparator = false;
            while (entriesIter.hasNext()) {
                if (needSeparator) {
                    sql_build.append(", ");
                    values.append(", ");
                }
                needSeparator = true;
                Map.Entry<String, Object> entry = entriesIter.next();
                sql_build.append(entry.getKey());
                values.append('?');
            }
            sql_build.append(')');
        } else {
            sql_build.append("(" + nullColumnHack + ") ");
            values.append("NULL");
        }

        sql_build.append(" VALUES(");
        sql_build.append(values);
        sql_build.append(");");
        String sql = sql_build.toString();
        
        SQLiteStatement statement = null;
        
        // if transaction id true, beginTransaction()
        if(transaction){
            db.beginTransaction();
        }
        try {
            for(int i=0,length=valueList.size(); i<length; i++){
                statement = db.compileStatement(sql);
                initialValues = valueList.get(i);
                entrySet = initialValues.valueSet();
                
                // Bind the values
                if (entrySet != null) {
                    int size = entrySet.size();
                    Iterator<Map.Entry<String, Object>> entriesIter = entrySet.iterator();
                    for (int j = 0; j < size; j++) {
                        Map.Entry<String, Object> entry = entriesIter.next();
                        DatabaseUtils.bindObjectToProgram(statement, j + 1, entry.getValue());
                    }
                }
                // Run the program and then cleanup
                statement.execute();
                statement.close();
            }
            
            // if transaction id true, setTransactionSuccessful()
            if(transaction){
                db.setTransactionSuccessful();
                db.endTransaction();
                transaction = false;
            }
            return true;
        } catch (SQLiteDatabaseCorruptException e) {
            throw e;
        } finally {
            if (statement != null) {
                statement.close();
            }
            // if transaction id true, endTransaction()
            if(transaction){
                db.endTransaction();
            }
        }
    }
    return false;
}
2011/05/10 0 コメント

Android - SQLite 文字列ソート

SQLiteの文字列ソートにおいて (SQLiteに限らず) , かな, 英字, 数字, 記号 の順番を群単位で変えたい場合は, そのためのフィールドを追加するのが一番簡単っぽい。というより、これしか思い浮かばなかった。

デフォルトだと<数字, 英字 .... >という順番だったが, ワードの頭文字に対して<かな, 記号(その他), 数字, 英語> という順番にソートしたかった。そこで, sortgroupというフィールドを目的のテーブルに作成する。

sortgroupの値は, 半角カナ → 1, 記号(その他) → 2, 数字 → 3, 英字 → 4 とする。

こうすれば, SELECT * FROM table ORDER BY sortgroup ASC みたいにすれば取ってこれるよね。

で、頭文字がどのタイプのものかを判別するためのプログラムは以下

public class CheckWordType {
    // 文字列が 半角カタカナ(1), その他(2), 数字(3), アルファベット(4)のどれかを調べる
    public int checkCharType(char c){
        if(c >= 0xff66 && c <= 0xff9d){ // 半角カタカナ (1) http://ash.jp/code/unitbl1.htm 参照
            return 1;
        }else if(Character.isLetter(c)){ // アルファベット (4)
            return 4;
        }else if(Character.isDigit(c)){ // 数字 (3)
            return 3;
        }else{ // その他 (2)
            return 2;
        }
    }
}

まぁ、まとめるほどの事でもないんだけど、書く記事がなかったんでw
2011/04/27 0 コメント

Android - プログラムでLinearLayoutのGravity属性を設定

LinearLayoutそのものを中央寄せしたい場合は, 以下のように LayoutParams の gravity 変数に値を設定すれば良い。

LinearLayout.LayoutParams lp =
    new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                                  LinearLayout.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_HORIZONTAL; 
view.setLayoutParams(lp);


view.setGravity(gravity); で設定しようとしてはまったのでメモ。
LinearLayout の小ビューの中央寄せはをする場合に, view.setGravity(gravity); を使うのかな?
0 コメント

Android - 画面の横幅と縦幅の取得

画面の横幅と縦幅を取得したい場合は以下の様にすれば良い

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;  // 横幅サイズを取得
int height = metrics.heightPixels;  // 縦幅サイズを取得

ちなみに, 幅が小さいほうが横幅, 大きいほうが縦幅というわけではなく, その時の画面の向きに対する横幅・縦幅です。
2011/04/20 0 コメント

MINE TYPE の一覧 (cakePHPより)

cakePHP1.3のmedia.phpで定義されているMINEタイプの一覧は以下のものとなっていた。
しっておくと便利かもしれないので、一応メモ!

var $mimeType = array(
    'ai' => 'application/postscript',
    'bcpio' => 'application/x-bcpio',
    'bin' => 'application/octet-stream',
    'ccad' => 'application/clariscad',
    'cdf' => 'application/x-netcdf',
    'class' => 'application/octet-stream',
    'cpio' => 'application/x-cpio',
    'cpt' => 'application/mac-compactpro',
    'csh' => 'application/x-csh',
    'csv' => 'application/csv',
    'dcr' => 'application/x-director',
    'dir' => 'application/x-director',
    'dms' => 'application/octet-stream',
    'doc' => 'application/msword',
    'drw' => 'application/drafting',
    'dvi' => 'application/x-dvi',
    'dwg' => 'application/acad',
    'dxf' => 'application/dxf',
    'dxr' => 'application/x-director',
    'eot' => 'application/vnd.ms-fontobject',
    'eps' => 'application/postscript',
    'exe' => 'application/octet-stream',
    'ez' => 'application/andrew-inset',
    'flv' => 'video/x-flv',
    'gtar' => 'application/x-gtar',
    'gz' => 'application/x-gzip',
    'bz2' => 'application/x-bzip',
    '7z' => 'application/x-7z-compressed',
    'hdf' => 'application/x-hdf',
    'hqx' => 'application/mac-binhex40',
    'ico' => 'image/vnd.microsoft.icon',
    'ips' => 'application/x-ipscript',
    'ipx' => 'application/x-ipix',
    'js' => 'application/x-javascript',
    'latex' => 'application/x-latex',
    'lha' => 'application/octet-stream',
    'lsp' => 'application/x-lisp',
    'lzh' => 'application/octet-stream',
    'man' => 'application/x-troff-man',
    'me' => 'application/x-troff-me',
    'mif' => 'application/vnd.mif',
    'ms' => 'application/x-troff-ms',
    'nc' => 'application/x-netcdf',
    'oda' => 'application/oda',
    'otf' => 'font/otf',
    'pdf' => 'application/pdf',
    'pgn' => 'application/x-chess-pgn',
    'pot' => 'application/mspowerpoint',
    'pps' => 'application/mspowerpoint',
    'ppt' => 'application/mspowerpoint',
    'ppz' => 'application/mspowerpoint',
    'pre' => 'application/x-freelance',
    'prt' => 'application/pro_eng',
    'ps' => 'application/postscript',
    'roff' => 'application/x-troff',
    'scm' => 'application/x-lotusscreencam',
    'set' => 'application/set',
    'sh' => 'application/x-sh',
    'shar' => 'application/x-shar',
    'sit' => 'application/x-stuffit',
    'skd' => 'application/x-koan',
    'skm' => 'application/x-koan',
    'skp' => 'application/x-koan',
    'skt' => 'application/x-koan',
    'smi' => 'application/smil',
    'smil' => 'application/smil',
    'sol' => 'application/solids',
    'spl' => 'application/x-futuresplash',
    'src' => 'application/x-wais-source',
    'step' => 'application/STEP',
    'stl' => 'application/SLA',
    'stp' => 'application/STEP',
    'sv4cpio' => 'application/x-sv4cpio',
    'sv4crc' => 'application/x-sv4crc',
    'svg' => 'image/svg+xml',
    'svgz' => 'image/svg+xml',
    'swf' => 'application/x-shockwave-flash',
    't' => 'application/x-troff',
    'tar' => 'application/x-tar',
    'tcl' => 'application/x-tcl',
    'tex' => 'application/x-tex',
    'texi' => 'application/x-texinfo',
    'texinfo' => 'application/x-texinfo',
    'tr' => 'application/x-troff',
    'tsp' => 'application/dsptype',
    'ttf' => 'font/ttf',
    'unv' => 'application/i-deas',
    'ustar' => 'application/x-ustar',
    'vcd' => 'application/x-cdlink',
    'vda' => 'application/vda',
    'xlc' => 'application/vnd.ms-excel',
    'xll' => 'application/vnd.ms-excel',
    'xlm' => 'application/vnd.ms-excel',
    'xls' => 'application/vnd.ms-excel',
    'xlw' => 'application/vnd.ms-excel',
    'zip' => 'application/zip',
    'aif' => 'audio/x-aiff',
    'aifc' => 'audio/x-aiff',
    'aiff' => 'audio/x-aiff',
    'au' => 'audio/basic',
    'kar' => 'audio/midi',
    'mid' => 'audio/midi',
    'midi' => 'audio/midi',
    'mp2' => 'audio/mpeg',
    'mp3' => 'audio/mpeg',
    'mpga' => 'audio/mpeg',
    'ra' => 'audio/x-realaudio',
    'ram' => 'audio/x-pn-realaudio',
    'rm' => 'audio/x-pn-realaudio',
    'rpm' => 'audio/x-pn-realaudio-plugin',
    'snd' => 'audio/basic',
    'tsi' => 'audio/TSP-audio',
    'wav' => 'audio/x-wav',
    'asc' => 'text/plain',
    'c' => 'text/plain',
    'cc' => 'text/plain',
    'css' => 'text/css',
    'etx' => 'text/x-setext',
    'f' => 'text/plain',
    'f90' => 'text/plain',
    'h' => 'text/plain',
    'hh' => 'text/plain',
    'htm' => 'text/html',
    'html' => 'text/html',
    'm' => 'text/plain',
    'rtf' => 'text/rtf',
    'rtx' => 'text/richtext',
    'sgm' => 'text/sgml',
    'sgml' => 'text/sgml',
    'tsv' => 'text/tab-separated-values',
    'tpl' => 'text/template',
    'txt' => 'text/plain',
    'xml' => 'text/xml',
    'avi' => 'video/x-msvideo',
    'fli' => 'video/x-fli',
    'mov' => 'video/quicktime',
    'movie' => 'video/x-sgi-movie',
    'mpe' => 'video/mpeg',
    'mpeg' => 'video/mpeg',
    'mpg' => 'video/mpeg',
    'qt' => 'video/quicktime',
    'viv' => 'video/vnd.vivo',
    'vivo' => 'video/vnd.vivo',
    'gif' => 'image/gif',
    'ief' => 'image/ief',
    'jpe' => 'image/jpeg',
    'jpeg' => 'image/jpeg',
    'jpg' => 'image/jpeg',
    'pbm' => 'image/x-portable-bitmap',
    'pgm' => 'image/x-portable-graymap',
    'png' => 'image/png',
    'pnm' => 'image/x-portable-anymap',
    'ppm' => 'image/x-portable-pixmap',
    'ras' => 'image/cmu-raster',
    'rgb' => 'image/x-rgb',
    'tif' => 'image/tiff',
    'tiff' => 'image/tiff',
    'xbm' => 'image/x-xbitmap',
    'xpm' => 'image/x-xpixmap',
    'xwd' => 'image/x-xwindowdump',
    'ice' => 'x-conference/x-cooltalk',
    'iges' => 'model/iges',
    'igs' => 'model/iges',
    'mesh' => 'model/mesh',
    'msh' => 'model/mesh',
    'silo' => 'model/mesh',
    'vrml' => 'model/vrml',
    'wrl' => 'model/vrml',
    'mime' => 'www/mime',
    'pdb' => 'chemical/x-pdb',
    'xyz' => 'chemical/x-pdb'
);
2011/04/18 0 コメント

Android - HTTP-POST通信を行う

HTTPのPOST処理を行う場合は, 以下のようにすればOK.

/**
 * HTTP POSTを行う
 *
 * @param url HTTP通信を行うターゲットのURL
 * @param requestParams パラメータ
 * @param encode HTTP要求時の文字コード
 * @return 受信結果の文字列
 */
public String httpPostRequest( String url, Map<String, String> requestParams, String encode ){
 try{        
  HttpPost httppost = new HttpPost( url );
     DefaultHttpClient client = new DefaultHttpClient();
 
     // リクエストパラメータの設定
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        for (Map.Entry<String, String> entry : requestParams.entrySet()) {
            params.add(new BasicNameValuePair((String) entry.getKey(), (String) entry.getValue()));
        }
 
     // POST データの設定
     httppost.setEntity(new UrlEncodedFormEntity(params, encode));

     HttpResponse response = client.execute( httppost );
     int status = response.getStatusLine().getStatusCode();
 
     // 結果が正しく帰って来なければエラー
     if ( status != HttpStatus.SC_OK ){ throw new Exception( "" ); }
 
     return EntityUtils.toString( response.getEntity());
 }catch ( Exception e ){
  return null;
 }
}


POST データを付加する際,
httppost.setEntity(new UrlEncodedFormEntity(params, encode));
とするが, ここで第二引数に, ちゃんと encode を指定してあげること。
内部エンコードがUTF-8だろうからって指定しなかったために、えらい目に会いました。

Webプログラム (PHP等) でもそうだけど、文字コードは明示的にちゃんと指定してあげなきゃだめですね。猛省。。。
2011/04/07 0 コメント

動作しているサービスの一覧について

動作しているサービスの一覧は,


chkconfig --list というコマンドで把握できる。出力例は以下



NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid           0:off 1:off 2:on 3:on 4:on 5:on 6:off
anacron         0:off 1:off 2:off 3:off 4:off 5:off 6:off
atd             0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd         0:off 1:off 2:off 3:off 4:off 5:off 6:off
     :
     :
wpa_supplicant 0:off 1:off 2:off 3:off 4:off 5:off 6:off
xfs             0:off 1:off 2:off 3:off 4:off 5:off 6:off
ypbind         0:off 1:off 2:off 3:off 4:off 5:off 6:off
yum-updatesd   0:off 1:off 2:off 3:off 4:off 5:off 6:off


ここで 0 ~ 6 の数字はランレベルを表しており,


0 : システムの停止
1 : シングルユーザーモード
2 : マルチユーザーモード(NFSなし)
3 : マルチユーザーモード(テキストログイン)
4 : 未使用
5 : マルチユーザーモード(グラフィカルログイン)
6 : システムの再起動

である。ちなみに,  ランレベルについては こちら

2011/04/05 0 コメント

Android - 画面の向きの固定方法

画面の向きを固定したい!という場合があると思います。
その場合は, 以下の様にすれば良い。

// 画面の向きを固定
public void fixDisplayOrientation(){
    Configuration config = getResources().getConfiguration();
    if(config.orientation == Configuration.ORIENTATION_PORTRAIT){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }else if (config.orientation == Configuration.ORIENTATION_LANDSCAPE){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

// 画面の向きの固定を解除
public void unfixDisplayOrientation(){
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

ここで, 画面の向きを取得するとき, config.orientation の値を使用。
Configuration.ORIENTATION_PORTRAIT なのか Configuration.ORIENTATION_LANDSCAPE なのかで判断する。


しかし, 画面の向きを設定するとき, は, setRequestedOrientation(int orientation) に与える引数の値は, Configuration.ORIENTATION_PORTRAIT や Configuration.ORIENTATION_LANDSCAPE ではなく, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT または ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE なので注意!
2011/04/04 0 コメント

Android - IMEの表示/非表示

IMEをプログラムで表示/非表示の切り替えを行いたかったので、その時のメモ。

まずは表示方法から
// 表示方法
EditText et = (EditText)findViewById(R.id.edittext);

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);

次に非表示にする方法
// 非表示方法
imm.hideSoftInputFromWindow(v.getWindowToken(),0);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

とりあえずこれで出来ました。
2011/04/01 0 コメント

Android - ローディング画像を表示する

画像読み込み中にローディング画像を表示させたい (クルクル回るやつ)。
この場合, Androidに用意されている ProgressBar を使用すれば良い。(gifアニメーションで実現しようとする場合は, 結構めんどくさそう)

<ProgressBar
    android:id="@+id/product_image_loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/progressBarStyle"/>

これだけでOK。

以下は例, 上から順に, styleは
progressBarStyleSmall
progressBarStyle
progressBarStyleLarge
progressBarStyleHorizontal
です。progressBarStyleHorizontal には, android:indeterminate="true" も指定してある。

2011/03/30 0 コメント

Android - colors.xml について

res/values/ に, colors.xmlというファイルを作成する (以下はその例)。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="color1">#ff66cdaa</color>
    <color name="color2">#ffff89c4</color>
    <color name="color3">#ffAAAAAA</color>
</resources>

こうすることで, 独自の色を定義することができる。

xml から使用する場合は, android:background="@color/color1" などというように, @color/ で指定して上げれば良い。

プログラム中から使用する場合は, 例として
int color = getResources().getColor(R.color.color1);
view.setBackgroundColor(color); としてあげればOK。


view.setBackgroundColor(R.color.color1)という指定をしてしまってハマったのでメモメモ。
 
;