Skip to content

Commit

Permalink
more work on the tester
Browse files Browse the repository at this point in the history
  • Loading branch information
Luminger committed Oct 16, 2013
1 parent 4d572a0 commit 2514f3c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
3 changes: 2 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name="org.failedprojects.anjaroot.tester.MainActivity"
android:label="@string/app_name" >
Expand Down
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

# Project target.
target=android-18
android.library.reference.1=../AnJaRootLibrary
android.library.reference.1=../android-support-v7-appcompat
18 changes: 18 additions & 0 deletions res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
android:layout_centerHorizontal="true"
android:text="@string/issue_request" />

<TextView
android:id="@+id/install_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="@string/install_text"
android:visibility="gone" />

<Button
android:id="@+id/install_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/install_text"
android:layout_centerHorizontal="true"
android:text="@string/install_btn"
android:visibility="gone" />

<TextView
android:id="@+id/restart_text"
android:layout_width="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<string name="issue_request">Request Access</string>
<string name="restart_text">Access to AnJaRoot has been granted! You now have to restart this app by hitting the button below.</string>
<string name="restart_btn">Restart App</string>
<string name="install_text">AnJaRoot is not installed on your system, you may install it from the Play Store.</string>
<string name="install_btn">Open Play Store</string>
<string name="functional">Access is granted and the power of AnJaRoot may now be used!</string>
<string name="execute_id_command">Execute \'id\' shell command</string>
<string name="get_package_list">First line of packages.list</string>
Expand Down
54 changes: 40 additions & 14 deletions src/org/failedprojects/anjaroot/tester/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,35 @@
import org.failedprojects.anjaroot.library.AnJaRoot;
import org.failedprojects.anjaroot.library.AnJaRootRequester;

import android.app.Activity;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements
public class MainActivity extends ActionBarActivity implements
AnJaRootRequester.ConnectionStatusListener,
AnJaRootRequester.AsyncRequestHandler {
private boolean connected = false;
private AnJaRootRequester requester;
private ProgressDialog dialog;
private ActionBar ab;

@Override
protected void onCreate(Bundle savedInstanceState) {
// normal onCreate business
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// init ActionBar
ab = getSupportActionBar();
ab.setTitle(R.string.app_name);

// instantiate a new requester, needed to request access if it's not
// already granted.
requester = new AnJaRootRequester(MainActivity.this, this);
Expand All @@ -60,6 +66,29 @@ protected void onCreate(Bundle savedInstanceState) {
dialog.setMessage("Requesting access...");
dialog.setIndeterminate(true);

if (!AnJaRoot.isInstalled()) {
// show the "AnJaRoot is not installed" UI
findViewById(R.id.install_text).setVisibility(View.VISIBLE);
findViewById(R.id.install_btn).setVisibility(View.VISIBLE);

// Hide the requesting UI
findViewById(R.id.access_not_granted).setVisibility(View.GONE);
findViewById(R.id.issue_request).setVisibility(View.GONE);
} else if (AnJaRoot.isAccessGranted()) {
// Display UI which lets the user issue commands
findViewById(R.id.functional).setVisibility(View.VISIBLE);
findViewById(R.id.execute_id_command).setVisibility(View.VISIBLE);
findViewById(R.id.get_packages_list).setVisibility(View.VISIBLE);

// Hide the requesting UI
findViewById(R.id.access_not_granted).setVisibility(View.GONE);
findViewById(R.id.issue_request).setVisibility(View.GONE);
}

prepareButtons();
}

private void prepareButtons() {
// prepare the suicide button
Button suicide = (Button) findViewById(R.id.restart_btn);
suicide.setOnClickListener(new OnClickListener() {
Expand Down Expand Up @@ -88,18 +117,6 @@ public void onClick(View v) {
}
});

// TODO rename this library functions, they are not named properly
if (AnJaRoot.isAccessPossible() && AnJaRoot.isAccessGranted()) {
// Display UI which lets the user issue commands
findViewById(R.id.functional).setVisibility(View.VISIBLE);
findViewById(R.id.execute_id_command).setVisibility(View.VISIBLE);
findViewById(R.id.get_packages_list).setVisibility(View.VISIBLE);

// Hide the requesting UI
findViewById(R.id.access_not_granted).setVisibility(View.GONE);
findViewById(R.id.issue_request).setVisibility(View.GONE);
}

// prepare the "get id" button
Button id = (Button) findViewById(R.id.execute_id_command);
id.setOnClickListener(new OnClickListener() {
Expand Down Expand Up @@ -161,6 +178,15 @@ public void onClick(View v) {
AnJaRoot.dropAccess();
}
});

// prepare the "Open Play Store" Button
Button install = (Button) findViewById(R.id.install_btn);
install.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AnJaRoot.openPlayStore(MainActivity.this);
}
});
}

@Override
Expand Down

0 comments on commit 2514f3c

Please sign in to comment.