From bc8bf63699adcab49fc94bb2f2b85e03195232ce Mon Sep 17 00:00:00 2001 From: ligi Date: Fri, 13 Mar 2015 15:34:45 +0100 Subject: [PATCH] Introduce a FloatingAction menu and open via Storage Access Framework when available --- build.gradle | 6 +- .../org/ligi/passandroid/ui/FABCallback.java | 43 ----------- .../ligi/passandroid/ui/PassListActivity.java | 72 +++++++++++++++---- src/main/res/layout/pass_list.xml | 69 +++++++++++++++--- src/main/res/values/arrays.xml | 8 --- src/main/res/values/strings.xml | 1 - src/main/res/values/styles.xml | 7 ++ 7 files changed, 128 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/org/ligi/passandroid/ui/FABCallback.java delete mode 100644 src/main/res/values/arrays.xml diff --git a/build.gradle b/build.gradle index 6c452363..3e27f5f8 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ android { versionCode 249 versionName "2.4.9" minSdkVersion 9 - targetSdkVersion 21 + targetSdkVersion 22 applicationId "org.ligi.passandroid" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -110,7 +110,8 @@ dependencies { compile 'com.android.support:appcompat-v7:22.0.0' compile 'com.android.support:cardview-v7:22.0.0' - compile 'com.melnykov:floatingactionbutton:1.2.0' + compile 'net.i2p.android.ext:floatingactionbutton:1.8.0' + compile 'com.afollestad:material-dialogs:0.6.3.4' compile 'org.ligi:AXT:0.33' @@ -122,7 +123,6 @@ dependencies { compile 'com.google.code.findbugs:jsr305:3.0.0' androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0' - //compile 'fr.baloomba:viewpagerindicator:2.4.2' compile('com.mcxiaoke.viewpagerindicator:library:2.4.1') { exclude group: 'com.android.support' } diff --git a/src/main/java/org/ligi/passandroid/ui/FABCallback.java b/src/main/java/org/ligi/passandroid/ui/FABCallback.java deleted file mode 100644 index 457037e3..00000000 --- a/src/main/java/org/ligi/passandroid/ui/FABCallback.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.ligi.passandroid.ui; - -import android.app.Activity; -import android.content.Intent; -import android.view.View; - -import com.afollestad.materialdialogs.MaterialDialog; - -import org.ligi.axt.AXT; -import org.ligi.passandroid.App; -import org.ligi.passandroid.helper.PassUtil; -import org.ligi.passandroid.model.FiledPass; - -class FABCallback implements MaterialDialog.ListCallback { - - private final Activity activityContext; - - FABCallback(Activity activityContext) { - this.activityContext = activityContext; - } - - @Override - public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) { - switch (i) { - case 0: // scan - final Intent intent = new Intent(activityContext, SearchPassesIntentService.class); - activityContext.startService(intent); - break; - - case 1: // demo-pass - AXT.at(activityContext).startCommonIntent().openUrl("http://ligi.de/passandroid_samples/index.html"); - break; - - case 2: // add - final FiledPass pass = PassUtil.createEmptyPass(); - App.getPassStore().setCurrentPass(pass); - pass.save(App.getPassStore()); - AXT.at(activityContext).startCommonIntent().activityFromClass(PassEditActivity.class); - break; - - } - } -} diff --git a/src/main/java/org/ligi/passandroid/ui/PassListActivity.java b/src/main/java/org/ligi/passandroid/ui/PassListActivity.java index 14b052c2..7e41191f 100644 --- a/src/main/java/org/ligi/passandroid/ui/PassListActivity.java +++ b/src/main/java/org/ligi/passandroid/ui/PassListActivity.java @@ -1,8 +1,11 @@ package org.ligi.passandroid.ui; +import android.annotation.TargetApi; +import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; @@ -18,12 +21,12 @@ import android.widget.TextView; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnClick; -import com.afollestad.materialdialogs.MaterialDialog; import com.androidquery.service.MarketService; -import com.melnykov.fab.FloatingActionButton; import com.squareup.otto.Subscribe; import fr.nicolaspomepuy.discreetapprate.AppRate; import fr.nicolaspomepuy.discreetapprate.RetryPolicy; +import net.i2p.android.ext.floatingactionbutton.FloatingActionButton; +import net.i2p.android.ext.floatingactionbutton.FloatingActionsMenu; import org.ligi.axt.AXT; import org.ligi.passandroid.App; import org.ligi.passandroid.R; @@ -31,12 +34,15 @@ import org.ligi.passandroid.Tracker; import org.ligi.passandroid.events.NavigationOpenedEvent; import org.ligi.passandroid.events.SortOrderChangeEvent; import org.ligi.passandroid.events.TypeFocusEvent; +import org.ligi.passandroid.helper.PassUtil; +import org.ligi.passandroid.model.FiledPass; import org.ligi.passandroid.model.PassStore; import org.ligi.tracedroid.TraceDroid; import org.ligi.tracedroid.sending.TraceDroidEmailSender; public class PassListActivity extends ActionBarActivity { + private static final int OPEN_FILE_READ_REQUEST_CODE = 1000; private PassAdapter passAdapter; private ActionBarDrawerToggle drawerToggle; @@ -47,21 +53,62 @@ public class PassListActivity extends ActionBarActivity { @InjectView(R.id.drawer_layout) DrawerLayout drawer; - @InjectView(R.id.fab) - FloatingActionButton fab; - @InjectView(R.id.emptyView) TextView emptyView; - @OnClick(R.id.fab) + @InjectView(R.id.fam) + FloatingActionsMenu floatingActionsMenu; + + @OnClick(R.id.fab_action_create_pass) void onFABClick() { - new MaterialDialog.Builder(this).title(getString(R.string.fab_add_dialog_title)) - .items(R.array.items) - .itemsCallback(new FABCallback(this)) - .negativeText(android.R.string.cancel) - .show(); + final FiledPass pass = PassUtil.createEmptyPass(); + App.getPassStore().setCurrentPass(pass); + pass.save(App.getPassStore()); + AXT.at(this).startCommonIntent().activityFromClass(PassEditActivity.class); + floatingActionsMenu.collapse(); } + @OnClick(R.id.fab_action_scan) + void onScanClick() { + final Intent intent = new Intent(this, SearchPassesIntentService.class); + startService(intent); + floatingActionsMenu.collapse(); + } + + + @OnClick(R.id.fab_action_demo_pass) + void onAddDemoClick() { + AXT.at(this).startCommonIntent().openUrl("http://ligi.de/passandroid_samples/index.html"); + floatingActionsMenu.collapse(); + } + + + @InjectView(R.id.fab_action_open_file) + FloatingActionButton openFileFAB; + + public final static int VERSION_STARTING_TO_SUPPORT_STORAGE_FRAMEWORK =19; + + @OnClick(R.id.fab_action_open_file) + @TargetApi(VERSION_STARTING_TO_SUPPORT_STORAGE_FRAMEWORK) + void onAddOpenFileClick() { + final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); // tried with octet stream - no use + startActivityForResult(intent, OPEN_FILE_READ_REQUEST_CODE); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent resultData) { + if (requestCode == OPEN_FILE_READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) { + if (resultData != null) { + final Intent targetIntent = new Intent(this, PassImportActivity.class); + targetIntent.setData(resultData.getData()); + startActivity(targetIntent); + } + } + } + + private NavigationFragment navigationFragment; @Subscribe @@ -106,6 +153,8 @@ public class PassListActivity extends ActionBarActivity { setContentView(R.layout.pass_list); ButterKnife.inject(this); + AXT.at(openFileFAB).setVisibility(Build.VERSION.SDK_INT >= VERSION_STARTING_TO_SUPPORT_STORAGE_FRAMEWORK); + final LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.VERTICAL); llm.scrollToPosition(0); @@ -171,7 +220,6 @@ public class PassListActivity extends ActionBarActivity { protected void onResume() { super.onResume(); - fab.attachToRecyclerView(recyclerView); new InitAsyncTask().execute(); App.getBus().register(this); diff --git a/src/main/res/layout/pass_list.xml b/src/main/res/layout/pass_list.xml index 42702c84..24221d94 100644 --- a/src/main/res/layout/pass_list.xml +++ b/src/main/res/layout/pass_list.xml @@ -1,11 +1,11 @@ - - @@ -28,18 +28,65 @@ android:id="@+id/emptyView" /> - - + android:layout_alignParentBottom="true" + android:layout_alignParentRight="true" + android:layout_alignParentEnd="true" + fab:fab_addButtonColorNormal="@color/accent" + fab:fab_addButtonColorPressed="@color/icon_green" + fab:fab_addButtonPlusIconColor="@android:color/black" + fab:fab_labelStyle="@style/menu_labels_style" + android:layout_marginBottom="16dp" + android:layout_marginRight="16dp" + android:layout_marginEnd="16dp"> + + + + + + + + + + + + + + - - - @string/fab_choice_scan_pkpass_files - @string/fab_choice_add_demo_pass - @string/fab_choice_create_pass - - \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 3373dad5..e06a1a56 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -89,7 +89,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS LESS Select Picture Scanning for Passes - Source Scan for pkpass files Add Demo-Pass Create Pass (experimental) diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index ce2cce61..0331791e 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -38,4 +38,11 @@ @color/primary_text_default_material_dark 7dp + + + \ No newline at end of file