Fixed occasional crash
This commit is contained in:
@@ -18,6 +18,7 @@ import android.support.v4.app.DialogFragment;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -239,29 +240,35 @@ public abstract class ViewAddressFragment extends Fragment {
|
|||||||
* Load QR Code asynchronously and with a fade in animation
|
* Load QR Code asynchronously and with a fade in animation
|
||||||
*/
|
*/
|
||||||
private void loadQrCode() {
|
private void loadQrCode() {
|
||||||
AsyncTask<Void, Void, Bitmap> loadTask =
|
AsyncTask<Void, Void, Bitmap[]> loadTask =
|
||||||
new AsyncTask<Void, Void, Bitmap>() {
|
new AsyncTask<Void, Void, Bitmap[]>() {
|
||||||
protected Bitmap doInBackground(Void... unused) {
|
protected Bitmap[] doInBackground(Void... unused) {
|
||||||
String qrCodeContent = Constants.EMAILDEST_SCHEME + ":" + mAddress;
|
String qrCodeContent = Constants.EMAILDEST_SCHEME + ":" + mAddress;
|
||||||
// render with minimal size
|
// render with minimal size
|
||||||
return QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0);
|
Bitmap qrCode = QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0);
|
||||||
|
Bitmap[] scaled = new Bitmap[2];
|
||||||
|
|
||||||
|
// scale the image up to our actual size. we do this in code rather
|
||||||
|
// than let the ImageView do this because we don't require filtering.
|
||||||
|
int size = getResources().getDimensionPixelSize(R.dimen.qr_code_size);
|
||||||
|
scaled[0] = Bitmap.createScaledBitmap(qrCode, size, size, false);
|
||||||
|
|
||||||
|
// scale for the expanded image
|
||||||
|
DisplayMetrics dm = new DisplayMetrics();
|
||||||
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||||
|
int smallestDimen = Math.min(dm.widthPixels, dm.heightPixels);
|
||||||
|
scaled[1] = Bitmap.createScaledBitmap(qrCode,
|
||||||
|
smallestDimen, smallestDimen,
|
||||||
|
false);
|
||||||
|
|
||||||
|
return scaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Bitmap qrCode) {
|
protected void onPostExecute(Bitmap[] scaled) {
|
||||||
// only change view, if fragment is attached to activity
|
// only change view, if fragment is attached to activity
|
||||||
if (ViewAddressFragment.this.isAdded()) {
|
if (ViewAddressFragment.this.isAdded()) {
|
||||||
// scale the image up to our actual size. we do this in code rather
|
mAddressQrCode.setImageBitmap(scaled[0]);
|
||||||
// than let the ImageView do this because we don't require filtering.
|
mExpandedQrCode.setImageBitmap(scaled[1]);
|
||||||
Bitmap scaled = Bitmap.createScaledBitmap(qrCode,
|
|
||||||
mAddressQrCode.getHeight(), mAddressQrCode.getHeight(),
|
|
||||||
false);
|
|
||||||
mAddressQrCode.setImageBitmap(scaled);
|
|
||||||
// scale for the expanded image
|
|
||||||
int smallestDimen = Math.min(mExpandedQrCode.getWidth(), mExpandedQrCode.getHeight());
|
|
||||||
scaled = Bitmap.createScaledBitmap(qrCode,
|
|
||||||
smallestDimen, smallestDimen,
|
|
||||||
false);
|
|
||||||
mExpandedQrCode.setImageBitmap(scaled);
|
|
||||||
// simple fade-in animation
|
// simple fade-in animation
|
||||||
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
|
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
|
||||||
anim.setDuration(200);
|
anim.setDuration(200);
|
||||||
|
|||||||
@@ -95,8 +95,8 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/email_dest_qr_code"
|
android:id="@+id/email_dest_qr_code"
|
||||||
android:layout_width="200dp"
|
android:layout_width="@dimen/qr_code_size"
|
||||||
android:layout_height="200dp"
|
android:layout_height="@dimen/qr_code_size"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="8dp"/>
|
android:layout_marginTop="8dp"/>
|
||||||
|
|
||||||
|
|||||||
@@ -34,5 +34,7 @@
|
|||||||
<dimen name="contact_chip_right_margin">12dp</dimen>
|
<dimen name="contact_chip_right_margin">12dp</dimen>
|
||||||
<dimen name="contact_chip_corner_radius">16dp</dimen>
|
<dimen name="contact_chip_corner_radius">16dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="qr_code_size">200dp</dimen>
|
||||||
|
|
||||||
<dimen name="pie_size">300dp</dimen>
|
<dimen name="pie_size">300dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user