Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/Hannah/master' into FontColor
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/morristaedt/mirror/SetUpActivity.java
  • Loading branch information
sokris95 committed May 20, 2016
2 parents 2f2abda + 49c650b commit b69e858
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 4 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/com/morristaedt/mirror/MirrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.morristaedt.mirror.modules.BirthdayModule;
import com.morristaedt.mirror.modules.CalendarModule;
import com.morristaedt.mirror.modules.ChoresModule;
import com.morristaedt.mirror.modules.CountdownModule;
import com.morristaedt.mirror.modules.DayModule;
import com.morristaedt.mirror.modules.ForecastModule;
import com.morristaedt.mirror.modules.MoodModule;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class MirrorActivity extends ActionBarActivity {
private TextView mNewsHeadline;
private TextView mCalendarTitleText;
private TextView mCalendarDetailsText;
private TextView mCountdownText;

private XKCDModule.XKCDListener mXKCDListener = new XKCDModule.XKCDListener() {
@Override
Expand Down Expand Up @@ -137,6 +139,19 @@ public void onCalendarUpdate(String title, String details) {
}
};

private CountdownModule.CountdownListener mCountdownListener = new CountdownModule.CountdownListener() {
@Override
public void onCountdownUpdate(final String timeLeft) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mCountdownText.setVisibility(View.VISIBLE);
mCountdownText.setText(timeLeft);
}
});
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -176,6 +191,7 @@ protected void onCreate(Bundle savedInstanceState) {
mNewsHeadline = (TextView) findViewById(R.id.news_headline);
mCalendarTitleText = (TextView) findViewById(R.id.calendar_title);
mCalendarDetailsText = (TextView) findViewById(R.id.calendar_details);
mCountdownText = (TextView) findViewById(R.id.countdown_text);

if (mConfigSettings.invertXKCD()) {
//Negative of XKCD image
Expand Down Expand Up @@ -277,6 +293,12 @@ private void setViewState() {
} else {
mMoodText.setVisibility(View.GONE);
}

if (mConfigSettings.showCountdown()){
CountdownModule.getTimeRemaining(mConfigSettings.getCountdownEnd(), mCountdownListener);
} else {
mCountdownText.setVisibility(View.GONE);
}
}

@Override
Expand Down
62 changes: 60 additions & 2 deletions app/src/main/java/com/morristaedt/mirror/SetUpActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.SeekBar;
Expand Down Expand Up @@ -46,18 +47,23 @@ public class SetUpActivity extends Activity {
private CheckBox mShowNewsHeadlineCheckbox;
private CheckBox mXKCDCheckbox;
private CheckBox mXKCDInvertCheckbox;
private CheckBox mCountdownCheckbox;
private CheckBox mNewCountdownCheckbox;
private View mNewCountdownView;
private View mLocationView;
private View mColorShowView;
private EditText mLatitude;
private EditText mLongitude;
private EditText mStockTickerSymbol;
private SeekBar mColorPickerRed;
private EditText mCountdownDays;
private EditText mCountdownHours;
private EditText mCountdownMins;
private EditText mCountdownSecs; private SeekBar mColorPickerRed;
private SeekBar mColorPickerGreen;
private SeekBar mColorPickerBlue;
private TextView mColorShowerRed;
private TextView mColorShowerGreen;
private TextView mColorShowerBlue;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -166,6 +172,48 @@ public void onStopTrackingTouch(SeekBar seekBar) {}
mStockTickerSymbol = (EditText) findViewById(R.id.stock_name);
mStockTickerSymbol.setText(mConfigSettings.getStockTickerSymbol());

mCountdownCheckbox = (CheckBox) findViewById(R.id.countdown_checkbox);
mCountdownCheckbox.setChecked(mConfigSettings.showCountdown());

mNewCountdownCheckbox = (CheckBox) findViewById(R.id.countdown_new_checkbox);
mNewCountdownCheckbox.setChecked(false);
if (!mConfigSettings.showCountdown()) {
mNewCountdownCheckbox.setVisibility(View.GONE);
}

mNewCountdownView = findViewById(R.id.new_countdown_view);
mNewCountdownView.setVisibility(View.GONE);

mCountdownDays = (EditText) findViewById(R.id.countdown_days);
mCountdownHours = (EditText) findViewById(R.id.countdown_hours);
mCountdownMins = (EditText) findViewById(R.id.countdown_mins);
mCountdownSecs = (EditText) findViewById(R.id.countdown_secs);

mCountdownCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked){
mNewCountdownCheckbox.setVisibility(View.VISIBLE);
} else {
mNewCountdownCheckbox.setChecked(false);
mNewCountdownCheckbox.setVisibility(View.GONE);
mNewCountdownView.setVisibility(View.GONE);
}
}
});

mNewCountdownCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked){
mNewCountdownView.setVisibility(View.VISIBLE);
} else {
mNewCountdownView.setVisibility(View.GONE);
}
}
});


findViewById(R.id.launch_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -244,6 +292,16 @@ private void saveFields() {
mConfigSettings.setShowNextCalendarEvent(mShowNextCaledarEventCheckbox.isChecked());
mConfigSettings.setShowNewsHeadline(mShowNewsHeadlineCheckbox.isChecked());
mConfigSettings.setXKCDPreference(mXKCDCheckbox.isChecked(), mXKCDInvertCheckbox.isChecked());
mConfigSettings.setShowCountdown(mCountdownCheckbox.isChecked());
if (mNewCountdownCheckbox.isChecked()){
mConfigSettings.setCountdownTime(
Integer.parseInt("0"+mCountdownDays.getText().toString()),
Integer.parseInt("0"+mCountdownHours.getText().toString()),
Integer.parseInt("0"+mCountdownMins.getText().toString()),
Integer.parseInt("0"+mCountdownSecs.getText().toString()));
mNewCountdownCheckbox.setChecked(false);
mNewCountdownView.setVisibility(View.GONE);
}

if (mLocation == null) {
mConfigSettings.setLatLon(mLatitude.getText().toString(), mLongitude.getText().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.morristaedt.mirror.BuildConfig;
import com.morristaedt.mirror.requests.ForecastRequest;

import java.util.Date;

/**
* Created by HannahMitt on 9/26/15.
*/
Expand All @@ -32,6 +34,8 @@ public class ConfigurationSettings {
private static final String LAT = "lat";
private static final String LON = "lon";
private static final String STOCK_TICKER = "stock_ticker";
private static final String SHOW_COUNTDOWN = "show_countdown";
private static final String COUNTDOWN_END = "countdown_end";

@NonNull
private SharedPreferences mSharedPrefs;
Expand All @@ -44,6 +48,9 @@ public class ConfigurationSettings {
private boolean mShowNewsHeadline;
private boolean mShowXKCD;
private boolean mInvertXKCD;
private boolean mShowCountdown;

private long mCountdownEnd;

private String mLatitude;
private String mLongitude;
Expand All @@ -66,6 +73,8 @@ private void readPrefs() {
mShowNewsHeadline = mSharedPrefs.getBoolean(SHOW_HEADLINE, false);
mShowXKCD = mSharedPrefs.getBoolean(SHOW_XKCD, false);
mInvertXKCD = mSharedPrefs.getBoolean(INVERT_XKCD, false);
mShowCountdown = mSharedPrefs.getBoolean(SHOW_COUNTDOWN, false);
mCountdownEnd = mSharedPrefs.getLong(COUNTDOWN_END, System.currentTimeMillis());

mLatitude = mSharedPrefs.getString(LAT, "");
mLongitude = mSharedPrefs.getString(LON, "");
Expand Down Expand Up @@ -153,6 +162,21 @@ public void setStockTickerSymbol(String tickerSymbol) {
editor.apply();
}

public void setShowCountdown(boolean showCountdown){
mShowCountdown = showCountdown;
SharedPreferences.Editor editor = mSharedPrefs.edit();
editor.putBoolean(SHOW_COUNTDOWN, showCountdown);
editor.apply();
}

public void setCountdownTime(int days, int hours, int mins, int secs){
mCountdownEnd = System.currentTimeMillis();
mCountdownEnd += (((days*24l+hours)*60l+mins)*60l+secs)*1000l;
SharedPreferences.Editor editor = mSharedPrefs.edit();
editor.putLong(COUNTDOWN_END, mCountdownEnd);
editor.apply();
}

public boolean getIsCelsius() {
return ForecastRequest.UNITS_SI.equals(mForecastUnits);
}
Expand Down Expand Up @@ -189,6 +213,14 @@ public boolean invertXKCD() {
return mInvertXKCD;
}

public boolean showCountdown(){
return mShowCountdown;
}

public Date getCountdownEnd(){
return new Date(mCountdownEnd);
}

public String getLatitude() {
return mLatitude;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.morristaedt.mirror.modules;

import android.app.Activity;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class CountdownModule {

public interface CountdownListener {
void onCountdownUpdate(String timeLeft);
}

private static Timer timer;

public static void getTimeRemaining(final Date countdownEnd, final CountdownListener listener){
if (timer != null) {
timer.cancel();
}
timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
long timeLeft = countdownEnd.getTime() - System.currentTimeMillis();
listener.onCountdownUpdate(formatTime(timeLeft));
}
}, 0, 1000);
}

private static String formatTime(long time) {
String formattedTime = "Time is up!";

time /= 1000; //convert to secs
if (time <= 0){
return formattedTime;
}
formattedTime = time%60 + "s";

time /= 60; //convert to mins
if (time == 0){
return formattedTime;
}
formattedTime = time%60 + "m " + formattedTime;

time /= 60; //convert to hours
if (time == 0) {
return formattedTime;
}
formattedTime = time%60 + "h " + formattedTime;

time /= 24; //convert to days
if (time == 0) {
return formattedTime;
}
formattedTime = time + "d " + formattedTime;

return formattedTime;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ protected String doInBackground(Void... params) {
String url = "http://feeds.bbci.co.uk/news/world/rss.xml?edition=uk";
try {
RSSFeed feed = rssReader.load(url);
return feed.getItems().get(0).getTitle();
String headline = feed.getItems().get(0).getTitle();
for (int i = 1; i < 10; ++i) {
headline += " " + feed.getItems().get(i).getTitle();
}
return headline;
} catch (RSSReaderException e) {
Log.e("NewsModule", "Error parsing RSS");
return null;
Expand Down
Loading

0 comments on commit b69e858

Please sign in to comment.