Navigation Menu

Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
miracle2k committed Feb 24, 2009
0 parents commit 4931630
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/BRANCH_TODO
/bin/*
33 changes: 33 additions & 0 deletions .project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>WifiLock</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
18 changes: 18 additions & 0 deletions AndroidManifest.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.elsdoerfer.wifilock"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ToggleActivity"
android:label="@string/app_name"
android:theme="@style/Theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".WifiLockService"/>
</application>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
</manifest>
Binary file added res/drawable/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions res/layout/main.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="@style/Theme"
>
</FrameLayout>
3 changes: 3 additions & 0 deletions res/values/colors.xml
@@ -0,0 +1,3 @@
<resources>
<drawable name="transparent_background">#00000000</drawable>
</resources>
7 changes: 7 additions & 0 deletions res/values/strings.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">WifiLock</string>
<string name="service_enabled">WifiLock is now ENABLED, and your wifi connection will remain active at all times.</string>
<string name="service_disabled">WifiLock is now DISABLED, and your wifi may be shutoff when sleeping to conserve battery power.</string>
</resources>
7 changes: 7 additions & 0 deletions res/values/styles.xml
@@ -0,0 +1,7 @@
<resources>
<style name="Theme">
<item name="android:windowBackground">@drawable/transparent_background</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
</style>
</resources>
28 changes: 28 additions & 0 deletions src/com/elsdoerfer/wifilock/R.java
@@ -0,0 +1,28 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.elsdoerfer.wifilock;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
public static final int transparent_background=0x7f020001;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
public static final int service_disabled=0x7f040002;
public static final int service_enabled=0x7f040001;
}
public static final class style {
public static final int Theme=0x7f050000;
}
}
31 changes: 31 additions & 0 deletions src/com/elsdoerfer/wifilock/ToggleActivity.java
@@ -0,0 +1,31 @@
package com.elsdoerfer.wifilock;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class ToggleActivity extends Activity {

static private String LOG_TAG = "WifiLock.Toggle";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

final Intent svc = new Intent(this, WifiLockService.class);

if (WifiLockService.serviceRunning) {
Log.d(LOG_TAG, "before stopService");
stopService(svc);
Log.d(LOG_TAG, "after stopService");
}
else{
Log.d(LOG_TAG, "before startService");
startService(svc);
Log.d(LOG_TAG, "after startService");
}

this.finish();
}
}
59 changes: 59 additions & 0 deletions src/com/elsdoerfer/wifilock/WifiLockService.java
@@ -0,0 +1,59 @@
package com.elsdoerfer.wifilock;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class WifiLockService extends Service {

/**
* Global state of this service. Is checked by the
* toggle activity to determine whether to start or
* stop the service.
*/
static public boolean serviceRunning = false;

/**
* The WifiLock the service holds while running.
*/
protected WifiManager.WifiLock lock = null;

static private String LOG_TAG = "WifiLock.Service";

public WifiLockService() {}

@Override
public IBinder onBind(Intent intent) { return null; }

@Override
public void onCreate() {
Log.v(LOG_TAG, "WifiLock service about to be created");
super.onCreate();

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
lock = manager.createWifiLock("com.elsdoerfer.wifilock");
lock.acquire();
serviceRunning = true;

Toast.makeText(this, R.string.service_enabled, Toast.LENGTH_LONG).show();

Log.v(LOG_TAG, "WifiLock service creation completed");
}

@Override
public void onDestroy() {
Log.v(LOG_TAG, "WifiLock service about to shutdown");

serviceRunning = false;
lock.release();
Toast.makeText(this, R.string.service_disabled, Toast.LENGTH_LONG).show();

super.onDestroy();
Log.v(LOG_TAG, "WifiLock service shutdown completed");
}

}

0 comments on commit 4931630

Please sign in to comment.