Back to project page Genius-Android.
The source code is released under:
Apache License
If you think the Android project Genius-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.qiujuer.genius.sample; //from w w w . java 2 s .co m import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.TextView; import net.qiujuer.genius.Genius; import net.qiujuer.genius.app.UIKit; import net.qiujuer.genius.command.Command; import net.qiujuer.genius.nettool.DnsResolve; import net.qiujuer.genius.nettool.Ping; import net.qiujuer.genius.nettool.Telnet; import net.qiujuer.genius.nettool.TraceRoute; import net.qiujuer.genius.util.FixedList; import net.qiujuer.genius.util.HashUtils; import net.qiujuer.genius.util.Log; import net.qiujuer.genius.util.Tools; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; public class CaseActivity extends ActionBarActivity { private static final String TAG = CaseActivity.class.getSimpleName(); TextView mText = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_case); // ???? Genius.initialize(getApplication()); mText = (TextView) findViewById(R.id.text); // ???? Log.addCallbackListener(new Log.LogCallbackListener() { @Override public void onLogArrived(final Log data) { //????????? UIKit.runOnMainThreadAsync(new Runnable() { @Override public void run() { if (mText != null) mText.append("\n" + data.getMsg()); } }); } }); // ???? testLog(); testTool(); testToolKit(); testHashUtils(); testFixedList(); testNetTool(); testCommand(); } @Override protected void onDestroy() { super.onDestroy(); mText = null; // ??? Genius.dispose(); } /** * ?? ??? */ private void testToolKit() { // ?????????????????????????????????????????????? // ???????????????????????????????? Thread thread = new Thread(new Runnable() { @Override public void run() { // ?????????????????????????? // ???????????????????? String msg = "ToolKit:"; long start = System.currentTimeMillis(); // ???????????????? // ?????????????? // ????????????????????? // ??????????????????????????? UIKit.runOnMainThreadSync(new Runnable() { @Override public void run() { Tools.sleepIgnoreInterrupt(20); } }); msg += "??????:" + (System.currentTimeMillis() - start) + ", "; start = System.currentTimeMillis(); // ?????????????? // ???????????????????????????? UIKit.runOnMainThreadAsync(new Runnable() { @Override public void run() { Tools.sleepIgnoreInterrupt(20); } }); msg += "????:" + (System.currentTimeMillis() - start) + " "; Log.v(TAG, msg); } }); thread.start(); } private void testTool() { Log.i(TAG, "ToolKit?getAndroidId?" + Tools.getAndroidId(Genius.getApplication())); Log.i(TAG, "ToolKit?getSerialNumber?" + Tools.getSerialNumber()); } /** * ???? */ private void testLog() { //????????Android Log????????????false Log.setCallLog(true); //????????? Log.clearLogFile(); //?????????????????????????????????Mb? Log.setSaveLog(true, 10, 1); //????????????????????? //??????????????SD???????????????????? //?????????????????????????????????? //?????????SD????? Log.setCopyExternalStorage(true, "Test/Logs"); //?????? //VERBOSE?5?ERROR?1?????? Log.setLevel(Log.ALL); Log.v(TAG, "???? VERBOSE ???"); Log.d(TAG, "???? DEBUG ???"); Log.i(TAG, "???? INFO ???"); Log.w(TAG, "???? WARN ???"); Log.e(TAG, "???? ERROR ???"); Log.setLevel(Log.INFO); Log.v(TAG, "?????? VERBOSE ???"); Log.d(TAG, "?????? DEBUG ???"); Log.i(TAG, "?????? INFO ???"); Log.w(TAG, "?????? WARN ???"); Log.e(TAG, "?????? ERROR ???"); Log.setLevel(Log.ALL); } /** * ??MD5 */ private void testHashUtils() { Log.i(TAG, "HashUtils?QIUJUER?MD5???" + HashUtils.getMD5String("QIUJUER")); //??MD5??????????file??????? } /** * ???????? */ private void testFixedList() { //?????????5 FixedList<Integer> list = new FixedList<Integer>(5); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); //??4??? list.add(1); list.add(2); list.add(3); list.add(4); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); //????2? list.add(5); list.add(6); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); //?????? list.setMaxSize(6); list.add(7); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); list.add(8); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); //??????????????????? list.setMaxSize(3); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); list.add(9); Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize()); //????????????????? List<Integer> addList = new ArrayList<Integer>(); addList.add(10); addList.add(11); addList.add(12); addList.add(13); list.addAll(addList); Log.i(TAG, "FixedList:AddList:" + list.toString() + " " + list.size() + " ," + list.getMaxSize()); //??poll??????? Log.i(TAG, "FixedList:Poll:[" + list.poll() + "] " + list.size() + " ," + list.getMaxSize()); Log.i(TAG, "FixedList:Poll:[" + list.poll() + "] " + list.size() + " ," + list.getMaxSize()); Log.i(TAG, "FixedList:Poll:[" + list.poll() + "] " + list.size() + " ," + list.getMaxSize()); //?????????add?? list.addLast(14); list.addLast(15); list.addLast(16); list.addLast(17); list.addLast(18); Log.i(TAG, "FixedList:AddLast:" + list.toString() + " " + list.size() + " ," + list.getMaxSize()); //?????????????????? list.addFirst(19); list.addFirst(20); Log.i(TAG, "FixedList:AddFirst:" + list.toString() + " " + list.size() + " ," + list.getMaxSize()); //Remove?poll?????????????????????? list.remove(); Log.i(TAG, "FixedList:Remove:" + list.toString() + " " + list.size() + " ," + list.getMaxSize()); //????? list.clear(); Log.i(TAG, "FixedList:Clear:" + list.toString() + " " + list.size() + " ," + list.getMaxSize()); //??List???,????2 List<Integer> list1 = new FixedList<Integer>(2); list1.add(1); list1.add(2); Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString()); list1.add(3); Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString()); list1.add(4); Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString()); list1.clear(); Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString()); } /** * ??????? */ private void testCommand() { //???? Thread thread = new Thread() { public void run() { //??????ProcessBuilder????????? Command command = new Command(Command.TIMEOUT, "/system/bin/ping", "-c", "4", "-s", "100", "www.baidu.com"); //????????? String res = Command.command(command); Log.i(TAG, "\n\nCommand ?????" + res); } }; thread.setDaemon(true); thread.start(); //?? Command command = new Command("/system/bin/ping", "-c", "4", "-s", "100", "www.baidu.com"); //??????? //???????????????? //????????????????? Command.command(command, new Command.CommandListener() { @Override public void onCompleted(String str) { Log.i(TAG, "\n\nCommand ?? onCompleted?\n" + str); } @Override public void onCancel() { Log.i(TAG, "\n\nCommand ?? onCancel"); } @Override public void onError(Exception e) { Log.i(TAG, "\n\nCommand ?? onError:" + (e != null ? e.toString() : "null")); } }); } /** * ???????? */ public void testNetTool() { //?????????IP???? Thread thread = new Thread() { public void run() { //??????????????????IP Ping ping = new Ping(4, 32, "www.baidu.com", true); ping.start(); Log.i(TAG, "Ping?" + ping.toString()); //??????????????? DnsResolve dns = null; try { // ??????DNS????????????? dns = new DnsResolve("www.baidu.com", InetAddress.getByName("202.96.128.166")); dns.start(); Log.i(TAG, "DnsResolve?" + dns.toString()); } catch (UnknownHostException e) { e.printStackTrace(); } //??????? Telnet telnet = new Telnet("www.baidu.com", 80); telnet.start(); Log.i(TAG, "Telnet?" + telnet.toString()); //?? TraceRoute traceRoute = new TraceRoute("www.baidu.com"); traceRoute.start(); Log.i(TAG, "\n\nTraceRoute?" + traceRoute.toString()); } }; thread.setDaemon(true); thread.start(); } }