Skip to content

Commit 6b26ed9

Browse files
committed
Initial commit
0 parents  commit 6b26ed9

File tree

20 files changed

+277
-0
lines changed

20 files changed

+277
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.shraddhazingade.firstaiapiapp;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.example.shraddhazingade.firstaiapiapp", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.shraddhazingade.firstaiapiapp">
4+
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".MainActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
<uses-library android:name="com.google.android.maps" />
22+
23+
<meta-data
24+
android:name="com.google.android.gms.version"
25+
android:value="@integer/google_play_services_version" />
26+
</application>
27+
28+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.example.shraddhazingade.firstaiapiapp;
2+
3+
/**
4+
* Created by shraddhazingade on 11/22/16.
5+
*/
6+
7+
import ai.api.model.AIError;
8+
import ai.api.model.AIResponse;
9+
10+
public interface AIListener {
11+
void onResult(AIResponse result); // here process response
12+
void onError(AIError error); // here process error
13+
void onAudioLevel(float level); // callback for sound level visualization
14+
void onListeningStarted(); // indicate start listening here
15+
void onListeningCanceled(); // indicate stop listening here
16+
void onListeningFinished(); // indicate stop listening here
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.example.shraddhazingade.firstaiapiapp;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
import ai.api.AIConfiguration;
6+
import ai.api.AIListener;
7+
import ai.api.AIService;
8+
import ai.api.model.AIError;
9+
import ai.api.model.AIResponse;
10+
import ai.api.model.Result;
11+
12+
import com.google.android.gms.appindexing.AppIndex;
13+
import com.google.android.gms.common.api.GoogleApiClient;
14+
import com.google.gson.JsonElement;
15+
import java.util.Map;
16+
17+
import android.util.Log;
18+
import android.view.View;
19+
import android.widget.Button;
20+
import android.widget.TextView;
21+
22+
public class MainActivity extends AppCompatActivity implements AIListener {
23+
24+
private Button listenButton;
25+
private TextView resultTextView;
26+
private AIService aiService;
27+
private AIListener listener;
28+
private GoogleApiClient client;
29+
30+
@Override
31+
protected void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
setContentView(R.layout.activity_main);
34+
35+
listenButton = (Button) findViewById(R.id.listenButton);
36+
resultTextView = (TextView) findViewById(R.id.resultTextView);
37+
38+
final AIConfiguration config = new AIConfiguration("6863b1e035514720ba21f579eaef5be4",
39+
AIConfiguration.SupportedLanguages.English,
40+
AIConfiguration.RecognitionEngine.System);
41+
42+
aiService = AIService.getService(this, config);
43+
aiService.setListener(this);
44+
45+
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
46+
}
47+
48+
49+
50+
@Override
51+
public void onStart() {
52+
super.onStart();
53+
client.connect();
54+
}
55+
56+
@Override
57+
public void onStop() {
58+
super.onStop();
59+
client.disconnect();
60+
}
61+
62+
public void listenButtonOnClick ( final View view){
63+
Log.d("","Entered listenButtonOnClick");
64+
aiService.startListening();
65+
}
66+
67+
public void onResult(final AIResponse response) {
68+
Log.d("","Entered onResult");
69+
Result result = response.getResult();
70+
71+
String parameterString="";
72+
if (result.getParameters() != null && !result.getParameters().isEmpty()) {
73+
for (final Map.Entry<String, JsonElement> entry : result.getParameters().entrySet()) {
74+
parameterString += entry.getValue();
75+
}
76+
}
77+
78+
resultTextView.setText(parameterString);
79+
}
80+
81+
@Override
82+
public void onError(final AIError error) {
83+
resultTextView.setText(error.toString());
84+
}
85+
86+
87+
@Override
88+
public void onListeningStarted() {
89+
if (listener != null) {
90+
listener.onListeningStarted();
91+
}
92+
}
93+
94+
@Override
95+
public void onListeningCanceled() {}
96+
97+
@Override
98+
public void onListeningFinished() {
99+
// if (listener != null) {
100+
// listener.onListeningFinished();
101+
// }
102+
}
103+
104+
@Override
105+
public void onAudioLevel(final float level) {
106+
if (listener != null) {
107+
listener.onAudioLevel(level);
108+
}
109+
}
110+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/activity_main"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:paddingBottom="@dimen/activity_vertical_margin"
8+
android:paddingLeft="@dimen/activity_horizontal_margin"
9+
android:paddingRight="@dimen/activity_horizontal_margin"
10+
android:paddingTop="@dimen/activity_vertical_margin"
11+
tools:context="com.example.shraddhazingade.firstaiapiapp.MainActivity">
12+
13+
<Button
14+
android:text="Listen"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_alignParentTop="true"
18+
android:layout_alignParentLeft="true"
19+
android:layout_alignParentStart="true"
20+
android:layout_marginLeft="120dp"
21+
android:layout_marginStart="120dp"
22+
android:layout_marginTop="38dp"
23+
android:id="@+id/listenButton"
24+
tools:text="Listen"
25+
android:onClick="listenButtonOnClick" />
26+
27+
<TextView
28+
android:layout_height="match_parent"
29+
android:layout_below="@+id/listenButton"
30+
android:layout_marginTop="31dp"
31+
android:id="@+id/resultTextView"
32+
android:layout_width="match_parent"
33+
android:layout_alignParentLeft="true"
34+
android:layout_alignParentStart="true" />
35+
</RelativeLayout>
3.34 KB
Loading
2.15 KB
Loading
4.73 KB
Loading
7.54 KB
Loading
10.2 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>

app/src/main/res/values/colors.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>

app/src/main/res/values/dimens.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<!-- Default screen margins, per the Android Design guidelines. -->
3+
<dimen name="activity_horizontal_margin">16dp</dimen>
4+
<dimen name="activity_vertical_margin">16dp</dimen>
5+
</resources>

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">FirstAIAPIApp</string>
3+
</resources>

app/src/main/res/values/styles.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
10+
11+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.example.shraddhazingade.firstaiapiapp;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() throws Exception {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

libs/commons-io-2.4.jar

181 KB
Binary file not shown.

0 commit comments

Comments
 (0)