« 2016年04月 | メイン | 2017年08月 »

2016年07月 アーカイブ

2016年07月01日

夏休みの工作・自由研究におすすめ

Handmade Electronic Music ―手作り電子回路から生まれる音と音楽 (Make: PROJECTS)
バネを使った、「ぼよよ~ん」玩具のヒントがあるかも

続きを読む "夏休みの工作・自由研究におすすめ" »

2016年07月02日

地図に十字中心線を表示

 Android Studio2.1.2 のテンプレートGoogleMapsActivityの地図上に十字中心線を表示する簡単な方法。
 その前に、Google Maps APIキーをセットしコンパイルすると
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
 メソッド数の上限を超えた(Building Apps with Over 65K Methods)
→ https://developer.android.com/studio/build/multidex.html?hl=ja
ということで
MyApplication\app\build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "asia.remix.map"
        minSdkVersion 10
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true ★追加
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services:9.4.0'
}

MyApplication\app\src\main\AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="example.myapplication"
          xmlns:android="http://schemas.android.com/apk/res/android"
    >

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name="android.support.multidex.MultiDexApplication" ★追加
    >

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key"
            />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

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

</manifest>
それぞれ ★印の行を追加。
ちなみに googleの巨大なライブラリを使う場合
MyApplication\gradle.properties

左ペインツリー Projectの Gradle Scripts/gradle.properties

VM起動オプション
org.gradle.jvmargs=-Xmx2048m
を指定するとメモリ不足解消とコンパイル時間を短縮(約1/10)。
本題の十字中心線は...▼

続きを読む "地図に十字中心線を表示" »

2016年07月03日

simple_list_item_1 + SimpleAdapter

 android.widget.ListView を使う定番サンプル。
String[] strings = { "1列目", "2列目", "3列目" };
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
	getApplicationContext()
,	android.R.layout.simple_list_item_1
,	strings
);

 実際には選択リストの表示名とは別にひもづいた値を利用することがほとんど。
 そこで標準のレイアウト android.R.layout.simple_list_item_1 のまま android.widget.ArrayAdapter ではなく android.widget.SimpleAdapter に交換してみる。 あえて動的配列で...
ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put( "display", "1列目" );
map.put( "offset", 1 );
arrayList.add( map );
map.put( "display", "2列目" );
map.put( "offset", 2 );
arrayList.add( map );
map.put( "display", "3列目" );
map.put( "offset", 3 );
arrayList.add( map );

SimpleAdapter simpleAdapter = new SimpleAdapter(
	getApplicationContext()
,	arrayList
,	android.R.layout.simple_list_item_1 ←★
,	new String[]{ "display"},
	new int[]{android.R.id.text1} ←★
);

2016年07月05日

オリジナルandroid.view.View参考

Android ADK 組込みプログラミング完全ガイド (Smart Mobile Developer)
全サンプルコードは
https://www.shoeisha.co.jp/book/detail/9784798125930
からダウンロード可能。
『第8章 Android 対応の電子オルゴールを作る』
の簡易サンプルの画面・・・▼


続きを読む "オリジナルandroid.view.View参考" »

About 2016年07月

2016年07月にブログ「Remix.asia」に投稿されたすべてのエントリーです。過去のものから新しいものへ順番に並んでいます。

前のアーカイブは2016年04月です。

次のアーカイブは2017年08月です。

他にも多くのエントリーがあります。メインページアーカイブページも見てください。