diff --git a/README.md b/README.md index be5f7e7..3881b89 100644 --- a/README.md +++ b/README.md @@ -61,3 +61,11 @@ It is advisable to clone only the development branch using the following command * Make all the PR's in development branch. * Contact the mentors at Gitter or Slack channel before contributing. +### Team Members +* Amartya Mondal +* Aman Jee +* Anmol Chaddha +* Aparsh Gupta +* Somenath Sarkar +* Oindrilla +* Bhavna Haritsa diff --git a/app/build.gradle b/app/build.gradle index a41e22a..15c0835 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation 'com.android.support:design:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:support-v4:28.0.0' + implementation 'com.google.firebase:firebase-storage:17.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' @@ -44,15 +45,22 @@ dependencies { implementation 'com.firebaseui:firebase-ui-firestore:4.3.1' //firebase dependencies implementation 'com.google.android.gms:play-services-auth:16.0.1' - implementation 'com.google.firebase:firebase-auth:16.2.1' - implementation 'com.google.firebase:firebase-messaging:17.6.0' - implementation 'com.google.firebase:firebase-firestore:18.2.0' - implementation 'com.google.firebase:firebase-core:16.0.8' + implementation 'com.google.firebase:firebase-auth:17.0.0' + implementation 'com.google.firebase:firebase-messaging:18.0.0' + implementation 'com.google.firebase:firebase-firestore:19.0.0' + implementation 'com.google.firebase:firebase-core:16.0.9' //Glide implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' implementation 'com.wang.avi:library:2.1.3' implementation 'me.panavtec:drawableview:0.6.0' implementation 'com.pes.materialcolorpicker:library:1.2.0' + //smilie rating + implementation 'com.github.sujithkanna:smileyrating:1.6.8' + //youtuvelib + implementation 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:7.0.1' + // code generator for view + implementation 'com.jakewharton:butterknife:8.8.1' + annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1" } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 201589e..b48433e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,10 @@ + + + + - - - + + + + + android:screenOrientation="portrait" + android:configChanges="orientation|keyboardHidden|screenSize"/> + android:theme="@style/AppTheme.NoActionBar" + android:configChanges="orientation|keyboardHidden|screenSize"/> + android:theme="@style/AppTheme.NoActionBar" + android:configChanges="orientation|keyboardHidden|screenSize"> @@ -35,7 +56,8 @@ android:name=".Dictionary.DictionaryActivity" android:label="Dictionary" android:parentActivityName=".MainActivity" - android:windowSoftInputMode="stateHidden"> + android:windowSoftInputMode="stateHidden" + android:configChanges="orientation|keyboardHidden|screenSize"> diff --git a/app/src/main/assets/shabd_data.json b/app/src/main/assets/shabd_data.json index 43ac8f7..95ccbef 100644 --- a/app/src/main/assets/shabd_data.json +++ b/app/src/main/assets/shabd_data.json @@ -14,7 +14,7 @@ "imageResource" : "", "isItTopic" : 1, "parentClass" : "Home", - "title" : "Advanced" + "title" : "General" }, { "description" : "", "hindiTitle" : "", @@ -30,28 +30,28 @@ "imageResource" : "https://www.pngarts.com/files/3/Clothing-PNG-Image-Background.png", "isItTopic" : 1, "parentClass" : "Basic", - "title" : "Clothes" + "title" : "Getting Ready" }, { "description" : "", "hindiTitle" : "", "id" : 5, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", - "isItTopic" : 1, - "parentClass" : "Basic", - "title" : "Drink" + "imageResource" : "https://i.pinimg.com/originals/ff/89/2d/ff892d65159c65ae8ab29eb7e1e22c5c.png", + "isItTopic" : 0, + "parentClass" : "Animals and Birds", + "title" : "I saw an elephant" }, { "description" : "", "hindiTitle" : "", "id" : 6, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "https://classroomclipart.com/images/gallery/Clipart/Emotions/TN_smiley-face-character-surprise-expression-clipart-2.jpg", "isItTopic" : 1, "parentClass" : "Basic", - "title" : "Play" + "title" : "Feelings" }, { "description" : "", "hindiTitle" : "", "id" : 7, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "http://clipart-library.com/data_images/506916.jpg", "isItTopic" : 1, "parentClass" : "Food", "title" : "Breakfast" @@ -62,20 +62,20 @@ "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", "isItTopic" : 1, "parentClass" : "Food", - "title" : "Lunch" + "title" : "Want Food" }, { "description" : "", "hindiTitle" : "", "id" : 9, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "http://clipart-library.com/images/rcLnpExRi.png", "isItTopic" : 1, "parentClass" : "Food", - "title" : "Dinner" + "title" : "Want Fruit" }, { "description" : "", "hindiTitle" : "", "id" : 10, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "http://clipart-library.com/data_images/376510.gif", "isItTopic" : 0, "parentClass" : "Food", "title" : "I am Hungry" @@ -83,7 +83,7 @@ "description" : "", "hindiTitle" : "", "id" : 11, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "http://clipart-library.com/images/8TE645z9c.png", "isItTopic" : 0, "parentClass" : "Food", "title" : "I want Sweets because I like them" @@ -93,13 +93,13 @@ "id" : 12, "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", "isItTopic" : 0, - "parentClass" : "Food", + "parentClass" : "Want Food", "title" : "I want food" }, { "description" : "", "hindiTitle" : "", "id" : 13, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "https://previews.123rf.com/images/lineartestpilot/lineartestpilot1603/lineartestpilot160317083/53662157-freehand-drawn-thought-bubble-cartoon-i-love-food-symbol.jpg", "isItTopic" : 0, "parentClass" : "Food", "title" : "I love eating" @@ -107,10 +107,10 @@ "description" : "", "hindiTitle" : "", "id" : 14, - "imageResource" : "https://www.pinclipart.com/picdir/big/1-19283_snack-healthy-diet-clip-art-transprent-png-clip.png", + "imageResource" : "http://clipart-library.com/img/1438508.jpg", "isItTopic" : 0, "parentClass" : "QuickAction", - "title" : "I love eating" + "title" : "All the Best" }, { "description" : "", "hindiTitle" : "", @@ -151,5 +151,733 @@ "isItTopic" : 0, "parentClass" : "QuickAction", "title" : "Stop" - } ] + },{ + "description" : "", + "hindiTitle" : "", + "id" : 20, + "imageResource" : "http://www.dsource.in/tool/trinetra/img/tool_images/2_1471346756.png", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want idli" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 21, + "imageResource" : "http://www.urbanspicekitchen.ca/assets/images/menu/dosa.jpg", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want dosa" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 22, + "imageResource" : "https://www.justforhearts.org/wp-content/uploads/Untitled-1-copy2.jpg", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want upma" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 23, + "imageResource" : "https://c7.uihere.com/files/359/269/226/breakfast-sandwich-puri-tiffin-bonda-indian-cuisine-others.jpg", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want puris" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 24, + "imageResource" : "https://previews.123rf.com/images/cokemomo/cokemomo1208/cokemomo120800028/14827116-parotta-south-indian-layered-flat-bread.jpg", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want parathas" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 25, + "imageResource" : "http://clipart-library.com/data_images/586968.png", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want sandwich" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 26, + "imageResource" : "https://media.istockphoto.com/vectors/drinking-milk-vector-id913968204?k=6&m=913968204&s=612x612&w=0&h=30pgN7uzswcoaQc-47Cc-xVS36GdGks6qnIDl6QZBlQ=", + "isItTopic" : 0, + "parentClass" : "Breakfast", + "title" : "I want milk" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 27, + "imageResource" : "http://clipart-library.com/data_images/258170.gif", + "isItTopic" : 0, + "parentClass" : "Want Food", + "title" : "I want rice" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 28, + "imageResource" : "https://spng.pngfly.com/20190219/stw/kisspng-corn-tortilla-roti-indian-cuisine-ciudad-mante-cha-nuestros-grupos-de-inters-reporte-de-sostenibi-5c6bc33a38fc67.4661292415505662022334.jpg", + "isItTopic" : 0, + "parentClass" : "Want Food", + "title" : "I want roti" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 29, + "imageResource" : "https://www.iflkuwait.com/images/tadka_dal.jpg", + "isItTopic" : 0, + "parentClass" : "Want Food", + "title" : "I want dal" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 30, + "imageResource" : "http://3.bp.blogspot.com/-77du8JkZnh8/VNG5SF-aMGI/AAAAAAAANwg/HiM6DJSyxZs/s1600/FullSizeRender-5.jpg", + "isItTopic" : 0, + "parentClass" : "Want Food", + "title" : "I want sabzi" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 31, + "imageResource" : "https://us.123rf.com/450wm/altoclassic/altoclassic1805/altoclassic180500008/102210217-stock-illustration-bowl-of-sour-cream-sauce-mayonnaise-closeup-isolated-on-a-white-background-3d-illustration.jpg?ver=6", + "isItTopic" : 0, + "parentClass" : "Want Food", + "title" : "I want curd" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 32, + "imageResource" : "https://cognigen-cellular.com/images/salt-clipart.png", + "isItTopic" : 0, + "parentClass" : "Want Food", + "title" : "Please add some salt" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 33, + "imageResource" : "http://clipart-library.com/images/rcLnpExRi.png", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want a fruit" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 34, + "imageResource" : "https://www.sccpre.cat/mypng/detail/51-517362_banana-clipart-png-banana-clipart.png", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want banana" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 35, + "imageResource" : "http://clipart-library.com/data_images/51439.gif", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want apple" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 36, + "imageResource" : "https://www.sccpre.cat/mypng/detail/21-213567_mango-clipart-png.png", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want mango" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 37, + "imageResource" : "http://clipart-library.com/data_images/161969.png", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want grapes" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 38, + "imageResource" : "http://clipart-library.com/data_images/184625.gif", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want watermelon" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 39, + "imageResource" : "https://media.istockphoto.com/vectors/florida-orange-vector-id165974969?k=6&m=165974969&s=612x612&w=0&h=bAIbAFJu-cEhHJFzjb_NhbynDvB2TQsUudQjV7vSOSs=", + "isItTopic" : 0, + "parentClass" : "Want Fruit", + "title" : "I want orange" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 40, + "imageResource" : "http://clipart-library.com/data_images/290201.png", + "isItTopic" : 0, + "parentClass" : "Food", + "title" : "I want some snacks" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 41, + "imageResource" : "https://classroomclipart.com/images/gallery/Clipart/Food/Drink_and_Beverage_Clipart/TN_boy-holding-glass-of-cola-with-ice-cubes-clipart-1220.jpg", + "isItTopic" : 0, + "parentClass" : "Food", + "title" : "I want some drinks" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 42, + "imageResource" : "https://mostlybrightideas.files.wordpress.com/2010/06/spinach.jpg", + "isItTopic" : 0, + "parentClass" : "Food", + "title" : "Food is not good" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 43, + "imageResource" : "http://clipart-library.com/img1/938724.jpg", + "isItTopic" : 0, + "parentClass" : "Dressing", + "title" : "Where is my dress?" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 44, + "imageResource" : "https://clipartstation.com/wp-content/uploads/2017/11/wear-clean-clothes-clipart-3.jpg", + "isItTopic" : 0, + "parentClass" : "Dressing", + "title" : "Please help me to wear dress" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 45, + "imageResource" : "https://clipartion.com/wp-content/uploads/2015/11/get-dressed-clipart-free-clip-art-images.jpg", + "isItTopic" : 0, + "parentClass" : "Dressing", + "title" : "I am wearing a new dress" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 46, + "imageResource" : "https://media.istockphoto.com/vectors/indian-woman-in-salwar-kameez-vector-id504600377?k=6&m=504600377&s=612x612&w=0&h=p9XFRigA5jhwGG3tg-faY0tRgQG1Whsp0CAVXY7elDE=", + "isItTopic" : 0, + "parentClass" : "Dressing", + "title" : "I want to wear salwar kameez" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 47, + "imageResource" : "http://clipart-library.com/data_images/10285.png", + "isItTopic" : 0, + "parentClass" : "Dressing", + "title" : "I want jeans" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 48, + "imageResource" : "https://media.istockphoto.com/vectors/sweatpants-a-vector-illustration-vector-id1050839362?k=6&m=1050839362&s=612x612&w=0&h=bRKwdpWC7wRzpO2Lp3UqzEOHWkqe9vn7XU5DQOGRrl8=", + "isItTopic" : 0, + "parentClass" : "Dressing", + "title" : "I want pant" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 49, + "imageResource" : "http://clipart-library.com/data_images/88939.jpg", + "isItTopic" : 1, + "parentClass" : "Getting Ready", + "title" : "Washroom" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 50, + "imageResource" : "https://previews.123rf.com/images/sararoom/sararoom1301/sararoom130100053/17478187-illustration-of-boy-dressing.jpg", + "isItTopic" : 1, + "parentClass" : "Getting Ready", + "title" : "Dressing" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 51, + "imageResource" : "https://media.istockphoto.com/vectors/cute-boy-brushing-his-teeth-vector-id614432052?k=6&m=614432052&s=612x612&w=0&h=5JFWmJd6BbPnQfTHs2XX0BnpNXYOGK7epU1K-4Y1sDI=", + "isItTopic" : 0, + "parentClass" : "Washroom", + "title" : "I want brush-paste" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 52, + "imageResource" : "https://previews.123rf.com/images/rastudio/rastudio1202/rastudio120200100/12372303-cartoon-home-kitchen-towel.jpg", + "isItTopic" : 0, + "parentClass" : "Washroom", + "title" : "I want towel" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 53, + "imageResource" : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTGZ4vUci_cfpyJxXrSwFWjWWG59hT0U8zpQmIw-0TCBI0O7CL9", + "isItTopic" : 0, + "parentClass" : "Washroom", + "title" : "I want hot water" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 54, + "imageResource" : "https://www.pinclipart.com/picdir/middle/178-1789505_shampoo-clipart-png-download.png", + "isItTopic" : 0, + "parentClass" : "Washroom", + "title" : "I want shampoo" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 55, + "imageResource" : "http://www.clker.com/cliparts/7/b/d/c/15163397841548291646taking-a-bath-clipart-free.hi.png", + "isItTopic" : 0, + "parentClass" : "Washroom", + "title" : "I want to bath" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 56, + "imageResource" : "https://clipground.com/images/familiy-clipart-14.jpg", + "isItTopic" : 1, + "parentClass" : "Basic", + "title" : "My Family" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 57, + "imageResource" : "https://i.pinimg.com/originals/26/4e/30/264e30439c42387c1e3c48d2d038429d.png", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "My father is a doctor" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 58, + "imageResource" : "https://images.cdn1.stockunlimited.net/preview1300/male-teacher_1818579.jpg", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "My uncle is a teacher" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 59, + "imageResource" : "https://previews.123rf.com/images/tigatelu/tigatelu1509/tigatelu150900536/45168918-cartoon-happy-family-mother-holding-her-son.jpg", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "My mother takes care of me" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 60, + "imageResource" : "https://us.123rf.com/450wm/yeletkeshet/yeletkeshet1701/yeletkeshet170100004/69685965-stock-vector-little-girl-hugging-a-baby.jpg?ver=6", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "I have a sister" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 61, + "imageResource" : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT9W8YSZEcZacsYmTl98IWRU4C1MMm6chT8oJWJU7MRJvvvrLfl", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "My grandmother stays with me" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 62, + "imageResource" : "https://previews.123rf.com/images/memoangeles/memoangeles1407/memoangeles140700031/30567525-girl-hugging-her-grandmother-vector-clip-art-illustration-with-simple-gradients.jpg", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "I want to visit my grandmother" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 63, + "imageResource" : "https://i.pinimg.com/originals/00/ad/11/00ad11903c53c7736b47745c58bc8554.jpg", + "isItTopic" : 0, + "parentClass" : "My Family", + "title" : "I want to meet my mother" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 64, + "imageResource" : "http://clipart-library.com/image_gallery/107636.png", + "isItTopic" : 0, + "parentClass" : "Getting Ready", + "title" : "I want my bag" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 65, + "imageResource" : "http://i1.wp.com/clipartportal.com/wp-content/uploads/2018/12/stationery-clipart-images-3.jpg", + "isItTopic" : 0, + "parentClass" : "Getting Ready", + "title" : "I want my stationery" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 66, + "imageResource" : "https://previews.123rf.com/images/dazdraperma/dazdraperma1407/dazdraperma140700026/30401803-schoolboy-ready-go-to-school.jpg", + "isItTopic" : 0, + "parentClass" : "Getting Ready", + "title" : "Please make me ready fast" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 67, + "imageResource" : "http://clipart-library.com/img/834334.jpg", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I want to play" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 68, + "imageResource" : "http://clipart-library.com/images/LcdoxnnLi.png", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I am feeling bored" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 69, + "imageResource" : "http://clipart-library.com/data_images/105053.jpg", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I am angry with you" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 70, + "imageResource" : "https://i.pinimg.com/originals/56/32/c1/5632c13a0be038a4a219200e6dd2335d.jpg", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I am sad to hear that" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 71, + "imageResource" : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTnuHL50qSer8LrhLqm0kzgFM19i7Y96nsuvbUMMawu7PadiF1L", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I want to cry" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 72, + "imageResource" : "http://clipart-library.com/image_gallery/412974.jpg", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I want to go outside" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 73, + "imageResource" : "http://www.amisvegetarian.com/wp-content/uploads/2018/09/scared-clipart-a-girl-shaking-in-horror-clipart-vector-toons-clip-art-for-students.jpg", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I am scared" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 74, + "imageResource" : "", + "isItTopic" : 1, + "parentClass" : "Home", + "title" : "Getting Started" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 75, + "imageResource" : "https://i.pinimg.com/originals/84/1a/b5/841ab5803ed2df9e072509b764b7e0c1.png", + "isItTopic" : 0, + "parentClass" : "Feelings", + "title" : "I am sorry" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 76, + "imageResource" : "https://previews.123rf.com/images/blueringmedia/blueringmedia1703/blueringmedia170300310/74311500-two-american-kids-saying-hi-illustration.jpg", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "Hi" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 77, + "imageResource" : "https://clipartstation.com/wp-content/uploads/2018/09/bye-clipart-8.jpg", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "Bye" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 78, + "imageResource" : "http://www.clker.com/cliparts/E/a/A/C/b/M/go-inside-a-circle-hi.png", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "Go" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 79, + "imageResource" : "https://us.123rf.com/450wm/iconicbestiary/iconicbestiary1705/iconicbestiary170500104/77358246-stock-vector-businessman-looking-ahead-with-hand-over-his-eyes.jpg?ver=6", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "Look" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 80, + "imageResource" : "https://www.pinclipart.com/picdir/big/115-1154350_vector-illustration-of-school-crossing-guard-stops-crossing.png", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "Stop" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 81, + "imageResource" : "https://us.123rf.com/450wm/martialred/martialred1507/martialred150700939/42621315-stock-vector-thumbs-up-like-line-art-icon-for-apps-and-websites.jpg?ver=6", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "like" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 82, + "imageResource" : "http://clipart-library.com/data_images/208821.png", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "no" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 83, + "imageResource" : "http://www.clker.com/cliparts/H/l/8/M/I/c/more-games-hi.png", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "more" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 84, + "imageResource" : "https://listimg.pinclipart.com/picdir/s/0-9482_communication-friendship-face-help-help-me-clip-art.png", + "isItTopic" : 0, + "parentClass" : "Getting Started", + "title" : "Help" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 85, + "imageResource" : "http://clipart-library.com/data_images/304113.png", + "isItTopic" : 1, + "parentClass" : "General", + "title" : "Today" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 86, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 1, + "parentClass" : "General", + "title" : "Days of Week" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 87, + "imageResource" : "https://www.pngkey.com/png/full/65-653120_tree-tree-plant-clip-art.png", + "isItTopic" : 1, + "parentClass" : "General", + "title" : "Plants and Trees" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 88, + "imageResource" : "http://clipart-library.com/newimages/leaf-clip-art-1.png", + "isItTopic" : 0, + "parentClass" : "Plants and Trees", + "title" : "These leaves are green" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 89, + "imageResource" : "http://clipart-library.com/img/1239162.jpg", + "isItTopic" : 1, + "parentClass" : "General", + "title" : "Animals and Birds" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 90, + "imageResource" : "https://i.etsystatic.com/9709710/r/il/714bff/802892968/il_794xN.802892968_gia9.jpg", + "isItTopic" : 0, + "parentClass" : "Today", + "title" : "Today is a holiday" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 91, + "imageResource" : "http://clipart-library.com/img/1221427.png", + "isItTopic" : 0, + "parentClass" : "Today", + "title" : "What day is it today?" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 92, + "imageResource" : "http://www.clipartbay.com/cliparts/calendar-date-clipart-free-wtcmewn.png", + "isItTopic" : 0, + "parentClass" : "Today", + "title" : "What is the date today?" + } ,{ + "description" : "", + "hindiTitle" : "", + "id" : 93, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Monday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 94, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Tuesday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 95, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Wednesday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 96, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Thursday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 97, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Friday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 98, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Saturday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 99, + "imageResource" : "http://clipart-library.com/images/8TG6xX7Gc.jpg", + "isItTopic" : 0, + "parentClass" : "Days of Week", + "title" : "Today is Sunday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 100, + "imageResource" : "http://clipart-library.com/img/1418792.jpg", + "isItTopic" : 0, + "parentClass" : "Plants and Trees", + "title" : "The tree is tall" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 101, + "imageResource" : "http://clipart-library.com/images/di48g6jie.png", + "isItTopic" : 0, + "parentClass" : "Plants and Trees", + "title" : "The flower looks pretty" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 102, + "imageResource" : "https://www.pngkey.com/png/detail/164-1648116_crow-png-library-black-thing-huge-outline-of.png", + "isItTopic" : 0, + "parentClass" : "Animals and Birds", + "title" : "I saw a crow" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 103, + "imageResource" : "https://banner2.kisspng.com/20180107/lye/dog-clip-art-5a523580ac7722.14801650151533708870644816.jpg", + "isItTopic" : 0, + "parentClass" : "Animals and Birds", + "title" : "I saw a dog" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 104, + "imageResource" : "http://clipart-library.com/data_images/279518.png", + "isItTopic" : 0, + "parentClass" : "Animals and Birds", + "title" : "I saw a cat" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 105, + "imageResource" : "https://us.123rf.com/450wm/irwanjos/irwanjos1601/irwanjos160100006/50993708-stock-vector-cute-baby-monkey-hanging-on-tree.jpg?ver=6", + "isItTopic" : 0, + "parentClass" : "Animals and Birds", + "title" : "I saw a monkey" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 106, + "imageResource" : "http://www.mascotdesigngallery.com/wp/wp-content/uploads/2013/11/12154415421767612404lemmling_Simple_cartoon_mouse.svg.med_.png", + "isItTopic" : 0, + "parentClass" : "Animals and Birds", + "title" : "I saw a mouse" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 107, + "imageResource" : "https://mackinsgroup.com/wp-content/uploads/2017/12/thief-clipart-11-1024x1024.jpg", + "isItTopic" : 0, + "parentClass" : "QuickAction", + "title" : "Their is a thief" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 108, + "imageResource" : "http://www.emri.in/wp-content/uploads/2014/06/1081.png", + "isItTopic" : 0, + "parentClass" : "QuickAction", + "title" : "Call 108" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 109, + "imageResource" : "http://clipart-library.com/img/1505372.jpg", + "isItTopic" : 0, + "parentClass" : "QuickAction", + "title" : "Happy Birthday" + },{ + "description" : "", + "hindiTitle" : "", + "id" : 110, + "imageResource" : "https://previews.123rf.com/images/arcady31/arcady311403/arcady31140300044/27239318-do-not-disturb-red-signboard.jpg", + "isItTopic" : 0, + "parentClass" : "QuickAction", + "title" : "Do not Disturb" + }] } diff --git a/app/src/main/assets/task_data.json b/app/src/main/assets/task_data.json new file mode 100644 index 0000000..842967d --- /dev/null +++ b/app/src/main/assets/task_data.json @@ -0,0 +1,51 @@ +{ + "data" : [ { + "title" : "Draw an apple", + "hindiTitle" : "ihh", + "id" : 1, + "imageResource" : "https://i5.walmartimages.ca/images/Large/428/5_r/6000195494285_R.jpg", + "description" : "Basic", + "intentClass" : "Drawing", + "intent": "DrawingActivity" + }, { + "title" : "Score 5 points", + "hindiTitle" : "ghj", + "id" : 2, + "imageResource" : "https://www.codester.com/static//uploads/items/2658/preview-xl.jpg", + "description" : "Basic", + "intentClass" : "ColorGame", + "intent": "ColorGameActivity" + }, { + "title" : "Draw a Bird", + "hindiTitle" : "ghj", + "id" : 3, + "imageResource" : "https://akm-img-a-in.tosshub.com/indiatoday/images/story/201810/white_stork.jpeg?B2LINO47jclcIb3QCW.Bj9nto934Lox4", + "description" : "Basic", + "intentClass" : "Drawing", + "intent": "DrawingActivity" + }, { + "title" : "Score 5 points", + "hindiTitle" : "ghj", + "id" : 4, + "imageResource" : "http://clipartmag.com/images/quiz-clipart-24.jpg", + "description" : "Basic", + "intentClass" : "Quiz", + "intent": "QuizActivity" + }, { + "title" : "Watch 2 videos", + "hindiTitle" : "ghj", + "id" : 4, + "imageResource" : "https://s3.amazonaws.com/media.eremedia.com/wp-content/uploads/2018/04/06122011/story.jpeg", + "description" : "Basic", + "intentClass" : "Video", + "intent": "VideoActivity" + }, { + "title" : "Holiday", + "hindiTitle" : "ghj", + "id" : 4, + "imageResource" : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSWEXBiGxKzBLNDhHMmgrR6KBYlOOO2f0SXP5TZ3DS_UthzhOoq", + "description" : "Basic", + "intentClass" : "null", + "intent": "null" + } ] +} diff --git a/app/src/main/java/com/dsciitp/shabd/Dictionary/DictionaryActivity.java b/app/src/main/java/com/dsciitp/shabd/Dictionary/DictionaryActivity.java index 1d3c051..2207134 100644 --- a/app/src/main/java/com/dsciitp/shabd/Dictionary/DictionaryActivity.java +++ b/app/src/main/java/com/dsciitp/shabd/Dictionary/DictionaryActivity.java @@ -10,157 +10,169 @@ import android.view.View; import android.widget.EditText; import android.widget.ImageView; +import android.widget.Toast; import com.dsciitp.shabd.R; import java.util.Locale; -public class DictionaryActivity extends AppCompatActivity implements DictionaryAdapter.OnCategorySelectedListener,MeaningFragment.OnMeaningPass { +public class DictionaryActivity extends AppCompatActivity implements DictionaryAdapter.OnCategorySelectedListener, MeaningFragment.OnMeaningPass { EditText word; ImageView del, play; TextToSpeech tts; FloatingActionButton search; private static final String TTS_SPEAK_ID = "SPEAK"; - Fragment activefragment; + Fragment activeFragment; String press = "Press me to know the meaning"; @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_dictionary); + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_dictionary ); ActionBar bar = getSupportActionBar(); if (bar != null) getSupportActionBar().hide(); - del = findViewById(R.id.deld); - word = findViewById(R.id.speak); - search = findViewById(R.id.search); - setBaseFragment(savedInstanceState); - play = findViewById(R.id.playd); + del = findViewById( R.id.deld ); + word = findViewById( R.id.speak ); + search = findViewById( R.id.search ); + setBaseFragment( savedInstanceState ); + play = findViewById( R.id.playd ); onclicksearch(); - del.setOnClickListener(new View.OnClickListener() { + del.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String textString = word.getText().toString(); if (textString.length() > 0) { - word.setText(textString.substring(0, textString.length() - 1)); - word.setSelection(word.getText().length());//position cursor at the end of the line + word.setText( textString.substring( 0, textString.length() - 1 ) ); + word.setSelection( word.getText().length() );//position cursor at the end of the line } } - }); - del.setOnLongClickListener(new View.OnLongClickListener() { + } ); + del.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { String textString = word.getText().toString(); if (textString.length() > 0) { - word.setText(""); - word.setSelection(word.getText().length()); + word.setText( "" ); + word.setSelection( word.getText().length() ); } return false; } - }); - tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { + } ); + //Locale current = getResources().getConfiguration().locale; + tts = new TextToSpeech( this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status != TextToSpeech.ERROR) { - tts.setLanguage(Locale.US); + tts.setLanguage( Locale.US ); } } - }); + } ); - tts.setPitch(1f); - tts.setSpeechRate(0.9f); - play.setOnClickListener(new View.OnClickListener() { + tts.setPitch( 1f ); + tts.setSpeechRate( 0.9f ); + play.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { - tts.speak(word.getText(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); - search.animate().scaleX(2f).scaleY(2f).setDuration(1000).translationZBy(25f).withEndAction(new Runnable() { - @Override - public void run() { - search.animate().scaleX(1f).scaleY(1f).setDuration(1000).translationZBy(-25f).withEndAction(new Runnable() { - @Override - public void run() { - tts.speak(press, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); - search.animate().scaleX(2f).scaleY(2f).setDuration(1000).translationZBy(+25f).withEndAction(new Runnable() { - @Override - public void run() { - search.animate().scaleX(1f).scaleY(1f).translationZBy(25f).setDuration(1000); - } - }); - } - }); - } - }); + if (!word.getText().toString().equals( "" )) { + tts.speak( word.getText(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + search.animate().scaleX( 2f ).scaleY( 2f ).setDuration( 1000 ).translationZBy( 25f ).withEndAction( new Runnable() { + @Override + public void run() { + search.animate().scaleX( 1f ).scaleY( 1f ).setDuration( 1000 ).translationZBy( -25f ).withEndAction( new Runnable() { + @Override + public void run() { + if (word.getText().toString().length() < 15) + tts.speak( press, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + search.animate().scaleX( 2f ).scaleY( 2f ).setDuration( 1000 ).translationZBy( +25f ).withEndAction( new Runnable() { + @Override + public void run() { + search.animate().scaleX( 1f ).scaleY( 1f ).translationZBy( 25f ).setDuration( 1000 ); + } + } ); + } + } ); + } + } ); + } } - }); + } ); } private void setBaseFragment(Bundle savedInstanceState) { - if (findViewById(R.id.frame_dictionary) != null) { + if (findViewById( R.id.frame_dictionary ) != null) { if (savedInstanceState != null) { return; } DictionaryFragment firstFragment = new DictionaryFragment(); - firstFragment.setArguments(getIntent().getExtras()); + firstFragment.setArguments( getIntent().getExtras() ); getSupportFragmentManager().beginTransaction() - .add(R.id.frame_dictionary, firstFragment).commit(); + .add( R.id.frame_dictionary, firstFragment ).commit(); } } private void transactFragment(Fragment frag) { FragmentTransaction fragmentManager = getSupportFragmentManager().beginTransaction(); - fragmentManager.replace(R.id.frame_dictionary, frag, frag.getTag()) - .addToBackStack(frag.getTag()) + fragmentManager.replace( R.id.frame_dictionary, frag, frag.getTag() ) + .addToBackStack( frag.getTag() ) .commit(); } @Override public void onTopicSelected(String title) { - tts.speak(title, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); - word.append(title); + tts.speak( title, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + word.append( title ); + } public void onDictionarySelected() { // NetworkUtils.dictionaryEntries(word.getText().toString()); - MeaningFragment fragment = MeaningFragment.newInstance(word.getText().toString()); - transactFragment(fragment); + MeaningFragment fragment = MeaningFragment.newInstance( word.getText().toString() ); + transactFragment( fragment ); final View view = this.getWindow().getDecorView(); - activefragment=fragment; + activeFragment = fragment; // view.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); - search.setBackgroundColor(getResources().getColor(R.color.searchBackground)); - search.setOnClickListener(new View.OnClickListener() { + search.setBackgroundColor( getResources().getColor( R.color.searchBackground ) ); + search.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { DictionaryActivity.super.onBackPressed(); onclicksearch(); } - }); + } ); } private void onclicksearch() { - search.setOnClickListener(new View.OnClickListener() { + search.setOnClickListener( new View.OnClickListener() { @Override public void onClick(final View v) { - search.setImageResource(R.color.searchBackground); - search.setBackgroundColor(getResources().getColor(R.color.searchBackground)); - v.animate().x(350f).y(250f).scaleX(40f).scaleY(40f).setDuration(500).translationZBy(25f).withEndAction(new Runnable() { - @Override - public void run() { - v.animate().translationX(0f).translationY(0f).scaleX(1f).scaleY(1f).setDuration(300).translationZBy(-25f).withEndAction(new Runnable() { - @Override - public void run() { - search.setImageResource(R.drawable.ic_search_black_24dp); - } - }); - onDictionarySelected(); - } - }); + if (word.getText().toString().equals( "" )) { + Toast.makeText( DictionaryActivity.this, "Type a word to search", Toast.LENGTH_SHORT ).show(); + tts.speak( "Type a word to search", TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + } else { + search.setImageResource( R.color.searchBackground ); + search.setBackgroundColor( getResources().getColor( R.color.searchBackground ) ); + v.animate().x( 350f ).y( 250f ).scaleX( 40f ).scaleY( 40f ).setDuration( 500 ).translationZBy( 25f ).withEndAction( new Runnable() { + @Override + public void run() { + v.animate().translationX( 0f ).translationY( 0f ).scaleX( 1f ).scaleY( 1f ).setDuration( 300 ).translationZBy( -25f ).withEndAction( new Runnable() { + @Override + public void run() { + search.setImageResource( R.drawable.ic_search_black_24dp ); + } + } ); + onDictionarySelected(); + } + } ); + } } - }); + } ); + } @Override @@ -174,8 +186,7 @@ protected void onDestroy() { @Override public void onBackPressed() { - if(activefragment instanceof MeaningFragment) - { + if (activeFragment instanceof MeaningFragment) { onclicksearch(); } super.onBackPressed(); @@ -183,8 +194,8 @@ public void onBackPressed() { @Override public void onMeaningPass(String data) { - tts.setSpeechRate(0.8f); - tts.speak(data, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); + tts.setSpeechRate( 0.8f ); + tts.speak( data, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); } } diff --git a/app/src/main/java/com/dsciitp/shabd/Dictionary/NetworkUtils.java b/app/src/main/java/com/dsciitp/shabd/Dictionary/NetworkUtils.java index 041f73f..f52cac7 100644 --- a/app/src/main/java/com/dsciitp/shabd/Dictionary/NetworkUtils.java +++ b/app/src/main/java/com/dsciitp/shabd/Dictionary/NetworkUtils.java @@ -25,8 +25,8 @@ private static String getResponseFromHttpUrl(URL url) throws IOException { urlConnection.setReadTimeout(2000);*/ InputStream in = urlConnection.getInputStream(); - Scanner scanner = new Scanner(in); - scanner.useDelimiter("\\A"); + Scanner scanner = new Scanner( in ); + scanner.useDelimiter( "\\A" ); try { boolean hasInput = scanner.hasNext(); if (hasInput) { @@ -42,25 +42,25 @@ private static String getResponseFromHttpUrl(URL url) throws IOException { public static String dictionaryEntries(String search) { String language = "en"; - Uri builtUri = Uri.parse(base).buildUpon() - .appendQueryParameter(PARAM_QUERY, search.toLowerCase()) + Uri builtUri = Uri.parse( base ).buildUpon() + .appendQueryParameter( PARAM_QUERY, search.toLowerCase() ) .build(); URL url = null; try { - url = new URL(builtUri.toString()); + url = new URL( builtUri.toString() ); } catch (MalformedURLException e) { e.printStackTrace(); } if (url == null) return null; - Log.d("uri", url.toString()); + Log.d( "uri", url.toString() ); try { - String json = getResponseFromHttpUrl(url); + String json = getResponseFromHttpUrl( url ); if (json != null) { - return extractJson(json); + return extractJson( json ); } } catch (IOException e) { e.printStackTrace(); @@ -70,42 +70,32 @@ public static String dictionaryEntries(String search) { private static String extractJson(String string) { - StringBuilder def = new StringBuilder(""); + StringBuilder def = new StringBuilder( "" ); //meaning.setText(result); try { JSONObject definition; - JSONObject js = new JSONObject(string); - JSONObject meaning=js.getJSONObject("meaning"); - JSONArray noun=meaning.getJSONArray("noun"); - if(noun!=null) - { - definition=noun.getJSONObject(0); - def.append("\n").append(definition.getString("definition")).append(","); + + JSONObject js = new JSONObject( string ); + JSONObject meaning = js.getJSONObject( "meaning" ); + + if (meaning.has( "noun" )) { + JSONArray noun = meaning.getJSONArray( "noun" ); + def.append( "\n" ).append( noun.getJSONObject( 0 ).getString( "definition" ) ).append( "\n" ); } - JSONArray exclamation=meaning.getJSONArray("exclamation"); - if(exclamation!=null) - { - definition=exclamation.getJSONObject(0); - def.append("\n").append(definition.getString("definition")).append(","); + if (meaning.has( "exclamation" )) { + JSONArray exclamation = meaning.getJSONArray( "exclamation" ); + def.append( "\n" ).append( exclamation.getJSONObject( 0 ).getString( "definition" ) ).append( "\n" ); } - - JSONArray verb=meaning.getJSONArray("verb"); - if(verb!=null) - { - definition=verb.getJSONObject(0); - def.append("\n").append(definition.getString("definition")).append(","); + if (meaning.has( "verb" )) { + JSONArray verb = meaning.getJSONArray( "verb" ); + def.append( "\n" ).append( verb.getJSONObject( 0 ).getString( "definition" ) ).append( "\n" ); } - JSONArray adjective=meaning.getJSONArray("adjective"); - if(verb!=null) - { - definition=adjective.getJSONObject(0); - def.append("\n").append(definition.getString("definition")).append(","); + if (meaning.has( "adjective" )) { + JSONArray adjective = meaning.getJSONArray( "adjective" ); + def.append( "\n" ).append( adjective.getJSONObject( 0 ).getString( "definition" ) ).append( "\n" ); } - //def.append(js.getString("word")); - //def.append("/n" + js.getJSONArray("meaning")); - } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/ColorGame/ColorAdapter.java b/app/src/main/java/com/dsciitp/shabd/Learn/ColorGame/ColorAdapter.java new file mode 100644 index 0000000..5483ba0 --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/ColorGame/ColorAdapter.java @@ -0,0 +1,71 @@ +package com.dsciitp.shabd.Learn.ColorGame; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.widget.CardView; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.dsciitp.shabd.R; + +import java.util.ArrayList; + +public class ColorAdapter extends RecyclerView.Adapter { + + + private Context context; + private ArrayList mylist; + public ColorAdapter.OnCategorySelectedListener callback; + + ColorAdapter(ArrayList mylist, Context context, ColorAdapter.OnCategorySelectedListener listener) { + this.mylist = mylist; + callback = listener; + this.context = context; + + } + + public interface OnCategorySelectedListener { + void onTopicSelected(int pos); + } + + @NonNull + @Override + public ColorAdapter.ColorHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from( parent.getContext() ).inflate( R.layout.color_card, parent, false ); + return new ColorHolder( view ); + } + + @Override + public void onBindViewHolder(@NonNull final ColorAdapter.ColorHolder holder, final int position) { + + int e = mylist.get( holder.getAdapterPosition() ); + + holder.cardCardView.setCardBackgroundColor( e ); + holder.cardCardView.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + callback.onTopicSelected( holder.getAdapterPosition() ); + + } + } ); + + + } + + @Override + public int getItemCount() { + return mylist.size(); + } + + class ColorHolder extends RecyclerView.ViewHolder { + CardView cardCardView; + + ColorHolder(@NonNull View itemView) { + super( itemView ); + cardCardView = itemView.findViewById( R.id.card_color ); + } + } + +} diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/ColorGame/ColorGameActivity.java b/app/src/main/java/com/dsciitp/shabd/Learn/ColorGame/ColorGameActivity.java new file mode 100644 index 0000000..c8f5413 --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/ColorGame/ColorGameActivity.java @@ -0,0 +1,212 @@ +package com.dsciitp.shabd.Learn.ColorGame; + +import android.content.SharedPreferences; +import android.graphics.Color; +import android.media.MediaPlayer; +import android.os.Bundle; +import android.os.CountDownTimer; +import android.os.Handler; +import android.preference.PreferenceManager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.dsciitp.shabd.Learn.Video.VideoAdapter; +import com.dsciitp.shabd.R; + +import java.util.ArrayList; +import java.util.Random; + +public class ColorGameActivity extends AppCompatActivity implements ColorAdapter.OnCategorySelectedListener { + private ArrayList colours; + private ColorAdapter colorAdapter; + private RecyclerView colorRecycler; + private int d, span; + SharedPreferences preferences; + + int totalQuestions; + int correctQuestions; + + TextView pointsTextView; + TextView resultTextView; + TextView timeTextView; + Button playAgainButton; + MediaPlayer mediaPlayer,mediaPlayer1; + CountDownTimer timer; + + int highScore; + TextView highScoreView; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_color_game ); + mediaPlayer = MediaPlayer.create( this, R.raw.clock ); + mediaPlayer1=MediaPlayer.create( this,R.raw.applause ); + getSupportActionBar().setElevation( 0f ); + getSupportActionBar().setHomeAsUpIndicator( getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp ) ); + getSupportActionBar().setTitle( getString( R.string.quiz ) ); + preferences = PreferenceManager.getDefaultSharedPreferences( this ); + highScore = preferences.getInt( "high_score_color", 0 ); + span = preferences.getInt( "span", 2 ); + preferences.edit().putInt( "span", 2 ).apply(); + highScoreView = findViewById( R.id.tv_high_score1 ); + highScoreView.setText( "HighScore = " + String.valueOf( preferences.getInt( "high_score_color", 0 ) ) ); + d = preferences.getInt( "correctanswer", 0 ); + pointsTextView = findViewById( R.id.tv_points ); + resultTextView = findViewById( R.id.tv_result ); + timeTextView = findViewById( R.id.tv_timer ); + + preferences = PreferenceManager.getDefaultSharedPreferences( this ); + colorRecycler = findViewById( R.id.learn_color_game ); + colours = new ArrayList(); + playAgainButton = findViewById( R.id.button_play_again ); + + colorRecycler.setVisibility( View.INVISIBLE ); + + playAgainButton.setText( "Play" ); + playAgainButton.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + playAgainButton.setVisibility( View.INVISIBLE ); + timeTextView.setVisibility( View.VISIBLE ); + pointsTextView.setVisibility( View.VISIBLE ); + colorRecycler.setVisibility( View.VISIBLE ); + highScoreView.setVisibility( View.INVISIBLE ); + createQuestion(); + startQuiz(); + + } + } ); + } + + private void startQuiz() { + timeTextView.setText( "30s" ); + totalQuestions = 0; + correctQuestions = 0; + pointsTextView.setText( "0/0" ); + resultTextView.setVisibility( View.INVISIBLE ); + timer = new CountDownTimer( 30100, 1000 ) { + @Override + public void onTick(long millisUntilFinished) { + + + mediaPlayer.start(); + timeTextView.setText( String.valueOf( millisUntilFinished / 1000 ) + "s" ); + } + + @Override + public void onFinish() { + mediaPlayer.pause(); + + timeTextView.setText( "0s" ); + playAgainButton.setText( "Play Again" ); + playAgainButton.setVisibility( View.VISIBLE ); + timeTextView.setVisibility( View.INVISIBLE ); + pointsTextView.setVisibility( View.INVISIBLE ); + colorRecycler.setVisibility( View.INVISIBLE ); + showScore(); + + } + }.start(); + } + + private void showScore() { + resultTextView.setVisibility( View.VISIBLE ); + resultTextView.setText( "Score = " + correctQuestions + "/" + totalQuestions ); + preferences.edit().putInt( "span", 2 ).apply(); + ; + String message; + + if (correctQuestions >= highScore) { + highScore = correctQuestions; + preferences.edit().putInt( "high_score_color", correctQuestions ).apply(); + message = "CONGRATS\nNew High Score = "; + mediaPlayer1.start(); + } else { + message = "High Score = "; + } + + highScoreView.setText( message + String.valueOf( highScore ) ); + highScoreView.setVisibility( View.VISIBLE ); + + } + + public void createQuestion() { + int a, i, b, c, span; + colours.clear(); + span = preferences.getInt( "span", 2 ); + colorRecycler.setLayoutManager( new GridLayoutManager( this, span ) ); + Random random = new Random(); + + int d = random.nextInt( span * 5 - 1 ); + preferences.edit().putInt( "correctanswer", d ).apply(); + a = random.nextInt( 256 ); + b = random.nextInt( 256 ); + c = random.nextInt( 256 ); + + int color2 = Color.argb( 255, a, b, c ); + int color1 = Color.argb( 255, a + 12, b - 11, c + 13 ); + for (i = 0; i <= span * 5 - 1; i++) { + if (i == d) + colours.add( color1 ); + else + colours.add( color2 ); + } + colorAdapter = new ColorAdapter( colours, this, (ColorAdapter.OnCategorySelectedListener) this ); + + colorRecycler.setAdapter( colorAdapter ); + } + + @Override + public void onTopicSelected(int pos) { + if (pos == preferences.getInt( "correctanswer", 0 )) { + + pointsTextView.setBackgroundColor( getResources().getColor( R.color.green ) ); + int c = preferences.getInt( "span", 2 ); + if (c <= 5) + preferences.edit().putInt( "span", ++c ).apply(); + ; + correctQuestions++; + } else { + final RecyclerView.ViewHolder g = colorRecycler.findViewHolderForAdapterPosition( preferences.getInt( "correctanswer", 0 ) ); + g.itemView.animate().scaleX( 1.3f ).scaleY( 1.3f ).setDuration( 500 ).withEndAction( new Runnable() { + @Override + public void run() { + g.itemView.animate().setDuration( 200 ).scaleX( 1 ).scaleY( 1 ).start(); + } + } ).start(); + pointsTextView.setBackgroundColor( getResources().getColor( R.color.red ) ); + } + totalQuestions++; + pointsTextView.setText( correctQuestions + "/" + totalQuestions ); + final Handler handler = new Handler(); + handler.postDelayed( new Runnable() { + @Override + public void run() { + // Do something after 5s = 5000ms + pointsTextView.setBackgroundResource( R.color.grey ); + createQuestion(); + + } + }, 700 ); + + } + + @Override + public void onBackPressed() { + if (highScoreView.getVisibility() == View.VISIBLE) { + mediaPlayer.stop(); + super.onBackPressed(); + mediaPlayer1.stop(); + } else { + timer.onFinish(); + timer.cancel(); + mediaPlayer.stop(); + } + } +} diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/Drawing/DrawingActivity.java b/app/src/main/java/com/dsciitp/shabd/Learn/Drawing/DrawingActivity.java index c5161e4..818a27e 100644 --- a/app/src/main/java/com/dsciitp/shabd/Learn/Drawing/DrawingActivity.java +++ b/app/src/main/java/com/dsciitp/shabd/Learn/Drawing/DrawingActivity.java @@ -1,21 +1,52 @@ package com.dsciitp.shabd.Learn.Drawing; + +import android.annotation.TargetApi; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Point; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.os.Environment; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.Display; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.Toast; import com.dsciitp.shabd.R; +import com.dsciitp.shabd.UserConstants; +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; +import com.google.firebase.storage.UploadTask; import com.pes.androidmaterialcolorpickerdialog.ColorPicker; +import java.io.File; +import java.io.FileOutputStream; +import java.util.Objects; import java.util.Random; import me.panavtec.drawableview.DrawableView; import me.panavtec.drawableview.DrawableViewConfig; +import static android.Manifest.permission.READ_EXTERNAL_STORAGE; +import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; + public class DrawingActivity extends AppCompatActivity { private DrawableView drawableView; @@ -24,51 +55,70 @@ public class DrawingActivity extends AppCompatActivity { private int selectedColorG; private int selectedColorB; private int selectedColorRGB; + private StorageReference mStorageRef; + private SharedPreferences counter; + private int PERMISSION_REQUEST_CODE = 200; + private int i = 0; + private Button submit; + @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_drawing2); - drawableView= findViewById(R.id.paintView); - Button strokeWidthMinusButton = findViewById(R.id.strokeWidthMinusButton); - Button strokeWidthPlusButton = findViewById(R.id.strokeWidthPlusButton); - Button changeColorButton = findViewById(R.id.changeColorButton); - Button undoButton = findViewById(R.id.undoButton); - Display display = getWindowManager(). getDefaultDisplay(); + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_drawing2 ); + submit = findViewById( R.id.submit1 ); + int drawing = getIntent().getIntExtra( "drawing", 0 ); + if (drawing != 1) + submit.setVisibility( View.VISIBLE ); + else + submit.setVisibility( View.GONE ); + counter = getSharedPreferences( "i", 0 ); + Objects.requireNonNull( getSupportActionBar() ).setHomeAsUpIndicator( getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp ) ); + getSupportActionBar().setTitle( "Draw" ); + mStorageRef = FirebaseStorage.getInstance().getReference(); + drawableView = findViewById( R.id.paintView ); + Button strokeWidthMinusButton = findViewById( R.id.strokeWidthMinusButton ); + Button strokeWidthPlusButton = findViewById( R.id.strokeWidthPlusButton ); + Button changeColorButton = findViewById( R.id.changeColorButton ); + Button undoButton = findViewById( R.id.undoButton ); + Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); - display. getSize(size); - int width = size. x; - int height = size. y-200; - final ColorPicker cp = new ColorPicker(DrawingActivity.this, 25, 30, 40); - - config= new DrawableViewConfig(); - config.setStrokeColor(getResources().getColor(android.R.color.black)); - config.setShowCanvasBounds(true); // If the view is bigger than canvas, with this the user will see the bounds (Recommended) - config.setStrokeWidth(20.0f); - config.setMinZoom(1.0f); - config.setMaxZoom(1.0f); - config.setCanvasHeight(height); - config.setCanvasWidth(width); - drawableView.setConfig(config); - strokeWidthPlusButton.setOnClickListener(new View.OnClickListener() { - - @Override public void onClick(View v) { - config.setStrokeWidth(config.getStrokeWidth() + 10); + display.getSize( size ); + int width = size.x; + int height = size.y - 200; + final ColorPicker cp = new ColorPicker( DrawingActivity.this, 25, 30, 40 ); + + config = new DrawableViewConfig(); + config.setStrokeColor( getResources().getColor( android.R.color.black ) ); + config.setShowCanvasBounds( true ); // If the view is bigger than canvas, with this the user will see the bounds (Recommended) + config.setStrokeWidth( 20.0f ); + config.setMinZoom( 1.0f ); + config.setMaxZoom( 1.0f ); + config.setCanvasHeight( height ); + config.setCanvasWidth( width ); + drawableView.setConfig( config ); + strokeWidthPlusButton.setOnClickListener( new View.OnClickListener() { + + @Override + public void onClick(View v) { + config.setStrokeWidth( config.getStrokeWidth() + 10 ); } - }); - strokeWidthMinusButton.setOnClickListener(new View.OnClickListener() { + } ); + strokeWidthMinusButton.setOnClickListener( new View.OnClickListener() { - @Override public void onClick(View v) { - config.setStrokeWidth(config.getStrokeWidth() - 10); + @Override + public void onClick(View v) { + config.setStrokeWidth( config.getStrokeWidth() - 10 ); } - }); - changeColorButton.setOnClickListener(new View.OnClickListener() { + } ); + changeColorButton.setOnClickListener( new View.OnClickListener() { - @Override public void onClick(View v) { + @Override + public void onClick(View v) { Random random = new Random(); cp.show(); - Button okColor = cp.findViewById(R.id.okColorButton); + Button okColor = cp.findViewById( R.id.okColorButton ); - okColor.setOnClickListener(new View.OnClickListener() { + okColor.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { @@ -80,18 +130,159 @@ public void onClick(View v) { /* Or the android RGB Color (see the android Color class reference) */ selectedColorRGB = cp.getColor(); config.setStrokeColor( - Color.argb(255, selectedColorR, selectedColorG, selectedColorB)); + Color.argb( 255, selectedColorR, selectedColorG, selectedColorB ) ); cp.dismiss(); } - }); + } ); } - }); - undoButton.setOnClickListener(new View.OnClickListener() { + } ); + undoButton.setOnClickListener( new View.OnClickListener() { - @Override public void onClick(View v) { + @Override + public void onClick(View v) { drawableView.undo(); } - }); + } ); + requestPermissionAndContinue(); + submit.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + save(); + } + } ); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + if(submit.getVisibility()==View.GONE) { + getMenuInflater().inflate( R.menu.drawingmenu, menu ); + Drawable drawable = menu.findItem( R.id.save ).getIcon(); + + drawable = DrawableCompat.wrap( drawable ); + DrawableCompat.setTint( drawable, ContextCompat.getColor( this, R.color.white) ); + menu.findItem( R.id.save ).setIcon( drawable ); + } + return true; + } + + private void requestPermissionAndContinue() { + if (ContextCompat.checkSelfPermission( this, WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED + && ContextCompat.checkSelfPermission( this, READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED) { + + if (ActivityCompat.shouldShowRequestPermissionRationale( this, WRITE_EXTERNAL_STORAGE ) + && ActivityCompat.shouldShowRequestPermissionRationale( this, READ_EXTERNAL_STORAGE )) { + AlertDialog.Builder alertBuilder = new AlertDialog.Builder( this ); + alertBuilder.setCancelable( true ); + alertBuilder.setTitle( "Permission necessary" ); + alertBuilder.setMessage( "jaldi do" ); + alertBuilder.setPositiveButton( android.R.string.yes, new DialogInterface.OnClickListener() { + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + public void onClick(DialogInterface dialog, int which) { + ActivityCompat.requestPermissions( DrawingActivity.this, new String[]{WRITE_EXTERNAL_STORAGE + , READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE ); + } + } ); + AlertDialog alert = alertBuilder.create(); + alert.show(); + Log.e( "", "permission denied, show dialog" ); + } else { + ActivityCompat.requestPermissions( this, new String[]{WRITE_EXTERNAL_STORAGE, + READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE ); + } + } else { + openActivity(); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + + if (requestCode == PERMISSION_REQUEST_CODE) { + if (permissions.length > 0 && grantResults.length > 0) { + + boolean flag = true; + for (int i = 0; i < grantResults.length; i++) { + if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { + flag = false; + } + } + if (flag) { + openActivity(); + } else { + finish(); + } + + } else { + finish(); + } + } else { + super.onRequestPermissionsResult( requestCode, permissions, grantResults ); + } + } + + private void openActivity() { + //add your further process after giving permission or to download images from remote server. + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.save) { + save(); + return super.onOptionsItemSelected( item ); + } + return true; + } + + private void save() { + + drawableView.setDrawingCacheEnabled( true ); + drawableView.setDrawingCacheQuality( View.DRAWING_CACHE_QUALITY_HIGH ); + Bitmap bitmap = drawableView.getDrawingCache(); + File f = new File( Environment.getExternalStorageDirectory().getAbsolutePath(), "shabd" ); + if (!f.exists()) { + f.mkdirs(); + } + SharedPreferences.Editor editor = counter.edit(); + int c = counter.getInt( "i", 1 ); + editor.putInt( "i", ++c ); + editor.apply(); + String s = "image"; + if (UserConstants.displayName != null) + s = UserConstants.displayName; + StorageReference mDrawing = mStorageRef.child( "ShabdDrawing" ).child( s ).child( c + " " ); + File file = new File( f.getAbsolutePath() + "/drawingimage" + c + ".png" ); + + FileOutputStream ostream; + try { + file.createNewFile(); + ostream = new FileOutputStream( file ); + bitmap.compress( Bitmap.CompressFormat.PNG, 100, ostream ); + Uri uri = Uri.fromFile( new File( f.getAbsolutePath() + "/drawingimage" + c + ".png" ) ); + + if (submit.getVisibility() == View.VISIBLE) { + mStorageRef.putFile( uri ); + UploadTask uploadTask = mDrawing.putFile( uri ); + uploadTask.addOnFailureListener( new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + Toast.makeText( DrawingActivity.this, "Check your network connection.Connect to Internet", Toast.LENGTH_SHORT ).show(); + } + } ).addOnSuccessListener( new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + Toast.makeText( DrawingActivity.this, "Your task is successfully submitted", Toast.LENGTH_SHORT ).show(); + } + } ); + } + ostream.flush(); + ostream.close(); + Toast.makeText( this, "Drawing saved to Gallery", Toast.LENGTH_SHORT ).show(); + } catch (Exception e) { + e.printStackTrace(); + Toast.makeText( this, "Not saved", Toast.LENGTH_SHORT ).show(); + } } } diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/LearnActivity.java b/app/src/main/java/com/dsciitp/shabd/Learn/LearnActivity.java index 398795f..5d31b9e 100644 --- a/app/src/main/java/com/dsciitp/shabd/Learn/LearnActivity.java +++ b/app/src/main/java/com/dsciitp/shabd/Learn/LearnActivity.java @@ -2,126 +2,167 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.TextView; import com.bumptech.glide.Glide; +import com.dsciitp.shabd.Learn.ColorGame.ColorGameActivity; import com.dsciitp.shabd.Learn.Drawing.DrawingActivity; import com.dsciitp.shabd.Learn.Piano.PianoActivity; +import com.dsciitp.shabd.Learn.Quiz.QuizActivity; +import com.dsciitp.shabd.Learn.Video.VideoActivity; import com.dsciitp.shabd.R; -import com.firebase.ui.firestore.FirestoreRecyclerAdapter; -import com.firebase.ui.firestore.FirestoreRecyclerOptions; -import com.google.firebase.firestore.FirebaseFirestore; -import com.google.firebase.firestore.Query; -public class LearnActivity extends AppCompatActivity { +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; - FirestoreRecyclerAdapter storiesAdapter; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Objects; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_learn); - - getSupportActionBar().setElevation(0f); - getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp)); - - FirebaseFirestore mFirestore = FirebaseFirestore.getInstance(); +public class LearnActivity extends AppCompatActivity implements LearnAdapter.OnCategorySelectedListener { - RecyclerView storyRecycler = findViewById(R.id.learn_recycler_story); - storyRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); + LearnAdapter storiesAdapter; - Query query = mFirestore.collection("stories").orderBy("position"); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_learn ); + Objects.requireNonNull( getSupportActionBar() ).setElevation( 0f ); + getSupportActionBar().setHomeAsUpIndicator( getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp ) ); + + RecyclerView storyRecycler = findViewById( R.id.learn_recycler_story ); + storyRecycler.setLayoutManager( new LinearLayoutManager( this, LinearLayoutManager.HORIZONTAL, false ) ); + ArrayList options = new ArrayList(); + + try { + JSONObject data = new JSONObject( loadJSONFromAsset() ); + JSONArray task = data.getJSONArray( "data" ); + for (int i = 0; i < task.length(); i++) { + JSONObject jo_inside = task.getJSONObject( i ); + String title = jo_inside.getString( "title" ); + String url_value = jo_inside.getString( "imageResource" ); + String hindititle = jo_inside.getString( "hindiTitle" ); + String description = jo_inside.getString( "description" ); + String intent = jo_inside.getString( "intent" ); + String intentclass = jo_inside.getString( "intentClass" ); + String classname = "com.dsciitp.shabd.Learn." + intentclass + "." + intent; + options.add( new LearnStoryModel( title, description, hindititle, url_value, Class.forName( classname ) ) ); + } + } catch (JSONException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } finally { + options.add( new LearnStoryModel( "Holiday", "", "gdfg", "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSWEXBiGxKzBLNDhHMmgrR6KBYlOOO2f0SXP5TZ3DS_UthzhOoq", null ) ); + } - FirestoreRecyclerOptions options = new FirestoreRecyclerOptions.Builder() - .setQuery(query, LearnStoryModel.class) - .build(); + storiesAdapter = new LearnAdapter( options, LearnActivity.this, (LearnAdapter.OnCategorySelectedListener) this ); + storyRecycler.setAdapter( storiesAdapter ); - storiesAdapter = new FirestoreRecyclerAdapter(options) { + ImageView learnImage2 = findViewById( R.id.learn_image_2 ); + Glide.with( this ) + .load( R.raw.play_play ) + .centerCrop() + .placeholder( R.color.transparent ) + .into( learnImage2 ); + ImageView learnImage3 = findViewById( R.id.learn_image_3 ); + Glide.with( this ) + .load( "https://s3.amazonaws.com/media.eremedia.com/wp-content/uploads/2018/04/06122011/story.jpeg" ) + .centerCrop() + .placeholder( R.color.transparent ) + .into( learnImage3 ); + ImageView learnImage4 = findViewById( R.id.learn_image_4 ); + Glide.with( this ) + .load( "http://clipartmag.com/images/quiz-clipart-24.jpg" ) + .centerCrop() + .placeholder( R.color.transparent ) + .into( learnImage4 ); + ImageView learnImage5 = findViewById( R.id.learn_image_5 ); + Glide.with( this ) + .load( "https://www.codester.com/static//uploads/items/2658/preview-xl.jpg" ) + .centerCrop() + .placeholder( R.color.transparent ) + .into( learnImage5 ); + CardView pianoCard = findViewById( R.id.learn_card_2 ); + pianoCard.setOnClickListener( new View.OnClickListener() { @Override - protected void onBindViewHolder(@NonNull StoryHolder holder, int position, @NonNull final LearnStoryModel model) { - - holder.wordTitle.setText(model.getTitle()); - - Glide.with(LearnActivity.this) - .load(model.getImageResource()) - .centerCrop() - .placeholder(R.color.transparent) - .into(holder.wordImage); - - holder.cardCardView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); + public void onClick(View v) { + startActivity( new Intent( LearnActivity.this, PianoActivity.class ) ); } - - @NonNull + } ); + CardView drawingCard = findViewById( R.id.learn_card_1 ); + drawingCard.setOnClickListener( new View.OnClickListener() { @Override - public StoryHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { - View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_learn_stories, viewGroup, false); - - return new StoryHolder(view); + public void onClick(View v) { + Intent i = new Intent( LearnActivity.this, DrawingActivity.class ); + i.putExtra( "drawing", 1 ); + startActivity( i ); } - }; - storyRecycler.setAdapter(storiesAdapter); - - ImageView learnImage2 = findViewById(R.id.learn_image_2); - Glide.with(this) - .load(R.raw.play_play) - .centerCrop() - .placeholder(R.color.transparent) - .into(learnImage2); - - CardView pianoCard = findViewById(R.id.learn_card_2); - pianoCard.setOnClickListener(new View.OnClickListener() { + } ); + CardView numberCard = findViewById( R.id.learn_card_4 ); + numberCard.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { - startActivity(new Intent(LearnActivity.this, PianoActivity.class)); + startActivity( new Intent( LearnActivity.this, QuizActivity.class ) ); } - }); - CardView drawingCard = findViewById(R.id.learn_card_1); - drawingCard.setOnClickListener(new View.OnClickListener() { + } ); + CardView videoCard = findViewById( R.id.learn_card_3 ); + videoCard.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { - startActivity(new Intent(LearnActivity.this, DrawingActivity.class)); + startActivity( new Intent( LearnActivity.this, VideoActivity.class ) ); } - }); + } ); + CardView colorCard = findViewById( R.id.learn_card_5 ); + colorCard.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity( new Intent( LearnActivity.this, ColorGameActivity.class ) ); + } + } ); + } + public String loadJSONFromAsset() { + String json = null; + try { + InputStream is = this.getAssets().open( "task_data.json" ); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read( buffer ); + is.close(); + json = new String( buffer, "UTF-8" ); + + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } + return json; } @Override public void onStop() { super.onStop(); - storiesAdapter.stopListening(); + //storiesAdapter.stopListening(); } @Override public void onStart() { super.onStart(); - storiesAdapter.startListening(); + //storiesAdapter.startListening(); } - private class StoryHolder extends RecyclerView.ViewHolder { - TextView wordTitle; - ImageView wordImage; - CardView cardCardView; + @Override + public void onTopicSelected(LearnStoryModel title) { - StoryHolder(@NonNull View itemView) { - super(itemView); - wordTitle = itemView.findViewById(R.id.card_learn_stories_title); - wordImage = itemView.findViewById(R.id.card_learn_stories_image); - cardCardView = itemView.findViewById(R.id.card_learn_stories_card); - } + if (title.getIntent() != null) + startActivity( new Intent( LearnActivity.this, title.getIntent() ) ); } } diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/LearnAdapter.java b/app/src/main/java/com/dsciitp/shabd/Learn/LearnAdapter.java new file mode 100644 index 0000000..67e353c --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/LearnAdapter.java @@ -0,0 +1,79 @@ +package com.dsciitp.shabd.Learn; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.widget.CardView; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.dsciitp.shabd.R; + +import java.util.ArrayList; + + +public class LearnAdapter extends RecyclerView.Adapter { + + + + private Context context; + private ArrayList mylist; + public LearnAdapter.OnCategorySelectedListener callback; + LearnAdapter(ArrayList mylist, Context context,LearnAdapter.OnCategorySelectedListener listener) { + this.mylist = mylist; + callback=listener; + this.context = context; + } + + public interface OnCategorySelectedListener { + void onTopicSelected(LearnStoryModel title); + } + + @NonNull + @Override + public LearnAdapter.StoryHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_learn_stories, parent, false); + return new StoryHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull final StoryHolder holder, final int position) { + LearnStoryModel e=mylist.get(holder.getAdapterPosition()); + holder.wordTitle.setText(e.getTitle()); + Glide.with(context) + .load(e.getImageResource()) + .centerCrop() + .placeholder(R.color.transparent) + .into(holder.wordImage); + holder.cardCardView.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + callback.onTopicSelected(mylist.get(holder.getAdapterPosition())); + } + } ); + + } + + @Override + public int getItemCount() { + return mylist.size(); + } + + class StoryHolder extends RecyclerView.ViewHolder { + TextView wordTitle; + ImageView wordImage; + CardView cardCardView; + + StoryHolder(@NonNull View itemView) { + super(itemView); + wordTitle = itemView.findViewById(R.id.card_learn_stories_title); + wordImage = itemView.findViewById(R.id.card_learn_stories_image); + cardCardView = itemView.findViewById(R.id.card_learn_stories_card); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/LearnStoryModel.java b/app/src/main/java/com/dsciitp/shabd/Learn/LearnStoryModel.java index 25af44e..7f7d3c7 100644 --- a/app/src/main/java/com/dsciitp/shabd/Learn/LearnStoryModel.java +++ b/app/src/main/java/com/dsciitp/shabd/Learn/LearnStoryModel.java @@ -1,17 +1,17 @@ package com.dsciitp.shabd.Learn; -public class LearnStoryModel { +public class LearnStoryModel { private String title; private String description; private String hindiTitle; private String imageResource; - private String intent; + private Class intent; public LearnStoryModel() { } - public LearnStoryModel(String title, String description, String hindiTitle, String imageResource, String intent) { + public LearnStoryModel(String title, String description, String hindiTitle, String imageResource, Class intent) { this.title = title; this.description = description; this.hindiTitle = hindiTitle; @@ -51,11 +51,11 @@ public void setTitle(String title) { this.title = title; } - public String getIntent() { + public Class getIntent() { return intent; } - public void setIntent(String intent) { + public void setIntent(Class intent) { this.intent = intent; } } diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/Quiz/QuizActivity.java b/app/src/main/java/com/dsciitp/shabd/Learn/Quiz/QuizActivity.java new file mode 100644 index 0000000..977b072 --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/Quiz/QuizActivity.java @@ -0,0 +1,224 @@ +package com.dsciitp.shabd.Learn.Quiz; + +import android.content.SharedPreferences; +import android.media.MediaPlayer; +import android.os.CountDownTimer; +import android.preference.PreferenceManager; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.os.Handler; +import android.view.View; +import android.widget.Button; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.dsciitp.shabd.R; + +import java.util.ArrayList; +import java.util.Random; + +public class QuizActivity extends AppCompatActivity { + + int locationOfCorrectAnswer; + ArrayList answers = new ArrayList(); + int totalQuestions; + int correctQuestions; + + TextView pointsTextView; + TextView resultTextView; + TextView timeTextView; + Button button1; + Button button2; + Button button3; + Button button4; + TextView questionTextView; + Button playAgainButton; + MediaPlayer mediaPlayer,mediaPlayer1; + RelativeLayout gameRelativeLayout; + CountDownTimer timer; + SharedPreferences preferences; + int highScore; + TextView highScoreView; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_quiz ); + mediaPlayer = MediaPlayer.create( QuizActivity.this, R.raw.clock ); + mediaPlayer1=MediaPlayer.create( this,R.raw.applause ); + getSupportActionBar().setElevation( 0f ); + getSupportActionBar().setHomeAsUpIndicator( getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp ) ); + getSupportActionBar().setTitle( getString( R.string.quiz ) ); + initViews(); + + } + + private void initViews() { + + preferences = PreferenceManager.getDefaultSharedPreferences( this ); + + highScore = preferences.getInt( "high_score", 0 ); + highScoreView = findViewById( R.id.tv_high_score ); + highScoreView.setText( "HighScore = " + String.valueOf( preferences.getInt( "high_score", 0 ) ) ); + + pointsTextView = findViewById( R.id.tv_points ); + resultTextView = findViewById( R.id.tv_result ); + timeTextView = findViewById( R.id.tv_timer ); + questionTextView = findViewById( R.id.tv_question ); + button1 = findViewById( R.id.button1 ); + button2 = findViewById( R.id.button2 ); + button3 = findViewById( R.id.button3 ); + button4 = findViewById( R.id.button4 ); + playAgainButton = findViewById( R.id.button_play_again ); + gameRelativeLayout = findViewById( R.id.gameRelativeLayout ); + gameRelativeLayout.setVisibility( View.INVISIBLE ); + + playAgainButton.setText( "Play" ); + + playAgainButton.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + playAgainButton.setVisibility( View.INVISIBLE ); + gameRelativeLayout.setVisibility( View.VISIBLE ); + highScoreView.setVisibility( View.INVISIBLE ); + createQuestion(); + startQuiz(); + } + } ); + + } + + private void startQuiz() { + timeTextView.setText( "30s" ); + totalQuestions = 0; + correctQuestions = 0; + mediaPlayer = MediaPlayer.create( QuizActivity.this, R.raw.clock ); + pointsTextView.setText( "0/0" ); + resultTextView.setVisibility( View.INVISIBLE ); + timer = new CountDownTimer( 30100, 1000 ) { + @Override + public void onTick(long millisUntilFinished) { + + + mediaPlayer.start(); + timeTextView.setText( String.valueOf( millisUntilFinished / 1000 ) + "s" ); + } + + @Override + public void onFinish() { + mediaPlayer.pause(); + + timeTextView.setText( "0s" ); + playAgainButton.setText( "Play Again" ); + playAgainButton.setVisibility( View.VISIBLE ); + gameRelativeLayout.setVisibility( View.INVISIBLE ); + showScore(); + + } + }.start(); + } + + private void showScore() { + resultTextView.setVisibility( View.VISIBLE ); + resultTextView.setText( "Score = " + correctQuestions + "/" + totalQuestions ); + + String message; + + if (correctQuestions >= highScore) { + highScore = correctQuestions; + preferences.edit().putInt( "high_score", correctQuestions ).apply(); + message = "CONGRATS\nNew High Score = "; + mediaPlayer1.start(); + } else { + message = "High Score = "; + } + + highScoreView.setText( message + String.valueOf( highScore ) ); + highScoreView.setVisibility( View.VISIBLE ); + + } + + public void checkAnswer(final View view) { + + int g = R.color.green; + int r = R.color.red; + if (view.getTag().toString().equals( String.valueOf( locationOfCorrectAnswer ) )) { + view.setBackgroundResource( g ); + //resultTextView.setText("Correct"); + correctQuestions++; + } else { + view.setBackgroundResource( r ); + //resultTextView.setText("Incorrect"); + } + + totalQuestions++; + pointsTextView.setText( correctQuestions + "/" + totalQuestions ); + final Handler handler = new Handler(); + handler.postDelayed( new Runnable() { + @Override + public void run() { + // Do something after 5s = 5000ms + view.setBackgroundResource( R.color.grey ); + createQuestion(); + + } + }, 300 ); + + + } + + private void createQuestion() { + + answers.clear(); + + Random random = new Random(); + + int a = random.nextInt( 30 ); + int b = random.nextInt( 30 ); + + locationOfCorrectAnswer = random.nextInt( 4 ); + int wrongAnswer; + + for (int i = 0; i < 4; i++) { + + if (i == locationOfCorrectAnswer) { + answers.add( a + b ); + } else { + wrongAnswer = random.nextInt( 30 ); + + while (wrongAnswer == (a + b)) { + wrongAnswer = random.nextInt( 30 ); + } + answers.add( wrongAnswer ); + } + + } + + String question = String.valueOf( a ) + "+" + String.valueOf( b ); + questionTextView.setText( question ); + + button1.setText( String.valueOf( answers.get( 0 ) ) ); + button2.setText( String.valueOf( answers.get( 1 ) ) ); + button3.setText( String.valueOf( answers.get( 2 ) ) ); + button4.setText( String.valueOf( answers.get( 3 ) ) ); + + } + + @Override + public void onBackPressed() { + + if(highScoreView.getVisibility()==View.VISIBLE) + { + mediaPlayer.stop(); + super.onBackPressed(); + mediaPlayer1.stop(); + } + else { + timer.onFinish(); + timer.cancel(); + mediaPlayer.stop(); + } + + } +} diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/Video/BaseViewHolder.java b/app/src/main/java/com/dsciitp/shabd/Learn/Video/BaseViewHolder.java new file mode 100644 index 0000000..baebee8 --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/Video/BaseViewHolder.java @@ -0,0 +1,25 @@ +package com.dsciitp.shabd.Learn.Video; + +import android.support.v7.widget.RecyclerView; +import android.view.View; + +public abstract class BaseViewHolder extends RecyclerView.ViewHolder { + + private int mCurrentPosition; + + public BaseViewHolder(View itemView) { + super(itemView); + } + + protected abstract void clear(); + + public void onBind(int position) { + mCurrentPosition = position; + clear(); + } + + public int getCurrentPosition() { + return mCurrentPosition; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/Video/VideoActivity.java b/app/src/main/java/com/dsciitp/shabd/Learn/Video/VideoActivity.java new file mode 100644 index 0000000..52a8bd4 --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/Video/VideoActivity.java @@ -0,0 +1,89 @@ +package com.dsciitp.shabd.Learn.Video; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +import com.dsciitp.shabd.R; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; +import com.google.firebase.firestore.Query; +import com.google.firebase.firestore.QueryDocumentSnapshot; +import com.google.firebase.firestore.QuerySnapshot; + +import java.util.ArrayList; +import java.util.Objects; + +import butterknife.BindView; +import butterknife.ButterKnife; + + +public class VideoActivity extends AppCompatActivity { + + @BindView(R.id.watch_video) + RecyclerView recyclerViewFeed; + private FirebaseFirestore mFirestore; + private Query mQuery; + private VideoAdapter recycleradapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_video ); + ButterKnife.bind( this ); + + getSupportActionBar().setElevation( 0f ); + getSupportActionBar().setHomeAsUpIndicator( getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp ) ); + getSupportActionBar().setTitle( "Educational Videos" ); + getSupportActionBar().hide(); + + final ArrayList api = new ArrayList(); + mFirestore = FirebaseFirestore.getInstance(); + recycleradapter = new VideoAdapter( api ); + final YoutubeVideo video1 = new YoutubeVideo(); + video1.setId( 1l ); + video1.setImageUrl( "https://i.ytimg.com/vi/zI-Pux4uaqM/maxresdefault.jpg" ); + video1.setTitle( "Thugs Of Hindostan - Official Trailer | Amitabh Bachchan | Aamir Khan | Katrina Kaif | Fatima" ); + video1.setVideoId( "zI-Pux4uaqM" ); + api.add( video1 ); + final long c = 0; + + mFirestore.collection( "youtubeVideos" ) + .addSnapshotListener( new EventListener() { + @Override + public void onEvent(@Nullable QuerySnapshot value, + @Nullable FirebaseFirestoreException e) { + + if (e != null) { + return; + } + for (QueryDocumentSnapshot doc : value) { + if (doc.get( "url" ) != null) { + YoutubeVideo video4 = new YoutubeVideo(); + video4.setId( c ); + video4.setImageUrl( doc.getString( "imageurl" ) ); + video4.setTitle( doc.getString( "title" ) ); + video4.setVideoId( doc.getString( "id" ) ); + api.add(Integer.parseInt( Objects.requireNonNull( doc.getString( "position" ) ) )-1,video4); + + } + } + api.remove( video1 ); + + recycleradapter.notifyDataSetChanged(); + } + + + } ); + recyclerViewFeed.setLayoutManager( new LinearLayoutManager( this, LinearLayoutManager.VERTICAL, false ) ); + recyclerViewFeed.setItemAnimator( new DefaultItemAnimator() ); + recyclerViewFeed.setAdapter( recycleradapter ); + + } + + +} diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/Video/VideoAdapter.java b/app/src/main/java/com/dsciitp/shabd/Learn/Video/VideoAdapter.java new file mode 100644 index 0000000..40f5e5b --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/Video/VideoAdapter.java @@ -0,0 +1,132 @@ +package com.dsciitp.shabd.Learn.Video; + +import android.app.Activity; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.util.DisplayMetrics; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; +import com.dsciitp.shabd.R; +import com.pierfrancescosoffritti.youtubeplayer.player.AbstractYouTubePlayerListener; +import com.pierfrancescosoffritti.youtubeplayer.player.YouTubePlayer; +import com.pierfrancescosoffritti.youtubeplayer.player.YouTubePlayerInitListener; +import com.pierfrancescosoffritti.youtubeplayer.player.YouTubePlayerView; + +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; + + +public class VideoAdapter extends RecyclerView.Adapter { + + + public static final int VIEW_TYPE_NORMAL = 1; + + private List mYoutubeVideos; + DisplayMetrics displayMetrics = new DisplayMetrics(); + + public VideoAdapter(List youtubeVideos) { + mYoutubeVideos = youtubeVideos; + } + + @NonNull + @Override + public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ViewHolder( LayoutInflater.from( parent.getContext() ).inflate( R.layout.youtubeapi, parent, false ) ); + } + + @Override + public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) { + holder.onBind( holder.getAdapterPosition() ); + } + + + @Override + public int getItemViewType(int position) { + return VIEW_TYPE_NORMAL; + } + + @Override + public int getItemCount() { + + if (mYoutubeVideos != null && mYoutubeVideos.size() > 0) { + return mYoutubeVideos.size(); + } else { + return 1; + } + } + + public void setItems(List youtubeVideos) { + mYoutubeVideos = youtubeVideos; + notifyDataSetChanged(); + } + + + public class ViewHolder extends BaseViewHolder { + @BindView(R.id.textViewTitle) + TextView textWaveTitle; + @BindView(R.id.btnPlay) + ImageView playButton; + + @BindView(R.id.imageViewItem) + ImageView imageViewItems; + @BindView(R.id.youtube_view) + YouTubePlayerView youTubePlayerView; + + public ViewHolder(View itemView) { + super( itemView ); + ButterKnife.bind( this, itemView ); + } + + protected void clear() { + + } + + public void onBind(int position) { + super.onBind( position ); + final YoutubeVideo mYoutubeVideo = mYoutubeVideos.get( position ); + ((Activity) itemView.getContext()).getWindowManager().getDefaultDisplay().getMetrics( displayMetrics ); + int width = displayMetrics.widthPixels; + if (mYoutubeVideo.getTitle() != null) + textWaveTitle.setText( mYoutubeVideo.getTitle() ); + + if (mYoutubeVideo.getImageUrl() != null) { + Glide.with( itemView.getContext() ) + .load( mYoutubeVideo.getImageUrl() ). + apply( new RequestOptions().override( width - 36, 200 ) ) + .into( imageViewItems ); + } + imageViewItems.setVisibility( View.VISIBLE ); + playButton.setVisibility( View.VISIBLE ); + youTubePlayerView.setVisibility( View.GONE ); + + playButton.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View view) { + imageViewItems.setVisibility( View.GONE ); + youTubePlayerView.setVisibility( View.VISIBLE ); + playButton.setVisibility( View.GONE ); + youTubePlayerView.initialize( new YouTubePlayerInitListener() { + @Override + public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) { + initializedYouTubePlayer.addListener( new AbstractYouTubePlayerListener() { + @Override + public void onReady() { + initializedYouTubePlayer.loadVideo( mYoutubeVideo.getVideoId(), 0 ); + initializedYouTubePlayer.setVolume( 100 ); + } + } ); + } + }, true ); + } + } ); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/dsciitp/shabd/Learn/Video/YoutubeVideo.java b/app/src/main/java/com/dsciitp/shabd/Learn/Video/YoutubeVideo.java new file mode 100644 index 0000000..8318897 --- /dev/null +++ b/app/src/main/java/com/dsciitp/shabd/Learn/Video/YoutubeVideo.java @@ -0,0 +1,40 @@ +package com.dsciitp.shabd.Learn.Video; + +public class YoutubeVideo { + private String title; + private Long id; + private String videoId; + private String imageUrl; + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getVideoId() { + return videoId; + } + + public void setVideoId(String videoId) { + this.videoId = videoId; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/dsciitp/shabd/MainActivity.java b/app/src/main/java/com/dsciitp/shabd/MainActivity.java index f4bc282..b7c576c 100644 --- a/app/src/main/java/com/dsciitp/shabd/MainActivity.java +++ b/app/src/main/java/com/dsciitp/shabd/MainActivity.java @@ -50,15 +50,16 @@ public class MainActivity extends AppCompatActivity implements HomeRecyclerAdapt EditText speak; ImageView play; ImageView del; - Toolbar topbar; + Toolbar topBar; Resources res; Point size; Realm realm; - RelativeLayout speakbar; + RelativeLayout speakBar; private List activeFragment = new ArrayList<>(); private static final String TTS_SPEAK_ID = "SPEAK"; + private BottomNavigationView navigation; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -68,66 +69,69 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.navigation_home: showTopBar(); - speakbar.setVisibility(View.INVISIBLE); - updateFragment(new HomeFragment(), 0); + speakBar.setVisibility( View.VISIBLE ); + updateFragment( new HomeFragment(), 0 ); return true; case R.id.navigation_quick: showTopBar(); - updateFragment(new QuickActionFragment(), 1); + speakBar.setVisibility( View.VISIBLE ); + transactFragment( new QuickActionFragment() ); return true; case R.id.navigation_dictionary: - startActivity(new Intent(MainActivity.this, DictionaryActivity.class)); + startActivity( new Intent( MainActivity.this, DictionaryActivity.class ) ); return true; case R.id.navigation_settings: hideTopBar(); - updateFragment(new SettingFragment(), 1); + transactFragment( new SettingFragment() ); return true; case R.id.navigation_learn: - startActivity(new Intent(MainActivity.this, LearnActivity.class)); + startActivity( new Intent( MainActivity.this, LearnActivity.class ) ); return true; } return false; } }; + @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_main ); setLocale(); - speakbar = findViewById(R.id.speakbar); - BottomNavigationView navigation = findViewById(R.id.navigation); - navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - navigation.setSelectedItemId(R.id.navigation_home); + speakBar = findViewById( R.id.speakbar ); + navigation = findViewById( R.id.navigation ); + navigation.setOnNavigationItemSelectedListener( mOnNavigationItemSelectedListener ); + navigation.setSelectedItemId( R.id.navigation_home ); RealmConfiguration config = new RealmConfiguration.Builder() - .schemaVersion(2) + .schemaVersion( 2 ) .deleteRealmIfMigrationNeeded() .build(); - realm = Realm.getInstance(config); + realm = Realm.getInstance( config ); - speakbar.setVisibility(View.INVISIBLE); - setBaseFragment(savedInstanceState); + speakBar.setVisibility( View.INVISIBLE ); + setBaseFragment( savedInstanceState ); initSpeakBar(); Display display = getWindowManager().getDefaultDisplay(); size = new Point(); - display.getSize(size); + display.getSize( size ); } + private void setBaseFragment(Bundle savedInstanceState) { - if (findViewById(R.id.fragment_container) != null) { + if (findViewById( R.id.fragment_container ) != null) { if (savedInstanceState != null) { return; } HomeFragment firstFragment = new HomeFragment(); - firstFragment.setArguments(getIntent().getExtras()); + firstFragment.setArguments( getIntent().getExtras() ); getSupportFragmentManager().beginTransaction() - .add(R.id.fragment_container, firstFragment).commit(); - activeFragment.add(firstFragment); + .add( R.id.fragment_container, firstFragment ).commit(); + activeFragment.add( firstFragment ); } } @@ -136,165 +140,164 @@ private void setLocale() { res = getResources(); String deviceLocale = Locale.getDefault().getLanguage(); - if (!(deviceLocale.equals("en") || deviceLocale.equals("hi"))) { - Locale locale = new Locale("en"); - Locale.setDefault(locale); + if (!(deviceLocale.equals( "en" ) || deviceLocale.equals( "hi" ))) { + Locale locale = new Locale( "en" ); + Locale.setDefault( locale ); Configuration config = new Configuration(); config.locale = locale; - res.updateConfiguration(config, null); + res.updateConfiguration( config, null ); } } private void initSpeakBar() { - speak = findViewById(R.id.speak); - play = findViewById(R.id.play); - del = findViewById(R.id.del); + speak = findViewById( R.id.speak ); + play = findViewById( R.id.play ); + del = findViewById( R.id.del ); - tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { + tts = new TextToSpeech( this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { - int result = tts.setLanguage(new Locale(Locale.getDefault().getLanguage())); + int result = tts.setLanguage( new Locale( Locale.getDefault().getLanguage() ) ); if (result == TextToSpeech.LANG_NOT_SUPPORTED) { - Log.e("TTS", "This Language is not supported"); + Log.e( "TTS", "This Language is not supported" ); } else if (result == TextToSpeech.LANG_MISSING_DATA) { - Log.e("TTS", "This Language is missing data"); + Log.e( "TTS", "This Language is missing data" ); } - tts.setPitch(1.0f); - tts.setSpeechRate(0.8f); + tts.setPitch( 1.0f ); + tts.setSpeechRate( 0.8f ); } else { - Log.e("TTS", "Initialization Failed!"); + Log.e( "TTS", "Initialization Failed!" ); } } - }); - play.setOnClickListener(new View.OnClickListener() { + } ); + play.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String toSpeak = speak.getText().toString(); - tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); + tts.speak( toSpeak, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); } - }); - del.setOnLongClickListener(new View.OnLongClickListener() { + } ); + del.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { String textString = speak.getText().toString(); if (textString.length() > 0) { - speak.setText(""); - speak.setSelection(speak.getText().length()); + speak.setText( "" ); + speak.setSelection( speak.getText().length() ); } return false; } - }); - del.setOnClickListener(new View.OnClickListener() { + } ); + del.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String textString = speak.getText().toString(); if (textString.length() > 0) { - speak.setText(textString.substring(0, textString.length() - 1)); - speak.setSelection(speak.getText().length());//position cursor at the end of the line + speak.setText( textString.substring( 0, textString.length() - 1 ) ); + speak.setSelection( speak.getText().length() );//position cursor at the end of the line } } - }); + } ); } @Override public void onTopicSelected(int id) { - Toast.makeText(this, String.valueOf(id), Toast.LENGTH_SHORT).show(); + Toast.makeText( this, String.valueOf( id ), Toast.LENGTH_SHORT ).show(); if (id != (-1)) { - RealmQuery query = realm.where(WordsInRealm.class); - query.equalTo("id", id); + RealmQuery query = realm.where( WordsInRealm.class ); + query.equalTo( "id", id ); WordsInRealm result = query.findFirst(); realm.beginTransaction(); - tts.speak(result.getTitle(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); + tts.speak( result.getTitle(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); - if (Objects.requireNonNull(result).getIsItTopic() == 1) { - Toast.makeText(this, result.getTitle(), Toast.LENGTH_SHORT).show(); + if (Objects.requireNonNull( result ).getIsItTopic() == 1) { + Toast.makeText( this, result.getTitle(), Toast.LENGTH_SHORT ).show(); - BasicFragment basicFragment = BasicFragment.newInstance(result.getTitle()); - transactFragment(basicFragment); + BasicFragment basicFragment = BasicFragment.newInstance( result.getTitle() ); + transactFragment( basicFragment ); } realm.commitTransaction(); } else { - tts.speak("holi", TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); - CategoryFragment categoryFragment = CategoryFragment.newInstance("holi"); - transactFragment(categoryFragment); + tts.speak( "holi", TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + CategoryFragment categoryFragment = CategoryFragment.newInstance( "holi" ); + transactFragment( categoryFragment ); } } @Override public void onSubTopicSelected(int id, View view) { - Toast.makeText(this, String.valueOf(id), Toast.LENGTH_SHORT).show(); + Toast.makeText( this, String.valueOf( id ), Toast.LENGTH_SHORT ).show(); - RealmQuery query = realm.where(WordsInRealm.class); - query.equalTo("id", id); + RealmQuery query = realm.where( WordsInRealm.class ); + query.equalTo( "id", id ); WordsInRealm result = query.findFirst(); realm.beginTransaction(); - tts.speak(result.getTitle(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); + tts.speak( result.getTitle(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); if (result.getIsItTopic() == 1) { - BasicFragment basicFragment = BasicFragment.newInstance(result.getTitle()); - transactFragment(basicFragment); + BasicFragment basicFragment = BasicFragment.newInstance( result.getTitle() ); + transactFragment( basicFragment ); } else { - tts.speak(result.getTitle(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); - showWordAnimation(view); - speak.append(result.getTitle() + " "); + tts.speak( result.getTitle(), TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + showWordAnimation( view ); + speak.append( result.getTitle() + " " ); } realm.commitTransaction(); } @Override public void onOnlineWordSelected(String text, View view) { - tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID); - showWordAnimation(view); - speak.append(text + " "); + tts.speak( text, TextToSpeech.QUEUE_FLUSH, null, TTS_SPEAK_ID ); + showWordAnimation( view ); + speak.append( text + " " ); } private void showWordAnimation(final View view) { - view.setEnabled(false); - view.animate().x(size.x / 3f).y(size.y / 4f).translationZBy(10f).scaleXBy(1.25f).scaleYBy(1.25f).setDuration(750).withEndAction(new Runnable() { + view.setEnabled( false ); + view.animate().x( size.x / 3f ).y( size.y / 4f ).translationZBy( 10f ).scaleXBy( 1.25f ).scaleYBy( 1.25f ).setDuration( 750 ).withEndAction( new Runnable() { @Override public void run() { - view.animate().translationX(0f).translationY(0f).translationZBy(-10f).scaleXBy(-1.25f).scaleYBy(-1.25f).setDuration(1000).setStartDelay(500).withEndAction(new Runnable() { + view.animate().translationX( 0f ).translationY( 0f ).translationZBy( -10f ).scaleXBy( -1.25f ).scaleYBy( -1.25f ).setDuration( 1000 ).setStartDelay( 500 ).withEndAction( new Runnable() { @Override public void run() { - view.setEnabled(true); + view.setEnabled( true ); } - }); + } ); } - }); + } ); } private void transactFragment(Fragment frag) { - activeFragment.add(frag); + activeFragment.add( frag ); FragmentTransaction fragmentManager = getSupportFragmentManager().beginTransaction(); - fragmentManager.setCustomAnimations(R.anim.right_in, R.anim.left_out, R.anim.left_in, R.anim.right_out) - .replace(R.id.fragment_container, frag, frag.getTag()) - .addToBackStack(frag.getTag()) + fragmentManager.replace( R.id.fragment_container, frag, frag.getTag() ) + .addToBackStack( frag.getTag() ) .commit(); - if (frag instanceof BasicFragment) { - speakbar.setVisibility(View.VISIBLE); + if (frag instanceof BasicFragment || frag instanceof QuickActionFragment || frag instanceof CategoryFragment) { + speakBar.setVisibility( View.VISIBLE ); } else { - speakbar.setVisibility(View.INVISIBLE); + speakBar.setVisibility( View.INVISIBLE ); } } private void updateFragment(Fragment fragment, int bStack) { - activeFragment.add(fragment); + activeFragment.add( fragment ); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); - transaction.replace(R.id.fragment_container, fragment); - manager.popBackStackImmediate(1, 1); + transaction.replace( R.id.fragment_container, fragment ); + manager.popBackStackImmediate( 1, 1 ); if (bStack == 1) { - transaction.addToBackStack(fragment.getTag()); + transaction.addToBackStack( fragment.getTag() ); } else if (bStack == 0) { manager.popBackStackImmediate(); } @@ -304,7 +307,7 @@ private void updateFragment(Fragment fragment, int bStack) { @Override protected void onStop() { super.onStop(); - speak.setText(""); + speak.setText( "" ); } @Override @@ -318,35 +321,60 @@ protected void onDestroy() { @Override public void onBackPressed() { - if (activeFragment.get(activeFragment.size() - 1) instanceof SettingFragment) { + if(activeFragment.get(activeFragment.size()-1)instanceof CategoryFragment) + { + activeFragment.remove( activeFragment.size() - 1 ); + super.onBackPressed(); + navigation.setSelectedItemId( R.id.navigation_home ); + } + else if (activeFragment.get( activeFragment.size() - 1 ) instanceof QuickActionFragment) { + + if (activeFragment.get( activeFragment.size() - 2 ) instanceof SettingFragment) { + hideTopBar(); + } + activeFragment.remove( activeFragment.size() - 1 ); + super.onBackPressed(); + navigation.setSelectedItemId( R.id.navigation_home ); + } else if (activeFragment.get( activeFragment.size() - 1 ) instanceof SettingFragment) { showTopBar(); - if (activeFragment.size() > 1 && activeFragment.get(activeFragment.size() - 2) instanceof BasicFragment) { - speakbar.setVisibility(View.VISIBLE); + if (activeFragment.size() > 1 && activeFragment.get( activeFragment.size() - 2 ) instanceof BasicFragment) { + speakBar.setVisibility( View.VISIBLE ); } - activeFragment.remove(activeFragment.size() - 1); + activeFragment.remove( activeFragment.size() - 1 ); + super.onBackPressed(); + navigation.setSelectedItemId( R.id.navigation_home ); - } else if (activeFragment.get(activeFragment.size() - 1) instanceof BasicFragment) { - if (activeFragment.size() > 1 && activeFragment.get(activeFragment.size() - 2) instanceof HomeFragment) { - speakbar.setVisibility(View.INVISIBLE); + } else if (activeFragment.get( activeFragment.size() - 1 ) instanceof BasicFragment) { + if (activeFragment.size() > 1 && activeFragment.get( activeFragment.size() - 2 ) instanceof HomeFragment) { + //speakBar.setVisibility( View.INVISIBLE ); } - activeFragment.remove(activeFragment.size() - 1); + activeFragment.remove( activeFragment.size() - 1 ); + super.onBackPressed(); } + else + super.onBackPressed(); + + } - super.onBackPressed(); + @Override + protected void onResume() { + navigation.setSelectedItemId( R.id.navigation_home ); + super.onResume(); } private void hideTopBar() { - if (topbar == null) topbar = findViewById(R.id.bar); - if (topbar.getVisibility() == View.VISIBLE) { - topbar.setVisibility(View.GONE); + if (topBar == null) topBar = findViewById( R.id.bar ); + if (topBar.getVisibility() == View.VISIBLE) { + topBar.setVisibility( View.GONE ); } } private void showTopBar() { - if (topbar == null) topbar = findViewById(R.id.bar); - if (topbar.getVisibility() == View.GONE) { - topbar.setVisibility(View.VISIBLE); + if (topBar == null) + topBar = findViewById( R.id.bar ); + if (topBar.getVisibility() == View.GONE) { + topBar.setVisibility( View.VISIBLE ); } } diff --git a/app/src/main/java/com/dsciitp/shabd/Setting/LanguageSettingActivity.java b/app/src/main/java/com/dsciitp/shabd/Setting/LanguageSettingActivity.java index 9a052d7..fff3c0f 100644 --- a/app/src/main/java/com/dsciitp/shabd/Setting/LanguageSettingActivity.java +++ b/app/src/main/java/com/dsciitp/shabd/Setting/LanguageSettingActivity.java @@ -1,15 +1,52 @@ package com.dsciitp.shabd.Setting; import android.os.Bundle; +import android.provider.Settings; import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.SeekBar; +import android.widget.Spinner; +import android.widget.Toast; import com.dsciitp.shabd.R; +import java.util.Objects; + +import butterknife.BindView; + public class LanguageSettingActivity extends AppCompatActivity { + + Spinner languageSpinner; + private SeekBar pitchBar = null; + private SeekBar speechBar = null; + @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_language_setting); + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_language_setting ); + Objects.requireNonNull( getSupportActionBar() ).setElevation( 0f ); + getSupportActionBar().setHomeAsUpIndicator( getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp ) ); + getSupportActionBar().setTitle( "Language and Voice Settings" ); + languageSpinner = findViewById( R.id.language_spinner ); + ArrayAdapter languageAdapter = ArrayAdapter.createFromResource( this, R.array.language_array, R.layout.spinner_item ); + languageAdapter.setDropDownViewResource( R.layout.spinner_item ); + languageSpinner.setAdapter( languageAdapter ); + languageSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + languageSpinner.setSelection( (int) id ); + Toast.makeText( LanguageSettingActivity.this, "pos is" + position, Toast.LENGTH_SHORT ).show(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + } ); + pitchBar = findViewById( R.id.pitch_seekbar ); + speechBar = findViewById( R.id.speechRate_seekbar ); } } diff --git a/app/src/main/java/com/dsciitp/shabd/Setting/SettingFragment.java b/app/src/main/java/com/dsciitp/shabd/Setting/SettingFragment.java index 1f52463..032af40 100644 --- a/app/src/main/java/com/dsciitp/shabd/Setting/SettingFragment.java +++ b/app/src/main/java/com/dsciitp/shabd/Setting/SettingFragment.java @@ -4,20 +4,30 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupWindow; +import android.widget.Spinner; import android.widget.TextView; import com.bumptech.glide.Glide; import com.dsciitp.shabd.R; import com.dsciitp.shabd.UserConstants; import com.dsciitp.shabd.signin.SigninActivity; +import com.hsalf.smilerating.BaseRating; +import com.hsalf.smilerating.SmileRating; import java.util.Objects; +import butterknife.BindView; + +import static android.content.Context.LAYOUT_INFLATER_SERVICE; + /** * A simple {@link Fragment} subclass. */ @@ -25,6 +35,9 @@ public class SettingFragment extends Fragment { private final String INTENT_ACTION = "intent_action"; private LinearLayout language_setting; + + private int rating; + public SettingFragment() { // Required empty public constructor } @@ -63,6 +76,56 @@ public void onClick(View v) { } }); + final LinearLayout settings_layout = view.findViewById(R.id.settings_fragmenr_layout); + LinearLayout rate = view.findViewById(R.id.rate_button); + rate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + LayoutInflater inflater = (LayoutInflater) + getActivity().getSystemService(LAYOUT_INFLATER_SERVICE); + View popupView = inflater.inflate(R.layout.rate_popup, null); + + SmileRating smileRating = (SmileRating)popupView.findViewById(R.id.smile_rating); + + + smileRating.setOnSmileySelectionListener(new SmileRating.OnSmileySelectionListener() { + @Override + public void onSmileySelected(@BaseRating.Smiley int smiley, boolean reselected) { + + rating=smiley; + } + } + ); + + + + // create the popup window + int width = LinearLayout.LayoutParams.WRAP_CONTENT; + int height = LinearLayout.LayoutParams.WRAP_CONTENT; + boolean focusable = true; // lets taps outside the popup also dismiss it + final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable); + + // show the popup window + // which view you pass in doesn't matter, it is only used for the window tolken + popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0); + + // dismiss the popup window when touched + + Button submit = popupView.findViewById(R.id.submit_button); + submit.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //int rating will be sent + // text also + popupWindow.dismiss(); + + } + }); + + + } + }); + ImageView profileImage = view.findViewById(R.id.profile_image); Glide.with(getContext()) .load(UserConstants.photoUri) diff --git a/app/src/main/res/drawable/ic_save_black_24dp.xml b/app/src/main/res/drawable/ic_save_black_24dp.xml new file mode 100644 index 0000000..a561d63 --- /dev/null +++ b/app/src/main/res/drawable/ic_save_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/layout_bg.xml b/app/src/main/res/drawable/layout_bg.xml new file mode 100644 index 0000000..5fb6fc6 --- /dev/null +++ b/app/src/main/res/drawable/layout_bg.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/about_shabd.xml b/app/src/main/res/layout/about_shabd.xml index 0eb660c..8ed1995 100644 --- a/app/src/main/res/layout/about_shabd.xml +++ b/app/src/main/res/layout/about_shabd.xml @@ -55,7 +55,8 @@ android:layout_marginLeft="10dp" android:layout_marginTop="25dp" android:layout_marginRight="10dp" - android:background="@drawable/rounded_edittext"> + android:orientation="vertical" + > + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_color_game.xml b/app/src/main/res/layout/activity_color_game.xml new file mode 100644 index 0000000..6351788 --- /dev/null +++ b/app/src/main/res/layout/activity_color_game.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + +