Button btnShare=(Button)findViewById(R.id.btnShare);
btnShare.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Produk :"+title+"\n\nKet :"+title2+"\n\nHarga :"+title3+"\n\nStatus :"+title4);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
}});
Button btnsave=(Button)findViewById(R.id.btnsave);btnsave.setText("Download");
btnsave.setVisibility(View.VISIBLE);
btnsave.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
savepicture();
}});
public void savepicture() {
AlertDialog.Builder ad = new AlertDialog.Builder(DetailGaleri.this);
ad.setTitle("Save Picture");
ad.setMessage(title+" \n"+title3+"\n"+title4);
ad.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
View content = findViewById(R.id.myGambar);
Bitmap bitmap = getScreenShot(content);
// currentImage = "image" + System.currentTimeMillis() + ".jpg"; currentImage = title+" \n"+title3+"\n"+title4+".jpg";
store(bitmap, currentImage);
// b_share.setEnabled(true); // finish(); }
});
ad.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
ad.show();
}
private static Bitmap getScreenShot(View view) {
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
return bitmap;
}
private void store(Bitmap bm, String fileName) {
String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/FILEPROJEK";
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dirPath, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
Toast.makeText(this, "Saved to "+dirPath +"..!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
Tidak ada komentar:
Posting Komentar