Advertisement
Mappil

Untitled

May 8th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.85 KB | None | 0 0
  1. public class ProfiloFragment extends Fragment {
  2. View rootView;
  3.  
  4. private static final int RC_SIGN_IN = 9001;
  5.  
  6.  
  7.  
  8. String str_email;
  9. String str_foto;
  10.  
  11. String str_id ;
  12. String str_firstname;
  13. String str_lastname;
  14. String str_photo;
  15. String locale;
  16. String tipoLogin;
  17. String str_pass;
  18. List<NameValuePair> params = new ArrayList<NameValuePair>();
  19.  
  20. private GoogleApiClient mGoogleApiClient;
  21. private static final String TAG = "SignInActivity";
  22. TwitterLoginButton loginTW;
  23. TwitterSession session;
  24.  
  25.  
  26. int a;
  27. String password;
  28.  
  29. JSONParser jsonParser = new JSONParser();
  30.  
  31. private ProgressDialog dialog;
  32.  
  33. private static String register_user = "https://www.crazylex.com/v105/login.php";
  34.  
  35. // Creating Facebook CallbackManager Value
  36. public static CallbackManager callbackmanager;
  37.  
  38. @Nullable
  39. @Override
  40. public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  41. FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
  42.  
  43. TwitterAuthConfig authConfig = new TwitterAuthConfig("fKqzTc5H8P3E7aswE2NNCommv", "iifLdpVOghIqk9TSv8lTCR639bh6CM4yZYNuvNYhR3kpSm8lww");
  44. Fabric.with(getActivity(), new TwitterCore(authConfig));
  45.  
  46.  
  47.  
  48. rootView = inflater.inflate(R.layout.profilo_fragment, container, false);
  49.  
  50.  
  51.  
  52.  
  53. getActivity().setTitle(getResources().getString(R.string.PROFILE));
  54. setHasOptionsMenu(true);
  55.  
  56.  
  57. Button loginBt = (Button) rootView.findViewById(R.id.loginButton);
  58. ImageButton loginFbBt = (ImageButton) rootView.findViewById(R.id.facebookLogin);
  59. Button registrazioneBt = (Button) rootView.findViewById(R.id.registrazioneBtn);
  60. Button recuperaPass = (Button) rootView.findViewById(R.id.recuperaPass);
  61.  
  62. ImageButton loginGoogle = (ImageButton) rootView.findViewById(R.id.loginGoogle);
  63.  
  64.  
  65. locale = getActivity().getBaseContext().getResources().getConfiguration().locale.getCountry();
  66. Locale obj = new Locale("", locale);
  67. locale = obj.getDisplayCountry();
  68.  
  69. Button terminiecondizioni = (Button) rootView.findViewById(R.id.terminiecondizioniProfilo);
  70. terminiecondizioni.setOnClickListener(new View.OnClickListener() {
  71. @Override
  72. public void onClick(View view) {
  73. Intent myIntent = new Intent(getActivity().getBaseContext(), InfoActivity.class);
  74. startActivity(myIntent);
  75. }
  76. });
  77.  
  78.  
  79.  
  80. loginGoogle.setOnClickListener(new View.OnClickListener() {
  81. @Override
  82. public void onClick(View view) {
  83. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
  84. .requestEmail()
  85. .requestProfile()
  86. .build();
  87.  
  88.  
  89. mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
  90. .enableAutoManage(getActivity(), null)
  91. .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
  92. .build();
  93.  
  94. signIn();
  95. }
  96. });
  97.  
  98. loginBt.setOnClickListener(new View.OnClickListener() {
  99. @Override
  100. public void onClick(View view) {
  101.  
  102.  
  103. tipoLogin = "login";
  104.  
  105.  
  106. LinearLayout layout = new LinearLayout(getContext());
  107. layout.setOrientation(LinearLayout.VERTICAL);
  108.  
  109. final EditText inputE = new EditText(getActivity());
  110. final EditText inputP = new EditText(getActivity());
  111. inputE.setHint("Email");
  112. inputP.setHint("Password");
  113.  
  114. layout.addView(inputE);
  115. layout.addView(inputP);
  116.  
  117.  
  118.  
  119. AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
  120. alertDialog.setTitle("Login");
  121. alertDialog.setMessage(getResources().getString(R.string.ENTER_LOGIN));
  122. alertDialog.setView(layout, 10, 0, 10, 0); // 10 spacing, left and right
  123. alertDialog.setButton("Login", new DialogInterface.OnClickListener() {
  124. @Override
  125. public void onClick(DialogInterface dialog, int which) {
  126. // Clicked
  127. str_email = inputE.getText().toString();
  128. str_pass = inputP.getText().toString();
  129.  
  130. Networking n = new Networking();
  131. n.execute("https://www.crazylex.com/v105/login.php", Networking.NETWORK_STATE_REGISTER);
  132.  
  133. }
  134. });
  135. alertDialog.show();
  136.  
  137.  
  138.  
  139. }
  140. });
  141.  
  142. registrazioneBt.setOnClickListener(new View.OnClickListener() {
  143. @Override
  144. public void onClick(View view) {
  145.  
  146. Intent i = new Intent(getActivity().getBaseContext(), Registrazione_Activity.class);
  147. startActivity(i);
  148.  
  149.  
  150.  
  151.  
  152. }
  153. });
  154. recuperaPass.setOnClickListener(new View.OnClickListener() {
  155. @Override
  156. public void onClick(View view) {
  157.  
  158.  
  159. tipoLogin = "recupera";
  160.  
  161. final EditText input = new EditText(getActivity());
  162. input.setHint("Email");
  163.  
  164. AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
  165. alertDialog.setTitle(getResources().getString(R.string.RECOVERPASSWORD_BUTTON));
  166. alertDialog.setMessage(getResources().getString(R.string.ENTER_EMAIL));
  167. alertDialog.setView(input, 10, 0, 10, 0); // 10 spacing, left and right
  168. alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  169. @Override
  170. public void onClick(DialogInterface dialog, int which) {
  171. // Clicked
  172. str_email = input.getText().toString();
  173.  
  174. Networking n = new Networking();
  175. n.execute("https://www.crazylex.com/v105/user_password.php", Networking.NETWORK_STATE_REGISTER);
  176.  
  177. }
  178. });
  179. alertDialog.show();
  180.  
  181.  
  182.  
  183. }
  184. });
  185.  
  186.  
  187.  
  188.  
  189. loginFbBt.setOnClickListener(new View.OnClickListener() {
  190.  
  191. public void onClick(View v) {
  192. // TODO Auto-generated method stub
  193. tipoLogin = "fb";
  194.  
  195.  
  196. onFblogin();
  197.  
  198. }
  199. });
  200.  
  201.  
  202.  
  203. loginTW = (TwitterLoginButton) rootView.findViewById(R.id.twitter_login_button);
  204.  
  205.  
  206. loginTW.setCallback(new LoginHandler());
  207.  
  208.  
  209.  
  210.  
  211.  
  212. return rootView;
  213. }
  214.  
  215.  
  216. @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
  217. super.onActivityResult(requestCode, resultCode, data);
  218.  
  219.  
  220. Log.e("request",""+requestCode);
  221. // Result returned from launching the Intent from
  222. // GoogleSignInApi.getSignInIntent(...);
  223. if (requestCode == RC_SIGN_IN) {
  224. GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
  225. if (result.isSuccess()) {
  226. GoogleSignInAccount acct = result.getSignInAccount();
  227. // Get account information
  228. String mFullName = acct.getDisplayName();
  229. String[] items = mFullName.split(" ");
  230.  
  231.  
  232. str_firstname =items[0];
  233. str_lastname = items[1];
  234. str_photo = acct.getPhotoUrl().toString();
  235. str_email = acct.getEmail();
  236. Log.e("risultato", str_firstname+str_email + str_lastname + str_photo);
  237. tipoLogin = "Google";
  238. Networking n = new Networking();
  239. n.execute("https://www.crazylex.com/v105/loginGP.php", Networking.NETWORK_STATE_REGISTER);
  240.  
  241.  
  242. }
  243. }else{
  244. callbackmanager.onActivityResult(requestCode, resultCode, data);
  245. loginTW.onActivityResult(requestCode, resultCode, data);
  246.  
  247.  
  248. }
  249.  
  250.  
  251.  
  252.  
  253. }
  254. void getUserData() {
  255. Twitter.getApiClient(session).getAccountService()
  256. .verifyCredentials(true, false, new Callback<User>() {
  257.  
  258. @Override
  259. public void failure(TwitterException e) {
  260.  
  261. }
  262.  
  263. @Override
  264. public void success(Result<User> userResult) {
  265.  
  266. User user = userResult.data;
  267. String twitterImage = user.profileImageUrl;
  268.  
  269. try {
  270. Log.e("imageurl", user.profileImageUrl);
  271. Log.e("name", user.name);
  272. //Log.d("email",user.email);
  273. Log.e("des", user.description);
  274. Log.e("followers ", String.valueOf(user.followersCount));
  275. Log.e("createdAt", user.createdAt);
  276. } catch (Exception e) {
  277. e.printStackTrace();
  278. }
  279.  
  280.  
  281. }
  282.  
  283. });
  284. }
  285. private class LoginHandler extends Callback<TwitterSession> {
  286. @Override
  287. public void success(Result<TwitterSession> twitterSessionResult) {
  288. String output = "Status: " +
  289. "Your login was successful " +
  290. twitterSessionResult.data.getUserName() +
  291. "\nAuth Token Received: " +
  292. twitterSessionResult.data.getAuthToken().token;
  293.  
  294. Log.e("loginTWOK",output);
  295. }
  296.  
  297. @Override
  298. public void failure(TwitterException e) {
  299. Log.e("loginTWFAIL","FAIL");
  300.  
  301. }
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement