com.neovisionaries.android.util.SystemServices Maven / Gradle / Ivy
Show all versions of nv-android-base Show documentation
/*
* Copyright (C) 2013 Neo Visionaries Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neovisionaries.android.util;
import android.accounts.AccountManager;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.KeyguardManager;
import android.app.NotificationManager;
import android.app.SearchManager;
import android.app.UiModeManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.hardware.SensorManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.wifi.WifiManager;
import android.os.DropBoxManager;
import android.os.PowerManager;
import android.os.Vibrator;
import android.service.wallpaper.WallpaperService;
import android.telephony.TelephonyManager;
import android.text.ClipboardManager;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.InputMethodManager;
import com.neovisionaries.android.app.App;
/**
* System service utility.
*
* @since 1.2
* @author Takahiko Kawasaki
*/
public final class SystemServices
{
private SystemServices()
{
}
/**
* Get a system service by name.
*
*
* This method is equivalent to {@link App}{@code .}{@link App#getInstance()
* getInstance()}{@code .}{@link App#getContext() getContext()}{@code
* .getSystemService(serviceName)}. Therefore, {@code App} class must be
* initialized by {@link App#init(Context)} before calling this method.
*
*
* @param serviceName
* System service name.
*
* @return
* System service instance.
*/
public static Object getSystemService(String serviceName)
{
return App.getInstance().getContext().getSystemService(serviceName);
}
/**
* Get {@link AccessibilityManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.ACCESSIBILITY_SERVICE)}.
*
*
* @return
* AccessibilityManager
*/
public static AccessibilityManager getAccessibilityManager()
{
return (AccessibilityManager)getSystemService(Context.ACCESSIBILITY_SERVICE);
}
/**
* Get {@link AccountManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.ACCOUNT_SERVICE)}.
*
*
* @return
* AccountManager
*/
public static AccountManager getAccountManager()
{
return (AccountManager)getSystemService(Context.ACCOUNT_SERVICE);
}
/**
* Get {@link ActivityManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.ACTIVITY_SERVICE)}.
*
*
* @return
* ActivityManager
*/
public static ActivityManager getActivityManager()
{
return (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
}
/**
* Get {@link AlarmManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.ALARM_SERVICE)}.
*
*
* @return
* AlarmManager
*/
public static AlarmManager getAlarmManager()
{
return (AlarmManager)getSystemService(Context.ALARM_SERVICE);
}
/**
* Get {@link AudioManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.AUDIO_SERVICE)}.
*
*
* @return
* AudioManager
*/
public static AudioManager getAudioManager()
{
return (AudioManager)getSystemService(Context.AUDIO_SERVICE);
}
/**
* Get {@link ClipboardManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.CLIPBOARD_SERVICE)}.
*
*
* @return
* ClipboardManager
*/
public static ClipboardManager getClipboardManager()
{
return (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
}
/**
* Get {@link DevicePolicyManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.DEVICE_POLICY_SERVICE)}.
*
*
* @return
* DevicePolicyManager
*/
public static DevicePolicyManager getDevicePolicyManager()
{
return (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
}
/**
* Get {@link DropBoxManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.DROPBOX_SERVICE)}.
*
*
* @return
* DropBoxManager
*/
public static DropBoxManager getDownloadManager()
{
return (DropBoxManager)getSystemService(Context.DROPBOX_SERVICE);
}
/**
* Get {@link InputMethodManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.INPUT_METHOD_SERVICE)}.
*
*
* @return
* InputMethodManager
*/
public static InputMethodManager getInputMethodManager()
{
return (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
}
/**
* Get {@link KeyguardManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.KEYGUARD_SERVICE)}.
*
*
* @return
* KeyguardManager
*/
public static KeyguardManager getKeyguardManager()
{
return (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
}
/**
* Get {@link LayoutInflater}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.LAYOUT_INFLATER_SERVICE)}.
*
*
* @return
* LayoutInflater
*/
public static LayoutInflater getLayoutInflater()
{
return (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
/**
* Get {@link LocationManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.LOCATION_SERVICE)}.
*
*
* @return
* LocationManager
*/
public static LocationManager getLocationManager()
{
return (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
/**
* Get {@link NotificationManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.NOTIFICATION_SERVICE)}.
*
*
* @return
* NotificationManager
*/
public static NotificationManager getNotificationManager()
{
return (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
}
/**
* Get {@link PowerManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.POWER_SERVICE)}.
*
*
* @return
* PowerManager
*/
public static PowerManager getPowerManager()
{
return (PowerManager)getSystemService(Context.POWER_SERVICE);
}
/**
* Get {@link SearchManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.SEARCH_SERVICE)}.
*
*
* @return
* SearchManager
*/
public static SearchManager getSearchManager()
{
return (SearchManager)getSystemService(Context.SEARCH_SERVICE);
}
/**
* Get {@link SensorManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.SENSOR_SERVICE)}.
*
*
* @return
* SensorManager
*/
public static SensorManager getSensorManager()
{
return (SensorManager)getSystemService(Context.SENSOR_SERVICE);
}
/**
* Get {@link TelephonyManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.TELEPHONY_SERVICE)}.
*
*
* @return
* TelephonyManager
*/
public static TelephonyManager getTelephonyManager()
{
return (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
}
/**
* Get {@link UiModeManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.UI_MODE_SERVICE)}.
*
*
* @return
* UiModeManager
*/
public static UiModeManager getUiModeManager()
{
return (UiModeManager)getSystemService(Context.UI_MODE_SERVICE);
}
/**
* Get {@link Vibrator}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.VIBRATOR_SERVICE)}.
*
*
* @return
* Vibrator
*/
public static Vibrator getVibrator()
{
return (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
}
/**
* Get {@link WallpaperService}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.WALLPAPER_SERVICE)}.
*
*
* @return
* WallpaperService
*/
public static WallpaperService getWallpaperService()
{
return (WallpaperService)getSystemService(Context.WALLPAPER_SERVICE);
}
/**
* Get {@link WifiManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.WIFI_SERVICE)}.
*
*
* @return
* WifiManager
*/
public static WifiManager getWifiManager()
{
return (WifiManager)getSystemService(Context.WIFI_SERVICE);
}
/**
* Get {@link WindowManager}.
*
*
* This method is equivalent to {@link #getSystemService(String)
* getSystemService}{@code (Context.WINDOW_SERVICE)}.
*
*
* @return
* WindowManager
*/
public static WindowManager getWindowManager()
{
return (WindowManager)getSystemService(Context.WINDOW_SERVICE);
}
}