This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update back buttone example and add as actual code
- Loading branch information
1 parent
e6f4f17
commit 3171e8a
Showing
18 changed files
with
250 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.1" | ||
|
||
defaultConfig { | ||
applicationId "com.nononsenseapps.filepicker.examples" | ||
minSdkVersion 15 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile project(':library') | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:24.2.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /home/jonas/Android/Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
examples/src/androidTest/java/com/nononsenseapps/filepicker/examples/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.nononsenseapps.filepicker.examples; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.nononsenseapps.filepicker.examples"> | ||
|
||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<!-- Only needed to create sub directories. --> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/FilePickerTheme"> | ||
|
||
<activity | ||
android:name=".backbutton.BackHandlingFilePickerActivity" | ||
android:label="Override back button" | ||
android:theme="@style/FilePickerTheme"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
48 changes: 48 additions & 0 deletions
48
...ava/com/nononsenseapps/filepicker/examples/backbutton/BackHandlingFilePickerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.nononsenseapps.filepicker.examples.backbutton; | ||
|
||
import android.os.Environment; | ||
import com.nononsenseapps.filepicker.AbstractFilePickerFragment; | ||
import com.nononsenseapps.filepicker.FilePickerActivity; | ||
import java.io.File; | ||
|
||
public class BackHandlingFilePickerActivity extends FilePickerActivity { | ||
|
||
/** | ||
* Need access to the fragment | ||
*/ | ||
BackHandlingFilePickerFragment currentFragment; | ||
|
||
/** | ||
* Return a copy of the new fragment and set the variable above. | ||
*/ | ||
@Override | ||
protected AbstractFilePickerFragment<File> getFragment( | ||
final String startPath, final int mode, final boolean allowMultiple, | ||
final boolean allowDirCreate, final boolean allowExistingFile, | ||
final boolean singleClick) { | ||
|
||
// startPath is allowed to be null. | ||
// In that case, default folder should be SD-card and not "/" | ||
String path = (startPath != null ? startPath | ||
: Environment.getExternalStorageDirectory().getPath()); | ||
|
||
currentFragment = new BackHandlingFilePickerFragment(); | ||
currentFragment.setArgs(path, mode, allowMultiple, allowDirCreate, | ||
allowExistingFile, singleClick); | ||
return currentFragment; | ||
} | ||
|
||
/** | ||
* Override the back-button. | ||
*/ | ||
@Override | ||
public void onBackPressed() { | ||
// If at top most level, normal behaviour | ||
if (currentFragment.isBackTop()) { | ||
super.onBackPressed(); | ||
} else { | ||
// Else go up | ||
currentFragment.goUp(); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ava/com/nononsenseapps/filepicker/examples/backbutton/BackHandlingFilePickerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.nononsenseapps.filepicker.examples.backbutton; | ||
|
||
import com.nononsenseapps.filepicker.FilePickerFragment; | ||
import java.io.File; | ||
|
||
public class BackHandlingFilePickerFragment extends FilePickerFragment { | ||
|
||
/** | ||
* For consistency, the top level the back button checks against should be the start path. | ||
* But it will fall back on /. | ||
*/ | ||
public File getBackTop() { | ||
if (getArguments().containsKey(KEY_START_PATH)) { | ||
return getPath(getArguments().getString(KEY_START_PATH)); | ||
} else { | ||
return new File("/"); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @return true if the current path is the startpath or / | ||
*/ | ||
public boolean isBackTop() { | ||
return 0 == compareFiles(mCurrentPath, getBackTop()) || 0 == compareFiles(mCurrentPath, new File("/")); | ||
} | ||
|
||
/** | ||
* Go up on level, same as pressing on "..". | ||
*/ | ||
public void goUp() { | ||
mCurrentPath = getParent(mCurrentPath); | ||
mCheckedItems.clear(); | ||
mCheckedVisibleViewHolders.clear(); | ||
refresh(mCurrentPath); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="primary2">#F44336</color> | ||
<color name="primary_dark2">#D32F2F</color> | ||
<color name="accent2">#FFAB00</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">Examples</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<resources> | ||
|
||
<style name="FilePickerTheme" parent="NNF_BaseTheme"> | ||
<item name="colorPrimary">@color/primary2</item> | ||
<item name="colorPrimaryDark">@color/primary_dark2</item> | ||
<item name="colorAccent">@color/accent2</item> | ||
|
||
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item> | ||
</style> | ||
|
||
<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert"> | ||
<item name="colorPrimary">@color/primary2</item> | ||
<item name="colorPrimaryDark">@color/primary_dark2</item> | ||
<item name="colorAccent">@color/accent2</item> | ||
</style> | ||
|
||
</resources> |
15 changes: 15 additions & 0 deletions
15
examples/src/test/java/com/nononsenseapps/filepicker/examples/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.nononsenseapps.filepicker.examples; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* To work on unit tests, switch the Test Artifact in the Build Variants view. | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() throws Exception { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters