summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Prezkuta <fermion@gmx.com>2015-08-09 17:05:25 -0600
committerZach Prezkuta <fermion@gmx.com>2015-08-14 20:28:03 -0600
commitc4b791a029bd70cdc611e537efcb8b03780703ae (patch)
treeae493f154cec7a3c6263532555777b18c0855f66
parent4619501ac40f473170a0cff9023283c548df2b14 (diff)
downloadpackages_apps_LockClock-c4b791a029bd70cdc611e537efcb8b03780703ae.zip
packages_apps_LockClock-c4b791a029bd70cdc611e537efcb8b03780703ae.tar.gz
packages_apps_LockClock-c4b791a029bd70cdc611e537efcb8b03780703ae.tar.bz2
Allow user to change background color/transparency for the widget,
for greater compatibility with various wallpapers Use slider for background transparency adjustment Change-Id: I7f1d00fd5df6ea52b127287fc17baf1477fbb9a3
-rw-r--r--AndroidManifest.xml4
-rw-r--r--res/layout/appwidget.xml3
-rw-r--r--res/layout/background_transparency.xml28
-rw-r--r--res/layout/weather_panel.xml8
-rw-r--r--res/values/strings.xml4
-rw-r--r--res/xml/preferences_clock.xml15
-rw-r--r--src/com/cyanogenmod/lockclock/ClockWidgetService.java8
-rwxr-xr-xsrc/com/cyanogenmod/lockclock/misc/Constants.java6
-rw-r--r--src/com/cyanogenmod/lockclock/misc/Preferences.java12
-rw-r--r--src/com/cyanogenmod/lockclock/preference/BackgroundTransparency.java200
10 files changed, 280 insertions, 8 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8d45a72..1bf0043 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -16,8 +16,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyanogenmod.lockclock"
- android:versionCode="20"
- android:versionName="3.4.0" >
+ android:versionCode="21"
+ android:versionName="3.4.1" >
<uses-sdk android:minSdkVersion="21" />
diff --git a/res/layout/appwidget.xml b/res/layout/appwidget.xml
index dc8fe8e..0af81c2 100644
--- a/res/layout/appwidget.xml
+++ b/res/layout/appwidget.xml
@@ -26,15 +26,12 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top" />
- <!-- Use a negative top margin to create a bit of an overlap
- and get rid of some of the gap -->
<include layout="@layout/weather_panel"
android:id="@+id/weather_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:layout_below="@id/clock_panel"
- android:layout_marginTop="-4dp"
android:visibility="gone" />
<include layout="@layout/calendar_panel"
diff --git a/res/layout/background_transparency.xml b/res/layout/background_transparency.xml
new file mode 100644
index 0000000..482fb6f
--- /dev/null
+++ b/res/layout/background_transparency.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_horizontal"
+ android:paddingStart="20dip"
+ android:paddingEnd="20dip">
+
+ <SeekBar android:id="@+id/background_transparency_seekbar"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+</FrameLayout>
diff --git a/res/layout/weather_panel.xml b/res/layout/weather_panel.xml
index 5401081..4af7732 100644
--- a/res/layout/weather_panel.xml
+++ b/res/layout/weather_panel.xml
@@ -53,7 +53,9 @@
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
- android:padding="4dip"
+ android:paddingLeft="4dip"
+ android:paddingRight="4dip"
+ android:paddingBottom="4dip"
android:gravity="center"
android:src="@android:drawable/ic_dialog_alert" />
@@ -63,7 +65,9 @@
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/weather_image"
android:orientation="horizontal"
- android:padding="4dip" >
+ android:paddingLeft="4dip"
+ android:paddingRight="4dip"
+ android:paddingBottom="4dip" >
<TextView
android:id="@+id/weather_city"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c40d62e..9317151 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -189,6 +189,10 @@
<string name="font_color_timestamp">Timestamp font color</string>
<string name="font_color_calendar_details">Details font color</string>
+ <!-- Preferences - Background color -->
+ <string name="background_color">Background color</string>
+ <string name="background_transparency">Background transparency</string>
+
<!-- Calendar - Lookahead -->
<string name="calendar_lookahead_3hrs">3 hours</string>
<string name="calendar_lookahead_6hrs">6 hours</string>
diff --git a/res/xml/preferences_clock.xml b/res/xml/preferences_clock.xml
index 8eca8fe..04f6175 100644
--- a/res/xml/preferences_clock.xml
+++ b/res/xml/preferences_clock.xml
@@ -72,5 +72,20 @@
android:defaultValue="#80ffffff"
android:entries="@array/font_color_entries"
android:entryValues="@array/font_color_values" />
+
+ <ListPreference
+ android:key="clock_background_color"
+ android:title="@string/background_color"
+ android:summary="%s"
+ android:defaultValue="#ff000000"
+ android:entries="@array/font_color_entries"
+ android:entryValues="@array/font_color_values" />
+
+ <!-- Background transparency selection -->
+ <com.cyanogenmod.lockclock.preference.BackgroundTransparency
+ android:key="clock_background_transparency"
+ android:title="@string/background_transparency"
+ android:dialogTitle="@string/background_transparency"
+ android:persistent="false" />
</PreferenceCategory>
</PreferenceScreen>
diff --git a/src/com/cyanogenmod/lockclock/ClockWidgetService.java b/src/com/cyanogenmod/lockclock/ClockWidgetService.java
index 8402194..d5f6635 100644
--- a/src/com/cyanogenmod/lockclock/ClockWidgetService.java
+++ b/src/com/cyanogenmod/lockclock/ClockWidgetService.java
@@ -183,6 +183,14 @@ public class ClockWidgetService extends IntentService {
setClockSize(remoteViews, ratio);
}
+ // Set the widget background color/transparency
+ int backColor = Preferences.clockBackgroundColor(this);
+ int backTrans = Preferences.clockBackgroundTransparency(this);
+ backColor = (backTrans << 24) | (backColor & 0xFFFFFF);
+ remoteViews.setInt(R.id.clock_panel, "setBackgroundColor", backColor);
+ remoteViews.setInt(R.id.calendar_panel, "setBackgroundColor", backColor);
+ remoteViews.setInt(R.id.weather_panel, "setBackgroundColor", backColor);
+
// Do the update
mAppWidgetManager.updateAppWidget(id, remoteViews);
}
diff --git a/src/com/cyanogenmod/lockclock/misc/Constants.java b/src/com/cyanogenmod/lockclock/misc/Constants.java
index 751de2d..a7113f2 100755
--- a/src/com/cyanogenmod/lockclock/misc/Constants.java
+++ b/src/com/cyanogenmod/lockclock/misc/Constants.java
@@ -31,6 +31,8 @@ public class Constants {
public static final String CLOCK_SHOW_ALARM = "clock_show_alarm";
public static final String CLOCK_FONT_COLOR = "clock_font_color";
public static final String CLOCK_ALARM_FONT_COLOR = "clock_alarm_font_color";
+ public static final String CLOCK_BACKGROUND_COLOR = "clock_background_color";
+ public static final String CLOCK_BACKGROUND_TRANSPARENCY = "clock_background_transparency";
public static final String CLOCK_AM_PM_INDICATOR = "clock_am_pm_indicator";
public static final String SHOW_WEATHER = "show_weather";
@@ -91,7 +93,9 @@ public class Constants {
public static final String DEFAULT_LIGHT_COLOR = "#ffffffff";
public static final String DEFAULT_DARK_COLOR = "#80ffffff";
-
+ public static final String DEFAULT_BACKGROUND_COLOR = "#00000000";
+ public static final int DEFAULT_BACKGROUND_TRANSPARENCY = 0;
+
// Intent actions
public static final String ACTION_SHOW_FORECAST = "com.cyanogenmod.lockclock.action.SHOW_FORECAST";
diff --git a/src/com/cyanogenmod/lockclock/misc/Preferences.java b/src/com/cyanogenmod/lockclock/misc/Preferences.java
index 01e1d45..941e761 100644
--- a/src/com/cyanogenmod/lockclock/misc/Preferences.java
+++ b/src/com/cyanogenmod/lockclock/misc/Preferences.java
@@ -81,6 +81,18 @@ public class Preferences {
return color;
}
+ public static int clockBackgroundColor(Context context) {
+ int color = Color.parseColor(getPrefs(context).getString(Constants.CLOCK_BACKGROUND_COLOR,
+ Constants.DEFAULT_BACKGROUND_COLOR));
+ return color;
+ }
+
+ public static int clockBackgroundTransparency(Context context) {
+ int trans = getPrefs(context).getInt(Constants.CLOCK_BACKGROUND_TRANSPARENCY,
+ Constants.DEFAULT_BACKGROUND_TRANSPARENCY);
+ return trans;
+ }
+
public static int weatherFontColor(Context context) {
int color = Color.parseColor(getPrefs(context).getString(Constants.WEATHER_FONT_COLOR,
Constants.DEFAULT_LIGHT_COLOR));
diff --git a/src/com/cyanogenmod/lockclock/preference/BackgroundTransparency.java b/src/com/cyanogenmod/lockclock/preference/BackgroundTransparency.java
new file mode 100644
index 0000000..88eebe9
--- /dev/null
+++ b/src/com/cyanogenmod/lockclock/preference/BackgroundTransparency.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.lockclock.preference;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.os.UserHandle;
+import android.preference.DialogPreference;
+import android.provider.Settings;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.Button;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import com.cyanogenmod.lockclock.ClockWidgetProvider;
+import com.cyanogenmod.lockclock.R;
+import com.cyanogenmod.lockclock.misc.Constants;
+
+/**
+ * Preference for selection of background transparency for the clock widget
+ */
+public class BackgroundTransparency extends DialogPreference {
+ private static final String TAG = "BackgroundTransparency";
+
+ private final Context mContext;
+
+ private TransparencySeekBar mBackgroundTransparency;
+
+ private int mOriginalBackgroundTransparency;
+
+ private final int mDefaultBackgroundTransparency;
+
+ public BackgroundTransparency(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mContext = context;
+
+ mDefaultBackgroundTransparency = Constants.DEFAULT_BACKGROUND_TRANSPARENCY;
+ setDialogLayoutResource(R.layout.background_transparency);
+ }
+
+ @Override
+ protected void onBindDialogView(View view) {
+ super.onBindDialogView(view);
+
+ SharedPreferences getPrefs = mContext.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
+ mOriginalBackgroundTransparency = getPrefs.getInt(Constants.CLOCK_BACKGROUND_TRANSPARENCY,
+ Constants.DEFAULT_BACKGROUND_TRANSPARENCY);
+
+ SeekBar trans = (SeekBar) view.findViewById(R.id.background_transparency_seekbar);
+ mBackgroundTransparency = new TransparencySeekBar(trans);
+
+ mBackgroundTransparency.setProgress(mOriginalBackgroundTransparency);
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ super.onDialogClosed(positiveResult);
+ updateTransparency(positiveResult);
+ }
+
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ final Parcelable superState = super.onSaveInstanceState();
+ if (getDialog() == null || !getDialog().isShowing()) {
+ return superState;
+ }
+
+ // Save the dialog state
+ final SavedState myState = new SavedState(superState);
+ myState.originalBackgroundTransparency = mOriginalBackgroundTransparency;
+ myState.currentBackgroundTransparency = mBackgroundTransparency.getProgress();
+
+ // Restore the old state when the activity or dialog is being paused
+ updateTransparency(false);
+
+ return myState;
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state) {
+ if (state == null || !state.getClass().equals(SavedState.class)) {
+ // Didn't save state for us in onSaveInstanceState
+ super.onRestoreInstanceState(state);
+ return;
+ }
+
+ SavedState myState = (SavedState) state;
+ super.onRestoreInstanceState(myState.getSuperState());
+
+ mOriginalBackgroundTransparency = myState.originalBackgroundTransparency;
+ mBackgroundTransparency.setProgress(myState.currentBackgroundTransparency);
+
+ updateTransparency(true);
+ }
+
+ private static class SavedState extends BaseSavedState {
+ int originalBackgroundTransparency;
+ int currentBackgroundTransparency;
+
+ public SavedState(Parcelable superState) {
+ super(superState);
+ }
+
+ public SavedState(Parcel source) {
+ super(source);
+ originalBackgroundTransparency = source.readInt();
+ currentBackgroundTransparency = source.readInt();
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeInt(originalBackgroundTransparency);
+ dest.writeInt(currentBackgroundTransparency);
+ }
+
+ public static final Parcelable.Creator<SavedState> CREATOR =
+ new Parcelable.Creator<SavedState>() {
+
+ public SavedState createFromParcel(Parcel in) {
+ return new SavedState(in);
+ }
+
+ public SavedState[] newArray(int size) {
+ return new SavedState[size];
+ }
+ };
+ }
+
+ private void updateTransparency(boolean accept) {
+ int trans = accept ? mBackgroundTransparency.getProgress() : mOriginalBackgroundTransparency;
+ callChangeListener(trans);
+
+ SharedPreferences getPrefs = mContext.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
+ SharedPreferences.Editor edit = getPrefs.edit();
+ edit.putInt(Constants.CLOCK_BACKGROUND_TRANSPARENCY, trans);
+ edit.apply();
+ }
+
+ private class TransparencySeekBar implements SeekBar.OnSeekBarChangeListener {
+ private final SeekBar mSeekBar;
+
+ private static final int MIN = 0;
+ private static final int MAX = 255;
+ private static final int STEP = 5;
+
+ public TransparencySeekBar(SeekBar seekBar) {
+ mSeekBar = seekBar;
+
+ mSeekBar.setMax((MAX - MIN) / STEP);
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if (fromUser) {
+ updateTransparency(true);
+ }
+ }
+
+ public void setProgress(int progress) {
+ int p = Math.max(progress, MIN) - MIN;
+ mSeekBar.setProgress(Math.round((float) p / STEP));
+ }
+
+ public int getProgress() {
+ return mSeekBar.getProgress() * STEP + MIN;
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // Do nothing here
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // Do nothing here
+ }
+ }
+}