| 21189 |
rajender |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.AlertDialog;
|
|
|
4 |
import android.app.ProgressDialog;
|
|
|
5 |
import android.content.Context;
|
|
|
6 |
import android.content.DialogInterface;
|
|
|
7 |
import android.content.Intent;
|
|
|
8 |
import android.content.SharedPreferences;
|
|
|
9 |
import android.graphics.Paint;
|
|
|
10 |
import android.graphics.drawable.ColorDrawable;
|
|
|
11 |
import android.os.AsyncTask;
|
|
|
12 |
import android.support.v7.app.ActionBar;
|
|
|
13 |
import android.support.v7.app.ActionBarActivity;
|
|
|
14 |
import android.os.Bundle;
|
|
|
15 |
import android.telephony.TelephonyManager;
|
|
|
16 |
import android.util.Log;
|
|
|
17 |
import android.view.View;
|
|
|
18 |
import android.widget.Button;
|
|
|
19 |
import android.widget.TextView;
|
|
|
20 |
|
|
|
21 |
import com.facebook.Session;
|
|
|
22 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
23 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
24 |
import com.google.android.gms.plus.Plus;
|
|
|
25 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
26 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
27 |
import com.saholic.profittill.R;
|
|
|
28 |
|
|
|
29 |
import org.apache.http.HttpEntity;
|
|
|
30 |
import org.apache.http.HttpResponse;
|
|
|
31 |
import org.apache.http.client.ClientProtocolException;
|
|
|
32 |
import org.apache.http.client.HttpClient;
|
|
|
33 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
34 |
import org.apache.http.client.methods.HttpGet;
|
|
|
35 |
import org.apache.http.client.methods.HttpPost;
|
|
|
36 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
37 |
import org.apache.http.util.EntityUtils;
|
|
|
38 |
import org.json.JSONArray;
|
|
|
39 |
import org.json.JSONException;
|
|
|
40 |
import org.json.JSONObject;
|
|
|
41 |
|
|
|
42 |
import java.io.IOException;
|
|
|
43 |
|
|
|
44 |
public class PendingActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
|
|
45 |
SharedPreferences userData;
|
|
|
46 |
SharedPreferences apiData;
|
|
|
47 |
SharedPreferences.Editor userDataEditor;
|
|
|
48 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
49 |
TextView contactUsNumber;
|
|
|
50 |
Button updateProfile;
|
|
|
51 |
String type1;
|
|
|
52 |
MixpanelAPI mixpanel;
|
|
|
53 |
public GoogleApiClient mGoogleApiClient;
|
|
|
54 |
boolean glogout;
|
|
|
55 |
|
|
|
56 |
@Override
|
|
|
57 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
58 |
super.onCreate(savedInstanceState);
|
|
|
59 |
setContentView(R.layout.activity_pending);
|
|
|
60 |
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.White)));
|
|
|
61 |
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
62 |
getSupportActionBar().setCustomView(R.layout.profitmandiicon);
|
|
|
63 |
mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
64 |
userData = getApplicationContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
65 |
apiData = getApplicationContext().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
|
|
66 |
userDataEditor = userData.edit();
|
|
|
67 |
apiSettingsEditor = apiData.edit();
|
|
|
68 |
type1 = userData.getString("type", null);
|
|
|
69 |
|
|
|
70 |
if (type1 != null && type1.equalsIgnoreCase("google")) {
|
|
|
71 |
mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
|
72 |
.addConnectionCallbacks(this)
|
|
|
73 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
74 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
75 |
mGoogleApiClient.connect();
|
|
|
76 |
}
|
|
|
77 |
contactUsNumber = (TextView) findViewById(R.id.contactUsNumber);
|
|
|
78 |
updateProfile = (Button) findViewById(R.id.updateProfile);
|
|
|
79 |
contactUsNumber.setText("Call Us at " + apiData.getString("contactus.number", "") + " >");
|
|
|
80 |
contactUsNumber.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
|
|
|
81 |
|
|
|
82 |
updateProfile.setOnClickListener(new View.OnClickListener() {
|
|
|
83 |
@Override
|
|
|
84 |
public void onClick(View v) {
|
|
|
85 |
|
|
|
86 |
Intent intent = new Intent(PendingActivity.this, BasicInformation.class);
|
|
|
87 |
|
|
|
88 |
startActivity(intent);
|
|
|
89 |
}
|
|
|
90 |
});
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
@Override
|
|
|
96 |
public void onBackPressed() {
|
|
|
97 |
new AlertDialog.Builder(this)
|
|
|
98 |
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
99 |
.setTitle("Exit!")
|
|
|
100 |
.setMessage("Are you sure you want to sign out?")
|
|
|
101 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
102 |
@Override
|
|
|
103 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
104 |
|
|
|
105 |
if (type1.equalsIgnoreCase("facebook")) {
|
|
|
106 |
Log.d("fblogout", "logout");
|
|
|
107 |
if (Session.getActiveSession() != null) {
|
|
|
108 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
109 |
}
|
|
|
110 |
Session.setActiveSession(null);
|
|
|
111 |
userDataEditor.clear().commit();
|
|
|
112 |
startActivity(new Intent(PendingActivity.this, LoginActivity.class));
|
|
|
113 |
} else {
|
|
|
114 |
Log.d("gmailLogout", "logout");
|
|
|
115 |
signOutFromGplus();
|
|
|
116 |
if (glogout == true) {
|
|
|
117 |
startActivity(new Intent(PendingActivity.this, LoginActivity.class));
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
})
|
|
|
124 |
.setNegativeButton("No", null)
|
|
|
125 |
.show();
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public void signOutFromGplus() {
|
|
|
129 |
if (mGoogleApiClient.isConnected()) {
|
|
|
130 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
131 |
mGoogleApiClient.disconnect();
|
|
|
132 |
mGoogleApiClient.connect();
|
|
|
133 |
glogout = true;
|
|
|
134 |
userDataEditor.clear();
|
|
|
135 |
userDataEditor.commit();
|
|
|
136 |
} else {
|
|
|
137 |
glogout = false;
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
@Override
|
|
|
142 |
public void onConnected(Bundle bundle) {
|
|
|
143 |
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
@Override
|
|
|
147 |
public void onConnectionSuspended(int i) {
|
|
|
148 |
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
@Override
|
|
|
152 |
public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
}
|