經過一段時間的實驗. 在別的framework找到可以讓backend的route支援angular html5mode了. 基本方式是如果我路由規則沒有定義的,全部指向index頁面(有ng-view的)

所以基於這個原則. mvc的路由規則就要稍微調整一下. 將原本的DefaultApp修改一下

1
2
3
4
5
6
7
8
9
10
11
12
// 舊
routes.MapRoute(
name: "DefaultApp",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// 新
routes.MapRoute(
name: "DefaultApp",
url: "app/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

然後新增

1
routes.Add(new SingleRoute());

SingleRoute Class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class SingleRoute : RouteBase
{
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var data = new RouteData(this, new MvcRouteHandler());
data.Values.Add("controller", "Home");
data.Values.Add("action", "Index");
return data;
}

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
return null;
}
}

Client angular side:

1
2
3
4
5
6
7
$stateProvider
.state('state1', {
url: "/state1",
templateUrl: "app/Home/state1" <= mvc route rule
})
$locationProvider.html5Mode(true).hashPrefix('!')

以上

HTML裡有也Element是沒有辦法focus, 原因是因為它們預設的tabindex是-1 所以要讓他們能focus, 只要改變tabindex=0. 就可以了

1
<span tabindex=0>something</span>

when use ngCordova socialSharing plugin. there is a method 『canShareVia』 which can share to specific social application by it’s appPackageName.

To Line(http://line.me) the packageName is jp.naver.line.android

1
2
3
4
var lineAppPackageName = 'jp.naver.line.android';
$cordovaSocialSharing
.shareVia(lineAppPackageName, content, subject, null, '')
...

Response::Download() in Laravel 4.x needs php_fileinfo extension. Sometimes web hosting server doesn’t have that extension on, althought it’s default for php 5.4.

so the way to work around is make a response, and add header to it. See code below

1
2
3
4
5
$file = File::get($filepath);
$response = Response::make($file, 200);
$response->header('Content-Type', $item->mime);
$response->header('Content-Disposition','attachment;filename="'.$filename.'"');
return $response;

之前有寫過一篇有關[Laravel] Laravel with Angular, 但是這個方法在Laravel 5.0裡面是不合用的

所以laravel 5.0的作法如下 在 app/Exceptions/Handler.php 裡修改render function

1
2
3
4
5
6
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
return response()->view('index')->header('Content-Type', 'text/html');
return parent::render($request, $e);
}

這個效果等於laravel 4.x的app::missing

Kinect Data Source

- Color
- Infrared
- Depth
- Body
- BodyIndex    

For Windows 8.1 App

- 開啟microphone, webcam權限
- 加入WindowsPreview.Kinect
- 建置CPU設定為x86

取得kinectSensor的方式

1
2
3
this.sensor = KinectSensor.GetDefault();
this.sensor.Open();
this.sensor.Close();

Readers

1
2
InfraredFrameReader reader = this.sensor.InfraredFrameSource.OpenReader();
reader.FrameArrived += InfraredReaderFrameArrvied;

Frame references

- Send in frame event args
- AcquireFrame : access to the actual frame
- RelativeTime : allow to templorally correlate frames
1
2
3
4
5
6
7
8
9
10
11
private void InfraredReaderFrameArrvied(InfraredFrameReader sender, InfraredFrameArrivedEventArgs args)
{
using (InfraredFrame frame = args.FrameReference.AcquireFrame())
{
if (frame != null)
{
// Get What you need from the frame

}
}
}

Frame

- Gives access to the frame data
    - Make a local copy of access the underlying buffer directly
- Contains metadata for the frame
    - Color, Format, width, height,etc.
- Important: Not Disposing frames will cause you to not receive more frames

Demo Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using WindowsPreview.Kinect;
using Windows.UI.Xaml.Media.Imaging;

namespace KinectStudy_01
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}

KinectSensor sensor;
InfraredFrameReader reader;
ushort[] irData;
byte[] irDateConverted;
WriteableBitmap irBitmap;

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
sensor = KinectSensor.GetDefault();
reader = sensor.InfraredFrameSource.OpenReader();
FrameDescription fd = sensor.InfraredFrameSource.FrameDescription;
irData = new ushort[fd.LengthInPixels];
irDateConverted = new byte[fd.LengthInPixels * 4];
irBitmap = new WriteableBitmap(fd.Width, fd.Height);
image.Source = irBitmap;

sensor.Open();
reader.FrameArrived += InfraredReaderFrameArrvied;
}


private void InfraredReaderFrameArrvied(InfraredFrameReader sender, InfraredFrameArrivedEventArgs args)
{
using (InfraredFrame frame = args.FrameReference.AcquireFrame())
{
if (frame != null)
{
// Get What you need from the frame
frame.CopyFrameDataToArray(irData);
for (int i = 0; i < irData.Length; i++)
{
byte intensity = (byte)(irData[i] >> 8);
irDateConverted[i * 4] = intensity;
irDateConverted[i * 4 + 1] = intensity;
irDateConverted[i * 4 + 2] = intensity;
irDateConverted[i * 4 + 3] = 255;
}

irDateConverted.CopyTo(irBitmap.PixelBuffer);
irBitmap.Invalidate();
}
}

}
}
}

Demo2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using WindowsPreview.Kinect;
using Windows.UI.Xaml.Media.Imaging;

using Windows.UI.Xaml.Shapes;
using Windows.UI;


namespace KinectStudy_01
{
public sealed partial class MainPage : Page
{
KinectSensor sensor;
InfraredFrameReader reader;
ushort[] irData;
byte[] irDateConverted;
WriteableBitmap irBitmap;

Body[] bodies;
MultiSourceFrameReader msfr;

public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
sensor = KinectSensor.GetDefault();
reader = sensor.InfraredFrameSource.OpenReader();
FrameDescription fd = sensor.InfraredFrameSource.FrameDescription;
irData = new ushort[fd.LengthInPixels];
irDateConverted = new byte[fd.LengthInPixels * 4];
irBitmap = new WriteableBitmap(fd.Width, fd.Height);
image.Source = irBitmap;

bodies = new Body[6];
msfr = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Infrared);
msfr.MultiSourceFrameArrived += msfr_MultiSourceFrameArrived;

sensor.Open();
}

void msfr_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrameArrivedEventArgs args)
{
using (MultiSourceFrame frame = args.FrameReference.AcquireFrame())
{
if (frame != null)
{
using (BodyFrame bodyframe = frame.BodyFrameReference.AcquireFrame())
{
using (InfraredFrame ifFrame = frame.InfraredFrameReference.AcquireFrame())
{
if (bodyframe != null && ifFrame != null)
{
// Get What you need from the frame
ifFrame.CopyFrameDataToArray(irData);
for (int i = 0; i < irData.Length; i++)
{
byte intensity = (byte)(irData[i] >> 8);
irDateConverted[i * 4] = intensity;
irDateConverted[i * 4 + 1] = intensity;
irDateConverted[i * 4 + 2] = intensity;
irDateConverted[i * 4 + 3] = 255;
}

irDateConverted.CopyTo(irBitmap.PixelBuffer);
irBitmap.Invalidate();

// 取得身體的相關資料
bodyframe.GetAndRefreshBodyData(bodies);
bodyCanvas.Children.Clear();
foreach (Body body in bodies)
{
if (body.IsTracked)
{
// 取得頭的關節位置
Joint headJoint = body.Joints[JointType.Head];
if (headJoint.TrackingState == TrackingState.Tracked)
{
// 轉換成DepthSpacePoint
DepthSpacePoint dsp = sensor.CoordinateMapper.MapCameraPointToDepthSpace(headJoint.Position);
// 在該位置上畫圓圈
Ellipse headCircle = new Ellipse() { Width = 50, Height = 50, Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)) };
bodyCanvas.Children.Add(headCircle);
Canvas.SetLeft(headCircle, dsp.X - 25);
Canvas.SetTop(headCircle, dsp.Y - 25);
}
}
}
}
}
}
}
}
}
}
}

Xbox One 同時推出Kinect v2,提供更強大的硬體功能及軟體功能, 剛好手上的案子也差不多到一個段落了。 所以決定來學習Kinect的開發

前置準備

  1. Kinect for windows
  2. 如果已經有了xbox one, 可以只買kinect adapter轉接器就可以了 巴哈
  3. Kinect sdk 2

硬體需求

  1. CPU: i7(建議)
  2. RAM: 4GB(建議)
  3. GPU: DirectX11 (必須)
  4. USB 3.0(必須)
  5. OS: Windows 8.0/8.1(必須)

詳細細節請參考官方網站

已經買了adapter, 等東西寄到後就可以開始學習了

當laravel想要好好的跟angular在一起時,Route都是他們之間的第三者。 前一陣子有發現一個還不錯的方式可以讓Laravel的Route失效。那就是利用

App::missing(function($exception)
{	
	return View::make('index');
});
```

這樣子的設定,就可以不用讓Laravel一直回傳index頁面. 如果需要其他路由設定時,就直接在上面新增即可.

當這樣子設定時,html頁面就可以放在public folder下面,不用使用blade template. 好處是,不用再多學習blade的語法。angular的操作也比較直覺。