Commit f723e29c authored by kenan's avatar kenan

Fix 分享

parent fc045ade
......@@ -1002,12 +1002,18 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
ChangeToIGUIImageButton(btnReplayCancel, imageManager.tButton_S, imageManager.tButton_S_pressed);
env->addStaticText(dataManager.GetSysString(1349), rect<s32>(320 * xScale, 30 * yScale, 550 * xScale, 50 * yScale), false, true, wReplay);
stReplayInfo = env->addStaticText(L"", rect<s32>(320 * xScale, 60 * yScale, 570 * xScale, 315 * yScale), false, true, wReplay);
env->addStaticText(dataManager.GetSysString(1353), rect<s32>(320 * xScale, 240 * yScale, 550 * xScale, 260 * yScale), false, true, wReplay);
ebRepStartTurn = CAndroidGUIEditBox::addAndroidEditBox(L"", true, env, rect<s32>(320 * xScale, 260 * yScale, 430 * xScale, 300 * yScale), wReplay, -1);
env->addStaticText(dataManager.GetSysString(1353), rect<s32>(320 * xScale, 180 * yScale, 550 * xScale, 200 * yScale), false, true, wReplay);
ebRepStartTurn = CAndroidGUIEditBox::addAndroidEditBox(L"", true, env, rect<s32>(320 * xScale, 210 * yScale, 430 * xScale, 250 * yScale), wReplay, -1);
ebRepStartTurn->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
btnExportDeck = env->addButton(rect<s32>(440 * xScale, 260 * yScale, 550 * xScale, 300 * yScale), wReplay, BUTTON_EXPORT_DECK, dataManager.GetSysString(1282));
ChangeToIGUIImageButton(btnExportDeck, imageManager.tButton_S, imageManager.tButton_S_pressed);
//single play window
btnShareReplay = env->addButton(rect<s32>(320 * xScale, 260 * yScale, 430 * xScale, 300 * yScale), wReplay, BUTTON_SHARE_REPLAY, dataManager.GetSysString(1368));
ChangeToIGUIImageButton(btnShareReplay, imageManager.tButton_S, imageManager.tButton_S_pressed);
//single play window
wSinglePlay = env->addWindow(rect<s32>(220 * xScale, 100 * yScale, 800 * xScale, 520 * yScale), false, dataManager.GetSysString(1201));
wSinglePlay->getCloseButton()->setVisible(false);
wSinglePlay->setDrawBackground(false);
......
......@@ -385,6 +385,7 @@ public:
irr::gui::IGUIButton* btnReplayCancel;//
irr::gui::IGUIButton* btnExportDeck;//
irr::gui::IGUIEditBox* ebRepStartTurn;
irr::gui::IGUIButton* btnShareReplay;
//single play
irr::gui::IGUIWindow* wSinglePlay;
irr::gui::IGUIImage* bgSinglePlay;
......@@ -732,6 +733,7 @@ private:
#define BUTTON_DELETE_REPLAY 133
#define BUTTON_RENAME_REPLAY 134
#define BUTTON_EXPORT_DECK 135
#define BUTTON_SHARE_REPLAY 136
#define BUTTON_REPLAY_START 140
#define BUTTON_REPLAY_PAUSE 141
#define BUTTON_REPLAY_STEP 142
......
......@@ -119,6 +119,7 @@ int main(int argc, char* argv[]) {
ygo::mainGame->lstReplayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadReplay);
}
break;//只播放一个
} else if(!strcmp(arg, "-s")) { // Single
exit_on_return = !keep_on_return;
......
......@@ -273,6 +273,24 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
prev_sel = sel;
break;
}
case BUTTON_SHARE_REPLAY: {
int sel = mainGame->lstReplayList->getSelected();
if(sel == -1)
break;
mainGame->gMutex.lock();
char name[1024];
BufferIO::EncodeUTF8(mainGame->lstReplayList->getListItem(sel), name);
mainGame->gMutex.unlock();
prev_operation = id;
prev_sel = sel;
#if defined(_IRR_ANDROID_PLATFORM_)
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "1share replay file=%s", name);
android::OnShareFile(mainGame->appMain, "yrp", name);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "2after share replay file:index=%d", sel);
#endif
break;
}
case BUTTON_RENAME_REPLAY: {
int sel = mainGame->lstReplayList->getSelected();
if(sel == -1)
......
......@@ -796,7 +796,7 @@ int getLocalAddr(ANDROID_APP app) {
if (!app || !app->activity || !app->activity->vm)
return addr;
JNIEnv* jni = nullptr;
app->activity->vm->AttachCurrentThread(&jni, NULL);
app->activity->vm->AttachCurrentThread(&jni, nullptr);
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID MethodGetAddr = jni->GetMethodID(ClassNativeActivity,
......@@ -807,24 +807,6 @@ int getLocalAddr(ANDROID_APP app) {
return addr;
}
void OnShareFile(ANDROID_APP app, char* title, char* path){
if (!app || !app->activity || !app->activity->vm)
return;
JNIEnv* jni = nullptr;
app->activity->vm->AttachCurrentThread(&jni, nullptr);
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID MethodGetAddr = jni->GetMethodID(ClassNativeActivity,
"shareFile", "(Ljava/lang/String;Ljava/lang/String;)V");
jstring s_title = jni->NewStringUTF(title);
jstring s_path = jni->NewStringUTF(path);
jni->CallVoidMethod(lNativeActivity, MethodGetAddr, s_title, s_path);
jni->ReleaseStringUTFChars(s_title, title);
jni->ReleaseStringUTFChars(s_path, path);
jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread();
}
void showAndroidComboBoxCompat(ANDROID_APP app, bool pShow, char** pContents,
int count, int mode) {
if (!app || !app->activity || !app->activity->vm)
......@@ -985,6 +967,31 @@ bool android_deck_delete(const char* deck_name) {
return status == 0;
}
void OnShareFile(ANDROID_APP app,const char* title,const char* path){
if (!app || !app->activity || !app->activity->vm)
return;
JNIEnv* jni = nullptr;
app->activity->vm->AttachCurrentThread(&jni, nullptr);
if (!jni)
return;
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID methodId = jni->GetMethodID(ClassNativeActivity, "shareFile", "(Ljava/lang/String;Ljava/lang/String;)V");
jstring s_title = jni->NewStringUTF(title);
jstring s_path = jni->NewStringUTF(path);
jni->CallVoidMethod(lNativeActivity, methodId, s_title, s_path);
if (s_title) {
//不需要用ReleaseStringUTFChars,因为是c变量,函数外面自己释放
jni->DeleteLocalRef(s_title);
}
if (s_path) {
jni->DeleteLocalRef(s_path);
}
jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread();
}
void runWindbot(ANDROID_APP app, const char* args) {
if (!app || !app->activity || !app->activity->vm)
return;
......
......@@ -98,7 +98,7 @@ extern float getScreenWidth(ANDROID_APP app);
extern float getScreenHeight(ANDROID_APP app);
extern void OnShareFile(ANDROID_APP app, char* title, char* path);
extern void OnShareFile(ANDROID_APP app,const char* title,const char* path);
// Get SDCard path.
extern irr::io::path getExternalStorageDir(ANDROID_APP app);
......
......@@ -410,6 +410,7 @@
!system 1365 重命名失败,可能存在同名文件
!system 1366 自动保存录像
!system 1367 录像已自动保存为%ls.yrp
!system 1368 分享录像
!system 1370 星数↑
!system 1371 攻击↑
!system 1372 守备↑
......
......@@ -107,7 +107,7 @@
android:name="cn.garymb.ygomobile.ui.activities.ShareFileActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:theme="@style/AppTheme"
android:theme="@style/TranslucentTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="cn.garymb.ygomobile.game.shared.file" />
......@@ -213,7 +213,15 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
<uses-permission android:name="android.permission.INTERNET" />
......
......@@ -27,6 +27,9 @@ public class LogoActivity extends Activity {
finish();
return;
} else {
// File file = new File(AppsSettings.get().getDeckDir(), "1.ydk");
// Uri uri = FileUtils.toUri(this, file);
// Log.w("kk-test", file.getAbsolutePath() + "->" + uri);
handler = new Handler();
runnable = new Runnable() {
@Override
......
package cn.garymb.ygomobile.ui.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.Nullable;
import cn.garymb.ygomobile.core.IrrlichtBridge;
public class ShareFileActivity extends BaseActivity{
public class ShareFileActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO setContentView
doIntent(getIntent());
hideBottomUIMenu();
}
@Override
......@@ -21,9 +25,26 @@ public class ShareFileActivity extends BaseActivity{
super.onNewIntent(intent);
}
private void doIntent(Intent intent){
private void doIntent(Intent intent) {
String type = intent.getStringExtra(IrrlichtBridge.EXTRA_SHARE_TYPE);
String path = intent.getStringExtra(IrrlichtBridge.EXTRA_SHARE_FILE);
//TODO
Toast.makeText(this, "type=" + type + ",path=" + path, Toast.LENGTH_SHORT).show();
finish();
}
protected void hideBottomUIMenu() {
//隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
// View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
}
package cn.garymb.ygomobile.utils;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import androidx.core.content.FileProvider;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
......@@ -17,6 +21,10 @@ import java.util.List;
public class FileUtils {
public static Uri toUri(Context context, File file){
return FileProvider.getUriForFile(context, context.getPackageName()+".fileprovider", file);
}
public static boolean deleteFile(File file) {
if (file.isFile()) {
try {
......
......@@ -32,7 +32,6 @@
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="AppTheme.Translucent" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
</style>
......
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<root-path name="root" path="." />
<files-path name="files" path="." />
<cache-path name="cache" path="." />
<external-path name="external" path="." />
<!--/storage/emulated/0/Android/data/${applicationId}/files/ygocore-->
<external-files-path name="game_path" path="ygocore"/>
</paths>
\ No newline at end of file
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