Skip to content

Instantly share code, notes, and snippets.

Avatar

Magda Miu magdamiu

View GitHub Profile
View CustomDatePickerExample.java
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
@magdamiu
magdamiu / TimePickerDialogExample.java
Last active Dec 10, 2019
TimePickerDialog example
View TimePickerDialogExample.java
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
@magdamiu
magdamiu / AlertDialogExample.java
Last active Dec 10, 2019
Create and show an AlertDialog with buttons
View AlertDialogExample.java
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.notice));
builder.setMessage(getString(R.string.alert_title));
// add the buttons
builder.setPositiveButton(getString(R.string.launch_app), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(AlertsActivity.this, getString(R.string.launch_app) + " " + getString(R.string.click), Toast.LENGTH_SHORT).show();
View cardview_example.xml
// add this dependency in gradle file
implementation 'androidx.cardview:cardview:1.0.0'
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="148dp"
android:layout_marginTop="16dp"
app:cardCornerRadius="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
@magdamiu
magdamiu / gradient.xml
Last active Jul 27, 2021
Gradient with Animation
View gradient.xml
// gradients
// gradient_1.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="225"
android:endColor="#1a2980"
android:startColor="#26d0ce" />
</shape>
@magdamiu
magdamiu / shape_and_stroke.xml
Last active May 4, 2019
Shape drawable with stroke and gradient
View shape_and_stroke.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:centerColor="#1976d2"
android:centerX="0.1"
android:centerY="0.1"
android:endColor="#6200ea"
android:gradientRadius="100"
@magdamiu
magdamiu / fab.xml
Last active Dec 10, 2019
FloatingActionButton style
View fab.xml
implementation 'com.google.android.material:material:1.2.0-alpha02'
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/space_16"
android:src="@android:drawable/ic_dialog_email"
android:tint="@color/light_green"
@magdamiu
magdamiu / SnackBarExample.java
Last active Dec 10, 2019
Snackbar should be added in a view which contains a CoordinatorLayout.
View SnackBarExample.java
Snackbar snackbar = Snackbar
.make(view, R.string.error_occured, Snackbar.LENGTH_LONG)
.setAction(R.string.retry, new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(AlertsActivity.this, getString(R.string.retry_message), Toast.LENGTH_LONG).show();
}
});
snackbar.setActionTextColor(Color.RED);
View snackbarView = snackbar.getView();
View User.java
// Gradle dependencies
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
public class User {
@magdamiu
magdamiu / OnGetUsersCallback.java
Created Jan 14, 2019
OnGetUsersCallback interface to manage the response from the API
View OnGetUsersCallback.java
public interface OnGetUsersCallback {
void onSuccess(List<User> users);
void onError();
}