ConfigActivity: Add import menu item

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-11-08 00:50:11 -06:00
parent cd6a124c84
commit 4a98d07806
4 changed files with 33 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import com.wireguard.config.Config;
public class ConfigActivity extends BaseConfigActivity {
private static final String KEY_EDITOR_STATE = "editorState";
private static final int REQUEST_IMPORT = 1;
private static final String TAG_DETAIL = "detail";
private static final String TAG_EDIT = "edit";
private static final String TAG_LIST = "list";
@ -129,6 +130,16 @@ public class ConfigActivity extends BaseConfigActivity {
}
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (requestCode == REQUEST_IMPORT) {
if (resultCode == RESULT_OK)
VpnService.getInstance().importFrom(data.getData());
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
@ -184,6 +195,12 @@ public class ConfigActivity extends BaseConfigActivity {
// Try to make the editing fragment visible.
setIsEditing(true);
return true;
case R.id.menu_action_import:
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_IMPORT);
return true;
case R.id.menu_action_save:
// This menu item is handled by the editing fragment.
return false;

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:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z"
android:fillColor="#FFFFFF"/>
</vector>

View File

@ -6,4 +6,10 @@
android:icon="@drawable/ic_action_add"
android:showAsAction="always"
android:title="@string/add" />
<item
android:id="@+id/menu_action_import"
android:alphabeticShortcut="o"
android:icon="@drawable/ic_open"
android:showAsAction="ifRoom"
android:title="@string/import_config" />
</menu>

View File

@ -42,4 +42,5 @@
<string name="settings">Settings</string>
<string name="status">Status</string>
<string name="toggle">Toggle</string>
<string name="import_config">Import</string>
</resources>