Skip to content

Commit

Permalink
Add screenshot to the power menu ala CM10
Browse files Browse the repository at this point in the history
Change-Id: Ic239dcdf9aa7d652f63574a66030385ecfd9d7c9
  • Loading branch information
imnuts committed Nov 16, 2012
1 parent 3eb8fe2 commit 72ae101
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
Binary file added core/res/res/drawable-hdpi/ic_lock_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/res/res/drawable-mdpi/ic_lock_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/res/res/values/public.xml
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@
<public type="drawable" name="ic_menu_sort_alphabetically" id="0x0108009c" />
<public type="drawable" name="ic_menu_sort_by_size" id="0x0108009d" />
<public type="drawable" name="ic_lock_reboot" id="0x0108009e" />
<public type="drawable" name="ic_lock_screenshot" id="0x0108009f" />

<public type="layout" name="activity_list_item" id="0x01090000" />
<public type="layout" name="expandable_list_content" id="0x01090001" />
Expand Down
3 changes: 3 additions & 0 deletions core/res/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@
<!-- label for item that reboots the phone to bootloader in phone options dialog -->
<string name="global_action_reboot_bootloader">Bootloader</string>

<!-- label for item that screenshots in phone options dialog -->
<string name="global_action_screenshot">Screenshot</string>

<!-- Button to reboot the phone, within the Phone Options dialog -->
<string name="reboot_system" product="tablet">Reboot tablet</string>
<string name="reboot_system" product="default">Reboot phone</string>
Expand Down
3 changes: 3 additions & 0 deletions core/res/res/values/symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1822,4 +1822,7 @@
<java-symbol type="string" name="global_action_reboot_bootloader" />
<java-symbol type="string" name="global_action_reboot_download" />
<java-symbol type="string" name="global_action_reboot_recovery" />

<!-- Screenshot -->
<java-symbol type="string" name="global_action_screenshot" />
</resources>
107 changes: 105 additions & 2 deletions policy/src/com/android/internal/policy/impl/GlobalActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.content.ServiceConnection;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
Expand Down Expand Up @@ -251,7 +255,7 @@ public boolean showBeforeProvisioning() {
}
});

// next: reboot
// second: reboot
mItems.add(
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_reboot,
Expand All @@ -276,9 +280,26 @@ public boolean showBeforeProvisioning() {
}
});

// next: airplane mode
// third: airplane mode
mItems.add(mAirplaneModeOn);

// fourth: screenshot
mItems.add(
new SinglePressAction(com.android.internal.R.drawable.ic_lock_screenshot,
R.string.global_action_screenshot) {
public void onPress() {
takeScreenshot();
}

public boolean showDuringKeyguard() {
return true;
}

public boolean showBeforeProvisioning() {
return true;
}
});

// next: bug report, if enabled
if (Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0) {
Expand Down Expand Up @@ -405,6 +426,88 @@ public boolean showBeforeProvisioning() {
}
}

/**
* functions needed for taking screenhots.
* This leverages the built in ICS screenshot functionality
*/
final Object mScreenshotLock = new Object();
ServiceConnection mScreenshotConnection = null;

final Runnable mScreenshotTimeout = new Runnable() {
@Override public void run() {
synchronized (mScreenshotLock) {
if (mScreenshotConnection != null) {
mContext.unbindService(mScreenshotConnection);
mScreenshotConnection = null;
}
}
}
};

private void takeScreenshot() {
synchronized (mScreenshotLock) {
if (mScreenshotConnection != null) {
return;
}
ComponentName cn = new ComponentName("com.android.systemui",
"com.android.systemui.screenshot.TakeScreenshotService");
Intent intent = new Intent();
intent.setComponent(cn);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
synchronized (mScreenshotLock) {
if (mScreenshotConnection != this) {
return;
}
Messenger messenger = new Messenger(service);
Message msg = Message.obtain(null, 1);
final ServiceConnection myConn = this;
Handler h = new Handler(mHandler.getLooper()) {
@Override
public void handleMessage(Message msg) {
synchronized (mScreenshotLock) {
if (mScreenshotConnection == myConn) {
mContext.unbindService(mScreenshotConnection);
mScreenshotConnection = null;
mHandler.removeCallbacks(mScreenshotTimeout);
}
}
}
};
msg.replyTo = new Messenger(h);
msg.arg1 = msg.arg2 = 0;

/* remove for the time being
if (mStatusBar != null && mStatusBar.isVisibleLw())
msg.arg1 = 1;
if (mNavigationBar != null && mNavigationBar.isVisibleLw())
msg.arg2 = 1;
*/

/* wait for the dialog box to close */
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
}

/* take the screenshot */
try {
messenger.send(msg);
} catch (RemoteException e) {
}
}
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
if (mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
mScreenshotConnection = conn;
mHandler.postDelayed(mScreenshotTimeout, 10000);
}
}
}

private void prepareDialog() {
refreshSilentMode();
mAirplaneModeOn.updateState(mAirplaneState);
Expand Down

0 comments on commit 72ae101

Please sign in to comment.