add openhack files
This commit is contained in:
@ -0,0 +1,101 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Android.OS;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Support.V7.Widget;
|
||||
using MyDriving.Droid.Helpers;
|
||||
using Plugin.Permissions;
|
||||
using Android.Content.PM;
|
||||
using Android.Transitions;
|
||||
|
||||
namespace MyDriving.Droid
|
||||
{
|
||||
public abstract class BaseActivity : AppCompatActivity, IAccelerometerListener
|
||||
{
|
||||
AccelerometerManager accelerometerManager;
|
||||
bool canShowFeedback;
|
||||
public Toolbar Toolbar { get; set; }
|
||||
protected abstract int LayoutResource { get; }
|
||||
|
||||
protected int ActionBarIcon
|
||||
{
|
||||
set { Toolbar.SetNavigationIcon(value); }
|
||||
}
|
||||
|
||||
public void OnAccelerationChanged(float x, float y, float z)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnShake(float force)
|
||||
{
|
||||
if (!canShowFeedback)
|
||||
return;
|
||||
canShowFeedback = false;
|
||||
HockeyApp.FeedbackManager.ShowFeedbackActivity(this);
|
||||
}
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
InitActivityTransitions();
|
||||
base.OnCreate(bundle);
|
||||
SetContentView(LayoutResource);
|
||||
Toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
|
||||
if (Toolbar != null)
|
||||
{
|
||||
SetSupportActionBar(Toolbar);
|
||||
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
|
||||
SupportActionBar.SetHomeButtonEnabled(true);
|
||||
}
|
||||
|
||||
accelerometerManager = new AccelerometerManager(this, this);
|
||||
accelerometerManager.Configure(40, 350);
|
||||
}
|
||||
|
||||
|
||||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
|
||||
{
|
||||
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnResume()
|
||||
{
|
||||
base.OnResume();
|
||||
canShowFeedback = true;
|
||||
if (accelerometerManager.IsSupported)
|
||||
accelerometerManager.StartListening();
|
||||
}
|
||||
|
||||
void InitActivityTransitions()
|
||||
{
|
||||
if ((int) Build.VERSION.SdkInt >= 21)
|
||||
{
|
||||
var transition = new Slide();
|
||||
transition.ExcludeTarget(Android.Resource.Id.StatusBarBackground, true);
|
||||
Window.EnterTransition = transition;
|
||||
Window.ReturnTransition = transition;
|
||||
Window.RequestFeature(Android.Views.WindowFeatures.ContentTransitions);
|
||||
Window.RequestFeature(Android.Views.WindowFeatures.ActivityTransitions);
|
||||
Window.SharedElementEnterTransition = new ChangeBounds();
|
||||
Window.SharedElementReturnTransition = new ChangeBounds();
|
||||
Window.AllowEnterTransitionOverlap = true;
|
||||
Window.AllowReturnTransitionOverlap = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
base.OnStop();
|
||||
if (accelerometerManager.IsListening)
|
||||
accelerometerManager.StopListening();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
if (accelerometerManager.IsListening)
|
||||
accelerometerManager.StopListening();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using Android.Support.V4.App;
|
||||
using Android.Support.V4.View;
|
||||
using Android.Views;
|
||||
using MyDriving.Droid.Fragments;
|
||||
using Android.Graphics;
|
||||
using Android.Support.V4.Content;
|
||||
|
||||
namespace MyDriving.Droid.Activities
|
||||
{
|
||||
[Activity(Label = "Getting Started", Icon = "@drawable/ic_launcher",
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
|
||||
ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
public class GettingStartedActivity : BaseActivity
|
||||
{
|
||||
TabAdapter adapter;
|
||||
|
||||
ViewPager pager;
|
||||
protected override int LayoutResource => Resource.Layout.activity_getting_started;
|
||||
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
if ((int) Build.VERSION.SdkInt >= 21)
|
||||
{
|
||||
Window.SetStatusBarColor(new Color(ContextCompat.GetColor(this, Resource.Color.primary_dark)));
|
||||
Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
|
||||
}
|
||||
|
||||
adapter = new TabAdapter(this, SupportFragmentManager);
|
||||
pager = FindViewById<ViewPager>(Resource.Id.pager);
|
||||
pager.Adapter = adapter;
|
||||
pager.OffscreenPageLimit = 3;
|
||||
|
||||
SupportActionBar.Title = "Getting Started (1/5)";
|
||||
pager.PageSelected += (sender, e) => { SupportActionBar.Title = $"Getting Started ({e.Position + 1}/5)"; };
|
||||
|
||||
SupportActionBar?.SetDisplayHomeAsUpEnabled(false);
|
||||
SupportActionBar?.SetDisplayShowHomeEnabled(false);
|
||||
// Create your application here
|
||||
}
|
||||
|
||||
public override void OnBackPressed()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class TabAdapter : FragmentStatePagerAdapter
|
||||
{
|
||||
public TabAdapter(Context context, Android.Support.V4.App.FragmentManager fm) : base(fm)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Count => 5;
|
||||
|
||||
public override Java.Lang.ICharSequence GetPageTitleFormatted(int position)
|
||||
=> new Java.Lang.String(string.Empty);
|
||||
|
||||
|
||||
public override Android.Support.V4.App.Fragment GetItem(int position)
|
||||
{
|
||||
switch (position)
|
||||
{
|
||||
case 0:
|
||||
return FragmentGettingStarted1.NewInstance();
|
||||
case 1:
|
||||
return FragmentGettingStarted2.NewInstance();
|
||||
case 2:
|
||||
return FragmentGettingStarted3.NewInstance();
|
||||
case 3:
|
||||
return FragmentGettingStarted4.NewInstance();
|
||||
case 4:
|
||||
return FragmentGettingStarted5.NewInstance();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override int GetItemPosition(Java.Lang.Object frag) => PositionNone;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Content.PM;
|
||||
using MyDriving.ViewModel;
|
||||
using MyDriving.Utils;
|
||||
using Android.Support.V4.Content;
|
||||
using Android.Graphics;
|
||||
|
||||
namespace MyDriving.Droid.Activities
|
||||
{
|
||||
[Activity(Label = "Login", Theme = "@style/MyThemeDark",
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
|
||||
ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
public class LoginActivity : BaseActivity
|
||||
{
|
||||
LoginViewModel viewModel;
|
||||
|
||||
protected override int LayoutResource => Resource.Layout.activity_login;
|
||||
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
if ((int) Build.VERSION.SdkInt >= 21)
|
||||
{
|
||||
Window.SetStatusBarColor(new Color(ContextCompat.GetColor(this, Resource.Color.primary_dark)));
|
||||
Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
|
||||
}
|
||||
|
||||
viewModel = new LoginViewModel();
|
||||
viewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
var twitter = FindViewById<Button>(Resource.Id.button_twitter);
|
||||
var microsoft = FindViewById<Button>(Resource.Id.button_microsoft);
|
||||
var facebook = FindViewById<Button>(Resource.Id.button_facebook);
|
||||
|
||||
twitter.Click += (sender, e) => Login(LoginAccount.Twitter);
|
||||
microsoft.Click += (sender, e) => Login(LoginAccount.Microsoft);
|
||||
facebook.Click += (sender, e) => Login(LoginAccount.Facebook);
|
||||
|
||||
FindViewById<Button>(Resource.Id.button_skip).Click += (sender, e) =>
|
||||
{
|
||||
viewModel.InitFakeUser();
|
||||
var intent = new Intent(this, typeof(MainActivity));
|
||||
intent.AddFlags(ActivityFlags.ClearTop);
|
||||
StartActivity(intent);
|
||||
Finish();
|
||||
};
|
||||
|
||||
#if XTC || DEBUG
|
||||
#else
|
||||
FindViewById<Button>(Resource.Id.button_skip).Visibility = ViewStates.Gone;
|
||||
#endif
|
||||
var typeface = Typeface.CreateFromAsset(Assets, "fonts/Corbert-Regular.otf");
|
||||
FindViewById<TextView>(Resource.Id.text_app_name).Typeface = typeface;
|
||||
}
|
||||
|
||||
void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (!viewModel.IsLoggedIn)
|
||||
return;
|
||||
|
||||
//When the first screen of the app is launched after user has logged in, initialize the processor that manages connection to OBD Device and to the IOT Hub
|
||||
MyDriving.Services.OBDDataProcessor.GetProcessor().Initialize(ViewModel.ViewModelBase.StoreManager);
|
||||
|
||||
var intent = new Intent(this, typeof (MainActivity));
|
||||
intent.AddFlags(ActivityFlags.ClearTop);
|
||||
StartActivity(intent);
|
||||
Finish();
|
||||
}
|
||||
|
||||
|
||||
void Login(LoginAccount account)
|
||||
{
|
||||
switch (account)
|
||||
{
|
||||
case LoginAccount.Facebook:
|
||||
viewModel.LoginFacebookCommand.Execute(null);
|
||||
break;
|
||||
case LoginAccount.Microsoft:
|
||||
viewModel.LoginMicrosoftCommand.Execute(null);
|
||||
break;
|
||||
case LoginAccount.Twitter:
|
||||
viewModel.LoginTwitterCommand.Execute(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using Android.Support.V4.Widget;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using MyDriving.Droid.Fragments;
|
||||
using Android.Support.V4.View;
|
||||
using Android.Support.Design.Widget;
|
||||
using MyDriving.Utils;
|
||||
using Android.Runtime;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using HockeyApp;
|
||||
|
||||
|
||||
namespace MyDriving.Droid
|
||||
{
|
||||
[Activity(Label = "MyDriving", Icon = "@drawable/ic_launcher",
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
|
||||
ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
public class MainActivity : BaseActivity
|
||||
{
|
||||
DrawerLayout drawerLayout;
|
||||
NavigationView navigationView;
|
||||
|
||||
int oldPosition = -1;
|
||||
|
||||
bool shouldClose;
|
||||
|
||||
protected override int LayoutResource => Resource.Layout.activity_main;
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
base.OnCreate(bundle);
|
||||
|
||||
#if !XTC
|
||||
InitializeHockeyApp();
|
||||
#endif
|
||||
drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
|
||||
|
||||
//Set hamburger items menu
|
||||
SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu);
|
||||
|
||||
//setup navigation view
|
||||
navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
|
||||
|
||||
//handle navigation
|
||||
navigationView.NavigationItemSelected += (sender, e) =>
|
||||
{
|
||||
e.MenuItem.SetChecked(true);
|
||||
|
||||
ListItemClicked(e.MenuItem.ItemId);
|
||||
|
||||
|
||||
SupportActionBar.Title = e.MenuItem.ItemId == Resource.Id.menu_profile
|
||||
? Settings.Current.UserFirstName
|
||||
: e.MenuItem.TitleFormatted.ToString();
|
||||
|
||||
drawerLayout.CloseDrawers();
|
||||
};
|
||||
|
||||
if (Intent.GetBooleanExtra("tracking", false))
|
||||
{
|
||||
ListItemClicked(Resource.Id.menu_current_trip);
|
||||
SupportActionBar.Title = "Current Trip";
|
||||
return;
|
||||
}
|
||||
|
||||
//if first time you will want to go ahead and click first item.
|
||||
if (bundle == null)
|
||||
{
|
||||
ListItemClicked(Resource.Id.menu_current_trip);
|
||||
SupportActionBar.Title = "Current Trip";
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeHockeyApp()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Logger.HockeyAppAndroid))
|
||||
return;
|
||||
|
||||
HockeyApp.CrashManager.Register(this, Logger.HockeyAppAndroid);
|
||||
HockeyApp.Metrics.MetricsManager.Register(this, Application, Logger.HockeyAppAndroid);
|
||||
HockeyApp.Metrics.MetricsManager.EnableUserMetrics();
|
||||
|
||||
CheckForUpdates();
|
||||
|
||||
}
|
||||
|
||||
void CheckForUpdates()
|
||||
{
|
||||
// Remove this for store builds!
|
||||
UpdateManager.Register(this, Logger.HockeyAppAndroid);
|
||||
}
|
||||
|
||||
void UnregisterManagers()
|
||||
{
|
||||
UpdateManager.Unregister();
|
||||
}
|
||||
|
||||
protected override void OnPause()
|
||||
{
|
||||
base.OnPause();
|
||||
|
||||
UnregisterManagers();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
UnregisterManagers();
|
||||
}
|
||||
|
||||
|
||||
void ListItemClicked(int itemId)
|
||||
{
|
||||
//this way we don't load twice, but you might want to modify this a bit.
|
||||
if (itemId == oldPosition)
|
||||
return;
|
||||
shouldClose = false;
|
||||
oldPosition = itemId;
|
||||
|
||||
Android.Support.V4.App.Fragment fragment = null;
|
||||
switch (itemId)
|
||||
{
|
||||
case Resource.Id.menu_past_trips:
|
||||
fragment = FragmentPastTrips.NewInstance();
|
||||
break;
|
||||
case Resource.Id.menu_current_trip:
|
||||
fragment = FragmentCurrentTrip.NewInstance();
|
||||
break;
|
||||
case Resource.Id.menu_profile:
|
||||
fragment = FragmentProfile.NewInstance();
|
||||
break;
|
||||
case Resource.Id.menu_settings:
|
||||
fragment = FragmentSettings.NewInstance();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
SupportFragmentManager.BeginTransaction()
|
||||
.Replace(Resource.Id.content_frame, fragment)
|
||||
.Commit();
|
||||
|
||||
navigationView.SetCheckedItem(itemId);
|
||||
}
|
||||
|
||||
public override bool OnOptionsItemSelected(IMenuItem item)
|
||||
{
|
||||
switch (item.ItemId)
|
||||
{
|
||||
case Android.Resource.Id.Home:
|
||||
drawerLayout.OpenDrawer(GravityCompat.Start);
|
||||
return true;
|
||||
}
|
||||
return base.OnOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
shouldClose = false;
|
||||
}
|
||||
|
||||
public override void OnBackPressed()
|
||||
{
|
||||
if (drawerLayout.IsDrawerOpen((int) GravityFlags.Start))
|
||||
{
|
||||
drawerLayout.CloseDrawer(GravityCompat.Start);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!shouldClose)
|
||||
{
|
||||
Toast.MakeText(this, "Press back again to exit.", ToastLength.Short).Show();
|
||||
shouldClose = true;
|
||||
return;
|
||||
}
|
||||
base.OnBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using System.Linq;
|
||||
using Android.App;
|
||||
using Android.OS;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Content.PM;
|
||||
using Android.Graphics;
|
||||
using Android.Support.V4.Content;
|
||||
using Android.Gms.Maps;
|
||||
using MyDriving.ViewModel;
|
||||
using Android.Gms.Maps.Model;
|
||||
using Android.Graphics.Drawables;
|
||||
using System;
|
||||
using MyDriving.DataObjects;
|
||||
|
||||
namespace MyDriving.Droid.Activities
|
||||
{
|
||||
[Activity(Label = "Details", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
|
||||
ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
public class PastTripDetailsActivity : BaseActivity, IOnMapReadyCallback
|
||||
{
|
||||
Marker carMarker;
|
||||
TextView distance, distanceUnits, time, speed, speedUnits, consumption, consumptionUnits;
|
||||
string id;
|
||||
|
||||
GoogleMap map;
|
||||
SupportMapFragment mapFrag;
|
||||
SeekBar seekBar;
|
||||
TextView startTime, endTime;
|
||||
PastTripsDetailViewModel viewModel;
|
||||
|
||||
protected override int LayoutResource => Resource.Layout.activity_past_trip_details;
|
||||
|
||||
|
||||
public async void OnMapReady(GoogleMap googleMap)
|
||||
{
|
||||
map = googleMap;
|
||||
|
||||
var success = await viewModel.ExecuteLoadTripCommandAsync(id);
|
||||
if (!success)
|
||||
{
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
startTime.Text = viewModel.Trip.StartTimeDisplay;
|
||||
endTime.Text = viewModel.Trip.EndTimeDisplay;
|
||||
SupportActionBar.Title = viewModel.Title;
|
||||
SetupMap();
|
||||
UpdateStats();
|
||||
}
|
||||
public static Trip Trip { get; set; }
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
base.OnCreate(bundle);
|
||||
if ((int) Build.VERSION.SdkInt >= 21)
|
||||
{
|
||||
Window.SetStatusBarColor(new Color(ContextCompat.GetColor(this, Resource.Color.primary_dark)));
|
||||
Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
|
||||
}
|
||||
|
||||
|
||||
viewModel = new PastTripsDetailViewModel {Title = id = Intent.GetStringExtra("Id")};
|
||||
|
||||
viewModel.Trip = Trip;
|
||||
seekBar = FindViewById<SeekBar>(Resource.Id.trip_progress);
|
||||
seekBar.Enabled = false;
|
||||
|
||||
startTime = FindViewById<TextView>(Resource.Id.text_start_time);
|
||||
endTime = FindViewById<TextView>(Resource.Id.text_end_time);
|
||||
startTime.Text = endTime.Text = string.Empty;
|
||||
|
||||
time = FindViewById<TextView>(Resource.Id.text_time);
|
||||
distance = FindViewById<TextView>(Resource.Id.text_distance);
|
||||
distanceUnits = FindViewById<TextView>(Resource.Id.text_distance_units);
|
||||
consumption = FindViewById<TextView>(Resource.Id.text_consumption);
|
||||
consumptionUnits = FindViewById<TextView>(Resource.Id.text_consumption_units);
|
||||
speed = FindViewById<TextView>(Resource.Id.text_speed);
|
||||
speedUnits = FindViewById<TextView>(Resource.Id.text_speed_units);
|
||||
|
||||
mapFrag = (SupportMapFragment) SupportFragmentManager.FindFragmentById(Resource.Id.map);
|
||||
mapFrag.GetMapAsync(this);
|
||||
}
|
||||
|
||||
void UpdateStats()
|
||||
{
|
||||
time.Text = viewModel.ElapsedTime;
|
||||
consumption.Text = viewModel.FuelConsumption;
|
||||
consumptionUnits.Text = viewModel.FuelConsumptionUnits;
|
||||
speed.Text = viewModel.Speed;
|
||||
speedUnits.Text = viewModel.SpeedUnits;
|
||||
distanceUnits.Text = viewModel.DistanceUnits;
|
||||
distance.Text = viewModel.Distance;
|
||||
}
|
||||
|
||||
void SetupMap()
|
||||
{
|
||||
if (mapFrag.View.Width == 0)
|
||||
{
|
||||
mapFrag.View.PostDelayed(SetupMap, 500);
|
||||
return;
|
||||
}
|
||||
if (viewModel.Trip == null || viewModel.Trip.Points == null || viewModel.Trip.Points.Count == 0)
|
||||
return;
|
||||
|
||||
var start = viewModel.Trip.Points[0];
|
||||
var end = viewModel.Trip.Points[viewModel.Trip.Points.Count - 1];
|
||||
seekBar.Max = viewModel.Trip.Points.Count - 1;
|
||||
seekBar.ProgressChanged += SeekBar_ProgressChanged;
|
||||
|
||||
var logicalDensity = Resources.DisplayMetrics.Density;
|
||||
var thicknessCar = (int) Math.Ceiling(26*logicalDensity + .5f);
|
||||
var thicknessPoints = (int) Math.Ceiling(20*logicalDensity + .5f);
|
||||
|
||||
var b = ContextCompat.GetDrawable(this, Resource.Drawable.ic_car_blue) as BitmapDrawable;
|
||||
var finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessCar, thicknessCar, false);
|
||||
|
||||
var car = new MarkerOptions();
|
||||
car.SetPosition(new LatLng(start.Latitude, start.Longitude));
|
||||
car.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
|
||||
car.Anchor(.5f, .5f);
|
||||
|
||||
b = ContextCompat.GetDrawable(this, Resource.Drawable.ic_start_point) as BitmapDrawable;
|
||||
finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);
|
||||
|
||||
var startMarker = new MarkerOptions();
|
||||
startMarker.SetPosition(new LatLng(start.Latitude, start.Longitude));
|
||||
startMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
|
||||
startMarker.Anchor(.5f, .5f);
|
||||
|
||||
b = ContextCompat.GetDrawable(this, Resource.Drawable.ic_end_point) as BitmapDrawable;
|
||||
finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);
|
||||
|
||||
var endMarker = new MarkerOptions();
|
||||
endMarker.SetPosition(new LatLng(end.Latitude, end.Longitude));
|
||||
endMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
|
||||
endMarker.Anchor(.5f, .5f);
|
||||
|
||||
b = ContextCompat.GetDrawable(this, Resource.Drawable.ic_tip) as BitmapDrawable;
|
||||
finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);
|
||||
var poiIcon = BitmapDescriptorFactory.FromBitmap(finalIcon);
|
||||
foreach (var poi in viewModel.POIs)
|
||||
{
|
||||
var poiMarker = new MarkerOptions();
|
||||
poiMarker.SetPosition(new LatLng(poi.Latitude, poi.Longitude));
|
||||
poiMarker.SetIcon(poiIcon);
|
||||
poiMarker.Anchor(.5f, .5f);
|
||||
map.AddMarker(poiMarker);
|
||||
}
|
||||
|
||||
|
||||
var points = viewModel.Trip.Points.Select(s => new LatLng(s.Latitude, s.Longitude)).ToArray();
|
||||
var rectOptions = new PolylineOptions();
|
||||
rectOptions.Add(points);
|
||||
rectOptions.InvokeColor(ContextCompat.GetColor(this, Resource.Color.primary_dark));
|
||||
map.AddPolyline(rectOptions);
|
||||
|
||||
|
||||
map.AddMarker(startMarker);
|
||||
map.AddMarker(endMarker);
|
||||
|
||||
carMarker = map.AddMarker(car);
|
||||
|
||||
var boundsPoints = new LatLngBounds.Builder();
|
||||
foreach (var point in points)
|
||||
boundsPoints.Include(point);
|
||||
|
||||
var bounds = boundsPoints.Build();
|
||||
map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 64));
|
||||
|
||||
map.MoveCamera(CameraUpdateFactory.NewLatLng(carMarker.Position));
|
||||
|
||||
|
||||
seekBar.Enabled = true;
|
||||
}
|
||||
|
||||
void SeekBar_ProgressChanged(object sender, SeekBar.ProgressChangedEventArgs e)
|
||||
{
|
||||
if (carMarker == null)
|
||||
return;
|
||||
|
||||
viewModel.CurrentPosition = viewModel.Trip.Points[e.Progress];
|
||||
|
||||
RunOnUiThread(() =>
|
||||
{
|
||||
UpdateStats();
|
||||
carMarker.Position = new LatLng(viewModel.CurrentPosition.Latitude,
|
||||
viewModel.CurrentPosition.Longitude);
|
||||
map.MoveCamera(CameraUpdateFactory.NewLatLng(carMarker.Position));
|
||||
});
|
||||
}
|
||||
|
||||
public override bool OnOptionsItemSelected(IMenuItem item)
|
||||
{
|
||||
if (item.ItemId == Android.Resource.Id.Home)
|
||||
Finish();
|
||||
|
||||
return base.OnOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Support.V7.App;
|
||||
using MyDriving.Utils;
|
||||
|
||||
namespace MyDriving.Droid.Activities
|
||||
{
|
||||
[Activity(Label = "MyDriving", Theme = "@style/SplashTheme", MainLauncher = true)]
|
||||
public class SplashActivity : AppCompatActivity
|
||||
{
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
Intent newIntent;
|
||||
if (Settings.Current.IsLoggedIn)
|
||||
{
|
||||
newIntent = new Intent(this, typeof(MainActivity));
|
||||
|
||||
//When the first screen of the app is launched after user has logged in, initialize the processor that manages connection to OBD Device and to the IOT Hub
|
||||
MyDriving.Services.OBDDataProcessor.GetProcessor().Initialize(ViewModel.ViewModelBase.StoreManager);
|
||||
}
|
||||
|
||||
else if (Settings.Current.FirstRun)
|
||||
{
|
||||
#if XTC
|
||||
newIntent = new Intent(this, typeof(LoginActivity));
|
||||
|
||||
#else
|
||||
newIntent = new Intent(this, typeof(GettingStartedActivity));
|
||||
|
||||
#endif
|
||||
|
||||
#if !DEBUG
|
||||
Settings.Current.FirstRun = false;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
newIntent = new Intent(this, typeof(LoginActivity));
|
||||
|
||||
|
||||
newIntent.AddFlags(ActivityFlags.ClearTop);
|
||||
newIntent.AddFlags(ActivityFlags.SingleTop);
|
||||
StartActivity(newIntent);
|
||||
Finish();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Android.App;
|
||||
using Android.OS;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Content.PM;
|
||||
using MyDriving.ViewModel;
|
||||
using Android.Graphics;
|
||||
using Android.Support.V4.Content;
|
||||
|
||||
namespace MyDriving.Droid.Activities
|
||||
{
|
||||
[Activity(Label = "Trip Summary", Theme = "@style/MyTheme",
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
|
||||
ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
public class TripSummaryActivity : BaseActivity
|
||||
{
|
||||
public static TripSummaryViewModel ViewModel { get; set; }
|
||||
|
||||
|
||||
protected override int LayoutResource => Resource.Layout.activity_trip_summary;
|
||||
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
if ((int) Build.VERSION.SdkInt >= 21)
|
||||
{
|
||||
Window.SetStatusBarColor(new Color(ContextCompat.GetColor(this, Resource.Color.primary_dark)));
|
||||
Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
|
||||
}
|
||||
|
||||
|
||||
if (ViewModel == null)
|
||||
{
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
SupportActionBar.SetDisplayShowHomeEnabled(false);
|
||||
SupportActionBar.SetDisplayHomeAsUpEnabled(false);
|
||||
|
||||
|
||||
var date = ViewModel.Date.ToLocalTime();
|
||||
FindViewById<TextView>(Resource.Id.text_time).Text = ViewModel.TotalTimeDisplay;
|
||||
FindViewById<TextView>(Resource.Id.text_date).Text = date.ToString("M") + " " + date.ToString("t");
|
||||
FindViewById<TextView>(Resource.Id.text_distance).Text = ViewModel.TotalDistanceDisplay;
|
||||
FindViewById<TextView>(Resource.Id.text_max_speed).Text = ViewModel.MaxSpeedDisplay;
|
||||
FindViewById<TextView>(Resource.Id.text_fuel_consumption).Text = ViewModel.FuelDisplay;
|
||||
FindViewById<TextView>(Resource.Id.text_hard_accelerations).Text = ViewModel.HardAccelerations.ToString();
|
||||
FindViewById<TextView>(Resource.Id.text_hard_breaks).Text = ViewModel.HardStops.ToString();
|
||||
|
||||
ViewModel = null;
|
||||
}
|
||||
|
||||
public override bool OnCreateOptionsMenu(IMenu menu)
|
||||
{
|
||||
MenuInflater.Inflate(Resource.Menu.menu_summary, menu);
|
||||
return base.OnCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
public override bool OnOptionsItemSelected(IMenuItem item)
|
||||
{
|
||||
switch (item.ItemId)
|
||||
{
|
||||
case Resource.Id.menu_close:
|
||||
Finish();
|
||||
break;
|
||||
}
|
||||
return base.OnOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user