Commit 2a9fb92c authored by fallenstardust's avatar fallenstardust

shareActivity

parent fe56a18c
...@@ -283,9 +283,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -283,9 +283,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
char* fname= name; char* fname= name;
myswprintf(textBuffer, L"%ls", mainGame->lstReplayList->getListItem(sel)); myswprintf(textBuffer, L"%ls", mainGame->lstReplayList->getListItem(sel));
BufferIO::EncodeUTF8(textBuffer,fname); BufferIO::EncodeUTF8(textBuffer,fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "1share replay file=%s", fname); __android_log_print(ANDROID_LOG_DEBUG, "ygo", "share replay file=%s", fname);
android::OnShareFile(mainGame->appMain, fname, "yrp"); android::OnShareFile(mainGame->appMain, fname, "yrp");
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "2after share replay file:index=%s", fname);
mainGame->gMutex.unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
......
...@@ -6,14 +6,12 @@ ...@@ -6,14 +6,12 @@
*/ */
package cn.garymb.ygomobile; package cn.garymb.ygomobile;
import android.app.AlertDialog;
import android.app.NativeActivity; import android.app.NativeActivity;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
...@@ -31,7 +29,6 @@ import android.widget.PopupWindow; ...@@ -31,7 +29,6 @@ import android.widget.PopupWindow;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.io.File;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
...@@ -46,6 +43,7 @@ import cn.garymb.ygomobile.widget.EditWindowCompat; ...@@ -46,6 +43,7 @@ import cn.garymb.ygomobile.widget.EditWindowCompat;
import cn.garymb.ygomobile.widget.overlay.OverlayOvalView; import cn.garymb.ygomobile.widget.overlay.OverlayOvalView;
import cn.garymb.ygomobile.widget.overlay.OverlayView; import cn.garymb.ygomobile.widget.overlay.OverlayView;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_SHARE_FILE;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_START; import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_START;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_STOP; import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_STOP;
...@@ -531,25 +529,21 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -531,25 +529,21 @@ public class YGOMobileActivity extends NativeActivity implements
@Override @Override
public void shareFile(final String title, final String ext) { public void shareFile(final String title, final String ext) {
Log.i("看看", title +"." + ext);
//TODO 分享文件 //TODO 分享文件
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(YGOMobileActivity.this); Intent intent = new Intent(ACTION_SHARE_FILE);
builder.setTitle(title); intent.addCategory(Intent.CATEGORY_DEFAULT);
builder.setMessage(ext); intent.putExtra(IrrlichtBridge.EXTRA_SHARE_TYPE, title);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { intent.putExtra(IrrlichtBridge.EXTRA_SHARE_FILE, ext);
@Override intent.setPackage(getPackageName());
public void onClick(DialogInterface dialog, int which) { try {
Intent shareIntent = new Intent(Intent.ACTION_SEND); startActivity(intent);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(ext))); } catch (Throwable e) {
shareIntent.setType("*/*");//此处可发送多种文件 //ignore
startActivity(Intent.createChooser(shareIntent, "分享到")); Toast.makeText(YGOMobileActivity.this, "dev error:not found activity.", Toast.LENGTH_SHORT).show();
dialog.dismiss(); }
}
});
builder.show();
} }
}); });
} }
......
...@@ -26,6 +26,14 @@ import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint; ...@@ -26,6 +26,14 @@ import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
public final class IrrlichtBridge { public final class IrrlichtBridge {
public static final String ACTION_START = "cn.garymb.ygomobile.game.start"; public static final String ACTION_START = "cn.garymb.ygomobile.game.start";
public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop"; public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop";
/**
* @see #EXTRA_SHARE_FILE
* @see #EXTRA_SHARE_TYPE
*/
public static final String ACTION_SHARE_FILE = "cn.garymb.ygomobile.game.shared.file";
public static final String EXTRA_SHARE_FILE = Intent.EXTRA_STREAM;
public static final String EXTRA_SHARE_TYPE = Intent.EXTRA_TITLE;
//
public static final String EXTRA_PID = "extras.mypid"; public static final String EXTRA_PID = "extras.mypid";
public static final String EXTRA_ARGV = "extras.argv"; public static final String EXTRA_ARGV = "extras.argv";
public static final String EXTRA_ARGV_TIME_OUT = "extras.argv_timeout"; public static final String EXTRA_ARGV_TIME_OUT = "extras.argv_timeout";
......
...@@ -112,6 +112,17 @@ ...@@ -112,6 +112,17 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name="cn.garymb.ygomobile.ui.activities.ShareFileActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:theme="@style/AppTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="cn.garymb.ygomobile.game.shared.file" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity <activity
android:name="cn.garymb.ygomobile.YGOMobileActivity" android:name="cn.garymb.ygomobile.YGOMobileActivity"
android:theme="@style/AppTheme.Game" android:theme="@style/AppTheme.Game"
......
package cn.garymb.ygomobile.ui.activities;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.Nullable;
import java.io.File;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.R;
public class ShareFileActivity extends BaseActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO setContentView
setContentView(R.layout.combobox_compat_layout);
doIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
private void doIntent(Intent intent){
String title = intent.getStringExtra(IrrlichtBridge.EXTRA_SHARE_TYPE);
String ext = intent.getStringExtra(IrrlichtBridge.EXTRA_SHARE_FILE);
//TODO
Toast.makeText(this, title+"."+ext, Toast.LENGTH_LONG).show();
File shareFile = null;
if (ext.equals("yrp")) {
shareFile = new File(AppsSettings.get().getResourcePath() + "/" + Constants.CORE_REPLAY_PATH + "/" + title);
} else if (ext.equals("lua")) {
shareFile = new File(AppsSettings.get().getResourcePath()+ "/" + Constants.CORE_SINGLE_PATH + "/" + title);
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(shareFile));
shareIntent.setType("*/*");//此处可发送多种文件
startActivity(Intent.createChooser(shareIntent, "分享到"));
}
}
\ 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