當前位置: 首頁>>代碼示例>>Java>>正文


Java ContextWrapper類代碼示例

本文整理匯總了Java中android.content.ContextWrapper的典型用法代碼示例。如果您正苦於以下問題:Java ContextWrapper類的具體用法?Java ContextWrapper怎麽用?Java ContextWrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ContextWrapper類屬於android.content包,在下文中一共展示了ContextWrapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolveMethod

import android.content.ContextWrapper; //導入依賴的package包/類
@NonNull
private void resolveMethod(@Nullable Context context, @NonNull String name) {
    while (context != null) {
        try {
            if (!context.isRestricted()) {
                Method method = context.getClass().getMethod(this.mMethodName, new Class[]{View.class});
                if (method != null) {
                    this.mResolvedMethod = method;
                    this.mResolvedContext = context;
                    return;
                }
            }
        } catch (NoSuchMethodException e) {
        }
        if (context instanceof ContextWrapper) {
            context = ((ContextWrapper) context).getBaseContext();
        } else {
            context = null;
        }
    }
    int id = this.mHostView.getId();
    throw new IllegalStateException("Could not find method " + this.mMethodName + "(View) in a parent or ancestor Context for android:onClick " + "attribute defined on view " + this.mHostView.getClass() + (id == -1 ? "" : " with id '" + this.mHostView.getContext().getResources().getResourceEntryName(id) + "'"));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:AppCompatViewInflater.java

示例2: checkOnClickListener

import android.content.ContextWrapper; //導入依賴的package包/類
/**
 * android:onClick doesn't handle views with a ContextWrapper context. This method
 * backports new framework functionality to traverse the Context wrappers to find a
 * suitable target.
 */
private void checkOnClickListener(View view, AttributeSet attrs) {
    final Context context = view.getContext();

    if (!(context instanceof ContextWrapper) ||
            (Build.VERSION.SDK_INT >= 15 && !ViewCompat.hasOnClickListeners(view))) {
        // Skip our compat functionality if: the Context isn't a ContextWrapper, or
        // the view doesn't have an OnClickListener (we can only rely on this on API 15+ so
        // always use our compat code on older devices)
        return;
    }

    final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs);
    final String handlerName = a.getString(0);
    if (handlerName != null) {
        view.setOnClickListener(new DeclaredOnClickListener(view, handlerName));
    }
    a.recycle();
}
 
開發者ID:ximsfei,項目名稱:Android-skin-support,代碼行數:24,代碼來源:SkinCompatViewInflater.java

示例3: getActivity

import android.content.ContextWrapper; //導入依賴的package包/類
/**
 * Get the Activity of a context. This is typically used to determine the hosting activity of a
 * {@link View}
 *
 * @param context The context
 * @return The Activity or throws an Exception if Activity couldnt be determined
 */
@NonNull public static Activity getActivity(@NonNull Context context) {
  if (context == null) {
    throw new NullPointerException("context == null");
  }
  if (context instanceof Activity) {
    return (Activity) context;
  }

  while (context instanceof ContextWrapper) {
    if (context instanceof Activity) {
      return (Activity) context;
    }
    context = ((ContextWrapper) context).getBaseContext();
  }
  throw new IllegalStateException("Could not find the surrounding Activity");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:PresenterManager.java

示例4: wrap

import android.content.ContextWrapper; //導入依賴的package包/類
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String lang = prefs.getString(Constants.PREF_APP_LANGUAGE, "");
    Locale locale = StringUtils.getLocale(lang);
    locale = (locale == null) ? Locale.getDefault() : locale;
    Configuration configuration = context.getResources().getConfiguration();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList localeList = new LocaleList(locale);
        LocaleList.setDefault(localeList);
        Locale.setDefault(locale);
        configuration.setLocale(locale);
        configuration.setLocales(localeList);
        context = context.createConfigurationContext(configuration);

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        configuration.setLocale(locale);
        context = context.createConfigurationContext(configuration);
    } else {
        configuration.locale = locale;
        context.getResources().updateConfiguration(configuration, null);
    }

    return new ShowChatContextWrapper(context);
}
 
開發者ID:ansarisufiyan777,項目名稱:Show_Chat,代碼行數:27,代碼來源:ShowChatContextWrapper.java

示例5: wrap

import android.content.ContextWrapper; //導入依賴的package包/類
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context, String language) {
    Configuration config = context.getResources().getConfiguration();
    Locale sysLocale = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        sysLocale = getSystemLocale(config);
    } else {
        sysLocale = getSystemLocaleLegacy(config);
    }
    if (!language.equals("") && !sysLocale.getLanguage().equals(language)) {
        Locale locale = new Locale(language);
        Locale.setDefault(locale);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            setSystemLocale(config, locale);
        } else {
            setSystemLocaleLegacy(config, locale);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            context = context.createConfigurationContext(config);
        } else {
            context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
        }
    }
    return new MyContextWrapper(context);
}
 
開發者ID:hosamazzam,項目名稱:AndroidChangeLanguage,代碼行數:26,代碼來源:MyContextWrapper.java

示例6: unbindFromService

import android.content.ContextWrapper; //導入依賴的package包/類
/**
 * @param token The {@link ServiceToken} to unbind from
 */
public static void unbindFromService(final ServiceToken token) {
    if (token == null) {
        return;
    }

    final ContextWrapper mContextWrapper = token.mWrappedContext;
    final ServiceBinder mBinder = mConnectionMap.remove(mContextWrapper);
    if (mBinder == null) {
        return;
    }

    mContextWrapper.unbindService(mBinder);
    if (mConnectionMap.isEmpty()) {
        mService = null;
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:20,代碼來源:UploadUtils.java

示例7: unbindFromService

import android.content.ContextWrapper; //導入依賴的package包/類
/**
 * @param token The {@link ServiceToken} to unbind from
 */
public static void unbindFromService(final ServiceToken token) {
    if (token == null) {
        return;
    }

    final ContextWrapper mContextWrapper = token.mWrappedContext;
    final ServiceBinder mBinder = mConnectionMap.remove(mContextWrapper);
    if (mBinder == null) {
        return;
    }

    mContextWrapper.unbindService(mBinder);

    if (mConnectionMap.isEmpty()) {
        mService = null;
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:21,代碼來源:MusicUtils.java

示例8: onCreate

import android.content.ContextWrapper; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_whitelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setElevation(0.0f);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    new Prefs.Builder()
            .setContext(this)
            .setMode(ContextWrapper.MODE_PRIVATE)
            .setPrefsName(getPackageName())
            .setUseDefaultSharedPreference(true)
            .build();
    whitelistArray = Prefs.getOrderedStringSet("whitelistArray", new LinkedHashSet<String>());

    listView = (RecyclerView) findViewById(R.id.listView1);
    RecyclerView.LayoutManager manager = new LinearLayoutManager(this);
    listView.setLayoutManager(manager);
    listView.setHasFixedSize(true);
    listView.setAdapter(new RecyclerAdapter(whitelistArray.toArray(new String[whitelistArray.size()])));
}
 
開發者ID:theblixguy,項目名稱:ScanLinks,代碼行數:26,代碼來源:WhitelistActivity.java

示例9: resolveMethod

import android.content.ContextWrapper; //導入依賴的package包/類
@NonNull
private void resolveMethod(@Nullable Context context, @NonNull String name) {
    while (context != null) {
        try {
            if (!context.isRestricted()) {
                final Method method = context.getClass().getMethod(mMethodName, View.class);
                if (method != null) {
                    mResolvedMethod = method;
                    mResolvedContext = context;
                    return;
                }
            }
        } catch (NoSuchMethodException e) {
            // Failed to find method, keep searching up the hierarchy.
        }

        if (context instanceof ContextWrapper) {
            context = ((ContextWrapper) context).getBaseContext();
        } else {
            // Can't search up the hierarchy, null out and fail.
            context = null;
        }
    }

    final int id = mHostView.getId();
    final String idText = id == View.NO_ID ? "" : " with id '"
            + mHostView.getContext().getResources().getResourceEntryName(id) + "'";
    throw new IllegalStateException("Could not find method " + mMethodName
            + "(View) in a parent or ancestor Context for android:onClick "
            + "attribute defined on view " + mHostView.getClass() + idText);
}
 
開發者ID:ximsfei,項目名稱:Android-skin-support,代碼行數:32,代碼來源:SkinCompatViewInflater.java

示例10: extractActivity

import android.content.ContextWrapper; //導入依賴的package包/類
private Activity extractActivity(Context context) {
  while (true) {
    if (context instanceof Application) {
      return null;
    } else if (context instanceof Activity) {
      return (Activity) context;
    } else if (context instanceof ContextWrapper) {
      Context baseContext = ((ContextWrapper) context).getBaseContext();
      // Prevent Stack Overflow.
      if (baseContext == context) {
        return null;
      }
      context = baseContext;
    } else {
      return null;
    }
  }
}
 
開發者ID:GcsSloop,項目名稱:diycode,代碼行數:19,代碼來源:IMMLeaks.java

示例11: testNullDeviceIdKit

import android.content.ContextWrapper; //導入依賴的package包/類
@Test @SuppressLint("HardwareIds") public void testNullDeviceIdKit() {
	final CondomContext condom = CondomContext.wrap(new ContextWrapper(context), "NullDeviceId",
			new CondomOptions().addKit(new NullDeviceIdKit()));
	final TelephonyManager tm = (TelephonyManager) condom.getSystemService(Context.TELEPHONY_SERVICE);
	assertTrue(condom.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE).getClass().getName().startsWith(NullDeviceIdKit.class.getName()));

	assertPermission(condom, READ_PHONE_STATE, true);

	assertNull(tm.getDeviceId());
	if (SDK_INT >= M) assertNull(tm.getDeviceId(0));
	assertNull(tm.getImei());
	assertNull(tm.getImei(0));
	if (SDK_INT >= O) assertNull(tm.getMeid());
	if (SDK_INT >= O) assertNull(tm.getMeid(0));
	assertNull(tm.getSimSerialNumber());
	assertNull(tm.getLine1Number());
	assertNull(tm.getSubscriberId());
}
 
開發者ID:Trumeet,項目名稱:MiPushFramework,代碼行數:19,代碼來源:CondomKitTest.java

示例12: getAppContext

import android.content.ContextWrapper; //導入依賴的package包/類
Context getAppContext(final String packageName) {
	final Resources resources = getResources(packageName);
	Context context = null;
	try {
		context = getHostContext().createPackageContext(packageName,
				Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
	} catch (PackageManager.NameNotFoundException e) {
		context = getHostContext();
	}
	return new ContextWrapper(context) {
		@Override
		public Resources getResources() {
			return resources;
		}

		@Override
		public String getPackageName() {
			return packageName;
		}
	};
}
 
開發者ID:codehz,項目名稱:container,代碼行數:22,代碼來源:NotificationCompatCompatV14.java

示例13: testInitDifferentEngines

import android.content.ContextWrapper; //導入依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testInitDifferentEngines() throws Exception {
    // Test that concurrently instantiating Cronet context's upon various
    // different versions of the same Android Context does not cause crashes
    // like crbug.com/453845
    mTestFramework = startCronetTestFramework();
    CronetEngine firstEngine =
            new CronetUrlRequestContext(mTestFramework.createCronetEngineBuilder(getContext()));
    CronetEngine secondEngine = new CronetUrlRequestContext(
            mTestFramework.createCronetEngineBuilder(getContext().getApplicationContext()));
    CronetEngine thirdEngine = new CronetUrlRequestContext(
            mTestFramework.createCronetEngineBuilder(new ContextWrapper(getContext())));
    firstEngine.shutdown();
    secondEngine.shutdown();
    thirdEngine.shutdown();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:18,代碼來源:CronetUrlRequestContextTest.java

示例14: extractActivity

import android.content.ContextWrapper; //導入依賴的package包/類
private Activity extractActivity(Context context) {
    while (true) {
        if (context instanceof Application) {
            return null;
        } else if (context instanceof Activity) {
            return (Activity) context;
        } else if (context instanceof ContextWrapper) {
            Context baseContext = ((ContextWrapper) context).getBaseContext();
            // Prevent Stack Overflow.
            if (baseContext == context) {
                return null;
            }
            context = baseContext;
        } else {
            return null;
        }
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:19,代碼來源:IMMLeaks.java

示例15: popFromActivityStack

import android.content.ContextWrapper; //導入依賴的package包/類
public void popFromActivityStack(Activity activity) {
    if(sReminderDialog!=null &&
            (sReminderDialog.getContext()==activity ||
                    (sReminderDialog.getContext() instanceof ContextWrapper && ((ContextWrapper)sReminderDialog.getContext()).getBaseContext()==activity))){
        try{
            sReminderDialog.dismiss();
        }catch (Throwable e){}finally {
            sReminderDialog = null;
        }
    }
    for(int x=0; x<activityList.size(); x++){
        WeakReference<Activity> ref = activityList.get(x);
        if(ref!=null && ref.get()!=null && ref.get()==activity){
            activityList.remove(ref);
        }
    }
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:18,代碼來源:ActivityTaskMgr.java


注:本文中的android.content.ContextWrapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。