Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Added NotesSample application #21

Merged
merged 10 commits into from
Jul 7, 2020
2 changes: 2 additions & 0 deletions .kokoro/kokoro_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ cd ${KOKORO_ARTIFACTS_DIR}/github/glass-enterprise-samples
( cd QRCodeScannerSample && ./gradlew build )
( cd VoiceRecognitionSample && ./gradlew build )
( cd WebRTCSample && ./gradlew build )
( cd NotesSample && ./gradlew build )

13 changes: 13 additions & 0 deletions NotesSample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
.idea
.project
.settings
.DS_Store
/bin
/build
/captures
/out
.externalNativeBuild
.cxx
1 change: 1 addition & 0 deletions NotesSample/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
62 changes: 62 additions & 0 deletions NotesSample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.glass.notessample"
minSdkVersion 27
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

dependencies {
implementation 'com.example.glass.ui:gesture-lib-sample:0.1.0-SNAPSHOT'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation "androidx.fragment:fragment-ktx:1.2.4"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha03'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.1.0'

// Room persistence library imports
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"
}
60 changes: 60 additions & 0 deletions NotesSample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.glass.notessample">

<!-- Permission necessary to enable voice commands menu -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<!--
Changes Glass touchpad response from the following key strokes:
- Enter
- Tab
- Shift + Tab
- Back button
- Home button
- Arrows
to the motion events, enabling this app to use the touch gestures.
-->
<meta-data
android:name="com.google.android.glass.TouchEnabledApplication"
android:value="true" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<!--
Makes this app visible on the application list in the Glass Launcher.
-->
<category android:name="com.google.android.glass.category.DIRECTORY" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.glass.notessample

import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import com.example.glass.notessample.voicecommand.OnVoiceCommandListener
import com.example.glass.ui.GlassGestureDetector
import com.example.glass.ui.GlassGestureDetector.OnGestureListener

abstract class BaseActivity : AppCompatActivity(), OnGestureListener {

var onGestureListener: OnGestureListener? = null
set(value) {
glassGestureDetector = GlassGestureDetector(this, value)
}
var onVoiceCommandListener: OnVoiceCommandListener? = null
private lateinit var glassGestureDetector: GlassGestureDetector

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
glassGestureDetector = GlassGestureDetector(this, this)
}

override fun onResume() {
super.onResume()
window.hideSystemUI()
}

override fun onCreatePanelMenu(featureId: Int, menu: Menu): Boolean {
menuInflater.inflate(R.menu.notes_menu, menu)
return true
}

override fun onContextItemSelected(item: MenuItem): Boolean {
onVoiceCommandListener?.onVoiceCommandDetected(item)
return super.onContextItemSelected(item)
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
return glassGestureDetector.onTouchEvent(ev) || super.dispatchTouchEvent(ev)
}

override fun onGesture(gesture: GlassGestureDetector.Gesture): Boolean = false

/**
* Helper method for the [Fragment] replacement in the container. Depends on the given flag,
* fragment can be added to the back stack.
*/
fun replaceFragment(fragment: Fragment, addToBackStack: Boolean) {
supportFragmentManager.commit {
replace(R.id.container, fragment)
if (addToBackStack) {
addToBackStack(fragment.toString())
}
}
}

/**
* Pops the back stack on the fragment manager.
*/
fun popBackStack() {
supportFragmentManager.popBackStack()
}

private fun Window.hideSystemUI() {
decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.glass.notessample

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import androidx.core.app.ActivityCompat

class MainActivity : BaseActivity() {

companion object {
const val FEATURE_VOICE_COMMANDS = 14
const val REQUEST_PERMISSION_CODE = 200
val PERMISSIONS = arrayOf(Manifest.permission.RECORD_AUDIO)
val TAG = MainActivity::class.java.simpleName
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.requestFeature(FEATURE_VOICE_COMMANDS)
setContentView(R.layout.activity_main)

// Requesting permissions to enable voice commands menu
ActivityCompat.requestPermissions(
this,
PERMISSIONS,
REQUEST_PERMISSION_CODE
)

replaceFragment(NotesFragment(), false)
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode == REQUEST_PERMISSION_CODE) {
for (result in grantResults) {
if (result != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Permission denied. Voice commands menu is disabled.")
}
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}
}
Loading