package etelligens.com.foodsafety.utils; import static etelligens.com.foodsafety.utils.Keyword.DB_LOGIN_USER_DATA; import static etelligens.com.foodsafety.utils.Keyword.PREF_LANG; import static etelligens.com.foodsafety.utils.Keyword.PREF_NAME; import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.os.PersistableBundle; import android.util.Log; import android.view.inputmethod.InputMethodManager; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.multidex.MultiDex; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import etelligens.com.foodsafety.R; import etelligens.com.foodsafety.activities.Notification.Notification; import etelligens.com.foodsafety.activities.dashboard.Dashboard; public class BaseActivity extends AppCompatActivity { private static final String TAG = "BaseActivity"; private ProgressDialog progress = null; SharedPreferences DBuserData, langData; public String userId, userImg, userName, roleName, empID, currentLang, userEmail, userMob, loginToken, roleID, outletID, partnerID, isAdmin; @Override public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); } public void loadershow() { if (progress == null) { progress = new ProgressDialog(this, R.style.progressTheme); } progress.setTitle("Food Safety"); progress.setMessage(getString(R.string.loading)); progress.setCancelable(false); progress.show(); } public void getselectedLanguage() { langData = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); currentLang = langData.getString(PREF_LANG, null); Log.e(TAG, "getselectedLanguage==" + currentLang); } @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(LocaleHelper.onAttach(newBase)); MultiDex.install(this); Log.e(TAG, "attachCalled..."); } public void loaderHide() { if (progress == null) { progress = new ProgressDialog(this); } progress.dismiss(); } public void hideKeyBoard() { final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null && inputMethodManager.isActive()) { if (getCurrentFocus() != null) { inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } //do nothing... } } public void getSavedData() { DBuserData = getSharedPreferences(DB_LOGIN_USER_DATA, Context.MODE_PRIVATE); userId = DBuserData.getString("USERID", null); userImg = DBuserData.getString("userIMG", null); userName = DBuserData.getString("UserName", null); roleName = DBuserData.getString("roleName", null); empID = DBuserData.getString("EmpID", null); userEmail = DBuserData.getString("userEmail", null); userMob = DBuserData.getString("phone", null); loginToken = DBuserData.getString("LoginToken", null); roleID = DBuserData.getString("roleID", null); outletID = DBuserData.getString("outletID", null); partnerID = DBuserData.getString("partnerID", null); isAdmin = DBuserData.getString("isAdmin", null); } public void gotoDashboard() { Intent i = new Intent(getApplicationContext(), Dashboard.class); startActivity(i); finish(); } public void goToNotificationList() { Intent i = new Intent(getApplicationContext(), Notification.class); int values = 1; i.putExtra("value", values); startActivity(i); } private Bitmap saveImage(Bitmap finalBitmap) { String root = Environment.getExternalStorageDirectory().toString(); String path = root + "/product/thumb"; System.out.println("LOGGER Path:, " + path); File myDir = new File(path); myDir.mkdirs(); @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String fname = "IMG_" + timeStamp + ".jpg"; File file = new File(myDir, fname); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); finalBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return finalBitmap; } public Bitmap saveTempBitmap(Bitmap bitmap) { if (isExternalStorageWritable()) { return saveImage(bitmap); } else { return null; //prompt the user or do something } } /* Checks if external storage is available for read and write */ public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } }