Search in sources :

Example 86 with Context

use of android.content.Context in project platform_frameworks_base by android.

the class VibratorService method systemReady.

public void systemReady() {
    mIm = mContext.getSystemService(InputManager.class);
    mSettingObserver = new SettingsObserver(mH);
    mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
    mPowerManagerInternal.registerLowPowerModeObserver(new PowerManagerInternal.LowPowerModeListener() {

        @Override
        public void onLowPowerModeChanged(boolean enabled) {
            updateInputDeviceVibrators();
        }
    });
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES), true, mSettingObserver, UserHandle.USER_ALL);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            updateInputDeviceVibrators();
        }
    }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mH);
    updateInputDeviceVibrators();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) PowerManagerInternal(android.os.PowerManagerInternal) Intent(android.content.Intent) InputManager(android.hardware.input.InputManager) BroadcastReceiver(android.content.BroadcastReceiver)

Example 87 with Context

use of android.content.Context in project freeline by alibaba.

the class FreelineCore method getPackageInfo.

private static Object getPackageInfo(Application app) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    Context contextImpl = app.getBaseContext();
    Field mPackageInfoField = contextImpl.getClass().getDeclaredField("mPackageInfo");
    mPackageInfoField.setAccessible(true);
    Object mPackageInfo = mPackageInfoField.get(contextImpl);
    return mPackageInfo;
}
Also used : Context(android.content.Context) Field(java.lang.reflect.Field)

Example 88 with Context

use of android.content.Context in project platform_frameworks_base by android.

the class AppWidgetHostView method getDefaultView.

/**
     * Inflate and return the default layout requested by AppWidget provider.
     */
protected View getDefaultView() {
    if (LOGD) {
        Log.d(TAG, "getDefaultView");
    }
    View defaultView = null;
    Exception exception = null;
    try {
        if (mInfo != null) {
            Context theirContext = getRemoteContext();
            mRemoteContext = theirContext;
            LayoutInflater inflater = (LayoutInflater) theirContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflater = inflater.cloneInContext(theirContext);
            inflater.setFilter(sInflaterFilter);
            AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
            Bundle options = manager.getAppWidgetOptions(mAppWidgetId);
            int layoutId = mInfo.initialLayout;
            if (options.containsKey(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)) {
                int category = options.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY);
                if (category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
                    int kgLayoutId = mInfo.initialKeyguardLayout;
                    // If a default keyguard layout is not specified, use the standard
                    // default layout.
                    layoutId = kgLayoutId == 0 ? layoutId : kgLayoutId;
                }
            }
            defaultView = inflater.inflate(layoutId, this, false);
        } else {
            Log.w(TAG, "can't inflate defaultView because mInfo is missing");
        }
    } catch (RuntimeException e) {
        exception = e;
    }
    if (exception != null) {
        Log.w(TAG, "Error inflating AppWidget " + mInfo + ": " + exception.toString());
    }
    if (defaultView == null) {
        if (LOGD)
            Log.d(TAG, "getDefaultView couldn't find any view, so inflating error");
        defaultView = getErrorView();
    }
    return defaultView;
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Paint(android.graphics.Paint)

Example 89 with Context

use of android.content.Context in project platform_frameworks_base by android.

the class CardEmulation method getInstance.

/**
     * Helper to get an instance of this class.
     *
     * @param adapter A reference to an NfcAdapter object.
     * @return
     */
public static synchronized CardEmulation getInstance(NfcAdapter adapter) {
    if (adapter == null)
        throw new NullPointerException("NfcAdapter is null");
    Context context = adapter.getContext();
    if (context == null) {
        Log.e(TAG, "NfcAdapter context is null.");
        throw new UnsupportedOperationException();
    }
    if (!sIsInitialized) {
        IPackageManager pm = ActivityThread.getPackageManager();
        if (pm == null) {
            Log.e(TAG, "Cannot get PackageManager");
            throw new UnsupportedOperationException();
        }
        try {
            if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION, 0)) {
                Log.e(TAG, "This device does not support card emulation");
                throw new UnsupportedOperationException();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "PackageManager query failed.");
            throw new UnsupportedOperationException();
        }
        sIsInitialized = true;
    }
    CardEmulation manager = sCardEmus.get(context);
    if (manager == null) {
        // Get card emu service
        INfcCardEmulation service = adapter.getCardEmulationService();
        if (service == null) {
            Log.e(TAG, "This device does not implement the INfcCardEmulation interface.");
            throw new UnsupportedOperationException();
        }
        manager = new CardEmulation(context, service);
        sCardEmus.put(context, manager);
    }
    return manager;
}
Also used : Context(android.content.Context) INfcCardEmulation(android.nfc.INfcCardEmulation) IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) INfcCardEmulation(android.nfc.INfcCardEmulation)

Example 90 with Context

use of android.content.Context in project platform_frameworks_base by android.

the class CursorAdapter method getDropDownView.

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    if (mDataValid) {
        final Context context = mDropDownContext == null ? mContext : mDropDownContext;
        mCursor.moveToPosition(position);
        final View v;
        if (convertView == null) {
            v = newDropDownView(context, mCursor, parent);
        } else {
            v = convertView;
        }
        bindView(v, context, mCursor);
        return v;
    } else {
        return null;
    }
}
Also used : Context(android.content.Context) View(android.view.View)

Aggregations

Context (android.content.Context)3233 Intent (android.content.Intent)676 View (android.view.View)400 Test (org.junit.Test)346 BroadcastReceiver (android.content.BroadcastReceiver)338 IntentFilter (android.content.IntentFilter)301 TextView (android.widget.TextView)258 Resources (android.content.res.Resources)226 PendingIntent (android.app.PendingIntent)188 PackageManager (android.content.pm.PackageManager)164 File (java.io.File)156 IOException (java.io.IOException)150 LayoutInflater (android.view.LayoutInflater)139 ImageView (android.widget.ImageView)135 Drawable (android.graphics.drawable.Drawable)128 Uri (android.net.Uri)115 RemoteException (android.os.RemoteException)102 ArrayList (java.util.ArrayList)102 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)101 Bundle (android.os.Bundle)95