Skip to content

Commit

Permalink
added settings and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
h4mu committed Aug 4, 2017
1 parent a426ad7 commit 7421854
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 18 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LicenseActivity"></activity>
<activity android:name=".LicenseActivity" />
<activity android:name=".SettingsActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.view.View;
import android.widget.Checkable;
Expand All @@ -28,12 +30,24 @@ protected void onCreate(Bundle savedInstanceState) {
dir.setWritable(true, false);

TextView folderPathText = (TextView) findViewById(R.id.folderPathText);
folderPathText.setText(dir.getPath());
if (!dir.getAbsolutePath().startsWith("/mnt/expand/")) {
findViewById(R.id.warningLayout).setVisibility(View.VISIBLE);
folderPathText.setText(getString(R.string.path, dir));

updateWarnings();
}

private void updateWarnings() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
if (!getFilesDir().getAbsolutePath().startsWith("/mnt/expand/")) {
findViewById(R.id.warningLayout).setVisibility(sharedPref.getBoolean("locationWarningEnabled", true) ? View.VISIBLE : View.GONE);
}
}

@Override
protected void onResume() {
super.onResume();
updateWarnings();
}

public void onOpenAppSettingsButtonClick(View view) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Expand All @@ -42,10 +56,20 @@ public void onOpenAppSettingsButtonClick(View view) {
}

public void onFolderButtonClick(View view) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
boolean enableIntentData = sharedPref.getBoolean("enableIntentData", true);
boolean enableIntentType = sharedPref.getBoolean("enableIntentType", true);
String intentType = sharedPref.getString("intentType", "resource/folder");

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.fromFile(getFilesDir()));
if (!((Checkable) findViewById(R.id.enableActivityAttachmentSwitch)).isChecked()) {
intent.setType("resource/folder");
if (enableIntentData && enableIntentType) {
intent.setDataAndType(Uri.fromFile(getFilesDir()), intentType);
}
else if (enableIntentData) {
intent.setData(Uri.fromFile(getFilesDir()));
}
else if (enableIntentType) {
intent.setType(intentType);
}

if (intent.resolveActivityInfo(getPackageManager(), 0) != null) {
Expand All @@ -62,10 +86,10 @@ public void onClipboardButtonClick(View view) {
}

public void onSettingsButtonClick(View view) {
// startActivity(new Intent(getBaseContext(), SettingsActivity.class));
startActivity(new Intent(this, SettingsActivity.class));
}

public void onLicenseButtonClick(View view) {
startActivity(new Intent(getBaseContext(), LicenseActivity.class));
startActivity(new Intent(this, LicenseActivity.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.h4mu.adoptedstorageaccess;

import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;

public class SettingsActivity extends PreferenceActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.activity_settings);
}
}
10 changes: 2 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/path"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down Expand Up @@ -49,14 +51,6 @@
android:text="@string/openAppSettings" />
</LinearLayout>

<Switch
android:id="@+id/enableActivityAttachmentSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/enableActivityAttachment" />

<Button
android:id="@+id/folderButton"
android:layout_width="match_parent"
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,15 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
&lt;http://www.gnu.org/philosophy/why-not-lgpl.html&gt;."</string>
<string name="locationWarning">Warning: Application is not installed in adopted storage. You need to install this application to the storage where you want to store your files.</string>
<string name="locationWarning">Warning: Application is not installed in adopted storage. You should install this application to the storage where you want to store your files.</string>
<string name="openAppSettings">Move to Adopted Storage</string>
<string name="enableActivityAttachment">OI File Manager mode</string>
<string name="locationWarningEnabledTtitle">Warn if not run from adopted storage</string>
<string name="locationWarningEnabledSummary">Display a warning message in red with a button that takes the user to the application settings if the application is not installed in the adopted storage to let them change the installation location.</string>
<string name="enableIntentDataTitle">Set Intent Data</string>
<string name="enableIntentDataSummary">Enable for ES File Explorer and OI File Manager</string>
<string name="enableIntentTypeTitle">Set Intent Mime Type</string>
<string name="enableIntentTypeSummary">Disable for OI File Manager</string>
<string name="intentTypeTitle">Intent Mime Type</string>
<string name="intentTypeSummary">See target applications\' intent filters</string>
</resources>
26 changes: 26 additions & 0 deletions app/src/main/res/xml/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="true"
android:key="locationWarningEnabled"
android:persistent="true"
android:summary="@string/locationWarningEnabledSummary"
android:title="@string/locationWarningEnabledTtitle"></SwitchPreference>
<SwitchPreference
android:defaultValue="true"
android:key="enableIntentData"
android:summary="@string/enableIntentDataSummary"
android:title="@string/enableIntentDataTitle"></SwitchPreference>
<SwitchPreference
android:defaultValue="true"
android:key="enableIntentType"
android:summary="@string/enableIntentTypeSummary"
android:title="@string/enableIntentTypeTitle"></SwitchPreference>
<EditTextPreference
android:defaultValue="resource/folder"
android:dependency="enableIntentType"
android:key="intentType"
android:singleLine="true"
android:summary="@string/intentTypeSummary"
android:title="@string/intentTypeTitle"></EditTextPreference>
</PreferenceScreen>

0 comments on commit 7421854

Please sign in to comment.