Skip to content

Commit 353fdd4

Browse files
authored
Merge pull request #15 from Get-Siempo/SSA-2022_2
Ssa 2022 2
2 parents 3f887ed + b9c320a commit 353fdd4

17 files changed

+1065
-9
lines changed

MiniumApps/launcher3/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<uses-feature android:name="android.hardware.location.network" />
7878

7979
<uses-permission android:name="android.permission.USES_POLICY_FORCE_LOCK" />
80+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
8081

8182
<application
8283
android:name=".app.Launcher3App_"
@@ -191,6 +192,11 @@
191192
android:exported="true"
192193
android:label="@string/app_name" />
193194

195+
<service
196+
android:name=".service.ScreenFilterService"
197+
android:enabled="true" >
198+
</service>
199+
194200
<receiver android:name=".receivers.BootReceiver">
195201
<intent-filter>
196202
<action android:name="android.intent.action.BOOT_COMPLETED" />

MiniumApps/launcher3/src/main/java/co/siempo/phone/activities/DashboardActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import co.siempo.phone.service.LoadJunkFoodPane;
7373
import co.siempo.phone.service.LoadToolPane;
7474
import co.siempo.phone.service.MailChimpOperation;
75+
import co.siempo.phone.service.ScreenFilterService;
7576
import co.siempo.phone.service.SiempoNotificationListener_;
7677
import co.siempo.phone.service.StatusBarService;
7778
import co.siempo.phone.ui.SiempoViewPager;
@@ -256,6 +257,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
256257
}
257258

258259
getColorList();
260+
261+
if(PrefSiempo.getInstance(DashboardActivity.this).read(PrefSiempo.DEFAULT_SCREEN_OVERLAY, false)) {
262+
Intent command = new Intent(DashboardActivity.this, ScreenFilterService.class);
263+
command.putExtra(ScreenFilterService.BUNDLE_KEY_COMMAND, 0);
264+
startService(command);
265+
}
259266
}
260267

261268
private void getColorList()

MiniumApps/launcher3/src/main/java/co/siempo/phone/fragments/TempoHomeFragment.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333

3434
import co.siempo.phone.R;
3535
import co.siempo.phone.activities.ChooseBackgroundActivity;
36+
import co.siempo.phone.activities.DashboardActivity;
3637
import co.siempo.phone.activities.UpdateBackgroundActivity;
3738
import co.siempo.phone.app.CoreApplication;
3839
import co.siempo.phone.event.NotifyBackgroundChange;
3940
import co.siempo.phone.event.NotifyBackgroundToService;
4041
import co.siempo.phone.event.ThemeChangeEvent;
4142
import co.siempo.phone.helper.FirebaseHelper;
43+
import co.siempo.phone.service.ScreenFilterService;
4244
import co.siempo.phone.util.AppUtils;
4345
import co.siempo.phone.utils.PermissionUtil;
4446
import co.siempo.phone.utils.PrefSiempo;
@@ -80,6 +82,11 @@ public class TempoHomeFragment extends CoreFragment {
8082
@ViewById
8183
RelativeLayout relDarkTheme;
8284

85+
86+
@ViewById
87+
Switch switchScreenOverlay;
88+
89+
8390
private PermissionUtil permissionUtil;
8491

8592
public TempoHomeFragment() {
@@ -229,6 +236,27 @@ public void onClick(View v)
229236
AppUtils.notificationBarManaged(getActivity(), null);
230237
}
231238
});
239+
240+
switchScreenOverlay.setChecked(PrefSiempo.getInstance(getActivity()).read(PrefSiempo.DEFAULT_SCREEN_OVERLAY, false));
241+
switchScreenOverlay.setOnClickListener(new View.OnClickListener() {
242+
@Override
243+
public void onClick(View view) {
244+
245+
Switch sb = (Switch) view;
246+
if(sb.isChecked())
247+
{
248+
checkPermissionsForSystemWindow();
249+
250+
}else
251+
{
252+
PrefSiempo.getInstance(getActivity()).write(PrefSiempo.DEFAULT_SCREEN_OVERLAY, false);
253+
Intent command = new Intent(getActivity(), ScreenFilterService.class);
254+
command.putExtra(ScreenFilterService.BUNDLE_KEY_COMMAND, 1);
255+
getActivity().startService(command);
256+
}
257+
258+
}
259+
});
232260
}
233261

234262
private void notificationVisibility() {
@@ -298,6 +326,41 @@ public void onPermissionDenied(ArrayList<String> deniedPermissions) {
298326
}
299327
}
300328

329+
330+
private void checkPermissionsForSystemWindow() {
331+
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !permissionUtil.hasGiven
332+
(PermissionUtil.SYSTEM_WINDOW_ALERT))) {
333+
try {
334+
TedPermission.with(getActivity())
335+
.setPermissionListener(new PermissionListener() {
336+
@Override
337+
public void onPermissionGranted() {
338+
PrefSiempo.getInstance(getActivity()).write(PrefSiempo.DEFAULT_SCREEN_OVERLAY, true);
339+
Intent command = new Intent(getActivity(), ScreenFilterService.class);
340+
command.putExtra(ScreenFilterService.BUNDLE_KEY_COMMAND, 0);
341+
getActivity().startService(command);
342+
}
343+
344+
@Override
345+
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
346+
347+
}
348+
})
349+
.setDeniedMessage(R.string.msg_permission_denied)
350+
.setPermissions(new String[]{
351+
Manifest.permission.SYSTEM_ALERT_WINDOW})
352+
.check();
353+
} catch (Exception e) {
354+
e.printStackTrace();
355+
}
356+
} else {
357+
PrefSiempo.getInstance(getActivity()).write(PrefSiempo.DEFAULT_SCREEN_OVERLAY, true);
358+
Intent command = new Intent(getActivity(), ScreenFilterService.class);
359+
command.putExtra(ScreenFilterService.BUNDLE_KEY_COMMAND, 0);
360+
getActivity().startService(command);
361+
}
362+
}
363+
301364
@Override
302365
public void onResume() {
303366
super.onResume();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package co.siempo.phone.receivers;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.content.res.Configuration;
7+
import android.content.res.Resources;
8+
9+
public class OrientationChangeReceiver extends BroadcastReceiver {
10+
11+
private Context mContext;
12+
private OnOrientationChangeListener mListener;
13+
14+
public OrientationChangeReceiver(Context context,
15+
OnOrientationChangeListener listener) {
16+
mContext = context;
17+
mListener = listener;
18+
}
19+
20+
@Override
21+
public void onReceive(Context context, Intent intent) {
22+
if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
23+
Resources r = mContext.getResources();
24+
if(r.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
25+
mListener.onPortraitOrientation();
26+
}
27+
else {
28+
mListener.onLandscapeOrientation();
29+
}
30+
}
31+
}
32+
33+
public interface OnOrientationChangeListener {
34+
void onPortraitOrientation();
35+
void onLandscapeOrientation();
36+
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package co.siempo.phone.screenfilter;
2+
3+
import android.animation.Animator;
4+
5+
public abstract class AbstractAnimatorListener implements Animator.AnimatorListener {
6+
@Override
7+
public void onAnimationStart(Animator animator) {}
8+
9+
@Override
10+
public void onAnimationEnd(Animator animator) {}
11+
12+
@Override
13+
public void onAnimationCancel(Animator animator) {}
14+
15+
@Override
16+
public void onAnimationRepeat(Animator animator) {}
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package co.siempo.phone.screenfilter;
2+
3+
4+
import android.content.Context;
5+
import android.content.Intent;
6+
7+
import co.siempo.phone.service.ScreenFilterService;
8+
9+
public class FilterCommandFactory {
10+
11+
private Context mContext;
12+
13+
public FilterCommandFactory(Context context) {
14+
mContext = context;
15+
}
16+
17+
/**
18+
*
19+
* @param screenFilterServiceCommand one of {@link ScreenFilterService#COMMAND_OFF},
20+
* {@link ScreenFilterService#COMMAND_ON}, or {@link ScreenFilterService#COMMAND_PAUSE}.
21+
* @return an Intent containing a command that can be sent to {@link ScreenFilterService} via
22+
* {@link FilterCommandSender#send(Intent)}; null if
23+
* {@code screenFilterServiceCommand} is invalid.
24+
*/
25+
public Intent createCommand(int screenFilterServiceCommand) {
26+
Intent command;
27+
28+
if (screenFilterServiceCommand < ScreenFilterService.VALID_COMMAND_START ||
29+
screenFilterServiceCommand > ScreenFilterService.VALID_COMMAND_END) {
30+
command = null;
31+
} else {
32+
command = new Intent(mContext, ScreenFilterService.class);
33+
command.putExtra(ScreenFilterService.BUNDLE_KEY_COMMAND, screenFilterServiceCommand);
34+
}
35+
36+
return command;
37+
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package co.siempo.phone.screenfilter;
2+
3+
import android.content.Intent;
4+
5+
import co.siempo.phone.service.ScreenFilterService;
6+
7+
public class FilterCommandParser {
8+
9+
/**
10+
* Retrieves the command in an intent sent to {@link ScreenFilterService}.
11+
*
12+
* @param intent that was constructed by {@link FilterCommandFactory}.
13+
* @return one of {@link ScreenFilterService#COMMAND_OFF}, {@link ScreenFilterService#COMMAND_ON},
14+
* {@link ScreenFilterService#COMMAND_PAUSE}, or -1 if {@code intent} doesn't contain a
15+
* valid command.
16+
*/
17+
public int parseCommandFlag(Intent intent) {
18+
int errorCode = -1;
19+
20+
if (intent == null) {
21+
return errorCode;
22+
}
23+
24+
int commandFlag = intent.getIntExtra(ScreenFilterService.BUNDLE_KEY_COMMAND, errorCode);
25+
return commandFlag;
26+
}
27+
}

0 commit comments

Comments
 (0)