Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.ContentValues;
- import android.content.Context;
- import android.content.res.Resources;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import com.younginnovators.sjk.customcontrols.MessageDialog;
- import com.younginnovators.sjk.databaseandpreferences.SharedPref;
- import com.younginnovators.sjk.databaseandpreferences.ZayRideDatabase;
- import com.younginnovators.sjk.databaseandpreferences.ZayRideDatabaseUtility;
- import java.util.Locale;
- /**
- * Created by alone on image3/17/2016.
- */
- public class BaseActivity extends AppCompatActivity {
- public SharedPref prefs;
- public Resources resources;
- private Bitmap bitmap;
- public double lat;
- public double lang;
- public MessageDialog messageDialog;
- private Locale myLocale;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- prefs = new SharedPref();
- resources = getResources();
- messageDialog = MessageDialog.getInstance();
- //setLocale();
- }
- //public void setLocale() {
- //myLocale = new Locale("zh");
- //Resources res = getResources();
- //DisplayMetrics dm = res.getDisplayMetrics();
- //Configuration conf = res.getConfiguration();
- //conf.locale = myLocale;
- //res.updateConfiguration(conf, dm);
- //// Intent refresh = new Intent(this, AndroidLocalize.class);
- //// startActivity(refresh);
- //}
- /**
- * Get the device id from database.
- */
- public String getDeviceIdFromDatabase() {
- String deviceId = "";
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- Cursor cursor = database.getData("Select " + ZayRideDatabaseUtility.DEVICE_ID + " from " + ZayRideDatabaseUtility.TABLE_DEVICE_INFO);
- if (cursor.getCount() > 0 && cursor.moveToFirst()) {
- deviceId = cursor.getString(cursor.getColumnIndex(ZayRideDatabaseUtility.DEVICE_ID));
- }
- cursor.close();
- database.closeDatabase();
- return deviceId;
- }
- protected boolean isNetworkAvilable() {
- boolean isNetworkAvilable = false;
- ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo info = manager.getActiveNetworkInfo();
- if (info != null && info.isAvailable() && info.isConnected()) {
- isNetworkAvilable = true;
- }
- return isNetworkAvilable;
- }
- /**
- * Method to update the status of already login after successful login status is one and after signuout status is 0.
- *
- * @param status value to e updated in interger image1 for login and 0 for not login
- */
- protected void updateAlreadyLoginStatus(int status) {
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- ContentValues values = new ContentValues();
- values.put(ZayRideDatabaseUtility.Configuration.COLUMN_NAME_IS_ALREADY_LOGGED_IN, status);
- if (checkConfigurationTableDataExixtanceStatus()) {
- database.updateData(values, ZayRideDatabaseUtility.Configuration.TABLE_NAME);
- } else {
- database.insertData(values, ZayRideDatabaseUtility.Configuration.TABLE_NAME);
- }
- database.close();
- }
- /**
- * check the database for data status if has record or not
- *
- * @return boolean value true if table already containdata
- */
- protected boolean checkConfigurationTableDataExixtanceStatus() {
- boolean isAlreadyContainData = false;
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- Cursor cursor = database.getData("Select * from " + ZayRideDatabaseUtility.Configuration.TABLE_NAME);
- if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
- isAlreadyContainData = true;
- }
- cursor.close();
- database.close();
- return isAlreadyContainData;
- }
- /**
- * check the database for login status if user is alreadylogin then redirect it to home
- *
- * @return boolean value true if user is already login
- */
- protected boolean checkAlreadyLoginStatus() {
- boolean isAlreadyLoggin = false;
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- Cursor cursor = database.getData("Select * from " + ZayRideDatabaseUtility.Configuration.TABLE_NAME);
- if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
- do {
- int status = cursor.getInt(cursor.getColumnIndex(ZayRideDatabaseUtility.Configuration.COLUMN_NAME_IS_ALREADY_LOGGED_IN));
- if (status == 1) {
- isAlreadyLoggin = true;
- }
- } while (cursor.moveToNext());
- }
- cursor.close();
- database.close();
- return isAlreadyLoggin;
- }
- protected boolean checkProfileStatus() {
- boolean isAlreadyLoggin = false;
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- Cursor cursor = database.getData("Select * from " + ZayRideDatabaseUtility.ProfileDetail.TABLE_NAME);
- if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
- isAlreadyLoggin = true;
- }
- cursor.close();
- database.close();
- return isAlreadyLoggin;
- }
- /**
- * Get the device id from database.
- */
- public int getUserIdFromDatabase() {
- int userId = 0;
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- Cursor cursor = database.getData("Select " + ZayRideDatabaseUtility.USER_ID + " from " + ZayRideDatabaseUtility.TABLE_LOGIN_DATA);
- if (cursor.getCount() > 0 && cursor.moveToFirst()) {
- userId = cursor.getInt(cursor.getColumnIndex(ZayRideDatabaseUtility.USER_ID));
- }
- cursor.close();
- database.closeDatabase();
- return userId;
- }
- /**
- * get the coordinates of current location from database
- *
- * @return
- */
- // protected MyLocationCoordinates getCoordinates() {
- // MyLocationCoordinates coordinates = new MyLocationCoordinates();
- // ZayRideDatabase database = new ZayRideDatabase(this);
- // database.openDatabase();
- //
- // Cursor mCursor = database.getData("Select * from " + ZayRideDatabaseUtility.MyLocation.TABLE_NAME);
- // mCursor.moveToFirst();
- // if (mCursor != null && mCursor.getCount() > 0) {
- // do {
- //
- // double latitude = mCursor.getDouble(mCursor.getColumnIndex(ZayRideDatabaseUtility.MyLocation.COLUMN_NAME_LATITUDE));
- // double longitude = mCursor.getDouble(mCursor.getColumnIndex(ZayRideDatabaseUtility.MyLocation.COLUMN_NAME_LONGITUDE));
- // coordinates.setLatitude(latitude);
- // coordinates.setLongitude(longitude);
- // } while (mCursor.moveToNext());
- // }
- // mCursor.close();
- // database.close();
- // return coordinates;
- // }
- /**
- * Insert the current location coordinates in dadabase after getting from location service
- *
- * @param mLatitude
- * @param mLongitude
- */
- protected void insertLocationCoordinatesInDatabase(double mLatitude, double mLongitude) {
- ZayRideDatabase database = new ZayRideDatabase(this);
- database.openDatabase();
- database.deleteData(ZayRideDatabaseUtility.MyLocation.TABLE_NAME);
- ContentValues values = new ContentValues();
- values.put(ZayRideDatabaseUtility.MyLocation.COLUMN_NAME_LATITUDE, mLatitude);
- values.put(ZayRideDatabaseUtility.MyLocation.COLUMN_NAME_LONGITUDE, mLongitude);
- database.insertData(values, ZayRideDatabaseUtility.MyLocation.TABLE_NAME);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement