Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A plugin for Android Studio and Intellij IDEA that speeds up your day to day and

The following commands are provided:

* Toggle Display
* Uninstall App
* Kill App
* Start App
Expand Down Expand Up @@ -61,4 +62,4 @@ License
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
2 changes: 2 additions & 0 deletions src/com/developerphil/adbidea/action/QuickListAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected void fillActions(@Nullable final Project project,
return;
}

addAction("com.developerphil.adbidea.action.ToggleDisplayAction", group);
addAction("com.developerphil.adbidea.action.ClearDataAndRestartAction", group);
addAction("com.developerphil.adbidea.action.UninstallAction", group);
addAction("com.developerphil.adbidea.action.KillAction", group);
addAction("com.developerphil.adbidea.action.StartAction", group);
Expand Down
12 changes: 12 additions & 0 deletions src/com/developerphil/adbidea/action/ToggleDisplayAction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.developerphil.adbidea.action;

import com.developerphil.adbidea.adb.AdbFacade;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;

public class ToggleDisplayAction extends AdbAction {

public void actionPerformed(AnActionEvent e, Project project) {
AdbFacade.toggleDisplay(project);
}
}
4 changes: 4 additions & 0 deletions src/com/developerphil/adbidea/adb/AdbFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static void clearData(Project project) {
public static void clearDataAndRestart(Project project) {
executeOnDevice(project, new ClearDataAndRestartCommand());
}

public static void toggleDisplay(Project project) {
executeOnDevice(project, new ToggleDisplayCommand());
}

private static void executeOnDevice(final Project project, final Command runnable) {
final DeviceResult result = getDevice(project);
Expand Down
30 changes: 30 additions & 0 deletions src/com/developerphil/adbidea/adb/command/ToggleDisplayCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.developerphil.adbidea.adb.command;

import com.android.ddmlib.IDevice;
import com.developerphil.adbidea.adb.command.receiver.GenericReceiver;
import com.intellij.openapi.project.Project;
import org.jetbrains.android.facet.AndroidFacet;

import java.util.concurrent.TimeUnit;

import static com.developerphil.adbidea.adb.AdbUtil.isAppInstalled;
import static com.developerphil.adbidea.ui.NotificationHelper.error;
import static com.developerphil.adbidea.ui.NotificationHelper.info;

public class ToggleDisplayCommand implements Command {

@Override
public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) {
try {
device.executeShellCommand("input keyevent 26", new GenericReceiver(), 5L, TimeUnit.MINUTES);
info(String.format("Toggle the display state on %s", device.getName()));
return true;
}
} catch (Exception e1) {
error("Toggle display failed" + e1.getMessage());
}

return false;
}

}