Advertisement
Guest User

class

a guest
May 19th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.07 KB | None | 0 0
  1. package com.ck.awaza.awaza;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.v4.view.PagerAdapter;
  7. import android.support.v4.view.ViewPager;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.view.animation.Interpolator;
  12. import android.widget.EditText;
  13. import android.widget.ImageView;
  14. import android.widget.LinearLayout;
  15. import android.widget.Toast;
  16.  
  17. import com.android.volley.Request;
  18. import com.android.volley.RequestQueue;
  19. import com.android.volley.Response;
  20. import com.android.volley.VolleyError;
  21. import com.ck.awaza.awaza.others.Constant;
  22. import com.ck.awaza.awaza.utils.CustomJSONObjectRequest;
  23. import com.ck.awaza.awaza.utils.CustomVolleyRequestQueue;
  24. import com.daimajia.androidanimations.library.Techniques;
  25. import com.daimajia.androidanimations.library.YoYo;
  26. import com.nineoldandroids.animation.Animator;
  27.  
  28. import org.json.JSONException;
  29. import org.json.JSONObject;
  30.  
  31. import java.util.HashMap;
  32. import java.util.Map;
  33.  
  34.  
  35. /**
  36. * Created by Farhad on 5/7/2016.
  37. */
  38. public class Intro extends Activity {
  39.  
  40. MyPagerAdapter myPagerAdapter;
  41. int totalNumberOfPages = 3;
  42. ImageView image1, image2, image3;
  43. LinearLayout dotHolder, signup, signWithMail, login, intropage;
  44. EditText email, user, pass;
  45. private RequestQueue mQueue;
  46.  
  47. @Override
  48. protected void onCreate(Bundle savedInstanceState) {
  49. super.onCreate(savedInstanceState);
  50. setContentView(R.layout.intro);
  51. mQueue = CustomVolleyRequestQueue.getInstance(getApplicationContext()).getRequestQueue();
  52. ViewPager pager = (ViewPager) findViewById(R.id.pager);
  53. myPagerAdapter = new MyPagerAdapter();
  54. pager.setAdapter(myPagerAdapter);
  55. pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  56.  
  57. public void onPageScrollStateChanged(int arg0) {
  58. // circularProgress(arg0);
  59. }
  60.  
  61. public void onPageScrolled(int arg0, float arg1, int arg2) {
  62. }
  63.  
  64. public void onPageSelected(int position) {
  65.  
  66. // Toast.makeText(Intro.this, "Page " + position + " clicked", Toast.LENGTH_LONG).show();
  67. circularProgress(position);
  68. }
  69.  
  70. });
  71. inIt();
  72. }
  73.  
  74. // method to chnge the state of sliding progress circles
  75.  
  76. public void circularProgress(int position) {
  77. if (position == 0) {
  78. image1.setImageResource(R.drawable.b);
  79. image2.setImageResource(R.drawable.a);
  80. image3.setImageResource(R.drawable.a);
  81. } else if (position == 1) {
  82. image2.setImageResource(R.drawable.b);
  83. image1.setImageResource(R.drawable.a);
  84. image3.setImageResource(R.drawable.a);
  85. } else if (position == 2) {
  86. image3.setImageResource(R.drawable.b);
  87. image2.setImageResource(R.drawable.a);
  88. image1.setImageResource(R.drawable.a);
  89. }
  90. }
  91.  
  92.  
  93. public void inIt() {
  94. image1 = (ImageView) findViewById(R.id.image1);
  95. image2 = (ImageView) findViewById(R.id.image2);
  96. image3 = (ImageView) findViewById(R.id.image3);
  97.  
  98.  
  99. signup = (LinearLayout) findViewById(R.id.signup);
  100. signWithMail = (LinearLayout) findViewById(R.id.signupwithemail);
  101. login = (LinearLayout) findViewById(R.id.login);
  102. intropage = (LinearLayout) findViewById(R.id.intropage);
  103.  
  104. signup.setVisibility(View.GONE);
  105. signWithMail.setVisibility(View.GONE);
  106. login.setVisibility(View.GONE);
  107.  
  108. }
  109. //////////////////////////////////////////////////////////// codes associated with intropage.xml
  110.  
  111. public void SignInFromIntroPage(View v) {
  112. // signup.setVisibility(View.GONE);
  113. // signWithMail.setVisibility(View.GONE);
  114. // showRequiredAnimation(R.id.loginUI,login,R.id.intropage,intropage);
  115. // Toast.makeText(getApplicationContext(),"Will be implemented",Toast.LENGTH_LONG).show();
  116. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  117. }
  118.  
  119.  
  120. public void SignupFromIntroPage(View v) {
  121. signWithMail.setVisibility(View.GONE);
  122. login.setVisibility(View.GONE);
  123. showRequiredAnimation(R.id.loginUI, signup, R.id.intropage, intropage);
  124. }
  125. ////////////////////////////////////////////////////////////////////////////////////////////////
  126.  
  127.  
  128. /////////////////////////////////////////////////////////// codes associated with social signup page
  129.  
  130. public void SignUpWithFb(View v) {
  131. Toast.makeText(getApplicationContext(), "Will be implemented", Toast.LENGTH_LONG).show();
  132. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  133. }
  134.  
  135. public void SignUpWithGoogle(View v) {
  136. Toast.makeText(getApplicationContext(), "Will be implemented", Toast.LENGTH_LONG).show();
  137. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  138. }
  139.  
  140. public void ChangePageForSignUp(View v) {
  141. //signup.setVisibility(View.GONE);
  142. //signWithMail.setVisibility(View.VISIBLE);
  143. login.setVisibility(View.GONE);
  144. intropage.setVisibility(View.GONE);
  145. showRequiredAnimation(R.id.loginUI, signWithMail, R.id.signup, signup);
  146. }
  147.  
  148. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  149.  
  150. /////////////////////////////////////////////////////////// codes associated with signup with email page
  151. protected Map<String, String> getParams() {
  152.  
  153. Map<String, String> dataForParams = new HashMap<String, String>();
  154. dataForParams.put("email","a@abc.com");
  155. dataForParams.put("password", "12345678");
  156. // dataForParams.put("Content-Type", "application/json");
  157. // dataForParams.put("email", email.getText().toString());//Add the data you'd like to send to the server.
  158. // dataForParams.put("name", user.getText().toString());
  159. // dataForParams.put("password", pass.getText().toString());
  160. // dataForParams.put("birth_date", "1-1-1");
  161. // dataForParams.put("gender", "mail");
  162. // dataForParams.put("phone", "01231");
  163. return dataForParams;
  164. }
  165. protected Map<String, String> getDummyParams() {
  166. Map<String, String> dataForParams = new HashMap<String, String>();
  167. // dataForParams.put("Content-Type", "application/json");
  168. dataForParams.put("playlist_name","kulukulu");
  169. dataForParams.put("playlist_name_kurdish", "habijabi");
  170. return dataForParams;
  171. }
  172.  
  173. public void SignUpFromEmail(View v) throws JSONException {
  174. email = (EditText) findViewById(R.id.signup_email);
  175. user = (EditText) findViewById(R.id.signup_username);
  176. pass = (EditText) findViewById(R.id.signup_password);
  177. final CustomJSONObjectRequest jsonObjectRequest = new CustomJSONObjectRequest(Request.Method.POST, Constant.API_CREATE_PLAYLIST, new JSONObject(getDummyParams()), new Response.Listener<JSONObject>() {
  178. @Override
  179. public void onResponse(JSONObject response) {
  180. Log.v("Response in the signup", "" + response.toString());
  181. try {
  182.  
  183. if (response.getString("success").toString().matches("1"))
  184. {
  185. // AppSharedPreference app = AppSharedPreference.getInstance(getApplicationContext());
  186. // app.putLogInUserToken(response.getString("token"));
  187. Toast.makeText(getApplicationContext(), "Successfully Registered, Now Enjoy!", Toast.LENGTH_LONG).show();
  188. } else {
  189. Toast.makeText(getApplicationContext(), "Something went wrong, Please try later", Toast.LENGTH_LONG).show();
  190. }
  191. } catch (JSONException e) {
  192. e.printStackTrace();
  193. }
  194.  
  195.  
  196. }
  197. }, new Response.ErrorListener() {
  198. @Override
  199. public void onErrorResponse(VolleyError error) {
  200. Toast.makeText(getApplicationContext(), "Network error", Toast.LENGTH_LONG).show();
  201. Log.v("Error", "habijabi " + error);
  202. }
  203. });
  204.  
  205. mQueue.add(jsonObjectRequest);
  206.  
  207.  
  208.  
  209. // startActivity(new Intent(getApplicationContext(),MainActivity.class));
  210. }
  211.  
  212. //////////////////////////////////////////////////////////// codes associated with login page
  213.  
  214. public void loginWithFb(View v) {
  215. Toast.makeText(getApplicationContext(), "Will be implemented", Toast.LENGTH_LONG).show();
  216. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  217. }
  218.  
  219. public void loginWithGooglePlus(View v) {
  220. Toast.makeText(getApplicationContext(), "Will be implemented", Toast.LENGTH_LONG).show();
  221. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  222. }
  223.  
  224. public void loginPageDone(View v) {
  225. EditText userName = (EditText) findViewById(R.id.login_username);
  226. EditText password = (EditText) findViewById(R.id.login_password);
  227.  
  228. Toast.makeText(getApplicationContext(), "Will be implemented", Toast.LENGTH_LONG).show();
  229. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  230.  
  231. }
  232.  
  233. public void loginForgotPass(View v) {
  234. Toast.makeText(getApplicationContext(), "Will be implemented", Toast.LENGTH_LONG).show();
  235. }
  236.  
  237. //////////////////////////////////////////////////////////////////////////////////////////
  238.  
  239. /// shows the view animtion
  240. public void showRequiredAnimation(final int show, final LinearLayout keep, final int delete, final LinearLayout remove) {
  241.  
  242. YoYo.with(Techniques.SlideInUp)
  243. .duration(500)
  244. .interpolate(new Interpolator() {
  245. @Override
  246. public float getInterpolation(float v) {
  247. return 0;
  248. }
  249. })
  250. .withListener(new Animator.AnimatorListener() {
  251. @Override
  252. public void onAnimationStart(Animator animation) {
  253. keep.setVisibility(View.VISIBLE);
  254. }
  255.  
  256. @Override
  257. public void onAnimationEnd(Animator animation) {
  258. YoYo.with(Techniques.SlideOutRight)
  259. .duration(650)
  260. .playOn(findViewById(delete));
  261. remove.setVisibility(View.GONE);
  262. }
  263.  
  264. @Override
  265. public void onAnimationCancel(Animator animation) {
  266.  
  267. }
  268.  
  269. @Override
  270. public void onAnimationRepeat(Animator animation) {
  271.  
  272. }
  273. })
  274. .playOn(findViewById(show));
  275. }
  276.  
  277.  
  278. private class MyPagerAdapter extends PagerAdapter {
  279.  
  280. int NumberOfPages = 3;
  281. int cur = 0;
  282.  
  283. int[] res = {
  284. R.mipmap.splash1,
  285. R.mipmap.splash2,
  286. R.mipmap.splash3,};
  287. int[] backgroundcolor = {
  288. 0xFF101010,
  289. 0xFF202020,
  290. 0xFF303030};
  291.  
  292. @Override
  293. public int getCount() {
  294. return NumberOfPages;
  295. }
  296.  
  297. @Override
  298. public boolean isViewFromObject(View view, Object object) {
  299. return view == object;
  300. }
  301.  
  302. @Override
  303. public Object instantiateItem(ViewGroup container, int position) {
  304. int cur = position;
  305.  
  306. ImageView imageView = new ImageView(Intro.this);
  307. imageView.setImageResource(res[position]);
  308. ViewGroup.LayoutParams imageParams = new ViewGroup.LayoutParams(
  309. ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  310. imageView.setScaleType(ImageView.ScaleType.FIT_XY);
  311. imageView.setLayoutParams(imageParams);
  312.  
  313. LinearLayout layout = new LinearLayout(Intro.this);
  314. layout.setOrientation(LinearLayout.VERTICAL);
  315. ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
  316. ViewGroup.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.MATCH_PARENT);
  317. layout.setBackgroundColor(backgroundcolor[position]);
  318. layout.setLayoutParams(layoutParams);
  319. //layout.addView(textView);
  320. layout.addView(imageView);
  321.  
  322. final int page = position;
  323. layout.setOnClickListener(new View.OnClickListener() {
  324.  
  325. @Override
  326. public void onClick(View v) {
  327. }
  328. });
  329.  
  330. container.addView(layout);
  331. return layout;
  332. }
  333.  
  334. @Override
  335. public void destroyItem(ViewGroup container, int position, Object object) {
  336. container.removeView((LinearLayout) object);
  337. }
  338.  
  339. public int getCurrentPOsition() {
  340. return cur;
  341. }
  342.  
  343.  
  344. }
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement