-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloWikitude.java
161 lines (124 loc) · 4.08 KB
/
HelloWikitude.java
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package me.dineshkarpe.wikitude;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import com.wikitude.architect.ArchitectView;
import com.wikitude.architect.StartupConfiguration;
import java.io.IOException;
import me.dineshkarpe.hellowikitude.R;
/**
*
*/
public class HelloWikitude extends AppCompatActivity {
static final String TAG = HelloWikitude.class.getSimpleName();
private ArchitectView architectView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hellowikitude);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
this.architectView = (ArchitectView)this.findViewById(R.id.architectView);
if(ActivityCompat.checkSelfPermission(HelloWikitude.this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED){
if (ActivityCompat.shouldShowRequestPermissionRationale(HelloWikitude.this,
Manifest.permission.CAMERA)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Log.i(TAG,
"Displaying camera permission rationale to provide additional context.");
Snackbar.make(architectView, "Camera permission is needed to show the camera preview.",
Snackbar.LENGTH_INDEFINITE)
.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(HelloWikitude.this,
new String[]{Manifest.permission.CAMERA,Manifest.permission.BLUETOOTH},
0);
}
})
.show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA},
0);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}else{
loadArchitectView();
}
}
@Override
public void onResume() {
try{
super.onResume();
this.architectView.onResume();
}catch (NullPointerException e){
}
}
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onDestroy() {
try{
super.onDestroy();
}catch (NullPointerException e){
}
}
@Override
protected void onPause() {
try{
super.onPause();
this.architectView.onResume();
this.architectView.onPause();
}catch (NullPointerException e){
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case 0: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
loadArchitectView();
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
private void loadArchitectView() {
final StartupConfiguration startupConfiguration = new StartupConfiguration(getApplicationContext().getString(R.string.wikitude_trial_licence_key));
this.architectView.onCreate(startupConfiguration);
this.architectView.onPostCreate();
try {
this.architectView.load("index.html");
}catch (IOException e){
}
this.architectView.callJavascript("loadLogin()");
this.architectView.callJavascript("loadWelcome()");
}
}