Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21480 rajender 1
package com.saholic.profittill.main;
2
 
3
import android.app.Fragment;
4
import android.content.Context;
5
import android.content.Intent;
6
import android.content.SharedPreferences;
7
import android.content.pm.ActivityInfo;
8
import android.os.Bundle;
9
import android.support.v4.view.ViewPager;
10
import android.view.KeyEvent;
11
import android.view.LayoutInflater;
12
import android.view.View;
13
import android.view.ViewGroup;
14
import android.widget.Button;
15
import android.widget.TextView;
16
 
17
import com.google.android.gms.analytics.HitBuilders;
18
import com.google.android.gms.analytics.Tracker;
19
import com.saholic.profittill.R;
20
import com.saholic.profittill.Utils.CustomPageAdapter;
21
import com.viewpagerindicator.CirclePageIndicator;
22
 
23
 
24
public class HowItWorksFragment extends Fragment {
25
    SharedPreferences userData;
26
    SharedPreferences apiData;
27
    SharedPreferences.Editor userDataEditor;
28
    SharedPreferences.Editor apiSettingsEditor;
29
    CirclePageIndicator mIndicator;
30
    Button textDealsView;
31
    ViewPager vpPager;
32
    TextView skipHowItWorks;
33
 
34
    public HowItWorksFragment() {
35
 
36
    }
37
 
38
 
39
    @Override
40
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
41
                             Bundle savedInstanceState) {
42
        View rootView = inflater.inflate(R.layout.fragment_how_it_works, container, false);
43
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
44
        userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
45
        apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
46
        userDataEditor = userData.edit();
47
        apiSettingsEditor = apiData.edit();
48
        textDealsView = (Button)rootView.findViewById(R.id.howitwokstodeals);
49
        skipHowItWorks = (TextView)rootView.findViewById(R.id.skipHowItWorks);
50
        Tracker t = ((GoogleAnalyticsTracker) getActivity().getApplicationContext()).getTracker(
51
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
52
        t.setScreenName("Tutorials Screen");
53
        t.send(new HitBuilders.ScreenViewBuilder().build());
54
        /*final int[] flag = new int[] {R.drawable.mypreferencesnew,R.drawable.dealstutorial1, R.drawable.cashback,
55
                R.drawable.mypreferencestutorial, R.drawable.searchtutorial};*/
56
 
57
        final int[] flag = new int[] {R.drawable.deals_page,R.drawable.accessories_page,R.drawable.accessories_quick_buy, R.drawable.search_page, R.drawable.cashback_page,
58
                R.drawable.filter_page, R.drawable.preference};
59
 
60
        String[] rank = new String[] { "1", "2", "3", "4","5","6","7"};
61
        /*String[] openingText = new String[] { "First, Tell Us What You Like","We recommend, You profit","Get Cashback every time you shop", "Get deals that you are looking for", "Compare prices from all the big stores" };
62
        String[] middleText = new String[] { "Start by listing your favorite brands, your price range, & get better, targeted deals","We search the whole internet to find the best deals on mobiles and other products only for you", "Redeem your cashback every week. Get the money in your Saholic Wallet and use that on Mobile and DTH recharges.", "You can easily set up your preferences for the category, brand and price range that you are interested in", "You have a single screen to look at prices from Flipkart, Amazon, Snapdeal and more!"};*/
63
 
64
        String[] openingText = new String[] {"We recommend, You profit","Accessories at wholesale prices","Quick Buy","Compare prices from all the big stores","Get Cashback every time you shop", "Get deals that you are looking for", "Now, Tell Us What You Like" };
65
        String[] middleText = new String[] {"We search the whole internet to find the best deals on mobiles and other products only for you","Wide range. Easy returns","Buy multiple items together","You have a single screen to look at prices from Flipkart, Amazon, Snapdeal and more!", "Redeem your cashback every week. Get the money in your Saholic Wallet and use that on Mobile and DTH recharges.", "Simply use the filter tool to refine all deals by brand, price, popularity and our recommendations", "Start by listing your favorite brands, your price range, & get better, targeted deals"};
66
        vpPager = (ViewPager)rootView.findViewById(R.id.pager);
67
        CustomPageAdapter adapter = new CustomPageAdapter(getActivity(),rank,flag,openingText,middleText);
68
        vpPager.setAdapter(adapter);
69
        mIndicator = (CirclePageIndicator)rootView.findViewById(R.id.indicator);
70
        mIndicator.setViewPager(vpPager);
71
 
72
        final float density = getResources().getDisplayMetrics().density;
73
 
74
        mIndicator.setFillColor(getResources().getColor(R.color.White));
75
        mIndicator.setStrokeColor(getResources().getColor(R.color.Black));
76
        mIndicator.setStrokeWidth(1);
77
        mIndicator.setRadius(6 * density);
78
 
79
       vpPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
80
            @Override
81
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
82
 
83
            }
84
 
85
            @Override
86
            public void onPageSelected(int position) {
87
                /*mIndicator.setViewPager(vpPager);*/
88
                mIndicator.onPageScrolled(position,0,0);
89
                if(position==(flag.length-1)){
90
                    textDealsView.setVisibility(View.VISIBLE);
91
                    skipHowItWorks.setVisibility(View.GONE);
92
                }
93
                else{
94
                    textDealsView.setVisibility(View.GONE);
95
                    skipHowItWorks.setVisibility(View.VISIBLE);
96
                }
97
            }
98
 
99
            @Override
100
            public void onPageScrollStateChanged(int state) {
101
 
102
            }
103
        });
104
 
105
        skipHowItWorks.setOnClickListener(new View.OnClickListener() {
106
            @Override
107
            public void onClick(View v) {
108
                    userDataEditor.putString("preferences","true").commit();
109
                    PreferencesFragment my_preferences = new PreferencesFragment();
110
                    getActivity().getFragmentManager().beginTransaction()
111
                            .replace(R.id.frame_container, my_preferences, "Mike")
112
                            .addToBackStack(null)
113
                            .commit();
114
            }
115
        });
116
        textDealsView.setOnClickListener(new View.OnClickListener() {
117
            @Override
118
            public void onClick(View v) {
119
                    userDataEditor.putString("preferences","true").commit();
120
                    PreferencesFragment my_preferences = new PreferencesFragment();
121
                    getActivity().getFragmentManager().beginTransaction()
122
                            .replace(R.id.frame_container, my_preferences, "Mike")
123
                            .addToBackStack(null)
124
                            .commit();
125
 
126
            }
127
        });
128
 
129
        return rootView;
130
 
131
    }
132
    @Override
133
    public void onResume() {
134
        super.onResume();
135
        getView().setFocusableInTouchMode(true);
136
        getView().requestFocus();
137
        getView().setOnKeyListener(new View.OnKeyListener() {
138
            @Override
139
            public boolean onKey(View v, int keyCode, KeyEvent event) {
140
 
141
                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
142
                    Intent i = new Intent(getActivity(), MainActivity.class);
143
                    i.putExtra("displayView", "0");
144
                    startActivity(i);
145
                    return true;
146
                }
147
                return false;
148
            }
149
        });
150
    }
151
    @Override
152
    public void onViewCreated(View view, Bundle savedInstanceState) {
153
        super.onViewCreated(view, savedInstanceState);
154
    }
155
}