SQLの窓

2012年09月28日


Windows8(C#) 2ページテンプレート



ページ追加に関しては、Visual Studio 2012 が正常なら普通にページ追加するだけなのですが、フリーズするという現象が起きているので、テンプレートを作成して運用しています。

「C:\Users\ユーザ名\Documents\Visual Studio 2012\Templates\ProjectTemplates\Visual C#」ディレクトリに「Windows Store」ディレクトリを作成し、その中にテンプレートを入れる

また、Microsoft の解説ページにある『クイック スタート: アプリ バーの追加』 を付加してあります。

だいたいのソースコードは以下から参照できます。

MainPage : xaml / cs
BasicPage1 : xaml / cs

特に以下の部分は、WebView をキャプチャして、Rectangle に書き込むところなのでチェックしておくといいと思います。
private void AppBar_Opened(object sender, object e)
{
	WebViewBrush wvb = new WebViewBrush();
	wvb.SourceName = "contentView";
	wvb.Redraw();
	contentViewRect.Fill = wvb;
	contentView.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}

ドキュメントリンク

windows8


posted by lightbox at 2012-09-28 22:26 | Win8 ストアアプリ | このブログの読者になる | 更新情報をチェックする

2012年09月27日


google-gson で、JSON 文字列の構成要素の一覧を取り出す処理

実用の場合は、JSON に対応するクラスを作成してデシリアライズするはずですが、てっとりばやく処理するのならこちらのほうが簡単です。

※ データは、Twitter のデータを使っていますが、Array が無かったのでこのコードでは対応していません。
package winofsql.jp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		System.out.println("開始");
		
		String json_string = "{ \"姓\": \"山田\", \"名\": \"太郎\", \"age\": 53 }";

		test.print_json(json_string,1);

		json_string = "";
		
		try {
			// ターゲット
			URL url = new URL("http://textt.net/sworc/20120924055943.txt");
			// 接続オブジェクト
			HttpURLConnection http = (HttpURLConnection)url.openConnection();
			// GET メソッド 
			http.setRequestMethod("GET");
			// 接続 
			http.connect();
			 
			// EUC-JP でリーダーを作成
			InputStreamReader isr = new InputStreamReader(http.getInputStream(), "UTF-8");   
			// 行単位で読み込む為の準備   
			BufferedReader br = new BufferedReader(isr);   
			String line_buffer;   
			// BufferedReader は、readLine が null を返すと読み込み終了   
			while ( null != (line_buffer = br.readLine() ) ) {   
				// コマンドプロンプトに表示   
				json_string += line_buffer;
			}
 
			// 各々受け持ちクラスを閉じる   
			br.close();
			isr.close();
			http.disconnect();
		}
		catch( Exception e ) {}
		
		System.out.println("★-->");
		test.print_json(json_string,2);
		
	}

	private static void print_json( String json_string, int type ) {
		
		// パーサーを取得
		JsonParser jp = new JsonParser();
		// 文字列をパース
		JsonElement je = jp.parse(json_string);

		// key と value を取得する為に、JsonObject から、entrySet メソッドを実行
		Set<Map.Entry<String, JsonElement>> entrySet = je.getAsJsonObject().entrySet();

		// イテレータを取得
		Iterator<Map.Entry<String, JsonElement>> it = entrySet.iterator();

		// 一覧表示
		while(it.hasNext())
		{
			Map.Entry<String, JsonElement> entry = it.next();

			String key = entry.getKey();
			JsonElement value = entry.getValue();

			System.out.print(key+" : ");
			if ( value.isJsonObject() ) {
				System.out.println("★-->");
				print_json( value.toString(), 2 );
			}
			else {
				if ( value.isJsonNull() ) {
					System.out.println("NULL");
				}
				else {
					System.out.println(value.getAsString());
				}
			}
			// value.toString() だと、個別の文字列の場合 " で挟まれた文字列が取得されました
		}
		
		if ( type == 1 ) {
			// ***************************************
			// メンバ名で値を取得
			// ***************************************
			JsonObject jo = je.getAsJsonObject();
				System.out.println(jo.get("姓").getAsString());
				System.out.println(jo.get("名").getAsString());
				System.out.println(jo.get("age").getAsInt());
		}
		else {
			System.out.println("<--★");
		}

	}


}


▼ 結果

開始
姓 : 山田
名 : 太郎
age : 53
山田
太郎
53
★-->
id : 91500526
profile_background_tile : false
notifications : false
profile_sidebar_fill_color : FFF7CC
location : 大阪府
screen_name : sworc
profile_image_url : http://a0.twimg.com/profile_images/2388651010/zmq5cwm5nsvngpfrtr3f_normal.png
contributors_enabled : false
utc_offset : 32400
time_zone : Osaka
is_translator : false
default_profile : false
profile_background_color : 000000
name : night w?lker
geo_enabled : false
lang : ja
protected : false
profile_background_image_url : http://a0.twimg.com/profile_background_images/59645045/bbs_img_4598c0b36c78d.jpg
id_str : 91500526
listed_count : 6
profile_link_color : FF0000
follow_request_sent : false
description : 絵を描くプログラマ。好きな食べ物は水餃子。手書きブログ。DAZ3D。GIMP。Three.js。フリーフォントで簡単ロゴ作成 http://lightbox.on.coocan.jp/html/fontImage.php http://goo.gl/HDqTM
profile_use_background_image : true
following : false
profile_text_color : 0C3E53
url : http://winofsql.jp/
friends_count : 25
profile_background_image_url_https : https://si0.twimg.com/profile_background_images/59645045/bbs_img_4598c0b36c78d.jpg
created_at : Sat Nov 21 04:24:25 +0000 2009
default_profile_image : false
profile_sidebar_border_color : F2E195
verified : false
status : ★-->
in_reply_to_status_id_str : NULL
geo : NULL
place : NULL
created_at : Sun Sep 23 16:49:33 +0000 2012
in_reply_to_user_id_str : NULL
retweeted : false
in_reply_to_screen_name : NULL
truncated : false
possibly_sensitive_editable : true
possibly_sensitive : false
id_str : 249913404016427008
contributors : NULL
in_reply_to_status_id : NULL
in_reply_to_user_id : NULL
favorited : false
source : <a href="http://winofsql.jp/" rel="nofollow">TwitLink</a>
coordinates : NULL
id : 249913404016427008
retweet_count : 0
text : 家に持ち帰った mdb で簡単に php からアクセスしてテストプログラムを作る( DBクラス付き ) http://t.co/bDzKDGLY
<--★
favourites_count : 1
statuses_count : 6120
profile_image_url_https : https://si0.twimg.com/profile_images/2388651010/zmq5cwm5nsvngpfrtr3f_normal.png
followers_count : 55
<--★




タグ:JSON
posted by lightbox at 2012-09-27 21:20 | java : 通信関連 | このブログの読者になる | 更新情報をチェックする

2012年09月21日


android-binding を使用した、固定値、イベント、オプションメニューの構築


Google ドライブからダウンロード



バインドの方法としては、BindingActivityV30 + inflateAndBind を使うのが最新なのですが、作者さんの最新のサンプルがまだそれを使って無いのでここでは利用していません。それを利用すると、Android の最新バージョンで ActionBar を使う事を簡単に変更できるようです( メイン画面とメニューと ActionBar を一つの XML で定義します / 動作確認はしました )

プロジェクト作成の基本部分

android-binding を使って Windows C#(XAML) のようなバインド処理の実装

画面定義
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:binding="http://www.gueei.com/android-binding/"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        binding:text="hello"
        tools:context=".P1Activity" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        binding:text="button_value" 
        binding:onClick="Button_Click_1"/>

</RelativeLayout>



メニュー定義
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:binding="http://www.gueei.com/android-binding/">
    <item android:id="@+id/menu_settings"
        binding:title="bind_menu"
        android:orderInCategory="100"
        android:showAsAction="never" 
        binding:onClick="Menu_Click_1"/>
</menu>



BindingActivity

bindModel.button_value.set("ボタン"); は、クラス内で初期設定するのでは無く、外から設定した例です。また、メイン画面用のオブジェクトをメニューに引き渡して、メニュー処理から本体画面のバインド処理を行えるようにしています。( 別に分ける必要はありませんが、分けたとしたらこんな感じかと思います )

package winofsql.jp;

import gueei.binding.Binder;
import gueei.binding.app.BindingActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.support.v4.app.NavUtils;

public class P1Activity extends BindingActivity  {

    private BindModel bindModel = new BindModel();
    private BindModelMenu bindModelMenu = new BindModelMenu(bindModel);
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        bindModel.button_value.set("ボタン");
        this.setAndBindRootView(R.layout.activity_p1, bindModel);
        this.setAndBindOptionsMenu(R.menu.activity_p1, bindModelMenu);
    }
    
}


メイン画面のバインド用クラス
package winofsql.jp;

import android.view.View;
import gueei.binding.Command;
import gueei.binding.observables.StringObservable;
import gueei.binding.pojo.PojoViewModel;
import gueei.binding.pojo.PojoViewModelHelper;

public class BindModel implements PojoViewModel {

    private PojoViewModelHelper helper = new PojoViewModelHelper();
    
    public final StringObservable hello = new StringObservable("こんにちは");
    public final StringObservable button_value = new StringObservable();

    public final Command Button_Click_1 = new Command() {
        @Override
        public void Invoke(View arg0, Object... arg1) {
        	hello.set("はじめまして");
        }
    };
    
    @Override
    public PojoViewModelHelper getHelper() {
        return helper;
    }
 
    @Override
    public void notifyPropertyChanged( String propertyName ) {
        helper.notifyPropertyChanged( propertyName );
    }

}


メニュー用のバインド用クラス
※ メイン画面用の中に書いて共用してもいいです
package winofsql.jp;

import android.view.View;
import gueei.binding.Command;
import gueei.binding.observables.StringObservable;
import gueei.binding.pojo.PojoViewModel;
import gueei.binding.pojo.PojoViewModelHelper;

public class BindModelMenu implements PojoViewModel {

    private PojoViewModelHelper helper = new PojoViewModelHelper();
	private BindModel bindModel;
    
    public final StringObservable bind_menu = new StringObservable("バインドメニュー");

    public final Command Menu_Click_1 = new Command() {
        @Override
        public void Invoke(View arg0, Object... arg1) {
        	BindModelMenu.this.bindModel.hello.set("メニューから変更");
        }
    };

	public BindModelMenu(BindModel bindModel) {
		this.bindModel = bindModel;
	}
 
    @Override
    public PojoViewModelHelper getHelper() {
        return helper;
    }
 
    @Override
    public void notifyPropertyChanged( String propertyName ) {
        helper.notifyPropertyChanged( propertyName );
    }

}


posted by lightbox at 2012-09-21 14:25 | Android | このブログの読者になる | 更新情報をチェックする
Seesaa の各ページの表示について
Seesaa の 記事がたまに全く表示されない場合があります。その場合は、設定> 詳細設定> ブログ設定 で 最新の情報に更新の『実行ボタン』で記事やアーカイブが最新にビルドされます。

Seesaa のページで、アーカイブとタグページは要注意です。タグページはコンテンツが全く無い状態になりますし、アーカイブページも歯抜けページはコンテンツが存在しないのにページが表示されてしまいます。

また、カテゴリページもそういう意味では完全ではありません。『カテゴリID-番号』というフォーマットで表示されるページですが、実際存在するより大きな番号でも表示されてしまいます。

※ インデックスページのみ、実際の記事数を超えたページを指定しても最後のページが表示されるようです

対処としては、このようなヘルプ的な情報を固定でページの最後に表示するようにするといいでしょう。具体的には、メインの記事コンテンツの下に『自由形式』を追加し、アーカイブとカテゴリページでのみ表示するように設定し、コンテンツを用意するといいと思います。


※ エキスパートモードで表示しています

アーカイブとカテゴリページはこのように簡単に設定できますが、タグページは HTML 設定を直接変更して、以下の『タグページでのみ表示される内容』の記述方法で設定する必要があります

<% if:page_name eq 'archive' -%>
アーカイブページでのみ表示される内容
<% /if %>

<% if:page_name eq 'category' -%>
カテゴリページでのみ表示される内容
<% /if %>

<% if:page_name eq 'tag' -%>
タグページでのみ表示される内容
<% /if %>
この記述は、以下の場所で使用します
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり