Added option to scan QR codes directly from the app
This commit is contained in:
parent
a3c3fc082d
commit
a4f6642f6a
@ -55,6 +55,7 @@ dependencies {
|
|||||||
|
|
||||||
compile 'com.journeyapps:zxing-android-embedded:3.1.0@aar'
|
compile 'com.journeyapps:zxing-android-embedded:3.1.0@aar'
|
||||||
compile 'com.google.zxing:core:3.2.0'
|
compile 'com.google.zxing:core:3.2.0'
|
||||||
|
compile 'io.github.yavski:fab-speed-dial:1.0.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
idea.module {
|
idea.module {
|
||||||
|
@ -17,25 +17,31 @@
|
|||||||
package ch.dissem.apps.abit;
|
package ch.dissem.apps.abit;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
import com.google.zxing.integration.android.IntentIntegrator;
|
||||||
import ch.dissem.apps.abit.service.Singleton;
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import ch.dissem.apps.abit.listener.ActionBarListener;
|
||||||
|
import ch.dissem.apps.abit.service.Singleton;
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
|
import io.github.yavski.fabspeeddial.FabSpeedDial;
|
||||||
|
import io.github.yavski.fabspeeddial.SimpleMenuListenerAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that shows a list of all contacts, the ones we subscribed to first.
|
* Fragment that shows a list of all contacts, the ones we subscribed to first.
|
||||||
*/
|
*/
|
||||||
@ -48,7 +54,8 @@ public class AddressListFragment extends AbstractItemListFragment<BitmessageAddr
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateList() {
|
public void updateList() {
|
||||||
List<BitmessageAddress> addresses = Singleton.getAddressRepository(getContext()).getContacts();
|
List<BitmessageAddress> addresses = Singleton.getAddressRepository(getContext())
|
||||||
|
.getContacts();
|
||||||
Collections.sort(addresses, new Comparator<BitmessageAddress>() {
|
Collections.sort(addresses, new Comparator<BitmessageAddress>() {
|
||||||
/**
|
/**
|
||||||
* Yields the following order:
|
* Yields the following order:
|
||||||
@ -92,12 +99,15 @@ public class AddressListFragment extends AbstractItemListFragment<BitmessageAddr
|
|||||||
convertView = inflater.inflate(R.layout.subscription_row, null, false);
|
convertView = inflater.inflate(R.layout.subscription_row, null, false);
|
||||||
}
|
}
|
||||||
BitmessageAddress item = getItem(position);
|
BitmessageAddress item = getItem(position);
|
||||||
((ImageView) convertView.findViewById(R.id.avatar)).setImageDrawable(new Identicon(item));
|
((ImageView) convertView.findViewById(R.id.avatar)).setImageDrawable(new
|
||||||
|
Identicon(item));
|
||||||
TextView name = (TextView) convertView.findViewById(R.id.name);
|
TextView name = (TextView) convertView.findViewById(R.id.name);
|
||||||
name.setText(item.toString());
|
name.setText(item.toString());
|
||||||
TextView streamNumber = (TextView) convertView.findViewById(R.id.stream_number);
|
TextView streamNumber = (TextView) convertView.findViewById(R.id.stream_number);
|
||||||
streamNumber.setText(getContext().getString(R.string.stream_number, item.getStream()));
|
streamNumber.setText(getContext().getString(R.string.stream_number, item
|
||||||
convertView.findViewById(R.id.subscribed).setVisibility(item.isSubscribed() ? View.VISIBLE : View.INVISIBLE);
|
.getStream()));
|
||||||
|
convertView.findViewById(R.id.subscribed).setVisibility(item.isSubscribed() ?
|
||||||
|
View.VISIBLE : View.INVISIBLE);
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -113,23 +123,46 @@ public class AddressListFragment extends AbstractItemListFragment<BitmessageAddr
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
|
||||||
|
savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_address_list, container, false);
|
View view = inflater.inflate(R.layout.fragment_address_list, container, false);
|
||||||
|
|
||||||
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab_add_contact);
|
FabSpeedDial fabSpeedDial = (FabSpeedDial) view.findViewById(R.id.fab_add_contact);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public boolean onMenuItemSelected(MenuItem menuItem) {
|
||||||
// Intent intent = new Intent(getActivity().getApplicationContext(), ComposeMessageActivity.class);
|
switch (menuItem.getItemId()) {
|
||||||
// intent.putExtra(ComposeMessageActivity.EXTRA_IDENTITY, Singleton.getIdentity(getActivity()));
|
case R.id.action_read_qr_code:
|
||||||
// startActivity(intent);
|
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
||||||
// TODO
|
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
||||||
|
.initiateScan();
|
||||||
|
return true;
|
||||||
|
case R.id.action_create_contact:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startActivityForResult(Intent intent, int requestCode) {
|
||||||
|
super.startActivityForResult(intent, requestCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (data.hasExtra("SCAN_RESULT")) {
|
||||||
|
Uri uri = Uri.parse(data.getStringExtra("SCAN_RESULT"));
|
||||||
|
Intent intent = new Intent(getActivity(), OpenBitmessageLinkActivity.class);
|
||||||
|
intent.setData(uri);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void updateList(Label label) {
|
void updateList(Label label) {
|
||||||
updateList();
|
updateList();
|
||||||
|
9
app/src/main/res/drawable/ic_action_create_contact.xml
Normal file
9
app/src/main/res/drawable/ic_action_create_contact.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#DEFFFFFF"
|
||||||
|
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
|
||||||
|
</vector>
|
7
app/src/main/res/drawable/ic_action_qr_code.xml
Normal file
7
app/src/main/res/drawable/ic_action_qr_code.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:height="24dp"
|
||||||
|
android:width="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path android:fillColor="#000" android:pathData="M3,11H5V13H3V11M11,5H13V9H11V5M9,11H13V15H11V13H9V11M15,11H17V13H19V11H21V13H19V15H21V19H19V21H17V19H13V21H11V17H15V15H17V13H15V11M19,19V15H17V19H19M15,3H21V9H15V3M17,5V7H19V5H17M3,3H9V9H3V3M5,5V7H7V5H5M3,15H9V21H3V15M5,17V19H7V17H5Z" />
|
||||||
|
</vector>
|
@ -5,25 +5,28 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
android:id="@id/android:list"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@id/android:list"
|
|
||||||
|
|
||||||
android:paddingBottom="88dp"
|
android:layout_alignParentBottom="true"
|
||||||
android:clipToPadding="false"
|
|
||||||
android:scrollbarStyle="outsideOverlay"
|
|
||||||
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_alignParentBottom="true"/>
|
android:layout_alignParentTop="true"
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
android:clipToPadding="false"
|
||||||
|
android:paddingBottom="88dp"
|
||||||
|
android:scrollbarStyle="outsideOverlay"/>
|
||||||
|
|
||||||
|
<io.github.yavski.fabspeeddial.FabSpeedDial
|
||||||
android:id="@+id/fab_add_contact"
|
android:id="@+id/fab_add_contact"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/ic_action_add_contact"
|
|
||||||
app:elevation="8dp"
|
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_margin="16dp"/>
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:src="@drawable/ic_action_add_contact"
|
||||||
|
app:elevation="8dp"
|
||||||
|
app:fabGravity="bottom_end"
|
||||||
|
app:fabMenu="@menu/fab_address"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
27
app/src/main/res/menu/fab_address.xml
Normal file
27
app/src/main/res/menu/fab_address.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright 2016 Christian Basler
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_read_qr_code"
|
||||||
|
android:icon="@drawable/ic_action_qr_code"
|
||||||
|
android:title="@string/scan_qr_code"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_create_contact"
|
||||||
|
android:icon="@drawable/ic_action_create_contact"
|
||||||
|
android:title="@string/create_contact"/>
|
||||||
|
</menu>
|
@ -63,4 +63,6 @@
|
|||||||
<string name="share">Teilen</string>
|
<string name="share">Teilen</string>
|
||||||
<string name="delete_contact_warning">Sind Sie sicher dass dieser Kontakt gelöscht werden soll?</string>
|
<string name="delete_contact_warning">Sind Sie sicher dass dieser Kontakt gelöscht werden soll?</string>
|
||||||
<string name="delete_identity_warning">Sind Sie sicher dass diese Identität gelöscht werden soll? Sie werden keine Nachrichten mehr empfangen können welche an diese Adresse gesendet werden, und es est nicht möglich diese Aktion rückgängig zu machen.</string>
|
<string name="delete_identity_warning">Sind Sie sicher dass diese Identität gelöscht werden soll? Sie werden keine Nachrichten mehr empfangen können welche an diese Adresse gesendet werden, und es est nicht möglich diese Aktion rückgängig zu machen.</string>
|
||||||
|
<string name="create_contact">Kontakt erfassen</string>
|
||||||
|
<string name="scan_qr_code">QR-Code scannen</string>
|
||||||
</resources>
|
</resources>
|
@ -66,4 +66,6 @@
|
|||||||
<string name="share">Share</string>
|
<string name="share">Share</string>
|
||||||
<string name="delete_identity_warning">Are you sure you want to delete this identity? You won\'t be able to receive any messages sent to this address and can\'t undo this operation.</string>
|
<string name="delete_identity_warning">Are you sure you want to delete this identity? You won\'t be able to receive any messages sent to this address and can\'t undo this operation.</string>
|
||||||
<string name="delete_contact_warning">Are you sure you want to delete this contact?</string>
|
<string name="delete_contact_warning">Are you sure you want to delete this contact?</string>
|
||||||
|
<string name="scan_qr_code">Scan QR code</string>
|
||||||
|
<string name="create_contact">Create contact</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user