Skip to content

Commit

Permalink
Merge pull request #4 from PestrakMary/feature/settings
Browse files Browse the repository at this point in the history
Feature/settings
  • Loading branch information
uvlad7 authored Jun 6, 2021
2 parents f522772 + b32daf1 commit be36fc4
Show file tree
Hide file tree
Showing 18 changed files with 482 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.iml
.gradle
app/src/main/assets/sync/car.gram
app/src/main/assets/sync/car_long.gram
/local.properties
/.idea
.DS_Store
Expand Down
27 changes: 22 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import java.nio.file.Paths
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "by.surdoteam.surdo"
minSdkVersion 15
targetSdkVersion 29
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "0.4.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
Expand All @@ -30,7 +33,9 @@ android {
dependencies {
implementation project(':pocketsphinx-android-5prealpha-release')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation "androidx.fragment:fragment:1.3.4"
implementation "androidx.preference:preference:1.1.1"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
Expand All @@ -50,6 +55,9 @@ abstract class BuildGramTask extends DefaultTask {
@InputFile
abstract RegularFileProperty getDict();

@OutputFile
abstract RegularFileProperty getGramLong();

@OutputFile
abstract RegularFileProperty getGram();

Expand All @@ -69,13 +77,21 @@ abstract class BuildGramTask extends DefaultTask {
}
}
}
gram.get().asFile.write("""#JSGF V1.0;
gramLong.get().asFile.write("""#JSGF V1.0;
grammar car;
<item> = (${libCommands.join(") | (")});
public <command> = ( <item> ) + ;
""",'utf-8')
gram.get().asFile.write("""#JSGF V1.0;
grammar car;
<item> = (${libCommands.join(") | (")});
public <command> = ( <item> );
""",'utf-8')
}
}
Expand All @@ -84,6 +100,7 @@ task buildGram(type: BuildGramTask) {
def assetsDir = android.sourceSets.main.assets.srcDirs[0].toString()
lib = file(Paths.get(android.sourceSets.main.res.srcDirs[0].toString(), 'raw', 'lib.txt'))
dict = file(Paths.get(assetsDir, 'sync', 'car.dict').toString())
gramLong = file(Paths.get(assetsDir, 'sync', 'car_long.gram').toString())
gram = file(Paths.get(assetsDir, 'sync', 'car.gram').toString())
}

Expand Down
21 changes: 13 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="by.surdoteam.surdo">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
package="by.surdoteam.surdo">

<!-- is't required since API 19 for app dirs like-->
<!-- Context.getExternalCacheDir() -> /storage/emulated/0/Android/data/by.surdoteam.surdo/cache -->
<!-- Context.getExternalFilesDir(String) /storage/emulated/0/Android/data/by.surdoteam.surdo/files/String -->
<!-- and our case-->
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
116 changes: 116 additions & 0 deletions app/src/main/java/by/surdoteam/surdo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package by.surdoteam.surdo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentManager;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import androidx.room.Room;

import com.google.android.material.navigation.NavigationView;

import by.surdoteam.surdo.db.AppDatabase;
import by.surdoteam.surdo.fragments.AboutFragment;
import by.surdoteam.surdo.fragments.LibFragment;
import by.surdoteam.surdo.fragments.RecognizeFragment;
import by.surdoteam.surdo.fragments.SettingsFragment;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -20,6 +30,8 @@ public class MainActivity extends AppCompatActivity {
private AppDatabase database = null;
private LibFragment libFragment = null;
private RecognizeFragment recognizeFragment = null;
private SettingsFragment settingsFragment = null;
private AboutFragment aboutFragment = null;
private final Map<String, Integer> library = new TreeMap<>();

public AppDatabase getDatabase() {
Expand Down Expand Up @@ -49,6 +61,48 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

NavigationView navigationView = findViewById(R.id.navigation);
navigationView.
setNavigationItemSelectedListener
(menuItem -> {
int id = menuItem.getItemId();
if (id == R.id.recognizer_settings) {
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getRecognizeFragment())
.addToBackStack(null)
.commit();
} else if (id == R.id.library_settings) {
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getLibFragment())
.addToBackStack(null)
.commit();
} else if (id == R.id.action_settings) {
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getSettingsFragment())
.addToBackStack(null)
.commit();
} else if (id == R.id.about_settings) {
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getAboutFragment())
.addToBackStack(null)
.commit();
} else {
return false;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

drawer.closeDrawer(GravityCompat.START, true);
return true;
});

readLibrary();

database = Room.databaseBuilder(getApplicationContext(),
Expand All @@ -67,6 +121,54 @@ protected void onCreate(Bundle savedInstanceState) {
.commit();
}
libFragment = (LibFragment) fm.findFragmentById(R.id.fragmentContainer);
settingsFragment = (SettingsFragment) fm.findFragmentById(R.id.fragmentContainer);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.recognizer_settings:
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getRecognizeFragment())
.addToBackStack(null)
.commit();
return true;
case R.id.library_settings:
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getLibFragment())
.addToBackStack(null)
.commit();
return true;
case R.id.action_settings:
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getSettingsFragment())
.addToBackStack(null)
.commit();
return true;
case R.id.about_settings:
getSupportFragmentManager().
beginTransaction().
replace(R.id.fragmentContainer,
getAboutFragment())
.addToBackStack(null)
.commit();
return true;
}
return super.onOptionsItemSelected(item);
}

public LibFragment getLibFragment() {
Expand All @@ -82,4 +184,18 @@ public RecognizeFragment getRecognizeFragment() {
}
return recognizeFragment;
}

public AboutFragment getAboutFragment() {
if (aboutFragment == null) {
aboutFragment = new AboutFragment();
}
return aboutFragment;
}

public SettingsFragment getSettingsFragment() {
if (settingsFragment == null) {
settingsFragment = new SettingsFragment();
}
return settingsFragment;
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/by/surdoteam/surdo/fragments/AboutFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package by.surdoteam.surdo.fragments;

import android.os.Build;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import by.surdoteam.surdo.R;

public class AboutFragment extends Fragment {

public AboutFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_about, container, false);
((TextView) view.findViewById(R.id.textViewAboutText)).setMovementMethod(LinkMovementMethod.getInstance());
((TextView) view.findViewById(R.id.textViewMentioning)).setMovementMethod(LinkMovementMethod.getInstance());
return view;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.surdoteam.surdo;
package by.surdoteam.surdo.fragments;

import android.net.Uri;
import android.os.Build;
Expand All @@ -9,15 +9,15 @@
import android.view.ViewGroup;

import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;

import by.surdoteam.surdo.MainActivity;
import by.surdoteam.surdo.R;
import by.surdoteam.surdo.db.AppDatabase;
import by.surdoteam.surdo.db.Command;

Expand All @@ -33,37 +33,26 @@ public class LibFragment extends Fragment {
AppDatabase database;

public LibFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_lib, container, false);
ListView listViewFragmentLib = view.findViewById(R.id.listViewFragmentLib);
videoViewFragmentLib = view.findViewById(R.id.videoViewFragmentLib);
Button backButton = view.findViewById(R.id.buttonBackToHome);

listViewFragmentLib.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, arguments));
listViewFragmentLib.setOnItemClickListener((parent, itemClicked, position, id) -> {
TextView textView = (TextView) itemClicked;
String strText = textView.getText().toString(); // получаем текст нажатого элемента
videoViewFragmentLib.setVideoURI(Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + video.get(arguments.indexOf(strText))));
videoViewFragmentLib.setVideoURI(Uri.parse("android.resource://" + Objects.requireNonNull(getActivity()).getPackageName() + "/" + video.get(arguments.indexOf(strText))));
videoViewFragmentLib.requestFocus(0);
videoViewFragmentLib.start();
});
backButton.setOnClickListener(v -> Objects.requireNonNull(getFragmentManager()).
beginTransaction().
replace(R.id.fragmentContainer, ((MainActivity) Objects.requireNonNull(getActivity())).
getRecognizeFragment())
.addToBackStack(null)
.commit());

return view;
}

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Loading

0 comments on commit be36fc4

Please sign in to comment.