summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2015-11-19 01:05:43 +0100
committerArne Schwabe <arne@rfc2549.org>2015-11-19 01:05:49 +0100
commite700890f2236eb873d58babd8169d7fbce4f63b3 (patch)
treeaf62c09cd6679dbd563a311891311cb3502cd471 /main
parent210ad8633d606927bb0a526df5bde0baa612b717 (diff)
Fix the hacky and ugly fileselect dialog on Android M
Request the Window Panel on Android TV (thanks Don John on G+) (closes #399)
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java27
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java5
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/FileSelect.java30
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/LogWindow.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java28
7 files changed, 70 insertions, 26 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java b/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java
new file mode 100644
index 00000000..8cdc1e90
--- /dev/null
+++ b/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2012-2015 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+
+package de.blinkt.openvpn.activities;
+
+import android.app.Activity;
+import android.app.UiModeManager;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.view.Window;
+
+public class BaseActivity extends Activity {
+ private boolean isAndroidTV() {
+ final UiModeManager uiModeManager = (UiModeManager) getSystemService(Activity.UI_MODE_SERVICE);
+ return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ if (isAndroidTV()) {
+ requestWindowFeature(Window.FEATURE_OPTIONS_PANEL);
+ }
+ super.onCreate(savedInstanceState);
+ }
+}
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java b/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java
index 180dbe64..88d4a8c8 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java
@@ -61,7 +61,7 @@ import de.blinkt.openvpn.views.FileSelectLayout;
import static de.blinkt.openvpn.views.FileSelectLayout.FileSelectCallback;
-public class ConfigConverter extends Activity implements FileSelectCallback, View.OnClickListener {
+public class ConfigConverter extends BaseActivity implements FileSelectCallback, View.OnClickListener {
public static final String IMPORT_PROFILE = "de.blinkt.openvpn.IMPORT_PROFILE";
private static final int RESULT_INSTALLPKCS12 = 7;
@@ -583,9 +583,8 @@ public class ConfigConverter extends Activity implements FileSelectCallback, Vie
@Override
protected void onCreate(Bundle savedInstanceState) {
-
- setContentView(R.layout.config_converter);
super.onCreate(savedInstanceState);
+ setContentView(R.layout.config_converter);
ImageButton fab_button = (ImageButton) findViewById(R.id.fab_save);
if (fab_button != null) {
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/FileSelect.java b/main/src/main/java/de/blinkt/openvpn/activities/FileSelect.java
index 6f779e20..3ce78b4c 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/FileSelect.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/FileSelect.java
@@ -12,6 +12,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import android.Manifest;
+import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
@@ -20,6 +22,8 @@ import android.app.AlertDialog.Builder;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Base64;
@@ -29,15 +33,16 @@ import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.fragments.FileSelectionFragment;
import de.blinkt.openvpn.fragments.InlineFileTab;
-public class FileSelect extends Activity {
+public class FileSelect extends BaseActivity {
public static final String RESULT_DATA = "RESULT_PATH";
public static final String START_DATA = "START_DATA";
public static final String WINDOW_TITLE = "WINDOW_TILE";
public static final String NO_INLINE_SELECTION = "de.blinkt.openvpn.NO_INLINE_SELECTION";
public static final String SHOW_CLEAR_BUTTON = "de.blinkt.openvpn.SHOW_CLEAR_BUTTON";
public static final String DO_BASE64_ENCODE = "de.blinkt.openvpn.BASE64ENCODE";
-
- private FileSelectionFragment mFSFragment;
+ private static final int PERMISSION_REQUEST = 23621;
+
+ private FileSelectionFragment mFSFragment;
private InlineFileTab mInlineFragment;
private String mData;
private Tab inlineFileTab;
@@ -52,7 +57,10 @@ public class FileSelect extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_dialog);
- mData = getIntent().getStringExtra(START_DATA);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+ checkPermission();
+
+ mData = getIntent().getStringExtra(START_DATA);
if(mData==null)
mData=Environment.getExternalStorageDirectory().getPath();
@@ -86,7 +94,17 @@ public class FileSelect extends Activity {
}
-
+
+
+ @TargetApi(Build.VERSION_CODES.M)
+ private void checkPermission() {
+ if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
+
+ }
+ }
+
+
public boolean showClear() {
if(mData == null || mData.equals(""))
return false;
@@ -145,8 +163,6 @@ public class FileSelect extends Activity {
mInlineFragment.setData(data);
getActionBar().selectTab(inlineFileTab); */
saveInlineData(ifile.getName(), data);
- } catch (FileNotFoundException e) {
- fe = e;
} catch (IOException e) {
fe =e;
}
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/LogWindow.java b/main/src/main/java/de/blinkt/openvpn/activities/LogWindow.java
index 579f9dde..6757cc46 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/LogWindow.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/LogWindow.java
@@ -15,7 +15,7 @@ import de.blinkt.openvpn.fragments.LogFragment;
/**
* Created by arne on 13.10.13.
*/
-public class LogWindow extends Activity {
+public class LogWindow extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java b/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
index 38600e4b..5f41b874 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
@@ -27,7 +27,7 @@ import de.blinkt.openvpn.views.SlidingTabLayout;
import de.blinkt.openvpn.views.TabBarView;
-public class MainActivity extends Activity {
+public class MainActivity extends BaseActivity {
private ViewPager mPager;
private ScreenSlidePagerAdapter mPagerAdapter;
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java
index d81968a2..ec6cccaa 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java
@@ -35,7 +35,7 @@ import de.blinkt.openvpn.views.ScreenSlidePagerAdapter;
import de.blinkt.openvpn.views.TabBarView;
-public class VPNPreferences extends Activity {
+public class VPNPreferences extends BaseActivity {
static final Class validFragments[] = new Class[] {
Settings_Authentication.class, Settings_Basic.class, Settings_IP.class,
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java
index fe6f66b0..95fa3cb2 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java
@@ -5,14 +5,6 @@
package de.blinkt.openvpn.fragments;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.TreeMap;
-
-import android.app.AlertDialog;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -24,8 +16,17 @@ import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
-import de.blinkt.openvpn.activities.FileSelect;
+import android.widget.Toast;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.TreeMap;
+
import de.blinkt.openvpn.R;
+import de.blinkt.openvpn.activities.FileSelect;
public class FileSelectionFragment extends ListFragment {
@@ -113,9 +114,10 @@ public class FileSelectionFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ super.onCreate(savedInstanceState);
}
+
private void getDir(String dirPath) {
boolean useAutoSelection = dirPath.length() < currentPath.length();
@@ -242,9 +244,9 @@ public class FileSelectionFragment extends ListFragment {
lastPositions.put(currentPath, position);
getDir(path.get(position));
} else {
- new AlertDialog.Builder(getActivity()).setIcon(R.drawable.icon)
- .setTitle("[" + file.getName() + "] " + getText(R.string.cant_read_folder))
- .setPositiveButton("OK", null).show();
+ Toast.makeText(getActivity(),
+ "[" + file.getName() + "] " + getActivity().getText(R.string.cant_read_folder),
+ Toast.LENGTH_SHORT).show();
}
} else {
selectedFile = file;