Skip to content

Commit

Permalink
Merge pull request #30 from CarlosACepeda/Laboratory
Browse files Browse the repository at this point in the history
Version 0.8.0
  • Loading branch information
CarlosACepeda authored Apr 21, 2019
2 parents 2fb387e + 29f7766 commit c0e65f7
Show file tree
Hide file tree
Showing 27 changed files with 565 additions and 326 deletions.
71 changes: 43 additions & 28 deletions LiveDisplay/Activities/LockScreenActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class LockScreenActivity : Activity
{
private RecyclerView recycler;
private RecyclerView.LayoutManager layoutManager;
private ImageView wallpaper;
private ImageView wallpaperView;
private ImageView unlocker;
private Button clearAll;
private FrameLayout weatherandclockcontainer;
Expand All @@ -47,7 +47,6 @@ public class LockScreenActivity : Activity
private readonly float threshold = 1000; //1 second of threshold.(used to implement the double tap.)
private System.Timers.Timer watchDog; //the watchdog simply will start counting down until it gets resetted by OnUserInteraction() override.
private Animation fadeoutanimation;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Expand All @@ -71,7 +70,7 @@ protected override void OnCreate(Bundle savedInstanceState)
});

//Views
wallpaper = FindViewById<ImageView>(Resource.Id.wallpaper);
wallpaperView = FindViewById<ImageView>(Resource.Id.wallpaper);
unlocker = FindViewById<ImageView>(Resource.Id.unlocker);
startCamera = FindViewById<Button>(Resource.Id.btnStartCamera);
startDialer = FindViewById<Button>(Resource.Id.btnStartPhone);
Expand Down Expand Up @@ -102,7 +101,6 @@ protected override void OnCreate(Bundle savedInstanceState)
//CatcherHelper events
CatcherHelper.NotificationListSizeChanged += CatcherHelper_NotificationListSizeChanged;

//Load RecyclerView

using (recycler = FindViewById<RecyclerView>(Resource.Id.NotificationListRecyclerView))
{
Expand All @@ -117,7 +115,6 @@ protected override void OnCreate(Bundle savedInstanceState)

LoadNotificationFragment();

//Load User Configs.
LoadConfiguration();

CheckNotificationListSize();
Expand All @@ -126,7 +123,7 @@ protected override void OnCreate(Bundle savedInstanceState)
private void Fadeoutanimation_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
var fadeinanimation = AnimationUtils.LoadAnimation(Application.Context, Resource.Animation.abc_fade_in);
wallpaper.StartAnimation(fadeinanimation);
wallpaperView.StartAnimation(fadeinanimation);
}

private void WatchdogInterval_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
Expand Down Expand Up @@ -171,37 +168,51 @@ private void Weatherandclockcontainer_LongClick(object sender, View.LongClickEve

private void Wallpaper_NewWallpaperIssued(object sender, WallpaperChangedEventArgs e)
{
bool defaultwallpaperchanged = false;
Drawable userwallpaper = null;
if (!defaultwallpaperchanged)
{
userwallpaper = wallpaperView.Background;
}
if (e.SecondsOfAttention != 0)
{
//ThreadPool.QueueUserWorkItem(m => wallpaper.StartAnimation(fadeoutanimation));
ThreadPool.QueueUserWorkItem(method =>
{
RunOnUiThread(() =>
{
wallpaperView.StartAnimation(fadeoutanimation);
wallpaperView.Background = e.Wallpaper;
wallpaperView.Background.Alpha = e.OpacityLevel;
defaultwallpaperchanged = true;
});
Thread.Sleep(e.SecondsOfAttention * 1000);
if (wallpaperView != null)
{
if (defaultwallpaperchanged)
RunOnUiThread(() => { wallpaperView.Background = userwallpaper; defaultwallpaperchanged = false; });

////Grab the previous wallpaper so after the time has passed I can set the previous wallpaper.
//var previousWallpaper = wallpaper.Background;
//wallpaper.Background = e.Wallpaper;
//ThreadPool.QueueUserWorkItem(method =>
//{
// Thread.Sleep(e.SecondsOfAttention * 1000);
// if (wallpaper != null)
// {
// RunOnUiThread(() => wallpaper.Background = previousWallpaper);
// }
//}
//);
}
else
{
wallpaperView.Background= userwallpaper;
}
}
);
}
else
{
RunOnUiThread(() =>
{
wallpaper.StartAnimation(fadeoutanimation);
wallpaperView.StartAnimation(fadeoutanimation);

if (e.Wallpaper == null)
{
wallpaper.SetBackgroundColor(Color.Black);
wallpaperView.SetBackgroundColor(Color.Black);
}
else
{
wallpaper.Background = e.Wallpaper;
wallpaper.Background.Alpha = e.OpacityLevel;
wallpaperView.Background = e.Wallpaper;
wallpaperView.Background.Alpha = e.OpacityLevel;
}
});
}
Expand Down Expand Up @@ -283,16 +294,16 @@ protected override void OnDestroy()
unlocker.Dispose();
clearAll.Dispose();
lockscreen.Dispose();
wallpaper.Background.Dispose();
wallpaper.Dispose();
wallpaperView.Background.Dispose();
wallpaperView = null;

//Dispose Fragments
notificationFragment.Dispose();
musicFragment.Dispose();
clockFragment.Dispose();
weatherFragment.Dispose();

StopFloatingNotificationService();
//StopFloatingNotificationService();
}

public override void OnBackPressed()
Expand Down Expand Up @@ -348,6 +359,11 @@ private void BtnClearAll_Click(object sender, EventArgs e)

private void Unlocker_Touch(object sender, View.TouchEventArgs e)
{
//Log.Info("LiveDisplay", "Y pos:" + lockscreen.GetY());
//lockscreen.SetY(lockscreen.GetY()-25);

//lockscreen.SetY(lockscreen.GetY() - e.Event.RawY);

float startPoint = 0;
float finalPoint = 0;
if (e.Event.Action == MotionEventActions.Down)
Expand Down Expand Up @@ -442,7 +458,7 @@ private void LoadConfiguration()
}
int interval = int.Parse(configurationManager.RetrieveAValue(ConfigurationParameters.TurnOffScreenDelayTime, "5000"));
watchDog.Interval = interval;
if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnUserMovement) == true)
if (configurationManager.RetrieveAValue(ConfigurationParameters.EnableAwakeService) == true)
{
StartAwakeService();
}
Expand Down Expand Up @@ -482,7 +498,6 @@ private void AddFlags()
newUiOptions |= (int)SystemUiFlags.Immersive;
// This option will make bars disappear by themselves
newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;

view.SystemUiVisibility = (StatusBarVisibility)newUiOptions;
Window.AddFlags(WindowManagerFlags.DismissKeyguard);
Window.AddFlags(WindowManagerFlags.ShowWhenLocked);
Expand Down
1 change: 1 addition & 0 deletions LiveDisplay/Activities/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public override bool OnOptionsItemSelected(IMenuItem item)
return true;

case Resource.Id.action_sendtestnotification:

if (isApplicationHealthy)
{
using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance())
Expand Down
20 changes: 17 additions & 3 deletions LiveDisplay/Adapters/AppsToBeBlacklistedAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void App_Click(AppClickedEventArgs e)
using (Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(textView.Context))
{
builder.SetTitle(textView.Text);
builder.SetMultiChoiceItems(new string[] { textView.Context.GetString(Resource.String.blacklisted), textView.Context.GetString(Resource.String.nonallowedtoturnonscreen) }, GetLevelOfBlocking(currentSelectedAppPackage), DialogMultichoiceClick);
builder.SetMultiChoiceItems(new string[] { textView.Context.GetString(Resource.String.blacklisted), textView.Context.GetString(Resource.String.partiallyblocked), textView.Context.GetString(Resource.String.nonallowedtoturnonscreen) }, GetLevelOfBlocking(currentSelectedAppPackage), DialogMultichoiceClick);
builder.SetPositiveButton("Ok", OnDialogPositiveButtonEventArgs);

builder.Create();
Expand All @@ -70,21 +70,31 @@ private void DialogMultichoiceClick(object sender, DialogMultiChoiceClickEventAr

break;

case 1: //1 is 'Non allowed to turn on screen'
case 1: //1 is 'Only blocked in the app'
if (e.IsChecked)
levels |= LevelsOfAppBlocking.BlockInAppOnly;
else
{
levels &= ~LevelsOfAppBlocking.BlockInAppOnly;
}
break;
case 2: //2 is Totally Blocked
if (e.IsChecked)
levels |= LevelsOfAppBlocking.NonAllowedToTurnScreenOn;
else
{
levels &= ~LevelsOfAppBlocking.NonAllowedToTurnScreenOn;
}
break;

}
}

private bool[] GetLevelOfBlocking(string forWhichApp)
{
bool blacklisted = false;
bool nonallowedtoturnscreenon = false;
bool onlyremovesystem= false;
using (ConfigurationManager configurationManager = new ConfigurationManager(PreferenceManager.GetDefaultSharedPreferences(Application.Context)))
{
var flag = configurationManager.RetrieveAValue(forWhichApp, 0);
Expand All @@ -102,8 +112,12 @@ private bool[] GetLevelOfBlocking(string forWhichApp)
case LevelsOfAppBlocking.NonAllowedToTurnScreenOn:
nonallowedtoturnscreenon = true;
break;
case LevelsOfAppBlocking.BlockInAppOnly:
onlyremovesystem = true;
break;

case LevelsOfAppBlocking.TotallyBlocked:
onlyremovesystem = true;
blacklisted = true;
nonallowedtoturnscreenon = true;
break;
Expand All @@ -112,7 +126,7 @@ private bool[] GetLevelOfBlocking(string forWhichApp)
break;
}
}
return new bool[2] { blacklisted, nonallowedtoturnscreenon };
return new bool[3] { blacklisted, onlyremovesystem, nonallowedtoturnscreenon };
}

private void OnDialogPositiveButtonEventArgs(object sender, DialogClickEventArgs e)
Expand Down
71 changes: 57 additions & 14 deletions LiveDisplay/Fragments/NotificationFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using LiveDisplay.Servicios;
using LiveDisplay.Servicios.Notificaciones;
using LiveDisplay.Servicios.Notificaciones.NotificationEventArgs;
using LiveDisplay.Servicios.Notificaciones.NotificationStyle;
using LiveDisplay.Servicios.Wallpaper;
using System;
using System.Threading;
Expand All @@ -26,6 +27,7 @@ public class NotificationFragment : Fragment
private TextView appName;
private TextView when;
private LinearLayout notification;
private ImageButton closenotificationbutton;
private bool timeoutStarted = false;

#region Lifecycle events
Expand All @@ -46,10 +48,11 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
when = v.FindViewById<TextView>(Resource.Id.tvWhen);
appName = v.FindViewById<TextView>(Resource.Id.tvAppName);
notification = v.FindViewById<LinearLayout>(Resource.Id.llNotification);

closenotificationbutton = v.FindViewById<ImageButton>(Resource.Id.closenotificationbutton);
//Subscribe to events raised by several types.
notification.Drag += Notification_Drag;
notification.Click += LlNotification_Click;
closenotificationbutton.Click += Closenotificationbutton_Click;
NotificationAdapterViewHolder.ItemClicked += ItemClicked;
NotificationAdapterViewHolder.ItemLongClicked += ItemLongClicked;
CatcherHelper.NotificationPosted += CatcherHelper_NotificationPosted;
Expand All @@ -58,6 +61,35 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
return v;
}

private void Closenotificationbutton_Click(object sender, EventArgs e)
{
using (OpenNotification openNotification = new OpenNotification(position))
{
if (openNotification.IsRemovable())
{
using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance())
{
if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
{
int notiId = CatcherHelper.statusBarNotifications[position].Id;
string notiTag = CatcherHelper.statusBarNotifications[position].Tag;
string notiPack = CatcherHelper.statusBarNotifications[position].PackageName;
slave.CancelNotification(notiPack, notiTag, notiId);
}
else
{
slave.CancelNotification(CatcherHelper.statusBarNotifications[position].Key);
}
}
notification.Visibility = ViewStates.Invisible;
titulo.Text = null;
texto.Text = null;
notificationActions.RemoveAllViews();
}
}

}

private void Notification_Drag(object sender, View.DragEventArgs e)
{
StartTimeout(); //To keep the notification visible while the user touches the notification fragment
Expand All @@ -78,6 +110,12 @@ public override void OnDestroy()
CatcherHelper.NotificationUpdated -= CatcherHelper_NotificationUpdated;
CatcherHelper.NotificationRemoved -= CatcherHelper_NotificationRemoved;
CatcherHelper.NotificationPosted -= CatcherHelper_NotificationPosted;
notificationActions.Dispose();
texto.Dispose();
titulo.Dispose();
when.Dispose();
appName.Dispose();
closenotificationbutton.Dispose();
base.OnDestroy();
}

Expand Down Expand Up @@ -105,7 +143,7 @@ private void LlNotification_Click(object sender, EventArgs e)
Activity.RunOnUiThread(() =>
openNotification.ClickNotification()
);
if (OpenNotification.NotificationIsAutoCancel(position) == true)
if (OpenNotification.IsAutoCancellable(position) == true)
{
notification.Visibility = ViewStates.Invisible;
titulo.Text = null;
Expand Down Expand Up @@ -158,18 +196,14 @@ private void ItemClicked(object sender, NotificationItemClickedEventArgs e)
position = e.Position;
using (OpenNotification openNotification = new OpenNotification(e.Position))
{
ThreadPool.QueueUserWorkItem(method =>
{
var notificationBigPicture = new BitmapDrawable(Resources, openNotification.GetBigPicture());
WallpaperPublisher.ChangeWallpaper(new WallpaperChangedEventArgs { Wallpaper = notificationBigPicture, OpacityLevel = 125, SecondsOfAttention = 5 });
});
titulo.Text = openNotification.GetTitle();
texto.Text = openNotification.GetText();
appName.Text = openNotification.GetAppName();
when.Text = openNotification.GetWhen();
titulo.Text = openNotification.Title();
texto.Text = openNotification.Text();
appName.Text = openNotification.AppName();
when.Text = openNotification.When();
notificationActions.RemoveAllViews();

if (openNotification.NotificationHasActionButtons() == true)
//using (NotificationStyleApplier styleApplier = new NotificationStyleApplier(null, openNotification))
// styleApplier.ApplyStyle(openNotification.Style());
if (openNotification.HasActionButtons() == true)
{
var actions = openNotification.RetrieveActions();
foreach (var a in actions)
Expand Down Expand Up @@ -198,6 +232,14 @@ private void ItemClicked(object sender, NotificationItemClickedEventArgs e)
notificationActions.AddView(anActionButton);
};
}
if (openNotification.IsRemovable())
{
closenotificationbutton.Visibility = ViewStates.Visible;
}
else
{
closenotificationbutton.Visibility = ViewStates.Invisible;
}
}
if (notification.Visibility != ViewStates.Visible)
{
Expand All @@ -215,7 +257,7 @@ private void StartTimeout()
{
//This action is: 'Hide the notification, and set the timeoutStarted as finished(false)
//because this action will be invoked only when the timeout has finished.
Action hideNotification = () => { notification.Visibility = ViewStates.Gone; timeoutStarted = false; };
Action hideNotification = () => { if (notification != null) notification.Visibility = ViewStates.Gone; timeoutStarted = false; };
//If the timeout has started, then cancel the action, and start again.
if (timeoutStarted == true)
{
Expand All @@ -231,4 +273,5 @@ private void StartTimeout()
}
}
}

}
Loading

0 comments on commit c0e65f7

Please sign in to comment.