달력

3

« 2024/3 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2011. 8. 31. 08:47

File저장기법+dialog를 이용해 보기 Study/Android2011. 8. 31. 08:47

package com.narratage.com;

import java.io.FileOutputStream;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MyFile extends Activity {
/** Called when the activity is first created. */

// 사용할 것들
EditText edit;
Button btn;
static final int dialog_id0 = 0;
String txt;
AlertDialog dlg;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// findViewById를 이용해 id 값을 불러옴
btn = (Button) findViewById(R.id.button);

}

public void onResume() {
super.onResume();


edit = (EditText) findViewById(R.id.editText);
// button의 OnClickListener 이벤트 
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//dialog를 보여줌
showDialog(dialog_id0);
}
});

}

@Override
//맨처음 만들어질 다이얼로그
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
System.out.println("oncreatedialog");

switch (id) {
case dialog_id0:

dlg = new AlertDialog.Builder(this)
//AlertDialog의 아이콘
.setIcon(R.drawable.icon)
//AlertDialog의 타이틀
.setTitle("저장내용")
//AlertDialog의 메세지 내용 단 최초 한번은 여기서 부르나
                                        //다음부터는 onPrepareDialog 메소드에서 재정의함
.setMessage(edit.getText().toString())  
//Ok를 누르면 발생할 이벤트
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
//입력받은 값이 있는지 없는지를 판단하여 fail 이나
                                                                        //save 메소드를 호출함.
// == 이것으로 비교할 경우 논리오류가 발생할
                                                                        //        우려가 있음(해보진않음)
if (edit.getText().toString().equals("")) {
fail();
} else {
save();
}
}
})
//cancel을 누르면 dialog 닫힘
.setNegativeButton("CANCEL",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
}).create();
break;

default:
dlg = null;
}
return dlg;
}

@Override
//두번째부터 재정의하게 될 onPrepareDialog 여기서 메세지를 재정의해줌
public void onPrepareDialog(int id, Dialog dlg) {
super.onPrepareDialog(id, dlg);
this.dlg.setMessage(edit.getText().toString());
}

public void save() {
// id 값을 가져와서 R.id.button 값일 경우 실행

try {

// 입력받은 값을 String 형으로 저장함
String txt = edit.getText().toString();

// test.txt 파일을 쓰기 권한으로 줌
FileOutputStream outstream = openFileOutput("test.txt",
Activity.MODE_WORLD_WRITEABLE);

// byte 단위로 입력함
outstream.write(txt.getBytes());

// Exception이 발생하지 않았으므로 저장완료 Toast를 띄움
Toast.makeText(this, "저장완료!!", Toast.LENGTH_LONG).show();

} catch (Exception e) {

e.printStackTrace();

// Exception이 발생하였으므로 저장실패 Toast를 띄움
Toast.makeText(this, "저장실패!", Toast.LENGTH_LONG).show();
}

}

public void fail() {
Toast.makeText(this, "아무것도  입력되지 않았어요!", Toast.LENGTH_LONG).show();
}
}

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
Data Storage 中 Preferences  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자
2011. 8. 30. 15:26

EditText 에 입력하여 file로 저장하기 Study/Android2011. 8. 30. 15:26

public class MyFile extends Activity implements OnClickListener {
/** Called when the activity is first created. */
//사용할 것들
EditText edit;
Button btn;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//findViewById를 이용해 id 값을 불러옴
edit = (EditText) findViewById(R.id.editText);
btn = (Button) findViewById(R.id.button);

//button을 클릭하면 이벤트 발생
btn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

//id 값을 가져와서 R.id.button 값일 경우 실행
switch(v.getId()){
case R.id.button:
try {

//입력받은 값을 String 형으로 저장함
String txt = edit.getText().toString();

//test.txt 파일을 쓰기 권한으로 줌
FileOutputStream outstream = openFileOutput("test.txt",
Activity.MODE_WORLD_WRITEABLE);
//byte 단위로 입력함
outstream.write(txt.getBytes());

//Exception이 발생하지 않았으므로 저장완료 Toast를 띄움
Toast.makeText(this, "저장완료!!", Toast.LENGTH_LONG).show();

} catch (Exception e) {

e.printStackTrace();
//Exception이 발생하였으므로 저장실패 Toast를 띄움
Toast.makeText(this, "저장실패!", Toast.LENGTH_LONG).show();
}
}

}
}

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
File저장기법+dialog를 이용해 보기  (0) 2011.08.31
Data Storage 中 Preferences  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자
2011. 8. 30. 13:57

Data Storage 中 Preferences Study/Android2011. 8. 30. 13:57

화면저장방식. 게임같은곳에서 셋팅같은것등 ( 말그대로 화면을 저장한다고 생각하면 되겠다.)
 
activity 라이프사이클에서 판단해서 사용하면 되는데 대부분 onStop에서 저장을

onStart에서 불러오는것이 보편적인 방법이다.

        //현재화면상태정보를 pref  라는 key이름으로 가져옴
        SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE); 
  
 
       //findViewById로 각 id 값을 가져옴
        EditText edit1 = (EditText)findViewById(R.id.EditText);
CheckBox check1 = (CheckBox)findViewById(R.id.CheckBox01);
CheckBox check2 = (CheckBox)findViewById(R.id.CheckBox02);
 
        //pref에 저장되어 있는  값을 가져오는데 "이름" ,"만약 값이 없을경우 Default 값" 형태로 사용한다. 
String text = pref.getString("editText", "");
Boolean chk1 = pref.getBoolean("check1", false);
Boolean chk2 = pref.getBoolean("check2", false);
 
        //값을 set 함 
edit1.setText(text);
check1.setChecked(chk1);
check2.setChecked(chk2); 






//activity life cycle   ... onStop()

        //현재화면저장정보를 pref 란 key 값으로 가져옴
SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
              
 
       //Editor 클래스를 이용해 저장할거임
        SharedPreferences.Editor editor = pref.edit(); 
 
EditText edit1 = (EditText)findViewById(R.id.EditText);
CheckBox check1 = (CheckBox)findViewById(R.id.CheckBox01);
CheckBox check2 = (CheckBox)findViewById(R.id.CheckBox02);
 
// 저장할 값들을 입력
editor.putString("editText", edit1.getText().toString());
editor.putBoolean("check1", check1.isChecked());
editor.putBoolean("check2", check2.isChecked()); 

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
File저장기법+dialog를 이용해 보기  (0) 2011.08.31
EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자
2011. 8. 30. 11:51

TextView 그림자처리와 자동링크 Study/Android2011. 8. 30. 11:51

TextView 속성중

shadowColor, shadowRadius(그림자범위) 

autoLink(자동링크) 

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
File저장기법+dialog를 이용해 보기  (0) 2011.08.31
EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
Data Storage 中 Preferences  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자
2011. 8. 29. 18:10

px (vs) dp Study/Android2011. 8. 29. 18:10

밀도차이..

예를 들어 (4:3 - > 8:6 으로 늘었다면)

px는 1.7배  dp는 2배 정확히 늘어남.

모바일에서는 dp가 좋다.
:
Posted by 유쾌한순례자
2011. 8. 29. 17:08

상태바 Notification 예제 파일분석 Study/Android2011. 8. 29. 17:08

//가장 처음에 보이는 화면 StatusExamActivity


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class StatusExamActivity extends Activity implements OnClickListener {
//앞으로 사용할 것들 선언
private EditText tickerText;
private EditText contentTitle;
private EditText contentText;
private Button registerButton;
private NotificationManager nm;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        

//findViewByid를 이용해 main.xml에서 정의해두고 R클래스에 저장시킨 view 들의 id값을 가져옴
        tickerText = (EditText)findViewById(R.id.tickerText);
        contentTitle= (EditText)findViewById(R.id.contentTitle);
        contentText = (EditText)findViewById(R.id.contentText);
        registerButton = (Button)findViewById(R.id.registerNotification);
        
//registerButton을 클릭시 이벤트 발생
        registerButton.setOnClickListener(this);  
        
    }

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

//뷰의 아이디 값을 가져와서 switch ~ case 문 실행
switch(v.getId()){

//registerNotification id값을 가진 버튼이 클릭 되었을 경우 실행할 case문 
case R.id.registerNotification:

//getSystemService 를 이용해 현재 활성화중인
                                // NOTIFICATION_SERVICE를 불러와 NotificationManager 형태로 cast 후 저장
  
        nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//PendingIntent를 사용해서 intent가 실행될때 다이얼 (  new Intent(...) 를 실행 )
                                //를 실행하고 하라는 이야기.
PendingIntent intent = PendingIntent.getActivity(StatusExamActivity.this, 0,
new Intent(StatusExamActivity.this,Message.class),0);
//각 View의 값을 가져와서 각 변수에 저장함
String ticker= tickerText.getText().toString();
String title= contentTitle.getText().toString();
String text= contentText.getText().toString();

//상태바에 생성할 정보 저장(아이콘,문구,시간)
Notification notification = new
 Notification(android.R.drawable.ic_input_add,ticker,System.currentTimeMillis());
//상태바의 확장부분
notification.setLatestEventInfo(StatusExamActivity.this, title, text, intent);
//상태바에 띄움
nm.notify(1234,notification);

//간단한 Toast Notification 
Toast.makeText(StatusExamActivity.this, "Notification Register",
Toast.LENGTH_SHORT).show();
}
}
}

'Study > Android' 카테고리의 다른 글

File저장기법+dialog를 이용해 보기  (0) 2011.08.31
EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
Data Storage 中 Preferences  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
Notification 공부 정리  (0) 2011.08.29
getVisibility와 View.GONE View.INVISIBLE  (0) 2011.08.26
:
Posted by 유쾌한순례자
2011. 8. 29. 15:08

Intent Study/Android2011. 8. 29. 15:08

Intent 
상태전환

Intent i = new Intent(출발,목적지) //명시적 Intent
           new Intent(출발)        //암묵적 Intent


/*암묵적 Intent*/
mainifest에 <intent-filter> 가 있어야함.

조건비교를 해서 해당조건을 만족하는쪽으로..

andorid.intent.action.MAIN -> 기본화면


action: 해당 엔트리포인트가 어떤작업을 해나가는지 보여주는곳

category: action에 대한 세부설정 

data,Extras,Flags 


intent-filter를 검색할 경우 category 에서 DEFAULT 속성을 가진것만을 검색한다.

PendingIntent 다른 activity에 가는 것은 맞으나 어디에 들렸다간다 라고 생각하면 편하겟다!

'Study > Android' 카테고리의 다른 글

EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
Data Storage 中 Preferences  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
Notification 공부 정리  (0) 2011.08.29
getVisibility와 View.GONE View.INVISIBLE  (0) 2011.08.26
layout_alignWithParentIfMissing  (0) 2011.08.26
:
Posted by 유쾌한순례자
2011. 8. 29. 15:07

getSystemService Study/Android2011. 8. 29. 15:07

getSystemService 현재 서비스중인것을 뽑아옴.

ex) getSystemService(NOTIFICATION_SERVICE)

현재 notification_service를 뽑아 오겠다 라는 이야기

'Study > Android' 카테고리의 다른 글

Data Storage 中 Preferences  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
Notification 공부 정리  (0) 2011.08.29
getVisibility와 View.GONE View.INVISIBLE  (0) 2011.08.26
layout_alignWithParentIfMissing  (0) 2011.08.26
Relative Layout 예제 중 명함예제  (0) 2011.08.26
:
Posted by 유쾌한순례자
2011. 8. 29. 15:06

Style / Theme Study/Android2011. 8. 29. 15:06


Style / Theme

예를 들어 화면마다 배경이 똑같을경우 테마를 이용 해서 지정할 수 가 있다.

어플리케이션전체, 하나의 activity    ,    하나의 레이아웃,하나의 view(컴포넌트)
---------------------------------/------------------------------------
Theme                                                                    style
android:Theme=""                    
mainifest파일에 적용함

res/values/style.xml   파일에 정의함.

'Study > Android' 카테고리의 다른 글

TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Notification 공부 정리  (0) 2011.08.29
getVisibility와 View.GONE View.INVISIBLE  (0) 2011.08.26
layout_alignWithParentIfMissing  (0) 2011.08.26
Relative Layout 예제 중 명함예제  (0) 2011.08.26
LinerLayout 추가 기록  (0) 2011.08.25
:
Posted by 유쾌한순례자
2011. 8. 29. 15:05

Notification 공부 정리 Study/Android2011. 8. 29. 15:05


단방향임.. (한번 알려주면 끝)

 -Toast
  :일방적으로 보냄 일정시간동안.. 간단한 메세지만들어감
   기타 처리는 불가능. 무조건 나옴(단 늦게나오거나 일찍나올수도있음)
   사용자의 현재 Activity에는 영향을 끼치지 않음
   일정시간 유지 후 소멸됨
   화면에 영향을 주지는 않으나 가릴 수는 있기에 되도록 짧은시간을 이용하는게 좋다.
 
 -Status Bar(상태바)
  :Notification 매니저를 이용해 여러가지 가능함
    
 -Dialog Notification
  :하나만 보여줄 수 있음

'Study > Android' 카테고리의 다른 글

px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
getVisibility와 View.GONE View.INVISIBLE  (0) 2011.08.26
layout_alignWithParentIfMissing  (0) 2011.08.26
Relative Layout 예제 중 명함예제  (0) 2011.08.26
LinerLayout 추가 기록  (0) 2011.08.25
Android process 개략설명  (0) 2011.08.25
:
Posted by 유쾌한순례자