package com.mmad.mytimesheet;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Layout;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class TimeActivity extends Activity {
Button startTimeBut,endTimeBut;
final Context context = this;
Dialog dialog ;
String startNo,startTimeTypevalue;
List<String> timeType;
Spinner timeTypeSpinner;
int increaseNumber,decreaseNumber;
String callTime;
String setStartingTimeValue="Start";
String endStartingTimeValue="End";
String setTimeType="";
String setStartTime="";
String setStartTimeType="";
Intent intent= getIntent();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_preparation);
setTitle("Time Preparation");
startTimeBut=(Button)findViewById(R.id.start_time);
endTimeBut=(Button)findViewById(R.id.end_time);
//KAPIL
startTimeBut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startTime("start");
}
});
/*********************Statting Value end**********************************/
endTimeBut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startTime("end");
}
});
}
/**********dialog box start*********/
//KAPIL
private void startTime(String calType) {
if(calType.equals("start"))
callTime="start";
else
callTime="end";
// custom dialog
dialog = new Dialog(context);
dialog.setContentView(R.layout.start_time);
dialog.setTitle("Set Your Time");
Button startMinus=(Button)dialog.findViewById(R.id.start_minus);
Button startPlus=(Button)dialog.findViewById(R.id.start_plus);
final EditText startNumber=(EditText)dialog.findViewById(R.id.start_number);
startNumber.setText("0");
timeTypeSpinner=(Spinner)dialog.findViewById(R.id.timeTypeSpinner);
timeType=new ArrayList<String>();
timeType.add("AM");
timeType.add("PM");
ArrayAdapter<String> startAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,timeType);
startAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeTypeSpinner.setAdapter(startAdapter);
timeTypeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
startTimeTypevalue=arg0.getItemAtPosition(arg2).toString();
Toast.makeText(getBaseContext(), "Value"+startTimeTypevalue, 10).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
//Integer value=arg1.getId();
}
});
startMinus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
decreaseNumber=0;
startNo=startNumber.getText().toString();
try{
decreaseNumber=Integer.parseInt(startNo);
}
catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "Error in Minus"+e, 500).show();
decreaseNumber=0;
}
if(decreaseNumber<1)
{
Log.d("Minus***************", "Not doing");
}else
{
decreaseNumber=decreaseNumber-1;
startNumber.setText(""+decreaseNumber);
}
}
});
startPlus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
increaseNumber=0;
startNo=startNumber.getText().toString();
try{
increaseNumber=Integer.parseInt(startNo);
}
catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "Error in plus"+e, 500).show();
increaseNumber=0;
}
if(increaseNumber > 12 )
{
Log.d("Plus***************", "Not doing");
}
else
{
increaseNumber=increaseNumber+1;
startNumber.setText(""+increaseNumber);
}
}
});
/******************OK button start*********************/
Button ok=(Button)dialog.findViewById(R.id.Ok);
ok.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(getBaseContext(),TimeActivity.class);
if(callTime.equalsIgnoreCase("start")){
setStartingTimeValue=startNo+" "+startTimeTypevalue;
startTimeBut.setText(setStartingTimeValue);
}else{
endStartingTimeValue=startNo+" "+startTimeTypevalue;
endTimeBut.setText(endStartingTimeValue);
}
dialog.dismiss();
//startActivity(intent);
}
});
/******************OK button end*********************/
/******************Cancel button start*********************/
Button cancel=(Button)dialog.findViewById(R.id.Dialog_Cancel);
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
/******************Cancel button end*********************/
dialog.show();
}
/**********dialog box end*********/
}
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Layout;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class TimeActivity extends Activity {
Button startTimeBut,endTimeBut;
final Context context = this;
Dialog dialog ;
String startNo,startTimeTypevalue;
List<String> timeType;
Spinner timeTypeSpinner;
int increaseNumber,decreaseNumber;
String callTime;
String setStartingTimeValue="Start";
String endStartingTimeValue="End";
String setTimeType="";
String setStartTime="";
String setStartTimeType="";
Intent intent= getIntent();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_preparation);
setTitle("Time Preparation");
startTimeBut=(Button)findViewById(R.id.start_time);
endTimeBut=(Button)findViewById(R.id.end_time);
//KAPIL
startTimeBut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startTime("start");
}
});
/*********************Statting Value end**********************************/
endTimeBut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startTime("end");
}
});
}
/**********dialog box start*********/
//KAPIL
private void startTime(String calType) {
if(calType.equals("start"))
callTime="start";
else
callTime="end";
// custom dialog
dialog = new Dialog(context);
dialog.setContentView(R.layout.start_time);
dialog.setTitle("Set Your Time");
Button startMinus=(Button)dialog.findViewById(R.id.start_minus);
Button startPlus=(Button)dialog.findViewById(R.id.start_plus);
final EditText startNumber=(EditText)dialog.findViewById(R.id.start_number);
startNumber.setText("0");
timeTypeSpinner=(Spinner)dialog.findViewById(R.id.timeTypeSpinner);
timeType=new ArrayList<String>();
timeType.add("AM");
timeType.add("PM");
ArrayAdapter<String> startAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,timeType);
startAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeTypeSpinner.setAdapter(startAdapter);
timeTypeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
startTimeTypevalue=arg0.getItemAtPosition(arg2).toString();
Toast.makeText(getBaseContext(), "Value"+startTimeTypevalue, 10).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
//Integer value=arg1.getId();
}
});
startMinus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
decreaseNumber=0;
startNo=startNumber.getText().toString();
try{
decreaseNumber=Integer.parseInt(startNo);
}
catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "Error in Minus"+e, 500).show();
decreaseNumber=0;
}
if(decreaseNumber<1)
{
Log.d("Minus***************", "Not doing");
}else
{
decreaseNumber=decreaseNumber-1;
startNumber.setText(""+decreaseNumber);
}
}
});
startPlus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
increaseNumber=0;
startNo=startNumber.getText().toString();
try{
increaseNumber=Integer.parseInt(startNo);
}
catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "Error in plus"+e, 500).show();
increaseNumber=0;
}
if(increaseNumber > 12 )
{
Log.d("Plus***************", "Not doing");
}
else
{
increaseNumber=increaseNumber+1;
startNumber.setText(""+increaseNumber);
}
}
});
/******************OK button start*********************/
Button ok=(Button)dialog.findViewById(R.id.Ok);
ok.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(getBaseContext(),TimeActivity.class);
if(callTime.equalsIgnoreCase("start")){
setStartingTimeValue=startNo+" "+startTimeTypevalue;
startTimeBut.setText(setStartingTimeValue);
}else{
endStartingTimeValue=startNo+" "+startTimeTypevalue;
endTimeBut.setText(endStartingTimeValue);
}
dialog.dismiss();
//startActivity(intent);
}
});
/******************OK button end*********************/
/******************Cancel button start*********************/
Button cancel=(Button)dialog.findViewById(R.id.Dialog_Cancel);
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
/******************Cancel button end*********************/
dialog.show();
}
/**********dialog box end*********/
}
No comments:
Post a Comment