Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fature/development setting #117

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Run/Debug

* Open project in intellij
* Open _edit configurations_ to create a new run/debug configuration
* Choose a new gradle configuration and name it `build and run` that runs <code>./gradlew buildPlugin runIdea</code>
* Choose a new gradle configuration and name it `build and run` that runs <code>./gradlew buildPlugin runIde</code>
![Create debug configuration](website/debug_howto.png)
* hit debug button as usual

Running from command line
-------------------------
<code>
./gradlew buildPlugin runIdea
./gradlew buildPlugin runIde
</code>

Create new menu item
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The following commands are provided:
* Restart App
* Clear App Data
* Clear App Data and Restart
* start Aapplication Development Setting page

Usage
=====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected void fillActions(@Nullable final Project project,
addAction("com.developerphil.adbidea.action.RestartWithDebuggerAction", group);
}

group.addSeparator();
addAction("com.developerphil.adbidea.action.StartDevelopmentActivityAction", group);

}

protected boolean isEnabled() {
Expand Down
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 StartDevelopmentActivityAction extends AdbAction {

public void actionPerformed(AnActionEvent e, Project project) {
AdbFacade.startDevelopmentActivity(project);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/developerphil/adbidea/adb/AdbFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class AdbFacade {

private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("AdbIdea-%d").build());

public static void startDevelopmentActivity(Project project){
executeOnDevice(project, new StartActivityCommand("android.settings.APPLICATION_DEVELOPMENT_SETTINGS"));
}

public static void uninstall(Project project) {
executeOnDevice(project, new UninstallCommand());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 javax.annotation.Nonnull;
import java.util.concurrent.TimeUnit;

import static com.developerphil.adbidea.ui.NotificationHelper.error;
import static com.developerphil.adbidea.ui.NotificationHelper.info;

public class StartActivityCommand implements Command {
private String action;

public StartActivityCommand(@Nonnull String action) {
this.action = action;
}

@Override
public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) {
try {
GenericReceiver genericReceiver = new GenericReceiver();
device.executeShellCommand("am start -a " + action, genericReceiver, 15L, TimeUnit.SECONDS);
if(genericReceiver.isSuccess()) {
info(String.format("<b>%s</b> started on %s", action, device.getName()));
return true;
}
error("Error: " + genericReceiver.getAdbOutputString());
} catch (Exception e1) {
error("Start fail... \n" + e1.getMessage());
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
public class GenericReceiver extends MultiLineReceiver {

private static final String SUCCESS_OUTPUT = "Success"; //$NON-NLS-1$
private static final Pattern FAILURE_PATTERN = Pattern.compile("Failure\\s+\\[(.*)\\]"); //$NON-NLS-1$
private static final Pattern FAILURE_PATTERN = Pattern.compile("(Failure|Error)[:]?\\s+(.*)");

private String mErrorMessage = null;
private boolean isSuccess = false;

private List<String> adbOutputLines = new ArrayList<String>();

Expand All @@ -23,18 +23,12 @@ public GenericReceiver() {
@Override
public void processNewLines(String[] lines) {
this.adbOutputLines.addAll(Arrays.asList(lines));

for (String line : lines) {
if (!line.isEmpty()) {
if (line.startsWith(SUCCESS_OUTPUT)) {
mErrorMessage = null;
isSuccess = true;
} else {
Matcher m = FAILURE_PATTERN.matcher(line);
if (m.matches()) {
mErrorMessage = m.group(1);
} else {
mErrorMessage = "Unknown failure";
}
isSuccess = !FAILURE_PATTERN.matcher(line).matches();
}
}
}
Expand All @@ -49,11 +43,12 @@ public List<String> getAdbOutputLines() {
return adbOutputLines;
}

public boolean isSuccess() {
return mErrorMessage == null;
public String getAdbOutputString() {
return String.join("\n", adbOutputLines);
}

public String getErrorMessage() {
return mErrorMessage;
public boolean isSuccess() {
return isSuccess;
}

}
8 changes: 8 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@
text="ADB Restart App With Debugger"
description="Restarts the current application and attach the debugger">
</action>

<separator/>
<action id="com.developerphil.adbidea.action.StartDevelopmentActivityAction"
class="com.developerphil.adbidea.action.StartDevelopmentActivityAction"
text="ADB Start Development Activity"
description="Starts development activity of system setting">
</action>

<add-to-group group-id="AndroidToolsGroup" anchor="first"/>
</group>
</actions>
Expand Down
Binary file modified website/debug_howto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.