Skip to content

Commit

Permalink
fix dialogfragment to popupwindow
Browse files Browse the repository at this point in the history
  • Loading branch information
hurshi1 committed Aug 21, 2018
1 parent d5dda20 commit 66adbd5
Show file tree
Hide file tree
Showing 17 changed files with 326 additions and 452 deletions.
53 changes: 42 additions & 11 deletions app/src/main/java/com/github/hurshi/clickedwords/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package com.github.hurshi.clickedwords;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.github.hurshi.clickedwordslib.ClickedWords;
import com.github.hurshi.clickedwordslib.core.ClickedWords;
import com.github.hurshi.clickedwordslib.helper.ClickedWordsDisplayer;
import com.github.hurshi.clickedwordslib.ui.OnWordsDisplayListener;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements OnWordsDisplayListener {
private TextView textView1;
private TextView textView2;
private TextView textView3;
WordDetailDialog wordDetailDialog = new WordDetailDialog();

private PopupWindow popupWindow;
private TextView tv;


@Override
Expand All @@ -25,10 +35,19 @@ protected void onCreate(Bundle savedInstanceState) {
textView3 = (TextView) findViewById(R.id.textview3);

setTextViewSpanStr();

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.view_words, null);
tv = (TextView) popupView.findViewById(R.id.textview);

popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);

if (Build.VERSION.SDK_INT >= 21)
popupWindow.setElevation(20);

setClickedWords(textView1);
setClickedWords(textView2);
setClickedWords(textView3);

}

private void setTextViewSpanStr() {
Expand All @@ -38,13 +57,25 @@ private void setTextViewSpanStr() {
textView2.setText(spannableString);
}

@Override
public void wordDisplay(String words) {
tv.setText(words);
}

@Override
public void showPopupWindow(PopupWindow popupWindow, TextView textView, int offsetX, int offsetY) {
popupWindow.showAtLocation(textView, Gravity.CENTER_HORIZONTAL | Gravity.TOP, offsetX, offsetY);
}

private void setClickedWords(TextView textView) {
new ClickedWords.Builder()
.setTextView(textView)
.setWordDetailDialog(wordDetailDialog)
.setFragmentManager(getSupportFragmentManager())
.setFocusedBgColor(R.color.focusedBgColor)
.setFocusedFgColor(R.color.focusedFgColor)
.build();
ClickedWordsDisplayer.showAsPopupWindow(
new ClickedWords.Builder()
.setTextView(textView),
popupWindow,
this,
R.color.focusedFgColor,
R.color.focusedBgColor
);
}

}

This file was deleted.

18 changes: 18 additions & 0 deletions app/src/main/res/drawable/popup_window_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="8dp" />

<solid android:color="#fff" />

<!--<stroke-->
<!--android:width="1px"-->
<!--android:color="#333" />-->
<padding
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp" />

</shape>
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="40dp"
android:text="At Monday night's announcement in the East Room, Judge Kavanaugh, 53, said: Mr President, thank you. Throughout this process I have witnessed firsthand your appreciation for the vital role of the American judiciary."
android:textSize="20sp" />
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/view_words.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup_window_bg">

<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:gravity="center_horizontal"
android:text="Hello word"
android:textSize="40sp"
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 66adbd5

Please sign in to comment.