-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
272 additions
and
10 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
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
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
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
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/ryey/easer/plugins/operation/hotspot/HotspotContentLayout.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,39 @@ | ||
/* | ||
* Copyright (c) 2016 - 2017 Rui Zhao <renyuneyun@gmail.com> | ||
* | ||
* This file is part of Easer. | ||
* | ||
* Easer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Easer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Easer. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ryey.easer.plugins.operation.hotspot; | ||
|
||
import android.content.Context; | ||
|
||
import ryey.easer.R; | ||
import ryey.easer.commons.plugindef.StorageData; | ||
import ryey.easer.plugins.reusable.SwitchContentLayout; | ||
|
||
public class HotspotContentLayout extends SwitchContentLayout { | ||
|
||
public HotspotContentLayout(Context context) { | ||
super(context); | ||
setDesc(context.getString(R.string.operation_hotspot)); | ||
} | ||
|
||
@Override | ||
public StorageData getData() { | ||
return new HotspotOperationData(state()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/ryey/easer/plugins/operation/hotspot/HotspotHelper.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,55 @@ | ||
package ryey.easer.plugins.operation.hotspot; | ||
|
||
import android.content.Context; | ||
import android.net.wifi.WifiConfiguration; | ||
import android.net.wifi.WifiManager; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
class HotspotHelper { | ||
private static HotspotHelper instance = null; | ||
private WifiManager wifiManager; | ||
|
||
static synchronized HotspotHelper getInstance(Context context) { | ||
if (instance != null) | ||
return instance; | ||
instance = new HotspotHelper(); | ||
instance.wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); | ||
return instance; | ||
} | ||
|
||
boolean enableAp() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { | ||
boolean apStatus = setApStatus(null, true); | ||
return apStatus; | ||
} | ||
|
||
boolean disableAp() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { | ||
boolean apStatus = setApStatus(null, false); | ||
return apStatus; | ||
} | ||
|
||
boolean isApEnabled() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
Method isWifiApEnabledmethod = wifiManager.getClass().getMethod("isWifiApEnabled"); | ||
Boolean isWifiApEnabled = (boolean) isWifiApEnabledmethod.invoke(wifiManager); | ||
return isWifiApEnabled; | ||
} | ||
|
||
WifiConfiguration getApConfiguration() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
Method getWifiApConfigurationMethod = wifiManager.getClass().getMethod("getWifiApConfiguration"); | ||
WifiConfiguration netConfig = (WifiConfiguration) getWifiApConfigurationMethod.invoke(wifiManager); | ||
return netConfig; | ||
} | ||
|
||
boolean setApStatus(WifiConfiguration netConfig, boolean enable) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
Method setWifiApMethod = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); | ||
boolean apStatus = (boolean) setWifiApMethod.invoke(wifiManager, netConfig, enable); | ||
return apStatus; | ||
} | ||
|
||
int getApState() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
Method getWifiApStateMethod = wifiManager.getClass().getMethod("getWifiApState"); | ||
int apState = (int) getWifiApStateMethod.invoke(wifiManager); | ||
return apState; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/ryey/easer/plugins/operation/hotspot/HotspotLoader.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,52 @@ | ||
/* | ||
* Copyright (c) 2016 - 2017 Rui Zhao <renyuneyun@gmail.com> | ||
* | ||
* This file is part of Easer. | ||
* | ||
* Easer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Easer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Easer. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ryey.easer.plugins.operation.hotspot; | ||
|
||
import android.content.Context; | ||
|
||
import ryey.easer.commons.plugindef.operationplugin.OperationData; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationLoader; | ||
|
||
public class HotspotLoader extends OperationLoader { | ||
HotspotHelper helper; | ||
|
||
public HotspotLoader(Context context) { | ||
super(context); | ||
helper = HotspotHelper.getInstance(context); | ||
} | ||
|
||
@Override | ||
public boolean _load(OperationData data) { | ||
Boolean state = (Boolean) data.get(); | ||
if (state == null) | ||
return true; | ||
try { | ||
if (helper.isApEnabled() == state) | ||
return true; | ||
if (state) | ||
return helper.enableAp(); | ||
else | ||
return helper.disableAp(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/ryey/easer/plugins/operation/hotspot/HotspotOperationData.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,50 @@ | ||
/* | ||
* Copyright (c) 2016 - 2017 Rui Zhao <renyuneyun@gmail.com> | ||
* | ||
* This file is part of Easer. | ||
* | ||
* Easer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Easer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Easer. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ryey.easer.plugins.operation.hotspot; | ||
|
||
import org.xmlpull.v1.XmlPullParser; | ||
import org.xmlpull.v1.XmlPullParserException; | ||
import org.xmlpull.v1.XmlSerializer; | ||
|
||
import java.io.IOException; | ||
|
||
import ryey.easer.commons.IllegalXmlException; | ||
import ryey.easer.plugins.operation.BooleanOperationData; | ||
|
||
import static ryey.easer.plugins.operation.hotspot.HotspotOperationPlugin.pname; | ||
|
||
public class HotspotOperationData extends BooleanOperationData { | ||
public HotspotOperationData() { | ||
} | ||
|
||
public HotspotOperationData(Boolean state) { | ||
super(state); | ||
} | ||
|
||
@Override | ||
public void parse(XmlPullParser parser) throws IOException, XmlPullParserException, IllegalXmlException { | ||
mParse(parser, pname()); | ||
} | ||
|
||
@Override | ||
public void serialize(XmlSerializer serializer) throws IOException { | ||
mSerialize(serializer, pname()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/ryey/easer/plugins/operation/hotspot/HotspotOperationPlugin.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,53 @@ | ||
/* | ||
* Copyright (c) 2016 - 2017 Rui Zhao <renyuneyun@gmail.com> | ||
* | ||
* This file is part of Easer. | ||
* | ||
* Easer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Easer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Easer. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ryey.easer.plugins.operation.hotspot; | ||
|
||
import android.content.Context; | ||
|
||
import ryey.easer.commons.plugindef.ContentLayout; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationData; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationLoader; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationPlugin; | ||
|
||
public class HotspotOperationPlugin implements OperationPlugin { | ||
public static String pname() { | ||
return "hotspot"; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return pname(); | ||
} | ||
|
||
@Override | ||
public OperationData data() { | ||
return new HotspotOperationData(); | ||
} | ||
|
||
@Override | ||
public ContentLayout view(Context context) { | ||
return new HotspotContentLayout(context); | ||
} | ||
|
||
@Override | ||
public OperationLoader loader(Context context) { | ||
return new HotspotLoader(context); | ||
} | ||
} |
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
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
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
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
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