diff --git a/app/build.gradle b/app/build.gradle index 8a0ca3f..bc8e771 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,18 +25,11 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.+' - compile 'com.google.android.gms:play-services-maps:10.0.1' - compile 'com.google.android.gms:play-services:10.0.1' compile 'com.google.firebase:firebase-core:10.0.1' compile 'com.google.firebase:firebase-messaging:10.0.1' compile 'com.android.support:design:24.0.0' - compile 'com.synnapps:carouselview:0.0.10' compile 'com.android.support:cardview-v7:24.2.1' compile 'com.android.support:recyclerview-v7:24.2.1' compile 'com.squareup:otto:1.3.7' - compile 'com.squareup.okhttp3:okhttp:3.2.0' - compile 'noman.placesapi:placesAPI:1.1.3' testCompile 'junit:junit:4.12' } - -apply plugin: 'com.google.gms.google-services' diff --git a/app/libs/aws-android-sdk-apigateway-core-0.0.1.jar b/app/libs/aws-android-sdk-apigateway-core-0.0.1.jar index ae09b8b..d1df5c5 100644 Binary files a/app/libs/aws-android-sdk-apigateway-core-0.0.1.jar and b/app/libs/aws-android-sdk-apigateway-core-0.0.1.jar differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e8dc0c1..f8e9e94 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,11 +2,8 @@ - - - - - - - @@ -36,34 +25,40 @@ + + + diff --git a/app/src/main/java/net/bluehack/kiosk/ApplicationLoader.java b/app/src/main/java/net/bluehack/kiosk/ApplicationLoader.java index fa0fda6..bbeb475 100644 --- a/app/src/main/java/net/bluehack/kiosk/ApplicationLoader.java +++ b/app/src/main/java/net/bluehack/kiosk/ApplicationLoader.java @@ -3,20 +3,21 @@ import android.app.Application; import android.content.Context; +import net.bluehack.kiosk.util.KioskPreference; + import static net.bluehack.kiosk.util.Logger.makeLogTag; public class ApplicationLoader extends Application { private static String TAG = makeLogTag(ApplicationLoader.class); - private static Context instance; + private static volatile Context instance; @Override public void onCreate() { super.onCreate(); - instance = this; - - + instance = getApplicationContext(); + KioskPreference.getInstance().init(instance); } public static Context getContext() { diff --git a/app/src/main/java/net/bluehack/kiosk/api/ApiClient.java b/app/src/main/java/net/bluehack/kiosk/api/ApiClient.java index cc4da7a..878f831 100644 --- a/app/src/main/java/net/bluehack/kiosk/api/ApiClient.java +++ b/app/src/main/java/net/bluehack/kiosk/api/ApiClient.java @@ -2,12 +2,18 @@ import android.os.AsyncTask; import android.util.Log; +import android.view.Menu; +import android.widget.Toast; import com.amazonaws.mobileconnectors.apigateway.ApiClientFactory; +import net.bluehack.kiosk.ApplicationLoader; import net.bluehack.kiosk.KioskAPIClient; -import net.bluehack.kiosk.model.Menu; +import net.bluehack.kiosk.api.net.NetworkManager; +import net.bluehack.kiosk.model.LoginReq; +import net.bluehack.kiosk.model.LoginRes; +import static net.bluehack.kiosk.util.Logger.LOGD; import static net.bluehack.kiosk.util.Logger.makeLogTag; public class ApiClient { @@ -15,6 +21,7 @@ public class ApiClient { private static ApiClient ourInstance = new ApiClient(); private final ApiClientFactory factory; private final KioskAPIClient client; + private final static String headerToken = "temp"; public static ApiClient getInstance() { return ourInstance; @@ -33,7 +40,23 @@ public KioskAPIClient getClient() { return client; } - public void menuGet(final String query, final ApiResponseListener listener) { + public void usersLoginPost(final LoginReq loginReq, final ApiResponseListener listener) { + new AsyncTask() { + @Override + protected Void doInBackground(Void... params) { + + LoginRes output = null; + output = client.usersLoginPost(headerToken, loginReq); + LOGD("usersLoginPost:", String.valueOf(output.getResponseStatus())); + + listener.onResponse(output); + return null; + } + + }.execute(); + } + + /*public void menuGet(final String query, final ApiResponseListener listener) { new AsyncTask() { @Override protected Void doInBackground(Void... params) { @@ -49,5 +72,5 @@ protected Void doInBackground(Void... params) { } }.execute(); - } + }*/ } diff --git a/app/src/main/java/net/bluehack/kiosk/api/net/NetworkManager.java b/app/src/main/java/net/bluehack/kiosk/api/net/NetworkManager.java new file mode 100644 index 0000000..3948786 --- /dev/null +++ b/app/src/main/java/net/bluehack/kiosk/api/net/NetworkManager.java @@ -0,0 +1,51 @@ +package net.bluehack.kiosk.api.net; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.widget.Toast; + +import net.bluehack.kiosk.ApplicationLoader; + +import static net.bluehack.kiosk.util.Logger.LOGD; +import static net.bluehack.kiosk.util.Logger.LOGE; +import static net.bluehack.kiosk.util.Logger.makeLogTag; + +public class NetworkManager { + + private static final String TAG = makeLogTag(NetworkManager.class); + private static NetworkManager ourInstance = new NetworkManager(); + + public static NetworkManager getInstance() { + return ourInstance; + } + + private NetworkManager() { + } + + public static boolean isNetworkOnline() { + try { + ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.getContext() + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo netInfo = cm.getActiveNetworkInfo(); + if (netInfo != null && (netInfo.isConnectedOrConnecting() || netInfo.isAvailable())) { + return true; + } + + netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); + + if (netInfo != null && netInfo.isConnectedOrConnecting()) { + return true; + } else { + netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + if (netInfo != null && netInfo.isConnectedOrConnecting()) { + return true; + } + } + } catch (Exception e) { + LOGE(TAG, String.valueOf(e)); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/net/bluehack/kiosk/login/LoginActivity.java b/app/src/main/java/net/bluehack/kiosk/login/LoginActivity.java new file mode 100644 index 0000000..e0ec464 --- /dev/null +++ b/app/src/main/java/net/bluehack/kiosk/login/LoginActivity.java @@ -0,0 +1,189 @@ +package net.bluehack.kiosk.login; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.content.ContextCompat; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.View; +import android.view.inputmethod.EditorInfo; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.gson.Gson; + +import net.bluehack.kiosk.ApplicationLoader; +import net.bluehack.kiosk.R; +import net.bluehack.kiosk.api.ApiClient; +import net.bluehack.kiosk.api.net.NetworkManager; +import net.bluehack.kiosk.main.MainActivity; +import net.bluehack.kiosk.model.LoginReq; +import net.bluehack.kiosk.model.LoginRes; +import net.bluehack.kiosk.model.LoginResDataItem; +import net.bluehack.kiosk.store.StoreActivity; +import net.bluehack.kiosk.util.KioskPreference; + +import static net.bluehack.kiosk.util.Logger.LOGD; +import static net.bluehack.kiosk.util.Logger.LOGE; +import static net.bluehack.kiosk.util.Logger.makeLogTag; + +public class LoginActivity extends Activity { + + private static final String TAG = makeLogTag(LoginActivity.class); + private Button login_btn; + private EditText login_text_id; + private EditText login_text_pw; + private TextView login_underline_text_id; + private TextView login_underline_text_pw; + private LoginReq loginReq; + private static String loginIdText; + private static String loginPwText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + if (checkedAutoLogin()) { + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + startActivity(intent); + finish(); + } + + login_btn = (Button) findViewById(R.id.login_btn); + login_text_id = (EditText) findViewById(R.id.login_text_id); + login_text_pw = (EditText) findViewById(R.id.login_text_pw); + login_underline_text_id = (TextView) findViewById(R.id.login_underline_text_id); + login_underline_text_pw = (TextView) findViewById(R.id.login_underline_text_pw); + + login_text_id.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + login_underline_text_id.setBackgroundColor(getColor(getApplicationContext(),R.color.color_09)); + login_underline_text_pw.setBackgroundColor(getColor(getApplicationContext(),R.color.color_04)); + } + } + }); + login_text_id.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + loginIdText = s.toString(); + } + }); + + login_text_pw.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + login_underline_text_pw.setBackgroundColor(getColor(getApplicationContext(),R.color.color_09)); + login_underline_text_id.setBackgroundColor(getColor(getApplicationContext(),R.color.color_04)); + } + } + }); + login_text_pw.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + login_btn.setBackgroundColor(getColor(getApplicationContext(),R.color.color_09)); + loginPwText = s.toString(); + } + }); + + login_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + LOGE(TAG, "loginReq info : " + loginIdText + "," + loginPwText); + + loginReq = new LoginReq(); + loginReq.setLoginId(loginIdText); + loginReq.setLoginPasswd(loginPwText); + + doLogin(loginReq); + } + }); + } + + public static int getColor(Context context, int id) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return context.getColor(id); + } else { + //noinspection deprecation + return context.getResources().getColor(id); + } + } + + private void doLogin(final LoginReq loginReq) { + + if (NetworkManager.isNetworkOnline()) { + ApiClient.getInstance().usersLoginPost(loginReq, new ApiClient.ApiResponseListener() { + @Override + public void onResponse(final Object result) { + new Thread(new Runnable() { + @Override + public void run() { + runOnUiThread(new Runnable() { + @Override + public void run() { + LoginRes loginRes = (LoginRes) result; + + if (loginRes.getResponseStatus() != null && loginRes.getResponseStatus().equals("200")) { + + LOGD(TAG, "login success!"); + + //set preference + Gson gson = new Gson(); + String loginResDataItem = gson.toJson(loginRes.getData()); + KioskPreference.getInstance().setLoginInfo(loginResDataItem); + + Intent intent = new Intent(LoginActivity.this, StoreActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + startActivity(intent); + finish(); + + } else { + Toast.makeText(getApplicationContext(), "아이디 / 비밀번호가 잘못되었습니다.", Toast.LENGTH_SHORT).show(); + } + } + }); + } + }).start(); + } + }); + } else { + //offline + Toast.makeText(ApplicationLoader.getContext(),"check network status!",Toast.LENGTH_SHORT).show(); + } + } + + private boolean checkedAutoLogin() { + if (KioskPreference.getInstance().getLoginInfo() != null) { + return true; + } else { + return false; + } + } +} diff --git a/app/src/main/java/net/bluehack/kiosk/main/MainActivity.java b/app/src/main/java/net/bluehack/kiosk/main/MainActivity.java index 8d13c71..e70bcd5 100644 --- a/app/src/main/java/net/bluehack/kiosk/main/MainActivity.java +++ b/app/src/main/java/net/bluehack/kiosk/main/MainActivity.java @@ -11,15 +11,11 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.view.Gravity; import android.view.MenuItem; import android.view.View; import android.widget.ImageView; import android.widget.Toast; -import com.synnapps.carouselview.CarouselView; -import com.synnapps.carouselview.ViewListener; - import net.bluehack.kiosk.R; import net.bluehack.kiosk.store.StoreActivity; @@ -31,8 +27,6 @@ public class MainActivity extends AppCompatActivity { private Context context; private DrawerLayout drawerLayout; private NavigationView navigationView; - private CarouselView carouselView; - private int[] carouselImgs = {R.drawable.img_slidemenu_promotion, R.drawable.img_slidemenu_promotion, R.drawable.img_slidemenu_promotion, R.drawable.img_slidemenu_promotion}; private RecyclerView recyclerView; private RecyclerView.LayoutManager layoutManager; @@ -56,10 +50,11 @@ protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar = getSupportActionBar(); actionBar.setHomeAsUpIndicator(R.drawable.btn_main_menu_nor); actionBar.setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(false); + orderBtn = (ImageView) findViewById(R.id.order_btn); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - carouselView = (CarouselView) findViewById(R.id.carousel_view); //recyclerView = (RecyclerView) findViewById(R.id.recent_menu_list); //recyclerView.setHasFixedSize(true); @@ -70,21 +65,6 @@ protected void onCreate(Bundle savedInstanceState) { //recyclerView.setAdapter(recentCardAdapter); //recentCardAdapter.notifyDataSetChanged(); - carouselView.setPageCount(carouselImgs.length); - carouselView.setSlideInterval(2000); - carouselView.setViewListener(new ViewListener() { - @Override - public View setViewForPosition(int position) { - View carouselListItem = getLayoutInflater().inflate(R.layout.carousel_list_item, null); - ImageView carouselItemImg = (ImageView) carouselListItem.findViewById(R.id.carousel_item_img); - - carouselItemImg.setImageResource(carouselImgs[position]); - carouselView.setIndicatorGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM); - - return carouselListItem; - } - }); - navigationView = (NavigationView) findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override diff --git a/app/src/main/java/net/bluehack/kiosk/order/CatalogAdapter.java b/app/src/main/java/net/bluehack/kiosk/order/CatalogAdapter.java index 4a5babe..53afaf7 100644 --- a/app/src/main/java/net/bluehack/kiosk/order/CatalogAdapter.java +++ b/app/src/main/java/net/bluehack/kiosk/order/CatalogAdapter.java @@ -1,3 +1,4 @@ +/* package net.bluehack.kiosk.order; import android.app.Activity; @@ -9,8 +10,6 @@ import net.bluehack.kiosk.R; import net.bluehack.kiosk.api.ApiClient; -import net.bluehack.kiosk.model.Menu; -import net.bluehack.kiosk.model.MenuDataItem; import java.util.ArrayList; @@ -102,3 +101,4 @@ public int getItemCount() { } } } +*/ diff --git a/app/src/main/java/net/bluehack/kiosk/order/MenuItemAdapter.java b/app/src/main/java/net/bluehack/kiosk/order/MenuItemAdapter.java index 76ac450..fa76962 100644 --- a/app/src/main/java/net/bluehack/kiosk/order/MenuItemAdapter.java +++ b/app/src/main/java/net/bluehack/kiosk/order/MenuItemAdapter.java @@ -1,3 +1,4 @@ +/* package net.bluehack.kiosk.order; import android.content.Context; @@ -7,7 +8,6 @@ import android.view.ViewGroup; import net.bluehack.kiosk.R; -import net.bluehack.kiosk.model.MenuDataItem; import java.util.ArrayList; @@ -61,3 +61,4 @@ public void addItem(ArrayList menuList) { } } } +*/ diff --git a/app/src/main/java/net/bluehack/kiosk/order/OrderActivity.java b/app/src/main/java/net/bluehack/kiosk/order/OrderActivity.java index 650897f..0a1a500 100644 --- a/app/src/main/java/net/bluehack/kiosk/order/OrderActivity.java +++ b/app/src/main/java/net/bluehack/kiosk/order/OrderActivity.java @@ -1,3 +1,4 @@ +/* package net.bluehack.kiosk.order; import android.content.Context; @@ -54,3 +55,4 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } } +*/ diff --git a/app/src/main/java/net/bluehack/kiosk/store/StoreActivity.java b/app/src/main/java/net/bluehack/kiosk/store/StoreActivity.java index e154ddd..ea3955c 100644 --- a/app/src/main/java/net/bluehack/kiosk/store/StoreActivity.java +++ b/app/src/main/java/net/bluehack/kiosk/store/StoreActivity.java @@ -1,529 +1,26 @@ package net.bluehack.kiosk.store; -import android.Manifest; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; - -import android.location.Address; -import android.location.Geocoder; -import android.location.Location; -import android.location.LocationManager; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.util.Log; -import android.widget.Toast; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.api.GoogleApiClient; - -import com.google.android.gms.location.LocationListener; -import com.google.android.gms.location.LocationRequest; -import com.google.android.gms.location.LocationServices; -import com.google.android.gms.location.places.Places; -import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapFragment; -import com.google.android.gms.maps.OnMapReadyCallback; -import com.google.android.gms.maps.model.LatLng; - -import net.bluehack.kiosk.R; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import noman.googleplaces.NRPlaces; -import noman.googleplaces.Place; -import noman.googleplaces.PlaceType; -import noman.googleplaces.PlacesException; -import noman.googleplaces.PlacesListener; - -import static net.bluehack.kiosk.util.Logger.LOGD; -import static net.bluehack.kiosk.util.Logger.LOGE; import static net.bluehack.kiosk.util.Logger.makeLogTag; -public class StoreActivity extends Activity implements - GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, - LocationListener, OnMapReadyCallback, PlacesListener { +public class StoreActivity extends Activity { private static final String TAG = makeLogTag(StoreActivity.class); private Context context; - private static GoogleApiClient googleApiClient = null; - private static LocationRequest locationRequest = null; - private static GoogleMap googleMap = null; - private String currentLocationAddress = null; - private static LocationManager locationManager = null; - private static MapFragment mapFragment = null; - private boolean setGPS = false; //현재는 network check - private final int REQUEST_CODE_LOCATION = 2000; - private final int REQUEST_CODE_GPS = 2001; - private static Location location = null; - private final String radius = "1000"; - private final String types = "cafe"; - private static List storeList = new ArrayList(); - private StoreAdapter storeAdapter; private RecyclerView recyclerView; private RecyclerView.LayoutManager layoutManager; - LatLng SEOUL = new LatLng(37.56, 126.97); - - protected synchronized void buildGoogleApiClient() { - googleApiClient = new GoogleApiClient.Builder(this) - .addConnectionCallbacks(this) - .addOnConnectionFailedListener(this) - .addApi(LocationServices.API) - .addApi(Places.GEO_DATA_API) //place - .addApi(Places.PLACE_DETECTION_API) - .addConnectionCallbacks(this) - .build(); - - googleApiClient.connect(); - } - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(net.bluehack.kiosk.R.layout.activity_store); context = getApplicationContext(); - locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); - recyclerView = (RecyclerView) findViewById(R.id.store_recommend_list); - recyclerView.setHasFixedSize(true); - mapFragment = (MapFragment) getFragmentManager() - .findFragmentById(R.id.map); - mapFragment.getMapAsync(this); - - storeAdapter = new StoreAdapter(context); - layoutManager = new LinearLayoutManager(this); - recyclerView.setLayoutManager(layoutManager); - recyclerView.setAdapter(storeAdapter); - } - - - public boolean checkLocationPermission() - { - LOGD(TAG, "checkLocationPermission"); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED - && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - - //퍼미션 요청을 위해 UI를 보여줘야 하는지 검사 - if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) { - - //Prompt the user once explanation has been shown; - requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_CODE_LOCATION); - - } else - //UI보여줄 필요 없이 요청 - requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_CODE_LOCATION); - - return false; - } else { - - LOGD(TAG, "checkLocationPermission"+"이미 퍼미션 획득한 경우"); - if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !setGPS) - { - LOGD(TAG, "checkLocationPermission Version >= M"); - showGPSDisabledAlertToUser(); - } - - if (googleApiClient == null) { - LOGD(TAG, "checkLocationPermission "+"mGoogleApiClient==NULL"); - buildGoogleApiClient(); - } - else { - LOGD(TAG, "checkLocationPermission "+"mGoogleApiClient!=NULL"); - } - - if ( googleApiClient.isConnected()) { - LOGD(TAG, "checkLocationPermission"+"mGoogleApiClient 연결되 있음"); - } - else { - LOGD(TAG, "checkLocationPermission"+"mGoogleApiClient 끊어져 있음"); - } - - - googleApiClient.reconnect();//이미 연결되 있는 경우이므로 다시 연결 - - googleMap.setMyLocationEnabled(true); - } - } - else { - if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !setGPS) - { - LOGD(TAG, "checkLocationPermission Version < M"); - showGPSDisabledAlertToUser(); - } - - if (googleApiClient == null) { - buildGoogleApiClient(); - } - googleMap.setMyLocationEnabled(true); - } - - return true; - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - switch (requestCode) { - case REQUEST_CODE_LOCATION: { - - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - //퍼미션이 허가된 경우 - if ((ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED - || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { - - if (!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && !setGPS || - !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !setGPS) { - showGPSDisabledAlertToUser(); - } - - if (googleApiClient == null) { - buildGoogleApiClient(); - } - googleMap.setMyLocationEnabled(true); - } - } else { - Toast.makeText(this, "퍼미션 취소", Toast.LENGTH_LONG).show(); - } - return; - } - } } - @Override - public void onMapReady(GoogleMap map) - { - googleMap = map; - - googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { - - @Override - public void onMapLoaded() { - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - checkLocationPermission(); - } else { - - if (!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && !setGPS || - !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !setGPS) { - showGPSDisabledAlertToUser(); - } - - if (googleApiClient == null) { - buildGoogleApiClient(); - } - - googleMap.setMyLocationEnabled(true); - } - } - }); - - //구글 플레이 서비스 초기화 - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - { - if (ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED - || ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) - { - buildGoogleApiClient(); - googleMap.setMyLocationEnabled(true); - } - else - { - /**앱을 삭제할 경우*/ - checkLocationPermission(); - } - } - else - { - buildGoogleApiClient(); - googleMap.setMyLocationEnabled(true); - } - } - - @Override - public void onConnected(Bundle bundle) { - - LOGD(TAG, "onConnected"); - - /**Fixme: @k - * LocationManager - * NETWORK_PROVIDER, GPS_PROVIDER 둘다 기기별 테스트 필요 */ - if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { - - setGPS = true; - //location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - - - } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { - - setGPS = true; - //location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); - - - }else { - LOGD(TAG, "Can't get locationManager!"); - } - - if ( setGPS && googleApiClient.isConnected() ) { - - locationRequest = new LocationRequest(); - //locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); - locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); - locationRequest.setInterval(1000); - locationRequest.setFastestInterval(1000); - - LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); - location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); - LOGD(TAG, "GPS_PROVIDER location:" + location.getLatitude() + "," + location.getLongitude()); - //LOGD(TAG, "GPS_PROVIDER Address:" + findAddress(location)); - if (location != null) { - - new NRPlaces.Builder() - .listener(this) - .key("AIzaSyA7av6NBZ3U-CwHzYMPex2M96OWP1zQz4Y") - .latlng(location.getLatitude(), location.getLongitude()) - .radius(1000) - .type(PlaceType.CAFE) - .build() - .execute(); - } else { - return; - } - } - - if (ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED - || ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { - - if ( !googleApiClient.isConnected()) { - googleApiClient.connect(); - } - } - } - - - @Override - public void onConnectionFailed(ConnectionResult result) { - LOGD(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); - } - - @Override - public void onConnectionSuspended(int cause) { - LOGD(TAG, "Connection suspended"); - googleApiClient.connect(); - } - - @Override - protected void onStart() { - super.onStart(); - - storeAdapter.clean(); - if (googleApiClient != null) { - googleApiClient.connect(); - } - } - - @Override - public void onResume() { - super.onResume(); - - if (googleApiClient != null) { - googleApiClient.connect(); - } - } - - @Override - protected void onStop() { - super.onStop(); - - if (googleApiClient != null && googleApiClient.isConnected()) { - googleApiClient.disconnect(); - } - } - - - @Override - public void onPause() { - super.onPause(); - - storeAdapter.clean(); - if ( googleApiClient != null && googleApiClient.isConnected()) { - googleApiClient.disconnect(); - } - } - - @Override - protected void onDestroy() { - - if (googleApiClient != null) { - googleApiClient.unregisterConnectionCallbacks(this); - googleApiClient.unregisterConnectionFailedListener(this); - - if (googleApiClient.isConnected()) { - LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this); - } - - googleApiClient.disconnect(); - googleApiClient = null; - } - - super.onDestroy(); - } - - - @Override - public void onLocationChanged(Location location) { - - LOGD(TAG, "location:" + location.getLatitude() + "," + location.getLongitude()); - } - - //GPS 활성화를 위한 다이얼로그 보여주기 - private void showGPSDisabledAlertToUser() { - AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); - alertDialogBuilder.setMessage("GPS가 비활성화 되어있습니다. 활성화 할까요?") - .setCancelable(false) - .setPositiveButton("설정", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - Intent callGPSSettingIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); - startActivityForResult(callGPSSettingIntent, REQUEST_CODE_GPS); - } - }); - - alertDialogBuilder.setNegativeButton("취소", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - AlertDialog alert = alertDialogBuilder.create(); - alert.show(); - } - - - //GPS 활성화를 위한 다이얼로그의 결과 처리 - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - switch (requestCode) { - case REQUEST_CODE_GPS: - - if (locationManager == null) - locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); - - if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { - - setGPS = true; - mapFragment.getMapAsync(this); - } - break; - } - } - - //좌표값 => 주소 변환 - private String findAddress(Location location) { - StringBuffer bf = new StringBuffer(); - Geocoder geocoder = new Geocoder(this, Locale.KOREA); - List
address; - - try { - if (geocoder != null) { - - double lat = location.getLatitude(); - double lng = location.getLongitude(); - - // 세번째 인수는 최대결과값 - address = geocoder.getFromLocation(lat, lng, 1); - - if (address != null && address.size() > 0) { - // 주소 - currentLocationAddress = address.get(0).getAddressLine(0).toString(); - - // 전송할 주소 데이터 (위도/경도 포함 편집) - bf.append(currentLocationAddress).append("#"); - bf.append(lat).append("#"); - bf.append(lng); - } - } - - } catch (IOException e) { - e.printStackTrace(); - } - return bf.toString(); - } - - @Override - public void onPlacesFailure(PlacesException e) { - LOGE(TAG,"onPlacesFailure()"); - } - - @Override - public void onPlacesStart() { - LOGD(TAG,"onPlacesStart()"); - } - - @Override - public void onPlacesSuccess(final List places) { - LOGD(TAG,"onPlacesSuccess()"); - - runOnUiThread(new Runnable() { - @Override - public void run() { - - for (noman.googleplaces.Place place : places) { - - if (places.size() != 0) { - StoreItem storeItem = new StoreItem(); - int meter = distanceLocation(location.getLatitude(), location.getLongitude(), place.getLatitude(), place.getLongitude()); - LOGD(TAG,"PALCE meter : " + meter); - LOGD(TAG,"PALCE getName : " + place.getName()); - storeItem.setName(place.getName()); - storeItem.setAddress(place.getVicinity()); - storeItem.setMeter(String.valueOf(meter)+"m"); - storeList.add(storeItem); - } else { - LOGE(TAG, "places is null"); - } - } - } - }); - } - - @Override - public void onPlacesFinished() { - LOGD(TAG,"onPlacesFinished()"); - - storeAdapter.addItem(storeList); - storeAdapter.notifyDataSetChanged(); - } - - - public static int distanceLocation(double curLatitude, double curLongitude, double targetLatitude, double targetLngitude) { - - int meter; - Location current = new Location("current"); - Location target = new Location("target"); - - current.setLatitude(curLatitude); - current.setLongitude(curLongitude); - target.setLatitude(targetLatitude); - target.setLongitude(targetLngitude); - - double distance = current.distanceTo(target); - meter = (int) distance; - - return meter; - } } diff --git a/app/src/main/java/net/bluehack/kiosk/store/StoreAdapter.java b/app/src/main/java/net/bluehack/kiosk/store/StoreAdapter.java index f6360c7..8711c14 100644 --- a/app/src/main/java/net/bluehack/kiosk/store/StoreAdapter.java +++ b/app/src/main/java/net/bluehack/kiosk/store/StoreAdapter.java @@ -8,8 +8,6 @@ import android.view.ViewGroup; import net.bluehack.kiosk.R; -import net.bluehack.kiosk.order.OrderActivity; -import net.bluehack.kiosk.order_pay.OrderPayActivity; import java.util.ArrayList; import java.util.List; @@ -51,9 +49,9 @@ public void onClick(View v) { /**Fixme: @k * flow 추가시 map 선택으로 바뀔 예정 */ - Intent intent = new Intent(context, OrderActivity.class); + /*Intent intent = new Intent(context, OrderActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + context.startActivity(intent);*/ } }); } diff --git a/app/src/main/java/net/bluehack/kiosk/util/KioskPreference.java b/app/src/main/java/net/bluehack/kiosk/util/KioskPreference.java new file mode 100644 index 0000000..7cbe9a6 --- /dev/null +++ b/app/src/main/java/net/bluehack/kiosk/util/KioskPreference.java @@ -0,0 +1,40 @@ +package net.bluehack.kiosk.util; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.util.Log; + +import com.google.gson.Gson; + +import net.bluehack.kiosk.model.LoginResDataItem; + +public class KioskPreference { + + private Context context; + + public static final String LOGIN_INFO = "pref_login_info"; + + private static class SingletonHolder { + static final KioskPreference INSTANCE = new KioskPreference(); + } + + public static KioskPreference getInstance() { + return SingletonHolder.INSTANCE; + } + + public void init(Context context) { + this.context = context; + } + + public String getLoginInfo() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); + return sp.getString(LOGIN_INFO, null); + } + + public void setLoginInfo(String loginResDataItem) { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); + Log.e("preference: ", loginResDataItem); + sp.edit().putString(LOGIN_INFO, loginResDataItem).apply(); + } +} diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..e9bb8ff --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_store.xml b/app/src/main/res/layout/activity_store.xml index 59b5125..45e7736 100644 --- a/app/src/main/res/layout/activity_store.xml +++ b/app/src/main/res/layout/activity_store.xml @@ -41,14 +41,5 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/content_login.xml b/app/src/main/res/layout/content_login.xml new file mode 100644 index 0000000..11ed5ed --- /dev/null +++ b/app/src/main/res/layout/content_login.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +