Posts: 292
Threads: 25
Joined: Dec 2010
Reputation:
19
Code: package com.example.t;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Action extends Activity {
private TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action);
getActionBar().setDisplayHomeAsUpEnabled(false);
Intent intent = getIntent();
String user = intent.getStringExtra(Home.USER_NAME);
String pass = intent.getStringExtra(Home.PASS_WORD);
String dest = intent.getStringExtra(Home.END_POINT);
download(dest, user, pass);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_action, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void download(String endpoint, String user, String pass) {
getHTML task = new getHTML();
task.execute(endpoint, user, pass);
textView = (TextView) findViewById(R.id.textView1);
textView.setText("User: "+ user +" Pass: "+ pass +" URL: "+ endpoint);
}
class getHTML extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
try {
get_data(params[0], params[1], params[2]);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
}
}
public String get_data(String dest, String user, String pass) throws IOException{
InputStream is = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(dest);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("email", user));
nameValuePairs.add(new BasicNameValuePair("password", pass));
nameValuePairs.add(new BasicNameValuePair("do","user_login"));
nameValuePairs.add(new BasicNameValuePair("akey", "android_app"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response;
Log.d("http", "Dest: " + dest);
Log.d("http", "User: " + user);
Log.d("http", "Pass: " + pass);
Log.d("http", "Device: " + System.currentTimeMillis());
response = httpclient.execute(httppost);
Boolean outp = request(response);
if(outp) {
Log.i("auth", "Login Successful");
return "0x00";
} else {
Log.i("auth", "Login Failed with " + outp);
return "0x01";
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} finally {
if (is != null) {
is.close();
}
}
return null;
}
public static Boolean request(HttpResponse response){
String result = "";
try{
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
str.append(line);
}
in.close();
result = str.toString();
if(str.toString().equals("0")) {
return true;
} else {
return false;
}
}catch(Exception ex){
result = "Error";
}
return false;
}
}
crAyon makes no warranty with respect to documents or other information available from this place, assumes no legal liability or responsibility whatsoever for the accuracy, completeness, or usefulness of any such information, and does not represent that its use would not infringe privately owned rights. crAyon disclaims all warranties, express and implied, including the warranties of merchantability and fitness for a particular purpose.
Posts: 292
Threads: 25
Joined: Dec 2010
Reputation:
19
Code: package com.example.t;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.workfeed.beta.R;
public class Home extends Activity {
public final static String PASS_WORD = "com.example.t.PASS_WORD";
public final static String USER_NAME = "com.example.t.USER_NAME";
public final static String END_POINT = "com.example.t.END_POINT";
private EditText inputEmail;
private EditText inputPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}
}
public void error(String error, String message) {
TextView nstatus = (TextView) findViewById(R.id.nstatus);
nstatus.setTextSize(40);
nstatus.setText(message);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_home, menu);
return true;
}
public void startNet(View view) {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
Intent intent = new Intent(this, Action.class);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
String dest = "http://workfeed.co/core/wf_auth.php";
String user = inputEmail.getText().toString();
String pass = inputPassword.getText().toString();
intent.putExtra(USER_NAME, user);
intent.putExtra(PASS_WORD, pass);
intent.putExtra(END_POINT, dest);
startActivity(intent);
} else {
TextView nstatus = (TextView) findViewById(R.id.nstatus);
nstatus.setTextSize(40);
nstatus.setText("No Network...");
}
}
}
Code: package com.example.t;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Looper;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.workfeed.beta.R;
public class Action extends Activity {
public TextView textView;
public final static String USER_NAME = "com.example.t.USER_NAME";
public final static String INVALID_PASS = "com.example.t.INVALID_PASS";
static final int DIALOG_ERROR_LOGIN = 1;
static final int DIALOG_OK_LOGIN = 2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action);
getActionBar().setDisplayHomeAsUpEnabled(false);
Intent intent = getIntent();
String user = intent.getStringExtra(Home.USER_NAME);
String pass = intent.getStringExtra(Home.PASS_WORD);
String dest = intent.getStringExtra(Home.END_POINT);
download(dest, user, pass);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_action, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void download(String endpoint, String user, String pass) {
getHTML task = new getHTML();
task.execute(endpoint, user, pass);
}
class getHTML extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
try {
get_data(params[0], params[1], params[2]);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
}
}
public String get_data(String dest, String user, String pass)
throws IOException {
InputStream is = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(dest);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
4);
nameValuePairs.add(new BasicNameValuePair("email", user));
nameValuePairs.add(new BasicNameValuePair("password", pass));
nameValuePairs.add(new BasicNameValuePair("do", "user_login"));
nameValuePairs
.add(new BasicNameValuePair("akey", "android_app"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response;
Log.d("http", "Dest: " + dest);
Log.d("http", "User: " + user);
Log.d("http", "Pass: " + pass);
Log.d("http", "Device: " + System.currentTimeMillis());
response = httpclient.execute(httppost);
Boolean outp = request(response);
if (outp) {
Log.i("auth", "Login Successful");
final Intent intent = new Intent(this, Workfeed.class);
startActivity(intent);
Action.this.finish();
return "0x00";
} else {
Log.e("auth", "Login Failed with " + outp);
fireAlert(1);
return "0x01";
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} finally {
if (is != null) {
is.close();
}
}
return null;
}
public void fireAlert(final Integer alertID) {
Action.this.runOnUiThread(new Runnable() {
public void run() {
switch (alertID) {
case 1:
showDialog(DIALOG_ERROR_LOGIN);
break;
case 2:
// do the work to define the game over Dialog
break;
}
}
});
}
public Dialog onCreateDialog(int id) {
Dialog dialog;
switch (id) {
case DIALOG_ERROR_LOGIN:
final Intent intent = new Intent(this, Home.class);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Error Logging In")
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
startActivity(intent);
Action.this.finish();
}
});
AlertDialog alert = builder.create();
return alert;
case DIALOG_OK_LOGIN:
break;
default:
dialog = null;
}
return null;
}
public static Boolean request(HttpResponse response) {
@SuppressWarnings("unused")
String result = "";
try {
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
in.close();
result = str.toString();
if (str.toString().equals("0")) {
return true;
} else {
return false;
}
} catch (Exception ex) {
result = "Error";
}
return false;
}
}
Code: package com.example.t;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import com.workfeed.beta.R;
public class Workfeed extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_workfeed);
getActionBar().setDisplayHomeAsUpEnabled(false);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Latest");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Latest");
TabSpec spec2=tabHost.newTabSpec("All");
spec2.setIndicator("All");
spec2.setContent(R.id.tab2);
TabSpec spec3=tabHost.newTabSpec("Profile");
spec3.setIndicator("Profile");
spec3.setContent(R.id.tab3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_workfeed, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
Intent intent = new Intent(this, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
}
crAyon makes no warranty with respect to documents or other information available from this place, assumes no legal liability or responsibility whatsoever for the accuracy, completeness, or usefulness of any such information, and does not represent that its use would not infringe privately owned rights. crAyon disclaims all warranties, express and implied, including the warranties of merchantability and fitness for a particular purpose.
|