Android proqramda ardıcıllıq

Mənim əlimdə proqram var və qeydiyyat tələb edir.
Üç aşama var
1. Qeydiyyatlı deyilsə qeydiyyat pəncərəsi açılır
2. Nömrəsini daxil edir
3. Sonra nömrəyə mesaj gəlir təsdiq edir

Buna görə istəyirəm nömrəni yazsın bazaya əlavə olunsun amma aktivetmə nömrəsi gəlməsin ikinci aşamada sona yetsin main səhifəsi açılsın.


Yadda saxlama
Kateqoriya: Sual . , . Qısa keçid.

Verilmiş cavablar və yazılan şərhlər (1 cavab var)

(17:12, 29/11/2016 ) #66194

Açılış ekranı budur

1package com.emgroup.whatssms.activities.main;
2 
3import android.Manifest;
4import android.accounts.Account;
5import android.accounts.AccountAuthenticatorActivity;
6import android.accounts.AccountManager;
7import android.annotation.TargetApi;
8import android.content.Context;
9import android.content.Intent;
10import android.os.Build;
11import android.os.Bundle;
12import android.os.CountDownTimer;
13import android.os.Handler;
14import android.support.design.widget.FloatingActionButton;
15import android.support.design.widget.TextInputEditText;
16import android.support.v4.view.PagerAdapter;
17import android.support.v4.view.ViewPager;
18import android.support.v7.widget.LinearLayoutManager;
19import android.support.v7.widget.RecyclerView;
20import android.text.Editable;
21import android.view.View;
22import android.view.inputmethod.InputMethodManager;
23import android.widget.ImageView;
24import android.widget.LinearLayout;
25import android.widget.ProgressBar;
26import android.widget.TextView;
27 
28import com.google.gson.Gson;
29import com.google.gson.reflect.TypeToken;
30import com.google.i18n.phonenumbers.NumberParseException;
31import com.google.i18n.phonenumbers.PhoneNumberUtil;
32import com.google.i18n.phonenumbers.Phonenumber;
33import com.emgroup.whatssms.R;
34import com.emgroup.whatssms.adapters.recyclerView.CountriesAdapter;
35import com.emgroup.whatssms.adapters.recyclerView.TextWatcherAdapter;
36import com.emgroup.whatssms.api.APIAuthentication;
37import com.emgroup.whatssms.api.APIService;
38import com.emgroup.whatssms.app.EndPoints;
39import com.emgroup.whatssms.app.WhatsCloneApplication;
40import com.emgroup.whatssms.helpers.AppHelper;
41import com.emgroup.whatssms.helpers.PreferenceManager;
42import com.emgroup.whatssms.helpers.SignUpPreferenceManager;
43import com.emgroup.whatssms.models.CountriesModel;
44import com.emgroup.whatssms.models.JoinModel;
45import com.emgroup.whatssms.models.users.Pusher;
46import com.emgroup.whatssms.services.SMSVerificationService;
47import com.emgroup.whatssms.sync.AuthenticatorService;
48 
49import java.util.ArrayList;
50import java.util.List;
51 
52import butterknife.Bind;
53import butterknife.ButterKnife;
54import de.greenrobot.event.EventBus;
55import retrofit2.Call;
56import retrofit2.Callback;
57import retrofit2.Response;
58 
59/**
60 * Created by Abderrahim El imame on 09/02/2016.
61 * Email : abderrahim.elimame@gmail.com
62 */
63public class WelcomeActivity extends AccountAuthenticatorActivity implements View.OnClickListener {
64    @Bind(R.id.numberPhone)
65    TextInputEditText phoneNumberWrapper;
66    @Bind(R.id.inputOtpWrapper)
67    TextInputEditText inputOtpWrapper;
68    @Bind(R.id.btn_request_sms)
69    FloatingActionButton btnNext;
70    @Bind(R.id.btn_verify_otp)
71    TextView btnVerifyOtp;
72    @Bind(R.id.viewPagerVertical)
73    ViewPager viewPager;
74    @Bind(R.id.TimeCount)
75    TextView textViewShowTime;
76    @Bind(R.id.Resend)
77    TextView Resend;
78    @Bind(R.id.progressbar)
79    ProgressBar mProgressBar;
80    @Bind(R.id.code)
81    TextView code;
82    @Bind(R.id.btn_change_number)
83    TextView EditBtn;
84    @Bind(R.id.toolbar)
85    LinearLayout toolbar;
86    @Bind(R.id.CounrtriesList)
87    RecyclerView CountriesList;
88    @Bind(R.id.txtEditMobile)
89    TextView txtEditMobile;
90    @Bind(R.id.search_input)
91    TextInputEditText searchInput;
92    @Bind(R.id.clear_btn_search_view)
93    ImageView clearBtn;
94 
95 
96    private CountriesAdapter mCountriesAdapter;
97    private String Code;
98    private String Country;
99    private CountDownTimer countDownTimer;
100    private long totalTimeCountInMilliseconds;
101    private long seconds, ResumeSeconds;
102    private ViewPagerAdapter adapter;
103    private SignUpPreferenceManager mSignUpPreferenceManager;
104    public static final String PARAM_AUTH_TOKEN_TYPE = "auth.token";
105 
106    @Override
107    protected void onCreate(Bundle savedInstanceState) {
108        super.onCreate(savedInstanceState);
109        setContentView(R.layout.activity_welcome);
110        ButterKnife.bind(this);
111        EventBus.getDefault().register(this);
112        initializerView();
113    }
114 
115    /**
116     * method to initialize the view
117     */
118    private void initializerView() {
119        /**
120         * Checking if user already connected
121         */
122        if (PreferenceManager.getToken(this) != null) {
123            Intent intent = new Intent(this, MainActivity.class);
124            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
125            startActivity(intent);
126            finish();
127 
128        }
129 
130        initializerSearchView(searchInput, clearBtn);
131        clearBtn.setOnClickListener(v -> clearSearchView());
132        LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(WhatsCloneApplication.getAppContext());
133        CountriesList.setLayoutManager(mLinearLayoutManager);
134        mCountriesAdapter = new CountriesAdapter(this);
135        CountriesList.setAdapter(mCountriesAdapter);
136        Gson gson = new Gson();
137        final List list = gson.fromJson(AppHelper.loadJSONFromAsset(this), new TypeToken<List>() {
138        }.getType());
139        mCountriesAdapter.setCountries(list);
140        Code = "" + list.get(1).getDial_code();
141        Country = "" + list.get(1).getName();
142        code.setText(Code);
143        toolbar.setBackgroundColor(AppHelper.getColor(this, R.color.colorPrimary));
144        btnNext.setOnClickListener(this);
145        btnVerifyOtp.setOnClickListener(this);
146        Resend.setOnClickListener(this);
147        EditBtn.setOnClickListener(this);
148        mSignUpPreferenceManager = new SignUpPreferenceManager(this);
149        adapter = new ViewPagerAdapter();
150        viewPager.setAdapter(adapter);
151 
152        /**
153         * Checking if the device is waiting for sms
154         * showing the user OTP screen
155         */
156        if (mSignUpPreferenceManager.isWaitingForSms()) {
157            viewPager.setCurrentItem(1);
158            resumeTimer();
159        }
160 
161        if (viewPager.getCurrentItem() == 1) {
162 
163            if (AppHelper.checkPermission(this, Manifest.permission.RECEIVE_SMS)) {
164                AppHelper.LogCat("RECEIVE SMS permission already granted.");
165            } else {
166                AppHelper.LogCat("Please request RECEIVE SMS permission.");
167                AppHelper.requestPermission(this, Manifest.permission.RECEIVE_SMS);
168            }
169            if (AppHelper.checkPermission(this, Manifest.permission.READ_SMS)) {
170                AppHelper.LogCat("READ SMS permission already granted.");
171            } else {
172                AppHelper.LogCat("Please request READ SMS permission.");
173                AppHelper.requestPermission(this, Manifest.permission.READ_SMS);
174            }
175 
176        }
177 
178 
179    }
180 
181    /**
182     * method to clear/reset search view content
183     */
184    public void clearSearchView() {
185        if (searchInput.getText() != null) {
186            searchInput.setText("");
187            Gson gson = new Gson();
188            final List list = gson.fromJson(AppHelper.loadJSONFromAsset(this), new TypeToken<List>() {
189            }.getType());
190            mCountriesAdapter.setCountries(list);
191        }
192 
193    }
194 
195    /**
196     * method to initial the search view
197     */
198    public void initializerSearchView(TextInputEditText searchInput, ImageView clearSearchBtn) {
199 
200        final Context context = this;
201        searchInput.setOnFocusChangeListener((v, hasFocus) -> {
202            if (!hasFocus) {
203                InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
204                inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
205            }
206 
207        });
208        searchInput.addTextChangedListener(new TextWatcherAdapter() {
209            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
210            @Override
211            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
212                clearSearchBtn.setVisibility(View.GONE);
213            }
214 
215            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
216            @Override
217            public void onTextChanged(CharSequence s, int start, int before, int count) {
218                mCountriesAdapter.setString(s.toString());
219                Search(s.toString().trim());
220                clearSearchBtn.setVisibility(View.VISIBLE);
221            }
222 
223            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
224            @Override
225            public void afterTextChanged(Editable s) {
226 
227                if (s.length() == 0) {
228                    clearSearchBtn.setVisibility(View.GONE);
229                    Gson gson = new Gson();
230                    final List list = gson.fromJson(AppHelper.loadJSONFromAsset(WelcomeActivity.this), new TypeToken<List>() {
231                    }.getType());
232                    mCountriesAdapter.setCountries(list);
233                }
234            }
235        });
236 
237    }
238 
239    /**
240     * method to start searching
241     *
242     * @param string this is parameter of Search method
243     */
244    public void Search(String string) {
245 
246        final List filteredModelList;
247        filteredModelList = FilterList(string);
248        if (filteredModelList.size() != 0) {
249            mCountriesAdapter.animateTo(filteredModelList);
250            CountriesList.scrollToPosition(0);
251        }
252    }
253 
254    /**
255     * method to filter the list
256     *
257     * @param query this is parameter of FilterList method
258     * @return this for what method return
259     */
260    private List FilterList(String query) {
261        query = query.toLowerCase();
262        List countriesModelList = mCountriesAdapter.getCountries();
263        final List filteredModelList = new ArrayList();
264        for (CountriesModel countriesModel : countriesModelList) {
265            final String name = countriesModel.getName().toLowerCase();
266            if (name.contains(query)) {
267                filteredModelList.add(countriesModel);
268            }
269        }
270        return filteredModelList;
271    }
272 
273    /**
274     * method to validate user information
275     */
276    private void validateInformation() {
277        String mobile = null;
278        try {
279            mobile = phoneNumberWrapper.getText().toString().trim();
280        } catch (Exception e) {
281            AppHelper.LogCat(" number mobile is null Exception WelcomeActivity " + e.getMessage());
282        }
283        if (mobile != null) {
284            PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
285            Phonenumber.PhoneNumber phNumberProto = null;
286            Code = Code.replace("+", "");
287            String countryCode = phoneUtil.getRegionCodeForCountryCode(Integer.parseInt(Code));
288            try {
289                phNumberProto = phoneUtil.parse(mobile, countryCode);
290            } catch (NumberParseException e) {
291                e.printStackTrace();
292                AppHelper.LogCat("number  error  NumberParseException  WelcomeActivity" + mobile);
293                phoneNumberWrapper.setError(getString(R.string.enter_a_val_number));
294            }
295            if (phNumberProto != null) {
296                boolean isValid = phoneUtil.isValidNumber(phNumberProto);
297                if (isValid) {
298                    String internationalFormat = phoneUtil.format(phNumberProto, PhoneNumberUtil.PhoneNumberFormat.E164);
299                    mSignUpPreferenceManager.setMobileNumber(internationalFormat);
300                    requestForSMS(internationalFormat, Country);
301                } else {
302                    phoneNumberWrapper.setError(getString(R.string.enter_a_val_number));
303                }
304            }
305        } else {
306            phoneNumberWrapper.setError(getString(R.string.enter_a_val_number));
307        }
308    }
309 
310    /**
311     * method to resend a request for SMS
312     *
313     * @param mobile this is parameter of ResendRequestForSMS method
314     */
315    private void ResendRequestForSMS(String mobile) {
316 
317        APIAuthentication mAPIAuthentication = APIService.RootService(APIAuthentication.class, EndPoints.BASE_URL);
318        Call ResendModelCall = mAPIAuthentication.resend(mobile);
319        ResendModelCall.enqueue(new Callback() {
320            @Override
321            public void onResponse(Call call, Response response) {
322                if (response.isSuccessful()) {
323                    if (response.body().isSuccess()) {
324                        Resend.setVisibility(View.GONE);
325                        mProgressBar.setVisibility(View.VISIBLE);
326                        textViewShowTime.setVisibility(View.VISIBLE);
327                        setTimer();
328                        startTimer();
329                        mSignUpPreferenceManager.setIsWaitingForSms(true);
330                        viewPager.setCurrentItem(1);
331                        txtEditMobile.setText(mSignUpPreferenceManager.getMobileNumber());
332                    } else {
333                        AppHelper.CustomToast(WelcomeActivity.this, response.body().getMessage());
334                    }
335                } else {
336                    AppHelper.CustomToast(WelcomeActivity.this, response.message());
337                }
338            }
339 
340            @Override
341            public void onFailure(Call call, Throwable t) {
342                AppHelper.CustomToast(WelcomeActivity.this, t.getMessage());
343            }
344        });
345    }
346 
347    /**
348     * method to send an SMS request to provider
349     *
350     * @param mobile  this the first parameter of  requestForSMS method
351     * @param country this the second parameter of requestForSMS  method
352     */
353    private void requestForSMS(String mobile, String country) {
354        APIAuthentication mAPIAuthentication = APIService.RootService(APIAuthentication.class, EndPoints.BASE_URL);
355        Call JoinModelCall = mAPIAuthentication.join(mobile, country);
356        AppHelper.showDialog(this, getString(R.string.set_back_and_keep_calm_you_will_receive_an_sms_of_verification));
357        JoinModelCall.enqueue(new Callback() {
358            @Override
359            public void onResponse(Call call, Response response) {
360                if (response.isSuccessful()) {
361                    if (response.body().isSuccess()) {
362                        AppHelper.hideDialog();
363                        setTimer();
364                        startTimer();
365                        mSignUpPreferenceManager.setIsWaitingForSms(true);
366                        viewPager.setCurrentItem(1);
367                        txtEditMobile.setText(mSignUpPreferenceManager.getMobileNumber());
368                        String accountType = getIntent().getStringExtra(PARAM_AUTH_TOKEN_TYPE);
369                        if (accountType == null) {
370                            accountType = AuthenticatorService.ACCOUNT_TYPE;
371                        }
372                        AccountManager accMgr = AccountManager.get(WelcomeActivity.this);
373                        // This is the magic that add the account to the Android Account Manager
374                        final Account account = new Account(getResources().getString(R.string.app_name), accountType);
375                        accMgr.addAccountExplicitly(account, response.body().getCode(), null);
376                        // Now we tell our caller, could be the Android Account Manager or even our own application
377                        // that the process was successful
378                        final Intent intent = new Intent();
379                        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, getResources().getString(R.string.app_name));
380                        intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
381                        intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType);
382                        setAccountAuthenticatorResult(intent.getExtras());
383                        setResult(RESULT_OK, intent);
384                        AppHelper.LogCat("Failed here 0 " + response.body().getMessage());
385                        new Handler().postDelayed(() -> testRun(response.body().getCode()), 4000);
386                    } else {
387                        AppHelper.hideDialog();
388                        AppHelper.CustomToast(WelcomeActivity.this, response.body().getMessage());
389                        AppHelper.LogCat("Failed here 1 " + response.body().getMessage());
390                    }
391                } else {
392                    AppHelper.hideDialog();
393                    AppHelper.CustomToast(WelcomeActivity.this, response.message());
394                    AppHelper.LogCat("Failed here 2 " + response.message());
395                }
396            }
397 
398            @Override
399            public void onFailure(Call call, Throwable t) {
400                AppHelper.hideDialog();
401                AppHelper.LogCat("Failed to create your account " + t.getMessage());
402                AppHelper.CustomToast(WelcomeActivity.this, "Please your internet connection and try again");
403                //Hide the Keyboard
404                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
405                imm.hideSoftInputFromWindow(phoneNumberWrapper.getWindowToken(), 0);
406            }
407        });
408 
409    }
410 
411    private void  testRun(String  code){
412        if (!code.isEmpty()) {
413            Intent otpIntent = new Intent(getApplicationContext(), SMSVerificationService.class);
414            otpIntent.putExtra("code", code);
415            startService(otpIntent);
416        } else {
417            AppHelper.CustomToast(this, getString(R.string.please_enter_your_ver_code));
418        }
419    }
420 
421    /**
422     * method to verify the code received by user then activating the user
423     */
424    private void verificationOfCode() {
425        String code = inputOtpWrapper.getText().toString().trim();
426        if (!code.isEmpty()) {
427            Intent otpIntent = new Intent(getApplicationContext(), SMSVerificationService.class);
428            otpIntent.putExtra("code", code);
429            startService(otpIntent);
430        } else {
431            AppHelper.CustomToast(this, getString(R.string.please_enter_your_ver_code));
432        }
433    }
434 
435 
436    @Override
437    public void onClick(View view) {
438        switch (view.getId()) {
439            case R.id.btn_request_sms:
440                validateInformation();
441                break;
442 
443            case R.id.btn_verify_otp:
444                verificationOfCode();
445                break;
446 
447            case R.id.btn_change_number:
448                viewPager.setCurrentItem(0);
449                stopTimer();
450                PreferenceManager.setID(0, this);
451                PreferenceManager.setToken(null, this);
452                mSignUpPreferenceManager.setIsWaitingForSms(false);
453                break;
454 
455            case R.id.Resend:
456                viewPager.setCurrentItem(1);
457                ResendRequestForSMS(mSignUpPreferenceManager.getMobileNumber());
458                break;
459        }
460    }
461 
462    class ViewPagerAdapter extends PagerAdapter {
463 
464        @Override
465        public int getCount() {
466            return 2;
467        }
468 
469        @Override
470        public boolean isViewFromObject(View view, Object object) {
471            return view == ((View) object);
472        }
473 
474        public Object instantiateItem(View collection, int position) {
475 
476            int resId = 0;
477            switch (position) {
478                case 0:
479                    resId = R.id.numberPhone_layout;
480                    break;
481                case 1:
482                    resId = R.id.layout_verification;
483                    break;
484            }
485            return findViewById(resId);
486        }
487    }
488 
489    private void setTimer() {
490        int time = 4;
491        mProgressBar.setMax(60 * time);
492        totalTimeCountInMilliseconds = 60 * time * 1000;
493 
494    }
495 
496    private void startTimer() {
497        countDownTimer = new WhatsCloneCounter(totalTimeCountInMilliseconds, 500).start();
498    }
499 
500    public void stopTimer() {
501        if (countDownTimer != null) {
502            countDownTimer.cancel();
503        }
504    }
505 
506    public void resumeTimer() {
507        countDownTimer = new WhatsCloneCounter(ResumeSeconds, 500).start();
508    }
509 
510 
511    public class WhatsCloneCounter extends CountDownTimer {
512        public WhatsCloneCounter(long millisInFuture, long countDownInterval) {
513            super(millisInFuture, countDownInterval);
514        }
515 
516        @Override
517        public void onTick(long leftTimeInMilliseconds) {
518            ResumeSeconds = leftTimeInMilliseconds;
519            seconds = leftTimeInMilliseconds / 1000;
520            mProgressBar.setProgress((int) (leftTimeInMilliseconds / 1000));
521            textViewShowTime.setText(String.format("%02d", seconds / 60) + ":" + String.format("%02d", seconds % 60));
522        }
523 
524        @Override
525        public void onFinish() {
526            textViewShowTime.setVisibility(View.GONE);
527            mProgressBar.setVisibility(View.GONE);
528            Resend.setVisibility(View.VISIBLE);
529        }
530    }
531 
532    @Override
533    protected void onDestroy() {
534        super.onDestroy();
535        EventBus.getDefault().unregister(this);
536    }
537 
538    /**
539     * method of EventBus
540     *
541     * @param pusher this is parameter of onEventMainThread method
542     */
543    @SuppressWarnings("unused")
544    public void onEventMainThread(Pusher pusher) {
545        switch (pusher.getAction()) {
546            case "countryCode":
547                Code = "" + pusher.getData();
548                code.setText(Code);
549                break;
550            case "countryName":
551                Country = "" + pusher.getData();
552                break;
553        }
554    }
555 
556}
Cavablamaq üçün sağ sütundan hesaba daxil olmaq lazımdır

Bu suala aid öz sualım var:
Sual verin
Bu suala cavab vermək istəyirəm:
Cavab verin

Cavab verin


Cavab yazmaq üçün lütfən sağ sütundan və ya buradan hesaba daxil olun.

Üzvlər üçün giriş

Qeydiyyat
Login with Facebook

Elan qutusu

Son cavablar və şərhlər

Software Developer cavab verdi - ilkaddimlar.com-a nə oldu? (6 gün əvvəl)

E. Hacı cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (16 gün əvvəl)

Triste cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (17 gün əvvəl)

E. Hacı cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (17 gün əvvəl)

Triste cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (18 gün əvvəl)

E. Hacı cavab verdi - Telefon almışam kamerasında ləkə var qaytarmaq istəyirəm, mağaza qaytarmır (18 gün əvvəl)

Software Developer cavab verdi - Rus dili yatırımı (18 gün əvvəl)

Cənab cavab verdi - Rus dili yatırımı (18 gün əvvəl)

Software Developer cavab verdi - Rus dili yatırımı (19 gün əvvəl)

Cənab cavab verdi - Rus dili yatırımı (19 gün əvvəl)

Software Developer cavab verdi - Rus dili yatırımı (19 gün əvvəl)

Azad cavab verdi - Windows 11 FPS drop (32 gün əvvəl)

AGAPROGRAMM cavab verdi - Kompyuterimin çox gec yanmasının səbəbləri nədir ? Necə düzəldərəm ? (35 gün əvvəl)

Ayaz2550 cavab verdi - 1ci qrupda informatika üzre imtahan vermek (36 gün əvvəl)

Ayaz2550 cavab verdi - Windows 11 FPS drop (36 gün əvvəl)

Software Developer - 615 xal

E. Hacı - 608 xal

Onar Alili - 526 xal

Dilsuz - 448 xal

Cabbarov Sübhan - 434 xal

Maqa - 346 xal

Ruslan Butdayev - 328 xal

Namiq Bəndəli - 297 xal

U.Tarlan - 244 xal

Meherremoff - 234 xal

Sistemə daxil olmuş 23307 sualdan 92%-dən çoxu cavablandırılmışdır.

Proyekt haqqında

E-Haci.net istehsalı. © 2010-2025