├── .gitattributes ├── .gitignore └── Dimmer ├── AndroidManifest.xml ├── README ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── others ├── Screenshots │ ├── Screenshot_2014-01-10-14-05-29.png │ ├── Screenshot_2014-01-10-14-05-43.png │ ├── Screenshot_2014-01-10-14-05-56.png │ ├── Screenshot_2014-01-14-10-06-41.png │ ├── Screenshot_2014-01-14-10-07-00.png │ ├── Screenshot_2014-01-14-10-07-13.png │ ├── Screenshot_2014-01-14-10-07-44.png │ ├── Screenshot_2014-01-14-10-08-55.png │ ├── Screenshot_2014-01-14-10-43-27.png │ ├── Screenshot_2014-01-14-10-44-00.png │ ├── Screenshot_2014-01-14-10-44-18.png │ ├── Screenshot_2014-04-16-14-28-01.png │ ├── Screenshot_2014-04-16-14-29-01.png │ ├── Screenshot_2014-04-16-14-30-01.png │ ├── Theme.png │ └── effect.png ├── keystore │ ├── Dimmer.apk │ └── giraffine ├── light-144-1.png ├── light-144-2.png ├── light-144-3.png ├── light-144.png ├── light-48-1.png ├── light-48-2.png ├── light-48-3.png ├── light-48.png ├── light-512-1.png ├── light-512-2.png ├── light-512.png ├── light-72-1.png ├── light-72-2.png ├── light-72-3.png ├── light-72.png ├── light-96-1.png ├── light-96-2.png ├── light-96-3.png └── light-96.png ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ ├── ic_launcher.png │ ├── ic_widget.png │ ├── seek_thumb_normal.png │ └── seek_thumb_pressed.png ├── drawable-mdpi │ ├── ic_launcher.png │ ├── ic_widget.png │ ├── seek_thumb_normal.png │ └── seek_thumb_pressed.png ├── drawable-xhdpi │ ├── ic_close.png │ ├── ic_down.png │ ├── ic_launcher.png │ ├── ic_pause.png │ ├── ic_start.png │ ├── ic_up.png │ ├── ic_widget.png │ ├── seek_thumb_normal.png │ └── seek_thumb_pressed.png ├── drawable-xxhdpi │ ├── ic_launcher.png │ └── ic_widget.png ├── layout │ ├── activity_dimmer.xml │ ├── color_picker.xml │ ├── mask_window.xml │ ├── notification.xml │ ├── setting_about.xml │ ├── setting_alarm.xml │ ├── setting_ap_list.xml │ ├── setting_ap_list_item.xml │ ├── setting_enter_bright.xml │ ├── setting_enter_dim.xml │ ├── setting_notify_range.xml │ ├── setting_notify_step.xml │ └── widget_layout.xml ├── menu │ └── dimmer_menu.xml ├── values-ar │ ├── arrays.xml │ └── strings.xml ├── values-de │ ├── arrays.xml │ └── strings.xml ├── values-es │ ├── arrays.xml │ └── strings.xml ├── values-fr │ ├── arrays.xml │ └── strings.xml ├── values-hu │ ├── arrays.xml │ └── strings.xml ├── values-in │ ├── arrays.xml │ └── strings.xml ├── values-it │ ├── arrays.xml │ └── strings.xml ├── values-ja │ ├── arrays.xml │ └── strings.xml ├── values-ko │ ├── arrays.xml │ └── strings.xml ├── values-nl │ ├── arrays.xml │ └── strings.xml ├── values-pl │ ├── arrays.xml │ └── strings.xml ├── values-pt │ ├── arrays.xml │ └── strings.xml ├── values-ru │ ├── arrays.xml │ └── strings.xml ├── values-sr │ ├── arrays.xml │ └── strings.xml ├── values-sw600dp │ └── dimens.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-uk │ ├── arrays.xml │ └── strings.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── values-zh-rCN │ ├── arrays.xml │ └── strings.xml ├── values-zh-rTW │ ├── arrays.xml │ └── strings.xml ├── values │ ├── arrays.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── xml │ ├── preference.xml │ └── widget.xml └── src └── giraffine └── dimmer ├── AlarmUtil.java ├── AlphaPatternDrawable.java ├── BootReceiver.java ├── BrightnessUtil.java ├── ColorPickerPreference.java ├── ColorPickerView.java ├── Dimmer.java ├── DimmerService.java ├── DimmerWidget.java ├── LightSensor.java ├── LuxUtil.java ├── Mask.java ├── Prefs.java ├── ProximitySensor.java ├── RangeSeekBar.java ├── SettingAbout.java ├── SettingAlarm.java ├── SettingApList.java ├── SettingEnterBright.java ├── SettingEnterDim.java ├── SettingNotifyLayout.java ├── SettingNotifyRange.java ├── SettingNotifyStep.java ├── SettingsActivity.java ├── SettingsFragment.java └── TaskerReceiver.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /Dimmer/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Dimmer/README: -------------------------------------------------------------------------------- 1 | Copyright 2014 giraffine@gmail.com 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /Dimmer/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/ic_launcher-web.png -------------------------------------------------------------------------------- /Dimmer/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/libs/android-support-v4.jar -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-10-14-05-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-10-14-05-29.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-10-14-05-43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-10-14-05-43.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-10-14-05-56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-10-14-05-56.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-06-41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-06-41.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-07-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-07-00.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-07-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-07-13.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-07-44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-07-44.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-08-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-08-55.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-43-27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-43-27.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-44-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-44-00.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-01-14-10-44-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-01-14-10-44-18.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-04-16-14-28-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-04-16-14-28-01.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-04-16-14-29-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-04-16-14-29-01.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Screenshot_2014-04-16-14-30-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Screenshot_2014-04-16-14-30-01.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/Theme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/Theme.png -------------------------------------------------------------------------------- /Dimmer/others/Screenshots/effect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/Screenshots/effect.png -------------------------------------------------------------------------------- /Dimmer/others/keystore/Dimmer.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/keystore/Dimmer.apk -------------------------------------------------------------------------------- /Dimmer/others/keystore/giraffine: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/keystore/giraffine -------------------------------------------------------------------------------- /Dimmer/others/light-144-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-144-1.png -------------------------------------------------------------------------------- /Dimmer/others/light-144-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-144-2.png -------------------------------------------------------------------------------- /Dimmer/others/light-144-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-144-3.png -------------------------------------------------------------------------------- /Dimmer/others/light-144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-144.png -------------------------------------------------------------------------------- /Dimmer/others/light-48-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-48-1.png -------------------------------------------------------------------------------- /Dimmer/others/light-48-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-48-2.png -------------------------------------------------------------------------------- /Dimmer/others/light-48-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-48-3.png -------------------------------------------------------------------------------- /Dimmer/others/light-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-48.png -------------------------------------------------------------------------------- /Dimmer/others/light-512-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-512-1.png -------------------------------------------------------------------------------- /Dimmer/others/light-512-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-512-2.png -------------------------------------------------------------------------------- /Dimmer/others/light-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-512.png -------------------------------------------------------------------------------- /Dimmer/others/light-72-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-72-1.png -------------------------------------------------------------------------------- /Dimmer/others/light-72-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-72-2.png -------------------------------------------------------------------------------- /Dimmer/others/light-72-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-72-3.png -------------------------------------------------------------------------------- /Dimmer/others/light-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-72.png -------------------------------------------------------------------------------- /Dimmer/others/light-96-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-96-1.png -------------------------------------------------------------------------------- /Dimmer/others/light-96-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-96-2.png -------------------------------------------------------------------------------- /Dimmer/others/light-96-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-96-3.png -------------------------------------------------------------------------------- /Dimmer/others/light-96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/others/light-96.png -------------------------------------------------------------------------------- /Dimmer/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Dimmer/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | -------------------------------------------------------------------------------- /Dimmer/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-hdpi/ic_widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-hdpi/ic_widget.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-hdpi/seek_thumb_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-hdpi/seek_thumb_normal.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-hdpi/seek_thumb_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-hdpi/seek_thumb_pressed.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-mdpi/ic_widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-mdpi/ic_widget.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-mdpi/seek_thumb_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-mdpi/seek_thumb_normal.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-mdpi/seek_thumb_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-mdpi/seek_thumb_pressed.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_close.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_down.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_pause.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_start.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_up.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/ic_widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/ic_widget.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/seek_thumb_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/seek_thumb_normal.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xhdpi/seek_thumb_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xhdpi/seek_thumb_pressed.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Dimmer/res/drawable-xxhdpi/ic_widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/res/drawable-xxhdpi/ic_widget.png -------------------------------------------------------------------------------- /Dimmer/res/layout/activity_dimmer.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 21 | 22 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Dimmer/res/layout/color_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Dimmer/res/layout/mask_window.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Dimmer/res/layout/notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 26 | 27 | 32 | 37 | 42 | 47 | 52 | 57 | 62 | 67 | 72 | 77 | 82 | 87 | 92 | 97 | 102 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_alarm.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_ap_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_ap_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_enter_bright.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | 26 | 27 | 28 | 29 | 33 | 34 | 37 | 38 | 44 | 45 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_enter_dim.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 18 | 19 | 26 | 27 | 35 | 36 | 37 | 38 | 42 | 43 | 47 | 48 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_notify_range.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | 27 | 28 | 29 | 30 | 33 | 34 | 40 | 41 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Dimmer/res/layout/setting_notify_step.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | 27 | 28 | 29 | 30 | 34 | 35 | 38 | 39 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Dimmer/res/layout/widget_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Dimmer/res/menu/dimmer_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Dimmer/res/values-ar/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | أعلى 5 | عالي 6 | عادي 7 | منخفض 8 | أدنى 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-ar/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | خفض الإضاءة 5 | إعدادات 6 | المس صعودا وهبوطا لضبط السطوع. 7 | 8 | الوضع التلقائي 9 | الخافت تلقائيا وسطع مثل البيئة. 10 | الحالي الإضاءة المحيطة: 11 | هذا الجهاز لا يدعم استشعار الإضاءة المحيطة. 12 | وضع ويدجت 13 | بنقرة واحدة رمز للتبديل الخافت والمشرق. 14 | يمكنك النقر فوق إشعار للدخول التطبيق. 15 | إدخال الخافت 16 | كشف أدنى الإضاءة المحيطة. 17 | تعيين أدنى ضوء 18 | ضوء المحيط 19 | عودة المشرقة 20 | فرق الضوء المحيط 21 | سرعة الاستجابة الخافت 22 | سرعة الاستجابة المشرقة 23 | وضع الوقت 24 | وقت الدخول الخافت 25 | وقت العودة المشرقة 26 | إيقاف 27 | إشعارات 28 | إخفاء أيقونة على شريط الحالة 29 | خطوة للتكيف 30 | مجموعة من التكيف 31 | زر الترتيب 32 | اضغط على زر طويل من أجل تغيير الموقع. 33 | فلتر اللون 34 | إنتقاء اللون 35 | استبعاد التطبيق 36 | اخرى 37 | زر تعطيل الخلفية 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-de/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | höchstes 5 | hoch 6 | normal 7 | niedrig 8 | niedrigstes 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-de/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dimmer 5 | Einstellungen 6 | Aufwärts und abwärts berühren um die Helligkeit zu regulieren. 7 | 8 | Automatischer Modus 9 | Abhängig von der Umgebung automatisch dimmen. 10 | Aktuelles Umgebungslicht: 11 | Gerät unterstützt keinen Umgebungslichtsensor. 12 | Widget Modus 13 | One-click-icon um zwischen Dimmen und hell zu schalten. 14 | App ist über das Benachrichtigungsfeld aufrufbar. 15 | Regulierung eingeben 16 | Ermittle geringstes Umgebungslicht 17 | Setze geringsten Lux-wert 18 | Umgebungslicht 19 | Zu hell zurückkehren 20 | Umgebungslichtdifferenz 21 | Reaktionsgeschwindigkeit des dimmens 22 | Reaktionsgeschwindigkeit des erhellens 23 | Zeitmodus 24 | Zeiteinstellung um zu dimmen 25 | Zeiteinstellung um zu erhellen 26 | Aus 27 | Benachrichtigung 28 | Symbol verbergen 29 | Einstellungsschritte 30 | Einstellungsbereich 31 | Tastenanordnung 32 | Lange drücken sie die taste, um position zu ändern 33 | Farbfilter 34 | Farbauswahl 35 | Auszuschließen App 36 | Andere 37 | Deaktivieren tastenbeleuchtung 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-es/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | El más alto 5 | Alto 6 | Normal 7 | Bajo 8 | El más bajo 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-es/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Atenuador 5 | Ajustes 6 | Toque arriba y abajo para ajustar el brillo. 7 | 8 | Modo automático 9 | Atenuar o dar brillo en función de la luz ambiental. 10 | Luz ambiente actual: 11 | Su dispositivo no dispone de sensor de luz ambiental. 12 | Modo widget 13 | Un toque alterna entre atenuado y brillante. 14 | Puede acceder a la aplicación desde el panel de notificaciones. 15 | Iniciar atenuado 16 | Detectar la luz ambiental mas baja. 17 | Fijar lux mínimo 18 | Luz ambiental 19 | Volver a brillo 20 | Diferencia de luz ambiental 21 | Velocidad de respuesta atenuado 22 | Velocidad de respuesta brillo 23 | Modo horario 24 | Hora para atenuar 25 | Hora para volver a brillo 26 | Apagado 27 | Notificación 28 | Ocultar icono en la barra de estado 29 | Pasos de ajuste 30 | Rango de ajuste 31 | Disposición de botones 32 | Pulse y mantenga para cambiar la posición. 33 | El filtro de color 34 | Selector de color 35 | Excluir aplicación 36 | Otro 37 | Desactivar el botón de luz de fondo 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-fr/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Le plus haut 5 | Haut 6 | Normal 7 | Faible 8 | Le plus bas 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-fr/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Variateur 5 | Réglages 6 | Presser haut et bas pour régler la luminosité 7 | 8 | Mode automatique 9 | Variation de luminosité automatique suivant l\'environnement 10 | Lumière ambiante actuelle: 11 | Cet appareil ne prend pas en charge le capteur de lumière ambiante 12 | Mode widget 13 | Passer de luminosité faible à intense en un clic 14 | Accéder à l\'application par la zone de notification 15 | Entrer dans la luminosité faible 16 | Détection de la lumière ambiante la plus basse 17 | Réglage du lux le plus bas 18 | Lumière ambiante 19 | Revenir à la luminosité élevée 20 | Différence de lumière ambiante 21 | Vitesse de réaction faible luminosité 22 | Vitesse de réaction haute luminosité 23 | Mode heure 24 | Heure de faible luminosité 25 | Heure de retour en luminosité élevée 26 | Arrêt 27 | Notification 28 | Cacher l\'icône de la barre de statut 29 | Niveau d\'ajustement 30 | Gamme d\'ajustement 31 | Arrangement des boutons 32 | Pression longue sur le bouton pour changer la position 33 | Filtre couleur 34 | Sélecteur de couleur 35 | Application exclue 36 | Autre 37 | Désactiver rétroéclairage des touches 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-hu/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Legmagasabb 5 | Magas 6 | Normál 7 | Alacsony 8 | Legalacsonyabb 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-hu/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Tompító 5 | Beállítások 6 | A fényerő állításához nyomd meg a fel vagy a le gombot. 7 | 8 | Automata üzemmód 9 | Fényerő automatikus állítása a környezeti fényerőnek megfelelően. 10 | Jelenlegi környezeti fényerő: 11 | Ez a készülék nem támogatja a környezeti fényerő érzékelését. 12 | Widget mód 13 | Egyetlen ikon a fény erősségének csökkentésére vagy növelésére. 14 | Az értesítésre való kattintással beléphetsz az alkalmazásba. 15 | Fényerő csökkentése 16 | Legalacsonyabb környezeti fényerő érzékelése. 17 | Legalacsonyabb fényerő beállítása 18 | Környezeti fényerő 19 | Visszaállítás világosra 20 | Környezeti fényerő különbség 21 | Fényerő csökkentésének sebessége 22 | Fényerő növelésének sebessége 23 | Időzítő mód 24 | Fényerő csökkentésének kezdő időpontja 25 | Fényerő visszaállításának időpontja 26 | KI 27 | Értesítés 28 | Elrejtése ikonra status bar 29 | Szabályozás lépésköze 30 | Szabályozás skálája 31 | Nyomógombok elrendezése 32 | Nyomd hosszan a gombot a pozíció megváltoztatásához. 33 | Színszűrő 34 | Színválasztó 35 | Alkalmazás kivételek 36 | Más 37 | Letiltása gomb háttérvilágítása 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-in/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Tertinggi 5 | Tinggi 6 | Normal 7 | Rendah 8 | Terendah 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-in/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dimmer 5 | Pengaturan 6 | Sentuh atas dan bawah untuk mengatur kecerahan. 7 | 8 | Modus otomatis. 9 | Redup dan terang secara otomatis sesuai lingkungan. 10 | Cahaya sekitar saat ini: 11 | Perangkat ini tidak mendukung sensor cahaya sekitar. 12 | Modus widget 13 | Sentuh ikon sekali untuk beralih terang dan redup. 14 | Anda dapat menyentuh notifikasi untuk memasuki aplikasi. 15 | Memasuki redup 16 | Deteksi cahaya sekitar terendah. 17 | Atur lux terendah 18 | Cahaya sekitar 19 | Kembalikan kecerahan 20 | Perbedaan cahaya sekitar 21 | Kecepatan respon meredup 22 | Kecepatan respon mencerah 23 | Modus waktu 24 | Waktu memasuki redup 25 | Waktu kembali mencerah 26 | Padam 27 | Notifikasi 28 | Sembunyikan ikon di bilah pemberitahuan 29 | Langkah pengaturan 30 | Jangkauan pengaturan 31 | Pengaturan tombol 32 | Sentuh dengan lama untuk mengubah posisi. 33 | Filter warna 34 | Pemilih warna 35 | Kecualikan aplikasi 36 | Lain-lain 37 | Nonaktifkan tombol lampu latar 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-it/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Massima 5 | Alta 6 | Normale 7 | Bassa 8 | Minima 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-it/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dimmer 5 | Impostazioni 6 | Tocca su e giù per regolare la luminosità. 7 | 8 | Modalità Automatica 9 | Regolare automaticamente la luminosità con l\'ambiente. 10 | Luminosità ambientale attuale: 11 | Questo dispositivo non ha il sensore di luminosità. 12 | Modalità Widget 13 | Tocca l\'icona per attivare e disattivare l\'attenuazione. 14 | Ora è possibile regolare la luminosità nell\'area di notifica 15 | Attiva attenuazione 16 | Rileva la luminosità ambientale minima 17 | Imposta lux minimo 18 | Luce ambientale 19 | Ritorna luminoso 20 | Differenza con luce ambientale 21 | Velocità di risposta attenuazione 22 | Velocità di riposta luminosità 23 | Modalità Oraria 24 | Attiva attenuazione alle ore 25 | Ritorna luminoso alle ore 26 | OFF 27 | Notifiche 28 | Nascondi l\'icona nella barra di stato 29 | Scatto di regolazione 30 | Intervallo di regolazione 31 | Disposizione pulsanti 32 | Pressione prolungata del pulsante per cambiare posizione 33 | Filtro colorato 34 | Selettore colori 35 | Escludi applicazione 36 | Altro 37 | Disabilita retroilluminazione tasti 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-ja/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 最高 5 | 高い 6 | 普通 7 | 低い 8 | 最低 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-ja/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 明るさ調節 5 | 設定 6 | 上下にスワイプして明るさを調節 7 | 8 | オートモード 9 | 周囲の状況に応じて自動的に明るさを調節します。 10 | 現在の周囲の明るさ: 11 | この端末には周囲の明るさを感知するセンサーがありません。 12 | ウィジェットモード 13 | アプリアイコンをクリックして明暗の切り替えをします。 14 | 元に戻すには通知領域のアイコンをクリックして下さい。 15 | 暗さ 16 | 最も低く感知した周囲の明るさ 17 | 最低のluxに設定 18 | 周囲の明るさ 19 | 戻った時の明るさ 20 | 周囲の明るさとの差 21 | 画面が暗くなるまでの反応速度 22 | 画面が明るくなるまでの反応速度 23 | タイマーモード 24 | 暗くする時間 25 | 元に戻す時間 26 | オフ 27 | 通知 28 | アイコンを隠す 29 | 明るさを増減する間隔 30 | 変更できる明るさの範囲 31 | ボタン配置 32 | 位置を変更するための長押しボタン 33 | カラーフィルター 34 | カラーセレクタ 35 | アプリケーションを除外する 36 | その他 37 | ボタンのバックライトを閉じる 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-ko/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 아주높음 5 | 높음 6 | 보통 7 | 낮음 8 | 아주낮음 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-ko/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 조광기 5 | 설정 6 | 밝기를 조절하려면 위 아래로 슬라이드 하세요 7 | 8 | 자동 모드 9 | 자동으로 밝아지고 어두워집니다 10 | 지금 현재 빛의 밝기: 11 | 이 장치는 주변 빛 센서를 지지하지 않습니다 12 | 위젯 모드 13 | 아이콘 클릭으로 밝음과 어두움을 조절합니다 14 | 당신은 앱 시작시 통지를 클릭할 수 있습니다 15 | 어둡게 설정 16 | 최하의 잔잔한 빛 감지 17 | 최하의 럭스로 설정 18 | 잔잔한 빛 19 | 밝기 되돌리기 20 | 잔잔한 빛 차이 21 | 어두운 응답 속도 22 | 밝은 응답 속도 23 | 시간 모드 24 | 어둑해 지는 시간 25 | 다시 밝아지는 시간 26 | 꺼짐 27 | 통지 28 | 상태 표시 줄에 아이콘 숨기기 29 | 조절 단계 30 | 조절 범위 31 | 버튼 배치 32 | 버튼을 길게 누르면 위치가 바뀜 33 | 컬러 필터 34 | 색상 선택기 35 | 제외할 앱 36 | 다른 37 | 버튼 백라이트를 사용하지 않도록 설정 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-nl/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Snelste 5 | Snel 6 | Normaal 7 | Langzaam 8 | Langzaamste 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-nl/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dimmer 4 | Instellingen 5 | Klik omhoog en omlaag om de helderheid aan te passen. 6 | Automatische modus 7 | Automatisch aanpassen aan de omgeving. 8 | Huidig omgevingslicht: 9 | Dit apparaat kan het omgevingslicht niet detecteren. 10 | Widget-modus 11 | Een keer klikken om te schakelen tussen gedimd en helder licht. 12 | Klik op de melding om de app te openen. 13 | Dimmer inschakelen 14 | Donkerste omgevingslicht detecteren 15 | Laagste lux instellen 16 | Omgevingslicht 17 | Terug naar helder 18 | Verschil met omgevingslicht 19 | Reactietijd van licht naar donker 20 | Reactietijd van donker naar licht 21 | Tijd-modus 22 | Scherm dimmen om 23 | Terug naar helder om 24 | Uitgeschakeld 25 | Melding 26 | Afbeelding in statusbalk verbergen 27 | Stapgrootte 28 | Aanpassingsbereik 29 | Volgorde van knoppen 30 | Lang vasthouden om posities te wijzigen. 31 | Kleurenfilter 32 | Kleurenkiezer 33 | Apps uitsluiten 34 | Overig 35 | Knopverlichting uitschakelen 36 | 37 | -------------------------------------------------------------------------------- /Dimmer/res/values-pl/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Największy 5 | Wysoki 6 | Normalny 7 | Niski 8 | Najniższy 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-pl/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Przygaszacz 5 | Ustawienia 6 | Dotknij w górę i w dół aby zmienić jasność. 7 | 8 | Tryb automatyczny 9 | Automatyczne zmienianie jasności. 10 | Aktualna jasność otoczenia: 11 | To urządzenie nie obsługuje sensoru jasności otoczenia. 12 | Tryb widżetu 13 | Dotknij ikonę aby zmienić jasność. 14 | Możesz dotknąć powiadomienia aby przejść do aplikacji. 15 | Wpisz przyciemnienie 16 | Wykryj najniższą jasność otoczenia. 17 | Ustaw najniższe lux 18 | Światło otoczenia 19 | Przywróć jasność 20 | Różnica światła otoczenia 21 | Prędkość reakcji ściemniania 22 | Prędkość reakcji jasności 23 | Tryb czasu 24 | Czas do zmiany jasności 25 | Czas do przywrócenia jasności 26 | Wyłącz 27 | Powiadomienia 28 | Ukryj ikonę na pasku statusu 29 | Krok regulacji 30 | Zakres regulacji 31 | Układ przycisków 32 | Naciśnij długo przycisk aby zmienić pozycję. 33 | Filtr kolorów 34 | Wyboru koloru 35 | Wyłącz aplikację 36 | Inne 37 | Wyłącz podświetlanie klawiszy 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-pt/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Alta 5 | Média 6 | Regular 7 | Baixa 8 | Fraca 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-pt/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dimmer - Escurecer Tela 5 | Configurações 6 | Deslize para cima ou para baixo para ajustar o brilho. 7 | 8 | Modo Automático 9 | Escurecer ou clarear conforme o ambiente. 10 | Luz atual do ambiente: 11 | Este dispositivo não é compatível com o sensor de luz ambiente. 12 | Modo Rápido 13 | Escurece a tela com um click no ícone da aplicação. 14 | Clique na notificação para entrar no aplicativo. 15 | Começar a escurecer 16 | Detectar menor luz ambiente. 17 | Definir menor luz 18 | Luz do ambiente 19 | Retornar o brilho 20 | Diferença da luz ambiente 21 | Velocidade para escurecer 22 | Velocidade para clarear 23 | Acionamento por Horário 24 | Escurecer tela ás 25 | Clarear tela ás 26 | Desativado 27 | Notificações 28 | Oculta ícone da barra de notificações 29 | Etapa de ajustamento 30 | Alcance de ajustamento 31 | Ordem dos Botões 32 | Pressione o botão por muito tempo para mudar de posição. 33 | Filtro colorido 34 | Seleção de cor 35 | Excluir aplicação 36 | Outro 37 | Desativar botão backlight 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-ru/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Очень высокая 5 | Высокая 6 | Нормальная 7 | Низкая 8 | Очень низкая 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-ru/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Диммер 5 | Настройки 6 | Листайте вверх и вниз для регулировки яркости 7 | 8 | Автоматический режим 9 | Подстройка под уровень освещения 10 | Текущий уровень освещенности: 11 | Это устройство не имеет датчика освещенности 12 | Режим виджета 13 | Переключение одним кликом по ярлыку 14 | Для доступа к настройкам кликните по уведомлению 15 | Начинать затемнение 16 | Определить минимум автоматически 17 | Автоматически 18 | Освещение 19 | Возвращать яркость 20 | Разница в освещении 21 | Скорость отклика затемнения 22 | Скорость отклика яркости 23 | Управление по времени 24 | Время начала затемнения 25 | Время возврата яркости 26 | ВЫКЛ. 27 | Уведомление 28 | спрятать значок в строке состояния 29 | Шаг регулировки 30 | Диапазон регулировки 31 | Расположение кнопок 32 | Нажмите и удерживайте для перемещения 33 | цветной фильтр 34 | выбора цвета 35 | Отключить в приложениях 36 | другой 37 | близко подсветка кнопки 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-sr/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Najbrže 5 | Brzo 6 | Normalna 7 | Sporo 8 | Najsporije 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-sr/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dimmer 5 | Podešavanja 6 | Dodirni strelice kako bi podesio osvetljenje. 7 | 8 | Automatski režim rada 9 | Automatsko podešavanje osvetljenja u skladu sa okruženjem. 10 | Trenutna jačina svetlosti u okruženju: 11 | Ovaj uređaj nema senzor za određivanje jačine svetlosti. 12 | Vidžet režim rada 13 | Dodirni ikonicu za promenu stanja osvetljenja. 14 | Dodirni ikonicu iz trake za obaveštenja za ulazak u aplikaciju. 15 | Pokreni smanjivanje osvetljenja 16 | Detektuj najmanju jačinu svetlosti. 17 | Podesi na najmanje 18 | Svetlo u okruženju 19 | Prekini smanjivanje osvetljenja 20 | Razlika osvetljenja okruženja 21 | Brzina smanjenja osvetljenja 22 | Brzina povećanja osvetljenja 23 | Podešavanje po vremenu 24 | Vreme smanjenja osvetljenja 25 | Vreme povećanja osvetljenja 26 | Isključeno 27 | Traka za obaveštenja 28 | Sakrij ikonicu sa trake za obaveštenja 29 | Veličina praga podešavanja 30 | Opseg podešavanja 31 | Raspored dugmadi 32 | Drži dugme pritisnutim kako bi mu promenio poziciju. 33 | Filter boja 34 | Izbor boja 35 | Izuzmi aplikacije 36 | Drugo 37 | Onemogući podešavanje osvetljenja dugmadi za navigaciju 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Dimmer/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /Dimmer/res/values-uk/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Дуже висока 5 | Висока 6 | Нормальна 7 | Низька 8 | Дуже низька 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-uk/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Диммер 5 | Налаштування 6 | Листайте вгору та вниз для регулювання яскравості 7 | 8 | Автоматичний режим 9 | Адаптація під рівень освітленості 10 | Поточний рівень освітлення: 11 | Цей пристрій не має датчику освітленності 12 | Режим віджета 13 | Перемикання режиму одним кліком по ярлику 14 | Для доступу до налаштувань клікніть по сповіщенню 15 | Починати затемнення 16 | Визначати мінімум автоматично 17 | Автоматично 18 | Освітлення 19 | Повертати яскравість 20 | Різниця у освітленні 21 | Швидкість відгуку затемнення 22 | Швидкість відгуку яскравості 23 | Керування за часом 24 | Час початку затемнення 25 | Час повернення яскравості 26 | ВИМК. 27 | Сповіщення 28 | заховати значок 29 | Крок регулювання 30 | Діапазон регулювання 31 | Розміщення кнопок 32 | Натисніть та утримуйте для переміщення 33 | кольоровий фільтр 34 | вибору кольору 35 | Вимкнути в програмах 36 | інший 37 | Вимкніть кнопку підсвічування 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Dimmer/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Dimmer/res/values-zh-rCN/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 最快 5 | 6 | 正常 7 | 8 | 最慢 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 调光器 5 | 设置 6 | 上下触控调整亮度 7 | 8 | 自动模式 9 | 根据环境光源自动变暗或变亮 10 | 目前的环境光源: 11 | 此设备不支持环境光线感应器 12 | 小工具模式 13 | 点击图示切换变暗或变亮 14 | 您可以点击通知进入应用程序 15 | 变暗的条件 16 | 侦测最低环境光源 17 | 侦测最低值 18 | 环境光源 19 | 变亮的条件 20 | 环境光源差异 21 | 变暗的反应速度 22 | 变亮的反应速度 23 | 定时模式 24 | 定时变暗 25 | 定时变亮 26 | 关闭 27 | 通知 28 | 隐藏状态栏的图示 29 | 调整的级别 30 | 调整的范围 31 | 按键布局 32 | 长按可以变更按键布局 33 | 彩色滤光片 34 | 颜色选择 35 | 排除应用程序 36 | 其他 37 | 关闭实体按钮背光 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values-zh-rTW/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 最快 5 | 6 | 正常 7 | 8 | 最慢 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values-zh-rTW/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 調光器 5 | 設定 6 | 上下觸控調整亮度 7 | 8 | 自動模式 9 | 根據環境光源自動變暗或變亮 10 | 目前的環境光源: 11 | 此裝置不支援環境光源感測器 12 | 小工具模式 13 | 點擊圖示切換變暗或變亮 14 | 您可以點擊通知進入應用程序 15 | 變暗的條件 16 | 偵測最低環境光源 17 | 偵測最低值 18 | 環境光源 19 | 變亮的條件 20 | 環境光源差異 21 | 變暗的反應速度 22 | 變亮的反應速度 23 | 定時模式 24 | 定時變暗 25 | 定時變亮 26 | 關閉 27 | 通知 28 | 隱藏狀態列的圖示 29 | 調整的大小 30 | 調整的範圍 31 | 按鍵設定 32 | 長按可以變更按鍵位置 33 | 彩色濾光 34 | 顏色選擇 35 | 排除應用程序 36 | 其他 37 | 關閉實體按鍵背光 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Highest 5 | Hight 6 | Normal 7 | Low 8 | Lowest 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 5 16 | 17 | 18 | -------------------------------------------------------------------------------- /Dimmer/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /Dimmer/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dimmer 5 | Settings 6 | Tap up and down to adjust brightness. 7 | 8 | Auto Mode 9 | Automatically dim and brighten with environment. 10 | Current ambient light: 11 | This device doesn\'t have an ambient light sensor. 12 | Widget Mode 13 | Tap the icon to switch between dim and bright. 14 | Click notification to enter app. 15 | Enter dim 16 | Detect lowest ambient light. 17 | Set lowest lux 18 | Ambient light 19 | Return bright 20 | Ambient light difference 21 | Speed of dim response 22 | Speed of bright response 23 | Time Mode 24 | Dim screen at 25 | Go back to bright at 26 | OFF 27 | Notification 28 | Hide status bar icon 29 | Step of adjustment 30 | Range of adjustment 31 | Button arrangement 32 | Long press button to change position. 33 | Color filter 34 | Color picker 35 | Exclude app 36 | Other 37 | Disable button backlight 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dimmer/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Dimmer/res/xml/preference.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 12 | 18 | 25 | 32 | 38 | 45 | 52 | 53 | 56 | 62 | 68 | 69 | 72 | 76 | 82 | 88 | 94 | 95 | 98 | 102 | 106 | 107 | 110 | 114 | 115 | 119 | 120 | -------------------------------------------------------------------------------- /Dimmer/res/xml/widget.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/AlarmUtil.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Calendar; 5 | import java.util.Collections; 6 | import java.util.Comparator; 7 | 8 | import android.app.AlarmManager; 9 | import android.app.PendingIntent; 10 | import android.content.Context; 11 | import android.content.Intent; 12 | import android.text.format.DateFormat; 13 | import android.util.Log; 14 | 15 | public class AlarmUtil { 16 | 17 | private Context mContext; 18 | private Comparator mComparator = new Comparator() 19 | { 20 | @Override 21 | public int compare(Calendar a, Calendar b) { 22 | return a.compareTo(b); 23 | } 24 | }; 25 | public AlarmUtil(Context context) 26 | { 27 | mContext = context; 28 | } 29 | public void update() // get the latest alarm and setup alarm 30 | { 31 | Calendar now = Calendar.getInstance(); 32 | Calendar next = getLatestAlarm(now); 33 | boolean isAlarmOn = !(next.compareTo(now) == 0); 34 | setupAlarm(isAlarmOn, next); 35 | } 36 | public boolean nowToDim() // check current time is to dim or bright. called when alarm fired. 37 | { 38 | boolean toDim = true; 39 | boolean toBright = false; 40 | Calendar dim = null; 41 | Calendar bright = null; 42 | if(getAlarmOnOff(Prefs.PREF_ALARM_DIM)) 43 | dim = getAlarmTime(Prefs.PREF_ALARM_DIM); 44 | if(getAlarmOnOff(Prefs.PREF_ALARM_BRIGHT)) 45 | bright = getAlarmTime(Prefs.PREF_ALARM_BRIGHT); 46 | 47 | if(dim == null && bright == null) 48 | return toBright; 49 | else if(dim != null && bright == null) 50 | return toDim; 51 | else if(dim == null && bright != null) 52 | return toBright; 53 | else 54 | { 55 | Calendar now = Calendar.getInstance(); 56 | int dimCompare = now.compareTo(dim); 57 | int brightCompare = now.compareTo(bright); 58 | int dimbrightCompare = dim.compareTo(bright); 59 | Log.e(Dimmer.TAG, "nowToDim: now: " + now.getTime().toGMTString()); 60 | Log.e(Dimmer.TAG, "nowToDim: dim: " + dim.getTime().toGMTString()); 61 | Log.e(Dimmer.TAG, "nowToDim: bright: " + bright.getTime().toGMTString()); 62 | Log.e(Dimmer.TAG, "nowToDim: dimCompare=" + dimCompare + ", brightCompare=" + brightCompare + ", dimbrightCompare=" + dimbrightCompare); 63 | if(dimCompare >= 0 && brightCompare < 0) 64 | { // dim ... now ... bright 65 | return toDim; 66 | } 67 | else if(dimCompare < 0 && brightCompare >= 0) 68 | { // bright ... now ... dim 69 | return toBright; 70 | } 71 | else 72 | { 73 | if(dimbrightCompare < 0) // [dim ... bright ... now] or [now ... dim ... bright] 74 | return toBright; 75 | else if(dimbrightCompare > 0) // [bright ... dim ... now] or [now ... bright ... dim] 76 | return toDim; 77 | } 78 | } 79 | 80 | return toBright; 81 | } 82 | public boolean bootToDim() // check if [dim ... now ... bright]. called when boot. 83 | { 84 | boolean toDim = true; 85 | boolean toBright = false; 86 | Calendar dim = null; 87 | Calendar bright = null; 88 | if(getAlarmOnOff(Prefs.PREF_ALARM_DIM)) 89 | dim = getAlarmTime(Prefs.PREF_ALARM_DIM); 90 | if(getAlarmOnOff(Prefs.PREF_ALARM_BRIGHT)) 91 | bright = getAlarmTime(Prefs.PREF_ALARM_BRIGHT); 92 | 93 | if(dim == null || bright == null) 94 | return toBright; 95 | 96 | Calendar now = Calendar.getInstance(); 97 | int dimCompare = now.compareTo(dim); 98 | int brightCompare = now.compareTo(bright); 99 | int dimbrightCompare = dim.compareTo(bright); 100 | Log.e(Dimmer.TAG, "bootToDim: now: " + now.getTime().toGMTString()); 101 | Log.e(Dimmer.TAG, "bootToDim: dim: " + dim.getTime().toGMTString()); 102 | Log.e(Dimmer.TAG, "bootToDim: bright: " + bright.getTime().toGMTString()); 103 | Log.e(Dimmer.TAG, "bootToDim: dimCompare=" + dimCompare + ", brightCompare=" + brightCompare + ", dimbrightCompare=" + dimbrightCompare); 104 | if(dimCompare >= 0 && brightCompare < 0) 105 | { // dim ... now ... bright 106 | return toDim; 107 | } 108 | else if(dimCompare < 0 && brightCompare >= 0) 109 | { // bright ... now ... dim 110 | return toBright; 111 | } 112 | else 113 | { 114 | if(dimbrightCompare < 0) // [dim ... bright ... now] or [now ... dim ... bright] 115 | return toBright; 116 | else if(dimbrightCompare > 0) // [bright ... dim ... now] or [now ... bright ... dim] 117 | return toDim; 118 | } 119 | return toBright; 120 | } 121 | private Calendar getLatestAlarm(Calendar now) 122 | { 123 | Calendar dim = null; 124 | Calendar bright = null; 125 | Calendar result = now; 126 | ArrayList list = new ArrayList(); 127 | list.add(now); 128 | Log.e(Dimmer.TAG, "getLatestAlarm now: " + now.getTime().toGMTString()); 129 | if(getAlarmOnOff(Prefs.PREF_ALARM_DIM)) 130 | { 131 | dim = getAlarmTime(Prefs.PREF_ALARM_DIM); 132 | if(dim.compareTo(now) <= 0) 133 | dim.roll(Calendar.DAY_OF_YEAR, true); 134 | list.add(dim); 135 | Log.e(Dimmer.TAG, "getLatestAlarm dim: " + dim.getTime().toGMTString()); 136 | } 137 | if(getAlarmOnOff(Prefs.PREF_ALARM_BRIGHT)) 138 | { 139 | bright = getAlarmTime(Prefs.PREF_ALARM_BRIGHT); 140 | if(bright.compareTo(now) <= 0) 141 | bright.roll(Calendar.DAY_OF_YEAR, true); 142 | list.add(bright); 143 | Log.e(Dimmer.TAG, "getLatestAlarm bright: " + bright.getTime().toGMTString()); 144 | } 145 | if(list.size() == 1) 146 | return result; 147 | 148 | Collections.sort(list, mComparator); 149 | // for(Calendar cal : list) 150 | // Log.e(Dimmer.TAG, "SORT#1: " + cal.getTime().toGMTString()); 151 | 152 | for(int i=0; i 0) 156 | { 157 | result = list.get(i); 158 | break; 159 | } 160 | } 161 | 162 | return result; 163 | } 164 | private void setupAlarm(boolean on, Calendar time) 165 | { 166 | Log.e(Dimmer.TAG, "setupAlarm: " + (on? time.getTime().toGMTString() : "OFF")); 167 | 168 | Intent intent = new Intent(DimmerService.ALARMMODE); 169 | intent.setComponent(DimmerService.COMPONENT); 170 | PendingIntent pi = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); 171 | AlarmManager alarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); 172 | alarmManager.cancel(pi); 173 | if(on) 174 | alarmManager.set(AlarmManager.RTC, time.getTimeInMillis(), pi); 175 | } 176 | public static boolean getAlarmOnOff(String type) 177 | { 178 | if(Prefs.getAlarm(type).startsWith("-")) 179 | return false; 180 | else 181 | return true; 182 | } 183 | public static void getAlarmTime(String type, int[] hourminute) 184 | { 185 | String time = Prefs.getAlarm(type); 186 | hourminute[0] = Integer.valueOf(time.substring(1, 3)); 187 | hourminute[1] = Integer.valueOf(time.substring(4, 6)); 188 | } 189 | public static String getAlarmTime(String type, Context context) 190 | { 191 | String time = Prefs.getAlarm(type); 192 | Calendar rightNow = Calendar.getInstance(); 193 | rightNow.set(Calendar.HOUR_OF_DAY, Integer.valueOf(time.substring(1, 3))); 194 | rightNow.set(Calendar.MINUTE, Integer.valueOf(time.substring(4, 6))); 195 | rightNow.set(Calendar.SECOND, 0); 196 | java.text.DateFormat dateformat = DateFormat.getTimeFormat(context); 197 | return dateformat.format(rightNow.getTime()); 198 | } 199 | public static Calendar getAlarmTime(String type) 200 | { 201 | String time = Prefs.getAlarm(type); 202 | Calendar cal = Calendar.getInstance(); 203 | cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(time.substring(1, 3))); 204 | cal.set(Calendar.MINUTE, Integer.valueOf(time.substring(4, 6))); 205 | cal.set(Calendar.SECOND, 0); 206 | cal.setTimeInMillis(cal.getTimeInMillis()/1000*1000); // set ms to 0 207 | return cal; 208 | } 209 | public static void setAlarm(String type, boolean isOn, int hour, int minute) 210 | { 211 | Prefs.setAlarm(type, String.format("%s%02d:%02d", isOn?"+":"-", hour, minute)); 212 | } 213 | 214 | } 215 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/AlphaPatternDrawable.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Bitmap.Config; 5 | import android.graphics.Canvas; 6 | import android.graphics.ColorFilter; 7 | import android.graphics.Paint; 8 | import android.graphics.Rect; 9 | import android.graphics.drawable.Drawable; 10 | 11 | public class AlphaPatternDrawable extends Drawable { 12 | 13 | private int mRectangleSize = 10; 14 | 15 | private Paint mPaint = new Paint(); 16 | private Paint mPaintWhite = new Paint(); 17 | private Paint mPaintGray = new Paint(); 18 | 19 | private int numRectanglesHorizontal; 20 | private int numRectanglesVertical; 21 | 22 | /** 23 | * Bitmap in which the pattern will be cahched. 24 | */ 25 | private Bitmap mBitmap; 26 | 27 | public AlphaPatternDrawable(int rectangleSize) { 28 | mRectangleSize = rectangleSize; 29 | mPaintWhite.setColor(0xffffffff); 30 | mPaintGray.setColor(0xffcbcbcb); 31 | } 32 | 33 | @Override 34 | public void draw(Canvas canvas) { 35 | canvas.drawBitmap(mBitmap, null, getBounds(), mPaint); 36 | } 37 | 38 | @Override 39 | public int getOpacity() { 40 | return 0; 41 | } 42 | 43 | @Override 44 | public void setAlpha(int alpha) { 45 | throw new UnsupportedOperationException("Alpha is not supported by this drawwable."); 46 | } 47 | 48 | @Override 49 | public void setColorFilter(ColorFilter cf) { 50 | throw new UnsupportedOperationException("ColorFilter is not supported by this drawwable."); 51 | } 52 | 53 | @Override 54 | protected void onBoundsChange(Rect bounds) { 55 | super.onBoundsChange(bounds); 56 | 57 | int height = bounds.height(); 58 | int width = bounds.width(); 59 | 60 | numRectanglesHorizontal = (int) Math.ceil((width / mRectangleSize)); 61 | numRectanglesVertical = (int) Math.ceil(height / mRectangleSize); 62 | 63 | generatePatternBitmap(); 64 | 65 | } 66 | 67 | /** 68 | * This will generate a bitmap with the pattern 69 | * as big as the rectangle we were allow to draw on. 70 | * We do this to chache the bitmap so we don't need to 71 | * recreate it each time draw() is called since it 72 | * takes a few milliseconds. 73 | */ 74 | private void generatePatternBitmap(){ 75 | 76 | if(getBounds().width() <= 0 || getBounds().height() <= 0){ 77 | return; 78 | } 79 | 80 | mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888); 81 | Canvas canvas = new Canvas(mBitmap); 82 | 83 | Rect r = new Rect(); 84 | boolean verticalStartWhite = true; 85 | for (int i = 0; i <= numRectanglesVertical; i++) { 86 | 87 | boolean isWhite = verticalStartWhite; 88 | for (int j = 0; j <= numRectanglesHorizontal; j++) { 89 | 90 | r.top = i * mRectangleSize; 91 | r.left = j * mRectangleSize; 92 | r.bottom = r.top + mRectangleSize; 93 | r.right = r.left + mRectangleSize; 94 | 95 | canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray); 96 | 97 | isWhite = !isWhite; 98 | } 99 | 100 | verticalStartWhite = !verticalStartWhite; 101 | 102 | } 103 | 104 | } 105 | 106 | } -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/BootReceiver.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | public class BootReceiver extends BroadcastReceiver{ 8 | @Override 9 | public void onReceive(Context context, Intent intent) { 10 | Intent startServiceIntent = new Intent(); 11 | startServiceIntent.setAction(DimmerService.BOOT); 12 | startServiceIntent.setComponent(DimmerService.COMPONENT); 13 | context.startService(startServiceIntent); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/BrightnessUtil.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.provider.Settings; 5 | 6 | public class BrightnessUtil { 7 | 8 | private static Context mContext; 9 | private static int mAutoState; 10 | private static int mLevelState; 11 | public static void init(Context context) 12 | { 13 | mContext = context; 14 | } 15 | public static int getBrightness() 16 | { 17 | return Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255); 18 | } 19 | public static void setBrightness(int i) 20 | { 21 | // Log.e(Dimmer.TAG, "setBrightness: " + i); 22 | Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); 23 | Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, i); 24 | } 25 | public static void setAutoBrightness(boolean b) 26 | { 27 | if(b == true) 28 | Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 29 | else 30 | Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); 31 | } 32 | private static int getAutoBrightness() 33 | { 34 | return Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 35 | } 36 | public static void collectState() 37 | { 38 | mAutoState = getAutoBrightness(); 39 | mLevelState = getBrightness(); 40 | } 41 | public static void restoreState() 42 | { 43 | setBrightness(mLevelState); 44 | setAutoBrightness(mAutoState == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/ColorPickerPreference.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Bitmap.Config; 7 | import android.graphics.Color; 8 | import android.preference.DialogPreference; 9 | import android.util.AttributeSet; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.widget.ImageView; 13 | import android.widget.LinearLayout; 14 | 15 | public class ColorPickerPreference extends DialogPreference implements ColorPickerView.OnColorChangedListener{ 16 | 17 | View mView; 18 | public static int DEFAULT_COLOR = 0x50FFA757; // 2700 K 19 | private int mValue = DEFAULT_COLOR; 20 | private int targetColor = DEFAULT_COLOR; 21 | private float mDensity = 0; 22 | private ColorPickerView mColorPickerView = null; 23 | 24 | public ColorPickerPreference(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | Log.e(Dimmer.TAG, "ColorPickerPreference"); 27 | init(context, attrs); 28 | } 29 | 30 | private void init(Context context, AttributeSet attrs) { 31 | mDensity = getContext().getResources().getDisplayMetrics().density; 32 | setDialogLayoutResource(R.layout.color_picker); 33 | } 34 | 35 | @Override 36 | protected void onBindView(View view) { 37 | super.onBindView(view); 38 | // Log.e(Dimmer.TAG, "onBindView"); 39 | mView = view; 40 | mValue = Prefs.getColor(); 41 | targetColor = mValue; 42 | setPreviewColor(); 43 | } 44 | @Override 45 | public void onBindDialogView (View view) { 46 | // Log.e(Dimmer.TAG, "onBindDialogView"); 47 | mColorPickerView = (ColorPickerView)view.findViewById(R.id.color_picker_view); 48 | mColorPickerView.setOnColorChangedListener(this); 49 | mColorPickerView.setColor(mValue); 50 | } 51 | private void setPreviewColor() { 52 | if (mView == null) return; 53 | ImageView iView = new ImageView(getContext()); 54 | LinearLayout widgetFrameView = ((LinearLayout)mView.findViewById(android.R.id.widget_frame)); 55 | if (widgetFrameView == null) return; 56 | widgetFrameView.setVisibility(View.VISIBLE); 57 | widgetFrameView.setPadding( 58 | widgetFrameView.getPaddingLeft(), 59 | widgetFrameView.getPaddingTop(), 60 | (int)(mDensity * 8), 61 | widgetFrameView.getPaddingBottom() 62 | ); 63 | // remove already create preview image 64 | int count = widgetFrameView.getChildCount(); 65 | if (count > 0) { 66 | widgetFrameView.removeViews(0, count); 67 | } 68 | widgetFrameView.addView(iView); 69 | widgetFrameView.setMinimumWidth(0); 70 | iView.setBackgroundDrawable(new AlphaPatternDrawable((int)(5 * mDensity))); 71 | iView.setImageBitmap(getPreviewBitmap()); 72 | } 73 | 74 | private Bitmap getPreviewBitmap() { 75 | int d = (int) (mDensity * 31); //30dip 76 | int color = mValue; 77 | Bitmap bm = Bitmap.createBitmap(d, d, Config.ARGB_8888); 78 | int w = bm.getWidth(); 79 | int h = bm.getHeight(); 80 | int c = color; 81 | for (int i = 0; i < w; i++) { 82 | for (int j = i; j < h; j++) { 83 | c = (i <= 1 || j <= 1 || i >= w-2 || j >= h-2) ? Color.GRAY : color; 84 | bm.setPixel(i, j, c); 85 | if (i != j) { 86 | bm.setPixel(j, i, c); 87 | } 88 | } 89 | } 90 | 91 | return bm; 92 | } 93 | @Override 94 | public void onColorChanged(int color) { 95 | // Log.e(Dimmer.TAG, "onColorChanged: " + color); 96 | targetColor = color; 97 | changeColor(color); 98 | } 99 | public void changeColor(int color) 100 | { 101 | // Log.e(Dimmer.TAG, "color=" + Integer.toHexString(color)); 102 | Intent startServiceIntent = new Intent(); 103 | startServiceIntent.setComponent(DimmerService.COMPONENT); 104 | startServiceIntent.setAction(DimmerService.COLORCHANGE); 105 | startServiceIntent.putExtra(DimmerService.COLORCHANGE, color); 106 | getContext().startService(startServiceIntent); 107 | } 108 | @Override 109 | public void onDialogClosed(boolean positiveResult) 110 | { 111 | if(positiveResult) 112 | { 113 | mValue = targetColor; 114 | setPreviewColor(); 115 | Prefs.setColor(mValue); 116 | } 117 | else 118 | { 119 | changeColor(mValue); 120 | } 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/Dimmer.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.os.Bundle; 4 | import android.app.Activity; 5 | import android.content.BroadcastReceiver; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.IntentFilter; 9 | import android.util.Log; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.MotionEvent; 13 | import android.view.View; 14 | import android.widget.RelativeLayout; 15 | import android.widget.TextView; 16 | 17 | public class Dimmer extends Activity { 18 | 19 | public static String TAG = "Dimmer"; 20 | public static final String REFRESH_INDEX = "refreshIndex"; 21 | public static boolean showMainApp = false; 22 | public static boolean collectState = false; 23 | private TextView mIndex; 24 | 25 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver(){ 26 | @Override 27 | public void onReceive(Context arg0, Intent arg1) { 28 | onResume(); 29 | } 30 | }; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | 36 | Prefs.init(this); 37 | boolean showActivity = !Prefs.getWidgetMode() 38 | || DimmerService.ACTIONNOTIFICATION.equalsIgnoreCase(getIntent().getAction()); 39 | 40 | if(showActivity) showMainApp = true; 41 | 42 | if(showActivity) 43 | setTheme(R.style.AppTheme); 44 | else 45 | setTheme(android.R.style.Theme_Dialog); 46 | 47 | setContentView(R.layout.activity_dimmer); 48 | 49 | mIndex = (TextView)findViewById(R.id.index); 50 | 51 | startDimmerService(!showActivity); 52 | 53 | RelativeLayout background = (RelativeLayout)findViewById(R.id.relativelayout); 54 | background.setOnTouchListener(new View.OnTouchListener() { 55 | private int downx = 0; 56 | private int downy = 0; 57 | private int pivot = 0; 58 | @Override 59 | public boolean onTouch(View v, MotionEvent event) { 60 | switch(event.getAction()) 61 | { 62 | case MotionEvent.ACTION_DOWN: 63 | Log.e(TAG, "MotionEvent.ACTION_DOWN: (" + event.getX() + ", " + event.getY() + "), (" + event.getRawX() + ", " + event.getRawY() + ")"); 64 | downx = (int)event.getRawX(); 65 | downy = (int)event.getRawY(); 66 | pivot = 0; 67 | if(!collectState) // Only at the first time adjustment, try collect state to keep original setting 68 | { 69 | BrightnessUtil.collectState(); 70 | collectState = true; 71 | } 72 | break; 73 | case MotionEvent.ACTION_MOVE: 74 | // Log.e(TAG, "MotionEvent.ACTION_MOVE: (" + event.getX() + ", " + event.getY() + "), (" + event.getRawX() + ", " + event.getRawY() + ")"); 75 | int diffx = (int)event.getRawX() - downx; 76 | int diffy = (int)event.getRawY() - downy; 77 | 78 | int temp = diffy; 79 | temp = temp > 1000 ? 1000 : temp; 80 | temp = temp < -1000 ? -1000 : temp; 81 | temp = -temp; 82 | pivot = DimmerService.lastLevel + temp; 83 | pivot = pivot < 10 ? 10 : pivot; 84 | pivot = pivot > 1000 ? 1000 : pivot; 85 | showIndex(pivot); 86 | changeLevel(DimmerService.ADJUSTLEVEL, pivot); 87 | // Log.e(TAG, "pivot=" + pivot + ", temp=" + temp); 88 | break; 89 | case MotionEvent.ACTION_UP: 90 | Log.e(TAG, "MotionEvent.ACTION_UP: (" + event.getX() + ", " + event.getY() + "), (" + event.getRawX() + ", " + event.getRawY() + ")"); 91 | showIndex(pivot); 92 | changeLevel(DimmerService.FINISHLEVEL, pivot); 93 | break; 94 | } 95 | return true; 96 | } 97 | }); 98 | registerReceiver(mBroadcastReceiver, new IntentFilter(REFRESH_INDEX)); 99 | 100 | if(!showActivity) 101 | finish(); 102 | } 103 | protected void onDestroy () 104 | { 105 | super.onDestroy(); 106 | unregisterReceiver(mBroadcastReceiver); 107 | showMainApp = false; 108 | } 109 | public void onResume () 110 | { 111 | super.onResume(); 112 | showIndex(DimmerService.lastLevel); 113 | } 114 | public void onPause () 115 | { 116 | super.onPause(); 117 | finish(); 118 | } 119 | @Override 120 | public boolean onCreateOptionsMenu(Menu menu) { 121 | // Inflate the menu; this adds items to the action bar if it is present. 122 | getMenuInflater().inflate(R.menu.dimmer_menu, menu); 123 | return true; 124 | } 125 | @Override 126 | public boolean onOptionsItemSelected(MenuItem item) { 127 | switch (item.getItemId()) { 128 | case R.id.action_settings: 129 | startSettings(); 130 | return true; 131 | } 132 | return false; 133 | } 134 | public void showIndex(int i) 135 | { 136 | mIndex.setText(String.valueOf(i/10)); 137 | } 138 | public void changeLevel(String action, int i) 139 | { 140 | Intent startServiceIntent = new Intent(); 141 | startServiceIntent.setComponent(DimmerService.COMPONENT); 142 | startServiceIntent.setAction(action); 143 | startServiceIntent.putExtra(action, i); 144 | startService(startServiceIntent); 145 | } 146 | public void startSettings() 147 | { 148 | startActivity(new Intent(this, SettingsActivity.class)); 149 | } 150 | public void startDimmerService(boolean switchDim) 151 | { 152 | Intent startServiceIntent = new Intent(); 153 | startServiceIntent.setComponent(DimmerService.COMPONENT); 154 | if(switchDim) 155 | startServiceIntent.setAction(DimmerService.SWITCHDIM); 156 | startService(startServiceIntent); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/DimmerService.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import java.util.List; 4 | 5 | import android.app.ActivityManager; 6 | import android.app.ActivityManager.RunningTaskInfo; 7 | import android.app.AlarmManager; 8 | import android.app.Notification; 9 | import android.app.PendingIntent; 10 | import android.app.Service; 11 | import android.content.BroadcastReceiver; 12 | import android.content.ComponentName; 13 | import android.content.ContentResolver; 14 | import android.content.Context; 15 | import android.content.Intent; 16 | import android.content.IntentFilter; 17 | import android.content.pm.PackageManager.NameNotFoundException; 18 | import android.database.ContentObserver; 19 | import android.os.Handler; 20 | import android.os.IBinder; 21 | import android.os.Message; 22 | import android.os.Process; 23 | import android.os.SystemClock; 24 | import android.provider.Settings; 25 | import android.support.v4.app.NotificationCompat; 26 | import android.util.Log; 27 | import android.view.View; 28 | import android.widget.RemoteViews; 29 | import android.widget.Toast; 30 | 31 | public class DimmerService extends Service implements LightSensor.EventCallback{ 32 | 33 | public static boolean DebugMode = false; 34 | public static String PACKAGENAME = "giraffine.dimmer"; 35 | public static String ACTIONNOTIFICATION = "giraffine.dimmer.Dimmer.action.notification"; 36 | public static ComponentName COMPONENT = new ComponentName(PACKAGENAME, PACKAGENAME+".DimmerService"); 37 | public static String ADJUSTLEVEL = "adjustLevel"; 38 | public static String FINISHLEVEL = "finishLevel"; 39 | public static String RESETLEVEL = "resetLevel"; 40 | public static String PAUSEFUNCTION = "pauseFunction"; 41 | public static String LAYOUTCHANGE = "layoutChange"; 42 | public static String STATUSBARCHANGE = "statusbarChange"; 43 | public static String STEPLEVELUP = "stepLevelUp"; 44 | public static String STEPLEVELDOWN = "stepLevelDown"; 45 | public static String SWITCHAUTOMODE = "switchAutoMode"; 46 | public static String SWITCHDIM = "switchDim"; 47 | public static String SENSITIVECHANGE = "sensitiveChange"; 48 | public static String ALARMMODE = "alarmMode"; 49 | public static String ALARMCHANGE = "alarmChange"; 50 | public static String COLORCHANGE = "colorChange"; 51 | public static String BOOT = "boot"; 52 | public static final int MSG_RESET_LEVEL = 0; 53 | public static final int MSG_RESET_LEVEL_RESTORE = 1; 54 | public static final int MSG_RESET_LEVEL_RESTORE_KEEP_NOTIFY = 2; 55 | public static final int MSG_RESET_ACTING = 3; 56 | public static final int MSG_ENTER_DIMM = 4; 57 | public static final int DEFAULTLEVEL = 1000; 58 | public static int lastLevel = DEFAULTLEVEL; 59 | 60 | private boolean mActing = false; 61 | private Notification mNotification; 62 | private RemoteViews mNotiRemoteView = null; 63 | private Mask mMask = null; 64 | private boolean mInDimMode = false; 65 | private LightSensor mLightSensor = null; 66 | private AlarmUtil mAlarmUtil = null; 67 | private boolean mKeepSticky = false; 68 | private boolean mIsPaused = false; 69 | private boolean mLayoutChanged = true; 70 | private boolean mUpdateNotifyInfo = true; 71 | 72 | @Override 73 | public IBinder onBind(Intent arg0) { 74 | return null; 75 | } 76 | public void postNotification(int levelHint, boolean dim) 77 | { 78 | if(mNotiRemoteView == null) 79 | initNotification(); 80 | 81 | if(mLayoutChanged) 82 | { 83 | relayoutNotification(); 84 | mLayoutChanged = false; 85 | } 86 | 87 | if(mUpdateNotifyInfo) 88 | { 89 | mNotiRemoteView.setTextViewText(R.id.noti_text, levelHint + ""); 90 | for(int i=0; i<4; i++) 91 | { 92 | if(dim) 93 | mNotiRemoteView.setImageViewResource(SettingNotifyLayout.getNotifyButtonID(i, 2), R.drawable.ic_pause); 94 | else 95 | mNotiRemoteView.setImageViewResource(SettingNotifyLayout.getNotifyButtonID(i, 2), R.drawable.ic_start); 96 | } 97 | } 98 | 99 | if(mNotification == null) 100 | { 101 | Intent intent = new Intent(ACTIONNOTIFICATION); 102 | intent.setClassName(PACKAGENAME, PACKAGENAME+".SettingsActivity"); 103 | PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); 104 | 105 | mNotification = new NotificationCompat.Builder(this) 106 | .setContent(mNotiRemoteView) 107 | .setSmallIcon(R.drawable.ic_launcher) 108 | .setContentIntent(pi) 109 | .setPriority(Prefs.getNotifyPriority() ? -2 : 0) // adjust priority to control show icon in status bar 110 | .build(); 111 | stopForeground(true); // remove notification first to ensure update 112 | } 113 | if(DebugMode) 114 | mNotification.tickerText = mLightSensor.getCurrentLux() + ""; 115 | 116 | mNotification.number = 1; 117 | startForeground(999, mNotification); 118 | } 119 | public void removeNotification() 120 | { 121 | if(mNotification != null) 122 | mNotification.number = 0; 123 | stopForeground(true); 124 | } 125 | public void initNotification() 126 | { 127 | Intent stepUpIntent = new Intent(this, DimmerService.class); 128 | stepUpIntent.setAction(STEPLEVELUP); 129 | PendingIntent piStepUp = PendingIntent.getService(this, 0, stepUpIntent, 0); 130 | 131 | Intent stepDownIntent = new Intent(this, DimmerService.class); 132 | stepDownIntent.setAction(STEPLEVELDOWN); 133 | PendingIntent piStepDown = PendingIntent.getService(this, 0, stepDownIntent, 0); 134 | 135 | Intent pauseIntent = new Intent(this, DimmerService.class); 136 | pauseIntent.setAction(PAUSEFUNCTION); 137 | PendingIntent piPause = PendingIntent.getService(this, 0, pauseIntent, 0); 138 | 139 | Intent resetIntent = new Intent(this, DimmerService.class); 140 | resetIntent.setAction(RESETLEVEL); 141 | PendingIntent piReset = PendingIntent.getService(this, 0, resetIntent, 0); 142 | 143 | // Customization for notification button: 144 | // Design A: Dynamically add Remoteivew. 145 | // Design B: Dynamically set visible/invisible Button. 146 | // Problem A: Fast click button will trigger notification content intent. 147 | // Problem B: Need list all permutations and combinations (4x4). 148 | mNotiRemoteView = new RemoteViews(PACKAGENAME, R.layout.notification); 149 | 150 | for(int i=0; i<4; i++) 151 | { 152 | for(int j=0; j<4; j++) 153 | { 154 | PendingIntent pi = null; 155 | switch(j) 156 | { 157 | case 0: pi = piStepUp; break; 158 | case 1: pi = piStepDown; break; 159 | case 2: pi = piPause; break; 160 | case 3: pi = piReset; break; 161 | } 162 | mNotiRemoteView.setOnClickPendingIntent(SettingNotifyLayout.getNotifyButtonID(i, j), pi); 163 | } 164 | } 165 | } 166 | public void relayoutNotification() 167 | { 168 | for(int i=0; i<4; i++) 169 | for(int j=0; j<4; j++) 170 | mNotiRemoteView.setViewVisibility(SettingNotifyLayout.getNotifyButtonID(i, j), View.GONE); 171 | String order = Prefs.getNotifyLayout(); 172 | Log.e(Dimmer.TAG, "relayoutNotification: order=" + order); 173 | if(order.startsWith("-")) 174 | mNotiRemoteView.setViewVisibility(R.id.noti_icon, View.GONE); 175 | else 176 | mNotiRemoteView.setViewVisibility(R.id.noti_icon, View.VISIBLE); 177 | order = order.substring(1); 178 | for(int i=0; i<4; i++) 179 | { 180 | if(order.charAt(i+4) == '1') 181 | mNotiRemoteView.setViewVisibility(SettingNotifyLayout.getNotifyButtonID(i, Integer.valueOf(String.valueOf(order.charAt(i)))), View.VISIBLE); 182 | } 183 | } 184 | @Override 185 | public void onCreate() { 186 | BrightnessUtil.init(this); 187 | Prefs.init(this); 188 | // lastLevel = BrightnessUtil.getPreferLevel(); 189 | int currentBrightness = BrightnessUtil.getBrightness(); 190 | lastLevel = (int)(((float)currentBrightness)/255*500 + 500); 191 | sendBroadcast(new Intent(Dimmer.REFRESH_INDEX)); 192 | 193 | mMask = new Mask(this); 194 | mLightSensor = new LightSensor(this, this); 195 | mAlarmUtil = new AlarmUtil(this); 196 | 197 | ContentResolver resolver = getContentResolver(); 198 | resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS), true, new ContentObserver(null){ 199 | public void onChange(boolean selfChange) 200 | { 201 | if(mActing == false) 202 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL); 203 | return; 204 | } 205 | }); 206 | resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE), true, new ContentObserver(null){ 207 | public void onChange(boolean selfChange) 208 | { 209 | if(mActing == false) 210 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL); 211 | return; 212 | } 213 | }); 214 | registerReceiver(new BroadcastReceiver(){ 215 | @Override 216 | public void onReceive(Context arg0, Intent arg1) { 217 | if(Prefs.isAutoMode()) 218 | mLightSensor.monitor(true); 219 | } 220 | }, new IntentFilter(Intent.ACTION_SCREEN_ON)); 221 | registerReceiver(new BroadcastReceiver(){ 222 | @Override 223 | public void onReceive(Context arg0, Intent arg1) { 224 | mLightSensor.monitor(false); 225 | } 226 | }, new IntentFilter(Intent.ACTION_SCREEN_OFF)); 227 | 228 | if(Prefs.isAutoMode()) 229 | { 230 | mLightSensor.monitor(true); 231 | mKeepSticky = true; 232 | } 233 | 234 | mAlarmUtil.update(); 235 | } 236 | public String getForegroundActivity() 237 | { 238 | ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); 239 | List Info = am.getRunningTasks(1); 240 | ComponentName topActivity = Info.get(0).topActivity; 241 | return topActivity.getPackageName(); 242 | } 243 | @Override 244 | public void onDestroy() { 245 | Log.e(Dimmer.TAG, "onDestroy()"); 246 | // need restart ASAP: 60 secs 247 | if(mKeepSticky) 248 | { 249 | Intent intent = new Intent(Intent.ACTION_MAIN); 250 | intent.addCategory(Intent.CATEGORY_LAUNCHER); 251 | intent.setComponent(COMPONENT); 252 | PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 253 | AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 254 | alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 60000, pi); 255 | } 256 | } 257 | @Override 258 | public void onLightChanged(int lux) { 259 | if(DebugMode) postNotification(lastLevel/10, false); 260 | if(SettingsActivity.showSettings) 261 | sendBroadcast(new Intent(SettingsFragment.REFRESH_LUX).putExtra("lux", lux)); 262 | } 263 | @Override 264 | public void onEnterDarkLight() { 265 | // Log.e(Dimmer.TAG, "onDarkLight() mIsAutoMode=" + Prefs.isAutoMode() + ", mInDimmMode=" + mInDimmMode); 266 | if(!Prefs.isAutoMode() || getDimMode() 267 | || (Prefs.getApList() != null && Prefs.getApList().size() != 0 && Prefs.getApList().contains(getForegroundActivity())) 268 | || mIsPaused) return; 269 | mLightSensor.setFreezeLux(); 270 | mHandler.sendEmptyMessage(MSG_ENTER_DIMM); 271 | } 272 | 273 | @Override 274 | public void onLeaveDarkLight() { 275 | // Log.e(Dimmer.TAG, "onOverDarkLight() mIsAutoMode=" + Prefs.isAutoMode() + ", mInDimmMode=" + mInDimmMode); 276 | if(!Prefs.isAutoMode() || !getDimMode()) return; 277 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL_RESTORE); 278 | } 279 | @Override 280 | public int onStartCommand(Intent intent, int flags, int startId) { 281 | if(intent != null && intent.getAction() != null) 282 | { 283 | if(intent.getAction().equals(ADJUSTLEVEL)) 284 | { 285 | mHandler.removeMessages(MSG_RESET_ACTING); 286 | mActing = true; 287 | adjustLevel(intent.getIntExtra(ADJUSTLEVEL, DEFAULTLEVEL), false, false); 288 | } 289 | else if(intent.getAction().equals(FINISHLEVEL)) 290 | { 291 | int i = intent.getIntExtra(FINISHLEVEL, DEFAULTLEVEL); 292 | adjustLevel(intent.getIntExtra(FINISHLEVEL, DEFAULTLEVEL), true, true); 293 | lastLevel = i; 294 | 295 | if(lastLevel < 500) 296 | { 297 | mLightSensor.setFreezeLux(); 298 | Prefs.setFavorMaskValue(lastLevel); 299 | } 300 | 301 | // Log.e(Dimmer.TAG, "" + LuxUtil.dumpLuxLevel()); 302 | } 303 | else if(intent.getAction().equals(PAUSEFUNCTION)) 304 | { 305 | if(getDimMode()) 306 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL_RESTORE_KEEP_NOTIFY); 307 | else 308 | { 309 | mLightSensor.setFreezeLux(); 310 | mHandler.sendEmptyMessage(MSG_ENTER_DIMM); 311 | } 312 | } 313 | else if(intent.getAction().equals(RESETLEVEL)) 314 | { 315 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL_RESTORE); 316 | } 317 | else if(intent.getAction().equals(LAYOUTCHANGE)) 318 | { 319 | mLayoutChanged = true; 320 | if(mNotification != null && mNotification.number == 1) 321 | { 322 | mUpdateNotifyInfo = false; 323 | postNotification(0, false); 324 | mUpdateNotifyInfo = true; 325 | } 326 | } 327 | else if(intent.getAction().equals(STATUSBARCHANGE)) 328 | { 329 | if(mNotification != null) 330 | { 331 | boolean needPost = mNotification.number == 1; 332 | mNotification = null; 333 | if(needPost) 334 | { 335 | mUpdateNotifyInfo = false; 336 | postNotification(0, false); 337 | mUpdateNotifyInfo = true; 338 | } 339 | } 340 | } 341 | else if(intent.getAction().equals(STEPLEVELUP)) 342 | { 343 | stepLevel(false); 344 | } 345 | else if(intent.getAction().equals(STEPLEVELDOWN)) 346 | { 347 | stepLevel(true); 348 | } 349 | else if(intent.getAction().equals(SWITCHAUTOMODE)) 350 | { 351 | boolean on = intent.getBooleanExtra(SWITCHAUTOMODE, false); 352 | mLightSensor.monitor(on); 353 | mKeepSticky = on; 354 | } 355 | else if(intent.getAction().equals(SWITCHDIM)) 356 | { 357 | if(getDimMode()) 358 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL_RESTORE); 359 | else 360 | { 361 | mLightSensor.setFreezeLux(); 362 | mHandler.sendEmptyMessage(MSG_ENTER_DIMM); 363 | } 364 | } 365 | else if(intent.getAction().equals(SENSITIVECHANGE)) 366 | { 367 | mLightSensor.updateSensitive(); 368 | } 369 | else if(intent.getAction().equals(ALARMCHANGE)) 370 | { 371 | mAlarmUtil.update(); 372 | } 373 | else if(intent.getAction().equals(ALARMMODE)) 374 | { 375 | if(!mAlarmUtil.nowToDim()) 376 | mHandler.sendEmptyMessage(MSG_RESET_LEVEL_RESTORE); 377 | else 378 | { 379 | mLightSensor.setFreezeLux(); 380 | mHandler.sendEmptyMessage(MSG_ENTER_DIMM); 381 | } 382 | mAlarmUtil.update(); 383 | } 384 | else if(intent.getAction().equals(COLORCHANGE)) 385 | { 386 | if(getDimMode()) 387 | { 388 | if(intent.hasExtra(COLORCHANGE+"ON")) 389 | mMask.adjustColor(intent.getBooleanExtra(COLORCHANGE+"ON", false), Prefs.getColor()); 390 | else if(Prefs.getColorMode()) 391 | mMask.adjustColor(true, intent.getIntExtra(COLORCHANGE, 0xFF000000)); 392 | } 393 | } 394 | else if(intent.getAction().equals(BOOT)) 395 | { 396 | if(mAlarmUtil.bootToDim()) 397 | { 398 | mLightSensor.setFreezeLux(); 399 | mHandler.sendEmptyMessage(MSG_ENTER_DIMM); 400 | } 401 | else if(!mKeepSticky) 402 | trySuicide(); 403 | } 404 | } 405 | // Only tf700t: If killed, next launch will NOT result in Activity/Service OnCreate. 406 | if(android.os.Build.DEVICE.equalsIgnoreCase("tf700t")) return START_STICKY; 407 | // Log.e(Dimmer.TAG, "onStartCommand(): " + lastLevel); 408 | // return Prefs.isAutoMode() ? START_STICKY : (lastLevel>500 ? START_NOT_STICKY : START_STICKY); 409 | return mKeepSticky ? START_STICKY : (lastLevel>500 ? START_NOT_STICKY : START_STICKY); 410 | // return START_STICKY; //sticky for continuous alive 411 | } 412 | private void adjustLevel(int i, boolean setBrightness, boolean postNotify) 413 | { 414 | if(postNotify) 415 | mIsPaused = false; 416 | 417 | if(i > 500) 418 | { 419 | if(i > 10*Prefs.getNotify(Prefs.PREF_NOTIFY_UPPER)) 420 | removeNotification(); 421 | else 422 | { 423 | if(postNotify) 424 | postNotification(i/10, false); 425 | } 426 | setDimMode(false); 427 | } 428 | else 429 | { 430 | if(postNotify) 431 | postNotification(i/10, true); 432 | setDimMode(true); 433 | } 434 | if(setBrightness) 435 | triggerActingSession(); 436 | mMask.adjustLevel(i, setBrightness); 437 | mMask.adjustColor((Prefs.getColorMode() && getDimMode()), Prefs.getColor()); 438 | } 439 | public void resetLevel(boolean restoreBrighnessState, boolean removeNotification) 440 | { 441 | Log.e(Dimmer.TAG, "resetLevel() lastLevel: " + lastLevel); 442 | 443 | mIsPaused = !removeNotification; 444 | if(restoreBrighnessState) 445 | { 446 | triggerActingSession(); 447 | BrightnessUtil.restoreState(); 448 | } 449 | 450 | int currentBrightness = BrightnessUtil.getBrightness(); 451 | lastLevel = (int)(((float)currentBrightness)/255*500 + 500); 452 | mMask.removeMask(); 453 | mMask.adjustColor(false, 0); 454 | 455 | boolean needSuicide = true; 456 | if(removeNotification) 457 | removeNotification(); 458 | else 459 | { 460 | postNotification(lastLevel/10, false); 461 | needSuicide = false; 462 | } 463 | setDimMode(false); 464 | sendBroadcast(new Intent(Dimmer.REFRESH_INDEX)); 465 | 466 | Dimmer.collectState = false; 467 | if(!mKeepSticky && needSuicide) 468 | trySuicide(); 469 | } 470 | public void stepLevel(boolean darker) 471 | { 472 | Log.e(Dimmer.TAG, "stepLevel() lastLevel: " + lastLevel + ", darker=" + darker); 473 | 474 | int step = 10*Prefs.getNotify(Prefs.PREF_NOTIFY_STEP); 475 | int lowerbound = 10*Prefs.getNotify(Prefs.PREF_NOTIFY_LOWER); 476 | int upperbound = 10*Prefs.getNotify(Prefs.PREF_NOTIFY_UPPER); 477 | if(darker) 478 | lastLevel -= step; 479 | else 480 | lastLevel += step; 481 | if(lastLevel > upperbound) lastLevel = upperbound; 482 | if(lastLevel < lowerbound) lastLevel = lowerbound; 483 | 484 | if(lastLevel >= 500) // if > 50, need call Mask.maskBrightness to set screenBrightness 485 | adjustLevel(lastLevel, false, false); 486 | adjustLevel(lastLevel, true, true); 487 | 488 | if(lastLevel < 500) 489 | { 490 | mLightSensor.setFreezeLux(); 491 | Prefs.setFavorMaskValue(lastLevel); 492 | } 493 | sendBroadcast(new Intent(Dimmer.REFRESH_INDEX)); 494 | } 495 | Handler mHandler = new Handler(){ 496 | public void handleMessage(Message msg) { 497 | switch (msg.what) { 498 | case MSG_RESET_LEVEL: 499 | resetLevel(false, true); 500 | break; 501 | case MSG_RESET_LEVEL_RESTORE: 502 | resetLevel(true, true); 503 | break; 504 | case MSG_RESET_LEVEL_RESTORE_KEEP_NOTIFY: 505 | resetLevel(true, false); 506 | break; 507 | case MSG_RESET_ACTING: 508 | mActing = false; 509 | break; 510 | case MSG_ENTER_DIMM: 511 | mMask.removeMask(); 512 | Dimmer.collectState = true; 513 | BrightnessUtil.collectState(); 514 | int favorvalue = Prefs.getFavorMaskValue(); 515 | adjustLevel(favorvalue, true, true); 516 | lastLevel = favorvalue; 517 | sendBroadcast(new Intent(Dimmer.REFRESH_INDEX)); 518 | showHint(); 519 | break; 520 | } 521 | } 522 | }; 523 | public void triggerActingSession() 524 | { 525 | mActing = true; 526 | mHandler.removeMessages(MSG_RESET_ACTING); 527 | mHandler.sendEmptyMessageDelayed(MSG_RESET_ACTING, 1000); 528 | } 529 | private void setDimMode(boolean dim) 530 | { 531 | mInDimMode = dim; 532 | mLightSensor.setDimState(dim); 533 | DimmerWidget.updateDim(this, dim); 534 | } 535 | private boolean getDimMode() 536 | { 537 | return mInDimMode; 538 | } 539 | private void trySuicide() 540 | { 541 | // Only tf700t: If killed, next launch will NOT result in Activity/Service OnCreate. 542 | if(android.os.Build.DEVICE.equalsIgnoreCase("tf700t")) return; 543 | if(SettingsActivity.showSettings || Dimmer.showMainApp) 544 | return; 545 | stopSelf(); 546 | Process.killProcess(Process.myPid()); 547 | } 548 | private void showHint() 549 | { 550 | try { 551 | String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; 552 | if(version == null || !version.equalsIgnoreCase(Prefs.getAbout())) 553 | Toast.makeText(this, R.string.pref_widget_hint, Toast.LENGTH_LONG).show(); 554 | } catch (NameNotFoundException e) { 555 | e.printStackTrace(); 556 | } 557 | } 558 | } 559 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/DimmerWidget.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.app.PendingIntent; 4 | import android.appwidget.AppWidgetManager; 5 | import android.appwidget.AppWidgetProvider; 6 | import android.content.ComponentName; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.widget.RemoteViews; 10 | 11 | public class DimmerWidget extends AppWidgetProvider{ 12 | 13 | private static RemoteViews mWidgetView; 14 | private static RemoteViews getWidgetView(Context context) 15 | { 16 | if(mWidgetView == null) 17 | { 18 | Intent intent = new Intent(context, DimmerService.class); 19 | intent.setAction(DimmerService.SWITCHDIM); 20 | PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); 21 | mWidgetView = new RemoteViews(context.getPackageName(), R.layout.widget_layout); 22 | mWidgetView.setOnClickPendingIntent(R.id.widgetImage, pendingIntent); 23 | } 24 | return mWidgetView; 25 | } 26 | public static void updateDim(Context context, boolean dim) 27 | { 28 | AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 29 | int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, DimmerWidget.class)); 30 | if(appWidgetIds.length < 1) 31 | return; 32 | if(dim) 33 | getWidgetView(context).setImageViewResource(R.id.widgetImage, R.drawable.ic_widget); 34 | else 35 | getWidgetView(context).setImageViewResource(R.id.widgetImage, R.drawable.ic_launcher); 36 | appWidgetManager.updateAppWidget(appWidgetIds, getWidgetView(context)); 37 | } 38 | public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 39 | if(appWidgetIds.length < 1) 40 | return; 41 | appWidgetManager.updateAppWidget(appWidgetIds, getWidgetView(context)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/LightSensor.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | import android.hardware.Sensor; 6 | import android.hardware.SensorEvent; 7 | import android.hardware.SensorEventListener; 8 | import android.hardware.SensorManager; 9 | import android.os.Handler; 10 | import android.os.Message; 11 | import android.util.Log; 12 | 13 | public class LightSensor implements ProximitySensor.EventCallback{ 14 | 15 | private static final int MSG_BASE = 100; 16 | private static final int MSG_ENTER_DARKLIGHT = 1 + MSG_BASE; 17 | private static final int MSG_LEAVE_DARKLIGHT = 2 + MSG_BASE; 18 | private static final int MSG_ENSURE_COVERED = 3 + MSG_BASE; 19 | private static final int MSG_SENSOR_INPUT = 4 + MSG_BASE; 20 | 21 | private Context mContext; 22 | private SensorManager mSensorManager; 23 | private Sensor mSensorLight; 24 | private SensorEventListener mSensorEventListener; 25 | private int mCurrentLux; 26 | private int mFreezeLux = 9999999; 27 | private EventCallback mEventCallback = null; 28 | private ProximitySensor mProximitySensor = null; 29 | private boolean mDimState = false; 30 | private int mDelayEnterDark = 5000; 31 | private int mDelayLeaveDark = 2000; 32 | private int mDelayCheckCover = 3000; 33 | 34 | interface EventCallback 35 | { 36 | public void onLightChanged(int lux); 37 | public void onEnterDarkLight(); 38 | public void onLeaveDarkLight(); 39 | } 40 | 41 | public LightSensor(Context context, EventCallback eventcallback) 42 | { 43 | LuxUtil.init(context); 44 | mProximitySensor = new ProximitySensor(context, this); 45 | mContext = context; 46 | mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); 47 | if(mSensorManager != null) 48 | mSensorLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); 49 | mEventCallback = eventcallback; 50 | updateSensitive(); 51 | } 52 | public static boolean hasLightSensor(Context context) 53 | { 54 | SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); 55 | Sensor sensorLight = null; 56 | if(sensorManager != null) 57 | sensorLight = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); 58 | if(sensorManager == null || sensorLight == null) 59 | return false; 60 | else 61 | return true; 62 | } 63 | public boolean monitor(boolean isOn) 64 | { 65 | if(!isOn) 66 | { 67 | mProximitySensor.monitor(false); 68 | mHandler.removeMessages(MSG_ENTER_DARKLIGHT); 69 | mHandler.removeMessages(MSG_LEAVE_DARKLIGHT); 70 | mHandler.removeMessages(MSG_ENSURE_COVERED); 71 | mHandler.removeMessages(MSG_SENSOR_INPUT); 72 | } 73 | 74 | if(mSensorManager == null || mSensorLight == null) 75 | return false; 76 | 77 | if(mSensorEventListener == null) 78 | mSensorEventListener = new SensorEventListener(){ 79 | @Override 80 | public void onAccuracyChanged(Sensor arg0, int arg1) { 81 | Log.e(Dimmer.TAG, "onAccuracyChanged: " + arg0.toString() + ", arg1=" + arg1); 82 | } 83 | @Override 84 | public void onSensorChanged(SensorEvent arg0) { 85 | Log.e(Dimmer.TAG, "onSensorChanged: " + arg0.values[0]); 86 | mHandler.removeMessages(MSG_SENSOR_INPUT); 87 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SENSOR_INPUT, (int)arg0.values[0], 0)); 88 | } 89 | }; 90 | if(isOn) 91 | mSensorManager.registerListener(mSensorEventListener, mSensorLight, SensorManager.SENSOR_DELAY_FASTEST); 92 | else 93 | { 94 | mSensorManager.unregisterListener(mSensorEventListener); 95 | Point bound = new Point(); 96 | LuxUtil.getBoundaryLevel(bound); 97 | mCurrentLux = bound.x; 98 | } 99 | return true; 100 | } 101 | public int getCurrentLux() 102 | { 103 | return mCurrentLux; 104 | } 105 | public void setFreezeLux() 106 | { 107 | mFreezeLux = mCurrentLux; 108 | } 109 | public void setDimState(boolean dim) 110 | { 111 | mDimState = dim; 112 | } 113 | public void updateSensitive() 114 | { 115 | switch(Prefs.getSpeed(Prefs.PREF_SPEED_DIM)) 116 | { 117 | case 1: mDelayEnterDark = 1000; break; 118 | case 2: mDelayEnterDark = 3000; break; 119 | case 3: mDelayEnterDark = 5000; break; 120 | case 4: mDelayEnterDark = 7000; break; 121 | case 5: mDelayEnterDark = 10000;break; 122 | } 123 | switch(Prefs.getSpeed(Prefs.PREF_SPEED_BRIGHT)) 124 | { 125 | case 1: mDelayLeaveDark = 500; break; 126 | case 2: mDelayLeaveDark = 1000; break; 127 | case 3: mDelayLeaveDark = 2000; break; 128 | case 4: mDelayLeaveDark = 5000; break; 129 | case 5: mDelayLeaveDark = 10000;break; 130 | } 131 | mDelayCheckCover = (int)(mDelayEnterDark * 0.6); 132 | } 133 | private boolean meetDarkThreshold(int lux) 134 | { 135 | if(Prefs.getThresholdDimLowest()) 136 | return LuxUtil.isLowestLevel(lux); 137 | else 138 | return lux <= Prefs.getThresholdDim(); 139 | } 140 | private void sensorInput(int lux) 141 | { 142 | mCurrentLux = lux; 143 | mEventCallback.onLightChanged(lux); 144 | LuxUtil.setLuxLevel(mCurrentLux); 145 | 146 | // Log.e(Dimmer.TAG, "sensorInput: " + LuxUtil.dumpLuxLevel()); 147 | 148 | if(!mDimState) 149 | { 150 | // need include proximity sensor to avoid cover situation 151 | if(meetDarkThreshold(mCurrentLux)) 152 | { 153 | mProximitySensor.monitor(true); 154 | mHandler.sendEmptyMessageDelayed(MSG_ENTER_DARKLIGHT, mDelayEnterDark); 155 | } 156 | else 157 | { 158 | mProximitySensor.monitor(false); 159 | mHandler.removeMessages(MSG_ENTER_DARKLIGHT); 160 | } 161 | } 162 | else 163 | { 164 | mProximitySensor.monitor(false); 165 | if(mCurrentLux > mFreezeLux + Prefs.getThresholdBright()) 166 | { 167 | if(!mHandler.hasMessages(MSG_LEAVE_DARKLIGHT)) 168 | mHandler.sendEmptyMessageDelayed(MSG_LEAVE_DARKLIGHT, mDelayLeaveDark); 169 | } 170 | else 171 | mHandler.removeMessages(MSG_LEAVE_DARKLIGHT); 172 | } 173 | } 174 | private Handler mHandler = new Handler(){ 175 | public void handleMessage(Message msg) { 176 | switch (msg.what) { 177 | case MSG_SENSOR_INPUT: 178 | sensorInput(msg.arg1); 179 | break; 180 | case MSG_ENTER_DARKLIGHT: 181 | mProximitySensor.monitor(false); 182 | mEventCallback.onEnterDarkLight(); 183 | break; 184 | case MSG_LEAVE_DARKLIGHT: 185 | mProximitySensor.monitor(false); 186 | mEventCallback.onLeaveDarkLight(); 187 | break; 188 | case MSG_ENSURE_COVERED: 189 | mProximitySensor.monitor(false); 190 | mHandler.removeMessages(MSG_ENTER_DARKLIGHT); 191 | break; 192 | } 193 | } 194 | }; 195 | @Override 196 | public void onNear() { 197 | mHandler.sendEmptyMessageDelayed(MSG_ENSURE_COVERED, mDelayCheckCover); 198 | } 199 | @Override 200 | public void onFar() { 201 | mHandler.removeMessages(MSG_ENSURE_COVERED); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/LuxUtil.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.Set; 7 | import java.util.TreeSet; 8 | 9 | import android.content.Context; 10 | import android.graphics.Point; 11 | 12 | public class LuxUtil { 13 | 14 | private static Context mContext; 15 | private static String PREFER = "LuxLevel"; 16 | private static String LEVELSET = "levelSet"; 17 | private static Set mLevelSet = null; 18 | private static Comparator mComparator = new Comparator() 19 | { 20 | @Override 21 | public int compare(String a, String b) { 22 | return Integer.valueOf(a) - Integer.valueOf(b); 23 | } 24 | }; 25 | 26 | public static void init(Context context) 27 | { 28 | mContext = context; 29 | } 30 | public static String dumpLuxLevel() 31 | { 32 | String result = ""; 33 | if(mLevelSet == null) 34 | mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); 35 | if(mLevelSet != null) 36 | { 37 | ArrayList array = Collections.list(Collections.enumeration(mLevelSet)); 38 | Collections.sort(array, mComparator); 39 | result = array.toString(); 40 | } 41 | return result; 42 | } 43 | public static boolean isLowestLevel(int level) 44 | { 45 | if(mLevelSet == null) 46 | mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); 47 | if(mLevelSet != null) 48 | { 49 | if(mLevelSet.size() < 5) // data is too few to judge lowest 50 | return false; 51 | ArrayList array = Collections.list(Collections.enumeration(mLevelSet)); 52 | Collections.sort(array, mComparator); 53 | // TODO: may need check statistics to ensure the level is true lowest and not false alarm. 54 | if(level <= Integer.valueOf(array.get(0))) 55 | return true; 56 | } 57 | return false; 58 | } 59 | public static boolean getBoundaryLevel(Point bound) 60 | { 61 | if(mLevelSet == null) 62 | mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); 63 | if(mLevelSet != null) 64 | { 65 | ArrayList array = Collections.list(Collections.enumeration(mLevelSet)); 66 | Collections.sort(array, mComparator); 67 | bound.x = Integer.valueOf(array.get(0)); 68 | bound.y = Integer.valueOf(array.get(array.size()-1)); 69 | return true; 70 | } 71 | return false; 72 | } 73 | public static void setLuxLevel(int level) 74 | { 75 | levelExist(level); 76 | 77 | // maybe no need the total lux statistics 78 | /* // this will cause app ANR on Galaxy S3 79 | int count = mContext.getSharedPreferences(PREFER, mContext.MODE_WORLD_WRITEABLE).getInt(String.valueOf(level), 0); 80 | count++; 81 | mContext.getSharedPreferences(PREFER, mContext.MODE_WORLD_WRITEABLE).edit().putInt(String.valueOf(level), count).commit(); 82 | */ 83 | } 84 | private static boolean levelExist(int level) 85 | { 86 | if(mLevelSet == null) 87 | mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); 88 | if(mLevelSet == null) 89 | { 90 | mLevelSet = new TreeSet(); 91 | mLevelSet.add(String.valueOf(level)); 92 | mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit().putStringSet(LEVELSET, mLevelSet).commit(); 93 | return false; 94 | } 95 | if(mLevelSet.contains(String.valueOf(level))) 96 | return true; 97 | else 98 | { 99 | mLevelSet.add(String.valueOf(level)); 100 | mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit().putStringSet(LEVELSET, mLevelSet).commit(); 101 | } 102 | return false; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/Mask.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.graphics.PixelFormat; 5 | import android.graphics.Point; 6 | import android.util.Log; 7 | import android.view.Gravity; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.WindowManager; 11 | 12 | public class Mask { 13 | 14 | private Context mContext; 15 | private WindowManager mWindowManager; 16 | private WindowManager.LayoutParams mWindowParams; 17 | private WindowManager.LayoutParams mColorWindowParams; 18 | private int maskLength = 0; 19 | private View mMaskView; 20 | private View mColorView; 21 | private boolean mHasColor = false; 22 | 23 | public Mask(Context context){ 24 | mContext = context; 25 | initMask(); 26 | } 27 | private void initMask() 28 | { 29 | mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 30 | mWindowParams = new WindowManager.LayoutParams(); 31 | 32 | mWindowParams.type = 33 | android.os.Build.VERSION.SDK_INT >= 19? 34 | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY // _OVERLAY can cover KK navigationbar, icon still bright 35 | : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; // _ERROR can cover whole navigationbar in JB 36 | mWindowParams.flags |= 37 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 38 | | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 39 | | WindowManager.LayoutParams.FLAG_FULLSCREEN // remove to keep status bar out of mask 40 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 41 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED 42 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 43 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; 44 | mWindowParams.gravity = Gravity.LEFT | Gravity.TOP; 45 | Point p = new Point(); 46 | mWindowManager.getDefaultDisplay().getSize(p); 47 | mWindowParams.x = 0; 48 | mWindowParams.y = 0; 49 | maskLength = ( p.x > p.y ? p.x : p.y) +300; 50 | mWindowParams.width = 1; 51 | mWindowParams.height = 1; 52 | mWindowParams.format = PixelFormat.TRANSLUCENT; 53 | mWindowParams.alpha = (float)0; // default is transparent 54 | 55 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 56 | mMaskView = inflater.inflate(R.layout.mask_window, null); 57 | // mMaskView.setAlpha((float)1); // == android:alpha 58 | 59 | mWindowManager.addView(mMaskView, mWindowParams); 60 | initColor(); 61 | } 62 | private void initColor() 63 | { 64 | mColorWindowParams = new WindowManager.LayoutParams(); 65 | mColorWindowParams.copyFrom(mWindowParams); 66 | mColorWindowParams.alpha = 1; 67 | mColorWindowParams.width = maskLength; 68 | mColorWindowParams.height = maskLength; 69 | } 70 | public void adjustColor(boolean enable, int color) 71 | { 72 | if(!enable) 73 | { 74 | if(mHasColor && mColorView != null) 75 | mWindowManager.removeView(mColorView); 76 | mHasColor = false; 77 | return; 78 | } 79 | if(mColorView == null) 80 | { 81 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 82 | mColorView = inflater.inflate(R.layout.mask_window, null); 83 | } 84 | mColorView.setBackgroundColor(color); 85 | if(!mHasColor) 86 | { 87 | mColorWindowParams.buttonBrightness = Prefs.getDisableButtonBacklight() ? 0 : -1; 88 | mWindowManager.addView(mColorView, mColorWindowParams); 89 | } 90 | mHasColor = true; 91 | } 92 | public void adjustLevel(int i, boolean setBrightness) 93 | { 94 | Log.e(Dimmer.TAG, "adjustLevel: " + i); 95 | if(i > 500) 96 | { 97 | float index = ((float)(i - 500))/500; 98 | if(setBrightness) 99 | BrightnessUtil.setBrightness((int)(index*255)); 100 | else 101 | maskBrightness(index); 102 | } 103 | else 104 | { 105 | if(setBrightness) 106 | BrightnessUtil.setBrightness(0); 107 | i = 500 - i; 108 | adjustMask(((float)i/500)); 109 | } 110 | } 111 | public void removeMask() 112 | { 113 | Log.e(Dimmer.TAG, "removeMask"); 114 | mWindowParams.width = 1; // reduce memory usage 115 | mWindowParams.height = 1; // reduce memory usage 116 | mWindowParams.screenBrightness = -1; // use the system preferred screen brightness 117 | mWindowParams.buttonBrightness = -1; // use the system preferred button backlight 118 | mWindowParams.alpha = 0; 119 | mWindowManager.updateViewLayout(mMaskView, mWindowParams); 120 | } 121 | private void maskBrightness(float value) 122 | { 123 | Log.e(Dimmer.TAG, "maskBrightness: " + value); 124 | if(value <= 0.01) return; // for padfone: value ~0.0 would fully dark screen 125 | mWindowParams.width = 1; // reduce memory usage 126 | mWindowParams.height = 1; // reduce memory usage 127 | mWindowParams.screenBrightness = value; 128 | mWindowParams.buttonBrightness = -1; // use the system preferred button backlight 129 | mWindowParams.alpha = 0; 130 | mWindowManager.updateViewLayout(mMaskView, mWindowParams); 131 | } 132 | private void adjustMask(float alpha) 133 | { 134 | Log.e(Dimmer.TAG, "adjustMask: " + alpha); 135 | if(alpha > 0.98) alpha = (float)0.9; 136 | else if(alpha < 0) alpha = (float)0; 137 | // mMaskView.setAlpha(alpha); // control parent window is much safe 138 | mWindowParams.width = maskLength; 139 | mWindowParams.height = maskLength; 140 | mWindowParams.buttonBrightness = Prefs.getDisableButtonBacklight() ? 0 : -1; 141 | mWindowParams.alpha = alpha; 142 | // this will cause fully dark screen 143 | // if(mWindowParams.screenBrightness != 0) mWindowParams.screenBrightness = (float)0; 144 | mWindowManager.updateViewLayout(mMaskView, mWindowParams); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/Prefs.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import java.util.Set; 4 | 5 | import android.content.Context; 6 | import android.content.SharedPreferences; 7 | import android.preference.PreferenceManager; 8 | import android.view.WindowManager; 9 | 10 | public class Prefs { 11 | 12 | private static Context mContext = null; 13 | private static String PREFER = "settings"; 14 | private static String AUTOMODE = "automode"; 15 | private static String FAVORMASKVALUE = "favormaskvalue"; 16 | private static String PROXIMITYMAX = "proximitymax"; 17 | private static String PROXIMITYMIN = "proximitymin"; 18 | private static String PREF_COMPATIBLE = "pref_compatible"; 19 | 20 | public static String PREF_AUTOMODE = "pref_automode"; 21 | public static String PREF_THRESHOLD_DIM = "pref_threshold_dim"; 22 | public static String PREF_THRESHOLD_DIM_LOWEST = "pref_threshold_dim_lowest"; 23 | public static String PREF_THRESHOLD_BRIGHT = "pref_threshold_bright"; 24 | public static String PREF_SPEED_DIM = "pref_speed_dim"; 25 | public static String PREF_SPEED_BRIGHT = "pref_speed_bright"; 26 | public static String PREF_WIDGETMODE = "pref_widgetmode"; 27 | public static String PREF_ABOUT = "pref_about"; 28 | public static String PREF_ALARM_DIM = "pref_alarm_dim"; 29 | public static String PREF_ALARM_BRIGHT = "pref_alarm_bright"; 30 | public static String PREF_NOTIFY_STEP = "pref_notify_step"; 31 | public static String PREF_NOTIFY_RANGE = "pref_notify_range"; 32 | public static String PREF_NOTIFY_LOWER = "pref_notify_lower"; 33 | public static String PREF_NOTIFY_UPPER = "pref_notify_upper"; 34 | public static String PREF_NOTIFY_LAYOUT = "pref_notify_layout"; 35 | public static String PREF_NOTIFY_PRIORITY = "pref_notify_priority"; 36 | public static String PREF_AP_LIST = "pref_ap_list"; 37 | public static String PREF_BUTTON_BACKLIGHT = "pref_button_backlight"; 38 | public static String PREF_COLORMODE = "pref_colormode"; 39 | public static String PREF_COLOR_VALUE = "pref_color_value"; 40 | 41 | private static SharedPreferences mPrefer = null; 42 | 43 | public static void init(Context context) 44 | { 45 | if(mContext != null) 46 | return; 47 | mContext = context; 48 | mPrefer = PreferenceManager.getDefaultSharedPreferences(mContext); 49 | 50 | // backward compatible 51 | if(!mPrefer.getBoolean(PREF_COMPATIBLE, false)) 52 | { 53 | SharedPreferences prefer = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE); 54 | if(prefer.contains(AUTOMODE)) 55 | mPrefer.edit().putBoolean(AUTOMODE, prefer.getBoolean(AUTOMODE, false)).commit(); 56 | if(prefer.contains(FAVORMASKVALUE)) 57 | mPrefer.edit().putInt(FAVORMASKVALUE, prefer.getInt(FAVORMASKVALUE, 250)).commit(); 58 | if(prefer.contains(PROXIMITYMAX)) 59 | mPrefer.edit().putFloat(PROXIMITYMAX, prefer.getFloat(PROXIMITYMAX, ProximitySensor.DEFAULT_DISTANCE)).commit(); 60 | if(prefer.contains(PROXIMITYMIN)) 61 | mPrefer.edit().putFloat(PROXIMITYMIN, prefer.getFloat(PROXIMITYMIN, ProximitySensor.DEFAULT_DISTANCE)).commit(); 62 | mPrefer.edit().putBoolean(PREF_COMPATIBLE, true).commit(); 63 | } 64 | if(((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth() < 540) 65 | SettingNotifyLayout.DEFAULT_LAYOUT = "-01231111"; 66 | } 67 | 68 | public static boolean isAutoMode() 69 | { 70 | return mPrefer.getBoolean(PREF_AUTOMODE, false); 71 | } 72 | public static int getSpeed(String key) 73 | { 74 | return Integer.valueOf(mPrefer.getString(key, "3")); 75 | } 76 | public static boolean getWidgetMode() 77 | { 78 | return mPrefer.getBoolean(PREF_WIDGETMODE, true); 79 | } 80 | public static int getFavorMaskValue() 81 | { 82 | return mPrefer.getInt(FAVORMASKVALUE, 250); 83 | } 84 | public static void setFavorMaskValue(int value) 85 | { 86 | mPrefer.edit().putInt(FAVORMASKVALUE, value).commit(); 87 | } 88 | public static float getProximity(boolean isMax) 89 | { 90 | return mPrefer.getFloat(isMax ? PROXIMITYMAX : PROXIMITYMIN, ProximitySensor.DEFAULT_DISTANCE); 91 | } 92 | public static void setProximity(boolean isMax, float value) 93 | { 94 | mPrefer.edit().putFloat(isMax ? PROXIMITYMAX : PROXIMITYMIN, value).commit(); 95 | } 96 | public static int getThresholdDim() 97 | { 98 | return mPrefer.getInt(PREF_THRESHOLD_DIM, 0); 99 | } 100 | public static void setThresholdDim(int value) 101 | { 102 | mPrefer.edit().putInt(PREF_THRESHOLD_DIM, value).commit(); 103 | } 104 | public static boolean getThresholdDimLowest() 105 | { 106 | return mPrefer.getBoolean(PREF_THRESHOLD_DIM_LOWEST, true); 107 | } 108 | public static void setThresholdDimLowest(boolean yes) 109 | { 110 | mPrefer.edit().putBoolean(PREF_THRESHOLD_DIM_LOWEST, yes).commit(); 111 | } 112 | public static int getThresholdBright() 113 | { 114 | return mPrefer.getInt(PREF_THRESHOLD_BRIGHT, 40); 115 | } 116 | public static void setThresholdBright(int value) 117 | { 118 | mPrefer.edit().putInt(PREF_THRESHOLD_BRIGHT, value).commit(); 119 | } 120 | public static String getAlarm(String type) 121 | { 122 | return mPrefer.getString(type, "-00:00"); 123 | } 124 | public static void setAlarm(String type, String value) 125 | { 126 | mPrefer.edit().putString(type, value).commit(); 127 | } 128 | public static boolean getNotifyPriority() 129 | { 130 | return mPrefer.getBoolean(PREF_NOTIFY_PRIORITY, false); 131 | } 132 | public static int getNotify(String type) 133 | { 134 | int value = 0; 135 | if(type.equalsIgnoreCase(PREF_NOTIFY_STEP)) 136 | value = 5; 137 | else if(type.equalsIgnoreCase(PREF_NOTIFY_LOWER)) 138 | value = 10; 139 | else if(type.equalsIgnoreCase(PREF_NOTIFY_UPPER)) 140 | value = 50; 141 | return mPrefer.getInt(type, value); 142 | } 143 | public static void setNotify(String type, int value) 144 | { 145 | mPrefer.edit().putInt(type, value).commit(); 146 | } 147 | public static String getNotifyLayout() 148 | { 149 | String r = mPrefer.getString(PREF_NOTIFY_LAYOUT, SettingNotifyLayout.DEFAULT_LAYOUT); 150 | return (r.length() != SettingNotifyLayout.DEFAULT_LAYOUT.length() ? SettingNotifyLayout.DEFAULT_LAYOUT : r); 151 | } 152 | public static void setNotifyLayout(String layout) 153 | { 154 | if(layout.length() != SettingNotifyLayout.DEFAULT_LAYOUT.length()) layout = SettingNotifyLayout.DEFAULT_LAYOUT; 155 | mPrefer.edit().putString(PREF_NOTIFY_LAYOUT, layout).commit(); 156 | } 157 | public static Set getApList() 158 | { 159 | return mPrefer.getStringSet(PREF_AP_LIST, null); 160 | } 161 | public static void setApList(Set list) 162 | { 163 | mPrefer.edit().putStringSet(PREF_AP_LIST, list).commit(); 164 | } 165 | public static boolean getColorMode() 166 | { 167 | return mPrefer.getBoolean(PREF_COLORMODE, false); 168 | } 169 | public static int getColor() 170 | { 171 | return mPrefer.getInt(PREF_COLOR_VALUE, ColorPickerPreference.DEFAULT_COLOR); 172 | } 173 | public static void setColor(int color) 174 | { 175 | mPrefer.edit().putInt(PREF_COLOR_VALUE, color).commit(); 176 | } 177 | public static boolean getDisableButtonBacklight() 178 | { 179 | return mPrefer.getBoolean(PREF_BUTTON_BACKLIGHT, true); 180 | } 181 | public static String getAbout() 182 | { 183 | return mPrefer.getString(PREF_ABOUT, ""); 184 | } 185 | public static void setAbout(String value) 186 | { 187 | mPrefer.edit().putString(PREF_ABOUT, value).commit(); 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/ProximitySensor.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.hardware.Sensor; 5 | import android.hardware.SensorEvent; 6 | import android.hardware.SensorEventListener; 7 | import android.hardware.SensorManager; 8 | import android.util.Log; 9 | 10 | public class ProximitySensor { 11 | 12 | public static float DEFAULT_DISTANCE = 5; 13 | 14 | private Context mContext; 15 | private SensorManager mSensorManager; 16 | private Sensor mSensorProximity; 17 | private SensorEventListener mSensorEventListener; 18 | private EventCallback mEventCallback = null; 19 | private float mMax = Prefs.getProximity(true); 20 | private float mMin = Prefs.getProximity(false); 21 | private float mCurrent = DEFAULT_DISTANCE; 22 | 23 | interface EventCallback 24 | { 25 | public void onNear(); 26 | public void onFar(); 27 | } 28 | 29 | public ProximitySensor(Context context, EventCallback callback) 30 | { 31 | mContext = context; 32 | mEventCallback = callback; 33 | mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); 34 | if(mSensorManager != null) 35 | mSensorProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); 36 | } 37 | public boolean hasProximitySensor() 38 | { 39 | if(mSensorManager == null || mSensorProximity == null) 40 | return false; 41 | else 42 | return true; 43 | } 44 | public boolean monitor(boolean isOn) 45 | { 46 | Log.e(Dimmer.TAG, "ProximitySensor.monitor isOn=" + isOn); 47 | if(mSensorManager == null || mSensorProximity == null) 48 | return false; 49 | 50 | mCurrent = DEFAULT_DISTANCE; 51 | 52 | if(mSensorEventListener == null) 53 | mSensorEventListener = new SensorEventListener(){ 54 | @Override 55 | public void onAccuracyChanged(Sensor arg0, int arg1) { 56 | Log.e(Dimmer.TAG, "Proximity:: onAccuracyChanged: " + arg0.toString() + ", arg1=" + arg1); 57 | } 58 | @Override 59 | public void onSensorChanged(SensorEvent arg0) { 60 | Log.e(Dimmer.TAG, "Proximity:: onSensorChanged: " + arg0.values[0]); 61 | mCurrent = arg0.values[0]; 62 | if(mMax < mCurrent) 63 | { 64 | mMax = mCurrent; 65 | Prefs.setProximity(true, mMax); 66 | } 67 | if(mMin > mCurrent) 68 | { 69 | mMin = mCurrent; 70 | Prefs.setProximity(false, mMin); 71 | } 72 | 73 | if(mCurrent == mMin) 74 | mEventCallback.onNear(); 75 | else 76 | mEventCallback.onFar(); 77 | } 78 | }; 79 | if(isOn) 80 | mSensorManager.registerListener(mSensorEventListener, mSensorProximity, SensorManager.SENSOR_DELAY_FASTEST); 81 | else 82 | mSensorManager.unregisterListener(mSensorEventListener); 83 | return true; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingAbout.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.preference.DialogPreference; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | 9 | public class SettingAbout extends DialogPreference{ 10 | 11 | public SettingAbout(Context context, AttributeSet attrs) { 12 | super(context, attrs); 13 | setDialogLayoutResource(R.layout.setting_about); 14 | } 15 | @Override 16 | public void onBindDialogView (View view) 17 | { 18 | setDialogTitle("Dimmer Open Source Project"); 19 | String string = 20 | "Welcome to contribute Dimmer." 21 | + "\n" 22 | + "\nSource Code on GitHub:" 23 | + "\nhttps://github.com/giraffine" 24 | + "\n" 25 | + "\nDimmer Develop Group:" 26 | + "\nhttp://goo.gl/03dsL1"; 27 | 28 | TextView about = (TextView)view.findViewById(R.id.aboutText); 29 | about.setText(string); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingAlarm.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.preference.DialogPreference; 6 | import android.text.format.DateFormat; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.widget.TimePicker; 10 | 11 | public class SettingAlarm extends DialogPreference{ 12 | 13 | private TimePicker mTimePicker = null; 14 | public SettingAlarm(Context context, AttributeSet attrs) { 15 | super(context, attrs); 16 | setDialogLayoutResource(R.layout.setting_alarm); 17 | setNegativeButtonText(getContext().getResources().getString(R.string.pref_alarm_off)); 18 | } 19 | @Override 20 | public void onBindDialogView (View view) 21 | { 22 | mTimePicker = (TimePicker)view.findViewById(R.id.timePicker1); 23 | int[] hourminute = new int[2]; 24 | AlarmUtil.getAlarmTime(getKey(), hourminute); 25 | mTimePicker.setCurrentHour(hourminute[0]); 26 | mTimePicker.setCurrentMinute(hourminute[1]); 27 | mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getContext())); 28 | } 29 | @Override 30 | public void onDialogClosed(boolean positiveResult) 31 | { 32 | AlarmUtil.setAlarm(getKey(), positiveResult, mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute()); 33 | updateAlarmSettings(); 34 | changeAlarm(); 35 | } 36 | public void updateAlarmSettings() 37 | { 38 | if(AlarmUtil.getAlarmOnOff(getKey())) 39 | setSummary(AlarmUtil.getAlarmTime(getKey(), getContext())); 40 | else 41 | setSummary(getContext().getResources().getString(R.string.pref_alarm_off)); 42 | } 43 | public void changeAlarm() 44 | { 45 | Intent startServiceIntent = new Intent(); 46 | startServiceIntent.setComponent(DimmerService.COMPONENT); 47 | startServiceIntent.setAction(DimmerService.ALARMCHANGE); 48 | getContext().startService(startServiceIntent); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingApList.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import android.content.Context; 11 | import android.content.pm.ApplicationInfo; 12 | import android.content.pm.PackageInfo; 13 | import android.content.pm.PackageManager; 14 | import android.graphics.Color; 15 | import android.os.Handler; 16 | import android.os.Message; 17 | import android.preference.DialogPreference; 18 | import android.util.AttributeSet; 19 | import android.util.Log; 20 | import android.view.LayoutInflater; 21 | import android.view.View; 22 | import android.view.ViewGroup; 23 | import android.widget.AdapterView; 24 | import android.widget.BaseAdapter; 25 | import android.widget.ImageView; 26 | import android.widget.ListView; 27 | import android.widget.TextView; 28 | 29 | public class SettingApList extends DialogPreference{ 30 | 31 | private Context mContext = null; 32 | private ApAdapter mApAdapter = null; 33 | private List mListAll = null; 34 | private class ApItem { 35 | ApplicationInfo appInfo; 36 | Boolean checked; 37 | String label; 38 | public ApItem(Context context, ApplicationInfo info, boolean b) 39 | { 40 | appInfo = info; 41 | checked = Boolean.valueOf(b); 42 | label = (String) appInfo.loadLabel(context.getPackageManager()); 43 | } 44 | } 45 | private List mListApItem = null; 46 | 47 | public SettingApList(Context context, AttributeSet attrs) { 48 | super(context, attrs); 49 | setDialogLayoutResource(R.layout.setting_ap_list); 50 | mContext = context; 51 | } 52 | @Override 53 | public void onBindDialogView (View view) 54 | { 55 | if(mListApItem == null) 56 | mListApItem = new ArrayList(); 57 | else 58 | mListApItem.clear(); 59 | if(mApAdapter == null) 60 | mApAdapter = new ApAdapter(mContext); 61 | 62 | ListView listview = (ListView)view.findViewById(R.id.apListView); 63 | listview.setAdapter(mApAdapter); 64 | listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 65 | @Override 66 | public void onItemClick(AdapterView parent, View view, int position, long id) { 67 | ApItem item = mListApItem.get(position); 68 | if(item.checked) 69 | { 70 | item.checked = false; 71 | view.setBackgroundColor(Color.TRANSPARENT); 72 | } 73 | else 74 | { 75 | item.checked = true; 76 | view.setBackgroundColor(Color.LTGRAY); 77 | } 78 | } 79 | }); 80 | new Thread(new Runnable() 81 | { 82 | @Override 83 | public void run() { 84 | if(mListAll == null) 85 | mListAll = mContext.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES); 86 | 87 | for(PackageInfo ap : mListAll) 88 | { 89 | if(ap.activities != null && ap.applicationInfo.enabled) 90 | { 91 | Set settinglist = Prefs.getApList(); 92 | if(settinglist!=null && settinglist.contains(ap.packageName)) 93 | mListApItem.add(new ApItem(mContext, ap.applicationInfo, true)); 94 | else 95 | mListApItem.add(new ApItem(mContext, ap.applicationInfo, false)); 96 | } 97 | } 98 | Collections.sort(mListApItem, mComparator); 99 | mHandler.sendEmptyMessage(MSG_REFRESH_LIST); 100 | } 101 | }).start(); 102 | } 103 | @Override 104 | public void onDialogClosed(boolean positiveResult) 105 | { 106 | if(positiveResult) 107 | { 108 | Set result = new HashSet(); 109 | for(ApItem item : mListApItem) 110 | { 111 | if(item.checked) 112 | result.add(item.appInfo.packageName); 113 | } 114 | Prefs.setApList(result); 115 | setSummary(getSummary(result, mContext.getPackageManager())); 116 | } 117 | } 118 | public static String getSummary(Set list, PackageManager pm) 119 | { 120 | String summary = ""; 121 | if(list == null) 122 | return summary; 123 | 124 | for(String name : list) 125 | { 126 | try{ 127 | summary += pm.getApplicationLabel(pm.getApplicationInfo(name, 0)) + ", "; 128 | } catch (PackageManager.NameNotFoundException e) { 129 | Log.e(Dimmer.TAG, "can't find " + name); 130 | } 131 | } 132 | int end = summary.lastIndexOf(", "); 133 | if(end != -1) 134 | summary = summary.substring(0, end); 135 | return summary; 136 | } 137 | private Comparator mComparator = new Comparator(){ 138 | @Override 139 | public int compare(ApItem a, ApItem b) { 140 | if(a.checked && !b.checked) 141 | return -1; 142 | else if(!a.checked && b.checked) 143 | return 1; 144 | else 145 | return a.label.compareToIgnoreCase(b.label); 146 | } 147 | }; 148 | 149 | public class ApAdapter extends BaseAdapter{ 150 | private Context mContext = null; 151 | private LayoutInflater mInflater; 152 | 153 | private class ViewHolder { 154 | TextView name; 155 | ImageView icon; 156 | } 157 | 158 | public ApAdapter(Context context) 159 | { 160 | mContext = context; 161 | mInflater = LayoutInflater.from(context); 162 | } 163 | @Override 164 | public int getCount() { 165 | return mListApItem.size(); 166 | } 167 | @Override 168 | public Object getItem(int arg0) { 169 | return mListApItem.get(arg0); 170 | } 171 | @Override 172 | public long getItemId(int arg0) { 173 | return arg0; 174 | } 175 | @Override 176 | public View getView(int position, View convertView, ViewGroup parent) { 177 | ViewHolder holder; 178 | if (convertView == null) { 179 | convertView = mInflater.inflate(R.layout.setting_ap_list_item, null); 180 | holder = new ViewHolder(); 181 | holder.icon = (ImageView) convertView.findViewById(R.id.apIcon); 182 | holder.name = (TextView) convertView.findViewById(R.id.apName); 183 | convertView.setTag(holder); 184 | } else { 185 | holder = (ViewHolder) convertView.getTag(); 186 | } 187 | 188 | holder.name.setText(mListApItem.get(position).label); 189 | holder.icon.setImageDrawable(mListApItem.get(position).appInfo.loadIcon(mContext.getPackageManager())); 190 | if(mListApItem.get(position).checked) 191 | convertView.setBackgroundColor(Color.LTGRAY); 192 | else 193 | convertView.setBackgroundColor(Color.TRANSPARENT); 194 | 195 | return convertView; 196 | } 197 | } 198 | private static final int MSG_REFRESH_LIST = 0; 199 | Handler mHandler = new Handler(){ 200 | public void handleMessage(Message msg) { 201 | switch (msg.what) { 202 | case MSG_REFRESH_LIST: 203 | mApAdapter.notifyDataSetChanged(); 204 | break; 205 | } 206 | } 207 | }; 208 | } 209 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingEnterBright.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.preference.DialogPreference; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.SeekBar; 9 | import android.widget.TextView; 10 | 11 | public class SettingEnterBright extends DialogPreference{ 12 | 13 | private TextView mPivotLux; 14 | private SeekBar mSeekBar; 15 | 16 | public SettingEnterBright(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | 19 | setDialogLayoutResource(R.layout.setting_enter_bright); 20 | } 21 | @Override 22 | public void onBindDialogView (View view) 23 | { 24 | mPivotLux = (TextView)view.findViewById(R.id.pivotLux_bright); 25 | mSeekBar = (SeekBar)view.findViewById(R.id.luxSeekBar_bright); 26 | mSeekBar.setMax(99); 27 | TextView min = (TextView)view.findViewById(R.id.seekMin_bright); 28 | TextView max = (TextView)view.findViewById(R.id.seekMax_bright); 29 | min.setText(String.valueOf(1)); 30 | max.setText(String.valueOf(100)); 31 | 32 | mSeekBar.setProgress(Prefs.getThresholdBright()); 33 | showPivotLux(Prefs.getThresholdBright()); 34 | 35 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 36 | @Override 37 | public void onStopTrackingTouch(SeekBar seekBar) { 38 | Log.e(Dimmer.TAG, "onStopTrackingTouch"); 39 | } 40 | @Override 41 | public void onStartTrackingTouch(SeekBar seekBar) { 42 | Log.e(Dimmer.TAG, "onStartTrackingTouch"); 43 | } 44 | @Override 45 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 46 | Log.e(Dimmer.TAG, "onProgressChanged: " + progress); 47 | showPivotLux(progress + 1); 48 | } 49 | }); 50 | } 51 | private void showPivotLux(int lux) 52 | { 53 | mPivotLux.setText(String.valueOf(lux) + " lux"); 54 | } 55 | @Override 56 | public void onDialogClosed(boolean positiveResult) 57 | { 58 | if(positiveResult) 59 | { 60 | Prefs.setThresholdBright(mSeekBar.getProgress() +1); 61 | setSummary(getContext().getResources().getString(R.string.pref_threshold_bright_diff) 62 | + " > "+ String.valueOf(mSeekBar.getProgress() +1) + " lux"); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingEnterDim.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | import android.preference.DialogPreference; 6 | import android.util.AttributeSet; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.widget.CompoundButton; 10 | import android.widget.SeekBar; 11 | import android.widget.Switch; 12 | import android.widget.TextView; 13 | 14 | public class SettingEnterDim extends DialogPreference{ 15 | 16 | private TextView mPivotLux; 17 | private SeekBar mSeekBar; 18 | private Switch mSwitchSetLowest; 19 | private int mShift; 20 | private int mAdjustRegion = 100; 21 | 22 | public SettingEnterDim(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | 25 | setDialogLayoutResource(R.layout.setting_enter_dim); 26 | } 27 | @Override 28 | public void onBindDialogView (View view) 29 | { 30 | mPivotLux = (TextView)view.findViewById(R.id.pivotLux_dim); 31 | mSeekBar = (SeekBar)view.findViewById(R.id.luxSeekBar_dim); 32 | mSwitchSetLowest = (Switch)view.findViewById(R.id.switchSetLowest); 33 | mSwitchSetLowest.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 34 | { 35 | @Override 36 | public void onCheckedChanged(CompoundButton arg0, boolean arg1) { 37 | if(arg1) 38 | { 39 | mSeekBar.setProgress(0); 40 | } 41 | } 42 | }); 43 | 44 | Point bound = new Point(); 45 | LuxUtil.getBoundaryLevel(bound); 46 | mShift = bound.x; 47 | mSeekBar.setMax(mAdjustRegion); 48 | TextView min = (TextView)view.findViewById(R.id.seekMin_dim); 49 | TextView max = (TextView)view.findViewById(R.id.seekMax_dim); 50 | min.setText(String.valueOf(bound.x)); 51 | max.setText(String.valueOf(bound.x + mAdjustRegion)); 52 | 53 | mSwitchSetLowest.setChecked(Prefs.getThresholdDimLowest()); 54 | if(Prefs.getThresholdDimLowest()) 55 | { 56 | mSeekBar.setProgress(0); 57 | showPivotLux(bound.x); 58 | } 59 | else 60 | { 61 | mSeekBar.setProgress(Prefs.getThresholdDim() - mShift); 62 | showPivotLux(Prefs.getThresholdDim()); 63 | } 64 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 65 | @Override 66 | public void onStopTrackingTouch(SeekBar seekBar) { 67 | Log.e(Dimmer.TAG, "onStopTrackingTouch"); 68 | } 69 | @Override 70 | public void onStartTrackingTouch(SeekBar seekBar) { 71 | Log.e(Dimmer.TAG, "onStartTrackingTouch"); 72 | } 73 | @Override 74 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 75 | Log.e(Dimmer.TAG, "onProgressChanged: " + progress); 76 | showPivotLux(progress + mShift); 77 | if(progress != 0) 78 | mSwitchSetLowest.setChecked(false); 79 | } 80 | }); 81 | } 82 | private void showPivotLux(int lux) 83 | { 84 | mPivotLux.setText(String.valueOf(lux) + " lux"); 85 | } 86 | @Override 87 | public void onDialogClosed(boolean positiveResult) 88 | { 89 | if(positiveResult) 90 | { 91 | Prefs.setThresholdDim(mSeekBar.getProgress() + mShift); 92 | Prefs.setThresholdDimLowest(mSwitchSetLowest.isChecked()); 93 | if(mSwitchSetLowest.isChecked()) 94 | setSummary(getContext().getResources().getString(R.string.pref_threshold_dim_lowest)); 95 | else 96 | setSummary(getContext().getResources().getString(R.string.pref_threshold_dim_lux) 97 | + " < "+ String.valueOf(mSeekBar.getProgress() + mShift) + " lux"); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingNotifyLayout.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giraffine/Android-Project/d4d02c86706f506d1a8b1d03a2ff61657a28e368/Dimmer/src/giraffine/dimmer/SettingNotifyLayout.java -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingNotifyRange.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import giraffine.dimmer.RangeSeekBar.OnRangeSeekBarChangeListener; 4 | import android.content.Context; 5 | import android.preference.DialogPreference; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | public class SettingNotifyRange extends DialogPreference{ 12 | 13 | private TextView mPivot = null; 14 | private RangeSeekBar mSeekBar = null; 15 | 16 | public SettingNotifyRange(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | setDialogLayoutResource(R.layout.setting_notify_range); 19 | } 20 | @Override 21 | public void onBindDialogView (View view) 22 | { 23 | mPivot = (TextView)view.findViewById(R.id.pivot_notify); 24 | TextView min = (TextView)view.findViewById(R.id.notify_seekMin); 25 | TextView max = (TextView)view.findViewById(R.id.notify_seekMax); 26 | min.setText(String.valueOf(1)); 27 | max.setText(String.valueOf(100)); 28 | 29 | // create RangeSeekBar as Integer range between 1 and 100 30 | mSeekBar = new RangeSeekBar(1, 100, getContext()); 31 | mSeekBar.setSelectedMinValue(Prefs.getNotify(Prefs.PREF_NOTIFY_LOWER)); 32 | mSeekBar.setSelectedMaxValue(Prefs.getNotify(Prefs.PREF_NOTIFY_UPPER)); 33 | 34 | mSeekBar.setNotifyWhileDragging(true); 35 | mSeekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener(){ 36 | @Override 37 | public void onRangeSeekBarValuesChanged(RangeSeekBar bar, Integer minValue, Integer maxValue) { 38 | if(maxValue < 50) 39 | { 40 | maxValue = 50; 41 | mSeekBar.setSelectedMaxValue(50); 42 | } 43 | if(minValue > 50) 44 | { 45 | minValue = 50; 46 | mSeekBar.setSelectedMinValue(50); 47 | } 48 | showPivot(minValue, maxValue); 49 | } 50 | }); 51 | // add RangeSeekBar to pre-defined layout 52 | ViewGroup group = (ViewGroup)view.findViewById(R.id.notify_root_view); 53 | group.addView(mSeekBar, 1); 54 | 55 | showPivot(Prefs.getNotify(Prefs.PREF_NOTIFY_LOWER), Prefs.getNotify(Prefs.PREF_NOTIFY_UPPER)); 56 | } 57 | private void showPivot(int min, int max) 58 | { 59 | mPivot.setText(String.valueOf(min) + " ~ " + String.valueOf(max)); 60 | } 61 | @Override 62 | public void onDialogClosed(boolean positiveResult) 63 | { 64 | if(positiveResult) 65 | { 66 | int min = mSeekBar.getSelectedMinValue(); 67 | int max = mSeekBar.getSelectedMaxValue(); 68 | Prefs.setNotify(Prefs.PREF_NOTIFY_LOWER, min); 69 | Prefs.setNotify(Prefs.PREF_NOTIFY_UPPER, max); 70 | setSummary(String.valueOf(min) + " ~ " + String.valueOf(max)); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingNotifyStep.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.Context; 4 | import android.preference.DialogPreference; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.SeekBar; 9 | import android.widget.TextView; 10 | 11 | public class SettingNotifyStep extends DialogPreference{ 12 | 13 | private TextView mPivot = null; 14 | private SeekBar mSeekBar = null; 15 | 16 | public SettingNotifyStep(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | setDialogLayoutResource(R.layout.setting_notify_step); 19 | } 20 | @Override 21 | public void onBindDialogView (View view) 22 | { 23 | mPivot = (TextView)view.findViewById(R.id.pivot_notify); 24 | mSeekBar = (SeekBar)view.findViewById(R.id.notifySeekBar); 25 | TextView min = (TextView)view.findViewById(R.id.notify_seekMin); 26 | TextView max = (TextView)view.findViewById(R.id.notify_seekMax); 27 | mSeekBar.setMax(9); 28 | min.setText(String.valueOf(1)); 29 | max.setText(String.valueOf(10)); 30 | mSeekBar.setProgress(Prefs.getNotify(getKey())); 31 | showPivot(Prefs.getNotify(getKey())); 32 | 33 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 34 | @Override 35 | public void onStopTrackingTouch(SeekBar seekBar) { 36 | } 37 | @Override 38 | public void onStartTrackingTouch(SeekBar seekBar) { 39 | } 40 | @Override 41 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 42 | Log.e(Dimmer.TAG, "onProgressChanged: " + progress); 43 | showPivot(progress + 1); 44 | } 45 | }); 46 | } 47 | private void showPivot(int value) 48 | { 49 | mPivot.setText(String.valueOf(value)); 50 | } 51 | @Override 52 | public void onDialogClosed(boolean positiveResult) 53 | { 54 | if(positiveResult) 55 | { 56 | int progress = mSeekBar.getProgress(); 57 | Prefs.setNotify(getKey(), progress +1); 58 | setSummary(String.valueOf(progress +1)); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | public class SettingsActivity extends Activity{ 7 | 8 | public static boolean showSettings = false; 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | if(getActionBar() != null) 15 | getActionBar().hide(); 16 | 17 | getFragmentManager().beginTransaction() 18 | .replace(android.R.id.content, new SettingsFragment()) 19 | .commit(); 20 | showSettings = true; 21 | } 22 | 23 | public void onPause () 24 | { 25 | super.onPause(); 26 | showSettings = false; 27 | finish(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/SettingsFragment.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.content.pm.PackageManager.NameNotFoundException; 9 | import android.os.Bundle; 10 | import android.preference.CheckBoxPreference; 11 | import android.preference.ListPreference; 12 | import android.preference.Preference; 13 | import android.preference.Preference.OnPreferenceChangeListener; 14 | import android.preference.Preference.OnPreferenceClickListener; 15 | import android.preference.PreferenceCategory; 16 | import android.preference.PreferenceFragment; 17 | import android.widget.Toast; 18 | 19 | public class SettingsFragment extends PreferenceFragment implements OnPreferenceClickListener, OnPreferenceChangeListener{ 20 | 21 | public static final String REFRESH_LUX = "refreshLux"; 22 | private CheckBoxPreference mPrefAutoMode = null; 23 | private CheckBoxPreference mPrefWidgetMode = null; 24 | private ListPreference mPrefSpeedDim = null; 25 | private ListPreference mPrefSpeedBright = null; 26 | private Preference mPrefThresholdDim = null; 27 | private Preference mPrefThresholdBright = null; 28 | private Preference mPrefApList = null; 29 | private Preference mPrefAlarmDim = null; 30 | private Preference mPrefAlarmBright = null; 31 | private Preference mPrefNotifyStep = null; 32 | private Preference mPrefNotifyRange = null; 33 | private Preference mPrefNotifyLayout = null; 34 | private CheckBoxPreference mPrefNotifyPriority = null; 35 | private CheckBoxPreference mPrefColorMode = null; 36 | private Preference mPrefColorPicker = null; 37 | 38 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver(){ 39 | @Override 40 | public void onReceive(Context arg0, Intent arg1) { 41 | showLuxInfo(arg1.getIntExtra("lux", 0)); 42 | } 43 | }; 44 | 45 | @Override 46 | public void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | Prefs.init(getActivity()); 49 | 50 | addPreferencesFromResource(R.xml.preference); 51 | 52 | mPrefAutoMode = (CheckBoxPreference)findPreference(Prefs.PREF_AUTOMODE); 53 | mPrefAutoMode.setOnPreferenceClickListener(this); 54 | 55 | mPrefWidgetMode = (CheckBoxPreference)findPreference(Prefs.PREF_WIDGETMODE); 56 | mPrefWidgetMode.setOnPreferenceClickListener(this); 57 | mPrefWidgetMode.setChecked(Prefs.getWidgetMode()); 58 | 59 | mPrefSpeedDim = (ListPreference)findPreference(Prefs.PREF_SPEED_DIM); 60 | mPrefSpeedDim.setOnPreferenceChangeListener(this); 61 | mPrefSpeedBright = (ListPreference)findPreference(Prefs.PREF_SPEED_BRIGHT); 62 | mPrefSpeedBright.setOnPreferenceChangeListener(this); 63 | 64 | mPrefThresholdDim = findPreference(Prefs.PREF_THRESHOLD_DIM); 65 | mPrefThresholdBright = findPreference(Prefs.PREF_THRESHOLD_BRIGHT); 66 | 67 | mPrefApList = findPreference(Prefs.PREF_AP_LIST); 68 | 69 | mPrefAlarmDim = findPreference(Prefs.PREF_ALARM_DIM); 70 | mPrefAlarmBright = findPreference(Prefs.PREF_ALARM_BRIGHT); 71 | 72 | mPrefNotifyStep = findPreference(Prefs.PREF_NOTIFY_STEP); 73 | mPrefNotifyRange = findPreference(Prefs.PREF_NOTIFY_RANGE); 74 | mPrefNotifyLayout = findPreference(Prefs.PREF_NOTIFY_LAYOUT); 75 | mPrefNotifyPriority = (CheckBoxPreference)findPreference(Prefs.PREF_NOTIFY_PRIORITY); 76 | mPrefNotifyPriority.setOnPreferenceClickListener(this); 77 | 78 | mPrefColorMode = (CheckBoxPreference)findPreference(Prefs.PREF_COLORMODE); 79 | mPrefColorMode.setOnPreferenceClickListener(this); 80 | mPrefColorPicker = findPreference(Prefs.PREF_COLOR_VALUE); 81 | 82 | updateAutoSettings(); 83 | updateAlarmSettings(); 84 | updateNotifySettings(); 85 | updateColorSettings(); 86 | 87 | try { 88 | String version = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName; 89 | Preference about = findPreference(Prefs.PREF_ABOUT); 90 | about.setTitle("Version: " + version); 91 | Prefs.setAbout(version); 92 | } catch (NameNotFoundException e) { 93 | e.printStackTrace(); 94 | } 95 | 96 | getActivity().registerReceiver(mBroadcastReceiver, new IntentFilter(REFRESH_LUX)); 97 | // showAutoModeDetail(false); 98 | } 99 | public void onDestroy () 100 | { 101 | super.onDestroy(); 102 | getActivity().unregisterReceiver(mBroadcastReceiver); 103 | } 104 | public void showLuxInfo(int lux) 105 | { 106 | mPrefAutoMode.setSummaryOn(getActivity().getResources().getString(R.string.pref_auto_lux_state) 107 | + " " + String.valueOf(lux) + " lux"); 108 | } 109 | @Override 110 | public boolean onPreferenceClick(Preference pref) { 111 | if(pref.getKey().equalsIgnoreCase(Prefs.PREF_AUTOMODE)) 112 | { 113 | changeAutoMode(mPrefAutoMode.isChecked()); 114 | mPrefThresholdDim.setEnabled(mPrefAutoMode.isChecked()); 115 | mPrefThresholdBright.setEnabled(mPrefAutoMode.isChecked()); 116 | mPrefSpeedDim.setEnabled(mPrefAutoMode.isChecked()); 117 | mPrefSpeedBright.setEnabled(mPrefAutoMode.isChecked()); 118 | mPrefApList.setEnabled(mPrefAutoMode.isChecked()); 119 | return true; 120 | } 121 | else if(pref.getKey().equalsIgnoreCase(Prefs.PREF_WIDGETMODE)) 122 | { 123 | if(mPrefWidgetMode.isChecked()) 124 | Toast.makeText(getActivity(), R.string.pref_widget_hint, Toast.LENGTH_LONG).show(); 125 | } 126 | else if(pref.getKey().equalsIgnoreCase(Prefs.PREF_NOTIFY_PRIORITY)) 127 | { 128 | pref.getEditor().commit(); 129 | changeStatusBarIcon(); 130 | } 131 | else if(pref.getKey().equalsIgnoreCase(Prefs.PREF_COLORMODE)) 132 | { 133 | pref.getEditor().commit(); 134 | updateColorSettings(); 135 | changeColorMode(mPrefColorMode.isChecked()); 136 | } 137 | return false; 138 | } 139 | @Override 140 | public boolean onPreferenceChange(Preference pref, Object newValue) { 141 | if(pref.getKey().equalsIgnoreCase(Prefs.PREF_SPEED_DIM)) 142 | { 143 | CharSequence[] entries = mPrefSpeedDim.getEntries(); 144 | mPrefSpeedDim.setSummary(entries[Integer.valueOf((String)newValue)-1]); 145 | changeSensitive(); 146 | return true; 147 | } 148 | else if(pref.getKey().equalsIgnoreCase(Prefs.PREF_SPEED_BRIGHT)) 149 | { 150 | CharSequence[] entries = mPrefSpeedBright.getEntries(); 151 | mPrefSpeedBright.setSummary(entries[Integer.valueOf((String)newValue)-1]); 152 | changeSensitive(); 153 | return true; 154 | } 155 | return false; 156 | } 157 | 158 | public void changeAutoMode(boolean on) 159 | { 160 | Intent startServiceIntent = new Intent(); 161 | startServiceIntent.setComponent(DimmerService.COMPONENT); 162 | startServiceIntent.setAction(DimmerService.SWITCHAUTOMODE); 163 | startServiceIntent.putExtra(DimmerService.SWITCHAUTOMODE, on); 164 | getActivity().startService(startServiceIntent); 165 | } 166 | public void changeSensitive() 167 | { 168 | Intent startServiceIntent = new Intent(); 169 | startServiceIntent.setComponent(DimmerService.COMPONENT); 170 | startServiceIntent.setAction(DimmerService.SENSITIVECHANGE); 171 | getActivity().startService(startServiceIntent); 172 | } 173 | public void changeStatusBarIcon() 174 | { 175 | Intent startServiceIntent = new Intent(); 176 | startServiceIntent.setComponent(DimmerService.COMPONENT); 177 | startServiceIntent.setAction(DimmerService.STATUSBARCHANGE); 178 | getActivity().startService(startServiceIntent); 179 | } 180 | public void changeColorMode(boolean enable) 181 | { 182 | Intent startServiceIntent = new Intent(); 183 | startServiceIntent.setComponent(DimmerService.COMPONENT); 184 | startServiceIntent.setAction(DimmerService.COLORCHANGE); 185 | startServiceIntent.putExtra(DimmerService.COLORCHANGE+"ON", enable); 186 | getActivity().startService(startServiceIntent); 187 | } 188 | public void updateAutoSettings() 189 | { 190 | if(!LightSensor.hasLightSensor(getActivity())) 191 | { 192 | changeAutoMode(false); 193 | mPrefAutoMode.setChecked(false); 194 | mPrefAutoMode.setEnabled(false); 195 | showAutoModeDetail(false); 196 | mPrefAutoMode.setSummaryOff(getActivity().getResources().getString(R.string.pref_auto_summary) 197 | + "\n\n" + getActivity().getResources().getString(R.string.pref_auto_not_support)); 198 | return; 199 | } 200 | mPrefThresholdDim.setEnabled(mPrefAutoMode.isChecked()); 201 | mPrefThresholdDim.setSummary(Prefs.getThresholdDimLowest() ? 202 | getActivity().getResources().getString(R.string.pref_threshold_dim_lowest) : 203 | getActivity().getResources().getString(R.string.pref_threshold_dim_lux) + " < "+ Prefs.getThresholdDim() + " lux" ); 204 | mPrefThresholdBright.setEnabled(mPrefAutoMode.isChecked()); 205 | mPrefThresholdBright.setSummary(getActivity().getResources().getString(R.string.pref_threshold_bright_diff) 206 | + " > "+ Prefs.getThresholdBright() + " lux" ); 207 | mPrefSpeedDim.setEnabled(mPrefAutoMode.isChecked()); 208 | mPrefSpeedBright.setEnabled(mPrefAutoMode.isChecked()); 209 | mPrefSpeedDim.setSummary(mPrefSpeedDim.getEntry()); 210 | mPrefSpeedBright.setSummary(mPrefSpeedBright.getEntry()); 211 | 212 | mPrefApList.setEnabled(mPrefAutoMode.isChecked()); 213 | mPrefApList.setSummary(SettingApList.getSummary(Prefs.getApList(), getActivity().getPackageManager())); 214 | } 215 | public void updateAlarmSettings() 216 | { 217 | if(AlarmUtil.getAlarmOnOff(Prefs.PREF_ALARM_DIM)) 218 | mPrefAlarmDim.setSummary(AlarmUtil.getAlarmTime(Prefs.PREF_ALARM_DIM, getActivity())); 219 | else 220 | mPrefAlarmDim.setSummary(getActivity().getResources().getString(R.string.pref_alarm_off)); 221 | 222 | if(AlarmUtil.getAlarmOnOff(Prefs.PREF_ALARM_BRIGHT)) 223 | mPrefAlarmBright.setSummary(AlarmUtil.getAlarmTime(Prefs.PREF_ALARM_BRIGHT, getActivity())); 224 | else 225 | mPrefAlarmBright.setSummary(getActivity().getResources().getString(R.string.pref_alarm_off)); 226 | } 227 | public void updateNotifySettings() 228 | { 229 | mPrefNotifyStep.setSummary(String.valueOf(Prefs.getNotify(Prefs.PREF_NOTIFY_STEP))); 230 | mPrefNotifyRange.setSummary(String.valueOf(Prefs.getNotify(Prefs.PREF_NOTIFY_LOWER)) 231 | + " ~ " + String.valueOf(Prefs.getNotify(Prefs.PREF_NOTIFY_UPPER))); 232 | mPrefNotifyLayout.setSummary(SettingNotifyLayout.getSummary(Prefs.getNotifyLayout())); 233 | } 234 | public void updateColorSettings() 235 | { 236 | mPrefColorPicker.setEnabled(mPrefColorMode.isChecked()); 237 | } 238 | public void showAutoModeDetail(boolean show) 239 | { 240 | if(show) 241 | { 242 | ((PreferenceCategory)findPreference("pref_automode_category")).addPreference(mPrefThresholdDim); 243 | ((PreferenceCategory)findPreference("pref_automode_category")).addPreference(mPrefThresholdBright); 244 | ((PreferenceCategory)findPreference("pref_automode_category")).addPreference(mPrefSpeedDim); 245 | ((PreferenceCategory)findPreference("pref_automode_category")).addPreference(mPrefSpeedBright); 246 | ((PreferenceCategory)findPreference("pref_automode_category")).addPreference(mPrefApList); 247 | } 248 | else 249 | { 250 | ((PreferenceCategory)findPreference("pref_automode_category")).removePreference(mPrefThresholdDim); 251 | ((PreferenceCategory)findPreference("pref_automode_category")).removePreference(mPrefThresholdBright); 252 | ((PreferenceCategory)findPreference("pref_automode_category")).removePreference(mPrefSpeedDim); 253 | ((PreferenceCategory)findPreference("pref_automode_category")).removePreference(mPrefSpeedBright); 254 | ((PreferenceCategory)findPreference("pref_automode_category")).removePreference(mPrefApList); 255 | } 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /Dimmer/src/giraffine/dimmer/TaskerReceiver.java: -------------------------------------------------------------------------------- 1 | package giraffine.dimmer; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | 8 | public class TaskerReceiver extends BroadcastReceiver{ 9 | 10 | @Override 11 | public void onReceive(Context context, Intent intent) { 12 | if(intent.getAction().equalsIgnoreCase("giraffine.dimmer.TOGGLE_ON_OFF")) 13 | { 14 | startDimmer(context, DimmerService.SWITCHDIM, null); 15 | } 16 | else if(intent.getAction().equalsIgnoreCase("giraffine.dimmer.TOGGLE_PAUSE_RESUME")) 17 | { 18 | startDimmer(context, DimmerService.PAUSEFUNCTION, null); 19 | } 20 | else if(intent.getAction().equalsIgnoreCase("giraffine.dimmer.STOP")) 21 | { 22 | startDimmer(context, DimmerService.RESETLEVEL, null); 23 | } 24 | else if(intent.getAction().equalsIgnoreCase("giraffine.dimmer.STEP_UP")) 25 | { 26 | startDimmer(context, DimmerService.STEPLEVELUP, null); 27 | } 28 | else if(intent.getAction().equalsIgnoreCase("giraffine.dimmer.STEP_DOWN")) 29 | { 30 | startDimmer(context, DimmerService.STEPLEVELDOWN, null); 31 | } 32 | } 33 | public void startDimmer(Context context, String action, Bundle bundle) 34 | { 35 | Intent startServiceIntent = new Intent(); 36 | startServiceIntent.setComponent(DimmerService.COMPONENT); 37 | startServiceIntent.setAction(action); 38 | context.startService(startServiceIntent); 39 | } 40 | 41 | } 42 | --------------------------------------------------------------------------------