Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.ninjaroot.myapplication">
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- <!--
- The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
- Google Maps Android API v2, but you must specify either coarse or fine
- location permissions for the 'MyLocation' functionality.
- -->
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity
- android:name=".SplashActivity"
- android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity
- android:name=".Registar"
- android:label="@string/Registar"
- android:screenOrientation="portrait"/>
- <activity android:name=".MainActivity"
- android:screenOrientation="portrait" />
- <!--
- The API key for Google Maps-based APIs is defined as a string resource.
- (See the file "res/values/google_maps_api.xml").
- Note that the API key is linked to the encryption key used to sign the APK.
- You need a different API key for each encryption key, including the release key that is used to
- sign the APK for publishing.
- You can define the keys for the debug and release targets in src/debug/ and src/release/.
- -->
- <meta-data
- android:name="com.google.android.geo.API_KEY"
- android:value="@string/google_maps_key" />
- <activity
- android:name=".MapsActivity"
- android:label="@string/title_activity_maps" />
- <activity
- android:name=".NavActivity"
- android:label="@string/app_name"
- android:theme="@style/AppTheme"
- android:screenOrientation="portrait"></activity>
- </application>
- package com.example.ninjaroot.myapplication;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.graphics.Color;
- import android.os.AsyncTask;
- import android.preference.PreferenceManager;
- import android.support.design.widget.Snackbar;
- import android.support.design.widget.TextInputEditText;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.support.v7.widget.Toolbar;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.animation.AlphaAnimation;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.StringReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.net.URLEncoder;
- public class MainActivity extends AppCompatActivity {
- Button btnClickMe;
- String fa;
- EditText UsernameEt, PasswordEt;
- boolean disableBackButton = false,log=false;
- Context ctx=this;
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu, menu);
- disableBackButton = false;
- return true;
- }
- public void displayMsg(String msg)
- {
- AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
- builder1.setMessage(msg);
- builder1.setCancelable(true);
- builder1.setPositiveButton(
- "Ok",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert11 = builder1.create();
- alert11.show();
- }
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.botaoAjuda) {
- displayMsg("Seja bem-vindo, estamos aqui para o ajudar. nnPara Iniciar Sessão digite o seu email " +
- "e a sua password nos campos indicados.");
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onBackPressed() {
- //super.onBackPressed();
- if(!disableBackButton){
- //THIS BLOCK WILL NOT DO ANYTHING AND WOULD DISABLE BACK BUTTON
- }else{
- super.onBackPressed();
- super.finish();
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(myToolbar);
- UsernameEt = (EditText) findViewById(R.id.Username);
- PasswordEt = (EditText) findViewById(R.id.Password);
- final ImageButton button = (ImageButton) findViewById(R.id.imageEntrar);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- final AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.8F);
- button.startAnimation(buttonClick);
- String username = UsernameEt.getText().toString();
- String password = PasswordEt.getText().toString();
- BackgroundWorker backgroundWorker = new BackgroundWorker(ctx);
- backgroundWorker.execute("login", username, password);
- }
- });
- final ImageButton button1 = (ImageButton) findViewById(R.id.imageReg);
- button1.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- final AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.8F);
- button1.startAnimation(buttonClick);
- startActivity(new Intent(MainActivity.this, Registar.class)); //change Activity
- }
- });
- }
- private class BackgroundWorker extends AsyncTask<String,Void,String> {
- Context context;
- android.app.AlertDialog alertDialog;
- boolean isLog =false;
- BackgroundWorker (Context ctx) {
- context = ctx;
- }
- @Override
- protected String doInBackground(String... params) {
- String type = params[0];
- String login_url = "http://ninjaroot.x10.mx/login.php";
- if(type.equals("login")) {
- try {
- String user_name = params[1];
- String password = params[2];
- URL url = new URL(login_url);
- HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- OutputStream outputStream = httpURLConnection.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- String post_data = URLEncoder.encode("Username","UTF-8")+"="+URLEncoder.encode(user_name,"UTF-8")+"&"
- +URLEncoder.encode("Password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- InputStream inputStream = httpURLConnection.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
- String result="";
- String line="";
- while((line = bufferedReader.readLine())!= null) {
- result += line;
- }
- bufferedReader.close();
- inputStream.close();
- httpURLConnection.disconnect();
- return result;
- } catch (IOException e) {
- displayMsg(""+e);
- }
- }
- return null;
- }
- @Override
- protected void onPreExecute() {
- alertDialog = new android.app.AlertDialog.Builder(context).create();
- alertDialog.setTitle("Login Status");
- }
- @Override
- protected void onPostExecute(String result) {
- String username = UsernameEt.getText().toString();
- String password = PasswordEt.getText().toString();
- // do whatever you want wit22h result
- if(result.equalsIgnoreCase("true")) {
- disableBackButton = true;
- startActivity(new Intent(MainActivity.this, NavActivity.class));
- Toast lol = Toast.makeText(this.context, "Resultado Login: LOL " + result, Toast.LENGTH_LONG);
- lol.show();
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
- prefs.edit().putString("username", username).apply();
- prefs.edit().putString("password", password).apply();
- prefs.edit().putBoolean("IsLogin", true).apply();
- }else if(result.equalsIgnoreCase("false"))
- {
- Toast lol = Toast.makeText(this.context, "Resultado Login: LOL " + result, Toast.LENGTH_LONG);
- lol.show();
- }
- finishActivity(BackgroundWorker.this.hashCode());
- }
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- }
- public boolean getLog() {
- return isLog;
- }
- }
- }
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center">
- <fragment
- android:id="@+id/map"
- android:name="com.google.android.gms.maps.SupportMapFragment"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- tools:context=".MapsActivity" />
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Button" />
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement