Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing dictionary #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .idea/libraries/Gradle__com_android_volley_volley_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
Expand Down Expand Up @@ -139,6 +140,7 @@
<orderEntry type="library" name="Gradle: com.android.support:slidingpanelayout-28.0.0" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:viewmodel-1.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:collections:28.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.volley:volley-1.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:cardview-v7-28.0.0-alpha3" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:documentfile-28.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:cursoradapter-28.0.0" level="project" />
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:design:28.0.0-alpha3'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.android.volley:volley:1.0.0'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -23,6 +24,7 @@
android:name=".Reader"
android:label="@string/title_activity_main2" />
<activity android:name=".NewFile"></activity>
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>

</manifest>
65 changes: 65 additions & 0 deletions app/src/main/java/com/example/etashguha/etude/Dictionary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.etashguha.etude;

import android.app.Activity;
import android.net.Uri;
import android.os.Message;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

public class Dictionary extends Thread {

Activity currentActivity;
Reader.DictionaryHandler handler;
String word;
public Dictionary(Activity activity, Reader.DictionaryHandler dictionaryHandler, String word){
currentActivity = activity;
handler = dictionaryHandler;
this.word = word;
}

public void run(){
RequestQueue requestQueue = Volley.newRequestQueue(currentActivity);
String toParse = "https://wordsapiv1.p.mashape.com/words/" + word + "/definitions";
String uri = Uri.parse(toParse)
.buildUpon()
.build().toString();

StringRequest stringRequest = new StringRequest(
Request.Method.GET, uri, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Message message = new Message();
message.obj = response;
handler.handleMessage(message);
}

}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Log.e("VolleyError", error.toString());
}

}) {

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("X-Mashape-Key", "BNrk40KgrTmshu76EmLWGokuzqvXp1JgmKbjsnrYxFk7id8pWk");
params.put("Accept", "text/plain");
return params;
}
};
requestQueue.add(stringRequest);
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/example/etashguha/etude/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
public class MainActivity extends AppCompatActivity {

MaterialButton button;
MaterialButton cancel;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.next_button);
cancel = findViewById(R.id.cancel_button);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -23,4 +31,6 @@ public void onClick(View v) {
}
});
}


}
71 changes: 66 additions & 5 deletions app/src/main/java/com/example/etashguha/etude/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,90 @@
import android.os.Message;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;

import com.github.barteksc.pdfviewer.PDFView;


public class Reader extends AppCompatActivity {

PDFView pdfView;
PausePlay pausePlayState = PausePlay.PAUSED;
PausePlay pausePlayState;
int pageNumber = 0;
Screenshot screenshot;
boolean firstTimePlaying;
Reader.SSHandler ssHandler;
SSHandler ssHandler;
DictionaryHandler dictionaryHandler;
Player player;
BottomNavigationView bottomNavigationView;
ProgressBar progBar;
Activity baseActivity;
TextView definition;
ConstraintLayout baseLayout;
BottomSheetBehavior behavior;
CoordinatorLayout coordinatorLayout;
View bottomSheet;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reader);

baseActivity = this;
player = new Player("");
final Uri uri = getIntent().getData();
pdfView = findViewById(R.id.pdfView);
progBar = findViewById(R.id.progressBar);
definition = findViewById(R.id.definition);
progBar.setVisibility(View.INVISIBLE);
coordinatorLayout = findViewById(R.id.main_content);
bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
baseLayout = findViewById(R.id.container);

baseActivity = this;
player = new Player("");
final Uri uri = getIntent().getData();
firstTimePlaying = true;
dictionaryHandler = new DictionaryHandler();
pausePlayState = PausePlay.PAUSED;
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
Log.e("onStateChanged", "onStateChanged:" + newState);
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
Log.e("onSlide", "onSlide");
}
});

baseLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("coordinates", event.getX() + " " + event.getY());
return false;
}
});

behavior.setPeekHeight(0);
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

pdfView.fromUri(uri).pages(pageNumber).load();
dictionaryHandler = new DictionaryHandler();
bottomNavigationView = findViewById(R.id.bottomNavigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
Expand Down Expand Up @@ -159,4 +205,19 @@ public void handleMessage(Message msg){
}
}
}

public class DictionaryHandler extends Handler{

public DictionaryHandler(){
super();
}

@Override
public void handleMessage(Message msg) {
String response = (String)msg.obj;
definition.setText(response.substring(response.indexOf("\"definition\":\"") + 14, response.indexOf("\",\"partOfSpeech")));

behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
}
82 changes: 66 additions & 16 deletions app/src/main/res/layout/reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="match_parent"
tools:context=".Reader">


<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
Expand All @@ -24,21 +26,69 @@
android:indeterminateTint="@color/toolbarIconColor" />
</com.github.barteksc.pdfviewer.PDFView>

<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigation"
style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
android:layout_width="match_parent"
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
app:itemIconSize="@dimen/bottom_navigation_icon_size"
app:itemIconTint="@drawable/botselector"
app:itemTextColor="@drawable/botselector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation">

</android.support.design.widget.BottomNavigationView>
tools:layout_editor_absoluteX="0dp">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigation"
style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="false"
android:background="@color/colorPrimaryDark"
app:itemIconSize="@dimen/bottom_navigation_icon_size"
app:itemIconTint="@drawable/botselector"
app:itemTextColor="@drawable/botselector"
app:layout_constraintHorizontal_bias="0.0"
app:menu="@menu/navigation">

</android.support.design.widget.BottomNavigationView>
</RelativeLayout>


<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:behavior_peekHeight="0dp"
android:fitsSystemWindows="true"
tools:layout_editor_absoluteX="0dp">

<FrameLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimaryDark"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/definition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="banaa"
android:textSize="30dp" />

</LinearLayout>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>


</android.support.constraint.ConstraintLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

}

allprojects {
Expand Down