mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-18 15:07:30 +01:00
Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class AndroidComponentUtil {
|
||||
|
||||
public static void toggleComponent(Context context, Class componentClass, boolean enable) {
|
||||
Timber.i((enable ? "Enabling " : "Disabling ") + componentClass.getSimpleName());
|
||||
ComponentName componentName = new ComponentName(context, componentClass);
|
||||
PackageManager pm = context.getPackageManager();
|
||||
pm.setComponentEnabledSetting(componentName,
|
||||
enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
public static boolean isServiceRunning(Context context, Class serviceClass) {
|
||||
ActivityManager manager =
|
||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
13
app/src/main/java/eu/kanade/mangafeed/util/DataUtils.java
Normal file
13
app/src/main/java/eu/kanade/mangafeed/util/DataUtils.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
public class DataUtils {
|
||||
|
||||
public static boolean isNetworkAvailable(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return connectivityManager.getActiveNetworkInfo() != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import eu.kanade.mangafeed.R;
|
||||
|
||||
public class DialogFactory {
|
||||
|
||||
public static Dialog createSimpleOkErrorDialog(Context context, String title, String message) {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setNeutralButton(R.string.dialog_action_ok, null);
|
||||
return alertDialog.create();
|
||||
}
|
||||
|
||||
public static Dialog createSimpleErrorDialog(Context context) {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context)
|
||||
.setTitle(context.getString(R.string.dialog_error_title))
|
||||
.setMessage(context.getString(R.string.dialog_general_error_Message))
|
||||
.setNeutralButton(R.string.dialog_action_ok, null);
|
||||
return alertDialog.create();
|
||||
}
|
||||
|
||||
public static ProgressDialog createProgressDialog(Context context, String message) {
|
||||
ProgressDialog progressDialog = new ProgressDialog(context);
|
||||
progressDialog.setMessage(message);
|
||||
return progressDialog;
|
||||
}
|
||||
|
||||
public static ProgressDialog createProgressDialog(Context context, @StringRes int messageResoruce) {
|
||||
return createProgressDialog(context, context.getString(messageResoruce));
|
||||
}
|
||||
|
||||
}
|
||||
27
app/src/main/java/eu/kanade/mangafeed/util/NetworkUtil.java
Normal file
27
app/src/main/java/eu/kanade/mangafeed/util/NetworkUtil.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import retrofit.HttpException;
|
||||
|
||||
public class NetworkUtil {
|
||||
|
||||
/**
|
||||
* Returns true if the Throwable is an instance of RetrofitError with an
|
||||
* http status code equals to the given one.
|
||||
*/
|
||||
public static boolean isHttpStatusCode(Throwable throwable, int statusCode) {
|
||||
return throwable instanceof HttpException
|
||||
&& ((HttpException) throwable).code() == statusCode;
|
||||
}
|
||||
|
||||
public static boolean isNetworkConnected(Context context) {
|
||||
ConnectivityManager cm =
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import eu.kanade.mangafeed.R;
|
||||
|
||||
public class SnackbarFactory {
|
||||
|
||||
public static Snackbar createSnackbar(Context context, View view, String message) {
|
||||
Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
|
||||
ViewGroup group = (ViewGroup) snackbar.getView();
|
||||
group.setBackgroundColor(context.getResources().getColor(R.color.primary));
|
||||
return snackbar;
|
||||
}
|
||||
}
|
||||
13
app/src/main/java/eu/kanade/mangafeed/util/ViewUtils.java
Normal file
13
app/src/main/java/eu/kanade/mangafeed/util/ViewUtils.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public class ViewUtils {
|
||||
|
||||
public static float convertPixelsToDp(float px, Context context){
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
return px / (metrics.densityDpi / 160f);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user