OL盒子战斗力查询工具的请求和响应结构分析:

1. 使用服务器名和角色名请求LOL盒子的服务器。

2. 从返回的网页中使用正则表达式获得战斗力的基本信息。

3. 战斗力信息在HTML中的位置如下。

后续计划:

1. 在现有基础上继续丰富功能,实现其他数据的解析和展示。

2. 查询历史记录功能。

Activity代码暂无,可能会在未来的开发中添加。

public class LOLPowerActivity extends Activity {

private static final int MSG_GETPOWER_SUCCESS = 1;

private static final int MSG_GETPOWER_FAIL = 2;

private static final String[] servers = new String[] {

"电信一", "电信二", "电信三", "电信四", "电信五",

"电信六", "电信七", "电信八", "电信九", "电信十",

"电信十一", "电信十二", "电信十三", "电信十四"

};

private Handler handler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setTitle("LOL战斗力查询");

setContentView(R.layout.layout_lolpower);

getActionBar().setDisplayHomeAsUpEnabled(true);

createHandler();

init();

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

if (item.getItemId() == android.R.id.home) {

finish();

}

return super.onOptionsItemSelected(item);

}

private void init() {

final Spinner spServer = (Spinner) findViewById(R.id.spinnerServer);

ArrayAdapter adapter = new ArrayAdapter<>(this,

android.R.layout.simple_list_item_1, servers);

spServer.setAdapter(adapter);

spServer.setSelection(0);

final EditText etPlayer = (EditText) findViewById(R.id.editTextPlayer);

Button btnSearch = (Button) findViewById(R.id.buttonSearch);

btnSearch.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (spServer.getSelectedItemPosition() < 0 || etPlayer.getText().toString().length() == 0) {

Toast.makeText(LOLPowerActivity.this, "条件不充分,没法查", Toast.LENGTH_LONG).show();

return;

}

search(servers[spServer.getSelectedItemPosition()], etPlayer.getText().toString().trim());

}

});

}

private void createHandler() {

final TextView tvResult = (TextView) findViewById(R.id.textViewResult);

handler = new Handler() {

@Override

public void handleMessage(Message msg) {

super.handleMessage(msg);

switch (msg.what) {

case MSG_GETPOWER_SUCCESS:

String strResult = (String) msg.obj;

if (strResult != null) {

tvResult.setText(strResult);

}

break;

case MSG_GETPOWER_FAIL:

tvResult.setText("查询失败");

break;

default:

break;

}

}

};

}

private void search(final String strServer, final String strPlayer) {

new Thread(new Runnable() {

@Override

public void run() {

String strUrl = "http://lolbox.duowan.com/playerDetail.php?callback=jQuery111109943135452922434_1413010378460&token=524740466";

strUrl += "&serverName=" + URLEncoder.encode(strServer);

strUrl += "&playerName=" + URLEncoder.encode(strPlayer);

URL url;

try {

url = new URL(strUrl);

HttpURLConnection http = (HttpURLConnection) url.openConnection();

http.setReadTimeout(1000 * 200);

InputStream is = http.getInputStream();

BufferedReader isr = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));

StringBuilder sb = new StringBuilder();

String line;

while ((line = isr.readLine()) != null) {

sb.append(line);

}

String strUseful = getUseful(sb.toString());

if (strUseful == null || strUseful.length() == 0) {

Message msg = Message.obtain();

msg.what = MSG_GETPOWER_FAIL;

handler.sendMessage(msg);

} else {

Message msg = Message.obtain();

msg.obj = strUseful;

msg.what = MSG_GETPOWER_SUCCESS;

handler.sendMessage(msg);

}

} catch (Exception e) {

e.printStackTrace();

Message msg = Message.obtain();

msg.what = MSG_GETPOWER_FAIL;

handler.sendMessage(msg);

} finally { // 注意这里的 finally 是必须的,用于关闭流和释放资源。如果忘记写这个,可能会导致内存泄漏等问题。在 finally块中关闭流和释放资源。例如:InputStream isr = null; try{}catch{}finally{if (isr != null) isr.close();} 或者使用 try-with-resources 可以自动关闭流。try (InputStream isr = http.getInputStream()) {} catch (IOException e) {} finally {}

n\n抱歉,您提供的内容不足以完成重构。请提供更具体的信息和上下文,以便我能够更好地理解您的需求并为您提供帮助。

以下是重构后的代码:

```xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="5dp"

android:orientation="vertical"

tools:context=".LOLPowerActivity">

android:layout_width="match_parent"

android:layout_height="50dp">

android:id="@+id/textViewServer"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:gravity="center_vertical"

android:text="服务器"/>

android:id="@+id/spinnerServer"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:ems="10"/>

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/textViewPlayer"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="角色名"/>

android:id="@+id/editTextPlayer"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:ems="10"/>

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/buttonhistory"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="历史"/>

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/buttonSearch"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="查询"/>

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/textViewResult"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="false"/>

```