1 of 31

Get Started Developing for Android with @gabu's code 

PralineWebDesign  

梅田 悦子 (Etsuko Umeda)

2 of 31

The leader of Android Nagoya Developer Club

Android 名古屋 つくる部

塚田 翔也(Shoya Tsukada)さんの紹介

プログラマ/未踏/Android/GAE/HTML5/つ部/東海GTUG

「30分でつくれるAndroidアプリ Google App Inventorではじめよう!」

http://www.amazon.co.jp/exec/obidos/ASIN/4883377660/gabu-22/

「Android SDK開発のレシピ」

http://j.mp/gabubook1

@gabu

3 of 31

We can study his Android Code here.

Reading the source code you can find out how to make.

Android再入門 - 目次

  1. エミュレータの作成       http://qiita.com/items/8bc1a11f1382409f1d2a          
  2. プロジェクトの作成       http://qiita.com/items/cff2fbfbd2822f842862
  3. はじめてのView   http://qiita.com/items/f9b4389ae0c03f525f04
  4. カウンターを作ろう(前編)  http://qiita.com/items/614f89a9f659565806a6
  5. カウンターを作ろう(後編)  http://qiita.com/items/6ed716bb9af7cc3c26a3

Android再入門 - Twitterクライアントを作ってみよう - 目次 

  1. Twitter APIを使うアプリを登録 http://qiita.com/items/4a63e6b56dd50da1f528
  2. Twitter4Jのダウンロードと準備 http://qiita.com/items/f6f39900fd5e449045f9
  3. OAuth認証              http://qiita.com/items/673288c3a5b39f89aa92
  4. タイムラインを表示 http://qiita.com/items/53857fcfa871b921af45
  5. つぶやく http://qiita.com/items/ac505aac0ccf2b3d0b42

@gabu's SampleCoad on GitHub

https://github.com/gabu/android-twitter-sample

4 of 31

          Get the Android SDK

The Android SDK provides you the API libraries and developer tools necessary to build, test, and debug apps for Android.

     http://developer.android.com/sdk/index.html

It's mine.

5 of 31

6 of 31

7 of 31

8 of 31

9 of 31

10 of 31

11 of 31

12 of 31

13 of 31

14 of 31

15 of 31

16 of 31

The necessary preparation for Andoroid has been completed.

17 of 31

18 of 31

19 of 31

Coffee Break

AIR Aprication

 

ActionScript + Flash

Windows8 Aprication

Windows PHone

C#  + VisualStudio

Android Aprication

Java + Eclipse

similar

、ボタンやメニュー、スクロールバーといった ユーザーインターフェイス(UI)の コンポーネント(構成要素)が開発環境に含まれていて コードとデザインの画面を分離できるようになっています

The workbench contains a number of standard components which demonstrate the role of a view.

it's part of the design of Eclipse to separate the UI components - the View layer from the Model layer

20 of 31

Android再入門 - はじめてのView http://qiita.com/items/f9b4389ae0c03f525f04

Photoshopでいうならば背景レイヤーだけのようなもの

MainActivity.Java が activity_main.xml を呼びます

21 of 31

Android再入門 - はじめてのView http://qiita.com/items/f9b4389ae0c03f525f04

package com.example.helloworld;

import android.app.Activity;      import android.os.Bundle;      import android.view.Menu;       import android.view.View;       import android.widget.EditText; import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

     }

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

    }

public void click(View view) {

EditText input = (EditText) findViewById(R.id.editText1);

String text = input.getText().toString();

TextView main = (TextView) findViewById(R.id.textView1);

main.setText(text);

Toast.makeText(this,text, Toast.LENGTH_SHORT).show();

}

}

MainActivity.Java

22 of 31

Android再入門 - はじめてのView http://qiita.com/items/f9b4389ae0c03f525f04

activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

<TextView android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:text="@string/hello_world" />

<Button android:onClick="click"   

             android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_toRightOf="@+id/editText1"

android:layout_marginTop="24dp"                                                            android:text="@string/Button"  />

<EditText      android:id="@+id/editText1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:ems="10"

android:inputType="text"

android:labelFor="@+id/editText1" /> </RelativeLayout>

23 of 31

Android再入門 - はじめてのView http://qiita.com/items/f9b4389ae0c03f525f04

string.xml  

設定しないとエラー地獄でっせ

<?xml version="1.0" encoding="utf-8"?>

                                       <string name="app_name">HelloWorld</string>

                                     <string name="action_settings">Settings</string>

                                     <string name="hello_world">Hello world!</string>

                                     <string name="Button">Button</string>

                                       </resources>  

                                        ここで設定することでactivity_mail.xml の ボタンが 

android:text="@string/Button"  になります 

すると R. java に自動生成されます 

        

public static final class string {

public static final int Button=0x7f050003;

public static final int action_settings=0x7f050001;            public static final int app_name=0x7f050000;              public static final int hello_world=0x7f050002; }

string.xml    UIにつける 変数名の設定

24 of 31

Android再入門 - カウンターを作ろう http://qiita.com/items/6ed716bb9af7cc3c26a3

string.xml UIにつける変数名の設定 

+ の場合

                           

        

  activity_main.xml

<TextView android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:text="@string/zero"

android:textSize="90sp" />

<Button  android:id="@+id/button1"

     android:layout_width="150dp"

        android:layout_height="150dp"

         android:layout_centerHorizontal="true"

       android:layout_centerVertical="true"

        android:onClick="plus"

       android:text="@string/plus"

       android:textSize="60sp"    />

<Button android:id="@+id/button3"

        android:layout_width="80dp"

       android:layout_height="60dp"

       android:layo ut_alignBaseline="@+id/button2"

         android:layout_alignBottom="@+id/button2"

       android:layout_alignParentRight="true"

       android:layout_marginRight="30dp"

       android:onClick="minus"

       android:text="@string/minus" />

<Button   android:id="@+id/button2"

         android:layout_width="80dp"

         android:layout_height="60dp"

         android:layout_alignParentBottom="true"

         android:layout_alignParentLeft="true"

         android:layout_marginBottom="30dp"

         android:layout_marginLeft="30dp"

         android:onClick="clear"

         android:text="@string/Clear" />

<?xml version="1.0" encoding="utf-8"?><resources>

<string name="app_name">Counter</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<string name="zero">0</string>

<string name="plus">+</string>

<string name="minus">-</string>

<string name="Clear">Clear</string></resources>

25 of 31

Summary

open Android SDK manager

make string.xml

make activity_main.xml

Run configurations

make MainActivity.java

open AndroidVirtualDevices

Set up  AndroidVirtual Devices Manager

26 of 31

I wrote All source code in java. Only use MainActivity.java

package com.example.activitytest;

import android.app.Activity; import android.os.Bundle; import android.view.View;

import android.widget.EditText; import android.widget.TextView; import android.widget.Toast;

import android.widget.LinearLayout; import android.view.ViewGroup;

import android.widget.Button;

public class MainActivity extends Activity {

private final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

LinearLayout linearLayout = new LinearLayout(this);

linearLayout.setOrientation(LinearLayout.VERTICAL);

setContentView(linearLayout);

final TextView tv = new TextView(this);

tv.setText("Hello World! ");

linearLayout.addView(tv,

new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

final EditText edit = new EditText(this);

edit.setWidth(200);

linearLayout.addView(edit,

new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

Button button1 = new Button(this);

button1.setText("Button");

linearLayout.addView(button1,

new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

button1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

CharSequence str = edit.getText().toString(

tv.setText(str);

Toast.makeText(getApplication(), str, Toast.LENGTH_LONG).show(); });}}

main_activity.xml (stay Default)

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" ></RelativeLayout>

27 of 31

At First , Add Activity"NextActivity" into Android Manifest .xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.activitytest"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk

android:minSdkVersion="17"

android:targetSdkVersion="17" />

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.activitytest.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

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

</intent-filter>

</activity>

<activity

android:name="com.example.activitytest.NextActivity"

android:label="@string/app_name" >

</activity>

</application>

</manifest>

Starting Another Activity with @gabu's code

Respond to the Send Button; Build an Intent; Start the Second Activity

28 of 31

Secondary,make NextActivity.java ( "No use NextActivity.xml"Version )

package com.example.activitytest;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.Toast;

public class NextActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

LinearLayout ll = new LinearLayout(this);

ll.setOrientation(LinearLayout.VERTICAL);

setContentView(ll);

Intent intent = getIntent();

if(intent != null){

String str = intent.getStringExtra("inputtext");

Toast.makeText(this, str, Toast.LENGTH_LONG).show();

TextView tv = new TextView( this );

tv.setText( str );

ll.addView( tv );

}

}

}

Starting Another Activity with @gabu's code

Respond to the Send Button; Build an Intent; Start the Second Activity

29 of 31

Tertiary,make activity_main.xml and strings.xml (This is the same code that We made before)

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" >

<TextView android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world" />

<EditText android:id="@+id/editText1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/textView1"

android:layout_below="@+id/textView1"

android:layout_marginTop="24dp"

android:ems="10"

android:inputType="text"

android:labelFor="@+id/editText1" ><requestFocus /></EditText>

<Button android:id="@+id/button1"

android:layout_width="wrap_content"      android:layout_height="wrap_content"

android:layout_alignLeft="@+id/editText1"   android:layout_below="@+id/editText1"

android:layout_marginTop="24dp"         android:labelFor="@+id/button1"

android:onClick="click"                android:text="@string/Button" />

</RelativeLayout>

Starting Another Activity with @gabu's code

strings.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="app_name">ActivityTest</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<string name="Button">Button</string>

</resources>

30 of 31

Finally,make MainActivity.java

package com.example.activitytest;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main); }

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true; }

public void click(View view) {

EditText input = (EditText) findViewById(R.id.editText1);

String text = input.getText().toString();

TextView main = (TextView) findViewById(R.id.textView1);

main.setText(text);

Toast.makeText(this,text, Toast.LENGTH_SHORT).show();

Intent intent = new Intent(this,NextActivity.class);

intent.putExtra("inputtext", text);

intent.setAction(Intent.ACTION_VIEW);

startActivity(intent); }}

Starting Another Activity with @gabu's code

31 of 31

Starting Another Activity