2013年8月15日木曜日

エクセル16進数10進数2進数を変換する関数

n進数のデータを作成する際のメモ


BIN2DEC(String) 2 進数を 10 進数に変換 
BIN2HEX(String) 2 進数を 16 進数に変換 
BIN2OCT(String) 2 進数を 8 進数に変換 
DEC2BIN(String) 10 進数を 2 進数に変換 
DEC2HEX(String) 10 進数を 16 進数に変換 
DEC2OCT(String) 10 進数を 8 進数に変換 
HEX2BIN(String) 16 進数を 2 進数に変換 
HEX2DEC(String) 16 進数を 10 進数に変換 
HEX2OCT(String) 16 進数を 8 進数に変換 
OCT2BIN(String) 8 進数を 2 進数に変換 
OCT2DEC(String) 8 進数を 10 進数に変換 
OCT2HEX(String) 8 進数を 16 進数に変換 

エクセルの関数は便利です。

2013年8月13日火曜日

HTMLとJAVAScriptの難読化

でこんぱいるIPA
HTMLで作成したアプリはOSに依存しないためiOSとANDROIDの同時開発が可能になります。
WebプログラマーならJAVAScriptとCSSに慣れていて有利かもしれません。
Web Workersスレッドでマルチスレッドも可能になってきていますし。

問題はリソースを難読化しないとアプリを改ざんして再配布されてしまうことです。
現にいくつのアプリか不正な配布が行われていますが、グーグルプレイやアップルストアは開発者の権利を守ってはくれません。

JAVAは特にデコンパイルしやすいのでHTMLメインでアプリを作成すると、
簡単に復元、改ざんされてしまいます。

タイタニウムは難読化機能を備えていません。事前にHTMLを暗号化して、ネイティヴに複合する必要があります。

プログラマーに向いているタイプ


プログラマーIQ


情報系の学生から、自分がプログラマーに向いているか知りたいと聞かれることがあります。
私は「自力でソートを書いてみて」と返すのですが、フローチャートを書くのも慣れないと難しいのかもしれません。今の時代ソート処理なんか誰かがやってくれます。私自身クイックソートはコピペしますし。。

一般的にSEやプログラマーは頭がよさそうなイメージなようです。
テレビドラマのスーパーハカーのイメージなのでしょうか。

職種別IQを見てみると

医者や弁護士は最低でも東大生レベルのIQ130以上が必要。
ちなみに日本人の平均IQは115です。

プログラマーは最低でもIQ100以上。
日本人の6割はプログラマーになれるIQです。
一般からみるとプログラマーのIQは高さそうですが、
世界の平均IQが100ですから、大したことはありません。

まず言えることはプログラマーにIQの高さは必要ない


プログラマに必要なのはCISCよりRISC的なCPU。
それと高速で大きなVRAMです。

例えると、パソコンよりもゲーム機。

具体的には、目的から過程を想像し、論理だてる能力。
感覚的に大量の事象を組み合わせることです。
ようはパズルです。ピタゴラスイッチです。
説明書なしに道具を扱ったり、組み立てることが得意な人が、
プログラマーに向いています。

経験から統計を出すと、
IT系企業に入ってくる5人に1人はプログラマーに向いています。
向いている一人は、瞬時に論理だててプログラムを書いていけるタイプ。
他の2人は普通。時間はかかるがプログラミング可能程度のタイプ。
残りの2人は全く使えない。「なぜこうなる?」で固まってしまう。思考が停止するタイプ。
重要なのは目的から過程をイメージすること、始まりと結果だけを捉えること。
1+1=2であること以外は考えない。1が何故1であるかを考えても意味がないことです。
複数の結果から類推し、必要な結果を部品として得る。それを組み合わせることで目的を完成させる。それがプログラムです。

誇張して表現しているところもありますが、
向いている人とそうでない人で生産性が数倍違うのがIT業界です。

2013年8月12日月曜日

ソフトウエアゲームコントローラーのサンプル

アクションゲームでは見えないコントローラーを作ってみましたが、RPGなどではボタンの表示が必要です。

ゲーム開発コントロールサンプル画像

今回はレイアウトファイルでコントローラーを作成してみました。

この場合はクリックイベントではなく、タッチイベントを使用します。

サーフェースビューでコントローラーを作成しても良いのですが、
一部GUIにスクロール機能を付けたかったため手抜きをしました。
できるだけコードは書きたくないので。。


ボタンを大きくすると、どうしてもゲーム画面が小さくなってしまいます。
しかし、綺麗なグラフィックを売りにするつもりはありませんので、
操作性を重視してコントローラーを大きめにしています。


サンプルソースはこちら

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/lay1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="vertical" >

        <com.example.gametest2.GameView
            android:id="@+id/gameView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lay_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="20"
        android:orientation="vertical" >

        <MultiAutoCompleteTextView
            android:id="@+id/multiAutoCompleteTextView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:text="MultiAutoCompleteTextView" >

            <requestFocus />
        </MultiAutoCompleteTextView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lay2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/scr1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/sute"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Status" />

            <Button
                android:id="@+id/aitemu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_weight="1"
                android:text="Tool" />

            <Button
                android:id="@+id/sukiru"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="8dp"
                android:layout_weight="1"
                android:text="Skill" />

            <Button
                android:id="@+id/sisutemu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="System" />

        </LinearLayout>
        </ScrollView>

        <LinearLayout
            android:id="@+id/lay_jyuji"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.50"
                android:orientation="vertical" >

                <Button
                    android:id="@+id/jyuuji7"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="○" />

                <Button
                    android:id="@+id/jyuuji4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="←" />

                <Button
                    android:id="@+id/jyuuji1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="○" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.50"
                android:orientation="vertical" >

                <Button
                    android:id="@+id/jyuuji8"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="↑" />

                <Button
                    android:id="@+id/jyuuji5"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="□" />

                <Button
                    android:id="@+id/jyuuji2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="↓" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.50"
                android:orientation="vertical" >

                <Button
                    android:id="@+id/jyuuji9"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="○" />

                <Button
                    android:id="@+id/jyuuji6"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="→" />

                <Button
                    android:id="@+id/jyuuji3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="○" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/lay_atk"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="15dp"
                android:orientation="vertical" >

                <Button
                    android:id="@+id/houkou"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="⇔" />

                <Button
                    android:id="@+id/kougeki"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ATK" />
                
                <!--Android 縦方向に均等に  -->
            </LinearLayout>
        </LinearLayout>



    </LinearLayout>

</LinearLayout>



カスタムダイアログ サンプル

カスタムダイアログのさんぷる

カスタムダイアログ


カスタムダイアログ用のクラス作成して部品化してみました。

呼び出し
Daiarogu dl = new Daiarogu();
dl.create(this);

Daiarogu クラス 
    public void Create(Activity act) {
   
        // カスタムビュー
        LayoutInflater inflater = (LayoutInflater)act.getSystemService(
        act.LAYOUT_INFLATER_SERVICE);
        final View layout = inflater.inflate(R.layout.daiarogu,
        (ViewGroup)act.findViewById(R.id.daiarogu_lay));

        // ダイアログ
        AlertDialog.Builder builder = new AlertDialog.Builder(act);
        
        show(builder,layout);
    }
    
    private void show(Builder builder,View layout){
   
        builder.setTitle("タイトル");
        builder.setView(layout);
        
        ImageView iv
        = (ImageView)layout.findViewById(R.id.daiarogu_gazo);//仮の
        
        TextView pass
        = (TextView)layout.findViewById(R.id.daiarogu_text);
        
        pass.setText("てすと1");
        
        builder.setPositiveButton("Positive", new OnClickListener () {
            public void onClick(DialogInterface dialog, int which) {
                // android4以降なら右

            }
        });
        builder.setNegativeButton("Negative", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // android4移行なら左
            }
        });
        builder.setNeutralButton("Neutral", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // android4移行なら中央
            }
        });

        // 表示
        builder.create().show();
    }

DAIARGO.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/daiarogu_lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/daiarogu_gazo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/daiarogu_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.50"
        android:gravity="center_vertical"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />


</LinearLayout>


2013年8月11日日曜日

GooglePlay新規参入は困難

グーグルプレイは人気の高いアプリを検索結果上位に表示します。

検索キーワードと関係のないアプリで検索結果が溢れることも珍しくない。

ダウンロード数の少ないアプリはキーワードに関連しようが表示されません

つまり、

ダウンロード数が多いアプリ = ダウンロードされやすくなる

新規参入 ダウンロードが少ないアプリ = ダウンロードがされにくくなる

ダウンロードが少ないアプリはダウンロードされにくため。
永遠にダウンロードが少ないままとなる。

どんなに良いアプリでもダウンロードされなければ誰にも見えない


企業なら広告で補うこともできるが初期費用が嵩むこと間違いない。

せめてアマゾンのようにアプリに検索キーワードを指定できれば、
関係のないアプリが検索結果に表示されなくなるのに。


ディスプレイサイズを取得する

API Levele13からディスプレイサイズの取得方法が変わりました。
昔のコードも使えますが念のため覚書

アクションバーやステータスバーのサイズも考慮しなくてはいけない。

   WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
   Display disp = wm.getDefaultDisplay();
   
   int haba=0,taka=0;
   
   try{//API Levele12以下
   
   taka = disp.getHeight();
      haba =  disp.getWidth();
   }catch(Exception e){
    e.printStackTrace();
   }
   
   if(haba<=0){//API Levele13以上
   Point size = new Point();
   disp.getSize(size);
   
   haba = size.x;
   taka =size.y;
   }