-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
U-MAGNA\peterq.admin
authored and
U-MAGNA\peterq.admin
committed
Jun 18, 2019
1 parent
73e1175
commit aab9043
Showing
40 changed files
with
1,400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
27 changes: 27 additions & 0 deletions
27
app/src/androidTest/java/com/wifidirect/wifidirectproxy/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.wifidirect.wifidirectproxy; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.InstrumentationRegistry; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.wifidirect.wifidirectproxy", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wifidirect.wifidirectproxy"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<service | ||
android:name=".WifiDirectService" | ||
android:enabled="true" | ||
android:exported="true"> | ||
</service> | ||
|
||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
111 changes: 111 additions & 0 deletions
111
app/src/main/java/com/wifidirect/wifidirectproxy/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.wifidirect.wifidirectproxy; | ||
|
||
import android.os.*; | ||
import android.view.*; | ||
import android.content.*; | ||
import android.widget.*; | ||
import android.app.*; | ||
|
||
public class MainActivity extends Activity { | ||
|
||
boolean running; | ||
java.util.Timer timer; | ||
BroadcastReceiver receiver; | ||
IntentFilter intentFilter; | ||
String status; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
android.util.Log.d("WDPS", "MainActivity.onCreate()"); | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
WifiNotification.initOnce(getApplicationContext()); | ||
|
||
Button button = (Button)findViewById(R.id.button); | ||
button.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Button button = (Button)findViewById(R.id.button); | ||
if (!running) { | ||
startWifi(); | ||
running = true; | ||
button.setText("STOP"); | ||
} else { | ||
stopWifi(); | ||
running = false; | ||
button.setText("START"); | ||
status = "Ready"; | ||
} | ||
} | ||
}); | ||
status = "Ready"; | ||
if (timer == null) { | ||
timer = new java.util.Timer(); | ||
timer.schedule(new Updater(), 1000, 1000); | ||
} | ||
Context context = getApplicationContext(); | ||
intentFilter = new IntentFilter(); | ||
intentFilter.addAction(WifiDirectService.ACTION_SEND_STATUS); | ||
receiver = new MainBroadcastReceiver(); | ||
registerReceiver(receiver, intentFilter); | ||
WifiDirectService.getStatus(context); | ||
} | ||
|
||
public void onResume() { | ||
super.onResume(); | ||
} | ||
|
||
public void onPause() { | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
android.util.Log.d("WDPS", "MainActivity.onDestroy()"); | ||
super.onDestroy(); | ||
if (timer != null) { | ||
timer.cancel(); | ||
timer = null; | ||
} | ||
unregisterReceiver(receiver); | ||
} | ||
|
||
private void startWifi() { | ||
Context ctx = getApplicationContext(); | ||
WifiDirectService.start(ctx); | ||
} | ||
|
||
private void stopWifi() { | ||
Context ctx = getApplicationContext(); | ||
WifiDirectService.stop(getApplicationContext()); | ||
} | ||
|
||
public class Updater extends java.util.TimerTask { | ||
public void run() { | ||
runOnUiThread(new Runnable() {public void run() { | ||
TextView tv = (TextView)findViewById(R.id.status); | ||
tv.setText(status); | ||
WifiDirectService.getStatus(getApplicationContext()); | ||
}}); | ||
} | ||
} | ||
|
||
public class MainBroadcastReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
String action = intent.getAction(); | ||
android.util.Log.d("WDPS", "MainActivity.onReceive() action=" + action); | ||
|
||
switch (action) { | ||
case WifiDirectService.ACTION_SEND_STATUS: | ||
status = intent.getStringExtra("status"); | ||
if (!running) { | ||
running = true; | ||
Button button = (Button)findViewById(R.id.button); | ||
button.setText("STOP"); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.