├── .gitignore
├── LICENSE
├── PRIVACY.md
├── README.md
├── app
├── build.gradle
├── libs
│ └── json-simple.jar
├── lint.xml
├── proguard.txt
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ ├── androidx
│ │ └── viewpager
│ │ │ └── widget
│ │ │ └── UnderlinePagerTitleStrip.java
│ └── com
│ │ └── cypressworks
│ │ └── mensaplan
│ │ ├── AndroidV21Helper.java
│ │ ├── BackupAgent.java
│ │ ├── DayChangeListener.java
│ │ ├── HappyCowActivity.java
│ │ ├── MainActivity.java
│ │ ├── MensaWidgetProvider.java
│ │ ├── MensaWidgetService.java
│ │ ├── MyApplication.java
│ │ ├── OnPageChangeAdapter.java
│ │ ├── PlanFragmentPagerAdapter.java
│ │ ├── RangeTimePickerDialog.java
│ │ ├── ScrollListener.java
│ │ ├── Tools.java
│ │ ├── Views.java
│ │ ├── WebCamActivity.java
│ │ ├── food
│ │ ├── Line.java
│ │ ├── Meal.java
│ │ ├── Plan.java
│ │ ├── PlanAdapter.java
│ │ ├── PlanFragment.java
│ │ └── likes
│ │ │ ├── LikeManager.java
│ │ │ └── LikeStatus.java
│ │ ├── planmanager
│ │ ├── AdenauerPlanManager.java
│ │ ├── AkkStudentenWerkPlanManager.java
│ │ ├── CafeteriaMoltkePlanManager.java
│ │ ├── ErzbergerPlanManager.java
│ │ ├── GottesauePlanManager.java
│ │ ├── HolzgartenstrPlanManager.java
│ │ ├── MensaDropdownAdapter.java
│ │ ├── MoltkePlanManager.java
│ │ ├── PforzheimPlanManager.java
│ │ └── PlanManager.java
│ │ └── util
│ │ ├── SpannableStringBuilderHelper.java
│ │ └── StringUtils.java
│ └── res
│ ├── drawable-anydpi
│ ├── ic_action_more.xml
│ ├── thumbs_down.xml
│ ├── thumbs_undecided.xml
│ └── thumbs_up.xml
│ ├── drawable-hdpi
│ ├── ic_action_more.png
│ ├── icon.png
│ ├── icon_white.png
│ ├── thumbs_down.png
│ ├── thumbs_undecided.png
│ └── thumbs_up.png
│ ├── drawable-mdpi
│ ├── ic_action_more.png
│ ├── icon.png
│ ├── icon_white.png
│ ├── thumbs_down.png
│ ├── thumbs_undecided.png
│ └── thumbs_up.png
│ ├── drawable-nodpi
│ └── widget_preview.png
│ ├── drawable-xhdpi
│ ├── ic_action_more.png
│ ├── icon.png
│ ├── icon_white.png
│ ├── thumbs_down.png
│ ├── thumbs_undecided.png
│ └── thumbs_up.png
│ ├── drawable-xxhdpi
│ ├── heart.png
│ ├── ic_action_more.png
│ ├── ic_meal_bio.png
│ ├── ic_meal_cow.png
│ ├── ic_meal_cow_aw.png
│ ├── ic_meal_fish.png
│ ├── ic_meal_pork.png
│ ├── ic_meal_veg.png
│ ├── ic_meal_vegan.png
│ ├── icon.png
│ ├── icon_white.png
│ ├── thumbs_down.png
│ ├── thumbs_undecided.png
│ └── thumbs_up.png
│ ├── drawable-xxxhdpi
│ └── icon.png
│ ├── drawable
│ ├── ic_action_calendar_day.xml
│ ├── ic_action_refresh.xml
│ ├── list_selector.xml
│ ├── shadow_vertical.xml
│ └── widget_header_selector.xml
│ ├── layout-v21
│ └── like_button.xml
│ ├── layout
│ ├── actionitem_progress.xml
│ ├── activity_notification_settings.xml
│ ├── happy_cows_layout.xml
│ ├── layout_meal_types.xml
│ ├── like_button.xml
│ ├── list_header.xml
│ ├── list_item.xml
│ ├── main_new.xml
│ ├── spinner_dropdown_item.xml
│ ├── spinner_title_item.xml
│ ├── textview_drawer.xml
│ ├── view_shadow.xml
│ ├── webcam_activity.xml
│ ├── widget_layout.xml
│ ├── widget_list_header.xml
│ └── widget_list_item.xml
│ ├── menu
│ ├── mealcontextmenu.xml
│ ├── optionsmenu_frag.xml
│ └── optionsmenu_new.xml
│ ├── values-sw600dp
│ └── dimens.xml
│ ├── values
│ ├── colors_example.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ └── mensa_appwidget_info.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── green_button.png
├── green_button.psd
├── icon.psd
├── icon512.png
├── icon_new.psd
├── meal_icons.psd
├── red_button.png
└── red_shining_button.png
├── screenshots
├── device-2014-12-16-233433.png
├── device-2014-12-16-233453.png
└── device-2014-12-16-233723.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 | build
4 | /local.properties
5 | *.iml
6 | /motivkey.keystore
7 | /signing.properties
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/PRIVACY.md:
--------------------------------------------------------------------------------
1 | Die App KIT Mensa App erhebt und verarbeitet keine personenbezogenen Daten.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KitMensaAndroid
2 |
3 | https://play.google.com/store/apps/details?id=com.cypressworks.mensaplan
4 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 | signingConfigs {
6 | release {
7 | storeFile file('../motivkey.keystore')
8 | }
9 | }
10 |
11 | defaultConfig {
12 | applicationId 'com.cypressworks.mensaplan'
13 | minSdkVersion 14
14 | targetSdkVersion 34
15 | versionCode 34
16 | versionName "2.5.3"
17 | }
18 |
19 | compileSdk 34
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled true
28 | shrinkResources true
29 | signingConfig signingConfigs.release
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.txt'
31 | }
32 | }
33 | productFlavors {
34 | }
35 | packagingOptions {
36 | resources {
37 | excludes += ['META-INF/services/javax.annotation.processing.Processor']
38 | }
39 | }
40 |
41 |
42 | namespace 'com.cypressworks.mensaplan'
43 | lint {
44 | disable 'InvalidPackage'
45 | }
46 | }
47 |
48 | dependencies {
49 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
50 | implementation 'androidx.appcompat:appcompat:1.6.1'
51 | implementation 'org.jsoup:jsoup:1.15.3'
52 | implementation 'com.nineoldandroids:library:2.4.0'
53 | implementation files('libs/json-simple.jar')
54 | }
55 |
56 | def props = new Properties()
57 | def propFile = new File('signing.properties')
58 |
59 | if (propFile.canRead()) {
60 | props.load(new FileInputStream(propFile))
61 |
62 | if (props != null &&
63 | props.containsKey('STORE_PASSWORD') &&
64 | props.containsKey('KEY_ALIAS') &&
65 | props.containsKey('KEY_PASSWORD')) {
66 | android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
67 | android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
68 | android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
69 | }
70 | } else {
71 | println 'signing.properties not found'
72 | android.buildTypes.release.signingConfig = null
73 | }
74 |
--------------------------------------------------------------------------------
/app/libs/json-simple.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cypressious/KitMensaAndroid/9bf4b8bee9c9f4655e4099362353a6f824613475/app/libs/json-simple.jar
--------------------------------------------------------------------------------
/app/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/proguard.txt:
--------------------------------------------------------------------------------
1 | -dontobfuscate
2 |
3 | -keep public class * extends com.cypressworks.mensaplan.planmanager.PlanManager
4 |
5 | -dontwarn java.lang.invoke**
6 | -dontwarn javax.annotation.Nullable
7 | -dontwarn javax.annotation.ParametersAreNonnullByDefault
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
19 |
20 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
41 |
42 |
46 |
47 |
48 |
49 |
50 |
53 |
54 |
56 |
57 |
58 |
59 |
60 |
63 |
64 |
65 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/java/androidx/viewpager/widget/UnderlinePagerTitleStrip.java:
--------------------------------------------------------------------------------
1 | package androidx.viewpager.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.util.AttributeSet;
8 |
9 | import com.cypressworks.mensaplan.R;
10 |
11 | /**
12 | * Created by Kirill on 29.10.2014.
13 | */
14 | public class UnderlinePagerTitleStrip extends PagerTitleStrip {
15 |
16 | private final Paint mTabPaint = new Paint();
17 | private int mTabPadding;
18 | private int mIndicatorHeight;
19 | private int mTabAlpha = 0xFF;
20 | private int mIndicatorColor;
21 |
22 | public UnderlinePagerTitleStrip(final Context context) {
23 | super(context);
24 | init();
25 | }
26 |
27 | public UnderlinePagerTitleStrip(final Context context, final AttributeSet attrs) {
28 | super(context, attrs);
29 | init();
30 | }
31 |
32 | private void init() {
33 | Resources res = getResources();
34 | mTabPadding = (int) res.getDimension(R.dimen.tab_padding);
35 | mIndicatorHeight = (int) res.getDimension(R.dimen.indicator_height);
36 | mIndicatorColor = res.getColor(R.color.accent);
37 | }
38 |
39 | @Override
40 | protected void onDraw(final Canvas canvas) {
41 | super.onDraw(canvas);
42 |
43 | final int bottom = getHeight();
44 | final int left = mCurrText.getLeft() - mTabPadding;
45 | final int right = mCurrText.getRight() + mTabPadding;
46 | final int top = bottom - mIndicatorHeight;
47 | mTabPaint.setColor(mTabAlpha << 24 | (mIndicatorColor & 0xFFFFFF));
48 | canvas.drawRect(left, top, right, bottom, mTabPaint);
49 | }
50 |
51 | @Override
52 | void updateTextPositions(int position, float positionOffset, boolean force) {
53 | super.updateTextPositions(position, positionOffset, force);
54 | mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/AndroidV21Helper.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.app.ActivityManager;
6 | import android.graphics.BitmapFactory;
7 | import android.os.Build;
8 |
9 | /**
10 | * Created by Kirill on 28.10.2014.
11 | */
12 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
13 | public class AndroidV21Helper {
14 |
15 | public static void setTaskDescription(
16 | final Activity activity, final String label, final int icon, final int color) {
17 | activity.setTaskDescription(new ActivityManager.TaskDescription(label,
18 | BitmapFactory.decodeResource(
19 | activity.getResources(),
20 | icon), color));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/BackupAgent.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
2 |
3 | import android.app.backup.BackupAgentHelper;
4 | import android.app.backup.FileBackupHelper;
5 | import android.app.backup.SharedPreferencesBackupHelper;
6 | import com.cypressworks.mensaplan.food.likes.LikeManager;
7 |
8 | /**
9 | * Created by Kirill on 30.05.2016.
10 | */
11 | public class BackupAgent extends BackupAgentHelper {
12 |
13 | @Override
14 | public void onCreate() {
15 | addHelper("collected", new FileBackupHelper(this, HappyCowActivity.FILE_NAME_COLLECTED));
16 | addHelper("prefs",
17 | new SharedPreferencesBackupHelper(this, getPackageName() + "_preferences"));
18 | addHelper("likes", new SharedPreferencesBackupHelper(this, LikeManager.LIKES_PREFS));
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/DayChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.preference.PreferenceManager;
8 |
9 | /**
10 | * @author Kirill Rakhman
11 | */
12 | public class DayChangeListener extends BroadcastReceiver {
13 |
14 | @Override
15 | public void onReceive(final Context context, final Intent intent) {
16 | MensaWidgetProvider.updateWidgets(context);
17 |
18 | final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
19 | prefs.edit().putBoolean("dayChanged", true).apply();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/HappyCowActivity.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
2 |
3 | import android.app.Activity;
4 | import android.app.backup.BackupManager;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.res.Resources;
8 | import android.graphics.Color;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.graphics.drawable.Drawable;
11 | import android.graphics.drawable.TransitionDrawable;
12 | import android.os.Bundle;
13 | import android.text.Spannable;
14 | import android.text.SpannableString;
15 | import android.text.style.ForegroundColorSpan;
16 | import android.view.View;
17 | import android.view.ViewTreeObserver;
18 | import android.view.animation.DecelerateInterpolator;
19 | import android.view.animation.Interpolator;
20 | import android.widget.TextView;
21 |
22 | import com.cypressworks.mensaplan.planmanager.PlanManager;
23 | import com.nineoldandroids.animation.Animator;
24 | import com.nineoldandroids.animation.AnimatorListenerAdapter;
25 | import com.nineoldandroids.view.ViewHelper;
26 | import com.nineoldandroids.view.ViewPropertyAnimator;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.io.Serializable;
31 | import java.util.Calendar;
32 | import java.util.HashSet;
33 |
34 | import androidx.annotation.NonNull;
35 |
36 | /**
37 | * @author Kirill Rakhman
38 | */
39 | public class HappyCowActivity extends Activity {
40 |
41 | public static final String FILE_NAME_COLLECTED = "collected_cows";
42 |
43 | @NonNull
44 | public static File getCollectedFile(final Context c) {
45 | return new File(c.getFilesDir(), FILE_NAME_COLLECTED);
46 | }
47 |
48 | public static final String EXTRA_MENSA_CLASS = "EXTRA_MENSA_CLASS";
49 | public static final String EXTRA_DAY = "EXTRA_DAY";
50 | public static final String EXTRA_ITEM = "EXTRA_ITEM";
51 |
52 | private static final Interpolator sDecelerator = new DecelerateInterpolator();
53 |
54 | private File collectedFile;
55 | private HashSet collected;
56 | private Resources res;
57 |
58 | private TextView gratulations, total;
59 | private View layout;
60 | private View background;
61 |
62 | private String PACKAGE_NAME;
63 |
64 | @SuppressWarnings("unchecked")
65 | @Override
66 | protected void onCreate(final Bundle savedInstanceState) {
67 | super.onCreate(savedInstanceState);
68 |
69 | PACKAGE_NAME = getPackageName();
70 | res = getResources();
71 |
72 | setContentView(R.layout.happy_cows_layout);
73 | gratulations = Views.findViewById(this, R.id.textViewGratulations);
74 | total = Views.findViewById(this, R.id.textViewTotal);
75 |
76 | layout = findViewById(R.id.layoutHappyCowDialog);
77 | background = findViewById(R.id.layoutBackground);
78 | background.setOnClickListener(v -> animateOut());
79 |
80 | collectedFile = getCollectedFile(this);
81 | if (collectedFile.exists()) {
82 | try {
83 | collected = Tools.readObject(collectedFile);
84 | } catch (final Exception e) {
85 | collected = new HashSet<>();
86 | }
87 | } else {
88 | collected = new HashSet<>();
89 | }
90 |
91 | final Intent intent = getIntent();
92 |
93 | if (intent != null) {
94 | final Bundle extras = intent.getExtras();
95 |
96 | if (extras != null) {
97 | final Class extends PlanManager> planClass = (Class extends PlanManager>) extras.getSerializable(
98 | EXTRA_MENSA_CLASS);
99 | final Calendar date = (Calendar) extras.getSerializable(EXTRA_DAY);
100 | final int item = extras.getInt(EXTRA_ITEM);
101 |
102 | if (planClass != null && date != null) {
103 | checkCow(planClass, date, item);
104 | }
105 |
106 | if (savedInstanceState == null) {
107 | animateIn(extras);
108 | }
109 | }
110 | }
111 |
112 | setCollectedCount();
113 |
114 | }
115 |
116 | private void animateIn(final Bundle extras) {
117 | final int thumbnailTop = extras.getInt(PACKAGE_NAME + ".top");
118 | final int thumbnailLeft = extras.getInt(PACKAGE_NAME + ".left");
119 | final int thumbnailWidth = extras.getInt(PACKAGE_NAME + ".width");
120 | final int thumbnailHeight = extras.getInt(PACKAGE_NAME + ".height");
121 |
122 | final ViewTreeObserver observer = layout.getViewTreeObserver();
123 | observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
124 |
125 | @Override
126 | public boolean onPreDraw() {
127 | layout.getViewTreeObserver().removeOnPreDrawListener(this);
128 |
129 | final int[] screenLocation = new int[2];
130 | layout.getLocationOnScreen(screenLocation);
131 | final int mLeftDelta = thumbnailLeft - screenLocation[0];
132 | final int mTopDelta = thumbnailTop - screenLocation[1];
133 |
134 | // Scale factors to make the large version the same
135 | // size as the
136 | // thumbnail
137 | final float mWidthScale = (float) thumbnailWidth / layout.getWidth();
138 | final float mHeightScale = (float) thumbnailHeight / layout.getHeight();
139 |
140 | ViewHelper.setPivotX(layout, 0);
141 | ViewHelper.setPivotY(layout, 0);
142 | ViewHelper.setScaleX(layout, mWidthScale);
143 | ViewHelper.setScaleY(layout, mHeightScale);
144 | ViewHelper.setTranslationX(layout, mLeftDelta);
145 | ViewHelper.setTranslationY(layout, mTopDelta);
146 |
147 | // Animate scale and translation to go from
148 | // thumbnail to full
149 | // size
150 | ViewPropertyAnimator.animate(layout).scaleX(1).scaleY(1).translationX(
151 | 0).translationY(0).setInterpolator(sDecelerator).start();
152 |
153 | final TransitionDrawable backDrawable = new TransitionDrawable(
154 | new Drawable[]{new ColorDrawable(
155 | Color.parseColor("#00000000")), new ColorDrawable(
156 | Color.parseColor("#99000000"))});
157 | background.setBackgroundDrawable(backDrawable);
158 | backDrawable.startTransition(300);
159 |
160 | return true;
161 | }
162 | });
163 | }
164 |
165 | @Override
166 | public void onBackPressed() {
167 | animateOut();
168 | }
169 |
170 | private void animateOut() {
171 | final ViewPropertyAnimator anim = ViewPropertyAnimator.animate(background).alpha(0f);
172 | anim.setListener(new AnimatorListenerAdapter() {
173 | @Override
174 | public void onAnimationEnd(final Animator animation) {
175 | finish();
176 | }
177 | });
178 | anim.start();
179 | }
180 |
181 | @Override
182 | public void finish() {
183 | super.finish();
184 |
185 | // override transitions to skip the standard window animations
186 | overridePendingTransition(0, 0);
187 | }
188 |
189 | private void setCollectedCount() {
190 | final int num = collected.size();
191 | final String text = res.getQuantityString(R.plurals.happy_cow_total, num, num);
192 | final String numString = String.valueOf(num);
193 | final int numberPos = text.indexOf(numString);
194 |
195 | final Spannable spanned = new SpannableString(text);
196 | spanned.setSpan(new ForegroundColorSpan(Color.parseColor("#cc0000")), numberPos,
197 | numberPos + numString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
198 |
199 | total.setText(spanned);
200 | }
201 |
202 | private void checkCow(
203 | final Class extends PlanManager> planClass, final Calendar date, final int item) {
204 |
205 | final CowHolder holder = new CowHolder();
206 | holder.mensa = PlanManager.getInstance(planClass, this).getProviderName();
207 | holder.day = date.get(Calendar.DAY_OF_YEAR);
208 | holder.year = date.get(Calendar.YEAR);
209 | holder.item = item;
210 |
211 | if (!collected.contains(holder)) {
212 | collected.add(holder);
213 | try {
214 | Tools.writeObject(collected, collectedFile);
215 | new BackupManager(this).dataChanged();
216 | } catch (final IOException e) {
217 | e.printStackTrace();
218 | }
219 |
220 | gratulations.setText(R.string.happy_cow_gratulations);
221 | } else {
222 | gratulations.setText(R.string.happy_cow_already_found);
223 | }
224 |
225 | gratulations.setVisibility(View.VISIBLE);
226 | }
227 |
228 | private static class CowHolder implements Serializable {
229 | private static final long serialVersionUID = 2210140636911080441L;
230 |
231 | String mensa;
232 | int year, day, item;
233 |
234 | @Override
235 | public int hashCode() {
236 | final int prime = 31;
237 | int result = 1;
238 | result = prime * result + day;
239 | result = prime * result + item;
240 | result = prime * result + ((mensa == null) ? 0 : mensa.hashCode());
241 | result = prime * result + year;
242 | return result;
243 | }
244 |
245 | @Override
246 | public boolean equals(final Object obj) {
247 | if (this == obj) {
248 | return true;
249 | }
250 | if (obj == null) {
251 | return false;
252 | }
253 | if (!(obj instanceof CowHolder)) {
254 | return false;
255 | }
256 | final CowHolder other = (CowHolder) obj;
257 | if (day != other.day) {
258 | return false;
259 | }
260 | if (item != other.item) {
261 | return false;
262 | }
263 | if (mensa == null) {
264 | if (other.mensa != null) {
265 | return false;
266 | }
267 | } else if (!mensa.equals(other.mensa)) {
268 | return false;
269 | }
270 | return year == other.year;
271 | }
272 |
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.backup.BackupManager;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.content.pm.PackageInfo;
8 | import android.content.pm.PackageManager.NameNotFoundException;
9 | import android.content.res.Configuration;
10 | import android.content.res.Resources;
11 | import android.graphics.Color;
12 | import android.os.Build;
13 | import android.os.Bundle;
14 | import android.preference.PreferenceManager;
15 | import android.util.Log;
16 | import android.util.TypedValue;
17 | import android.view.Gravity;
18 | import android.view.Menu;
19 | import android.view.MenuInflater;
20 | import android.view.MenuItem;
21 | import android.view.View;
22 | import android.view.animation.AccelerateDecelerateInterpolator;
23 | import android.widget.ListView;
24 |
25 | import com.cypressworks.mensaplan.planmanager.MensaDropdownAdapter;
26 | import com.cypressworks.mensaplan.planmanager.PlanManager;
27 | import com.nineoldandroids.animation.ObjectAnimator;
28 |
29 | import java.io.File;
30 | import java.util.Calendar;
31 |
32 | import androidx.annotation.NonNull;
33 | import androidx.appcompat.app.ActionBar;
34 | import androidx.appcompat.app.ActionBarDrawerToggle;
35 | import androidx.appcompat.app.AppCompatActivity;
36 | import androidx.drawerlayout.widget.DrawerLayout;
37 | import androidx.viewpager.widget.PagerTitleStrip;
38 | import androidx.viewpager.widget.ViewPager;
39 | import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
40 |
41 | /**
42 | * @author Kirill Rakhman
43 | */
44 | public class MainActivity extends AppCompatActivity implements ScrollListener {
45 |
46 | public static final String PREF_MENSA_NUM = "pref_mensa_num";
47 | public static final String PACKAGE_WEAR = "com.google.android.wearable.app";
48 |
49 | private MensaDropdownAdapter mensaAdapter;
50 | private ViewPager viewPager;
51 | private ListView listDrawer;
52 | private DrawerLayout drawerLayout;
53 |
54 | private Calendar today = Calendar.getInstance();
55 | private int currentPagerPosition;
56 | private SharedPreferences prefs;
57 | private ActionBarDrawerToggle mDrawerToggle;
58 |
59 | @SuppressLint({"NewApi", "CommitPrefEdits"})
60 | @Override
61 | protected void onCreate(final Bundle arg0) {
62 | super.onCreate(arg0);
63 |
64 | mensaAdapter = new MensaDropdownAdapter(this);
65 | currentPagerPosition = PlanFragmentPagerAdapter.getDefaultPosition();
66 | prefs = PreferenceManager.getDefaultSharedPreferences(this);
67 | prefs.edit().putBoolean("dayChanged", false).apply();
68 |
69 | makeStartUpCleaning();
70 |
71 | setContentView(R.layout.main_new);
72 |
73 | viewPager = Views.findViewById(this, R.id.pager);
74 | viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.pager_margin));
75 | viewPager.addOnPageChangeListener(onPageChangeListener);
76 |
77 | drawerLayout = Views.findViewById(this, R.id.drawer_layout);
78 | listDrawer = Views.findViewById(this, R.id.left_drawer);
79 | prepareDrawer();
80 |
81 | final PagerTitleStrip titleStrip = Views.findViewById(this, R.id.titleStrip);
82 | titleStrip.setTextColor(Color.WHITE);
83 |
84 | prepareActionBar();
85 |
86 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
87 | setTaskDescription();
88 | }
89 |
90 | if (!prefs.getBoolean("backed_up", false) && HappyCowActivity.getCollectedFile(
91 | this).exists()) {
92 | prefs.edit().putBoolean("backed_up", true).apply();
93 | new BackupManager(this).dataChanged();
94 | }
95 | }
96 |
97 | private void setTaskDescription() {
98 | final TypedValue typedValue = new TypedValue();
99 | final Resources.Theme theme = getTheme();
100 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
101 | theme.resolveAttribute(android.R.attr.colorPrimary, typedValue, true);
102 | AndroidV21Helper.setTaskDescription(this, null, R.drawable.icon_white, typedValue.data);
103 | }
104 | }
105 |
106 | @Override
107 | protected void onResume() {
108 | super.onResume();
109 |
110 | if (prefs.getBoolean("dayChanged", false)) {
111 | prefs.edit().putBoolean("dayChanged", true).apply();
112 |
113 | today = Calendar.getInstance();
114 | currentPagerPosition = PlanFragmentPagerAdapter.getDefaultPosition();
115 |
116 | final int defaultItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(
117 | PREF_MENSA_NUM, 0);
118 | onMensaSelected(defaultItem);
119 | }
120 | }
121 |
122 | @Override
123 | protected void onPostCreate(final Bundle savedInstanceState) {
124 | super.onPostCreate(savedInstanceState);
125 | // Sync the toggle state after onRestoreInstanceState has occurred.
126 | mDrawerToggle.syncState();
127 | }
128 |
129 | @Override
130 | public void onConfigurationChanged(@NonNull final Configuration newConfig) {
131 | super.onConfigurationChanged(newConfig);
132 | mDrawerToggle.onConfigurationChanged(newConfig);
133 | }
134 |
135 | @Override
136 | public void onBackPressed() {
137 | if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
138 | drawerLayout.closeDrawers();
139 | return;
140 | }
141 |
142 | super.onBackPressed();
143 | }
144 |
145 | private void makeStartUpCleaning() {
146 | final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
147 | final int lastClean = prefs.getInt("lastClean", -1);
148 | final int version = getVersionNumber();
149 |
150 | if (lastClean < version) {
151 | prefs.edit().putInt("lastClean", version).apply();
152 |
153 | final File cacheDir = getCacheDir();
154 |
155 | for (final File file : cacheDir.listFiles()) {
156 | if (file.isDirectory()) {
157 | Tools.deleteFolder(file);
158 | } else {
159 | file.delete();
160 | }
161 | }
162 | } else {
163 | for (int i = 0; i < mensaAdapter.getCount(); i++) {
164 | PlanManager.getInstance(mensaAdapter.getItem(i), this).clearCache(8);
165 | }
166 | }
167 |
168 | // final boolean notificationDialogShown = prefs.getBoolean("notification_dialog_shown",
169 | // false);
170 | //
171 | // if (!notificationDialogShown) {
172 | // prefs.edit().putBoolean("notification_dialog_shown", true).apply();
173 | //
174 | // final List installedApplications = getPackageManager().getInstalledApplications(
175 | // 0);
176 | //
177 | // for (final ApplicationInfo info : installedApplications) {
178 | // if (info.packageName.equals(PACKAGE_WEAR)) {
179 | // new AlertDialog.Builder(this) //
180 | // .setTitle(R.string.notification_question_title) //
181 | // .setMessage(R.string.notification_question) //
182 | // .setPositiveButton(android.R.string.yes,
183 | // (dialog, which) -> startActivity(new Intent(this,
184 | // NotificationSettingsActivity.class))) //
185 | // .setNegativeButton(android.R.string.cancel, null) //
186 | // .show();
187 | // return;
188 | // }
189 | // }
190 | // }
191 |
192 | }
193 |
194 | private int getVersionNumber() {
195 | try {
196 | final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
197 | return packageInfo.versionCode;
198 | } catch (final NameNotFoundException e) {
199 | throw new RuntimeException(e);
200 | }
201 | }
202 |
203 | private final OnPageChangeListener onPageChangeListener = new OnPageChangeAdapter() {
204 | @Override
205 | public void onPageSelected(final int position) {
206 | currentPagerPosition = position;
207 | log("Page changed: " + currentPagerPosition);
208 | }
209 | };
210 |
211 | private void prepareActionBar() {
212 | final ActionBar actionBar = getSupportActionBar();
213 |
214 | actionBar.setElevation(0);
215 |
216 | }
217 |
218 | private void prepareDrawer() {
219 | mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open_drawer,
220 | R.string.close_drawer) {
221 | public void onDrawerClosed(final View view) {
222 | super.onDrawerClosed(view);
223 | }
224 |
225 | /** Called when a drawer has settled in a completely open state. */
226 | public void onDrawerOpened(final View drawerView) {
227 | super.onDrawerOpened(drawerView);
228 | }
229 |
230 | };
231 |
232 | drawerLayout.addDrawerListener(mDrawerToggle);
233 |
234 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
235 | getSupportActionBar().setHomeButtonEnabled(true);
236 |
237 | final int defaultItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(
238 | PREF_MENSA_NUM, 0);
239 |
240 | listDrawer.setAdapter(mensaAdapter);
241 | listDrawer.setOnItemClickListener((parent, view, position, id) -> {
242 | onMensaSelected(position);
243 | drawerLayout.closeDrawers();
244 | });
245 |
246 | onMensaSelected(defaultItem);
247 | }
248 |
249 | private void onMensaSelected(final int itemPosition) {
250 | PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(PREF_MENSA_NUM,
251 | itemPosition).apply();
252 | new BackupManager(this).dataChanged();
253 |
254 | final Class extends PlanManager> managerClass = mensaAdapter.getItem(itemPosition);
255 |
256 | final PlanFragmentPagerAdapter pagerAdapter = new PlanFragmentPagerAdapter(this,
257 | getSupportFragmentManager(),
258 | today,
259 | managerClass);
260 |
261 | viewPager.setAdapter(pagerAdapter);
262 | viewPager.removeOnPageChangeListener(onPageChangeListener);
263 | viewPager.setCurrentItem(currentPagerPosition);
264 | log("Setting current item: " + currentPagerPosition);
265 | viewPager.addOnPageChangeListener(onPageChangeListener);
266 |
267 | MensaWidgetProvider.updateWidgets(this);
268 |
269 | getSupportActionBar().setTitle(mensaAdapter.getName(itemPosition));
270 | }
271 |
272 | @Override
273 | public boolean onCreateOptionsMenu(final Menu menu) {
274 | final MenuInflater inflater = getMenuInflater();
275 | inflater.inflate(R.menu.optionsmenu_new, menu);
276 |
277 | return true;
278 | }
279 |
280 | @Override
281 | public void supportInvalidateOptionsMenu() {
282 | // unschöner Hack, aber scheinbar verhindert das, dass beim Start das
283 | // "today" action item fehlt
284 | viewPager.post(MainActivity.super::supportInvalidateOptionsMenu);
285 | }
286 |
287 | @Override
288 | public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
289 |
290 | if (mDrawerToggle.onOptionsItemSelected(item)) {
291 | return true;
292 | }
293 |
294 | int itemId = item.getItemId();
295 | if (itemId == R.id.webcam) {
296 | final Intent webcamActivity = new Intent(getBaseContext(), WebCamActivity.class);
297 | startActivity(webcamActivity);
298 | return true;
299 | } else if (itemId == R.id.today) {
300 | scrollToToday();
301 | return true;
302 | }
303 |
304 | return false;
305 | }
306 |
307 | private void scrollToToday() {
308 | final int todayPosition = PlanFragmentPagerAdapter.getDefaultPosition();
309 |
310 | if (viewPager.getCurrentItem() != todayPosition) {
311 | viewPager.setCurrentItem(todayPosition);
312 | } else {
313 |
314 | final View view = viewPager.getChildAt(1);
315 |
316 | final ObjectAnimator anim = ObjectAnimator.ofFloat(view, "translationX", 0, dp2px(0),
317 | dp2px(10), dp2px(0), dp2px(-10),
318 | dp2px(0), dp2px(2),
319 | dp2px(0)).setDuration(300);
320 |
321 | anim.setInterpolator(new AccelerateDecelerateInterpolator());
322 | anim.start();
323 | }
324 | }
325 |
326 | @Override
327 | public void onScrolled(final int yScroll) {
328 | // if (VERSION.SDK_INT >= 21) {
329 | // float elevation = titleStripMaxElevation * Math.min(1f,
330 | // yScroll / titleStripMaxElevationScroll);
331 | // AndroidV21Helper.setElevation(titleStrip, elevation);
332 | // }
333 | }
334 |
335 | private float dp2px(final float dp) {
336 | final Resources r = getResources();
337 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
338 | }
339 |
340 | void log(final String msg) {
341 | if (BuildConfig.DEBUG) {
342 | Log.d(getClass().getSimpleName(), msg);
343 | }
344 | }
345 |
346 | @SuppressLint("MissingSuperCall")
347 | @Override
348 | protected void onSaveInstanceState(@NonNull final Bundle outState) {
349 | // Verhinden, dass der ViewPager seine Position speichern. Wir wollen
350 | // immer bei heute beginnen.
351 | }
352 |
353 | }
354 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/MensaWidgetProvider.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
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.net.Uri;
10 | import android.preference.PreferenceManager;
11 | import android.util.Log;
12 | import android.widget.RemoteViews;
13 |
14 | import com.cypressworks.mensaplan.planmanager.MensaDropdownAdapter;
15 |
16 | import java.text.SimpleDateFormat;
17 | import java.util.Date;
18 | import java.util.Locale;
19 |
20 | /**
21 | * @author Kirill Rakhman
22 | */
23 | public class MensaWidgetProvider extends AppWidgetProvider {
24 |
25 | private static final SimpleDateFormat weekDayDateFormat = new SimpleDateFormat("E (dd.MM.)",
26 | Locale.GERMANY);
27 |
28 | private static final String ACTION_RELOAD = "com.cypressworks.mensaplan.REFRESH";
29 |
30 | @Override
31 | public void onReceive(final Context context, final Intent intent) {
32 | final String action = intent.getAction();
33 |
34 | if (action != null && action.equals(ACTION_RELOAD)) {
35 | log("Reloading data for widget");
36 |
37 | PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("reload",
38 | true).putBoolean(
39 | "dayChanged", true).apply();
40 |
41 | updateWidgets(context);
42 | } else {
43 | super.onReceive(context, intent);
44 | }
45 | }
46 |
47 | @Override
48 | public void onUpdate(
49 | final Context context, final AppWidgetManager appWidgetManager,
50 | final int[] appWidgetIds) {
51 | // update each of the app widgets with the remote adapter
52 | for (final int appWidgetId : appWidgetIds) {
53 | final RemoteViews rv = new RemoteViews(context.getPackageName(),
54 | R.layout.widget_layout);
55 |
56 | // header
57 | final String mensaName = MensaDropdownAdapter.getManagerFromPreferences(
58 | context).getFullProviderName();
59 | rv.setTextViewText(R.id.textViewMensa, mensaName);
60 |
61 | rv.setTextViewText(R.id.textViewDay, weekDayDateFormat.format(new Date()));
62 |
63 | final Intent refreshIntent = new Intent(context, getClass());
64 | refreshIntent.setAction(ACTION_RELOAD);
65 | final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0,
66 | refreshIntent,
67 | PendingIntent.FLAG_IMMUTABLE);
68 | rv.setOnClickPendingIntent(R.id.widgetButtonRefresh, refreshPendingIntent);
69 |
70 | // reload button
71 | final Intent mainActIntent = new Intent(context, MainActivity.class);
72 | final PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0,
73 | mainActIntent,
74 | PendingIntent.FLAG_IMMUTABLE);
75 | rv.setOnClickPendingIntent(R.id.LinearLayoutHeader, mainPendingIntent);
76 |
77 | // list
78 | final Intent widgetServiceIntent = new Intent(context, MensaWidgetService.class);
79 | widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
80 | widgetServiceIntent.setData(
81 | Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));
82 | rv.setRemoteAdapter(appWidgetId, R.id.listViewWidget, widgetServiceIntent);
83 |
84 | appWidgetManager.updateAppWidget(appWidgetId, rv);
85 | }
86 | super.onUpdate(context, appWidgetManager, appWidgetIds);
87 | }
88 |
89 | void log(final String msg) {
90 | if (BuildConfig.DEBUG) {
91 | Log.d(getClass().getSimpleName(), msg);
92 | }
93 | }
94 |
95 | public static void updateWidgets(final Context c) {
96 |
97 | final AppWidgetManager widgetManager = AppWidgetManager.getInstance(c);
98 | final int[] ids = widgetManager.getAppWidgetIds(
99 | new ComponentName(c, MensaWidgetProvider.class));
100 |
101 | final Intent intent = new Intent(c, MensaWidgetProvider.class);
102 | intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
103 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
104 |
105 | c.sendBroadcast(intent);
106 |
107 | widgetManager.notifyAppWidgetViewDataChanged(ids, R.id.listViewWidget);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cypressworks/mensaplan/MensaWidgetService.java:
--------------------------------------------------------------------------------
1 | package com.cypressworks.mensaplan;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.graphics.Color;
7 | import android.preference.PreferenceManager;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.RemoteViews;
11 | import android.widget.RemoteViewsService;
12 |
13 | import com.cypressworks.mensaplan.food.Line;
14 | import com.cypressworks.mensaplan.food.Meal;
15 | import com.cypressworks.mensaplan.food.Plan;
16 | import com.cypressworks.mensaplan.food.likes.LikeManager;
17 | import com.cypressworks.mensaplan.food.likes.LikeStatus;
18 | import com.cypressworks.mensaplan.planmanager.MensaDropdownAdapter;
19 | import com.cypressworks.mensaplan.planmanager.PlanManager;
20 | import com.cypressworks.mensaplan.util.StringUtils;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Calendar;
24 | import java.util.Collections;
25 | import java.util.List;
26 |
27 | import androidx.core.content.ContextCompat;
28 |
29 | /**
30 | * @author Kirill Rakhman
31 | */
32 | public class MensaWidgetService extends RemoteViewsService {
33 |
34 | @Override
35 | public RemoteViewsFactory onGetViewFactory(final Intent intent) {
36 | return new MensaRemoteViewsFactory(getApplicationContext());
37 | }
38 |
39 | static class MensaRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
40 | private final Context c;
41 | private List