Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.34 KB | None | 0 0
  1. package com.fashionwallet;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.app.Dialog;
  5. import android.content.ActivityNotFoundException;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.IntentFilter;
  10. import android.content.pm.PackageInfo;
  11. import android.content.pm.PackageManager;
  12. import android.content.pm.PackageManager.NameNotFoundException;
  13. import android.content.res.Configuration;
  14. import android.net.Uri;
  15. import android.os.Bundle;
  16. import android.os.Handler;
  17. import android.support.design.widget.NavigationView;
  18. import android.support.design.widget.TabLayout;
  19. import android.support.v4.app.Fragment;
  20. import android.support.v4.app.FragmentManager;
  21. import android.support.v4.app.FragmentPagerAdapter;
  22. import android.support.v4.app.FragmentTransaction;
  23. import android.support.v4.view.GravityCompat;
  24. import android.support.v4.view.ViewPager;
  25. import android.support.v4.view.ViewPager.OnPageChangeListener;
  26. import android.support.v4.widget.DrawerLayout;
  27. import android.support.v7.app.ActionBarDrawerToggle;
  28. import android.support.v7.app.AlertDialog;
  29. import android.support.v7.widget.Toolbar;
  30. import android.util.Log;
  31. import android.view.Menu;
  32. import android.view.MenuItem;
  33. import android.view.View;
  34. import android.view.View.OnClickListener;
  35. import android.view.Window;
  36. import android.view.animation.Animation;
  37. import android.view.animation.AnimationUtils;
  38. import android.view.inputmethod.InputMethodManager;
  39. import android.widget.AdapterView;
  40. import android.widget.AdapterView.OnItemClickListener;
  41. import android.widget.Button;
  42. import android.widget.ImageView;
  43. import android.widget.LinearLayout;
  44. import android.widget.ListView;
  45. import android.widget.RelativeLayout;
  46. import android.widget.TextView;
  47.  
  48. import com.adapter.AdapterCountry;
  49. import com.applovin.sdk.AppLovinSdk;
  50. import com.chartboost.sdk.CBLocation;
  51. import com.chartboost.sdk.Chartboost;
  52. import com.chartboost.sdk.ChartboostDelegate;
  53. import com.chartboost.sdk.Libraries.CBLogging;
  54. import com.chartboost.sdk.Model.CBError;
  55. import com.commonutility.FragmentTAG;
  56. import com.commonutility.GlobalData;
  57. import com.commonutility.GlobalVariables;
  58. import com.commonutility.PreferenceConnector;
  59. import com.commonutility.WebService;
  60. import com.commonutility.WebServiceListener;
  61. import com.facebook.login.LoginManager;
  62. import com.google.android.gcm.GCMRegistrar;
  63. import com.helper.MyUtils;
  64. import com.heyzap.sdk.ads.HeyzapAds;
  65. import com.heyzap.sdk.ads.VideoAd;
  66. import com.material.BaseActivity;
  67. import com.model.CountryListModel;
  68. import com.squareup.picasso.Picasso;
  69.  
  70. import net.adxmi.android.os.OffersManager;
  71.  
  72. import org.json.JSONArray;
  73. import org.json.JSONException;
  74. import org.json.JSONObject;
  75.  
  76. import java.util.ArrayList;
  77. import java.util.HashMap;
  78. import java.util.List;
  79.  
  80. @SuppressWarnings("deprecation")
  81. public class ActivityMainWallet extends BaseActivity implements WebServiceListener, NavigationView.OnNavigationItemSelectedListener{
  82. private Context aiContext;
  83. private Fragment mContent;
  84. private TextView textError;
  85. private GlobalData gd;
  86. private DrawerLayout mDrawerLayout;
  87. private ActionBarDrawerToggle mDrawerToggle;
  88. private Animation slideUp, slideDown;
  89. private RelativeLayout layConnection, progressbarInternet;
  90. NavigationView mDrawerLay;
  91. public static final String TAG_MESSAGE="Message";
  92. public static final String TAG_DATA="Data";
  93. public static final String TAG_COUNTRY_PRICE_SIGN="country_price_sign";
  94. public static final String TAG_COUNTRY_NAME="country_name";
  95. public static final String TAG_COUNTRY_STATUS="country_status";
  96. public static final String TAG_COUNTRY_ID="country_id";
  97. public static final String TAG_COUNTRY_LOGO="country_logo";
  98. public static final String TAG_RESULT="RESULT";
  99. ViewPager pager;
  100. FragmentPagerAdapter adapterTab;
  101. private ImageView countryFlagImageView;
  102.  
  103. private Toolbar drawerToolbar;
  104. private TabLayout tabLayout;
  105.  
  106. boolean isOutSidePage=false;
  107.  
  108. boolean isShowFlagDialog = false;
  109.  
  110. /**
  111. * Tag used on log messages.
  112. */
  113. static final String TAG = "ActivityMainWallet";
  114. static final String DISPLAY_MESSAGE_ACTION =
  115. "com.androidhive.pushnotifications.DISPLAY_MESSAGE";
  116.  
  117. static final String EXTRA_MESSAGE = "message";
  118. @Override
  119. protected void onCreate(Bundle savedInstanceState) {
  120. super.onCreate(savedInstanceState);
  121. setContentView(R.layout.main_activity);
  122. AppLovinSdk.initializeSdk(this);
  123. HeyzapAds.start(getString(R.string.heyzap_app_id), this);
  124. //HeyzapAds.startTestActivity(this);
  125.  
  126. VideoAd.fetch();
  127.  
  128. Chartboost.startWithAppId(this, getString(R.string.api_chartboost_app_id), getString(R.string.api_chartboost_app_signature));
  129.  
  130. Chartboost.setLoggingLevel(CBLogging.Level.ALL);
  131. Chartboost.setDelegate(new ChartboostDelegate() {
  132. @Override
  133. public void didFailToLoadInterstitial(String location, CBError.CBImpressionError error) {
  134. super.didFailToLoadInterstitial(location, error);
  135.  
  136. }
  137.  
  138. @Override
  139. public void didCloseInterstitial(String location) {
  140. super.didCloseInterstitial(location);
  141. upDatePoints(GlobalVariables.VIDEO_POINTS_NEW,"Chartboost");
  142.  
  143. }
  144.  
  145. @Override
  146. public boolean shouldDisplayInterstitial(String location) {
  147. //Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  148.  
  149. return super.shouldDisplayInterstitial(location);
  150.  
  151. }
  152.  
  153. @Override
  154. public void didCacheInterstitial(String location) {
  155. super.didCacheInterstitial(location);
  156. //Toast.makeText(ActivityMainWallet.this, "interstitial cached", Toast.LENGTH_SHORT).show();
  157. //Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  158. //Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  159.  
  160. }
  161.  
  162. });
  163.  
  164. Chartboost.onCreate(this);
  165. Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT);
  166. //Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  167.  
  168. /*ViewGroup viewGroup = (ViewGroup)((ViewGroup)this.findViewById(R.id.mainLayout));
  169. MyUtils.setFontAllView(viewGroup);*/
  170.  
  171. aiContext = this;
  172. gd = new GlobalData(aiContext);
  173. gd.setStatusBarColor();
  174. slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slideup);
  175. slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidedown);
  176.  
  177. layConnection = (RelativeLayout)findViewById(R.id.lay_connection);
  178. progressbarInternet = (RelativeLayout)findViewById(R.id.lay_dialog);
  179. textError = (TextView)findViewById(R.id.text_error);
  180. textError = (TextView)findViewById(R.id.text_error);
  181.  
  182. isShowFlagDialog = PreferenceConnector.readString(aiContext, PreferenceConnector.COUNTRYSELECTED, "").equals("");
  183.  
  184. if(!PreferenceConnector.readBoolean(aiContext, PreferenceConnector.WELCOME_DIALOG_SHOWN, false)) {
  185. if(getString(R.string.show_disclaimer).equals("true")) {
  186. showWelcomeDialog();
  187. }
  188. PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.WELCOME_DIALOG_SHOWN, true);
  189.  
  190. }
  191.  
  192. if (gd.isConnectingToInternet()) {
  193. callWebService(GlobalVariables.COUNTRYLIST, new HashMap<String, String>());
  194. }else {
  195. GlobalData.showToast(getResources().getString(R.string.error_no_internet), aiContext);
  196. }
  197.  
  198. textError.setVisibility(View.VISIBLE);
  199. progressbarInternet.setVisibility(View.INVISIBLE);
  200.  
  201. if (gd.isConnectingToInternet()) {
  202. hideNoConnectionError();
  203. }else {
  204. showErrorMessage(aiContext, GlobalVariables.ERRORIDINTERNETNOTAVAILABLE, "");
  205. }
  206.  
  207. mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
  208. mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.END);
  209. mDrawerLay = (NavigationView)findViewById(R.id.navigation_view);
  210. mDrawerLay.setNavigationItemSelectedListener(this);
  211. TextView navigationTotalCreditTextView = (TextView)mDrawerLay.findViewById(R.id.nav_drawer_username);
  212. navigationTotalCreditTextView.setText("Total Credits: " + PreferenceConnector.readInteger(aiContext,
  213. PreferenceConnector.WALLETPOINTS, 0));
  214. TextView navigationWalletIDText = (TextView)mDrawerLay.findViewById(R.id.nav_drawer_wallet_id);
  215. navigationWalletIDText.setText("Wallet ID: " + PreferenceConnector.readString(aiContext,
  216. PreferenceConnector.WALLETID, ""));
  217. TextView navigationUsernameText = (TextView)mDrawerLay.findViewById(R.id.nav_drawer_username);
  218. navigationUsernameText.setText(PreferenceConnector.readString(aiContext,
  219. PreferenceConnector.USERNAME, ""));
  220. // MyUtils.setFontAllView((RelativeLayout)findViewById(R.id.laymenu));
  221. // completedoffers = (Button)mDrawerLay.findViewById(R.id.completedoffers);
  222. // MyRewards = (Button)mDrawerLay.findViewById(R.id.MyRewards);
  223. // RateusonGooglePlay = (Button)mDrawerLay.findViewById(R.id.RateusonGooglePlay);
  224. // CheckforUpdates = (Button)mDrawerLay.findViewById(R.id.CheckforUpdates);
  225. // Assistance = (Button)mDrawerLay.findViewById(R.id.Assistance);
  226. // FAQ = (Button)mDrawerLay.findViewById(R.id.FAQ);
  227. // TermsOfServices = (Button)mDrawerLay.findViewById(R.id.TermsOfServices);
  228. // Logout = (Button)mDrawerLay.findViewById(R.id.Logout);
  229. //
  230. // userIdEditText = (EditText)mDrawerLay.findViewById(R.id.userIdEditText);
  231. // userEmailEditText = (EditText)mDrawerLay.findViewById(R.id.userEmailEditText);
  232. // userPaypalEditText = (EditText)mDrawerLay.findViewById(R.id.userPaypalEditText);
  233. // userFirstNameEditText = (EditText)mDrawerLay.findViewById(R.id.userFirstNameEditText);
  234. // userLastEditText = (EditText)mDrawerLay.findViewById(R.id.userLastEditText);
  235. //
  236. // userIdEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.WALLETID,""));
  237. // userEmailEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.USERNAME,""));
  238. // userPaypalEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.PAYPAL_EMAIL,""));
  239. // userFirstNameEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.FIRST_NAME,""));
  240. // userLastEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.LAST_NAME,""));
  241. //
  242. // tv_submit = (TextView)mDrawerLay.findViewById(R.id.tv_submit);
  243. // tv_cancel = (TextView)mDrawerLay.findViewById(R.id.tv_cancel);
  244. //
  245. // appFirstName= (TextView)mDrawerLay.findViewById(R.id.firstname);
  246. // appLastName= (TextView)mDrawerLay.findViewById(R.id.lastname);
  247. // MyUtils.firstText(appFirstName);
  248. // MyUtils.lastName(appLastName);
  249. // scrollView = (ScrollView)mDrawerLay.findViewById(R.id.scrollbar_invitepage);
  250.  
  251. drawerToolbar = (Toolbar)findViewById(R.id.drawer_toolbar);
  252. drawerToolbar.setTitle(getString(R.string.app_name));
  253. drawerToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
  254. drawerToolbar.setNavigationOnClickListener(new OnClickListener() {
  255. @Override
  256. public void onClick(View v) {
  257. openAndCloseDrawer();
  258. }
  259. });
  260.  
  261. // completedoffers.setOnClickListener(this);
  262. // MyRewards.setOnClickListener(this);
  263. // RateusonGooglePlay.setOnClickListener(this);
  264. // CheckforUpdates.setOnClickListener(this);
  265. // Assistance.setOnClickListener(this);
  266. // FAQ.setOnClickListener(this);
  267. // TermsOfServices.setOnClickListener(this);
  268. // Logout.setOnClickListener(this);
  269. //
  270. // tv_submit.setOnClickListener(this);
  271. // tv_cancel.setOnClickListener(this);
  272. layConnection.setOnClickListener(new OnClickListener() {
  273. @Override
  274. public void onClick(View arg0) {
  275. textError.setVisibility(View.INVISIBLE);
  276. progressbarInternet.setVisibility(View.VISIBLE);
  277.  
  278. if (gd.isConnectingToInternet()) {
  279. hideNoConnectionError();
  280. mContent = new FragEarnCredits();
  281. getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit();
  282. }else {
  283. new Handler().postDelayed(new Runnable() {
  284. @Override
  285. public void run() {
  286. textError.setVisibility(View.VISIBLE);
  287. progressbarInternet.setVisibility(View.INVISIBLE);
  288. }
  289. }, 1000);
  290. showErrorMessage(aiContext, GlobalVariables.ERRORIDINTERNETNOTAVAILABLE, "");
  291. }
  292. }
  293. });
  294.  
  295. adapterTab = new GoogleMusicAdapter(getSupportFragmentManager());
  296. pager = (ViewPager)findViewById(R.id.pager);
  297. pager.setOnPageChangeListener(new OnPageChangeListener() {
  298.  
  299. @Override
  300. public void onPageSelected(int position) {
  301. // TODO Auto-generated method stub
  302. MyUtils.sendScreenToGoogleAnalytics(getApplication(),"Screen : " + CONTENT[position]);
  303. String countryIconUrl = PreferenceConnector.readString(ActivityMainWallet.this, PreferenceConnector.COUNTRYLOGO, "");
  304. System.out.println("My Pager " + position);
  305. Fragment frag = ((GoogleMusicAdapter)pager.getAdapter()).getItem(position);
  306. View aiView = frag.getView();
  307. if(aiView == null) return;
  308. ImageView image = (ImageView) aiView.findViewById(R.id.image_view_country_flag);
  309. if (!countryIconUrl.isEmpty()) {
  310. Picasso.with(aiContext)
  311. .load(countryIconUrl)
  312. .error(R.drawable.ic_launcher)
  313. .into(image);
  314. }
  315. /* if(position==0)
  316. ((FirstFragment)pager.getChildAt(position)).onUpdateView(); //onUpdateView is public function at 'FirstFragment', insert your code here
  317.  
  318. */
  319. /*if(position==0)
  320. FragEarnCredits.onUpdateView(aiContext);
  321. if(position==1)
  322. // ((ViewRewardsFragment)adapterTab.getItem(position)).onUpdateView();
  323. ViewRewardsFragment.onUpdateView(aiContext);*/
  324. //adapterTab.notifyDataSetChanged(); //this line will force all pages to be loaded fresh when changing between fragments
  325. }
  326.  
  327. @Override
  328. public void onPageScrolled(int arg0, float arg1, int arg2) {
  329. // TODO Auto-generated method stub
  330.  
  331. }
  332.  
  333. @Override
  334. public void onPageScrollStateChanged(int arg0) {
  335. // TODO Auto-generated method stub
  336.  
  337. }
  338. });
  339. pager.setAdapter(adapterTab);
  340.  
  341. tabLayout = (TabLayout)findViewById(R.id.sliding_tabs);
  342. for(int i = 0 ;i <pager.getAdapter().getCount(); i++) {
  343. tabLayout.addTab(tabLayout.newTab().setText(pager.getAdapter().getPageTitle(i)));
  344. LinearLayout layout = ((LinearLayout)((LinearLayout)tabLayout.getChildAt(0)).getChildAt(i));
  345. layout.setPadding(10, 0, 10 ,0);
  346. }
  347. tabLayout.setTabTextColors(getResources().getColor(R.color.md_grey_400), getResources().getColor(R.color.md_white_1000));
  348. tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.md_white_1000));
  349. tabLayout.setBackgroundColor(getResources().getColor(R.color.material_color_primary));
  350. tabLayout.setSelectedTabIndicatorHeight(8);
  351. tabLayout.setupWithViewPager(pager);
  352.  
  353. // Button copyrightButton = (Button)findViewById(R.id.navigation_button_footer);
  354. // copyrightButton.setOnClickListener(new OnClickListener() {
  355. // @Override
  356. // public void onClick(View v) {
  357. // Intent viewIntent = new Intent(Intent.ACTION_VIEW);
  358. // viewIntent.setData(Uri.parse("https://github.com/mikimn/"));
  359. // startActivity(viewIntent);
  360. // }
  361. // });
  362.  
  363. customizeActionBar();
  364.  
  365. registerReceiver(mHandleMessageReceiver, new IntentFilter(
  366. DISPLAY_MESSAGE_ACTION));
  367.  
  368.  
  369.  
  370.  
  371.  
  372. }
  373.  
  374. public void initCountryFlagIcon(View aiView) {
  375. ImageView countryFlagImageView = (ImageView)aiView.findViewById(R.id.image_view_country_flag);
  376. countryFlagImageView.setClickable(true);
  377. countryFlagImageView.setOnClickListener(new View.OnClickListener() {
  378. @Override
  379. public void onClick(View v) {
  380. if (gd.isConnectingToInternet()) {
  381. callWebService(GlobalVariables.COUNTRYLIST, new HashMap<String, String>());
  382. } else {
  383. GlobalData.showToast(getResources().getString(R.string.error_no_internet), aiContext);
  384. }
  385. }
  386. });
  387. }
  388.  
  389. @Override
  390. protected void initViews() {
  391.  
  392. }
  393. public void upDatePoints(String points,String sdkName) {
  394. // TODO Auto-generated method stub
  395. String[] keys = {"wallet_id", "points","sdkName"};
  396. String[] value = {PreferenceConnector.readString(aiContext, PreferenceConnector.WALLETID, ""),points,sdkName};
  397.  
  398. HashMap<String, String> hash = new HashMap<String, String>();
  399. for (int i = 0; i < keys.length; i++) {
  400. System.out.println(keys[i]+ "......." + value[i]);
  401. hash.put(keys[i], value[i]);
  402. }
  403.  
  404. if (gd.isConnectingToInternet()) {
  405. callWebService(GlobalVariables.UPDATE_POINTS, hash);
  406. }else {
  407. GlobalData.showToast(getResources().getString(R.string.error_no_internet), aiContext);
  408. }
  409. }
  410.  
  411.  
  412.  
  413. public static final String[] CONTENT = new String[] {"EARN CREDITS", "REWARDS", "INVITE", "CONNECT"};
  414. class GoogleMusicAdapter extends FragmentPagerAdapter {
  415.  
  416. private Fragment[] frags;
  417.  
  418. public GoogleMusicAdapter(FragmentManager fm) {
  419. super(fm);
  420. frags = new Fragment[] {new FragEarnCredits(),
  421. new ViewRewardsFragment(),
  422. new InviteFriendsFragment(),
  423. new ConnectSocialFragment()};
  424. }
  425.  
  426. @Override
  427. public Fragment getItem(int position) {
  428. // Fragment frag = null;
  429. return frags[position];
  430. }
  431.  
  432. @Override
  433. public CharSequence getPageTitle(int position) {
  434. String title = null;
  435. switch (position) {
  436. case 0:
  437. title = CONTENT[0];
  438. break;
  439. case 1:
  440. title = CONTENT[1];
  441. break;
  442. case 2:
  443. title = CONTENT[2];
  444. break;
  445. case 3:
  446. title = CONTENT[3];
  447. break;
  448.  
  449. default:
  450. break;
  451. }
  452. return title;
  453. }
  454.  
  455. @Override
  456. public int getCount() {
  457. return CONTENT.length;
  458. }
  459. @Override
  460. public int getItemPosition(Object object) {
  461. return POSITION_UNCHANGED;
  462. }
  463. }
  464.  
  465. @SuppressLint("InflateParams")
  466. public void customizeActionBar() {
  467.  
  468.  
  469. mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
  470. mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
  471. @Override public void onDrawerClosed(View drawerView) {
  472. hideKeyboard();
  473. super.onDrawerClosed(drawerView);
  474. }
  475.  
  476. @Override public void onDrawerOpened(View drawerView) {
  477. hideKeyboard();
  478. super.onDrawerOpened(drawerView);
  479. }
  480. };
  481. mDrawerToggle.setDrawerIndicatorEnabled(true);
  482.  
  483. mDrawerLayout.setDrawerListener(mDrawerToggle);
  484. mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
  485. pager.setVisibility(View.VISIBLE);
  486. tabLayout.setVisibility(View.VISIBLE);
  487.  
  488. getToolbar().setTitle(R.string.app_name);
  489. mDrawerToggle.setDrawerIndicatorEnabled(true);
  490. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  491. getSupportActionBar().setHomeButtonEnabled(true);
  492. mDrawerToggle.syncState();
  493.  
  494. Toolbar toolbar = (Toolbar)findViewById(R.id.toolbarInner);
  495.  
  496. toolbar.setNavigationOnClickListener(new OnClickListener() {
  497. @Override
  498. public void onClick(View v) {
  499. openAndCloseDrawer();
  500. }
  501. });
  502. toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  503. @Override
  504. public boolean onMenuItemClick(MenuItem item) {
  505. switch (item.getItemId()) {
  506. case android.R.id.home:
  507. openAndCloseDrawer();
  508. return true;
  509. }
  510. return false;
  511. }
  512. });
  513. }
  514.  
  515. public void customizeActionBarWithBack(String string) {
  516.  
  517. Toolbar toolbar = (Toolbar)findViewById(R.id.toolbarInner);
  518. toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000));
  519. toolbar.setTitle(string);
  520.  
  521. setDisplayHomeAsUpEnabled(true, R.drawable.abc_ic_ab_back_mtrl_am_alpha);
  522. mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
  523.  
  524. toolbar.setNavigationOnClickListener(new OnClickListener() {
  525. @Override
  526. public void onClick(View v) {
  527. switchBack();
  528. customizeActionBar();
  529. }
  530. });
  531. toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  532. @Override
  533. public boolean onMenuItemClick(MenuItem item) {
  534. switch(item.getItemId()) {
  535. case android.R.id.home:
  536. switchBack();
  537. customizeActionBar();
  538. return true;
  539. }
  540.  
  541.  
  542. return false;
  543. }
  544. });
  545. }
  546.  
  547. // public static void showErrorMessage(Context aContext, int errorId, String strValue) {
  548. // textError.setVisibility(View.VISIBLE);
  549. // if (errorId == 0) {
  550. // textError.setText(strValue);
  551. // }else {
  552. // if(errorId == GlobalData.ERRORIDNOTGETTINGDATAFROMSERVER) {
  553. // textError.setText(GlobalData.getStringRes(aContext, R.string.errorgettingdatafromserver));
  554. // }else if (errorId == GlobalData.ERRORIDINTERNETNOTAVAILABLE) {
  555. // textError.setText(GlobalData.getStringRes(aContext, R.string.errorsplashinternetnotavailable));
  556. // }
  557. // }
  558. // }
  559. //
  560. // public static void hideErrorMessage() {
  561. // textError.setVisibility(View.GONE);
  562. // }
  563.  
  564.  
  565. @Override
  566. public boolean onCreateOptionsMenu(Menu menu) {
  567. return super.onCreateOptionsMenu(menu);
  568. }
  569.  
  570. @Override
  571. public boolean onOptionsItemSelected(MenuItem item) {
  572. switch (item.getItemId()) {
  573. case android.R.id.home:
  574. openAndCloseDrawer();
  575. break;
  576. }
  577. return super.onOptionsItemSelected(item);
  578. }
  579.  
  580. public void showErrorMessage(Context aiContext, int errorId, String strValue) {
  581. layConnection.setVisibility(View.VISIBLE);
  582.  
  583. textError.setVisibility(View.VISIBLE);
  584. progressbarInternet.setVisibility(View.INVISIBLE);
  585. if (errorId == GlobalVariables.CUSTOMIZEERROR) {
  586. textError.setText(strValue);
  587. }else {
  588. if(errorId == GlobalVariables.ERRORIDNOTGETTINGDATAFROMSERVER) {
  589. textError.setText(GlobalData.getStringRes(aiContext, R.string.error_data_from_server));
  590. }else if (errorId == GlobalVariables.ERRORIDINTERNETNOTAVAILABLE) {
  591. textError.setText(GlobalData.getStringRes(aiContext, R.string.error_splash_no_internet));
  592. }
  593. }
  594.  
  595. if (errorId == 1) {
  596. }
  597. }
  598.  
  599. public void hideNoConnectionError() {
  600. layConnection.setVisibility(View.GONE);
  601. textError.setVisibility(View.INVISIBLE);
  602. progressbarInternet.setVisibility(View.VISIBLE);
  603. }
  604.  
  605. public void switchContent(Fragment fragment, String tag) {
  606. hideNoConnectionError();
  607. hideKeyboard();
  608.  
  609. pager.setVisibility(View.GONE);
  610. tabLayout.setVisibility(View.GONE);
  611. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  612. transaction.replace(R.id.content_frame, fragment).addToBackStack(tag).commit();
  613. }
  614.  
  615.  
  616.  
  617. public void switchBack() {
  618. isOutSidePage=false;
  619. hideKeyboard();
  620. FragmentManager fragmentManager = getSupportFragmentManager();
  621. if(fragmentManager.getBackStackEntryCount() > 0){
  622. fragmentManager.popBackStack();
  623. }
  624. }
  625.  
  626. @Override
  627. protected void onPostCreate(Bundle savedInstanceState) {
  628. // Sync the toggle state after onRestoreInstanceState has occurred.
  629. mDrawerToggle.syncState();
  630. super.onPostCreate(savedInstanceState);
  631. }
  632.  
  633. @Override
  634. public void onConfigurationChanged(Configuration newConfig) {
  635. super.onConfigurationChanged(newConfig);
  636. // Pass any configuration change to the drawer toggles
  637. mDrawerToggle.onConfigurationChanged(newConfig);
  638. }
  639.  
  640. private void hideKeyboard() {
  641. InputMethodManager inputManager = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
  642. // check if no view has focus:
  643. View view = this.getCurrentFocus();
  644. if (view != null) {
  645. inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
  646. }
  647. }
  648.  
  649. public static void hideFragmentkeyboard(Context meraContext, View meraView) {
  650. final InputMethodManager imm = (InputMethodManager) meraContext.getSystemService(Context.INPUT_METHOD_SERVICE);
  651. imm.hideSoftInputFromWindow(meraView.getWindowToken(), 0);
  652. }
  653.  
  654. private void callWebService(String postUrl, HashMap<String, String> hash) {
  655. WebService webService = new WebService(aiContext, "", postUrl, hash, this, WebService.POST);
  656. webService.execute();
  657. }
  658.  
  659. @Override
  660. protected void onResume() {
  661. // TODO Auto-generated method stub
  662. super.onResume();
  663. if (!(adapterTab == null)) {
  664.  
  665. adapterTab.notifyDataSetChanged();
  666.  
  667.  
  668. }
  669. Chartboost.onResume(this);
  670. /*GlobalData.showToast("resume", this);*/
  671.  
  672. }
  673.  
  674. @Override
  675. public void onBackPressed() {
  676. super.onBackPressed();
  677. FragEarnCredits.onUpdateView(aiContext);
  678. ViewRewardsFragment.onUpdateView(aiContext);
  679. InviteFriendsFragment.onUpdateView(aiContext);
  680. ConnectSocialFragment.onUpdateView(aiContext);
  681. customizeActionBar();
  682. switchBack();
  683. Chartboost.onBackPressed();
  684. }
  685.  
  686. @Override
  687. protected void onPause() {
  688. super.onPause();
  689. Chartboost.onPause(this);
  690. }
  691.  
  692. @Override
  693. protected void onStart() {
  694. super.onStart();
  695. Chartboost.onStart(this);
  696. }
  697.  
  698. @Override
  699. protected void onStop() {
  700. super.onStop();
  701. Chartboost.onStop(this);
  702. }
  703.  
  704.  
  705. @Override
  706. public void onWebServiceActionComplete(String result, String url) {
  707. System.out.println("..pretext.." + result + ".........jsonresponse....." + url);
  708. countryList = new ArrayList<CountryListModel>();
  709. if (url.contains(GlobalVariables.COUNTRYLIST)) {
  710.  
  711. String countryIconUrl = "";
  712.  
  713. try {
  714. JSONObject json = new JSONObject(result);
  715. String str_RESULT = json.getString(TAG_RESULT);
  716. String str_Message = json.getString(TAG_MESSAGE);
  717. JSONArray Data = json.getJSONArray(TAG_DATA);
  718. for(int Data_i = 0; Data_i < Data.length(); Data_i++){
  719. JSONObject Data_obj=Data.getJSONObject(Data_i);
  720. String str_country_price_sign = Data_obj.getString(TAG_COUNTRY_PRICE_SIGN);
  721. String str_country_name = Data_obj.getString(TAG_COUNTRY_NAME);
  722. String str_country_status = Data_obj.getString(TAG_COUNTRY_STATUS);
  723. String str_country_id = Data_obj.getString(TAG_COUNTRY_ID);
  724. String str_country_logo = Data_obj.getString(TAG_COUNTRY_LOGO);
  725.  
  726. if(str_country_id.equals(PreferenceConnector.readString(aiContext, PreferenceConnector.COUNTRYID, "2"))) {
  727. countryIconUrl = str_country_logo;
  728. }
  729.  
  730. countryList.add(new CountryListModel(str_country_id, str_country_status,
  731. str_country_price_sign, str_country_name, str_country_logo));
  732.  
  733.  
  734. }
  735. }catch (JSONException e){
  736. e.printStackTrace();
  737. }
  738.  
  739. if(isShowFlagDialog) {
  740. showCountryDialog(aiContext);
  741. }
  742. isShowFlagDialog = true;
  743. for(int i = 0; i < pager.getAdapter().getCount(); i++) {
  744. Fragment frag = ((GoogleMusicAdapter) pager.getAdapter()).getItem(i);
  745. View aiView = frag.getView();
  746. if(aiView == null) continue;
  747. ImageView image = (ImageView) aiView.findViewById(R.id.image_view_country_flag);
  748. if (!countryIconUrl.isEmpty()) {
  749. Picasso.with(aiContext)
  750. .load(countryIconUrl)
  751. .error(R.drawable.ic_launcher)
  752. .into(image);
  753. }
  754. }
  755. }
  756. if (url.contains(GlobalVariables.UPDATE_PROFILE)) {
  757. try {
  758. JSONObject json = new JSONObject(result);
  759. String str_RESULT = json.getString(TAG_RESULT);
  760. String str_Message = json.getString(TAG_MESSAGE);
  761. GlobalData.showToast(str_Message, aiContext);
  762.  
  763.  
  764.  
  765. if (str_RESULT.equals("YES")) {
  766. openAndCloseDrawer();
  767. JSONObject Data_obj = json.getJSONObject(TAG_DATA);
  768. String str_first_name = Data_obj.getString(ActivityLogin.TAG_FIRST_NAME);
  769. String str_last_name = Data_obj.getString(ActivityLogin.TAG_LAST_NAME);
  770. String str_email = Data_obj.getString(ActivityLogin.TAG_PAYPAY_EMAIL);
  771.  
  772. PreferenceConnector.writeString(aiContext, PreferenceConnector.FIRST_NAME, str_first_name);
  773. PreferenceConnector.writeString(aiContext, PreferenceConnector.LAST_NAME, str_last_name);
  774. PreferenceConnector.writeString(aiContext, PreferenceConnector.PAYPAL_EMAIL, str_email);
  775.  
  776. // userPaypalEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.PAYPAL_EMAIL,""));
  777. // userFirstNameEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.FIRST_NAME,""));
  778. // userLastEditText.setText(PreferenceConnector.readString(aiContext, PreferenceConnector.LAST_NAME,""));
  779.  
  780.  
  781. }
  782. } catch (JSONException e){
  783. e.printStackTrace();
  784. }
  785. }
  786. }
  787.  
  788. List<CountryListModel> countryList = new ArrayList<CountryListModel>();
  789. private void showCountryDialog(final Context aiContext) {
  790. final Dialog dialog;
  791. dialog = new Dialog(aiContext);
  792. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  793. dialog.setContentView(R.layout.select_country_dialog);
  794.  
  795. ListView list = (ListView)dialog.findViewById(R.id.listView1);
  796.  
  797. AdapterCountry offerListAdapter = new AdapterCountry(aiContext, countryList);
  798. list.setAdapter(offerListAdapter);
  799. list.setOnItemClickListener(new OnItemClickListener() {
  800. @Override
  801. public void onItemClick(AdapterView<?> arg0, View arg1, int aiPos, long arg3) {
  802. PreferenceConnector.writeString(aiContext, PreferenceConnector.COUNTRYSELECTED,
  803. countryList.get(aiPos).getStr_country_name());
  804.  
  805. PreferenceConnector.writeString(aiContext, PreferenceConnector.COUNTRYSYMBOL,
  806. countryList.get(aiPos).getStr_country_price_sign());
  807.  
  808. PreferenceConnector.writeString(aiContext, PreferenceConnector.COUNTRYID,
  809. countryList.get(aiPos).getStr_country_id());
  810.  
  811. PreferenceConnector.writeString(aiContext, PreferenceConnector.COUNTRYLOGO,
  812. countryList.get(aiPos).getStr_country_logo());
  813.  
  814. String countryIconUrl = countryList.get(aiPos).getStr_country_logo();
  815.  
  816. dialog.dismiss();
  817. ViewRewardsFragment.onUpdateView(aiContext);
  818.  
  819. for (int i = 0; i < pager.getAdapter().getCount(); i++) {
  820. Fragment frag = ((GoogleMusicAdapter) pager.getAdapter()).getItem(i);
  821. if (frag instanceof ViewRewardsFragment) {
  822. ((ViewRewardsFragment)frag).LoadCountryDetail();
  823. }
  824. View aiView = frag.getView();
  825. if (aiView == null) continue;
  826. ImageView image = (ImageView) aiView.findViewById(R.id.image_view_country_flag);
  827. if (!countryIconUrl.isEmpty()) {
  828. Picasso.with(aiContext)
  829. .load(countryIconUrl)
  830. .error(R.drawable.ic_launcher)
  831. .into(image);
  832. }
  833. }
  834. }
  835. });
  836.  
  837. dialog.show();
  838. }
  839.  
  840. @Override
  841. public boolean onNavigationItemSelected(MenuItem menuItem) {
  842. switch (menuItem.getItemId()) {
  843. case R.id.drawer_home:
  844. openAndCloseDrawer();
  845. switchBack();
  846. break;
  847. case R.id.drawer_input_code:
  848. isOutSidePage = true;
  849. openAndCloseDrawer();
  850. switchContent(new InputInvitationCodeFragment(), FragmentTAG.FragInputInvitationCode);
  851. break;
  852. case R.id.drawer_offer_history:
  853. isOutSidePage=true;
  854. openAndCloseDrawer();
  855. switchContent(new CompletedOfferListFragment(), FragmentTAG.FragCompletedOffers);
  856. break;
  857. case R.id.drawer_reward_history:
  858. isOutSidePage=true;
  859. openAndCloseDrawer();
  860. switchContent(new MyRewardsListFragment(), FragmentTAG.FragMyRewardsOffer);
  861. break;
  862. case R.id.drawer_rate:
  863. openAndCloseDrawer();
  864. goToGooglePlay();
  865. break;
  866. case R.id.drawer_check_updates:
  867. openAndCloseDrawer();
  868.  
  869. PackageManager manager = this.getPackageManager();
  870. PackageInfo info;
  871. try {
  872. info = manager.getPackageInfo(this.getPackageName(), 0);
  873. if(info.versionCode<Float.parseFloat(PreferenceConnector.readString(aiContext, PreferenceConnector.APPVERSION, "1"))){
  874. showCheckUpdateDialog(aiContext, getResources().getString(R.string.error_old_version), 20, "UPDATE NOW", "");
  875. }
  876. else{
  877. showCheckUpdateDialog(aiContext, getResources().getString(R.string.message_updated_version), 20, "OK", "");
  878. }
  879.  
  880. } catch (NameNotFoundException e) {
  881. //TODO Auto-generated catch block
  882. e.printStackTrace();
  883. }
  884. break;
  885. case R.id.drawer_assistance:
  886. isOutSidePage=true;
  887. openAndCloseDrawer();
  888. switchContent(new AssistanceFragment(), FragmentTAG.FragAssistance);
  889. break;
  890. case R.id.drawer_faq:
  891. isOutSidePage=true;
  892. openAndCloseDrawer();
  893. switchContent(new FAQ(), FragmentTAG.FragFAQ);
  894. break;
  895. case R.id.drawer_terms:
  896. isOutSidePage=true;
  897. openAndCloseDrawer();
  898. switchContent(new TermsOfServiceFragemnt(), FragmentTAG.FragTermsOf);
  899. break;
  900. case R.id.drawer_logout:
  901. //PreferenceConnector.cleanPrefrences(aiContext);
  902. PreferenceConnector.writeString(aiContext, PreferenceConnector.USERNAME, "");
  903.  
  904. PreferenceConnector.writeString(aiContext, PreferenceConnector.FIRST_NAME, "");
  905. PreferenceConnector.writeString(aiContext, PreferenceConnector.LAST_NAME, "");
  906. PreferenceConnector.writeString(aiContext, PreferenceConnector.PAYPAL_EMAIL, "");
  907.  
  908. PreferenceConnector.writeString(aiContext, PreferenceConnector.PASSWORD, "");
  909.  
  910. PreferenceConnector.writeString(aiContext, PreferenceConnector.USERID, "");
  911. PreferenceConnector.writeString(aiContext, PreferenceConnector.WALLETID, "");
  912. PreferenceConnector.writeInteger(aiContext, PreferenceConnector.WALLETPOINTS,
  913. Integer.parseInt("0"));
  914. PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.ISREMEMBER, false);
  915. PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.ISFBLOGIN, false);
  916. PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.ISGPLOGIN, false);
  917. Intent aiIntent = new Intent(aiContext, ActivityLogin.class);
  918. startActivity(aiIntent);
  919. LoginManager.getInstance().logOut();
  920. finish();
  921. break;
  922. case R.id.drawer_edit_profile:
  923.  
  924. if (gd.isConnectingToInternet()) {
  925. isOutSidePage = true;
  926. openAndCloseDrawer();
  927. switchContent(new FragEditProfile(), FragmentTAG.FragEditProfile);
  928. break;
  929. // onUpdateProfile();
  930. }else {
  931. GlobalData.showToast(getResources().getString(R.string.error_no_internet), aiContext);
  932. }
  933. break;
  934. case R.id.drawer_view_invited_friends:
  935. isOutSidePage=true;
  936. openAndCloseDrawer();
  937. switchContent(new InvitedFriendListFragment(), FragmentTAG.FragInvitedFriends);
  938. break;
  939. /* case R.id.drawer_design:
  940. showDesignedByDialog();*/
  941. default:
  942. break;
  943. }
  944. return false;
  945. }
  946. //
  947. // @Override
  948. // public void onClick(View v) {
  949. // // TODO Auto-generated method stub
  950. // switch (v.getId()) {
  951. // case R.id.completedoffers:
  952. // isOutSidePage=true;
  953. // openAndCloseDrawer();
  954. // switchContent(new CompletedOfferListFragment(), FragmentTAG.FragCompletedOffers);
  955. // break;
  956. // case R.id.MyRewards:
  957. // isOutSidePage=true;
  958. // openAndCloseDrawer();
  959. // switchContent(new MyRewardsListFragment(), FragmentTAG.FragMyRewardsOffer);
  960. // break;
  961. // case R.id.RateusonGooglePlay:
  962. // openAndCloseDrawer();
  963. // goToGooglePlay();
  964. // break;
  965. // case R.id.CheckforUpdates:
  966. // openAndCloseDrawer();
  967. //
  968. // PackageManager manager = this.getPackageManager();
  969. // PackageInfo info;
  970. // try {
  971. // info = manager.getPackageInfo(this.getPackageName(), 0);
  972. // if(info.versionCode<Float.parseFloat(PreferenceConnector.readString(aiContext, PreferenceConnector.APPVERSION, "1"))){
  973. // showCheckUpdateDialog(aiContext, "You're using the old version!", 20, "UPDATE NOW", "");
  974. // }
  975. // else{
  976. // showCheckUpdateDialog(aiContext, "You're using the latest version!", 20, "OK", "");
  977. // }
  978. //
  979. // } catch (NameNotFoundException e) {
  980. // // TODO Auto-generated catch block
  981. // e.printStackTrace();
  982. // }
  983. // break;
  984. // case R.id.Assistance:
  985. // isOutSidePage=true;
  986. // openAndCloseDrawer();
  987. // switchContent(new AssistanceFragment(), FragmentTAG.FragAssistance);
  988. // break;
  989. // case R.id.FAQ:
  990. // isOutSidePage=true;
  991. // openAndCloseDrawer();
  992. // switchContent(new FAQ(), FragmentTAG.FragFAQ);
  993. // break;
  994. // case R.id.TermsOfServices:
  995. // isOutSidePage=true;
  996. // openAndCloseDrawer();
  997. // switchContent(new TermsOfServiceFragemnt(), FragmentTAG.FragTermsOf);
  998. // break;
  999. // case R.id.Logout:
  1000. // //PreferenceConnector.cleanPrefrences(aiContext);
  1001. // PreferenceConnector.writeString(aiContext, PreferenceConnector.USERNAME, "");
  1002. //
  1003. // PreferenceConnector.writeString(aiContext, PreferenceConnector.FIRST_NAME, "");
  1004. // PreferenceConnector.writeString(aiContext, PreferenceConnector.LAST_NAME, "");
  1005. // PreferenceConnector.writeString(aiContext, PreferenceConnector.PAYPAL_EMAIL, "");
  1006. //
  1007. // PreferenceConnector.writeString(aiContext, PreferenceConnector.PASSWORD, "");
  1008. //
  1009. // PreferenceConnector.writeString(aiContext, PreferenceConnector.USERID, "");
  1010. // PreferenceConnector.writeString(aiContext, PreferenceConnector.WALLETID, "");
  1011. // PreferenceConnector.writeInteger(aiContext, PreferenceConnector.WALLETPOINTS,
  1012. // Integer.parseInt("0"));
  1013. // PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.ISREMEMBER, false);
  1014. // PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.ISFBLOGIN, false);
  1015. // PreferenceConnector.writeBoolean(aiContext, PreferenceConnector.ISGPLOGIN, false);
  1016. // Intent aiIntent = new Intent(aiContext, ActivityLogin.class);
  1017. // startActivity(aiIntent);
  1018. // finish();
  1019. // break;
  1020. // case R.id.tv_submit:
  1021. //
  1022. // if (gd.isConnectingToInternet()) {
  1023. //// onUpdateProfile();
  1024. // }else {
  1025. // GlobalData.showToast(getResources().getString(R.string.error_internet), aiContext);
  1026. // }
  1027. // break;
  1028. // case R.id.tv_cancel:
  1029. // openAndCloseDrawer();
  1030. // break;
  1031. // default:
  1032. // break;
  1033. // }
  1034. //
  1035. // }
  1036.  
  1037. private void openAndCloseDrawer(){
  1038. if (mDrawerLayout.isDrawerOpen(mDrawerLay)) {
  1039. mDrawerLayout.closeDrawer(mDrawerLay);
  1040. //imgSlideMenu.setImageResource(R.drawable.ico_left);
  1041. }else {
  1042. mDrawerLayout.openDrawer(mDrawerLay);
  1043. //imgSlideMenu.setImageResource(R.drawable.menuopener);
  1044. }
  1045. }
  1046. private void goToGooglePlay(){
  1047. Uri uri = Uri.parse("market://details?id=" + aiContext.getPackageName());
  1048. Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
  1049. // To count with Play market backstack, After pressing back button,
  1050. // to taken back to our application, we need to add following flags to intent.
  1051. goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
  1052. Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
  1053. Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
  1054. try {
  1055. startActivity(goToMarket);
  1056. } catch (ActivityNotFoundException e) {
  1057. startActivity(new Intent(Intent.ACTION_VIEW,
  1058. Uri.parse("http://play.google.com/store/apps/details?id=" + aiContext.getPackageName())));
  1059. }
  1060. }
  1061.  
  1062. private void showCheckUpdateDialog(final Context aiContext, final String text, int textSize,
  1063. final String btnOneText, String btnTwoText) {
  1064.  
  1065.  
  1066. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  1067. builder.setTitle("Check for updates");
  1068. builder.setMessage(text);
  1069. builder.setPositiveButton(btnOneText, new DialogInterface.OnClickListener() {
  1070. public void onClick(DialogInterface dialog, int which) {
  1071. dialog.cancel();
  1072. if (btnOneText.equals("UPDATE NOW")) {
  1073. if (gd.isConnectingToInternet()) {
  1074. goToGooglePlay();
  1075. } else {
  1076. GlobalData.showDialog(aiContext, getResources().getString(R.string.error_no_internet), 16, "OK", "");
  1077. }
  1078. }
  1079. }
  1080. });
  1081.  
  1082. AlertDialog alert = builder.create();
  1083. alert.show();
  1084. Button buttonOk = alert.getButton(DialogInterface.BUTTON_POSITIVE);
  1085. buttonOk.setBackgroundColor(getResources().getColor(R.color.material_color_accent));
  1086. buttonOk.setTextColor(getResources().getColor(R.color.md_white_1000));
  1087. }
  1088.  
  1089. private void showWelcomeDialog() {
  1090. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  1091. builder.setTitle(getString(R.string.welcome_disclaimer_title));
  1092. builder.setMessage(getString(R.string.welcome_disclaimer_message)
  1093. );
  1094. builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  1095. public void onClick(DialogInterface dialog, int which) {
  1096. dialog.dismiss();
  1097. }
  1098. });
  1099. builder.setNegativeButton("More Questions", new DialogInterface.OnClickListener() {
  1100. @Override
  1101. public void onClick(DialogInterface dialog, int which) {
  1102. dialog.dismiss();
  1103. isOutSidePage=true;
  1104. openAndCloseDrawer();
  1105. switchContent(new FAQ(), FragmentTAG.FragFAQ);
  1106. }
  1107. });
  1108.  
  1109. AlertDialog alert = builder.create();
  1110. alert.show();
  1111. Button buttonOk = alert.getButton(DialogInterface.BUTTON_POSITIVE);
  1112. buttonOk.setBackgroundColor(getResources().getColor(R.color.material_color_accent));
  1113. buttonOk.setTextColor(getResources().getColor(R.color.md_white_1000));
  1114.  
  1115. Button buttonFAQ = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
  1116. buttonFAQ.setBackgroundColor(getResources().getColor(R.color.material_color_accent));
  1117. buttonFAQ.setTextColor(getResources().getColor(R.color.md_white_1000));
  1118. }
  1119.  
  1120. private void showDesignedByDialog() {
  1121. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  1122. builder.setTitle("Design & Copyright");
  1123. builder.setMessage("Copyright Sensible Mobile LLC 2016©\nDesigned with ♥ by Miki Mints\ngithub.com/mikimn/");
  1124. builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  1125. public void onClick(DialogInterface dialog, int which) {
  1126. dialog.dismiss();
  1127. }
  1128. });
  1129. builder.setNegativeButton("Visit Me!", new DialogInterface.OnClickListener() {
  1130. @Override
  1131. public void onClick(DialogInterface dialog, int which) {
  1132. dialog.dismiss();
  1133. Intent viewIntent = new Intent(Intent.ACTION_VIEW);
  1134. viewIntent.setData(Uri.parse("https://github.com/mikimn/"));
  1135. startActivity(viewIntent);
  1136. }
  1137. });
  1138.  
  1139. AlertDialog alert = builder.create();
  1140. alert.show();
  1141. Button buttonOk = alert.getButton(DialogInterface.BUTTON_POSITIVE);
  1142. buttonOk.setBackgroundColor(getResources().getColor(R.color.material_color_accent));
  1143. buttonOk.setTextColor(getResources().getColor(R.color.md_white_1000));
  1144.  
  1145. Button buttonFAQ = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
  1146. buttonFAQ.setBackgroundColor(getResources().getColor(R.color.material_color_accent));
  1147. buttonFAQ.setTextColor(getResources().getColor(R.color.md_white_1000));
  1148. }
  1149.  
  1150. // private void onUpdateProfile() {
  1151. // int response = 0;
  1152. // response = gd.emptyEditTextError(
  1153. // new EditText[] { userFirstNameEditText,userLastEditText},
  1154. // new String[] { "Enter first name", "Enter last name" });
  1155. //
  1156. // if (! GlobalData.isEmailValid(userPaypalEditText.getText().toString().trim())) {
  1157. // response++;
  1158. // userPaypalEditText.setError("Not an valid email");
  1159. // }
  1160. // if (response == 0) {
  1161. // String strFname = userFirstNameEditText.getText().toString().trim();
  1162. // String strLname = userLastEditText.getText().toString().trim();
  1163. // String strEmailID = userPaypalEditText.getText().toString().trim();
  1164. //
  1165. // String[] keys = {"user_id","first_name", "last_name", "paypal_account", "password" };
  1166. // String[] value = {
  1167. // PreferenceConnector.readString(aiContext, PreferenceConnector.USERID, ""),
  1168. // strFname,
  1169. // strLname,
  1170. // strEmailID,
  1171. // "",};
  1172. //
  1173. // HashMap<String, String> hash = new HashMap<String, String>();
  1174. // for (int i = 0; i < keys.length; i++) {
  1175. // System.out.println(keys[i] + "......." + value[i]);
  1176. // hash.put(keys[i], value[i]);
  1177. // }
  1178. // callWebService(GlobalVariables.UPDATE_PROFILE, hash);
  1179. // }
  1180. // }
  1181.  
  1182. /**
  1183. * Receiving push messages
  1184. * */
  1185. private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
  1186. @Override
  1187. public void onReceive(Context context, Intent intent) {
  1188.  
  1189.  
  1190. String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
  1191.  
  1192. // String type = intent.getExtras().getString("type");
  1193.  
  1194. String userpoints = intent.getExtras().getString("userpoints");
  1195. if(!userpoints.equals("0"))
  1196. {
  1197. //Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();
  1198. PreferenceConnector.writeInteger(aiContext, PreferenceConnector.WALLETPOINTS,
  1199. Integer.parseInt(userpoints));
  1200. FragEarnCredits.onUpdateView(aiContext);
  1201. ViewRewardsFragment.onUpdateView(aiContext);
  1202. InviteFriendsFragment.onUpdateView(aiContext);
  1203. ConnectSocialFragment.onUpdateView(aiContext);
  1204. }
  1205. }
  1206. };
  1207.  
  1208. @Override
  1209. protected void onDestroy() {
  1210.  
  1211. try {
  1212. unregisterReceiver(mHandleMessageReceiver);
  1213. GCMRegistrar.onDestroy(this);
  1214. } catch (Exception e) {
  1215. Log.e("UnRegister Error", "> " + e.getMessage());
  1216. }
  1217.  
  1218. OffersManager.getInstance(this).onAppExit();
  1219. super.onDestroy();
  1220. }
  1221. static void displayMessage(Context context, String message,String userpoints) {
  1222. Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
  1223. intent.putExtra(EXTRA_MESSAGE, message);
  1224. intent.putExtra("userpoints", userpoints);
  1225. context.sendBroadcast(intent);
  1226.  
  1227. }
  1228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement