Implement file picker and install methods into Modules section.

Tested and working.
This commit is contained in:
d8ahazard 2016-08-31 16:49:35 -05:00
parent 9d9fea49ca
commit 3a238e9d4b
2 changed files with 43 additions and 0 deletions

View File

@ -1,8 +1,12 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
@ -17,8 +21,11 @@ import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -30,8 +37,11 @@ public class ModulesFragment extends Fragment {
public static List<Module> listModules = new ArrayList<>(); public static List<Module> listModules = new ArrayList<>();
public static List<Module> listModulesCache = new ArrayList<>(); public static List<Module> listModulesCache = new ArrayList<>();
private static final int FILE_SELECT_CODE = 0;
private File input;
@BindView(R.id.progressBar) ProgressBar progressBar; @BindView(R.id.progressBar) ProgressBar progressBar;
@BindView(R.id.fab) FloatingActionButton fabio;
@BindView(R.id.pager) ViewPager viewPager; @BindView(R.id.pager) ViewPager viewPager;
@BindView(R.id.tab_layout) TabLayout tabLayout; @BindView(R.id.tab_layout) TabLayout tabLayout;
@ -51,8 +61,32 @@ public class ModulesFragment extends Fragment {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_module, menu); inflater.inflate(R.menu.menu_module, menu);
fabio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("*/zip");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,FILE_SELECT_CODE);
}
});
} }
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == Activity.RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = uri.getPath();
String fileName = uri.getLastPathSegment();
new Utils.FlashZIP(getActivity(), fileName, path).execute();
}
break;
}}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>