use of android.widget.DatePicker in project BloodHub by kazijehangir.
the class AddRequestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
mEmail = user.getEmail();
// INITIALIZE FIREBASE DB
db = FirebaseDatabase.getInstance().getReference().child("bloodrequests");
mStorageRef = FirebaseStorage.getInstance().getReference().child("bloodrequests");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_request);
setTitle("Add Request");
name = (AutoCompleteTextView) findViewById(R.id.name);
bloodgroup = (Spinner) findViewById(R.id.spin);
quantity = (Spinner) findViewById(R.id.spin1);
number = (EditText) findViewById(R.id.contact_num);
location = (AutoCompleteTextView) findViewById(R.id.loc);
when = (EditText) findViewById(R.id.editText);
diagnosis = (Spinner) findViewById(R.id.diagnosis);
transport_group = (RadioGroup) findViewById(R.id.transport);
image = (TextView) findViewById(R.id.image_text);
String[] hospitals = getResources().getStringArray(R.array.organizations_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, hospitals);
location.setAdapter(adapter);
final EditText set = (EditText) findViewById(R.id.editText);
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog = new Dialog(AddRequestActivity.this);
dialog.setTitle("Set Date and Time");
dialog.setContentView(R.layout.set_date);
dialog.show();
final Button setDate = (Button) dialog.findViewById(R.id.set_date);
final DatePicker datePicker = (DatePicker) dialog.findViewById(R.id.datePicker);
datePicker.setMinDate(System.currentTimeMillis() - 1000);
setDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
date = datePicker.getDayOfMonth();
month = datePicker.getMonth();
year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, date);
pdate = calendar.getTime();
String date = DateFormat.getDateInstance().format(pdate);
set.setText(date);
dialog.cancel();
}
});
}
});
Button image_btn = (Button) findViewById(R.id.upload_image_button);
image_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getApplicationContext();
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_INTENT);
}
});
Button submit = (Button) findViewById(R.id.submit_button);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pname = name.getText().toString();
bgroup = bloodgroup.getSelectedItem().toString();
quan = quantity.getSelectedItem().toString();
diag = diagnosis.getSelectedItem().toString();
num = number.getText().toString();
loc = location.getText().toString();
transport_btn = (RadioButton) findViewById(transport_group.getCheckedRadioButtonId());
String transport_text = (String) transport_btn.getText();
if (transport_text.equals("Available")) {
transport = true;
} else if (transport_text.equals("Not Available")) {
transport = false;
}
new_request = db.push();
String address = loc + ", Pakistan";
new GetCoordinates().execute(address.replace(" ", "+"));
if (image_file != null) {
mStorageRef.child(new_request.getKey()).putFile(image_file).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Toast.makeText(getApplicationContext(),"Image uploaded",
// Toast.LENGTH_SHORT).show();
String regToken = FirebaseInstanceId.getInstance().getToken();
BloodRequest request = new BloodRequest(user.getUid(), pname, bgroup, quan, num, loc, lat, lng, diag, pdate.getTime(), transport, regToken);
new_request.setValue(request);
request_added = true;
dialog = new Dialog(AddRequestActivity.this);
dialog.setContentView(R.layout.popup_submit);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.button_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddRequestActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getApplicationContext(), "Error uploading image", Toast.LENGTH_SHORT).show();
}
});
} else {
String regToken = FirebaseInstanceId.getInstance().getToken();
BloodRequest request = new BloodRequest(user.getUid(), pname, bgroup, quan, num, loc, lat, lng, diag, pdate.getTime(), transport, regToken);
new_request.setValue(request);
request_added = true;
dialog = new Dialog(AddRequestActivity.this);
dialog.setContentView(R.layout.popup_submit);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.button_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddRequestActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
}
});
}
use of android.widget.DatePicker in project BloodHub by kazijehangir.
the class AddRequestOrgActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
mEmail = user.getEmail();
// INITIALIZE FIREBASE DB
db = FirebaseDatabase.getInstance().getReference().child("bloodrequests");
mStorageRef = FirebaseStorage.getInstance().getReference().child("bloodrequests");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_request_org);
setTitle("Add Request for Patient");
location = (AutoCompleteTextView) findViewById(R.id.loc);
when = (EditText) findViewById(R.id.editText);
transport_group = (RadioGroup) findViewById(R.id.transport);
quantity = (Spinner) findViewById(R.id.spin1);
String[] hospitals = getResources().getStringArray(R.array.organizations_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, hospitals);
location.setAdapter(adapter);
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if (extras == null) {
patient = null;
} else {
patient = extras.getString("patient");
}
}
final EditText set = (EditText) findViewById(R.id.editText);
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog = new Dialog(AddRequestOrgActivity.this);
dialog.setTitle("Set Date and Time");
dialog.setContentView(R.layout.set_date);
dialog.show();
final Button setDate = (Button) dialog.findViewById(R.id.set_date);
final DatePicker datePicker = (DatePicker) dialog.findViewById(R.id.datePicker);
datePicker.setMinDate(System.currentTimeMillis() - 1000);
setDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
date = datePicker.getDayOfMonth();
month = datePicker.getMonth();
year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, date);
pdate = calendar.getTime();
String date = DateFormat.getDateInstance().format(pdate);
set.setText(date);
dialog.cancel();
}
});
}
});
// name = null;
// age = null;
// needs = null;
// when = null;
// diagnosis = null;
// gender = null;
// mEmail = null;
// } else {
// //
// name = extras.getString("name");
// age = extras.getString("age");
// needs = extras.getString("bgroup");
// when = extras.getString("lastRequest");
// diagnosis = extras.getString("diagnosis");
// gender = extras.getString("gender");
// mEmail = extras.getString("mEmail");
// Toast.makeText(this,gender,Toast.LENGTH_SHORT).show();
// }
// } else {
// // Toast.makeText(this, "getting strings from savedInstance",
// // Toast.LENGTH_SHORT).show();
// name = (String) savedInstanceState.getSerializable("name");
// age = (String) savedInstanceState.getSerializable("age");
// needs = (String) savedInstanceState.getSerializable("bgroup");
// when = (String) savedInstanceState.getSerializable("lastRequest");
// diagnosis = (String) savedInstanceState.getSerializable("diagnosis");
// gender = (String) savedInstanceState.getSerializable("gender");
// mEmail = (String) savedInstanceState.getSerializable("mEmail");
//
// }
//
// // TextView mName = (TextView) findViewById(R.id.name);
// // mName.setText("Name: "+name);
// // TextView mAge = (TextView) findViewById(R.id.age);
// // mName.setText("Age: "+age);
// // TextView mWhen = (TextView) findViewById(R.id.blood_g);
// // mWhen.setText("Blood Group: "+needs);
// // TextView mDiagnosis = (TextView) findViewById(R.id.con_num);
// // mDiagnosis.setText("Diagnosis: "+diagnosis);
// // TextView mTransport = (TextView) findViewById(R.id.last);
// mTransport.setText("Last Request: "+when);
// ImageView image = (ImageView) findViewById(R.id.image1);
// if (gender.equals("Female")){
// image.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.girl));
// }
// else {
// image.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.boy));
// }
// db = FirebaseDatabase.getInstance().getReference().child("patient details");
FirebaseDatabase.getInstance().getReference().child("patients").child(patient).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Patient data = dataSnapshot.getValue(Patient.class);
TextView mName = (TextView) findViewById(R.id.user_profile_name);
mName.setText(data.name);
pname = data.name;
TextView mAge = (TextView) findViewById(R.id.user_profile_age);
mAge.setText("Age: " + data.age);
TextView mCnumber = (TextView) findViewById(R.id.user_profile_number);
mCnumber.setText("Contact Number: " + data.cnumber);
num = data.cnumber;
TextView mBloodgroup = (TextView) findViewById(R.id.user_profile_bgroup);
mBloodgroup.setText("Blood Group: " + data.blood_group);
bgroup = data.blood_group;
TextView mDiagnosis = (TextView) findViewById(R.id.user_profile_Diagnosis);
mDiagnosis.setText("Diagnosis: " + data.diagnosis);
diag = data.diagnosis;
// Spinner mNeeds = (Spinner) findViewById(R.id.spin1);
// mNeeds.getSelectedItem().toString();
//
// TextView mLocation = (TextView) findViewById(R.id.request_detail_location);
// mLocation.setText(data.location);
// TextView mWhen = (TextView) findViewById(R.id.request_detail_when);
// String date = DateFormat.getDateInstance().format(new Date(data.date));
// mWhen.setText(date);
// if (date.equals(DateFormat.getDateInstance().format(new Date()))) {
// mWhen.setText("URGENT");
// mWhen.setTextColor(0xFFFF0000);
// }
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Button add = (Button) findViewById(R.id.add_button);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loc = location.getText().toString();
transport_btn = (RadioButton) findViewById(transport_group.getCheckedRadioButtonId());
quan = quantity.getSelectedItem().toString();
String transport_text = (String) transport_btn.getText();
if (transport_text.equals("Available")) {
transport = true;
} else if (transport_text.equals("Not Available")) {
transport = false;
}
final Context context = getApplicationContext();
new_request = db.push();
String address = loc + ", Lahore, Pakistan";
new GetCoordinates().execute(address.replace(" ", "+"));
// BloodRequest request = new BloodRequest(user.getUid(), pname, bgroup, quan, num, loc, lat, lng, diag, pdate.getTime(), transport);
// new_request.setValue(request);
dialog = new Dialog(AddRequestOrgActivity.this);
dialog.setTitle("Add Request");
dialog.setContentView(R.layout.popup_submit);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button add_request = (Button) dialog.findViewById(R.id.button_ok);
add_request.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddRequestOrgActivity.this, MainActivityOrg.class);
intent.putExtra("mEmail", mEmail);
startActivity(intent);
}
});
}
});
}
use of android.widget.DatePicker in project focus-android by mozilla-mobile.
the class GeckoViewPrompt method onDateTimePrompt.
@Override
public void onDateTimePrompt(final GeckoSession session, final String title, final int type, final String value, final String min, final String max, final TextCallback callback) {
final Activity activity = mActivity;
if (activity == null) {
callback.dismiss();
return;
}
final String format;
if (type == DATETIME_TYPE_DATE) {
format = "yyyy-MM-dd";
} else if (type == DATETIME_TYPE_MONTH) {
format = "yyyy-MM";
} else if (type == DATETIME_TYPE_WEEK) {
format = "yyyy-'W'ww";
} else if (type == DATETIME_TYPE_TIME) {
format = "HH:mm";
} else if (type == DATETIME_TYPE_DATETIME_LOCAL) {
format = "yyyy-MM-dd'T'HH:mm";
} else {
throw new UnsupportedOperationException();
}
final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ROOT);
final Date minDate = parseDate(formatter, min, /* defaultToNow */
false);
final Date maxDate = parseDate(formatter, max, /* defaultToNow */
false);
final Date date = parseDate(formatter, value, /* defaultToNow */
true);
final Calendar cal = formatter.getCalendar();
cal.setTime(date);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final LayoutInflater inflater = LayoutInflater.from(builder.getContext());
final DatePicker datePicker;
if (type == DATETIME_TYPE_DATE || type == DATETIME_TYPE_MONTH || type == DATETIME_TYPE_WEEK || type == DATETIME_TYPE_DATETIME_LOCAL) {
final int resId = builder.getContext().getResources().getIdentifier("date_picker_dialog", "layout", "android");
DatePicker picker = null;
if (resId != 0) {
try {
picker = (DatePicker) inflater.inflate(resId, /* root */
null);
} catch (final ClassCastException | InflateException e) {
}
}
if (picker == null) {
picker = new DatePicker(builder.getContext());
}
picker.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), /* listener */
null);
if (minDate != null) {
picker.setMinDate(minDate.getTime());
}
if (maxDate != null) {
picker.setMaxDate(maxDate.getTime());
}
datePicker = picker;
} else {
datePicker = null;
}
final TimePicker timePicker;
if (type == DATETIME_TYPE_TIME || type == DATETIME_TYPE_DATETIME_LOCAL) {
final int resId = builder.getContext().getResources().getIdentifier("time_picker_dialog", "layout", "android");
TimePicker picker = null;
if (resId != 0) {
try {
picker = (TimePicker) inflater.inflate(resId, /* root */
null);
} catch (final ClassCastException | InflateException e) {
}
}
if (picker == null) {
picker = new TimePicker(builder.getContext());
}
setTimePickerTime(picker, cal);
picker.setIs24HourView(DateFormat.is24HourFormat(builder.getContext()));
timePicker = picker;
} else {
timePicker = null;
}
final LinearLayout container = addStandardLayout(builder, title, /* msg */
null);
container.setPadding(/* left */
0, /* top */
0, /* right */
0, /* bottom */
0);
if (datePicker != null) {
container.addView(datePicker);
}
if (timePicker != null) {
container.addView(timePicker);
}
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (which == DialogInterface.BUTTON_NEUTRAL) {
// Clear
callback.confirm("");
return;
}
if (datePicker != null) {
cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
}
if (timePicker != null) {
setCalendarTime(cal, timePicker);
}
callback.confirm(formatter.format(cal.getTime()));
}
};
builder.setNegativeButton(android.R.string.cancel, /* listener */
null).setNeutralButton(R.string.gv_prompt_clear, listener).setPositiveButton(android.R.string.ok, listener);
createStandardDialog(builder, callback).show();
}
use of android.widget.DatePicker in project sdk_demo_app_android by zendesk.
the class CreateDateActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == android.R.id.home) {
Log.i(Global.LOG_TAG, "Pressed home");
onBackPressed();
return true;
}
// noinspection SimplifiableIfStatement
if (id == R.id.action_save) {
DatePicker datePicker = this.findViewById(R.id.datePicker);
TimePicker timePicker = this.findViewById(R.id.timePicker);
EditText title = this.findViewById(R.id.nameText);
if (title.getText().toString().matches("")) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// set dialog message
alertDialogBuilder.setTitle("Error").setMessage("You need to fill the title!").setCancelable(false).setPositiveButton("OK", null);
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
return true;
}
Time time = new Time();
time.year = datePicker.getYear();
time.month = datePicker.getMonth();
time.monthDay = datePicker.getDayOfMonth();
time.hour = timePicker.getCurrentHour();
time.minute = timePicker.getCurrentMinute();
long millis = time.toMillis(false);
String millisStr = String.valueOf(millis);
Map<String, DateModel> dateMap = new HashMap<>(storage.loadMapData());
if (key == null) {
// Sets key to be a the time represented as a long in milliseconds
key = millisStr;
} else {
dateMap.remove(key);
key = millisStr;
}
Log.i(Global.LOG_TAG, "onOptionsItemSelected: " + key + title.getText().toString());
DateModel date = new DateModel(title.getText().toString(), time);
dateMap.put(key, date);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, LocalNotification.class);
intent.putExtra("message", title.getText().toString());
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, (int) millis, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, millis, pendingIntent);
storage.storeMapData(dateMap);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
use of android.widget.DatePicker in project fitness-app by seemoo-lab.
the class SetDateInteraction method selectDate.
/**
* Lets the user select the date to override.
*/
private void selectDate() {
final int currentYear = calendar.get(Calendar.YEAR);
final int currentMonth = calendar.get(Calendar.MONTH);
final int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
DatePickerDialog mDatePickerDialog = new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, monthOfYear);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
selectTime();
}
}, currentYear, currentMonth, currentDay);
mDatePickerDialog.setTitle("Select date:");
mDatePickerDialog.setButton(DatePickerDialog.BUTTON_NEGATIVE, "", mDatePickerDialog);
mDatePickerDialog.setCancelable(false);
mDatePickerDialog.show();
}
});
}
Aggregations