Commit 3e6b2f2f authored by fallenstardust's avatar fallenstardust

webactivity页内关键词查找

parent 96486a0b
......@@ -12,15 +12,24 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import com.tencent.smtt.export.external.interfaces.IX5WebViewBase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -32,7 +41,6 @@ import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.ServerInfo;
import cn.garymb.ygomobile.bean.ServerList;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.home.ServerListManager;
......@@ -49,12 +57,17 @@ import cn.garymb.ygomobile.utils.YGOUtil;
import ocgcore.DataManager;
import ocgcore.data.Card;
public class WebActivity extends BaseActivity {
public class WebActivity extends BaseActivity implements View.OnClickListener {
private static String TAG = "WebActivity";
/* 全局存储了扩展卡版本号,会被其他activity使用 */
private static String exCardVer;
private WebViewPlus mWebViewPlus;
private String mUrl;
private String mTitle;
private ImageButton btn_context_search;
private LinearLayout find_in_page;
private EditText et_context_keyword;
private ImageButton btn_context_search_close, btn_context_search_last, btn_context_search_next;
private Button btn_download;
private List<ServerInfo> serverInfos;
private ServerInfo mServerInfo;
......@@ -118,6 +131,8 @@ public class WebActivity extends BaseActivity {
setSupportActionBar(toolbar);
enableBackHome();
mWebViewPlus = $(R.id.webbrowser);
find_in_page = $(R.id.find_in_page);
et_context_keyword = $(R.id.context_keyword);
serverInfos = new ArrayList<>();
xmlFile = new File(this.getFilesDir(), Constants.SERVER_FILE);
initButton();
......@@ -141,6 +156,16 @@ public class WebActivity extends BaseActivity {
btn_download.setVisibility(View.GONE);
}
}
TextView.OnEditorActionListener searchListener = (v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
mWebViewPlus.findAllAsync(et_context_keyword.getText().toString());
return true;
}
return false;
};
et_context_keyword.setOnEditorActionListener(searchListener);
}
@Override
......@@ -165,6 +190,7 @@ public class WebActivity extends BaseActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
find_in_page.setVisibility(View.GONE);
if (item.getItemId() == android.R.id.home) {
onBackHome();
return true;
......@@ -213,6 +239,47 @@ public class WebActivity extends BaseActivity {
super.onDestroy();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.web_text_search:
find_in_page.setVisibility(View.VISIBLE);
break;
case R.id.ib_last:
mWebViewPlus.findNext(false);//为false时表示上一项
break;
case R.id.ib_next:
mWebViewPlus.findNext(true);//为true时表示下一项
break;
case R.id.web_text_search_close:
find_in_page.setVisibility(View.GONE);
et_context_keyword.getText().clear();//清除输入内容
mWebViewPlus.clearMatches();//清除页面上的高亮项:
break;
case R.id.web_btn_download_prerelease:
downloadfromWeb(URL_YGO233_FILE);
break;
}
}
public void initButton() {
btn_context_search = $(R.id.web_text_search);
btn_context_search.setOnClickListener(this);
btn_context_search_last = $(R.id.ib_last);
btn_context_search_last.setOnClickListener(this);
btn_context_search_next = $(R.id.ib_next);
btn_context_search_next.setOnClickListener(this);
btn_context_search_close = $(R.id.web_text_search_close);
btn_context_search_close.setOnClickListener(this);
btn_download = $(R.id.web_btn_download_prerelease);
btn_download.setOnClickListener(this);
}
public static void open(Context context, String title, String url) {
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra(Intent.EXTRA_STREAM, url);
......@@ -225,16 +292,6 @@ public class WebActivity extends BaseActivity {
WebActivity.open(context, cardInfo.Name, uri);
}
public void initButton() {
btn_download = $(R.id.web_btn_download_prerelease);
btn_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
downloadfromWeb(URL_YGO233_FILE);
}
});
}
public void AddServer(String name, String Addr, int port, String playername) {
mServerInfo = new ServerInfo();
mServerInfo.setName(name);
......@@ -303,7 +360,7 @@ public class WebActivity extends BaseActivity {
if (files.getName().contains("-") && files.getName().contains(" new cards"))
files.delete();
}
UnzipUtils.upZipSelectFile(file, AppsSettings.get().getResourcePath(),".ypk");
UnzipUtils.upZipSelectFile(file, AppsSettings.get().getResourcePath(), ".ypk");
} catch (Exception e) {
message.what = UnzipUtils.ZIP_UNZIP_EXCEPTION;
} finally {
......
......@@ -121,7 +121,7 @@ public class CardSearcher implements View.OnClickListener {
resetButton.setOnClickListener(this);
mCardLoader = dataLoader;
// setCodeSpinner.setFirstIndex(1);
//输入即时搜索
OnEditorActionListener searchListener = (v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
......
......@@ -153,12 +153,8 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
//添加服务器
View footView = infla.inflate(R.layout.item_ic_add, null);
TextView add_server = footView.findViewById(R.id.add_server);
add_server.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mServerListManager.addServer();
}
});
add_server.setOnClickListener(this);
mServerListAdapter.addFooterView(footView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
mServerList.setLayoutManager(linearLayoutManager);
......@@ -766,6 +762,9 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
openGame();
}
break;
case R.id.add_server:
mServerListManager.addServer();
break;
case R.id.tv_banner_loading:
if (isMcNewsLoadException)
findMcNews();
......
<vector android:height="24dp" android:tint="#04D7F8"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z"/>
</vector>
<vector android:height="24dp" android:tint="#04D7F8"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"/>
</vector>
......@@ -10,11 +10,61 @@
<include layout="@layout/content_toolbar" />
<LinearLayout
android:id="@+id/find_in_page"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:weightSum="10"
android:orientation="horizontal"
android:visibility="gone">
<EditText
android:id="@+id/context_keyword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:hint="@string/find_in_page"
android:imeOptions="actionSearch"
android:inputType="textNoSuggestions"
android:maxLines="1" />
<ImageButton
android:id="@+id/ib_last"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@color/transparent"
android:src="@drawable/baseline_keyboard_arrow_up_24" />
<ImageButton
android:id="@+id/ib_next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@color/transparent"
android:src="@drawable/baseline_keyboard_arrow_down_24" />
<ImageButton
android:id="@+id/web_text_search_close"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@color/transparent"
android:src="@drawable/ic_close_black_24dp" />
</LinearLayout>
<cn.garymb.ygomobile.ui.widget.WebViewPlus
android:id="@+id/webbrowser"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/web_btn_bar"
android:layout_width="match_parent"
......@@ -28,7 +78,7 @@
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
android:text="@string/Download"
android:visibility="gone"/>
android:visibility="gone" />
</LinearLayout>
......
......@@ -11,5 +11,16 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/AppTheme.AppBarOverlay" />
app:theme="@style/AppTheme.AppBarOverlay">
<ImageButton
android:id="@+id/web_text_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:src="@drawable/ic_search"
android:background="@color/transparent">
</ImageButton>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
\ No newline at end of file
......@@ -347,4 +347,5 @@
<string name="reChatJoining">다시 로그인 중\.\.\.</string>
<string name="settings_data_language">언어</string>
<string name="settings_data_language_about">게임 데이터 언어를 변경합니다.</string>
<string name="find_in_page">" 발견:"</string>
</resources>
......@@ -102,6 +102,7 @@
<string name="deck_manager">卡组</string>
<string name="category_manager">卡组分类选择</string>
<string name="search">搜索</string>
<string name="find_in_page">输入要查找的词:</string>
<string name="search_open">过滤</string>
<string name="search_close">关闭</string>
<string name="reset">重置</string>
......
......@@ -357,4 +357,5 @@
<string name="settings_data_language_about">change language of YGOPro UI and card database </string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="find_in_page">find:</string>
</resources>
......@@ -16,9 +16,9 @@
</style>
<style name="AppTheme.Mycard" parent="AppBaseTheme">
<item name="colorPrimary">@color/mediumPurpleLight</item>
<item name="colorPrimaryDark">@color/mediumPurple</item>
<item name="colorAccent">@color/colorPrimary</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorNavy</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment