Skip to content
Open
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'io.realm:realm-android:0.87.1'
}
37 changes: 36 additions & 1 deletion app/src/main/java/slidenerd/vivz/bucketdrops/ActivityMain.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
package slidenerd.vivz.bucketdrops;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

public class ActivityMain extends AppCompatActivity {

Toolbar mToolbar;
Button mBtnAdd;
private View.OnClickListener mBtnAddListener = new View.OnClickListener() {

@Override
public void onClick(View v) {
showDialogAdd();
}
};

private void showDialogAdd() {
DialogAdd dialog = new DialogAdd();
dialog.show(getSupportFragmentManager(),"Add");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mBtnAdd = (Button) findViewById(R.id.btn_add);

mBtnAdd.setOnClickListener(mBtnAddListener);
setSupportActionBar(mToolbar);
initBackgroundImage();
}

private void initBackgroundImage() {
ImageView background = (ImageView) findViewById(R.id.iv_background);
Glide.with(this)
.load(R.drawable.background)
.centerCrop()
.into(background);
}
}
77 changes: 77 additions & 0 deletions app/src/main/java/slidenerd/vivz/bucketdrops/DialogAdd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package slidenerd.vivz.bucketdrops;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;

import io.realm.Realm;
import io.realm.RealmConfiguration;
import slidenerd.vivz.bucketdrops.beans.Drop;

/**
* Created by vivz on 28/12/15.
*/
public class DialogAdd extends DialogFragment {

private ImageButton mBtnClose;
private EditText mInputWhat;
private DatePicker mInputWhen;
private Button mBtnAdd;

private View.OnClickListener mBtnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int id =v.getId();
switch (id){
case R.id.btn_add_it:
addAction();
break;
}
dismiss();
}
};

private void addAction() {
//get the value of the 'goal' or 'to-do'
//get the time when it was added
String what=mInputWhat.getText().toString();
long now = System.currentTimeMillis();
RealmConfiguration configuration=new RealmConfiguration.Builder(getActivity()).build();
Realm.setDefaultConfiguration(configuration);
Realm realm=Realm.getDefaultInstance();
Drop drop= new Drop(what, now, 0, false);
realm.beginTransaction();
realm.copyToRealm(drop);
realm.commitTransaction();
realm.close();

}

public DialogAdd() {
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_add, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mBtnClose = (ImageButton) view.findViewById(R.id.btn_close);
mInputWhat = (EditText) view.findViewById(R.id.et_drop);
mInputWhen = (DatePicker) view.findViewById(R.id.bpv_date);
mBtnAdd = (Button) view.findViewById(R.id.btn_add_it);

mBtnClose.setOnClickListener(mBtnClickListener);
mBtnAdd.setOnClickListener(mBtnClickListener);
}
}
57 changes: 57 additions & 0 deletions app/src/main/java/slidenerd/vivz/bucketdrops/beans/Drop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package slidenerd.vivz.bucketdrops.beans;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;

/**
* Created by vivz on 30/12/15.
*/
public class Drop extends RealmObject {
public Drop(String what, long added, long when, boolean completed) {
this.what = what;
this.added = added;
this.when = when;
this.completed = completed;
}

private String what;
@PrimaryKey
private long added;
private long when;
private boolean completed;

public Drop() {
}

public String getWhat() {
return what;
}

public void setWhat(String what) {
this.what = what;
}

public long getAdded() {
return added;
}

public void setAdded(long added) {
this.added = added;
}

public long getWhen() {
return when;
}

public void setWhen(long when) {
this.when = when;
}

public boolean isCompleted() {
return completed;
}

public void setCompleted(boolean completed) {
this.completed = completed;
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/color/btn_add_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/dark_blue" android:state_pressed="true" />
<item android:color="@android:color/white" />
</selector>
Binary file added app/src/main/res/drawable-hdpi/ic_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/ic_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/bg_btn_add_it.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/green" />
<corners android:radius="@dimen/btn_add_it_corner_radius_green" />
</shape>
</item>
<item>
<shape>
<stroke android:width="@dimen/btn_add_it_stroke_width" android:color="@color/purple" />
<solid android:color="@android:color/transparent" />
<corners android:radius="@dimen/btn_add_it_corner_radius_purple" />
</shape>
</item>
</selector>
Binary file added app/src/main/res/drawable/logo_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 12 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="slidenerd.vivz.bucketdrops.ActivityMain">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />

<!--Warning! This code will crash as we are attempting to load the entire image in the main thread in one go-->
<ImageView
android:id="@+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar" />

<include layout="@layout/empty_drops" />
</RelativeLayout>
47 changes: 47 additions & 0 deletions app/src/main/res/layout/dialog_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/tv_title_vertical_margin"
android:layout_marginTop="@dimen/tv_title_vertical_margin"
android:text="@string/str_add_drop"
android:textSize="@dimen/tv_title_font_size" />

<ImageButton
android:id="@+id/btn_close"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignBottom="@id/tv_title"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/tv_title"
android:background="@null"
android:src="@drawable/ic_close" />

<EditText
android:id="@+id/et_drop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textVisiblePassword"
android:layout_below="@id/tv_title"
android:hint="@string/hint_et_drop"
android:padding="16dp" />

<DatePicker
android:id="@+id/bpv_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/et_drop" />

<Button
android:id="@+id/btn_add_it"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bpv_date"
android:textAllCaps="false"
android:text="@string/str_add_it"/>
</RelativeLayout>
31 changes: 31 additions & 0 deletions app/src/main/res/layout/empty_drops.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_logo"
android:layout_width="@dimen/iv_logo_size"
android:layout_height="@dimen/iv_logo_size"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/iv_logo_margin"
android:src="@drawable/logo_large" />

<Button
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_logo"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/btn_add_margin"
android:background="@drawable/bg_btn_add_it"
android:fontFamily="@string/sans_serif_thin"
android:paddingBottom="@dimen/btn_add_vertical_padding"
android:paddingLeft="@dimen/btn_add_horizontal_padding"
android:paddingRight="@dimen/btn_add_horizontal_padding"
android:paddingTop="@dimen/btn_add_vertical_padding"
android:text="@string/str_add_drop"
android:textAllCaps="false"
android:textColor="@color/btn_add_color"
android:textSize="@dimen/btn_add_font_size" />
</RelativeLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/dark_blue">

</android.support.v7.widget.Toolbar>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="purple">#B691FF</color>
<color name="green">#05FFCA</color>
<color name="dark_blue">#241543</color>
</resources>
17 changes: 17 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

<!--Used the background drawable for the button Add a drop inside empty drops xml file-->
<dimen name="btn_add_it_corner_radius_purple">2dp</dimen>
<dimen name="btn_add_it_corner_radius_green">2dp</dimen>
<dimen name="btn_add_it_stroke_width">1dp</dimen>

<!--The properties associated with the ImageView displaying the logo inside empty drops xml file-->
<dimen name="iv_logo_size">192dp</dimen>
<dimen name="iv_logo_margin">84dp</dimen>

<!--The properties associated with the Button displaying 'Add a drop' inside empty drops xml file-->
<dimen name="btn_add_margin">24dp</dimen>
<dimen name="btn_add_vertical_padding">8dp</dimen>
<dimen name="btn_add_horizontal_padding">60dp</dimen>
<dimen name="btn_add_font_size">28sp</dimen>
<dimen name="tv_title_vertical_margin">36dp</dimen>
<dimen name="tv_title_font_size">18sp</dimen>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<resources>
<string name="app_name">BucketDrops</string>
<string name="str_add_drop">Add a drop</string>
<string name="sans_serif_thin">sans-serif-thin</string>
<string name="hint_et_drop">What is it?</string>
<string name="str_add_it">Add It</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down