use of android.content.Context in project platform_frameworks_base by android.
the class GridTouchVerticalSpacingStackFromBottomTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
mGridView = getActivity().getGridView();
final Context context = mActivity.getApplicationContext();
mViewConfig = ViewConfiguration.get(context);
}
use of android.content.Context in project platform_frameworks_base by android.
the class MtpDevice method open.
/**
* Opens the MTP device. Once the device is open it takes ownership of the
* {@link android.hardware.usb.UsbDeviceConnection}.
* The connection will be closed when you call {@link #close()}
* The connection will also be closed if this method fails.
*
* @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
* @return true if the device was successfully opened.
*/
public boolean open(UsbDeviceConnection connection) {
boolean result = false;
Context context = connection.getContext();
if (context != null) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (!userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
}
}
if (!result) {
connection.close();
}
return result;
}
use of android.content.Context in project platform_frameworks_base by android.
the class NfcAdapterExtras method get.
/**
* Get the {@link NfcAdapterExtras} for the given {@link NfcAdapter}.
*
* <p class="note">
* Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission.
*
* @param adapter a {@link NfcAdapter}, must not be null
* @return the {@link NfcAdapterExtras} object for the given {@link NfcAdapter}
*/
public static NfcAdapterExtras get(NfcAdapter adapter) {
Context context = adapter.getContext();
if (context == null) {
throw new UnsupportedOperationException("You must pass a context to your NfcAdapter to use the NFC extras APIs");
}
synchronized (NfcAdapterExtras.class) {
if (sService == null) {
initService(adapter);
}
NfcAdapterExtras extras = sNfcExtras.get(adapter);
if (extras == null) {
extras = new NfcAdapterExtras(adapter);
sNfcExtras.put(adapter, extras);
}
return extras;
}
}
use of android.content.Context in project platform_frameworks_base by android.
the class NekoLand method showNameDialog.
private void showNameDialog(final Cat cat) {
final Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material_Light_Dialog_NoActionBar);
// TODO: Move to XML, add correct margins.
View view = LayoutInflater.from(context).inflate(R.layout.edit_text, null);
final EditText text = (EditText) view.findViewById(android.R.id.edit);
text.setText(cat.getName());
text.setSelection(cat.getName().length());
final int size = context.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
Drawable catIcon = cat.createIcon(this, size, size).loadDrawable(this);
new AlertDialog.Builder(context).setTitle(" ").setIcon(catIcon).setView(view).setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cat.logRename(context);
cat.setName(text.getText().toString().trim());
mPrefs.addCat(cat);
}
}).show();
}
use of android.content.Context in project platform_frameworks_base by android.
the class SectionBreakDocumentsAdapterWrapperTest method setUp.
public void setUp() {
final Context testContext = TestContext.createStorageTestContext(getContext(), AUTHORITY);
DocumentsAdapter.Environment env = new TestEnvironment(testContext);
mModel = new TestModel(AUTHORITY);
mAdapter = new SectionBreakDocumentsAdapterWrapper(env, new ModelBackedDocumentsAdapter(env, new IconHelper(testContext, State.MODE_GRID)));
mModel.addUpdateListener(mAdapter);
}
Aggregations