commit e9b99880d7ff143bc3fbfb15f714ded93f37038c Author: Phillip Hsu Date: Fri May 27 02:23:44 2016 -0700 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6cbe56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..eee3071 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Clock+ \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9a8b7e5 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..452bbbd --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6a1e020 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c737274 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..9a17300 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.android.application' +apply plugin: 'com.neenbedankt.android-apt' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.3" + + defaultConfig { + applicationId "com.philliphsu.clock" + minSdkVersion 19 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + provided 'com.google.auto.value:auto-value:1.2' + apt 'com.google.auto.value:auto-value:1.2' + compile 'com.android.support:appcompat-v7:23.2.1' + compile 'com.android.support:design:23.2.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..6e37b71 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/philliphsu/clock/ApplicationTest.java b/app/src/androidTest/java/com/philliphsu/clock/ApplicationTest.java new file mode 100644 index 0000000..8bcdb38 --- /dev/null +++ b/app/src/androidTest/java/com/philliphsu/clock/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.philliphsu.clock; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0b00313 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/philliphsu/clock/Alarm.java b/app/src/main/java/com/philliphsu/clock/Alarm.java new file mode 100644 index 0000000..b1d79d0 --- /dev/null +++ b/app/src/main/java/com/philliphsu/clock/Alarm.java @@ -0,0 +1,177 @@ +package com.philliphsu.clock; + +import com.google.auto.value.AutoValue; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +/** + * Created by Phillip Hsu on 5/26/2016. + */ +@AutoValue +public abstract class Alarm { + private static final int MAX_MINUTES_CAN_SNOOZE = 30; + // Define our own day constants because those in the + // Calendar class are not zero-based. + public static final int SUNDAY = 0; + public static final int MONDAY = 1; + public static final int TUESDAY = 2; + public static final int WEDNESDAY = 3; + public static final int THURSDAY = 4; + public static final int FRIDAY = 5; + public static final int SATURDAY = 6; + public static final int NUM_DAYS = 7; + + // =========== MUTABLE =========== + private long snoozingUntilMillis; + private boolean enabled; + // =============================== + public abstract long id(); // TODO: Counter in the repository. Set this field as the repo creates instances. + public abstract int hour(); + public abstract int minutes(); + @SuppressWarnings("mutable") + // TODO: Consider using an immutable collection instead + public abstract boolean[] recurringDays(); // array itself is immutable, but elements are not + public abstract String label(); + public abstract String ringtone(); + public abstract boolean vibrates(); + /** Initializes a Builder to the same property values as this instance */ + public abstract Builder toBuilder(); + + public static void main(String[] args) { + Alarm a = Alarm.builder().build(); + } + + public static Builder builder() { + // Unfortunately, default values must be provided for generated Builders. + // Fields that were not set when build() is called will throw an exception. + return new AutoValue_Alarm.Builder() + .id(-1) + .hour(0) + .minutes(0) + .recurringDays(new boolean[NUM_DAYS]) + .label("") + .ringtone("") + .vibrates(false); + } + + public final void snooze(int minutes) { + if (minutes <= 0 || minutes > MAX_MINUTES_CAN_SNOOZE) + throw new IllegalArgumentException("Cannot snooze for "+minutes+" minutes"); + snoozingUntilMillis = System.currentTimeMillis() + minutes * 60000; + } + + public final long snoozingUntil() { + return snoozingUntilMillis; + } + + public final boolean isSnoozed() { + if (snoozingUntilMillis <= System.currentTimeMillis()) { + snoozingUntilMillis = 0; + return false; + } + return true; + } + + public final void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public final boolean isEnabled() { + return enabled; + } + + public final void setRecurring(int day, boolean recurring) { + checkDay(day); + recurringDays()[day] = recurring; + } + + public final boolean isRecurring(int day) { + checkDay(day); + return recurringDays()[day]; + } + + public final boolean hasRecurrence() { + for (boolean b : recurringDays()) + if (b) return true; + return false; + } + + public final long ringsAt() { + // Always with respect to the current date and time + Calendar calendar = new GregorianCalendar(); + calendar.set(Calendar.HOUR_OF_DAY, hour()); + calendar.set(Calendar.MINUTE, minutes()); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + if (calendar.getTimeInMillis() <= System.currentTimeMillis()) { + // The specified time has passed for today + // TODO: This should be wrapped in an if (!hasRecurrence())? + calendar.add(Calendar.HOUR_OF_DAY, 24); + // TODO: Else, compute ring time for the next closest recurring day + } + + /* // Not fully thought out or completed! + // TODO: Compute ring time for the next closest recurring day + for (int i = 0; i < NUM_DAYS; i++) { + // The constants for the days defined in Calendar are + // not zero-based, but we are, so we must add 1. + int day = i + 1; // day for this index + int calendarDay = mCalendar.get(Calendar.DAY_OF_WEEK); + if (mRecurringDays[day]) { + mCalendar.add(Calendar.DAY_OF_WEEK, day); + break; + } + } + */ + return calendar.getTimeInMillis(); + } + + public final long ringsIn() { + return ringsAt() - System.currentTimeMillis(); + } + + /** @return true if this Alarm will ring in the next {@code hours} hours */ + public final boolean ringsWithinHours(int hours) { + return ringsIn() <= hours * 3600000; + } + + @AutoValue.Builder + public abstract static class Builder { + // Builder is mutable, so these are inherently setter methods. + // By omitting the set- prefix, we reduce the number of changes required to define the Builder + // class after copying and pasting the accessor fields here. + public abstract Builder id(long id); + public abstract Builder hour(int hour); + public abstract Builder minutes(int minutes); + /* // TODO: If using an immutable collection instead, can use its Builder instance + // and provide an "accumulating" method + abstract boolean[] recurringDays(); + public final Builder setRecurring(int day, boolean recurs) { + recurringDays()[day] = recurs; + return this; + } + */ + public abstract Builder recurringDays(boolean[] recurringDays); + public abstract Builder label(String label); + public abstract Builder ringtone(String ringtone); + public abstract Builder vibrates(boolean vibrates); + // To enforce preconditions, split the build method into two. autoBuild() is hidden from + // callers and is generated. You implement the public build(), which calls the generated + // autoBuild() and performs your desired validations. + /*not public*/abstract Alarm autoBuild(); + + public final Alarm build() { + Alarm alarm = autoBuild(); + if (alarm.hour() < 0 || alarm.hour() > 23 || alarm.minutes() < 0 || alarm.minutes() > 59) { + throw new IllegalStateException("Hour and minutes invalid"); + } + return alarm; + } + } + + private void checkDay(int day) { + if (day < SUNDAY || day > SATURDAY) + throw new IllegalArgumentException("Invalid day " + day); + } +} diff --git a/app/src/main/java/com/philliphsu/clock/MainActivity.java b/app/src/main/java/com/philliphsu/clock/MainActivity.java new file mode 100644 index 0000000..4a26458 --- /dev/null +++ b/app/src/main/java/com/philliphsu/clock/MainActivity.java @@ -0,0 +1,162 @@ +package com.philliphsu.clock; + +import android.support.design.widget.TabLayout; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; + +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; + +import android.widget.TextView; + +public class MainActivity extends AppCompatActivity { + + /** + * The {@link android.support.v4.view.PagerAdapter} that will provide + * fragments for each of the sections. We use a + * {@link FragmentPagerAdapter} derivative, which will keep every + * loaded fragment in memory. If this becomes too memory intensive, it + * may be best to switch to a + * {@link android.support.v4.app.FragmentStatePagerAdapter}. + */ + private SectionsPagerAdapter mSectionsPagerAdapter; + + /** + * The {@link ViewPager} that will host the section contents. + */ + private ViewPager mViewPager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + // Create the adapter that will return a fragment for each of the three + // primary sections of the activity. + mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + + // Set up the ViewPager with the sections adapter. + mViewPager = (ViewPager) findViewById(R.id.container); + mViewPager.setAdapter(mSectionsPagerAdapter); + + TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); + tabLayout.setupWithViewPager(mViewPager); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + }); + + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @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(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + public PlaceholderFragment() { + } + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static PlaceholderFragment newInstance(int sectionNumber) { + PlaceholderFragment fragment = new PlaceholderFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_main, container, false); + TextView textView = (TextView) rootView.findViewById(R.id.section_label); + textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER))); + return rootView; + } + } + + /** + * A {@link FragmentPagerAdapter} that returns a fragment corresponding to + * one of the sections/tabs/pages. + */ + public class SectionsPagerAdapter extends FragmentPagerAdapter { + + public SectionsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + // getItem is called to instantiate the fragment for the given page. + // Return a PlaceholderFragment (defined as a static inner class below). + return PlaceholderFragment.newInstance(position + 1); + } + + @Override + public int getCount() { + // Show 3 total pages. + return 3; + } + + @Override + public CharSequence getPageTitle(int position) { + switch (position) { + case 0: + return "SECTION 1"; + case 1: + return "SECTION 2"; + case 2: + return "SECTION 3"; + } + return null; + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..ce3a239 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml new file mode 100644 index 0000000..3099ffc --- /dev/null +++ b/app/src/main/res/layout/fragment_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..c580a79 --- /dev/null +++ b/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..dbbdd40 --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,9 @@ + + + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..cef3abc --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + 16dp + 16dp + 16dp + 8dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..a5b61dc --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,5 @@ + + Clock+ + Settings + Hello World from section: %1$d + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..177cefc --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + +