Introduce a FloatingAction menu and open via Storage Access Framework when available
This commit is contained in:
parent
86ca9613b8
commit
bc8bf63699
7 changed files with 128 additions and 78 deletions
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
@ -28,18 +28,65 @@
|
|||
android:id="@+id/emptyView"
|
||||
/>
|
||||
|
||||
<com.melnykov.fab.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.FloatingActionsMenu
|
||||
android:id="@+id/fam"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/ic_add_white_24dp"
|
||||
fab:fab_colorNormal="@color/accent"
|
||||
fab:fab_colorPressed="@color/icon_green"
|
||||
fab:fab_colorRipple="@color/icon_green"/>
|
||||
</FrameLayout>
|
||||
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">
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_action_open_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_colorNormal="@color/secondary"
|
||||
fab:fab_title="Open File"
|
||||
fab:fab_colorPressed="@color/icon_green"/>
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_action_demo_pass"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_colorNormal="@color/secondary"
|
||||
fab:fab_title="@string/fab_choice_add_demo_pass"
|
||||
fab:fab_colorPressed="@color/icon_green"/>
|
||||
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_action_scan"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_colorNormal="@color/secondary"
|
||||
fab:fab_title="@string/fab_choice_scan_pkpass_files"
|
||||
fab:fab_colorPressed="@color/icon_green"/>
|
||||
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_action_create_pass"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_colorNormal="@color/secondary"
|
||||
fab:fab_title="@string/fab_choice_create_pass"
|
||||
fab:fab_colorPressed="@color/icon_green"/>
|
||||
|
||||
|
||||
</net.i2p.android.ext.floatingactionbutton.FloatingActionsMenu>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/left_drawer"
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="items" >
|
||||
<item>@string/fab_choice_scan_pkpass_files</item>
|
||||
<item>@string/fab_choice_add_demo_pass</item>
|
||||
<item>@string/fab_choice_create_pass</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -89,7 +89,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
|
|||
<string name="less">LESS</string>
|
||||
<string name="select_picture">Select Picture</string>
|
||||
<string name="scanning_for_passes" >Scanning for Passes</string>
|
||||
<string name="fab_add_dialog_title">Source</string>
|
||||
<string name="fab_choice_scan_pkpass_files">Scan for pkpass files</string>
|
||||
<string name="fab_choice_add_demo_pass">Add Demo-Pass</string>
|
||||
<string name="fab_choice_create_pass">Create Pass (experimental)</string>
|
||||
|
|
|
@ -38,4 +38,11 @@
|
|||
<item name="android:textColor">@color/primary_text_default_material_dark</item>
|
||||
<item name="android:padding">7dp</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="menu_labels_style">
|
||||
<item name="android:background">@color/secondary</item>
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
<item name="android:padding">4dp</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in a new issue