use of android.content.ContextWrapper in project Phonograph by kabouzeid.
the class MusicPlayerRemote method bindToService.
public static ServiceToken bindToService(@NonNull final Context context, final ServiceConnection callback) {
Activity realActivity = ((Activity) context).getParent();
if (realActivity == null) {
realActivity = (Activity) context;
}
final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
contextWrapper.startService(new Intent(contextWrapper, MusicService.class));
final ServiceBinder binder = new ServiceBinder(callback);
if (contextWrapper.bindService(new Intent().setClass(contextWrapper, MusicService.class), binder, Context.BIND_AUTO_CREATE)) {
mConnectionMap.put(contextWrapper, binder);
return new ServiceToken(contextWrapper);
}
return null;
}
use of android.content.ContextWrapper in project android_packages_apps_Settings by DirtyUnicorns.
the class ThemePreferenceControllerTest method setup.
@Before
public void setup() {
mMockOverlayManager = mock(OverlayManager.class);
mMockPackageManager = mock(PackageManager.class);
mContext = new ContextWrapper(InstrumentationRegistry.getTargetContext()) {
@Override
public PackageManager getPackageManager() {
return mMockPackageManager;
}
};
mPreferenceController = new ThemePreferenceController(mContext, mMockOverlayManager);
}
use of android.content.ContextWrapper in project LibreraReader by foobnix.
the class MyContextWrapper method wrap.
@TargetApi(24)
public static ContextWrapper wrap(Context context) {
String language = AppState.get().appLang;
final float scale = AppState.get().appFontScale;
Resources res = context.getResources();
Configuration configuration = res.getConfiguration();
configuration.fontScale = scale;
if (AppState.MY_SYSTEM_LANG.equals(AppState.get().appLang)) {
language = Urls.getLangCode();
}
LOG.d("ContextWrapper language", language);
Locale newLocale = new Locale(language);
if (Build.VERSION.SDK_INT >= 24) {
configuration.setLocale(newLocale);
LocaleList localeList = new LocaleList(newLocale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);
context = context.createConfigurationContext(configuration);
} else if (Build.VERSION.SDK_INT >= 17) {
configuration.setLocale(newLocale);
context = context.createConfigurationContext(configuration);
} else {
configuration.locale = newLocale;
res.updateConfiguration(configuration, res.getDisplayMetrics());
}
return new ContextWrapper(context);
}
use of android.content.ContextWrapper in project platform_packages_providers_telephonyprovider by aosp-mirror.
the class TelephonyBackupAgentTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
/* Filling up subscription maps */
mStringWriter = new StringWriter();
mSubId2Phone = new SparseArray<String>();
mSubId2Phone.append(1, "+111111111111111");
mSubId2Phone.append(3, "+333333333333333");
mPhone2SubId = new ArrayMap<>();
for (int i = 0; i < mSubId2Phone.size(); ++i) {
mPhone2SubId.put(mSubId2Phone.valueAt(i), mSubId2Phone.keyAt(i));
}
mCursors = new HashMap<Uri, FakeCursor>();
/* Bind tables to the cursors */
mSmsCursor = new FakeCursor(mSmsTable, TelephonyBackupAgent.SMS_PROJECTION);
mCursors.put(Telephony.Sms.CONTENT_URI, mSmsCursor);
mMmsCursor = new FakeCursor(mMmsTable, TelephonyBackupAgent.MMS_PROJECTION);
mCursors.put(Telephony.Mms.CONTENT_URI, mMmsCursor);
/* Generating test data */
mSmsRows = new ContentValues[4];
mSmsJson = new String[4];
mSmsRows[0] = createSmsRow(1, 1, "+1232132214124", "sms 1", "sms subject", 9087978987l, 999999999, 3, 44, 1, false);
mSmsJson[0] = "{\"self_phone\":\"+111111111111111\",\"address\":" + "\"+1232132214124\",\"body\":\"sms 1\",\"subject\":\"sms subject\",\"date\":" + "\"9087978987\",\"date_sent\":\"999999999\",\"status\":\"3\",\"type\":\"44\"," + "\"recipients\":[\"+123 (213) 2214124\"],\"archived\":true,\"read\":\"0\"}";
mThreadProvider.setArchived(mThreadProvider.getOrCreateThreadId(new String[] { "+123 (213) 2214124" }));
mSmsRows[1] = createSmsRow(2, 2, "+1232132214124", "sms 2", null, 9087978987l, 999999999, 0, 4, 1, true);
mSmsJson[1] = "{\"address\":\"+1232132214124\",\"body\":\"sms 2\",\"date\":" + "\"9087978987\",\"date_sent\":\"999999999\",\"status\":\"0\",\"type\":\"4\"," + "\"recipients\":[\"+123 (213) 2214124\"],\"read\":\"1\"}";
mSmsRows[2] = createSmsRow(4, 3, "+1232221412433 +1232221412444", "sms 3", null, 111111111111l, 999999999, 2, 3, 2, false);
mSmsJson[2] = "{\"self_phone\":\"+333333333333333\",\"address\":" + "\"+1232221412433 +1232221412444\",\"body\":\"sms 3\",\"date\":\"111111111111\"," + "\"date_sent\":" + "\"999999999\",\"status\":\"2\",\"type\":\"3\"," + "\"recipients\":[\"+1232221412433\",\"+1232221412444\"],\"read\":\"0\"}";
mThreadProvider.getOrCreateThreadId(new String[] { "+1232221412433", "+1232221412444" });
mSmsRows[3] = createSmsRow(5, 3, null, "sms 4", null, 111111111111l, 999999999, 2, 3, 5, false);
mSmsJson[3] = "{\"self_phone\":\"+333333333333333\"," + "\"body\":\"sms 4\",\"date\":\"111111111111\"," + "\"date_sent\":" + "\"999999999\",\"status\":\"2\",\"type\":\"3\",\"read\":\"0\"}";
mAllSmsJson = makeJsonArray(mSmsJson);
mMmsRows = new ContentValues[3];
mMmsJson = new String[3];
mMmsRows[0] = createMmsRow(1, /*id*/
1, /*subid*/
"Subject 1", /*subject*/
100, /*subcharset*/
111111, /*date*/
111112, /*datesent*/
3, /*type*/
17, /*version*/
1, /*textonly*/
11, /*msgBox*/
"location 1", /*contentLocation*/
"MMs body 1", /*body*/
111, /*body charset*/
new String[] { "+111 (111) 11111111", "+11121212", "example@example.com", "+999999999" }, /*addresses*/
3, /*threadId*/
false, /*read*/
null, /*smil*/
null, /*attachmentTypes*/
null);
mMmsJson[0] = "{\"self_phone\":\"+111111111111111\",\"sub\":\"Subject 1\"," + "\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":\"3\",\"v\":\"17\"," + "\"msg_box\":\"11\",\"ct_l\":\"location 1\"," + "\"recipients\":[\"+11121212\",\"example@example.com\",\"+999999999\"]," + "\"read\":\"0\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"+111 (111) 11111111\",\"charset\":100}," + "{\"type\":11,\"address\":\"+11121212\",\"charset\":101},{\"type\":12,\"address\":" + "\"example@example.com\",\"charset\":102},{\"type\":13,\"address\":\"+999999999\"" + ",\"charset\":103}],\"mms_body\":\"MMs body 1\",\"mms_charset\":111,\"" + "sub_cs\":\"100\"}";
mThreadProvider.getOrCreateThreadId(new String[] { "+11121212", "example@example.com", "+999999999" });
mMmsRows[1] = createMmsRow(2, /*id*/
2, /*subid*/
null, /*subject*/
100, /*subcharset*/
111122, /*date*/
1111112, /*datesent*/
4, /*type*/
18, /*version*/
1, /*textonly*/
222, /*msgBox*/
"location 2", /*contentLocation*/
"MMs body 2", /*body*/
121, /*body charset*/
new String[] { "+7 (333) ", "example@example.com", "+999999999" }, /*addresses*/
4, /*threadId*/
true, /*read*/
null, /*smil*/
null, /*attachmentTypes*/
null);
mMmsJson[1] = "{\"date\":\"111122\",\"date_sent\":\"1111112\",\"m_type\":\"4\"," + "\"v\":\"18\",\"msg_box\":\"222\",\"ct_l\":\"location 2\"," + "\"recipients\":[\"example@example.com\",\"+999999999\"]," + "\"read\":\"1\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"+7 (333) \",\"charset\":100}," + "{\"type\":11,\"address\":\"example@example.com\",\"charset\":101}," + "{\"type\":12,\"address\":\"+999999999\",\"charset\":102}]," + "\"mms_body\":\"MMs body 2\",\"mms_charset\":121}";
mThreadProvider.getOrCreateThreadId(new String[] { "example@example.com", "+999999999" });
mMmsRows[2] = createMmsRow(9, /*id*/
3, /*subid*/
"Subject 10", /*subject*/
10, /*subcharset*/
111133, /*date*/
1111132, /*datesent*/
5, /*type*/
19, /*version*/
1, /*textonly*/
333, /*msgBox*/
null, /*contentLocation*/
"MMs body 3", /*body*/
131, /*body charset*/
new String[] { "333 333333333333", "+1232132214124" }, /*addresses*/
1, /*threadId*/
false, /*read*/
null, /*smil*/
null, /*attachmentTypes*/
null);
mMmsJson[2] = "{\"self_phone\":\"+333333333333333\",\"sub\":\"Subject 10\"," + "\"date\":\"111133\",\"date_sent\":\"1111132\",\"m_type\":\"5\",\"v\":\"19\"," + "\"msg_box\":\"333\"," + "\"recipients\":[\"+123 (213) 2214124\"],\"archived\":true," + "\"read\":\"0\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"333 333333333333\",\"charset\":100}," + "{\"type\":11,\"address\":\"+1232132214124\",\"charset\":101}]," + "\"mms_body\":\"MMs body 3\",\"mms_charset\":131," + "\"sub_cs\":\"10\"}";
mAllMmsJson = makeJsonArray(mMmsJson);
mMmsAttachmentRows = new ContentValues[1];
mMmsAttachmentJson = new String[1];
mMmsAttachmentRows[0] = createMmsRow(1, /*id*/
1, /*subid*/
"Subject 1", /*subject*/
100, /*subcharset*/
111111, /*date*/
111112, /*datesent*/
3, /*type*/
17, /*version*/
0, /*textonly*/
11, /*msgBox*/
"location 1", /*contentLocation*/
"MMs body 1", /*body*/
111, /*body charset*/
new String[] { "+111 (111) 11111111", "+11121212", "example@example.com", "+999999999" }, /*addresses*/
3, /*threadId*/
false, /*read*/
"<smil><head><layout><root-layout/>" + "<region id='Image' fit='meet' top='0' left='0' height='100%'" + " width='100%'/></layout></head><body><par dur='5000ms'>" + "<img src='image000000.jpg' region='Image' /></par></body></smil>", new String[] { "image/jpg" }, /*attachmentTypes*/
new String[] { "GreatPict.jpg" });
mMmsAttachmentJson[0] = "{\"self_phone\":\"+111111111111111\",\"sub\":\"Subject 1\"," + "\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":\"3\",\"v\":\"17\"," + "\"msg_box\":\"11\",\"ct_l\":\"location 1\"," + "\"recipients\":[\"+11121212\",\"example@example.com\",\"+999999999\"]," + "\"read\":\"0\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"+111 (111) 11111111\",\"charset\":100}," + "{\"type\":11,\"address\":\"+11121212\",\"charset\":101},{\"type\":12,\"address\":" + "\"example@example.com\",\"charset\":102},{\"type\":13,\"address\":\"+999999999\"" + ",\"charset\":103}],\"mms_body\":\"MMs body 1\",\"mms_charset\":111,\"" + "sub_cs\":\"100\"}";
mMmsAllAttachmentJson = makeJsonArray(mMmsAttachmentJson);
ContentProvider contentProvider = new MockContentProvider() {
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (mCursors.containsKey(uri)) {
FakeCursor fakeCursor = mCursors.get(uri);
if (projection != null) {
fakeCursor.setProjection(projection);
}
fakeCursor.nextRow = 0;
return fakeCursor;
}
fail("No cursor for " + uri.toString());
return null;
}
};
mMockContentResolver.addProvider("sms", contentProvider);
mMockContentResolver.addProvider("mms", contentProvider);
mMockContentResolver.addProvider("mms-sms", mThreadProvider);
mTelephonyBackupAgent = new TelephonyBackupAgent();
mTelephonyBackupAgent.attach(new ContextWrapper(getContext()) {
@Override
public ContentResolver getContentResolver() {
return mMockContentResolver;
}
});
mTelephonyBackupAgent.clearSharedPreferences();
mTelephonyBackupAgent.setContentResolver(mMockContentResolver);
mTelephonyBackupAgent.setSubId(mSubId2Phone, mPhone2SubId);
}
use of android.content.ContextWrapper in project CameraKit-Android by flurgle.
the class CameraView method requestPermissions.
private void requestPermissions(boolean requestCamera, boolean requestAudio) {
Activity activity = null;
Context context = getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
activity = (Activity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
List<String> permissions = new ArrayList<>();
if (requestCamera)
permissions.add(Manifest.permission.CAMERA);
if (requestAudio)
permissions.add(Manifest.permission.RECORD_AUDIO);
if (activity != null) {
ActivityCompat.requestPermissions(activity, permissions.toArray(new String[permissions.size()]), CameraKit.Constants.PERMISSION_REQUEST_CAMERA);
}
}
Aggregations