<repo_name>rohacompany/TestProject<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/custom/CountryInfo.java
package color.test.roha.com.colortestproject.custom;

import java.text.Collator;
import java.util.Locale;

class CountryInfo implements Comparable<CountryInfo> {
    private final Collator collator;
    public final Locale locale;
    public final int countryCode;

    public CountryInfo(Locale locale, int countryCode) {
        collator = Collator.getInstance(Locale.getDefault());
        collator.setStrength(Collator.PRIMARY);

        this.locale = locale;
        this.countryCode = countryCode;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final CountryInfo that = (CountryInfo) o;

        if (countryCode != that.countryCode) return false;
        return !(locale != null ? !locale.equals(that.locale) : that.locale != null);

    }

    @Override
    public int hashCode() {
        int result = locale != null ? locale.hashCode() : 0;
        result = 31 * result + countryCode;
        return result;
    }

    @Override
    public String toString() {
        return this.locale.getDisplayCountry() + "(+" + countryCode + ")";
    }

    @Override
    public int compareTo(CountryInfo info) {
        return collator.compare(this.locale.getDisplayCountry(), info.locale.getDisplayCountry());
    }
}<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/IntroActivity.java
package color.test.roha.com.colortestproject;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class IntroActivity extends AppCompatActivity implements View.OnClickListener{
    LinearLayout ll;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intro);

        ll = (LinearLayout) findViewById(R.id.activity_intro);


        Button btnColor1 = (Button) findViewById(R.id.color1);
        Button btnColor2 = (Button) findViewById(R.id.color2);
        Button btnColor3 = (Button) findViewById(R.id.color3);
        Button btnColor4 = (Button) findViewById(R.id.color4);

        btnColor1.setOnClickListener(this);
        btnColor2.setOnClickListener(this);
        btnColor3.setOnClickListener(this);
        btnColor4.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        int colorResdId = R.color.intro1;
        switch (v.getId()){
            case R.id.color1:
                colorResdId = R.color.intro1;
                break;
            case R.id.color2:
                colorResdId = R.color.intro2;
                break;
            case R.id.color3:
                colorResdId = R.color.intro3;
                break;
            case R.id.color4:
                colorResdId = R.color.intro4;
                break;
        }

        if(ll!=null){
            ll.setBackgroundColor(getResources().getColor(colorResdId));
        }
    }
}
<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/ProfileDialogActivity.java
package color.test.roha.com.colortestproject;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;

public class ProfileDialogActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        int screenWidth = (int) (metrics.widthPixels * 0.90);
        int screenHeight = (int) (metrics.heightPixels * 0.80);

        setContentView(R.layout.activity_profile_dialog);

        getWindow().setLayout(screenWidth, screenHeight); //set below the setContentvie

        setFinishOnTouchOutside(true);

    }
}
<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/URLManager.java
package color.test.roha.com.colortestproject;

/**
 * Created by dev on 2016-11-24.
 */

public class URLManager {
    public static String _MAIN_JSON_QUERY_HOST =
            "http://command.roha.co.kr/json/query.php";
    public static String _VERSION = "3.0";
}
<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/AuthPinConfirmActivity.java
package color.test.roha.com.colortestproject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.telephony.SmsMessage;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import com.google.gson.Gson;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import color.test.roha.com.colortestproject.datas.SMSAuthVO;

public class AuthPinConfirmActivity extends BaseActivity {
    CountDownTimer timer;
    int init_timer_value = 10000;
    String param_country_code,param_phone_number;
    public static final String CS_NUMBER = "07073538495";
    private SMSReceiver _receiver;
    SMSAuthVO _receivedVO;
    private String _received_auth_code = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auth_pin_confirm);

        aq = new AQuery(this);

        param_country_code = getIntent().getStringExtra("country_code");
        param_phone_number = getIntent().getStringExtra("phone_number");

        aq.id(R.id.phone_number).text( "+" + param_country_code + " " +  param_phone_number);

        setTimerText(3 , 0);
        startTimer();

        aq.id(R.id.timer).clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                requestSMS();
                startTimer();
            }
        });

        aq.id(R.id.btnSendAuthPinCode).clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                confirmVerification();
            }
        });

        registerReceiver();

        requestSMS();

        setupTop();
    }

    @Override
    public void setupTop() {
        super.setupTop();

        setTitle(R.string.activity_auth_2_name);
        setStep(2);
    }

    /**
     * REQUEST SMS
     */
    private void requestSMS(){
        HashMap<String,Object> paramMap = new HashMap<String,Object>();
        paramMap.put("version" , "3.0");
        paramMap.put("method" , "sms_auth");
        paramMap.put("rphone" , param_country_code +"-"+ param_phone_number);
        paramMap.put("alert" , "TW");

        aq.ajax(URLManager._MAIN_JSON_QUERY_HOST , paramMap , JSONObject.class , new AjaxCallback<JSONObject>(){
            @Override
            public void callback(String url, JSONObject object, AjaxStatus status) {
                Logger.log("object - > " + object);
                if(object!=null){
                    Gson gson = new Gson();
                    _receivedVO = gson.fromJson(object.toString() , SMSAuthVO.class);
                }
            }
        });
    }

    private void startTimer(){
        //타이머 설정
        timer = new CountDownTimer(init_timer_value, 1000) {
            @Override
            public void onFinish() {
                aq.id(R.id.timer).text(getText(R.string.re_send)).background(R.drawable.img_btn_bg_red);
            }

            @Override
            public void onTick(long millisUntilFinished) {

                long min = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished);
                long sec = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
                                TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished));


                Log.v("KTH", min + "," + sec);

                setTimerText(min , sec);

            }
        };
        timer.start();
    }

    private void setTimerText(long min , long sec){
        aq.id(R.id.timer).text(String.format(getString(R.string.auth_pine_code_timeout_format) , min , sec)).background(R.drawable.img_btn_bg_grey);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        finish();
        return super.onOptionsItemSelected(item);
    }

    private void registerReceiver() {
        unregisterReceiver();

        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(SMSReceiver.ACTION);

        _receiver = new SMSReceiver();
        registerReceiver(_receiver, intentFilter);
    }
    private void unregisterReceiver() {
        if(_receiver != null) {
            unregisterReceiver(_receiver);
            _receiver = null;
        }
    }

    public void confirmVerification(){
        String mPineCode = aq.id(R.id.pin_code).getText().toString();

        if(_receivedVO!=null){
            if(mPineCode.equalsIgnoreCase(_received_auth_code)
                    && mPineCode.equalsIgnoreCase(_receivedVO.getAuth_code())
                    ){
                Intent intent = new Intent(AuthPinConfirmActivity.this , ProfileMainActivity.class);
                startActivity(intent);
            }else{
                Toast.makeText(this , "인증코드가 일치하지 않습니다." , Toast.LENGTH_SHORT).show();
                aq.id(R.id.pin_code).text(null).getView().requestFocus();
            }
        }
    }


    private class SMSReceiver extends BroadcastReceiver {
        private static final String TAG="KTH";
        private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

        @Override
        public void onReceive(Context context, Intent intent) {
            // 문자만 수신받음
            Logger.log("receive intent!!");
            if(intent.getAction().equals(ACTION)) {
                final Bundle bundle = intent.getExtras();

                if(bundle == null)
                    return;

                final Object[] pdusObj = (Object[])bundle.get("pdus");
                if(pdusObj == null)
                    return;

                final SmsMessage[] smsMessages = new SmsMessage[pdusObj.length];

                for(int i=0; i<smsMessages.length; i++) {
                    smsMessages[i] = SmsMessage.createFromPdu((byte[])pdusObj[i]);

                    final String address = smsMessages[i].getOriginatingAddress();
                    final String message = smsMessages[i].getDisplayMessageBody();

                    if(address.equals(CS_NUMBER)) {
//                        String adjustMessage = message.replace("[Web발신]", "");
//                        int begin = adjustMessage.indexOf('[');
//                        int end = adjustMessage.indexOf(']');
//
//                        // 인증번호를 찾았다
//                        final String codeMessage = adjustMessage.substring(begin+1, end);

                        final String codeMessage = removeCharExceptNumber(message);

                        _received_auth_code = codeMessage;

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Logger.log("code -> " + codeMessage);
//                                _code.setText(codeMessage);
                                aq.id(R.id.pin_code).text(codeMessage);

                                mHandler.sendEmptyMessageDelayed( 1 , 1000);
                            }
                        });


                    }
                }
            }
        }

        private String removeCharExceptNumber(String str) {
            return str.replaceAll("[^0-9]", "");
        }
    }

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what == 1){
                confirmVerification();
            }
        }
    };

    @Override
    protected void onDestroy() {
        if(_receiver!=null)
            unregisterReceiver();

        super.onDestroy();
    }
}
<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/custom/CustomProfileImage.java
package color.test.roha.com.colortestproject.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import color.test.roha.com.colortestproject.R;

/**
 * Created by dev on 2016-11-25.
 */

public class CustomProfileImage extends RelativeLayout{

    public CustomProfileImage(Context context) {
        super(context);
        init();
    }

    public CustomProfileImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomProfileImage(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){


        setBackgroundResource(R.drawable.img_profile_center);
    }
}
<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/AuthMainActivity.java
package color.test.roha.com.colortestproject;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.text.util.Linkify;
import android.util.Log;
import android.view.View;
import android.widget.TextView;


import com.androidquery.AQuery;
import com.digits.sdk.android.models.PhoneNumber;

import java.util.Locale;
import java.util.regex.Pattern;

import color.test.roha.com.colortestproject.custom.CountryListSpinner;

import static color.test.roha.com.colortestproject.MainActivity._PERMISSION_REQUEST_CODE;

public class AuthMainActivity extends BaseActivity {
    TextView tvLinkify;
    CountryListSpinner countryListSpinner;

    // Note: Your consumer key and secret should be obfuscated in your source code before shipping.
    private static final String TWITTER_KEY = "kc1Das6xy7btT2jyqCg5alErx";
    private static final String TWITTER_SECRET = "<KEY>";
    boolean isTestMode = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auth_main);
        aq = new AQuery(this);

        tvLinkify = (TextView)findViewById(R.id.aggrement);
        countryListSpinner = (CountryListSpinner)findViewById(R.id.dgts__countryCode);

        checkPermission();

        setupTop();
    }

    @Override
    public void setupTop() {
        super.setupTop();

        setTitle(R.string.activity_auth_1_name);
        aq.id(R.id.ibtn_common_back).gone();
    }

    private void setLinkfy(){
        String text = getString(R.string.auth_phone_1);
        tvLinkify.setText(text);

        Pattern pattern1 = Pattern.compile("이용약관");
        Pattern pattern2 = Pattern.compile("개인 정보 취급 방침");


        Linkify.addLinks(tvLinkify, pattern1, "agreement1://");
        Linkify.addLinks(tvLinkify, pattern2, "agreement2://");

    }

    public void checkPermission(){
        int permissionCheck1 = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);
        int permissionCheck2 = ActivityCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS);
        int permissionCheck3 = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        int permissionCheck4 = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);

        if(permissionCheck1 == PackageManager.PERMISSION_DENIED
                || permissionCheck2 == PackageManager.PERMISSION_DENIED
                || permissionCheck3 == PackageManager.PERMISSION_DENIED
                || permissionCheck4 == PackageManager.PERMISSION_DENIED
                ){
            ActivityCompat.requestPermissions(this , new String[]{
                    Manifest.permission.RECEIVE_SMS,
                    Manifest.permission.READ_PHONE_STATE,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE} ,

                    _PERMISSION_REQUEST_CODE);
        }else{
            setup();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

        setup();
    }

    public void setup(){

        setLinkfy();

        final PhoneNumber validPhoneNumber = new PhoneNumber("01064292256", "KR", "82");
        final CountryListSpinner countryListSpinner = (CountryListSpinner) findViewById(R.id.dgts__countryCode);
        countryListSpinner.setSelectedForCountry(new Locale("",
                        validPhoneNumber.getCountryIso()),
                validPhoneNumber.getCountryCode());

        aq.id(R.id.btnSendAuthPinCode).clicked(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                String country_code = countryListSpinner.getSelectedCountCode() + "";
                String phone_number = aq.id(R.id.phone_number).getText().toString();

                Log.d("KTH" , country_code + "," + phone_number);

                if(isTestMode){
                    Intent intent = new Intent(AuthMainActivity.this, ProfileMainActivity.class);
                    startActivity(intent);
                }else {
                    Intent intent = new Intent(AuthMainActivity.this, AuthPinConfirmActivity.class);
                    intent.putExtra("country_code", country_code);
                    intent.putExtra("phone_number", phone_number);
                    startActivity(intent);
                }
            }
        });

        aq.id(R.id.phone_number).text(getMyPhoneNumber());

    }

    private String getMyPhoneNumber(){
        TelephonyManager mTelephonyMgr;
        mTelephonyMgr = (TelephonyManager)
                getSystemService(Context.TELEPHONY_SERVICE);
        String phoneNumber = mTelephonyMgr.getLine1Number();
        if(phoneNumber.startsWith("82")){
            phoneNumber.replace("82","0");
        }else if(phoneNumber.startsWith("+82")){
            phoneNumber.replace("+82","0");
        }
        return phoneNumber;
    }

    private String getMy10DigitPhoneNumber(String phoneNumber){
        String s = phoneNumber;
        return s.substring(2);
    }


}
<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/custom/CountryListAdapter.java
package color.test.roha.com.colortestproject.custom;

import android.content.Context;
import android.graphics.Movie;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;

import color.test.roha.com.colortestproject.R;

import static android.R.attr.data;

class CountryListAdapter extends ArrayAdapter<CountryInfo> implements SectionIndexer {
    final private HashMap<String, Integer> alphaIndex = new LinkedHashMap<>();
    final private HashMap<String, Integer> countryPosition = new LinkedHashMap<>();
    private String[] sections;
    Context ctx;

    public CountryListAdapter(Context context) {
        super(context, R.layout.view_spinner_auth_phone_number, android.R.id.text1);
        this.ctx = context;
    }

    // The list of countries should be sorted using locale-sensitive string comparison
    public void setData(List<CountryInfo> countries) {
        // Create index and add entries to adapter
        int index = 0;
        for (CountryInfo countryInfo : countries) {
            final String key = countryInfo.locale.getDisplayCountry().substring(0, 1)
                    .toUpperCase(Locale.getDefault());

            if (!alphaIndex.containsKey(key)) {
                alphaIndex.put(key, index);
            }
            countryPosition.put(countryInfo.locale.getDisplayCountry(), index);

            index++;
            add(countryInfo);
        }

        sections = new String[alphaIndex.size()];
        alphaIndex.keySet().toArray(sections);

        notifyDataSetChanged();
    }

    @Override
    public Object[] getSections() {
        return sections;
    }

    @Override
    public int getPositionForSection(int index) {
        if (sections == null) {
            return 0;
        }

        // Check index bounds
        if (index <= 0) {
            return 0;
        }
        if (index >= sections.length) {
            index = sections.length - 1;
        }

        // Return the position
        return alphaIndex.get(sections[index]);
    }

    @Override
    public int getSectionForPosition(int position) {
        return 0;
    }

    public int getPositionForCountry(String country) {
        final Integer position = countryPosition.get(country);
        return position == null ? 0 : position;
    }

//    @Override
//    public View getView(int position, View convertView, ViewGroup parent){
//
//        if(convertView==null){
//            //inflate the layout
//            LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//            convertView = inflater.inflate(R.layout.view_spinner_auth_phone_number, parent, false);
//        }
//
//
//        CountryInfo info = getItem(position);
//        //movie item based on the position
//
//        //get the TextView and then set the text(movie name) and tag(show_Movie.i) values
//        TextView textViewItem = (TextView)convertView.findViewById(android.R.id.text1);
//        textViewItem.setText(info.countryCode);
//
//
//        return convertView;
//
//
//    }
}<file_sep>/app/src/main/java/color/test/roha/com/colortestproject/custom/CustomDigits.java
package color.test.roha.com.colortestproject.custom;

import com.digits.sdk.android.Digits;
import com.digits.sdk.android.DigitsEventLogger;

import java.util.concurrent.ExecutorService;

import io.fabric.sdk.android.Fabric;

/**
 * Created by dev on 2016-11-22.
 */

public class CustomDigits extends Digits{

    protected CustomDigits(int themeResId, DigitsEventLogger externalLogger) {
        super(themeResId, externalLogger);
    }

    public static CustomDigits getInstance() {
        return (CustomDigits) Fabric.getKit(Digits.class);
    }

    @Override
    protected ExecutorService getExecutorService() {
        return super.getExecutorService();
    }
}
