Add original project.
1
app/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
/build
|
29
app/build.gradle
Executable file
@ -0,0 +1,29 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion '28.0.3'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hyperling.apps.the45minuterule"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 28
|
||||
versionCode 7
|
||||
versionName "1.06"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testImplementation 'junit:junit:4.12'
|
||||
implementation group: 'com.android.support', name: 'appcompat-v7', version: '28.0.0'
|
||||
//compile 'com.google.android.gms:play-services-ads:17.1.2'
|
||||
implementation group: 'com.google.android.gms', name: 'play-services-ads', version: '17.1.2'
|
||||
}
|
17
app/proguard-rules.pro
vendored
Executable file
@ -0,0 +1,17 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /home/ling/WDBlue/Programming/Java/Android/android-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 *;
|
||||
#}
|
@ -0,0 +1,13 @@
|
||||
package com.hyperling.apps.the45minuterule;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
41
app/src/main/AndroidManifest.xml
Executable file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.hyperling.apps.the45minuterule">
|
||||
|
||||
<uses-sdk tools:overrideLibrary="com.google.android.gms,com.google.android.gms.ads" />
|
||||
|
||||
<!-- Include required permissions for Google Mobile Ads to run. -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/t45mr_icon_003"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
|
||||
|
||||
<!-- This meta-data tag is required to use Google Play Services. -->
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Include the AdActivity configChanges and theme. -->
|
||||
<activity
|
||||
android:name="com.google.android.gms.ads.AdActivity"
|
||||
android:theme="@android:style/Theme.Translucent" />
|
||||
<activity android:name=".Tips"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
483
app/src/main/java/com/hyperling/apps/the45minuterule/MainActivity.java
Executable file
@ -0,0 +1,483 @@
|
||||
package com.hyperling.apps.the45minuterule;
|
||||
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import com.google.android.gms.ads.AdView;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Primitive
|
||||
boolean debug, alarmSet, adsEnabled;
|
||||
int alarmHour, alarmMinute, currentHour, currentMinute;
|
||||
final int TIME_PICKER_DIALOG = 0;
|
||||
String TAG;
|
||||
|
||||
// Java
|
||||
Timer timer;
|
||||
TimerTask timerTask;
|
||||
|
||||
// Android
|
||||
Resources recs;
|
||||
|
||||
// Shared Preferences
|
||||
private SharedPreferences sharedPreferences;
|
||||
private String keySharedPreferences, keyAdsEnabled;
|
||||
|
||||
// Views
|
||||
Button btnTime;
|
||||
RadioGroup radioGroup;
|
||||
RadioButton rb1, rb2, rb3;
|
||||
TextView digitalClockHeader;
|
||||
TableLayout layClocks;
|
||||
ArrayList<TextView> clocks;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set up variables
|
||||
recs = getResources();
|
||||
|
||||
debug = recs.getString(R.string.debug).toLowerCase().equals("true");
|
||||
|
||||
alarmSet = false;
|
||||
|
||||
updateCurrentTime();
|
||||
|
||||
alarmHour = currentHour;
|
||||
alarmMinute = currentMinute;
|
||||
|
||||
// Strings
|
||||
TAG = recs.getString(R.string.TAG);
|
||||
keySharedPreferences = recs.getString(R.string.keySharedPreferences);
|
||||
keyAdsEnabled = recs.getString(R.string.keyAdsEnabled);
|
||||
|
||||
// Shared Preferences
|
||||
sharedPreferences = getSharedPreferences(keySharedPreferences, MODE_PRIVATE);
|
||||
|
||||
adsEnabled = sharedPreferences.getBoolean(keyAdsEnabled, false);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get the Views
|
||||
btnTime = (Button) findViewById(R.id.btnTime);
|
||||
|
||||
radioGroup = (RadioGroup) findViewById(R.id.rgTired);
|
||||
|
||||
rb1 = (RadioButton) findViewById(R.id.rb1);
|
||||
rb2 = (RadioButton) findViewById(R.id.rb2);
|
||||
rb3 = (RadioButton) findViewById(R.id.rb3);
|
||||
|
||||
digitalClockHeader = (TextView) findViewById(R.id.tvDigitalClocksHeader);
|
||||
|
||||
layClocks = (TableLayout) findViewById(R.id.layClocks);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Start manipulating stuff!
|
||||
btnTime.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Check if the time is already being shown
|
||||
showDialog(TIME_PICKER_DIALOG);
|
||||
}
|
||||
});
|
||||
|
||||
rb2.setChecked(true);
|
||||
|
||||
radioGroup.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (debug) System.out.println("Radio group was clicked");
|
||||
startCheckTime(false);
|
||||
}
|
||||
});
|
||||
|
||||
rb1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (debug) System.out.println("Radio 1 was clicked");
|
||||
startCheckTime(false);
|
||||
}
|
||||
});
|
||||
|
||||
rb2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (debug) System.out.println("Radio 2 was clicked");
|
||||
startCheckTime(false);
|
||||
}
|
||||
});
|
||||
|
||||
rb3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (debug) System.out.println("Radio 3 was clicked");
|
||||
startCheckTime(false);
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Finally, load ads >:)
|
||||
if ( adsEnabled) {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
// Load an ad into the AdMob banner view.
|
||||
AdView adView = (AdView) findViewById(R.id.adView);
|
||||
AdRequest adRequest = new AdRequest.Builder()
|
||||
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
|
||||
.addTestDevice("C6A494DC6E7C9AC29102694D48487084") // Nexus 7
|
||||
.addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G
|
||||
.addTestDevice("") // Cappy, even though it doesn't support ads
|
||||
.setRequestAgent("android_studio:ad_template")
|
||||
.build();
|
||||
adView.loadAd(adRequest);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
MenuItem checkForNewArticles = menu.findItem(R.id.action_enable_ads);
|
||||
checkForNewArticles.setChecked(adsEnabled);
|
||||
|
||||
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();
|
||||
|
||||
if (id == R.id.action_tips) {
|
||||
startActivity(new Intent(MainActivity.this, Tips.class));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id == R.id.action_enable_ads) {
|
||||
if (debug) Log.d(TAG, "MainActivity.onOptionsItemSelected: Before! adsEnabled=" + adsEnabled);
|
||||
adsEnabled = !adsEnabled;
|
||||
if (debug) Log.d(TAG, "MainActivity.onOptionsItemSelected: After! adsEnabled=" + adsEnabled);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean(keyAdsEnabled, adsEnabled);
|
||||
editor.commit();
|
||||
|
||||
if (adsEnabled){
|
||||
Toast.makeText(this, "Thank you!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else{
|
||||
Toast.makeText(this, "Disabled ads", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
item.setChecked(adsEnabled);
|
||||
|
||||
Intent intent = new Intent(MainActivity.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id == R.id.action_settings) {
|
||||
Toast.makeText(this, "I can't do that, Jim", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id == R.id.action_about) {
|
||||
Toast.makeText(this, "I can't do that, Jim", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id == R.id.action_help) {
|
||||
Toast.makeText(this, "I can't do that, Jim", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id == R.id.action_exit) {
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id){
|
||||
|
||||
switch(id){
|
||||
case TIME_PICKER_DIALOG:
|
||||
if (debug) System.out.println("Showing time picker");
|
||||
|
||||
TimePickerDialog.OnTimeSetListener timeSetListener = new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
if (debug) System.out.println("Time chosen is " + getTimeString(hourOfDay, minute));
|
||||
|
||||
alarmHour = hourOfDay;
|
||||
alarmMinute = minute;
|
||||
|
||||
btnTime.setText(getTimeString(alarmHour, alarmMinute));
|
||||
alarmSet = true;
|
||||
startCheckTime(true);
|
||||
}
|
||||
};
|
||||
|
||||
TimePickerDialog timePickerDialog = new TimePickerDialog(this, timeSetListener, alarmHour, alarmMinute, DateFormat.is24HourFormat(getApplicationContext()));
|
||||
|
||||
return timePickerDialog;
|
||||
}
|
||||
|
||||
if (debug) System.out.println("Returning null, id was " + id);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void calculateTimes(){
|
||||
if (debug) System.out.println("Calculating times");
|
||||
if (alarmHour == currentHour && alarmMinute == currentMinute){
|
||||
if (debug) System.out.println("Alarm time not set");
|
||||
return;
|
||||
}
|
||||
else{
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get how long we have until the alarm rings
|
||||
int hourDifference, minuteDifference, minutesUntilAlarm, sleepiness;
|
||||
|
||||
hourDifference = alarmHour;
|
||||
minuteDifference = alarmMinute;
|
||||
|
||||
if(alarmMinute < currentMinute){
|
||||
minuteDifference += 60;
|
||||
hourDifference -= 1;
|
||||
}
|
||||
|
||||
if (alarmHour < currentHour){
|
||||
hourDifference += 24;
|
||||
}
|
||||
|
||||
hourDifference -= currentHour;
|
||||
minuteDifference -= currentMinute;
|
||||
|
||||
minutesUntilAlarm = (60*hourDifference) + minuteDifference;
|
||||
if (debug) System.out.println("Number of minutes until the alarm rings: " + minutesUntilAlarm);
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get sleepiness of the user
|
||||
switch(radioGroup.getCheckedRadioButtonId()){
|
||||
case R.id.rb1:
|
||||
sleepiness = Integer.parseInt(recs.getString(R.string.rb_opt1_value));
|
||||
break;
|
||||
case R.id.rb2:
|
||||
sleepiness = Integer.parseInt(recs.getString(R.string.rb_opt2_value));
|
||||
break;
|
||||
case R.id.rb3:
|
||||
sleepiness = Integer.parseInt(recs.getString(R.string.rb_opt3_value));
|
||||
break;
|
||||
default:
|
||||
sleepiness = 0;
|
||||
}
|
||||
if (debug) System.out.println("Sleepiness is " + sleepiness);
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Do math and set the clocks
|
||||
int bedHour, bedMinute, remainder;
|
||||
|
||||
bedHour = currentHour;
|
||||
bedMinute = currentMinute;
|
||||
|
||||
minutesUntilAlarm -= sleepiness;
|
||||
|
||||
clocks = new ArrayList<TextView>();
|
||||
if ((minutesUntilAlarm) > 0){
|
||||
remainder = (minutesUntilAlarm%45);
|
||||
|
||||
if (remainder < 0){
|
||||
remainder += 45;
|
||||
}
|
||||
|
||||
bedMinute += remainder;
|
||||
while (minutesUntilAlarm >= 45) {
|
||||
|
||||
if (bedMinute >= 60) {
|
||||
bedMinute -= 60;
|
||||
bedHour += 1;
|
||||
if (bedHour >= 24) {
|
||||
bedHour -= 24;
|
||||
}
|
||||
}
|
||||
|
||||
TextView newClock = new TextView(this);
|
||||
newClock.setText(getTimeString(bedHour, bedMinute));
|
||||
|
||||
clocks.add(newClock);
|
||||
|
||||
minutesUntilAlarm -= 45;
|
||||
bedMinute += 45;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Lay out the text views
|
||||
TableRow.LayoutParams params = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
|
||||
|
||||
int loop = 0;
|
||||
TableRow newRow = new TableRow(this);
|
||||
|
||||
layClocks.removeAllViews();
|
||||
|
||||
if (clocks.size() > 0) {
|
||||
for (TextView clock : clocks) {
|
||||
if (loop % 3 == 0) {
|
||||
newRow = new TableRow(this);
|
||||
layClocks.addView(newRow);
|
||||
}
|
||||
|
||||
params.column = (loop % 3) + 1;
|
||||
|
||||
clock.setLayoutParams(params);
|
||||
clock.setTextSize(18);
|
||||
clock.setGravity(Gravity.CENTER);
|
||||
|
||||
newRow.addView(clock);
|
||||
|
||||
loop++;
|
||||
}
|
||||
|
||||
while (loop % 3 != 0){
|
||||
TextView blankClock = new TextView(this);
|
||||
|
||||
params.column = (loop % 3) + 1;
|
||||
|
||||
blankClock.setLayoutParams(params);
|
||||
blankClock.setText(recs.getString(R.string.blank));
|
||||
blankClock.setTextSize(18);
|
||||
blankClock.setGravity(Gravity.CENTER);
|
||||
|
||||
newRow.addView(blankClock);
|
||||
|
||||
loop++;
|
||||
}
|
||||
|
||||
// TODO: Remove temp string
|
||||
String temp = recs.getString(R.string.main_bedtimes_header) + ". Refreshed at " + getTimeString(currentHour, currentMinute);
|
||||
digitalClockHeader.setText(temp);
|
||||
}
|
||||
else{
|
||||
digitalClockHeader.setText(recs.getString(R.string.main_bedtimes_header_too_close));
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void startCheckTime(boolean setTimer){
|
||||
if (debug) System.out.println("Checking time");
|
||||
|
||||
updateCurrentTime();
|
||||
calculateTimes();
|
||||
|
||||
if (setTimer) {
|
||||
timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
startCheckTime(true);
|
||||
}
|
||||
};
|
||||
|
||||
timer = new Timer();
|
||||
|
||||
// TODO: Fix timer
|
||||
//timer.schedule(timerTask, 5000); // Recalculate time every 5 seconds
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void updateCurrentTime(){
|
||||
Calendar now = Calendar.getInstance();
|
||||
|
||||
currentHour = now.get(Calendar.HOUR_OF_DAY);
|
||||
currentMinute = now.get(Calendar.MINUTE);
|
||||
|
||||
currentMinute = now.get(Calendar.MINUTE);
|
||||
currentHour = now.get(Calendar.HOUR_OF_DAY);
|
||||
if (debug) System.out.println("Current time is " + getTimeString(currentHour, currentMinute));
|
||||
}
|
||||
|
||||
private String getTimeString(int hour, int minute){
|
||||
String time, hours, minutes, meridian;
|
||||
|
||||
if (minute < 10){
|
||||
minutes = "0" + Integer.toString(minute);
|
||||
}
|
||||
else{
|
||||
minutes = Integer.toString(minute);
|
||||
}
|
||||
|
||||
if (DateFormat.is24HourFormat(getApplicationContext())){
|
||||
hours = (hour < 10 ? "0"+Integer.toString(hour) : Integer.toString(hour));
|
||||
|
||||
time = hours + ":" + minutes;
|
||||
}
|
||||
else {
|
||||
if (hour > 12){
|
||||
hour -= 12;
|
||||
meridian = "PM";
|
||||
}
|
||||
else{
|
||||
meridian = "AM";
|
||||
}
|
||||
|
||||
hours = (hour == 0 ? "12" : Integer.toString(hour));
|
||||
|
||||
time = hours + ":" + minutes + meridian;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
44
app/src/main/java/com/hyperling/apps/the45minuterule/Tips.java
Executable file
@ -0,0 +1,44 @@
|
||||
package com.hyperling.apps.the45minuterule;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Tips extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_tips);
|
||||
|
||||
Resources recs = getResources();
|
||||
|
||||
String[] tips = recs.getStringArray(R.array.tips_tips_array);
|
||||
|
||||
LinearLayout layout = (LinearLayout) findViewById(R.id.layTipsArray);
|
||||
|
||||
int colorCounter = 0;
|
||||
for (String tip : tips){
|
||||
TextView newTip = new TextView(this);
|
||||
|
||||
newTip.setText(tip);
|
||||
|
||||
newTip.setPadding(8,8,0,4);
|
||||
|
||||
if (colorCounter % 2 == 0){
|
||||
newTip.setTextColor(recs.getColor(R.color.colorAccent));
|
||||
}
|
||||
else{
|
||||
newTip.setTextColor(recs.getColor(R.color.colorPrimaryDark));
|
||||
}
|
||||
|
||||
layout.addView(newTip);
|
||||
|
||||
colorCounter++;
|
||||
}
|
||||
}
|
||||
}
|
116
app/src/main/res/layout/activity_main.xml
Executable file
@ -0,0 +1,116 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:ads="http://schemas.android.com/apk/res-auto"
|
||||
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="com.hyperling.apps.the45minuterule.MainActivity">
|
||||
|
||||
<!-- view for AdMob Banner Ad -->
|
||||
<com.google.android.gms.ads.AdView
|
||||
android:id="@+id/adView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
ads:adSize="BANNER"
|
||||
ads:adUnitId="@string/main_banner_ad" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_above="@id/adView"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:id="@+id/scrollView">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/innerRelativeLayout">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_alignParentTop="true"
|
||||
android:id="@+id/layTime">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/main_header_choose_time"
|
||||
android:textSize="20sp"
|
||||
android:id="@+id/tvTime"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:text="@string/main_button_show_time"
|
||||
android:textSize="20sp"
|
||||
android:textAllCaps="false"
|
||||
android:id="@+id/btnTime"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/layTime"
|
||||
android:text="@string/main_rb_header"
|
||||
android:textSize="18sp"
|
||||
android:id="@+id/tvTired"/>
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/tvTired"
|
||||
android:id="@+id/rgTired">
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/main_rb_opt1"
|
||||
android:textSize="14sp"
|
||||
android:id="@+id/rb1"/>
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/main_rb_opt2"
|
||||
android:textSize="14sp"
|
||||
android:id="@+id/rb2"/>
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/main_rb_opt3"
|
||||
android:textSize="14sp"
|
||||
android:id="@+id/rb3"/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/rgTired"
|
||||
android:paddingTop="8dp"
|
||||
android:text="@string/blank"
|
||||
android:textSize="16sp"
|
||||
android:id="@+id/tvDigitalClocksHeader"/>
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tvDigitalClocksHeader"
|
||||
android:id="@+id/layClocks"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
33
app/src/main/res/layout/activity_tips.xml
Executable file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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="com.hyperling.apps.the45minuterule.Tips">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="@string/tips_tips_header"
|
||||
android:textSize="20sp"
|
||||
android:id="@+id/txtTipsHeader"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/txtTipsHeader">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/layTipsArray"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
46
app/src/main/res/menu/menu_main.xml
Executable file
@ -0,0 +1,46 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.hyperling.apps.the45minuterule.MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_tips"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_tips"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_enable_ads"
|
||||
android:orderInCategory="150"
|
||||
android:title="@string/action_enable_ads"
|
||||
app:showAsAction="never"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_about"
|
||||
android:orderInCategory="200"
|
||||
android:title="@string/action_about"
|
||||
app:showAsAction="never"
|
||||
android:visible="false" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="300"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never"
|
||||
android:visible="false" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_help"
|
||||
android:orderInCategory="400"
|
||||
android:title="@string/action_help"
|
||||
app:showAsAction="never"
|
||||
android:visible="false" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_exit"
|
||||
android:orderInCategory="500"
|
||||
android:title="@string/action_exit"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Executable file
After Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Executable file
After Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Executable file
After Width: | Height: | Size: 4.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Executable file
After Width: | Height: | Size: 7.5 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Executable file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/t45mr_icon_001.png
Executable file
After Width: | Height: | Size: 24 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/t45mr_icon_002.png
Executable file
After Width: | Height: | Size: 47 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/t45mr_icon_003.png
Executable file
After Width: | Height: | Size: 48 KiB |
10
app/src/main/res/values-v21/styles.xml
Executable file
@ -0,0 +1,10 @@
|
||||
<resources>>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:statusBarColor">@color/colorAccent</item>
|
||||
<item name="android:navigationBarColor">@color/colorAccent</item>
|
||||
</style>
|
||||
</resources>
|
6
app/src/main/res/values-w820dp/dimens.xml
Executable file
@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
6
app/src/main/res/values/colors.xml
Executable file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#FF9900</color>
|
||||
<color name="colorPrimaryDark">#333333</color>
|
||||
<color name="colorAccent">#330066</color>
|
||||
</resources>
|
6
app/src/main/res/values/dimens.xml
Executable file
@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
</resources>
|
65
app/src/main/res/values/strings.xml
Executable file
@ -0,0 +1,65 @@
|
||||
<resources>
|
||||
|
||||
<!-- App details -->
|
||||
<string name="app_name">The 45 Minute Rule</string>
|
||||
|
||||
<string name="TAG">com.hyperling.apps.the45minuterule</string>
|
||||
|
||||
<string name="action_tips">Sleep Tips</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_about">About</string>
|
||||
<string name="action_help">Help</string>
|
||||
<string name="action_exit">Exit</string>
|
||||
<string name="action_enable_ads">Enable Ads?</string>
|
||||
|
||||
<!-- TODO: Turn off debug before releases! -->
|
||||
<string name="debug">true</string>
|
||||
|
||||
<string name="blank"> </string>
|
||||
|
||||
<!-- Main Screen -->
|
||||
<string name="main_header_choose_time">Morning alarm time:</string>
|
||||
|
||||
<string name="main_button_show_time">Click me!</string>
|
||||
|
||||
<string name="main_rb_header">How tired are you?</string>
|
||||
|
||||
<string name="main_rb_opt1">Very Tired (Fall asleep in 5 minutes)</string>
|
||||
<string name="rb_opt1_value">5</string>
|
||||
<string name="main_rb_opt2">Tired (Fall asleep in less than 20 minutes)</string>
|
||||
<string name="rb_opt2_value">20</string>
|
||||
<string name="main_rb_opt3">Alert (Hopefully fall asleep in 30 or 40 minutes)</string>
|
||||
<string name="rb_opt3_value">35</string>
|
||||
|
||||
<string name="main_bedtimes_header">Times you could go to bed</string>
|
||||
<string name="main_bedtimes_header_too_close">Alarm is too soon, no valid times to sleep.</string>
|
||||
|
||||
<!-- Shared Preferences -->
|
||||
<string name="keySharedPreferences">t45mr</string>
|
||||
<string name="keyAdsEnabled">AdsEnabled</string>
|
||||
|
||||
<!-- Settings Screen -->
|
||||
|
||||
|
||||
<!-- Tips Screen -->
|
||||
<string name="tips_tips_header">Tips for a good night sleep:</string>
|
||||
|
||||
<string-array name="tips_tips_array">
|
||||
<item>Use a program like f.lux (or Twilight on Android) to reduce screen brightness at night.</item>
|
||||
<item>
|
||||
Eat a high carbohydrate meal for dinner. Carbohydrates help you fall asleep faster and are necessary for your body to repair itself.
|
||||
Dr. Neal Barnard recommends eating two pieces of bread if you can\'t fall asleep.
|
||||
</item>
|
||||
<item>Plan aerobic activity in your daily routine. Twenty minutes of walking can be very effective when done between dinner and bedtime.</item>
|
||||
</string-array>
|
||||
|
||||
<!-- About Screen -->
|
||||
|
||||
|
||||
<!-- -
|
||||
This is an ad unit ID for a banner test ad. Replace with your own banner ad unit id.
|
||||
For more information, see https://support.google.com/admob/answer/3052638
|
||||
<!- -->
|
||||
<string name="main_banner_ad">ca-app-pub-9712416021907617/8586703280</string>
|
||||
<string name="title_activity_blank_test">BlankTest</string>
|
||||
</resources>
|
22
app/src/main/res/values/styles.xml
Executable file
@ -0,0 +1,22 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<!--
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
-->
|
||||
|
||||
</resources>
|
15
app/src/test/java/com/hyperling/apps/the45minuterule/ExampleUnitTest.java
Executable file
@ -0,0 +1,15 @@
|
||||
package com.hyperling.apps.the45minuterule;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|