I have a problem when I take a snapshot of my screen. The bitmap paint everything but the bottom of the view. I attach some code of the layout and also from the snapshot call.
The activity has also an action bar with TabListeners. So it has 3 tabs and few buttons in the action bar (they are shown on the snapshot. Could be nice if I could delete them as well in the snapshot causes I don’t need them at all ^^U But it is not the important thing).
Snapshot:
private void snapShot() {
Log.d("On snapShot","At beggining");
Bitmap bitmap;
getWindow().getDecorView().setDrawingCacheEnabled(true);
try{
bitmap = Bitmap.createBitmap(getWindow().getDecorView().getDrawingCache());
}catch (IllegalStateException e){
bitmap = null;
}
try{
Log.d("On snapShot", "inside Try");
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()){
pic = new File(root,"pic.png");
FileOutputStream out = new FileOutputStream(pic);
bitmap.compress(CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
}catch(IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
getWindow().getDecorView().setDrawingCacheEnabled(false);
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="20"
>
<com.example.daemon.views.CaptionView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/legendView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.example.daemon.views.CaptionView>
<View
android:id="@+id/lineSeparation"
android:background="#F000"
android:layout_marginTop="1dp"
android:layout_height="1dp"
android:layout_width="match_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.example.daemon.views.ChartView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewChart"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.example.daemon.views.ChartView>
</LinearLayout>
</LinearLayout>
Add a little more code, where the action bar and the tabs are created.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Set the application works only on Landscape orientation.
actionBar = getActionBar(); // Creates the action bar.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Log.i(TAG, "On create");
String label1 = "one day";
Tab tab = actionBar.newTab(); // Creates a tab
tab.setText(label1);
// Links the tab created with an existing Fragment
TabListener<Tab1Fragment> tl = new TabListener<Tab1Fragment>(this, label1, Tab1Fragment.class);
tab.setTabListener(tl); // Makes the tab respond the touch events.
actionBar.addTab(tab); // Add the tab to the action bar.
PNG when i push the snapshot:

How it should appear, picture from my camera:

The problem (I think) is that when the bitmap is created its maximun height is 732 (the same than the view) but it start capturing the view from the top (including the action bar that is not on the view) so it only can paint the first 732 rows. The point is that if I said to start after the action bar, an error appear because “y + height cannot be > bitmap.height” so… what can I do?
Thank you a lot!!!
I found the solution.
It was hard to find it but it’s quite easy.
I just add to the first LinearLayout (the one which content all the others) an id.
Then I can create the bitmap finding the view by id.
In the layout I add:
android:id="@+id/mainLayout"and then in the activity:
Thanks for the support and I hope this will help to someone else.