androidで時間を表示する

fun changeTextView(view: View){
        var calendar = Calendar.getInstance()
        val minute = calendar.get(Calendar.MINUTE)

        messageTextView.text = "Hello android!"
        textView.text = minute.toString()
    }

勝手が異なるから、スクリーンショットの転送も最初は一仕事だ。

valは変更不可
varは変更可

Android studioのEmulatorが遅すぎるので、実機でテストする

今回使うのは、HT17 android version 6.0(数年前に開発用としてほぼ新品で6000円くらいで買いました)

HT17
(1)Setting -> Dveloper optionsのDebuggingでUSB debuggingをonにする。
(2)Setting -> Personal -> Security -> Device administration -> Unknown sourcesをonにする
(3)windos | mac にUBSでつなぐ。

Android studio
(4)studio のDeploymentでConnected Devicesで、{$device}(HOMTOM HT17)を選択する。
(5)Runで実機に反映される!!!

きた~ ひゃっぽい!!!!!!!!!!gradle finishが1mくらいに改善。 エミュレーター遅すぎて、android開発撤退しようかと思ってたけど、良かった良かった!!!

デバックが解決したので、では少しずつ作っていきましょう♪

kotolinのtextを変えます。

fun changeTextView(view: View){
        messageTextView.text = "Hello android!"
    }

文字の変更が反映されてますね。

では、textViewを追加してみます。

fun changeTextView(view: View){
        messageTextView.text = "Hello android!"
        textView.text = "Hello android!"
    }

apply changeを押すと、buildが9sくらいに短縮されました。感動

build.gradle(module:app)

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "jp.hoge.anew"
        minSdkVersion 15
        targetSdkVersion 26
        resConfigs "ja", "xxhdpi"
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            ext.enableCrashlytics = false
        }
    }
    aaptOptions {
        cruncherEnabled false
    }
}

少し早くなった印象。

layout fileを表示する

studioアップロードしてここまでに1日かかった。。

iOS・Androidの開発の完成・納品の流れまでがいまいちイメージわかないので、Cacooでワイヤーを書いて、up workで依頼して流れをつかむことにした。

ああああ、なるほど!
API, frameworks, dependency injection libraries, databaseなどが項目としてあるのね!

Frame workはAGL、Angular、Appcelerator Titanium、Corona SDK、Framework7、Intel XDK
DBはCouchbase, LevelDB, Realm, SQLiteか。SQLite以外は使ったことない。やばいな、これ。

Android版もpostします。

うわ、android・iOS開発している人たちって、フルスタック+インフラも当然+なんでもできます系ばっかりだな。しかも、大量に。
しかも、皆さんストアーのアプリのリンクがポートフォリオなんだ。
それがスタンダードか、完全にマーケットのモノサシ誤ってた。。カスじゃん、俺。

しかし、5年以上のexperienceの人の作品中心にインストールしたけど、クオリティ高いし凄いっすわ。
完全に自分のレベルの低さ加減がわかりました。終わってる。
つくっていくしかないけど、これ追いつく・近づくのに1年くらいかかるかもしれんな~。。。GW終わりってのに、きっついな~

show line number

shift + shiftでsearch

show line number on or off で行番号の表示非表示を設定

app -> manifests -> androidManifest.xml

<activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

基本的には
layout activity_main.xml -> MainActivity 必要に応じてAndroidManifest.xml

vagrant->azureでwebappを作っていく

azure CLIにてplanをつくって、webappをcreate

az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku FREE
az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name boj-zh --runtime "PHP|7.0" --deployment-local-git

local

[vagrant@localhost azure]$ git init
[vagrant@localhost azure]$ git add *
[vagrant@localhost azure]$ git commit -m "initial commit"

[vagrant@localhost azure]$ git remote add azure https://name@boj-zh.scm.azurewebsites.net/boj-zh.git
[vagrant@localhost azure]$ git push azure master
Password for 'https://name@boj-zh.scm.azurewebsites.net':

azureに載りました。わーいわーい
若干気になるのは、ローカル(vagrant)と、azure(上)だと翻訳のされ方が違う。。何故?気になるな。

もうちょっとやりたいところだが、、、さーアプリやろう!!
Let’s Go!


iOSもやりますが、まずはandroidから。
welcome back!

最新の日銀金融政策を中国語で自動表示する

最新バージョンだけなら、難なくいけますね。


$text = $titles[0]."<br><br>";

foreach(glob("file/".$y."/{*.txt}",GLOB_BRACE) as $file){
    if(is_file($file)){
        $files[] = htmlspecialchars($file);
    }
}
// var_dump($files);

	$file = fopen($files[0], "r");
	if($file){
		while ($line = fgets($file)){
			$text .= $line;
		}
	}
	fclose($file);

	

	$key = '';

	$host = "https://api.cognitive.microsofttranslator.com";
	$path = "/translate?api-version=3.0";
	$params = "&to=zh";

	if(!function_exists('com_create_guid')){
		function com_create_guid(){
			return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
			mt_rand(0, 0xffff), mt_rand(0, 0xffff),
			mt_rand(0, 0xffff),
			mt_rand(0, 0x0fff) | 0x4000,
			mt_rand(0, 0x3fff) | 0x8000,
			mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
		}
	}

	function Translate ($host, $path, $key, $params, $content) {
	    $headers = "Content-type: application/json\r\n" .
	        "Content-length: " . strlen($content) . "\r\n" .
	        "Ocp-Apim-Subscription-Key: $key\r\n" .
	        "X-ClientTraceId: " . com_create_guid() . "\r\n";
	    $options = array (
	        'http' => array (
	            'header' => $headers,
	            'method' => 'POST',
	            'content' => $content
	        )
	    );
	    $context  = stream_context_create($options);
	    $result = file_get_contents ($host . $path . $params, false, $context);
	    return $result;
	}

	$requestBody = array (
	    array (
	        'Text' => $text,
	    ),
	);
	$content = json_encode($requestBody);
	$result = Translate($host, $path, $key, $params, $content);

	$json = json_decode($result);
	$newtext =  $json[0]->translations[0]->text;

	echo $newtext; 

ガンガンいきたいところだが、アプリ(android・iOS)のタスクがかなり重いので、translatorはひとまずこれをazureに載せるところまでとしたい。

preg_replaceのワイルドカード

.*を使います。

$text = "当面の金融政策運営について [PDF 195KB]";
echo preg_replace("/\[PDF.*\]/","", $text);

[PDF 195KB]が非表示となりました。

前)

後)

ディレクトリ配下のファイル名を取得

$y = "2017";
foreach(glob("file/".$y."/{*.txt}",GLOB_BRACE) as $file){
    if(is_file($file)){
        $files[] = htmlspecialchars($file);
    }
}
var_dump($files);

array(8) { [0]=> string(19) “file/2017/boj.0.txt” [1]=> string(19) “file/2017/boj.1.txt” [2]=> string(19) “file/2017/boj.2.txt” [3]=> string(19) “file/2017/boj.3.txt” [4]=> string(19) “file/2017/boj.4.txt” [5]=> string(19) “file/2017/boj.5.txt” [6]=> string(19) “file/2017/boj.6.txt” [7]=> string(19) “file/2017/boj.7.txt” }

しかしforeachでfunction Translateを回すと、 Cannot redeclareとなる。

 Cannot redeclare Translate() (previously declared in /home/vagrant/translator/test.php:40) in /home/vagrant/translator/test.php on line 40

これは困った。

phpファイルからlinuxコマンドを実行

exec('ls', $out, $ret);
print_r($out);

pdftotextの場合は、これでOK

exec('pdftotext boj.pdf boj2.txt');

ではこうするとどうでしょう?
コードがやや冗長になってしまいましたが、file_put_contentsしたpdfをpdftotextしてpdfだけunlinkします。

$i=0;
foreach($urls as $value){
    $pass = "file/".$y."/".$i.".pdf";
    $data = file_get_contents($value);
    file_put_contents($pass, $data);
    exec("pdftotext ".$pass." file/".$y."/boj.".$i.".txt");
    unlink($pass);
    $i++;
}

テキストファイルだけになってますね。

viewをどうするか?
タイトルを取得して、listで表示したい。