| 21480 |
rajender |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.Fragment;
|
|
|
4 |
import android.app.ProgressDialog;
|
|
|
5 |
import android.content.Context;
|
|
|
6 |
import android.content.Intent;
|
|
|
7 |
import android.content.SharedPreferences;
|
|
|
8 |
import android.graphics.Bitmap;
|
|
|
9 |
import android.graphics.BitmapShader;
|
|
|
10 |
import android.graphics.Canvas;
|
|
|
11 |
import android.graphics.Paint;
|
|
|
12 |
import android.net.ConnectivityManager;
|
|
|
13 |
import android.os.Bundle;
|
|
|
14 |
import android.util.Log;
|
|
|
15 |
import android.view.KeyEvent;
|
|
|
16 |
import android.view.LayoutInflater;
|
|
|
17 |
import android.view.View;
|
|
|
18 |
import android.view.ViewGroup;
|
|
|
19 |
|
|
|
20 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
21 |
import com.google.android.gms.analytics.Tracker;
|
|
|
22 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
23 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
24 |
import com.saholic.profittill.R;
|
|
|
25 |
import com.squareup.picasso.Transformation;
|
|
|
26 |
import com.testin.agent.TestinAgent;
|
|
|
27 |
|
|
|
28 |
import org.json.JSONException;
|
|
|
29 |
import org.json.JSONObject;
|
|
|
30 |
|
|
|
31 |
public class MyProfile extends Fragment {
|
|
|
32 |
SharedPreferences userData;
|
|
|
33 |
SharedPreferences apiData;
|
|
|
34 |
SharedPreferences.Editor userDataEditor;
|
|
|
35 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
36 |
public MyProfile() {
|
|
|
37 |
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
@Override
|
|
|
42 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
43 |
Bundle savedInstanceState) {
|
|
|
44 |
View rootView = inflater.inflate(R.layout.fragment_my_profile, container, false);
|
|
|
45 |
TestinAgent.init(getActivity());
|
|
|
46 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
47 |
|
|
|
48 |
Tracker t = ((GoogleAnalyticsTracker) getActivity().getApplicationContext()).getTracker(
|
|
|
49 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
50 |
t.setScreenName("Profile Screen");
|
|
|
51 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
52 |
|
|
|
53 |
userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
54 |
apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
|
|
55 |
userDataEditor = userData.edit();
|
|
|
56 |
apiSettingsEditor = apiData.edit();
|
|
|
57 |
TestinAgent.setUserInfo(userData.getString("id", ""));
|
|
|
58 |
JSONObject props = new JSONObject();
|
|
|
59 |
try {
|
|
|
60 |
mixpanel.identify(userData.getString("id",null));
|
|
|
61 |
props.put("Screen", "My Profile");
|
|
|
62 |
mixpanel.track("My Profile", props);
|
|
|
63 |
} catch (JSONException e) {
|
|
|
64 |
e.printStackTrace();
|
|
|
65 |
}
|
|
|
66 |
/* if(isInternetOn()){
|
|
|
67 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
68 |
AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Screen", "My Profile", "My Profile Screen"),
|
|
|
69 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
70 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
|
|
|
71 |
pd = new ProgressDialog(getActivity());
|
|
|
72 |
pd.setTitle("Please wait");
|
|
|
73 |
pd.setMessage("Fetching Profile Information..");
|
|
|
74 |
pd.show();
|
|
|
75 |
|
|
|
76 |
}
|
|
|
77 |
else{
|
|
|
78 |
SearchFragment nextFrag= new SearchFragment();
|
|
|
79 |
Bundle args = new Bundle();
|
|
|
80 |
args.putString("finishingurl","");
|
|
|
81 |
args.putString("fragmentNumber","10");
|
|
|
82 |
nextFrag.setArguments(args);
|
|
|
83 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
84 |
.replace(R.id.frame_container, nextFrag)
|
|
|
85 |
.addToBackStack(null)
|
|
|
86 |
.commit();
|
|
|
87 |
}*/
|
|
|
88 |
rootView.setOnKeyListener(new View.OnKeyListener() {
|
|
|
89 |
@Override
|
|
|
90 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
91 |
Log.d("In my profile" , "In my profile " );
|
|
|
92 |
if(event.getAction() == KeyEvent.ACTION_DOWN){
|
|
|
93 |
switch(keyCode) {
|
|
|
94 |
case KeyEvent.KEYCODE_BACK:
|
|
|
95 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
96 |
i.putExtra("displayView", "0");
|
|
|
97 |
startActivity(i);
|
|
|
98 |
return true;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
return false;
|
|
|
102 |
}
|
|
|
103 |
});
|
|
|
104 |
return rootView;
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
@Override
|
|
|
109 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
110 |
super.onViewCreated(view, savedInstanceState);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
public class CircleTransform implements Transformation {
|
|
|
114 |
@Override
|
|
|
115 |
public Bitmap transform(Bitmap source) {
|
|
|
116 |
int size = Math.min(source.getWidth(), source.getHeight());
|
|
|
117 |
|
|
|
118 |
int x = (source.getWidth() - size) / 2;
|
|
|
119 |
int y = (source.getHeight() - size) / 2;
|
|
|
120 |
|
|
|
121 |
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
|
|
|
122 |
if (squaredBitmap != source) {
|
|
|
123 |
source.recycle();
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
|
|
|
127 |
|
|
|
128 |
Canvas canvas = new Canvas(bitmap);
|
|
|
129 |
Paint paint = new Paint();
|
|
|
130 |
BitmapShader shader = new BitmapShader(squaredBitmap,
|
|
|
131 |
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
|
|
|
132 |
paint.setShader(shader);
|
|
|
133 |
paint.setAntiAlias(true);
|
|
|
134 |
|
|
|
135 |
float r = size / 2f;
|
|
|
136 |
canvas.drawCircle(r, r, r, paint);
|
|
|
137 |
|
|
|
138 |
squaredBitmap.recycle();
|
|
|
139 |
return bitmap;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
@Override
|
|
|
143 |
public String key() {
|
|
|
144 |
return "circle";
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
ProgressDialog pd = null;
|
|
|
149 |
|
|
|
150 |
public final boolean isInternetOn() {
|
|
|
151 |
|
|
|
152 |
ConnectivityManager connec =
|
|
|
153 |
(ConnectivityManager)getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
154 |
|
|
|
155 |
if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
156 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
157 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
158 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
159 |
|
|
|
160 |
return true;
|
|
|
161 |
|
|
|
162 |
} else if (
|
|
|
163 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
164 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
165 |
return false;
|
|
|
166 |
}
|
|
|
167 |
return false;
|
|
|
168 |
}
|
|
|
169 |
@Override
|
|
|
170 |
public void onResume() {
|
|
|
171 |
super.onResume();
|
|
|
172 |
getView().setFocusableInTouchMode(true);
|
|
|
173 |
getView().requestFocus();
|
|
|
174 |
getView().setOnKeyListener(new View.OnKeyListener() {
|
|
|
175 |
@Override
|
|
|
176 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
177 |
|
|
|
178 |
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
|
|
|
179 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
180 |
i.putExtra("displayView", "0");
|
|
|
181 |
startActivity(i);
|
|
|
182 |
return true;
|
|
|
183 |
}
|
|
|
184 |
return false;
|
|
|
185 |
}
|
|
|
186 |
});
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
public void dealsPageOnBack(){
|
|
|
190 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
191 |
i.putExtra("displayView", "0");
|
|
|
192 |
startActivity(i);
|
|
|
193 |
}
|
|
|
194 |
}
|