@Override public void onClick(View v) { if (v.getId() == R.id.single || v.getId() == R.id.multi) { isSingle = v.getId() == R.id.single; permissionHelper .setForceAccepting(false) // default is false. its here so you know that it exists. .request(isSingle ? SINGLE_PERMISSION : MULTI_PERMISSIONS); } else { permissionHelper.request( Manifest.permission.SYSTEM_ALERT_WINDOW); /*you can pass it along other permissions, just make sure you override OnActivityResult so you can get a callback. ignoring that will result to not be notified if the user enable/disable the permission*/ } }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.gmail_login_button: // mGoogleApiClient.connect(); // if (AppConstant.isNetworkAvailable(LoginActivity.this)) { if (AppConstant.isAndroid6()) { permissionHelper .setForceAccepting(false) // default is false. its here so you know that it exists. .request(SINGLE_PERMISSION); } else { signInGoogle(); } // } else { // Toast.makeText(LoginActivity.this, // "No Internet Connection Found.", Toast.LENGTH_LONG) // .show(); // } break; case R.id.btnFacebookLogin: LoginManager.getInstance() .logInWithReadPermissions( LoginActivity.this, Arrays.asList("public_profile", "user_friends", "email")); break; case R.id.btnLogin: logIn(1, v); break; case R.id.btnTryAgain: layoutCantConnect.setVisibility(View.GONE); if (AppConstant.isNetworkAvailable(LoginActivity.this)) { if (loginType == 1) { logIn(1, v); } else if (loginType == 2) { new LoginTask(loginId, loginName, loginEmail, loginImageUrl, 2).execute(); } else if (loginType == 3) { new LoginTask(loginId, loginName, loginEmail, loginImageUrl, 3).execute(); } } else { AppConstant.showNetworkError(LoginActivity.this); } break; case R.id.txtBottomSignup: Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); startActivity(intent); break; case R.id.txtfrgtPassword: showForgotPasswordDialog(v); break; default: break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample); result = (TextView) findViewById(R.id.result); findViewById(R.id.single).setOnClickListener(this); findViewById(R.id.multi).setOnClickListener(this); findViewById(R.id.overlay).setOnClickListener(this); permissionHelper = PermissionHelper.getInstance(this); }
@Override public void onPermissionNeedExplanation(String permissionName) { Log.i("NeedExplanation", "Permission( " + permissionName + " ) needs Explanation"); if (!isSingle) { neededPermission = PermissionHelper.declinedPermissions(this, MULTI_PERMISSIONS); StringBuilder builder = new StringBuilder(neededPermission.length); if (neededPermission.length > 0) { for (String permission : neededPermission) { builder.append(permission).append("\n"); } } result.setText("Permission( " + builder.toString() + " ) needs Explanation"); AlertDialog alert = getAlertDialog(neededPermission, builder.toString()); if (!alert.isShowing()) { alert.show(); } } else { result.setText("Permission( " + permissionName + " ) needs Explanation"); getAlertDialog(permissionName).show(); } }
@Override public void onRequestPermissionsResult( int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { permissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults); }
/** * Used to determine if the user accepted {@link android.Manifest.permission#SYSTEM_ALERT_WINDOW} * or no. * * <p>if you never passed the permission this method won't be called. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { permissionHelper.onActivityForResult(requestCode); }
// Twitter // private static Twitter twitter; // private static RequestToken requestToken; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); LogInActivityDialog = new ProgressDialog(LoginActivity.this); LogInActivityDialog.setCancelable(false); layoutCantConnect = (LinearLayout) findViewById(R.id.layoutCantConnect); LogInActivityDialog.setMessage("Please wait..."); etEmail = (EditText) findViewById(R.id.etEmail); etPassword = (EditText) findViewById(R.id.etPassword); btnLogin = (Button) findViewById(R.id.btnLogin); btnLogin.setOnClickListener(this); btnTryAgain = (TypedfacedButton) findViewById(R.id.btnTryAgain); if (AppConstant.isAndroid6()) { permissionHelper = PermissionHelper.getInstance(this); } btnTryAgain.setOnClickListener(this); // btnSignIn = (SignInButton) findViewById(R.id.gmail_login_button); btnSignIn = (Button) findViewById(R.id.gmail_login_button); txtBottomSignup = (TextView) findViewById(R.id.txtBottomSignup); txtfrgtPassword = (TextView) findViewById(R.id.txtfrgtPassword); txtBottomSignup.setOnClickListener(this); txtfrgtPassword.setOnClickListener(this); // Button click listeners btnSignIn.setOnClickListener(this); if (AppConstant.isAndroid5()) { btnLogin.setBackground(getDrawable(R.drawable.ripple_accent_round_corner)); } etPassword.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { try { if (actionId == EditorInfo.IME_ACTION_DONE) { try { logIn(1, v); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } return false; } }); Button btnFacebookLogin = (Button) findViewById(R.id.btnFacebookLogin); btnFacebookLogin.setOnClickListener(this); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance() .registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { loginId = Profile.getCurrentProfile().getId(); loginName = Profile.getCurrentProfile().getName(); loginEmail = object.optString("email"); loginImageUrl = Profile.getCurrentProfile() .getProfilePictureUri(200, 200) .toString(); if (AppConstant.isNetworkAvailable(LoginActivity.this)) { loginType = 2; new LoginTask(loginId, loginName, loginEmail, loginImageUrl, 2) .execute(); } else { AppConstant.showNetworkError(LoginActivity.this); } /* Intent intent = new Intent(LoginActivity.this, MainActivity.class); intent.putExtra("name", Profile.getCurrentProfile().getName()); intent.putExtra("image", Profile.getCurrentProfile().getId()); startActivity(intent); overridePendingTransition(R.anim.start_activity, R.anim.close_activity); finish();*/ // Log.v("Email", "Resp : " + email); Log.d( "Facebook", Profile.getCurrentProfile().getName() + "\n" + Profile.getCurrentProfile().getId() + "\n" + Profile.getCurrentProfile().getProfilePictureUri(200, 200)); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email,gender, birthday"); request.setParameters(parameters); request.executeAsync(); } @Override public void onCancel() {} @Override public void onError(FacebookException e) {} }); // Initializing google plus api client mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); }