Commit b42ff39e authored by k's avatar k

android 7.0 ydk文件

parent 0593a688
......@@ -87,6 +87,14 @@
<data android:host="*"/>
<data android:pathPattern=".*\\.ydk"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="content"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.ydk"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
......
......@@ -3,16 +3,20 @@ package cn.garymb.ygomobile;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.utils.FileUtils;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_DECK;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_GAME;
......@@ -65,11 +69,35 @@ public class GameUriManager {
}
private void doUri(Uri uri) {
if ("file".equalsIgnoreCase(uri.getScheme())) {
if ("file".equals(uri.getScheme())) {
File file = new File(uri.getPath());
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(startdeck);
} else if("content".equals(uri.getScheme())) {
try {
List<String> paths = uri.getPathSegments();
String name = "tmp_" + System.currentTimeMillis() + ".ydk";
if (paths.size() > 0) {
String tmp = paths.get(paths.size() - 1);
if (tmp.endsWith(".ydk")) {
name = tmp;
}
}
File file = new File(AppsSettings.get().getDeckDir(), name);
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
return;
} else {
FileUtils.copyFile(file.getAbsolutePath(), new FileOutputStream(pfd.getFileDescriptor()));
pfd.close();
}
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(startdeck);
} catch (Throwable e) {
throw new RuntimeException(e);
}
} else {
String host = uri.getHost();
if (!Constants.URI_HOST.equalsIgnoreCase(host)) {
......
package cn.garymb.ygomobile.ui.cards;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
......@@ -59,6 +60,13 @@ public class DeckManagerActivity3 extends BaseActivity implements OnItemDragList
mCardLoader = new CardLoader(this);
mCardLoader.setCallBack(this);
if (getIntent().hasExtra(Intent.EXTRA_TEXT)) {
String path = getIntent().getStringExtra(Intent.EXTRA_TEXT);
if (!TextUtils.isEmpty(path)) {
mPreLoad = path;
}
}
DialogPlus dlg = DialogPlus.show(this, null, getString(R.string.loading));
VUiKit.defer().when(() -> {
mCardLoader.setLimitList(mLimitManager.getTopLimit());
......
......@@ -181,6 +181,18 @@ class DeckManagerActivityImpl extends BaseCardsAcitivity implements RecyclerView
super.onDestroy();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (getIntent().hasExtra(Intent.EXTRA_TEXT)) {
String path = getIntent().getStringExtra(Intent.EXTRA_TEXT);
if (!TextUtils.isEmpty(path)) {
mPreLoad = path;
loadDeck(new File(path));
}
}
}
@Override
public void onLimitListChanged(LimitList limitList) {
......
......@@ -63,4 +63,21 @@ public class FileUtils {
}
return true;
}
public static void copyFile(String in, FileOutputStream outputStream) {
FileInputStream inputStream = null;
byte[] data = new byte[1024 * 8];
try {
inputStream = new FileInputStream(in);
int len;
while ((len = inputStream.read(data)) != -1) {
outputStream.write(data, 0, len);
}
} catch (Throwable e) {
//
} finally {
IOUtils.close(outputStream);
IOUtils.close(inputStream);
}
}
}
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