Google Play
https://play.google.com/store/apps/details?id=lgs.noyl.noyl
Github
https://github.com/leegiseong20030603/Life-And-Time.git
개발 목적 : 살아온 시간을 알아보기
기능 : 생년월일을 넣으면 살아온시간을 초, 분, 시, 일으로 보여준다.
개발 기간 : 23시간
사용 프레임워크 : android studio
개발 언어 : Java
에드몹 광고 추가
#Android Studio #Java #23시간 #첫 에드몹광고 달기 도전
Intro
Layout ( XML )
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="5dp"
android:background="@drawable/bar"
tools:context=".Intro">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:gravity="center"
android:layout_weight="1"
android:textSize="40dp"
android:text="내가 살아온 시간 \n 알아보는 앱" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginBottom="5dp"
android:fontFamily="@font/mp"
android:paddingLeft="10dp"
android:text="폰트 출쳐 : 마포금빛나루" />
</LinearLayout>
Class
public class Intro extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(Intro.this,MainActivity.class);
startActivity(intent);
finish();
}
},3500);
}
}
Main
Layout ( XML )
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:background="@drawable/bar"
tools:context=".MainActivity">
<LinearLayout
android:layout_weight="1"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bar"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:textSize="30dp"
android:fontFamily="@font/mp"
android:text="지금동안 살아온 시간"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<EditText
android:maxLines="1"
android:maxLength="4"
android:id="@+id/put_Y_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/mp"
android:hint="년도"
android:inputType="number"
android:maxEms="4"
android:paddingLeft="10dp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<EditText
android:maxLines="1"
android:maxLength="2"
android:id="@+id/put_M_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:layout_weight="1"
android:hint="월"
android:inputType="number"
android:maxEms="2"
android:paddingLeft="10dp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<EditText
android:maxLines="1"
android:maxLength="2"
android:id="@+id/put_D_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:layout_weight="1"
android:hint="일"
android:inputType="number"
android:maxEms="2"
android:paddingLeft="10dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
<Button
android:id="@+id/result_button"
android:layout_width="match_parent"
android:fontFamily="@font/mp"
android:layout_height="60dp"
android:gravity="center"
android:textSize="20dp"
android:background="#00000000"
android:text="결과" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
<RadioGroup
android:layout_marginTop="10dp"
android:background="@drawable/bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:id="@+id/radiogroup">
<RadioButton
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:text="일"
android:id="@+id/D" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<RadioButton
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:text="시간"
android:id="@+id/H" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<RadioButton
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:text="분"
android:id="@+id/m" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<RadioButton
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:text="초"
android:id="@+id/S" />
</RadioGroup>
<TextView
android:layout_weight="1"
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/mp"
android:gravity="center"
android:textSize="40dp" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
Class
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
EditText Y_et;
EditText M_et;
EditText D_et;
Button result_button;
TextView result;
AlertDialog dialog;
RadioGroup radioGroup;
long result_time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(MainActivity.this, getString(R.string.admob_app_id));
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Y_et = findViewById(R.id.put_Y_edit);
M_et = findViewById(R.id.put_M_edit);
D_et = findViewById(R.id.put_D_edit);
result_button = findViewById(R.id.result_button);
result = findViewById(R.id.result);
radioGroup = findViewById(R.id.radiogroup);
result_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Y_et.getText().toString().length() == 0 || M_et.getText().toString().length() == 0 || D_et.getText().toString().length() == 0){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.bulider_,null);
builder.setView(view);
Button ok = view.findViewById(R.id.ok);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog = builder.create();
dialog.show();
}else {
int get_Y = Integer.parseInt(Y_et.getText().toString());
int get_M = Integer.parseInt(M_et.getText().toString());
int get_D = Integer.parseInt(D_et.getText().toString());
long now = System.currentTimeMillis();
Date now_date = new Date(now);
SimpleDateFormat Y = new SimpleDateFormat("yyyy");
SimpleDateFormat M = new SimpleDateFormat("MM");
SimpleDateFormat D = new SimpleDateFormat("dd");
int now_Y = Integer.parseInt(Y.format(now_date));
int now_M = Integer.parseInt(M.format(now_date));
int now_D = Integer.parseInt(D.format(now_date));
Calendar cal2 = new GregorianCalendar(now_Y,now_M,now_D);
Calendar cal1 = new GregorianCalendar(get_Y,get_M,get_D);
result_time = cal2.getTimeInMillis() - cal1.getTimeInMillis();
long get_result_time = result_time;
get_result_time = get_result_time / 1000;
get_result_time = get_result_time / 3600;
get_result_time = get_result_time / 24;
result.setText(get_result_time + "일 \n 살아오셨네요!");
}
}
});
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.D : {
long get_result_time = result_time;
get_result_time = get_result_time / 1000;
get_result_time = get_result_time / 3600;
get_result_time = get_result_time / 24;
result.setText(get_result_time + "일 \n 살아오셨네요!");
break;
}
case R.id.H : {
long get_result_time = result_time;
get_result_time = get_result_time / 1000;
get_result_time = get_result_time / 3600;
result.setText(get_result_time + "시 \n 살아오셨네요!");
break;
}
case R.id.m : {
long get_result_time = result_time;
get_result_time = get_result_time / 1000;
get_result_time = get_result_time / 60;
result.setText(get_result_time + "분 \n 살아오셨네요!");
break;
}
case R.id.S : {
long get_result_time = result_time;
get_result_time = get_result_time / 1000;
result.setText(get_result_time + "초 \n 살아오셨네요!");
break;
}
}
}
});
}
}