Skip to content

Commit

Permalink
Added feature to change text color.
Browse files Browse the repository at this point in the history
  • Loading branch information
sokris95 committed Mar 23, 2016
1 parent eb3955f commit 2f2abda
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/morristaedt/mirror/MirrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
Expand Down Expand Up @@ -206,7 +207,20 @@ protected void onNewIntent(Intent intent) {
setViewState();
}

private void colorTextViews(ViewGroup mview){
for (int i = 0; i < mview.getChildCount(); i++) {
View view = mview.getChildAt(i);
if (view instanceof ViewGroup)
colorTextViews((ViewGroup) view);
else if (view instanceof TextView) {
((TextView) view).setTextColor(mConfigSettings.getTextColor());
}
}
}

private void setViewState() {
colorTextViews((ViewGroup) findViewById(R.id.main_layout));

String birthday = BirthdayModule.getBirthday();
if (TextUtils.isEmpty(birthday)) {
mBirthdayText.setVisibility(View.GONE);
Expand Down
78 changes: 78 additions & 0 deletions app/src/main/java/com/morristaedt/mirror/SetUpActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
Expand All @@ -16,6 +17,8 @@
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.morristaedt.mirror.configuration.ConfigurationSettings;
Expand Down Expand Up @@ -44,9 +47,16 @@ public class SetUpActivity extends Activity {
private CheckBox mXKCDCheckbox;
private CheckBox mXKCDInvertCheckbox;
private View mLocationView;
private View mColorShowView;
private EditText mLatitude;
private EditText mLongitude;
private EditText mStockTickerSymbol;
private SeekBar mColorPickerRed;
private SeekBar mColorPickerGreen;
private SeekBar mColorPickerBlue;
private TextView mColorShowerRed;
private TextView mColorShowerGreen;
private TextView mColorShowerBlue;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -58,6 +68,74 @@ protected void onCreate(Bundle savedInstanceState) {
mTemperatureChoice = (RadioGroup) findViewById(R.id.temperature_group);
mTemperatureChoice.check(mConfigSettings.getIsCelsius() ? R.id.celsius : R.id.farenheit);

mColorPickerRed = (SeekBar) findViewById(R.id.ColorPickerRed);
mColorPickerRed.setProgress(Color.red(mConfigSettings.getTextColor()));

mColorPickerGreen = (SeekBar) findViewById(R.id.ColorPickerGreen);
mColorPickerGreen.setProgress(Color.green(mConfigSettings.getTextColor()));

mColorPickerBlue = (SeekBar) findViewById(R.id.ColorPickerBlue);
mColorPickerBlue.setProgress(Color.blue(mConfigSettings.getTextColor()));

mColorShowerRed = (TextView) findViewById(R.id.ColorShowerRed);
mColorShowerRed.setText(String.format("%d", Color.red(mConfigSettings.getTextColor())));

mColorShowerGreen = (TextView) findViewById(R.id.ColorShowerGreen);
mColorShowerGreen.setText(String.format("%d", Color.green(mConfigSettings.getTextColor())));

mColorShowerBlue = (TextView) findViewById(R.id.ColorShowerBlue);
mColorShowerBlue.setText(String.format("%d", Color.blue(mConfigSettings.getTextColor())));

mColorShowView = findViewById(R.id.colored_bar);
mColorShowView.setBackgroundColor(mConfigSettings.getTextColor());

mColorPickerRed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mConfigSettings.setTextColorRed(progress);
mColorShowerRed.setText(String.format("%d", progress));
mColorShowView.setBackgroundColor(mConfigSettings.getTextColor());
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

mColorPickerGreen.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mConfigSettings.setTextColorGreen(progress);
mColorShowerGreen.setText(String.format("%d", progress));
mColorShowView.setBackgroundColor(mConfigSettings.getTextColor());
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});

mColorPickerBlue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mConfigSettings.setTextColorBlue(progress);
mColorShowerBlue.setText(String.format("%d", progress));
mColorShowView.setBackgroundColor(mConfigSettings.getTextColor());
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});

mBikingCheckbox = (CheckBox) findViewById(R.id.biking_checkbox);
mBikingCheckbox.setChecked(mConfigSettings.showBikingHint());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.text.TextUtils;

Expand All @@ -21,6 +22,7 @@ public class ConfigurationSettings {
private static final String PREFS_MIRROR = "MirrorPrefs";

private static final String FORECAST_UNITS = "forecast_units";
private static final String TEXT_COLOR = "text_color";
private static final String BIKING_HINT = "biking_hint";
private static final String USE_MOOD_DETECTION = "mood_detection";
private static final String SHOW_CALENDAR = "show_calendar";
Expand Down Expand Up @@ -48,13 +50,16 @@ public class ConfigurationSettings {

private String mStockTickerSymbol;

private int mTextColor;

public ConfigurationSettings(Context context) {
mSharedPrefs = context.getSharedPreferences(PREFS_MIRROR, Context.MODE_PRIVATE);
readPrefs();
}

private void readPrefs() {
mForecastUnits = mSharedPrefs.getString(FORECAST_UNITS, ForecastRequest.UNITS_US);
mTextColor = mSharedPrefs.getInt(TEXT_COLOR, Color.WHITE);
mShowBikingHint = mSharedPrefs.getBoolean(BIKING_HINT, false);
mShowMoodDetection = mSharedPrefs.getBoolean(USE_MOOD_DETECTION, false);
mShowNextCalendarEvent = mSharedPrefs.getBoolean(SHOW_CALENDAR, false);
Expand All @@ -74,6 +79,25 @@ public void setIsCelsius(boolean isCelsius) {
editor.apply();
}

public void setTextColorRed(int red){
setTextColor(Color.rgb(red, Color.green(mTextColor), Color.blue(mTextColor)));
}

public void setTextColorGreen(int green){
setTextColor(Color.rgb(Color.red(mTextColor), green, Color.blue(mTextColor)));
}

public void setTextColorBlue(int blue){
setTextColor(Color.rgb(Color.red(mTextColor), Color.green(mTextColor), blue));
}

public void setTextColor(int color){
mTextColor = color;
SharedPreferences.Editor editor = mSharedPrefs.edit();
editor.putInt(TEXT_COLOR, color);
editor.apply();
}

public void setShowBikingHint(boolean show) {
mShowBikingHint = show;
SharedPreferences.Editor editor = mSharedPrefs.edit();
Expand Down Expand Up @@ -137,6 +161,10 @@ public String getForecastUnits() {
return mForecastUnits;
}

public int getTextColor() {
return mTextColor;
}

public boolean showBikingHint() {
return mShowBikingHint;
}
Expand Down
117 changes: 117 additions & 0 deletions app/src/main/res/layout/activity_configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,123 @@

</RadioGroup>

<TextView
style="@style/ConfigurationItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Text Color" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/item_margin"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R" />

<SeekBar
android:id="@+id/ColorPickerRed"
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="255"/>

<TextView
android:id="@+id/ColorShowerRed"
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minEms="3"
android:text="0" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="G" />

<SeekBar
android:id="@+id/ColorPickerGreen"
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="255"/>

<TextView
android:id="@+id/ColorShowerGreen"
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minEms="3"
android:text="0" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />

<SeekBar
android:id="@+id/ColorPickerBlue"
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="255"/>

<TextView
android:id="@+id/ColorShowerBlue"
style="@style/ConfigurationItemText"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minEms="3"
android:text="0" />
</LinearLayout>
</LinearLayout>

<View
android:id="@+id/colored_bar"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>

<CheckBox
android:id="@+id/biking_checkbox"
style="@style/ConfigurationItemText"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_mirror.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
Expand Down

0 comments on commit 2f2abda

Please sign in to comment.