Added download button

This commit is contained in:
Keith Holliday 2016-08-11 17:00:49 -05:00
parent 30b736d9a1
commit d789a50de4
2 changed files with 53 additions and 0 deletions

View file

@ -66,6 +66,16 @@
android:id="@+id/QRImageView"
android:layout_gravity="center_horizontal|bottom" />
<Button
android:id="@+id/QRDownloadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_margin="20dp"
android:layout_gravity="center_horizontal|bottom"
/>
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -24,11 +24,23 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.glxn.qrgen.android.QRCode;
import net.glxn.qrgen.core.image.ImageType;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import javax.inject.Inject;
@ -52,6 +64,9 @@ public class GroupInformationFragment extends BaseFragment {
@BindView(R.id.QRImageView)
ImageView qrImageView;
@BindView(R.id.QRDownloadButton)
Button qRDownloadButton;
private View view;
private Group group;
private HabitRPGUser user;
@ -313,5 +328,33 @@ public class GroupInformationFragment extends BaseFragment {
if (qrImageView != null) {
qrImageView.setImageBitmap(myBitmap);
}
if (qRDownloadButton != null) {
qRDownloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
File path = new File(getActivity().getFilesDir(), "habitrpg-qr-code");
File file = QRCode.from(getString(R.string.SP_userID)).to(ImageType.JPG).file();
file.renameTo(path);
Toast.makeText(getActivity(), "QR code saved at " + path.getPath(),
Toast.LENGTH_LONG).show();
}
});
}
}
public static void copyFile(File src, File dst) throws IOException
{
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
}