mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
make qrcode available in two sizes
This commit is contained in:
parent
9981a559df
commit
98f8056b40
2 changed files with 75 additions and 38 deletions
|
@ -46,7 +46,9 @@ public class InviteView extends ScrollView
|
|||
implements RadioGroup.OnCheckedChangeListener {
|
||||
|
||||
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 void meansClicked( InviteMeans means );
|
||||
|
@ -59,6 +61,8 @@ public class InviteView extends ScrollView
|
|||
private RadioGroup mGroupHow;
|
||||
private Map<RadioButton, InviteMeans> mHowMeans = new HashMap<>();
|
||||
private Map<RadioButton, String> mWhoPlayers = new HashMap<>();
|
||||
private boolean mExpanded = false;
|
||||
private NetLaunchInfo mNli;
|
||||
|
||||
public InviteView( Context context, AttributeSet as ) {
|
||||
super( context, as );
|
||||
|
@ -67,7 +71,7 @@ public class InviteView extends ScrollView
|
|||
public InviteView setChoices( List<InviteMeans> meansList, int sel,
|
||||
String[] players )
|
||||
{
|
||||
Context context = getContext();
|
||||
final Context context = getContext();
|
||||
|
||||
boolean haveWho = null != players && 0 < players.length;
|
||||
|
||||
|
@ -111,14 +115,25 @@ public class InviteView extends ScrollView
|
|||
mIsWho = false; // start with how
|
||||
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;
|
||||
}
|
||||
|
||||
public InviteView setNli( NetLaunchInfo nli )
|
||||
{
|
||||
if ( null != nli ) {
|
||||
startQRCodeThread( nli );
|
||||
}
|
||||
startQRCodeThread( nli );
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -187,34 +202,46 @@ public class InviteView extends ScrollView
|
|||
|
||||
private void startQRCodeThread( NetLaunchInfo nli )
|
||||
{
|
||||
final String url = nli.makeLaunchUri( getContext() ).toString();
|
||||
new Thread( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||
BitMatrix bitMatrix = multiFormatWriter.encode( url, BarcodeFormat.QR_CODE,
|
||||
QRCODE_SIZE, QRCODE_SIZE );
|
||||
final Bitmap bitmap = Bitmap.createBitmap( QRCODE_SIZE, QRCODE_SIZE,
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
for ( int ii = 0; ii < QRCODE_SIZE; ++ii ) {
|
||||
for ( int jj = 0; jj < QRCODE_SIZE; ++jj ) {
|
||||
bitmap.setPixel( ii, jj, bitMatrix.get(ii, jj)
|
||||
? Color.BLACK : Color.WHITE );
|
||||
}
|
||||
}
|
||||
|
||||
post( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ImageView iv = (ImageView)findViewById( R.id.qr_view );
|
||||
iv.setImageBitmap( bitmap );
|
||||
if ( null != nli ) {
|
||||
mNli = nli;
|
||||
}
|
||||
if ( null != mNli ) {
|
||||
final String url = mNli.makeLaunchUri( getContext() ).toString();
|
||||
new Thread( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int qrSize = mExpanded ? QRCODE_SIZE_LARGE : QRCODE_SIZE_SMALL;
|
||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||
BitMatrix bitMatrix = multiFormatWriter.encode( url, BarcodeFormat.QR_CODE,
|
||||
qrSize, qrSize );
|
||||
final Bitmap bitmap = Bitmap.createBitmap( qrSize, qrSize,
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
for ( int ii = 0; ii < qrSize; ++ii ) {
|
||||
for ( int jj = 0; jj < qrSize; ++jj ) {
|
||||
bitmap.setPixel( ii, jj, bitMatrix.get(ii, jj)
|
||||
? Color.BLACK : Color.WHITE );
|
||||
}
|
||||
} );
|
||||
} catch ( WriterException we ) {
|
||||
Log.ex( TAG, we );
|
||||
}
|
||||
|
||||
post( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ImageView iv = (ImageView)findViewById( R.id.qr_view );
|
||||
iv.setImageBitmap( bitmap );
|
||||
post ( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scrollTo( 0, getBottom() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
} catch ( WriterException we ) {
|
||||
Log.ex( TAG, we );
|
||||
}
|
||||
}
|
||||
}
|
||||
} ).start();
|
||||
} ).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,12 +63,22 @@
|
|||
/>
|
||||
|
||||
<!-- intro for QR code: these two elems stay at the bottom -->
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/qrcode_invite_summary"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:padding="5dp"
|
||||
/>
|
||||
<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:text="@string/qrcode_invite_summary"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
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"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Add table
Reference in a new issue