-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #994 from 1019940946/master
- Loading branch information
Showing
15 changed files
with
913 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903115/AndroidManifest.xml
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="edu.hzuapps.androidworks"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" ></uses-permission> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission> | ||
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission> | ||
|
||
<!-- To auto-complete the email text field in the login form with the user's emails --> | ||
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> | ||
<uses-permission android:name="android.permission.READ_PROFILE" /> | ||
<uses-permission android:name="android.permission.READ_CONTACTS" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/net1314080903115logo" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".homeworks.net1314080903115.Net1314080903115MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".homeworks.net1314080903115.Net1314080903115LoginActivity"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for | ||
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> | ||
<meta-data | ||
android:name="com.google.android.gms.version" | ||
android:value="@integer/google_play_services_version" /> | ||
</application> | ||
|
||
</manifest> |
132 changes: 132 additions & 0 deletions
132
...va/edu/hzuapps/androidworks/homeworks/net1314080903115/Net1314080903115LoginActivity.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,132 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903115; | ||
|
||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import com.google.android.gms.appindexing.Action; | ||
import com.google.android.gms.appindexing.AppIndex; | ||
import com.google.android.gms.common.api.GoogleApiClient; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.util.EntityUtils; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import edu.hzuapps.androidworks.R; | ||
|
||
|
||
public class Net1314080903115LoginActivity extends Activity implements View.OnClickListener { | ||
|
||
private EditText login_Phone, login_PassWord; | ||
private Button login_Login, login_SignUp; | ||
/** | ||
* ATTENTION: This was auto-generated to implement the App Indexing API. | ||
* See https://g.co/AppIndexing/AndroidStudio for more information. | ||
*/ | ||
private GoogleApiClient client; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.net1314080903115login); | ||
|
||
login_Phone = (EditText) findViewById(R.id.login_Phone); | ||
login_PassWord = (EditText) findViewById(R.id.login_PassWord); | ||
login_Login = (Button) findViewById(R.id.login_Login); | ||
login_Login.setOnClickListener(this); | ||
login_SignUp = (Button) findViewById(R.id.login_SignUp); | ||
login_SignUp.setOnClickListener(this); | ||
// ATTENTION: This was auto-generated to implement the App Indexing API. | ||
// See https://g.co/AppIndexing/AndroidStudio for more information. | ||
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); | ||
} | ||
|
||
public void onClick(View v) { | ||
|
||
if (v.getId() == R.id.login_Login) { | ||
|
||
final String phont = login_Phone.getText().toString(); | ||
final String password = login_PassWord.getText().toString(); | ||
|
||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
HttpGet httpGet = new HttpGet("http://lyongsb.cn:81/CloudNotes.asmx/Login?Phone=" + phont + "&PassWord=" + password);//编者按:与HttpPost区别所在,这里是将参数在地址中传递 | ||
HttpResponse response = new DefaultHttpClient().execute(httpGet); | ||
if (response.getStatusLine().getStatusCode() == 200) { | ||
HttpEntity entity = response.getEntity(); | ||
String json3 = EntityUtils.toString(entity);//这里取得的是带xml头的字符串 | ||
String json2 = json3.substring(json3.indexOf("{"), json3.indexOf("}") + 1);//去掉头和尾取得中间的json字符串 | ||
Message msg = Message.obtain(); | ||
msg.obj = json2; | ||
handler.sendMessage(msg); | ||
} | ||
} catch (IOException e) { | ||
} | ||
} | ||
}).start(); | ||
|
||
} | ||
|
||
if (v.getId() == R.id.login_Login) { | ||
|
||
} | ||
|
||
} | ||
|
||
public JSONObject getJSON(String json) { | ||
JSONObject jsonObject=null; | ||
try { | ||
jsonObject = new JSONObject(json); | ||
}catch (JSONException e){ | ||
|
||
} | ||
return jsonObject; | ||
} | ||
|
||
public Handler handler = new Handler() { | ||
@Override | ||
public void handleMessage(Message msg) { | ||
String json = (String) msg.obj; | ||
JSONObject jsonObject = getJSON(json); | ||
|
||
String state = "0"; | ||
String NoteTable=""; | ||
try { | ||
state = jsonObject.getString("state"); | ||
NoteTable = jsonObject.getString("content"); | ||
if (state.equals("1")) { | ||
Net1314080903115MainActivity.Account.State = 2; | ||
Net1314080903115MainActivity.Account.UserName = "黎振锋"; | ||
Intent intent = new Intent(Net1314080903115LoginActivity.this, Net1314080903115MainActivity.class); | ||
startActivity(intent); | ||
} else { | ||
Toast.makeText(Net1314080903115LoginActivity.this, NoteTable, Toast.LENGTH_LONG).show(); | ||
} | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
}; | ||
} |
Oops, something went wrong.