Android Take Screeshot Width Is Too Wide - android

I am using the code below to programatically capture the screen layout of a linear layout, the problem is that the screenshot image is too wide, as if it is a landsacpe image, my activity is potrait where height is > width but for some reason this code captures a screenshot with width > height and it looks like a horizontal rectangle rather than a vertical rectangle. The view are correctly oriented so it definitely capturing in the correct orrientation (potrait) but just too wide with the views further apart and smaller.
private void takeScreenShot() {
ll_screenshot = findViewById(R.id.ll_screenshot);
try {
cacheDir = new File(android.os.Environment.getExternalStorageDirectory(), "store");
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
ll_screenshot.setDrawingCacheEnabled(true);
ll_screenshot.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
ll_screenshot.layout(0, 0, ll_screenshot.getMeasuredWidth(), ll_screenshot.getMeasuredHeight());
ll_screenshot.buildDrawingCache(true);
Bitmap bm = Bitmap.createBitmap(ll_screenshot.getDrawingCache());
ll_screenshot.setDrawingCacheEnabled(false); // clear drawing cache
path = new File(android.os.Environment.getExternalStorageDirectory(),"store") + "/screenshot.jpg";
savePic(bm, path);
shareFile();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public static void savePic(Bitmap b, String strFileName) {
FileOutputStream fos;
try {
fos = new FileOutputStream(strFileName);
b.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void shareFile() {
String file_path = path.toString();
Intent intentShareFile = new Intent(Intent.ACTION_SEND);
File fileWithinMyDir = new File(file_path);
if(fileWithinMyDir.exists()) {
intentShareFile.setType("image/*");
intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file_path));
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, "Share File...");
intentShareFile.putExtra(Intent.EXTRA_TEXT, "Share File...");
startActivity(Intent.createChooser(intentShareFile, "Share File"));
}
}
screenshot:
Edit (XML):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/bg_menu_h"
>
<LinearLayout
android:id="#+id/ll_screenshot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bg_menu_h"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/bg_menu_h"
>
<TextView
android:id="#+id/tvItem"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textStyle="bold"
android:gravity="center"
android:text=""
android:textSize="25sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/bg_menu_h"
>
<TextView
android:id="#+id/tvBrandLeft"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="Sunlight"
android:textSize="25sp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tvBrandRight"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="Sunlight"
android:textSize="25sp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/bg_menu_h"
>
<TextView
android:id="#+id/tvSizeLeft"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="1KG"
android:textSize="25sp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tvSizeRight"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="1KG"
android:textSize="25sp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_middle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
>
<ImageView
android:id="#+id/ivTrophyLeft"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="bottom|left"
android:background="#android:color/transparent"
android:src="#drawable/questionmark"
android:adjustViewBounds="true"
/>
<ImageView
android:id="#+id/ivItemLeft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|left"
android:background="#android:color/transparent"
android:src="#drawable/questionmark"
android:adjustViewBounds="true"
android:layout_weight="1"
android:paddingRight="5dp"
/>
<ImageView
android:id="#+id/ivItemRight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|left"
android:background="#android:color/transparent"
android:src="#drawable/questionmark"
android:adjustViewBounds="true"
android:layout_weight="1"
android:paddingRight="5dp"
/>
<ImageView
android:id="#+id/ivTrophyRight"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="bottom|left"
android:background="#android:color/transparent"
android:src="#drawable/questionmark"
android:adjustViewBounds="true"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_price"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
>
<TextView
android:id="#+id/tvPriceLeft"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textStyle="bold"
android:gravity="center"
android:text="0.00"
android:textSize="35sp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tvPriceDifference"
android:layout_height="70dp"
android:layout_width="70dp"
android:textStyle="bold"
android:gravity="center"
android:text="0.00"
android:textSize="20sp"
android:background="#drawable/roundstar"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/tvPriceRight"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textStyle="bold"
android:gravity="center"
android:text="0.00"
android:textSize="35sp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_shop"
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/ivShopLeft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|left"
android:background="#android:color/transparent"
android:src="#drawable/shop"
android:adjustViewBounds="true"
android:layout_weight="1"
android:paddingRight="5dp"
android:layout_margin="5dp"
/>
<ImageView
android:id="#+id/ivShopRight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|right"
android:background="#android:color/transparent"
android:src="#drawable/shop"
android:adjustViewBounds="true"
android:layout_weight="1"
android:paddingLeft="5dp"
android:layout_margin="5dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_bottom_sub"
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal"
android:gravity="right"
>
<ImageView
android:id="#+id/ivLogo"
android:layout_height="match_parent"
android:layout_width="20dp"
android:src="#drawable/ic_launcher"
android:background="#android:color/transparent"
android:scaleType="fitEnd"
/>
<TextView
android:id="#+id/tvCompare"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:textStyle="bold|italic"
android:gravity="left|bottom"
android:text="App"
android:textSize="10sp"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_blank"
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation="horizontal"
>
</LinearLayout>

in your method takeScreenShot() do this change.
private void takeScreenShot() {
ll_screenshot = findViewById(R.id.main);
----
//other code
----
}
// change to R.id.main inplace of R.id.ll_screenshot

Related

How to click button inside listview

I know this problem already asked many times but i still can't get effective way for solving this. I try for use ListView with clickable/editable widget and Android : How to set onClick event for Button in List item of ListView as reference but the result is i need click button several time for executing my program. Here my program
LeadActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LeadSalesActivity">
<LinearLayout
android:background="#E9ECEB"
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/b_menusamping2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:background="#drawable/menu_button"
android:backgroundTint="#27D01B"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome,"
android:textSize="20sp"
android:textStyle="italic"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/t_username3"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Rizaldi"
android:textColor="#android:color/black"
android:textSize="25sp"
android:textStyle="bold"
android:fontFamily="#font/action_man_bold"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_refresh2"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white">
<ImageView
android:backgroundTint="#27D01B"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:background="#drawable/icon_update"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="("
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:textStyle="bold"
android:id="#+id/count_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=")"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<Button
android:id="#+id/btn_add"
android:layout_marginRight="20dp"
android:backgroundTint="#android:color/holo_blue_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tambah Lead"
android:textAllCaps="false"/>
</LinearLayout>
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tanggal"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:layout_marginLeft="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telp"
android:textColor="#android:color/black"
android:textSize="20sp"/>
</LinearLayout>
<ListView
android:id="#+id/listviewlead"
tools:listitem="#layout/c_lead"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/back6"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"/>
</LinearLayout>
c_lead.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_tgl"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Tgl"
android:textSize="15sp"
android:textStyle="italic"
android:textColor="#000000" />
<TextView
android:id="#+id/t_lead4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Lead"
android:textSize="15sp"
android:textColor="#000000" />
<TextView
android:id="#+id/t_numberphone"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="right"
android:text="No.Telp"
android:textSize="15sp"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/pencil_icon"/>
</LinearLayout>
<LinearLayout
android:id="#+id/btn_delete"
android:layout_marginLeft="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/delete_icon"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_alamat"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Alamat"
android:textColor="#android:color/black"
android:textSize="15sp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
MyAdapter
public View getView(final int _position, View _v, ViewGroup _container) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _view = _v;
if (_view == null) {
_view = _inflater.inflate(R.layout.c_lead, null);
}
final HashMap<String, Object> hashMap = _data.get(_position);
final TextView t_tanggal = (TextView) _view.findViewById(R.id.t_tgl);
final TextView t_lead = (TextView) _view.findViewById(R.id.t_lead4);
final TextView t_alamat = (TextView) _view.findViewById(R.id.t_alamat);
final TextView t_numberphone = (TextView) _view.findViewById(R.id.t_numberphone);
final LinearLayout btn_edit = (LinearLayout) _view.findViewById(R.id.btn_edit);
final LinearLayout btn_delete = (LinearLayout) _view.findViewById(R.id.btn_delete);
String dateString = _data.get(_position).get("create_date").toString().replace("-","");
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmm");
format1.setTimeZone(TimeZone.getTimeZone("GMT+7"));
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
try {
Date date = format1.parse(dateString);
String dateFinal = format2.format(date);
t_tanggal.setText(String.valueOf((long)(_position + 1)).concat(".").concat(dateFinal));
} catch (ParseException e) {
e.printStackTrace();
}
t_lead.setText(_data.get((int)_position).get("type").toString());
t_alamat.setText(_data.get((int)_position).get("street").toString());
if (_data.get((int)_position).get("mobile").toString().equals(true)){
t_numberphone.setText("Tanpa Nomor");
} else {
t_numberphone.setText(_data.get((int)_position).get("phone").toString());
}
btn_edit.setFocusable(false);
btn_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i.setClass(getApplicationContext(), AddLeadSalesActivity.class);
startActivity(i);
}
});
btn_delete.setFocusable(false);
btn_delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Data Tidak Bisa Dihapus", Toast.LENGTH_SHORT).show();
}
});
return _view;
}
Is there any mistake inside my program? How to solve this?

How to take screenshot of a layout having a camera preview and text view?

i want to take screenshot of camera and map and address text view only, whenever i try to take screenshot its only saving map and text area but the camera area gets all white screen onlyHere is my xml layout , and i want to take screenshot of relative layout with id rl_photo, but after taking screenshot of layout its only taking the map and textview but not camera image , camera image gets all white screen .
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#android:color/black"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Photo"
android:visibility="gone"
android:textStyle="bold"
android:id="#+id/tv_save"
android:background="#android:color/black"
android:layout_alignParentRight="true"
android:layout_margin="20dp"
android:textColor="#ffffff"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_above="#+id/rl_action"
android:id="#+id/rl_photo"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="120dp"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_height="120dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="gravity"
android:gravity="right"
android:layout_toRightOf="#+id/map"
android:layout_alignParentBottom="true"
android:background="#66000000"
android:layout_margin="10dp"
android:padding="10dp"
android:textColor="#android:color/white"
android:layout_alignParentRight="true"
android:id="#+id/tv_latlong"
android:text="xbdjhgjrejgtrjbtbjr"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/rl_action"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/button_capture"
android:layout_width="50dp"
android:layout_margin="10dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:src="#drawable/record"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="30dp"
android:src="#drawable/flip"
android:id="#+id/img_flip"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_height="30dp"/>
<ImageView
android:layout_width="30dp"
android:src="#drawable/gallery"
android:id="#+id/img_gallery"
android:layout_marginLeft="20dp"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_height="30dp"/>
</RelativeLayout>
</RelativeLayout>
For screenshot
Add image view on above of FrameLayout
While capturing the ss set camera bitmap in image view and make Imageview visible one process is done to make image view invisible
For SS follow below Process
XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black">
<TextView
android:id="#+id/tv_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="20dp"
android:background="#android:color/black"
android:text="Save Photo"
android:textColor="#ffffff"
android:textStyle="bold"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/rl_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rl_action">
<ImageView
android:id="#+id/ImageViewOFCamera"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_height="match_parent"/>
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_margin="10dp" />
<TextView
android:id="#+id/tv_latlong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_toRightOf="#+id/map"
android:background="#66000000"
android:gravity="right"
android:padding="10dp"
android:text="xbdjhgjrejgtrjbtbjr"
android:textAlignment="gravity"
android:textColor="#android:color/white" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageView
android:id="#+id/button_capture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/record" />
<ImageView
android:id="#+id/img_flip"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="#drawable/flip" />
<ImageView
android:id="#+id/img_gallery"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:src="#drawable/gallery" />
</RelativeLayout>
</RelativeLayout>
for ss capture in java File
private Bitmap bitmap;
bitmap = ScreenshotUtil.getInstance().takeScreenshotForView( rl_photo);
public class ScreenshotUtil {
private static ScreenshotUtil mInstance;
private ScreenshotUtil() {
}
public static ScreenshotUtil getInstance() {
if (mInstance == null) {
synchronized (ScreenshotUtil.class) {
if (mInstance == null) {
mInstance = new ScreenshotUtil();
}
}
}
return mInstance;
}
public Bitmap takeScreenshotForView(View view) {
view.measure( MeasureSpec.makeMeasureSpec( view.getWidth(), MeasureSpec.EXACTLY ),
MeasureSpec.makeMeasureSpec( view.getHeight(), MeasureSpec.EXACTLY ) );
view.layout( (int) view.getX(), (int) view.getY(),
(int) view.getX() + view.getMeasuredWidth(),
(int) view.getY() + view.getMeasuredHeight() );
view.setDrawingCacheEnabled( true );
view.buildDrawingCache( true );
Bitmap bitmap = Bitmap.createBitmap( view.getDrawingCache() );
view.setDrawingCacheEnabled( false );
return bitmap;
}
public Bitmap takeScreenshotForScreen(Activity activity) {
return takeScreenshotForView( activity.getWindow().getDecorView().getRootView() );
}
}

i hide some imageViews inside recycler view, but when i do scroll down all imageViews hide

Hello Team!!
I'm new on android but i have knoweledge in html and javascript. So i have a JSON that have some options(img,or not img) and i create a recycler view to list this JSON and all ok, later i try that hide some imageView of card because the JSON show that this doesn't have picture. It works fine
But when i do scroll down to bottom limit all imageViews hide, i don't know how solve it and i search in web but i can't find some solution for this issue.
Code in adapter
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onBindViewHolder(postViewHolder postViewHolder, int position) {
addPostTimeline addPost = addPostTimelines.get(position);
try {
CircleImageView img=postViewHolder.imgFoto;
JSONObject fileson=addPost.getDatosTimeine().getJSONObject("file");
// postViewHolder.imgTimeLine = #+id/image_timeline
if(!fileson.getBoolean("err")){ // si tiene archivos adjuntos
switch (fileson.getString("type")){
case "Pic":
imageTimeline imgTm=new imageTimeline(fileson.getString("src"), postViewHolder.imgTimeLine);
imgTm.execute();
break;
default:
postViewHolder.imgTimeLine.setVisibility(View.GONE);
break;
}
}else{
postViewHolder.contentFiles.setVisibility(View.GONE);
}
putImgProfile putImg=new putImgProfile(addPost.getDatosTimeine().getString("pDir"), img);
putImg.execute();
} catch (JSONException e) {
e.printStackTrace();
}
}
Structure of card with recycler
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="#+id/cvManana"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
card_view:cardCornerRadius="4dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout android:background="#drawable/textlines"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:orientation="vertical"
android:id="#+id/post"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgPerfil"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginRight="8dp"
android:scaleType="centerCrop"
android:src="#mipmap/ic_load_img" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_fechaPost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hace 44 minutos sep. 22º 16"
android:textColor="#999" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="12dp"
android:text="SonickSeven"
android:textColor="#24650e"
android:textSize="16dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:id="#+id/contentTextStory">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_postTimeLine"
android:textColor="#666"
android:textSize="15dp"
android:layout_gravity="left"
android:text="historias"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contentFiles">
<!-- image to hide -->
<ImageView
android:id="#+id/image_timeline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitStart"
card_view:srcCompat="#drawable/campo_manana" />
<!-- end imagen to hide -->
</LinearLayout>
<LinearLayout
android:paddingTop="4dp"
android:paddingBottom="7dp"
android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:gravity="right"
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/bt_reply"
android:layout_gravity="center_vertical"
android:scaleType="centerCrop"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_reply_gray"/>
<TextView
android:id="#+id/countReply"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/bt_share"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_share_gray"/>
<TextView
android:id="#+id/countShare"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<ImageButton
android:layout_gravity="center_vertical"
android:id="#+id/bt_like"
android:scaleType="centerCrop"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_like_gray"/>
<TextView
android:id="#+id/countLike"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/bt_dislike"
android:layout_gravity="center_vertical"
android:scaleType="centerCrop"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_nolike_gray"/>
<TextView
android:id="#+id/countNoLike"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
i saw that when i go to bottom of scroll and up the switch trigger again, but it doesn't could because the recycler view run all array JSON. Sorry i can understand how work android-java
Try this in onBindViewHolder method:
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onBindViewHolder(postViewHolder postViewHolder, int position) {
addPostTimeline addPost = addPostTimelines.get(position);
try {
CircleImageView img=postViewHolder.imgFoto;
JSONObject fileson=addPost.getDatosTimeine().getJSONObject("file");
if(!fileson.getBoolean("err") && fileson.getString("type").equals("pic")){
//image must be visible and no error
postViewHolder.imgTimeLine.setVisibility(View.VISIBLE);
postViewHolder.contentFiles.setVisibility(View.VISIBLE);
imageTimeline imgTm=new imageTimeline(fileson.getString("src"), postViewHolder.imgTimeLine);
imgTm.execute();
}else if(!fileson.getBoolean("err") && !fileson.getString("type").equals("pic")){
//image shouldn't be visible and no error
postViewHolder.imgTimeLine.setVisibility(View.GONE);
postViewHolder.contentFiles.setVisibility(View.VISIBLE);
}else{
//error
postViewHolder.imgTimeLine.setVisibility(View.GONE);
postViewHolder.contentFiles.setVisibility(View.GONE);
}
putImgProfile putImg=new putImgProfile(addPost.getDatosTimeine().getString("pDir"), img);
putImg.execute();
} catch (JSONException e) {
e.printStackTrace();
}
}
You need to reset the visible where you don’t need to set the visible.
postViewHolder.imgTimeLine.setVisibility(View.VISIBLE);// reset
if(!fileson.getBoolean("err")){ // si tiene archivos adjuntos
switch (fileson.getString("type")){
case "Pic":
imageTimeline imgTm=new imageTimeline(fileson.getString("src"),
postViewHolder.imgTimeLine);
imgTm.execute();
break;
default:
postViewHolder.imgTimeLine.setVisibility(View.GONE);
break;
}
}else{
postViewHolder.contentFiles.setVisibility(View.GONE);
}

Android: List View and Scroll View compatability

A quick note about my application. This is an app that uses an API to get server requests about specific players for a game called League of Legends (LoL)
I recently changed my code from a static layout of 10 pre-set most recent matches to a ListView in order to avoid cludder as well in case a player did not have 10 recent matches.
The issue I am having with this ListView, is that when it is created, you can not scroll up and down through it. That is to say that it is created in a very small height, and when you scroll in it, the page doesn't scroll, the ListView itself scrolls. This is not desirable. I would rather have the user scroll the whole screen than just the small portion of the ListView.
I constructed my xml file like so:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="#dimen/activity_horizontal_margin">
<EditText
android:id="#+id/summoner_name"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:hint="Summoner Name"
android:imeOptions="actionSend"
android:lines="1" />
<Spinner
android:id="#+id/regions"
android:layout_width="60dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/search_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="#drawable/searchbuttononclick" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="9dp"
android:orientation="horizontal"
android:paddingLeft="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/leagueicon"
android:layout_width="160dp"
android:layout_height="150dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp" />
<TextView
android:id="#+id/summoner_name_after_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="22dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/league_tier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff0060a8"
android:textSize="18dp" />
<TextView
android:id="#+id/league_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/ranked_wins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff00b515"
android:textSize="18dp" />
<TextView
android:id="#+id/slash_between_wins_and_losses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#ff817a81"
android:textSize="18dp" />
<TextView
android:id="#+id/ranked_losses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#ffb5000f"
android:textSize="18dp" />
</LinearLayout>
<TextView
android:id="#+id/what_were_you_last_season"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#ff817a81"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="16dp"
android:id="#+id/normal_title"
android:textStyle="bold"
android:textColor="#ff000000" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:id="#+id/normal_wins"
android:gravity="center_vertical"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_one"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:id="#+id/normal_kills"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_two"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/normal_assists"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:gravity="center_vertical"
android:id="#+id/normal_wins_value"
android:paddingLeft="5dp"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_three"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:id="#+id/normal_kills_value"
android:textSize="16dp"
android:paddingLeft="5dp"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_four"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_assists_value"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:id="#+id/normal_minion_kills"
android:gravity="center_vertical"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_five"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="14dp"
android:id="#+id/normal_neutral_minion_kills"
android:layout_height="38dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_six"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/normal_turrets_destroyed"
android:textSize="12dp"
android:layout_height="38dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:gravity="center_vertical"
android:id="#+id/normal_minion_kills_value"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_seven"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/neutral_minion_kills_value"
android:textSize="16dp"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_eight"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_turrets_destroyed_value"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<com.ryanfolz.riotgamesapi.SwagObListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="20dp"></LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
As you see, I created a custom ListView called "SwagObListView"
Here is the code for that:
public class SwagObListView extends ListView implements AdapterView.OnItemClickListener {
private List<SwagOb> swagList;
private SwagObClickListener swagClicked;
public SwagObListView(Context context) {
super(context);
}
public SwagObListView(Context context, AttributeSet attrs) {
super(context, attrs);
this.swagList = swagList;
this.swagClicked = swagClicked;
}
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (swagClicked != null) {
swagClicked.onConnectionClicked(swagList.get(i));
}
}
public void setOnSwagObClickListener(SwagObClickListener c){
this.swagClicked = c;
}
public void setSwag(List<SwagOb> swagList) {
this.swagList = swagList;
SwagObAdapter swagDapter = new SwagObAdapter(getContext(), swagList);
setAdapter(swagDapter);
setOnItemClickListener(this);
}
}
As for the SwagOb class, here is the code for that:
public class SwagOb {
private String gameType;
private Drawable championPicturePlayed;
private String kills;
private String deaths;
private Drawable[] summonerSpells;
private String assists;
private String cs;
private String gold;
private boolean won;
private Drawable itemOne, itemTwo, itemThree, itemFour, itemFive, itemSix;
private Drawable[] tempDrawable;
private Drawable[] tempDrawable2;
private String[] tempString;
private SearchPlayerFragment activty;
private CollectUserData data;
public SwagOb(String gameType, Drawable championPicturePlayed, String kills, String deaths, Drawable[] summonerSpells,
String assists, String cs, String gold, boolean won, Drawable itemOne, Drawable itemTwo, Drawable itemThree, Drawable itemFour,
Drawable itemFive, Drawable itemSix, Drawable[] tempDrawable, Drawable[] tempDrawable2, String[] tempString, SearchPlayerFragment activity, CollectUserData data){
this.gameType = gameType;
this.championPicturePlayed = championPicturePlayed;
this.kills = kills;
this.deaths = deaths;
this.summonerSpells = summonerSpells;
this.itemFive = itemFive;
this.itemTwo = itemTwo;
this.itemOne = itemOne;
this.itemThree = itemThree;
this.itemFour = itemFour;
this.itemSix = itemSix;
this.assists = assists;
this.cs = cs;
this.gold = gold;
this.won = won;
this.tempDrawable = tempDrawable;
this.tempDrawable2 = tempDrawable2;
this.tempString = tempString;
this.activty = activity;
this.data = data;
}
(This also has getters and setters but that isn't important.)
Anyone know any ideas as to why this is acting this way?
Android does not allow to add ListView inside ScrollView. Possible workaround for this will be remove scrollview and adding top content to listivew header and bottom content into listview footer.
In your scroll view add this property That will do the trick
android:fillViewport="true"

Android - Capture ScreenShot Programmatically without title bar

I am developing an app in that I want to take a screen shot of current screen but with out title bar. I know the code to Capture a ScreenShot, but unable to customize it.
Code:
munchscreen.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
View v1 = L1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.screenshots);
image.setBackgroundDrawable(bitmapDrawable);
}
});
When I click on Clip then it should capture a screen shot of the screen shown below but should not include the part which I have circled..
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D8D5AA"
>
<LinearLayout
android:id="#+id/clip_from_web_linearlayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/header"
android:orientation="horizontal"
>
<TextView
android:id="#+id/clip_from_web_textview_back"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Back"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
/>
<TextView
android:id="#+id/clip_from_web_textview_header_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clip From Web"
android:layout_gravity="center"
android:layout_marginLeft="60dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
/>
<TextView
android:id="#+id/clip_from_web_textview_clip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clip"
android:layout_gravity="center"
android:layout_marginLeft="60dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
/>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/munch"
android:id="#+id/munchscreen"
android:layout_below="#+id/clip_from_web_linearlayout1"
/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="#+id/screenshots"
android:layout_below="#+id/munchscreen"
android:contentDescription="#string/app_name"
android:layout_centerInParent="true"
/>
<RelativeLayout
android:id="#+id/clip_from_web_bottom_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/header" >
<Button
android:id="#+id/clip_from_web_previous"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="4dp"
android:background="#android:drawable/ic_media_previous"
android:layout_marginTop="2dp"
/>
<Button
android:id="#+id/clip_from_web_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:drawable/ic_menu_rotate"
android:layout_marginTop="5dp"
/>
<Button
android:id="#+id/clip_from_web_next"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toRightOf="#+id/clip_from_web_reload"
android:layout_marginLeft="102dp"
android:background="#android:drawable/ic_media_next"
android:layout_marginTop="2dp"
/>
</RelativeLayout>
Image before Capturing screen shot..
Image after Capturing screen shot..
Take this to another Linear Layout
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/munch"
android:id="#+id/munchscreen"
/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="#+id/screenshots"
android:contentDescription="#string/app_name"
/>
</LinearLayout>
Now find Id for this Linear Layout on oncreate() method making it global variable
LinearLayout ll;
ll = (LinearLayout)findViewById(R.id.linear);
now capture this screen
ll.setDrawingCacheEnabled(true);
ll.buildDrawingCache(true);
Bitmap cs = Bitmap.createBitmap(ll.getDrawingCache());
ll.setDrawingCacheEnabled(false);
Now set this bitmap to your ImageView.
try this...
munchscreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View contentView = getWindow().getDecorView().findViewById(android.R.id.content);
contentView.setDrawingCacheEnabled(true);
contentView.buildDrawingCache();
Bitmap drawingCache = contentView.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), drawingCache);
image = (ImageView) findViewById(R.id.screenshots);
image.setBackgroundDrawable(bitmapDrawable);
}
});
Hey friends I got the solution of above problem.
Follow below steps:-
activity_main.xml
<RelativeLayout
android:id="#+id/toolbar_rl"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:background="#color/header_color"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="0"
tools:ignore="UselessParent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="#string/app_name"
android:padding="#dimen/_8sdp"
android:src="#drawable/ic_back_24" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_marginStart="#dimen/_20sdp"
android:layout_weight="1"
android:gravity="center"
android:text="#string/one_time"
android:textColor="#color/white"
android:textSize="#dimen/_13sdp"
tools:ignore="RtlHardcoded" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="#string/app_name"
android:padding="#dimen/_8sdp"
android:src="#drawable/ic_menu_icon" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:id="#+id/tabScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<ImageView
android:layout_width="fill_parent"
android:layout_height="210dp"
android:adjustViewBounds="true"
android:background="#drawable/otp_background"
android:contentDescription="#string/app_name"
android:scaleType="fitXY">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_16sdp"
android:background="#fff"
android:gravity="center"
android:text="Enter Unique Identification Number"
android:textColor="#color/header_color"
android:textSize="#dimen/_16sdp" />
<LinearLayout
android:id="#+id/layout_otp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_26sdp"
android:gravity="top|center"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextone"
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_42sdp"
android:inputType="number"
android:maxLength="1"
android:nextFocusRight="#+id/editText_two"
tools:ignore="LabelFor">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTexttwo"
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_42sdp"
android:inputType="numberDecimal"
android:maxLength="1"
tools:ignore="LabelFor" />
<EditText
android:id="#+id/editTextthree"
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_42sdp"
android:inputType="numberDecimal"
android:maxLength="1"
tools:ignore="LabelFor" />
<EditText
android:id="#+id/editTextfour"
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_42sdp"
android:inputType="numberDecimal"
android:maxLength="1"
tools:ignore="LabelFor" />
<EditText
android:id="#+id/editTextfive"
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_42sdp"
android:inputType="numberDecimal"
android:maxLength="1"
tools:ignore="LabelFor" />
</LinearLayout>
<Button
android:id="#+id/btn_submit"
android:layout_width="#dimen/_220sdp"
android:layout_height="#dimen/_40sdp"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/_46sdp"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:layout_marginTop="#dimen/_26sdp"
android:background="#drawable/editbox_one"
android:text="#string/capture"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="#dimen/_16sdp"
android:typeface="serif" />
</TableLayout>
</ScrollView>
This xml looks like.
in MainActivity Add some code.
3.1 Declare the Button.
Button button_submit;
3.2 Initialize the button.
button_submit = (Button) findViewById(R.id.btn_submit);
3.3 Set set OnClickListener to this button and Call one method i.e
takeScreenshot();
Note:- When you click on this button that time automatically capture the screen without title bar and it will store in file explore with current date, time and.jpg extension(Ex. Fri May 11 151938 GMT+0530 2018.jpg) and this captured image as a bitmap if you want you can set this bitmap to ImageView .
The Code of takeScreenshot().
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
View u = findViewById(R.id.tabScroll);
u.setDrawingCacheEnabled(true);
ScrollView z = (ScrollView) findViewById(R.id.tabScroll);
z.setBackgroundColor(getResources().getColor(R.color.white));
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
u.layout(0, 0, totalWidth, totalHeight);
u.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(u.getDrawingCache());
u.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
The output be looks like..
I hope it will helpful for you.

Categories

Resources