Ȥ Blog

Ruby,C#

2010ǯ07

Android⡡-顼ȥɽ

Androidǥʥ顼ȡˤɽϡ
Activity.showDialog(int id)
Activity.onCreateDialog(int id)
Ѥˡ侩Ƥ褦Ǥ
ĿŪˤϤäݤʥ᡼ޤ

ܥ򥯥åȡHello AlertDialog Ȥ顼ȥåɽ륵ץ롣
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.hello_dialog_activity);
    final Button b = (Button)this.findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            showDialog(0); //Υ᥽åɤƤӽФ onCreateDialog᥽åɤХåȤƸƤӽФ롣ϤȤꤢ
        }
    });
}

@Override
protected Dialog onCreateDialog(int id) {
    switch(id) {
    case 0:
        return new AlertDialog.Builder(this).setMessage("Hello AlertDialog").create();
    }
    return null;
}

id Ǥդͤꤷơ˱ơAlertDialog䡢DatePickerDialogäޤǤcaseϤʤΤǤȤꤢ

Ǥ⡢ñ˥顼ȽФʤ
new AlertDialog.Builder.new(this).setMessage("hello alertDialog").show();
ǤŪãޤ
㤤ϥƤӽФAcitivity˥å뤫ʤΰ㤤Ǥ
ܤϡ
http://developer.android.com/guide/topics/ui/dialogs.html#ShowingADialog
 

Android⡡-եեޥå

աDate) ʸˤϡ
DateFormatȤɤΤǤandroidǤ

java.text.DateFormat.getDateInstance()
android.text.format.DateFormat.getDateFormat(context)

ɤ java.text.DateFormatΥ󥹥󥹤֤ΤǤĤäƤɤȤФΤʡɤäƱˤʤΤʡ 

ºݤäƤߤޤ
public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        DateFormat _jf = DateFormat.getDateInstance();
        DateFormat _af = android.text.format.DateFormat.getDateFormat(this);
        
        Date d = new Date();
        
        TextView tv1 = (TextView)this.findViewById(R.id.date1);
        TextView tv2 = (TextView)this.findViewById(R.id.date2);
        
        tv1.setText(_jf.format(d));
        tv2.setText(_af.format(d));
        
        Log.i("timezone",_jf.getTimeZone().getDisplayName());
        Log.i("timezone",_af.getTimeZone().getDisplayName());
    }
}

52


ΤʤΤJavaȤܤͶƤȴ򤷤ΤǤ
ߤ DateFormat.getDateInstance(Locale.Japan) ǥꤷƤƱǤ
AndroidθܸˤƤƱȤȤϻפäΤǤ

AndroidץȤǤϤʤ̤EclipseJavaץȤƻƤߤȤ java.text.DateFormat.getDateInstance()ǼDateFormat֥ȤǤտޤȤ yyyy/MM/dd ޤ

ޤ虜虜 android.text.format.DateFormat ѰդƤ餳äȤäƤȤʤǤ礦ɡɥȤˤդΤȽ񤤤Ƥäʤ

Android⡡-UIƥ runOnUiThreadǥϥޤ

AndroidΥƥȥץʥƥȼΤ⤤AndroidץʤΤǤˤ顢ƥоݥץUI椹ϡоݥץƱåɤǼ¹Ԥɬפ뤿ᡢ

Activity.runOnUiThread(Runnable action)

Ѥޤ

Button1˥ե򥻥åȤơ󥿡

public void testButton1() {
    Activity a = this.getActivity();
    final Button b = (Button) a.findViewById(оݥץѥå.R.id.button1);
    
    a.runOnUiThread(new Runnable() {
        public void run() {
            b.requestFocus();
        }
    });
    this.sendKeys(KeyEvent.KEYCODE_ENTER);

}

@UiThreadTest ɬפޤ

ƥȥ饹instrumentation-based classes 
ºݤˤ
ActivityInstrumentationTestCase2<T>
ˤʤΤǤξ@UiThreadTestɬפʤɤꤷƤޤȡUIåɰʳƤӽФǤʤʤäƤޤޤ
sendKeysȤƤӽФʤʤΤǡ¼ƥȤޤ

㤢ʤǺǽϥ顼ˤʤäΤȻפ褯褯Ƥߤȡ
runOnUiThreadƽФθ˲ν⵭ҤƤʤȡUIåɤǼ¹Ԥrun᥽åν¹ԤˡƥȤΥåɤλäƤ뤫餫 

sendKeysȤνɲä顢ʤƥȤǤޤ

ܤϡ
http://developer.android.com/guide/topics/testing/testing_android.html#UITesting
 

Android⡡-SMSåߥ졼

ưΥߥ졼SMSåϡ
telnet localhost ݡֹ
³ơ

sms send 090xxxxxxxx(Ŭֹʸ

뤳Ȥޤ

ݡֹϥǥեȤǤ 5554ǤʣưƤϡ
adb devices

ǵưΥߥ졼ɽ졢˥ݡֹɽޤ 
51


telnet³ SMS
 ̤̾
 
̾˥åɽޤ
̤̾2
 

Android⡡-꥽եɤ߹

꥽ե ( res/raw ǥ쥯ȥ겼ˤեˤɤ߹ϡ
Resource֥ȤơopenRawResource(꥽ID) ǥȥ꡼Ǥޤ

res/raw/file1.txt ȤƥȥեѰդơΥեɤ߹Ƥ򥢥顼ȥɽ롣

Resources res = this.getResources();
InputStream st = null;
try {
    st = res.openRawResource(R.raw.file1);
    byte[] buffer = new byte[st.available()];
    while((st.read(buffer)) != -1) {}
    String s = new String(buffer);
    new AlertDialog.Builder(this).setMessage(s).show();
} catch (IOException e) {
} finally{
    try{
        st.close();
    }catch(IOException e2)
    }
}



Android⡡-եɤ߹

ץꥱǺեɤ߹ϡ

openFileInput(ե̾

ǥȥ꡼Ǥޤ

եϼºݤˤϡ /data/data/ѥå̾/files/ ˺ޤ

FileInputStream fs = null;
try{
    fs = this.oepnFileInput("myfile.txt");
    byte[] buffer = new bytes[fs.available()];
    while((fs.read(buffer)) != -1){}
    String s = new String(buffer); 
    Log.i("mysoft", s);
}catch(IOException ioe){
    // handle exception
}finally{
    if(fs != null){
        try{
            fs.close();
        }catch(IOException ioe2){
            //handle exception
        }
    }
}


Android-ե˽񤭹

AndroidǼʬΥץΰǤդΥե˥ǡ񤭹ϡ
openFileOutput᥽åɤǽ񤭹ѤΥȥ꡼Ǥޤ
¤ˤĤƤϡContext饹ƤMODE_xxx򻲾ȡ

myfileȤ̾Υեʸ "hello world" 񤭹¸硣

FileOutputStream
fs = null; try{ fs = this.oepnFileOutput("myfile", Context.MODE_PRIVATE); String data = "hello world"; fs.write(data.getBytes()); }catch(IOException ioe){ // handle exception }finally{ if(fs != null){ try{ fs.close(); }catch(IOException ioe2){ //handle exception } } }

ξ硢ºݤˤϡ/data/data/ѥå̾/files/

ȤmyfileȤ̾Υե뤬ޤ



SOSα ˺乬Ϻ

ʤ󤫡̡ФˤʤäƤ褦ǤɤǤߤ뵤ˤϤʤޤ


ȥSOSα
//Artist˺ Ϻ
, 1,575
ɾ
 2010-07-26

ƾҲ

ҤǯΡְ㱤פꤵ줿ˤȡ֤ˤ300ߤ»ȯΤθĴˡơŷ¹ʪϡ餬Ĥ롣˺乬ϺǿĹԾ⡣

ơʡBOOKץǡ١ˡ

ҤǯΡְ㱤פޤ줿ˤȡ֤ˤƻߤ»ФȯΤθĴˡơŷ¹ߤʪĤΤϡ顣

ƥȤ񤫤ʤPHPץȤ¿ΤǤ礦

PHPǤγȯ򤷤Ƥ͡꡼Ȥä򤹤뵡񤬤äΤǤεʤˡ֥ƥȥե졼äƲȤäƤޤפʹ顢ͤϡ֤󡢻ȤлȤСäƴǤ͡ס⤦ͤϡֻȤäƤʤǤ͡ פȤΤȡ

֤á 㤢ɤäƥƥȤƤǤ ʹȤָդϰɡ桼ƥȻפäƤסֲܤ¿ΤdzȯԤټ¹ԤƳǧƤפȡʤ󤫴Ф᤮ƤȤ㤤Ȥ̯֤äƤޤ

̤ͤΥץȤǸߤ˴طϤޤ󡣤ijȯˡϷ褷ƥեǤ⤢ޤ 
1ĤïǤΤäƤ˿ӥȴϢäꡢ

10ǯ餤xUnit(DUnit,NUnit)ȤǶRSpecФäɡƥȽ񤯤ΤˤäƤΤǤ֤ϤʤΤʤΤǤ礦ޤޤäȻפ
 

Ƕϥ󥻥ȤȤΤʤΤ

ǶϥեȥաŹǤʤ˥󥻥ȤѰդƤȤ

ϥޥɥʥɾͱŹΡä

IMG_0329
 
ץե

Ȥ

C#ɻŻRubyФʳȯԡ
ǶDockerȤؿȤAngularJS˥ϥޤäƤ롣
¢ȤĮȤȤ˽ס

QR
QR
  • 饤֥ɥ֥