make qrcode available in two sizes

This commit is contained in:
Eric House 2020-11-10 14:22:18 -08:00
parent 9981a559df
commit 98f8056b40
2 changed files with 75 additions and 38 deletions

View file

@ -46,7 +46,9 @@ public class InviteView extends ScrollView
implements RadioGroup.OnCheckedChangeListener { implements RadioGroup.OnCheckedChangeListener {
private static final String TAG = InviteView.class.getSimpleName(); private static final String TAG = InviteView.class.getSimpleName();
private static final int QRCODE_SIZE = 320; private static final String KEY_EXPANDED = TAG + ":expanded";
private static final int QRCODE_SIZE_SMALL = 320;
private static final int QRCODE_SIZE_LARGE = QRCODE_SIZE_SMALL * 2;
public interface ItemClicked { public interface ItemClicked {
public void meansClicked( InviteMeans means ); public void meansClicked( InviteMeans means );
@ -59,6 +61,8 @@ public class InviteView extends ScrollView
private RadioGroup mGroupHow; private RadioGroup mGroupHow;
private Map<RadioButton, InviteMeans> mHowMeans = new HashMap<>(); private Map<RadioButton, InviteMeans> mHowMeans = new HashMap<>();
private Map<RadioButton, String> mWhoPlayers = new HashMap<>(); private Map<RadioButton, String> mWhoPlayers = new HashMap<>();
private boolean mExpanded = false;
private NetLaunchInfo mNli;
public InviteView( Context context, AttributeSet as ) { public InviteView( Context context, AttributeSet as ) {
super( context, as ); super( context, as );
@ -67,7 +71,7 @@ public class InviteView extends ScrollView
public InviteView setChoices( List<InviteMeans> meansList, int sel, public InviteView setChoices( List<InviteMeans> meansList, int sel,
String[] players ) String[] players )
{ {
Context context = getContext(); final Context context = getContext();
boolean haveWho = null != players && 0 < players.length; boolean haveWho = null != players && 0 < players.length;
@ -111,14 +115,25 @@ public class InviteView extends ScrollView
mIsWho = false; // start with how mIsWho = false; // start with how
showWhoOrHow(); showWhoOrHow();
mExpanded = DBUtils.getBoolFor( context, KEY_EXPANDED, false );
((ExpandImageButton)findViewById( R.id.expander ))
.setOnExpandChangedListener( new ExpandImageButton.ExpandChangeListener() {
@Override
public void expandedChanged( boolean nowExpanded )
{
mExpanded = nowExpanded;
DBUtils.setBoolFor( context, KEY_EXPANDED, nowExpanded );
startQRCodeThread( null );
}
} )
.setExpanded( mExpanded );
return this; return this;
} }
public InviteView setNli( NetLaunchInfo nli ) public InviteView setNli( NetLaunchInfo nli )
{ {
if ( null != nli ) {
startQRCodeThread( nli ); startQRCodeThread( nli );
}
return this; return this;
} }
@ -187,18 +202,23 @@ public class InviteView extends ScrollView
private void startQRCodeThread( NetLaunchInfo nli ) private void startQRCodeThread( NetLaunchInfo nli )
{ {
final String url = nli.makeLaunchUri( getContext() ).toString(); if ( null != nli ) {
mNli = nli;
}
if ( null != mNli ) {
final String url = mNli.makeLaunchUri( getContext() ).toString();
new Thread( new Runnable() { new Thread( new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
int qrSize = mExpanded ? QRCODE_SIZE_LARGE : QRCODE_SIZE_SMALL;
MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
BitMatrix bitMatrix = multiFormatWriter.encode( url, BarcodeFormat.QR_CODE, BitMatrix bitMatrix = multiFormatWriter.encode( url, BarcodeFormat.QR_CODE,
QRCODE_SIZE, QRCODE_SIZE ); qrSize, qrSize );
final Bitmap bitmap = Bitmap.createBitmap( QRCODE_SIZE, QRCODE_SIZE, final Bitmap bitmap = Bitmap.createBitmap( qrSize, qrSize,
Bitmap.Config.ARGB_8888 ); Bitmap.Config.ARGB_8888 );
for ( int ii = 0; ii < QRCODE_SIZE; ++ii ) { for ( int ii = 0; ii < qrSize; ++ii ) {
for ( int jj = 0; jj < QRCODE_SIZE; ++jj ) { for ( int jj = 0; jj < qrSize; ++jj ) {
bitmap.setPixel( ii, jj, bitMatrix.get(ii, jj) bitmap.setPixel( ii, jj, bitMatrix.get(ii, jj)
? Color.BLACK : Color.WHITE ); ? Color.BLACK : Color.WHITE );
} }
@ -209,6 +229,12 @@ public class InviteView extends ScrollView
public void run() { public void run() {
ImageView iv = (ImageView)findViewById( R.id.qr_view ); ImageView iv = (ImageView)findViewById( R.id.qr_view );
iv.setImageBitmap( bitmap ); iv.setImageBitmap( bitmap );
post ( new Runnable() {
@Override
public void run() {
scrollTo( 0, getBottom() );
}
} );
} }
} ); } );
} catch ( WriterException we ) { } catch ( WriterException we ) {
@ -217,4 +243,5 @@ public class InviteView extends ScrollView
} }
} ).start(); } ).start();
} }
}
} }

View file

@ -63,12 +63,22 @@
/> />
<!-- intro for QR code: these two elems stay at the bottom --> <!-- intro for QR code: these two elems stay at the bottom -->
<TextView android:layout_width="wrap_content" <LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/qrcode_invite_summary" android:text="@string/qrcode_invite_summary"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="5dp" android:layout_weight="1"
/> />
<org.eehouse.android.xw4.ExpandImageButton android:id="@+id/expander"
style="@style/expander_button"
android:layout_weight="0"
/>
</LinearLayout>
<ImageView android:id="@+id/qr_view" <ImageView android:id="@+id/qr_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"