LeOS-Genesis/app/src/main/java/com/darkweb/genesissearchengine/helperMethod.java

53 lines
1.8 KiB
Java
Raw Normal View History

2019-04-28 18:54:22 +02:00
package com.darkweb.genesissearchengine;
2019-03-27 19:07:03 +01:00
import android.content.Context;
2019-05-10 20:44:08 +02:00
import android.content.SharedPreferences;
2019-03-27 19:07:03 +01:00
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
2019-05-10 20:44:08 +02:00
import android.preference.PreferenceManager;
2019-06-15 19:13:52 +02:00
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.darkweb.genesissearchengine.appManager.app_model;
import com.darkweb.genesissearchengine.constants.keys;
2019-05-30 21:19:30 +02:00
2019-03-27 19:07:03 +01:00
public class helperMethod
{
2019-06-15 19:13:52 +02:00
/*Helper Methods*/
public static boolean isNetworkAvailable()
2019-03-27 19:07:03 +01:00
{
2019-06-15 19:13:52 +02:00
ConnectivityManager cm = (ConnectivityManager) app_model.getInstance().getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
2019-03-27 19:07:03 +01:00
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
{
return true;
}
return false;
}
2019-06-15 19:13:52 +02:00
public static String readHomepageHTML(Context applicationContext)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
return prefs.getString(keys.homepage_html_key,"");
2019-05-10 20:44:08 +02:00
}
2019-06-15 19:13:52 +02:00
public static void setHomepageHTML(String html, Context applicationContext)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
2019-05-10 20:44:08 +02:00
SharedPreferences.Editor edit = prefs.edit();
2019-06-15 19:13:52 +02:00
edit.putString(keys.homepage_html_key, html);
2019-05-10 20:44:08 +02:00
edit.commit();
2019-05-30 21:19:30 +02:00
}
2019-06-15 19:13:52 +02:00
public static void hideKeyboard()
2019-05-30 21:19:30 +02:00
{
2019-06-15 19:13:52 +02:00
View view = app_model.getInstance().getAppInstance().findViewById(android.R.id.content);
if (view != null)
{
InputMethodManager imm = (InputMethodManager) app_model.getInstance().getAppInstance().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
2019-05-10 20:44:08 +02:00
}
2019-03-27 19:07:03 +01:00
}