Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.example.ninjaroot.myapplication">
  4. <uses-permission android:name="android.permission.INTERNET" />
  5. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  6. <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
  7. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  8. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  9.  
  10. <!--
  11. The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
  12. Google Maps Android API v2, but you must specify either coarse or fine
  13. location permissions for the 'MyLocation' functionality.
  14. -->
  15. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  16.  
  17. <application
  18. android:allowBackup="true"
  19. android:icon="@mipmap/ic_launcher"
  20. android:label="@string/app_name"
  21. android:supportsRtl="true"
  22. android:theme="@style/AppTheme">
  23. <activity
  24. android:name=".SplashActivity"
  25. android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar">
  26. <intent-filter>
  27. <action android:name="android.intent.action.MAIN" />
  28.  
  29. <category android:name="android.intent.category.LAUNCHER" />
  30. </intent-filter>
  31. </activity>
  32. <activity
  33. android:name=".Registar"
  34. android:label="@string/Registar"
  35. android:screenOrientation="portrait"/>
  36. <activity android:name=".MainActivity"
  37. android:screenOrientation="portrait" />
  38.  
  39. <!--
  40. The API key for Google Maps-based APIs is defined as a string resource.
  41. (See the file "res/values/google_maps_api.xml").
  42. Note that the API key is linked to the encryption key used to sign the APK.
  43. You need a different API key for each encryption key, including the release key that is used to
  44. sign the APK for publishing.
  45. You can define the keys for the debug and release targets in src/debug/ and src/release/.
  46. -->
  47. <meta-data
  48. android:name="com.google.android.geo.API_KEY"
  49. android:value="@string/google_maps_key" />
  50.  
  51. <activity
  52. android:name=".MapsActivity"
  53. android:label="@string/title_activity_maps" />
  54. <activity
  55. android:name=".NavActivity"
  56. android:label="@string/app_name"
  57. android:theme="@style/AppTheme"
  58. android:screenOrientation="portrait"></activity>
  59. </application>
  60.  
  61. package com.example.ninjaroot.myapplication;
  62.  
  63.  
  64. import android.content.Context;
  65. import android.content.DialogInterface;
  66. import android.content.Intent;
  67. import android.content.SharedPreferences;
  68. import android.graphics.Color;
  69. import android.os.AsyncTask;
  70. import android.preference.PreferenceManager;
  71. import android.support.design.widget.Snackbar;
  72. import android.support.design.widget.TextInputEditText;
  73. import android.support.v7.app.AlertDialog;
  74. import android.support.v7.app.AppCompatActivity;
  75. import android.os.Bundle;
  76. import android.support.v7.widget.Toolbar;
  77. import android.view.Menu;
  78. import android.view.MenuItem;
  79. import android.view.View;
  80. import android.view.animation.AlphaAnimation;
  81. import android.widget.Button;
  82. import android.widget.EditText;
  83. import android.widget.ImageButton;
  84. import android.widget.TextView;
  85. import android.widget.Toast;
  86.  
  87. import java.io.BufferedReader;
  88. import java.io.BufferedWriter;
  89. import java.io.IOException;
  90. import java.io.InputStream;
  91. import java.io.InputStreamReader;
  92. import java.io.OutputStream;
  93. import java.io.OutputStreamWriter;
  94. import java.io.StringReader;
  95. import java.net.HttpURLConnection;
  96. import java.net.URL;
  97. import java.net.URLEncoder;
  98.  
  99.  
  100. public class MainActivity extends AppCompatActivity {
  101. Button btnClickMe;
  102. String fa;
  103. EditText UsernameEt, PasswordEt;
  104. boolean disableBackButton = false,log=false;
  105. Context ctx=this;
  106.  
  107. @Override
  108. public boolean onCreateOptionsMenu(Menu menu) {
  109. getMenuInflater().inflate(R.menu.menu, menu);
  110. disableBackButton = false;
  111. return true;
  112. }
  113. public void displayMsg(String msg)
  114. {
  115. AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
  116. builder1.setMessage(msg);
  117. builder1.setCancelable(true);
  118.  
  119. builder1.setPositiveButton(
  120. "Ok",
  121. new DialogInterface.OnClickListener() {
  122. public void onClick(DialogInterface dialog, int id) {
  123. dialog.cancel();
  124. }
  125. });
  126.  
  127.  
  128.  
  129. AlertDialog alert11 = builder1.create();
  130. alert11.show();
  131. }
  132. public boolean onOptionsItemSelected(MenuItem item) {
  133. // Handle action bar item clicks here. The action bar will
  134. // automatically handle clicks on the Home/Up button, so long
  135. // as you specify a parent activity in AndroidManifest.xml.
  136. int id = item.getItemId();
  137.  
  138. //noinspection SimplifiableIfStatement
  139. if (id == R.id.botaoAjuda) {
  140. displayMsg("Seja bem-vindo, estamos aqui para o ajudar. nnPara Iniciar Sessão digite o seu email " +
  141. "e a sua password nos campos indicados.");
  142. return true;
  143. }
  144.  
  145. return super.onOptionsItemSelected(item);
  146. }
  147. @Override
  148. public void onBackPressed() {
  149. //super.onBackPressed();
  150.  
  151. if(!disableBackButton){
  152. //THIS BLOCK WILL NOT DO ANYTHING AND WOULD DISABLE BACK BUTTON
  153.  
  154. }else{
  155. super.onBackPressed();
  156. super.finish();
  157.  
  158. }
  159.  
  160. }
  161.  
  162. @Override
  163. protected void onCreate(Bundle savedInstanceState) {
  164. super.onCreate(savedInstanceState);
  165. setContentView(R.layout.activity_main);
  166. final Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
  167. setSupportActionBar(myToolbar);
  168.  
  169. UsernameEt = (EditText) findViewById(R.id.Username);
  170. PasswordEt = (EditText) findViewById(R.id.Password);
  171.  
  172.  
  173.  
  174. final ImageButton button = (ImageButton) findViewById(R.id.imageEntrar);
  175. button.setOnClickListener(new View.OnClickListener() {
  176. public void onClick(View v) {
  177.  
  178. final AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.8F);
  179. button.startAnimation(buttonClick);
  180.  
  181. String username = UsernameEt.getText().toString();
  182. String password = PasswordEt.getText().toString();
  183.  
  184. BackgroundWorker backgroundWorker = new BackgroundWorker(ctx);
  185. backgroundWorker.execute("login", username, password);
  186.  
  187.  
  188.  
  189.  
  190.  
  191. }
  192. });
  193.  
  194.  
  195. final ImageButton button1 = (ImageButton) findViewById(R.id.imageReg);
  196. button1.setOnClickListener(new View.OnClickListener() {
  197. public void onClick(View v) {
  198.  
  199. final AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.8F);
  200. button1.startAnimation(buttonClick);
  201. startActivity(new Intent(MainActivity.this, Registar.class)); //change Activity
  202.  
  203. }
  204. });
  205. }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212. private class BackgroundWorker extends AsyncTask<String,Void,String> {
  213. Context context;
  214. android.app.AlertDialog alertDialog;
  215. boolean isLog =false;
  216.  
  217.  
  218. BackgroundWorker (Context ctx) {
  219. context = ctx;
  220. }
  221.  
  222.  
  223.  
  224. @Override
  225. protected String doInBackground(String... params) {
  226. String type = params[0];
  227.  
  228.  
  229. String login_url = "http://ninjaroot.x10.mx/login.php";
  230. if(type.equals("login")) {
  231. try {
  232.  
  233. String user_name = params[1];
  234. String password = params[2];
  235. URL url = new URL(login_url);
  236. HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
  237. httpURLConnection.setRequestMethod("POST");
  238. httpURLConnection.setDoOutput(true);
  239. httpURLConnection.setDoInput(true);
  240.  
  241. OutputStream outputStream = httpURLConnection.getOutputStream();
  242. BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
  243. String post_data = URLEncoder.encode("Username","UTF-8")+"="+URLEncoder.encode(user_name,"UTF-8")+"&"
  244. +URLEncoder.encode("Password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
  245.  
  246. bufferedWriter.write(post_data);
  247. bufferedWriter.flush();
  248. bufferedWriter.close();
  249. outputStream.close();
  250. InputStream inputStream = httpURLConnection.getInputStream();
  251. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
  252. String result="";
  253. String line="";
  254. while((line = bufferedReader.readLine())!= null) {
  255. result += line;
  256. }
  257. bufferedReader.close();
  258. inputStream.close();
  259. httpURLConnection.disconnect();
  260. return result;
  261.  
  262.  
  263. } catch (IOException e) {
  264. displayMsg(""+e);
  265. }
  266. }
  267. return null;
  268. }
  269.  
  270. @Override
  271. protected void onPreExecute() {
  272.  
  273. alertDialog = new android.app.AlertDialog.Builder(context).create();
  274. alertDialog.setTitle("Login Status");
  275.  
  276. }
  277.  
  278.  
  279. @Override
  280. protected void onPostExecute(String result) {
  281. String username = UsernameEt.getText().toString();
  282. String password = PasswordEt.getText().toString();
  283. // do whatever you want wit22h result
  284. if(result.equalsIgnoreCase("true")) {
  285. disableBackButton = true;
  286. startActivity(new Intent(MainActivity.this, NavActivity.class));
  287. Toast lol = Toast.makeText(this.context, "Resultado Login: LOL " + result, Toast.LENGTH_LONG);
  288. lol.show();
  289.  
  290. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
  291. prefs.edit().putString("username", username).apply();
  292. prefs.edit().putString("password", password).apply();
  293. prefs.edit().putBoolean("IsLogin", true).apply();
  294.  
  295.  
  296. }else if(result.equalsIgnoreCase("false"))
  297. {
  298.  
  299. Toast lol = Toast.makeText(this.context, "Resultado Login: LOL " + result, Toast.LENGTH_LONG);
  300.  
  301. lol.show();
  302. }
  303. finishActivity(BackgroundWorker.this.hashCode());
  304.  
  305. }
  306.  
  307.  
  308.  
  309. @Override
  310. protected void onProgressUpdate(Void... values) {
  311. super.onProgressUpdate(values);
  312.  
  313. }
  314. public boolean getLog() {
  315. return isLog;
  316. }
  317.  
  318. }
  319.  
  320.  
  321.  
  322. }
  323.  
  324. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  325. xmlns:tools="http://schemas.android.com/tools"
  326. android:layout_width="match_parent"
  327. android:layout_height="match_parent"
  328. android:orientation="vertical"
  329. android:gravity="center">
  330.  
  331. <fragment
  332. android:id="@+id/map"
  333. android:name="com.google.android.gms.maps.SupportMapFragment"
  334. android:layout_width="match_parent"
  335. android:layout_height="0dp"
  336. android:layout_weight="1"
  337. tools:context=".MapsActivity" />
  338.  
  339. <Button
  340. android:id="@+id/button"
  341. android:layout_width="wrap_content"
  342. android:layout_height="wrap_content"
  343. android:text="Button" />
  344.  
  345. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement