optimize: auto file size generated by touch record
docs: selector
This commit is contained in:
@@ -5,13 +5,19 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.common.ScriptOperations;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.functions.Consumer;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/2.
|
||||
@@ -22,20 +28,14 @@ public class ImportIntentActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
try {
|
||||
handleIntent(getIntent());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.edit_and_run_handle_intent_error, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
onNewIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
try {
|
||||
handleIntent(intent);
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.edit_and_run_handle_intent_error, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
@@ -45,14 +45,28 @@ public class ImportIntentActivity extends BaseActivity {
|
||||
private void handleIntent(Intent intent) throws FileNotFoundException {
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null && "content".equals(uri.getScheme())) {
|
||||
MainActivity.importScriptFileByInputStream(this, getContentResolver().openInputStream(uri));
|
||||
InputStream stream = getContentResolver().openInputStream(uri);
|
||||
new ScriptOperations(this, null)
|
||||
.importFile("", stream)
|
||||
.subscribe(new Consumer<String>() {
|
||||
@Override
|
||||
public void accept(@NonNull String s) throws Exception {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
final String path = intent.getData().getPath();
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
MainActivity.importScriptFile(this, path);
|
||||
new ScriptOperations(this, null)
|
||||
.importFile(path)
|
||||
.subscribe(new Consumer<String>() {
|
||||
@Override
|
||||
public void accept(@NonNull String s) throws Exception {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -110,6 +110,7 @@ public class HelpCatalogueActivity extends BaseActivity {
|
||||
mLoadingIndicatorView.hide();
|
||||
handleIntent();
|
||||
}
|
||||
setToolbarAsBack(mTitle);
|
||||
}
|
||||
|
||||
private void readCatalogues() {
|
||||
@@ -141,7 +142,6 @@ public class HelpCatalogueActivity extends BaseActivity {
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_help);
|
||||
setToolbarAsBack(mTitle);
|
||||
setUpRecyclerView();
|
||||
setUpLoadingView();
|
||||
}
|
||||
|
||||
@@ -94,13 +94,12 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
private OnActivityResultDelegate.Mediator mActivityResultMediator = new OnActivityResultDelegate.Mediator();
|
||||
private DrawableSaver mDrawerHeaderBackgroundSaver, mAppbarBackgroundSaver;
|
||||
private VersionGuard mVersionGuard;
|
||||
private Intent mIntentToHandle;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
checkPermissions();
|
||||
mIntentToHandle = getIntent();
|
||||
EventBus.getDefault().register(this);
|
||||
mVersionGuard = new VersionGuard(this);
|
||||
showAnnunciationIfNeeded();
|
||||
@@ -200,15 +199,6 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
.build();
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
mPagerAdapter.setOnFragmentInstantiateListener(new FragmentPagerAdapterBuilder.OnFragmentInstantiateListener() {
|
||||
@Override
|
||||
public void OnInstantiate(Fragment fragment) {
|
||||
if (fragment instanceof MyScriptListFragment && mIntentToHandle != null) {
|
||||
handleIntent(mIntentToHandle);
|
||||
mIntentToHandle = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Click(R.id.add)
|
||||
@@ -239,7 +229,8 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
dialog.dismiss();
|
||||
provider.clearCacheExceptInitialDirectory();
|
||||
new ScriptOperations(MainActivity.this, mDrawerLayout)
|
||||
.importFile(file.getPath());
|
||||
.importFile(file.getPath())
|
||||
.subscribe();
|
||||
}
|
||||
})
|
||||
.title(R.string.text_please_choose_file_to_import)
|
||||
@@ -289,59 +280,6 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
mVersionGuard.checkDeprecateAndUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
handleIntent(intent);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
String action = intent.getStringExtra(EXTRA_ACTION);
|
||||
if (action == null)
|
||||
return;
|
||||
switch (action) {
|
||||
|
||||
case ACTION_IMPORT_SCRIPT:
|
||||
handleImportScriptFile(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleImportScriptFile(Intent intent) {
|
||||
String path = intent.getStringExtra(ARGUMENT_PATH);
|
||||
if (path != null) {
|
||||
new ScriptOperations(MainActivity.this, mDrawerLayout)
|
||||
.importFile(intent.getStringExtra(ARGUMENT_PATH))
|
||||
.subscribe();
|
||||
return;
|
||||
}
|
||||
InputStream inputStream = IntentExtras.fromIntent(intent).getAndClear(ARGUMENT_INPUT_STREAM);
|
||||
new ScriptOperations(MainActivity.this, mDrawerLayout)
|
||||
.importFile("", inputStream)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void importScriptFile(Context context, String path) {
|
||||
context.startActivity(new Intent(context, MainActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
.putExtra(EXTRA_ACTION, ACTION_IMPORT_SCRIPT)
|
||||
.putExtra(ARGUMENT_PATH, path));
|
||||
}
|
||||
|
||||
public static void importScriptFileByInputStream(Context context, InputStream inputStream) {
|
||||
Intent intent = new Intent(context, MainActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
.putExtra(EXTRA_ACTION, ACTION_IMPORT_SCRIPT);
|
||||
IntentExtras.newExtras()
|
||||
.put(ARGUMENT_INPUT_STREAM, inputStream)
|
||||
.putInIntent(intent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
@Click(R.id.toolbar)
|
||||
public void OnToolbarClick() {
|
||||
mAppbarBackgroundSaver.select(this, mActivityResultMediator);
|
||||
|
||||
Reference in New Issue
Block a user