$mdlhgdialog 回调函数resolve 可以返回一个函数吗

Android技术精髓-理解Context [源码]
时间: 14:58:06
Android技术-理解Context [源码]
Context类是一个类,定义应用程序环境的全局信息,它允许访问应用程序特定的资源和类,以及最新的电话应用程序的操作,例如:&launching
activities, broadcasting and receiving intents 等操作!
图1:Context定义的抽象方法以及全局变量
举个例子:
Context抽象类定义了StartActivity的方法,而是我们的在Activity中定义。
abstract void
startActivities(Intent[]&intents,&Bundle&options)
Launch multiple new activities.
abstract void
startActivities(Intent[]&intents)
Same as&startActivities(Intent[],
Bundle)&with no options specified.
abstract void
startActivity(Intent&intent)
Same as&startActivity(Intent,
Bundle)&with no options specified.
abstract void
startActivity(Intent&intent,&Bundle&options)
Launch a new activity.
在Android源代码中此抽象方法定义如下:
public abstract void startActivity(Intent intent);
public abstract boolean stopService(Intent service);
public abstract boolean bindService(Intent service, ServiceConnection conn,
int flags);
public abstract void unbindService(ServiceConnection conn);
1、它描述的是一个应用程序环境的信息,即上下文。
2、是一个抽象(abstract class)类,Android提供了该抽象类的具体实现类(后面我们会讲到是ContextIml类)。
3、通过它我们可以获取应用程序的资源和类,也包括一些应用级别操作,例如:启动一个Activity,发送,接受Intent信息&等。
Context相关类的继承关系
ContextIml.java类:
该Context类的实现类为ContextIml,该类实现了Context类的功能。请注意,该函数的大部分功能都是直接调用其属性mPackageInfo去完成
* Common implementation of Context API, which provides the base
* context object for Activity and other application components.
class ContextImpl extends Context {
private final static String TAG = &ApplicationContext&;
private final static boolean DEBUG =
private final static boolean DEBUG_ICONS =
//以下选择部分function实现源码贴出&@Override
& & public PackageManager getPackageManager() {
& & & & if (mPackageManager != null) {
& & & & & & return mPackageM
& & & & IPackageManager pm = ActivityThread.getPackageManager();
& & & & if (pm != null) {
& & & & & & // Doesn't matter if we make more than one instance.
& & & & & & return (mPackageManager = new ApplicationPackageManager(this, pm));
& @Override
& & public void setTheme(int resid) {
& & & & mThemeResource =
& & @Override
& & public Resources.Theme getTheme() {
& & & & if (mTheme == null) {
& & & & & & if (mThemeResource == 0) {
& & & & & & & & mThemeResource = com.android.internal.R.style.T
& & & & & & }
& & & & & & mTheme = mResources.newTheme();
& & & & & & mTheme.applyStyle(mThemeResource, true);
& & & & return mT
& private static File makeBackupFile(File prefsFile) {
& & & & return new File(prefsFile.getPath() + &.bak&);
& & public File getSharedPrefsFile(String name) {
& & & & return makeFilename(getPreferencesDir(), name + &.xml&);
& & @Override
& & public SharedPreferences getSharedPreferences(String name, int mode) {
& & & & SharedPreferencesI
& & & & File prefsF
& & & & boolean needInitialLoad =
& & & & synchronized (sSharedPrefs) {
& & & & & & sp = sSharedPrefs.get(name);
& & & & & & if (sp != null && !sp.hasFileChangedUnexpectedly()) {
& & & & & & & &
& & & & & & }
& & & & & & prefsFile = getSharedPrefsFile(name);
& & & & & & if (sp == null) {
& & & & & & & & sp = new SharedPreferencesImpl(prefsFile, mode, null);
& & & & & & & & sSharedPrefs.put(name, sp);
& & & & & & & & needInitialLoad =
& & & & & & }
& & & & synchronized (sp) {
& & & & & & if (needInitialLoad && sp.isLoaded()) {
& & & & & & & & // l another thread handled it
& & & & & & & &
& & & & & & }
& & & & & & File backup = makeBackupFile(prefsFile);
& & & & & & if (backup.exists()) {
& & & & & & & & prefsFile.delete();
& & & & & & & & backup.renameTo(prefsFile);
& & & & & & }
& & & & & & // Debugging
& & & & & & if (prefsFile.exists() && !prefsFile.canRead()) {
& & & & & & & & Log.w(TAG, &Attempt to read preferences file & + prefsFile + & without permission&);
& & & & & & }
& & & & & & Map map =
& & & & & & FileStatus stat = new FileStatus();
& & & & & & if (FileUtils.getFileStatus(prefsFile.getPath(), stat) && prefsFile.canRead()) {
& & & & & & & & try {
& & & & & & & & & & FileInputStream str = new FileInputStream(prefsFile);
& & & & & & & & & & map = XmlUtils.readMapXml(str);
& & & & & & & & & & str.close();
& & & & & & & & } catch (org.xmlpull.v1.XmlPullParserException e) {
& & & & & & & & & & Log.w(TAG, &getSharedPreferences&, e);
& & & & & & & & } catch (FileNotFoundException e) {
& & & & & & & & & & Log.w(TAG, &getSharedPreferences&, e);
& & & & & & & & } catch (IOException e) {
& & & & & & & & & & Log.w(TAG, &getSharedPreferences&, e);
& & & & & & & & }
& & & & & & }
& & & & & & sp.replace(map, stat);
& & private File getPreferencesDir() {
& & & & synchronized (mSync) {
& & & & & & if (mPreferencesDir == null) {
& & & & & & & & mPreferencesDir = new File(getDataDirFile(), &shared_prefs&);
& & & & & & }
& & & & & & return mPreferencesD
& & @Override
& & public FileInputStream openFileInput(String name)
& & & & throws FileNotFoundException {
& & & & File f = makeFilename(getFilesDir(), name);
& & & & return new FileInputStream(f);
& & @Override
& & public FileOutputStream openFileOutput(String name, int mode)
& & & & throws FileNotFoundException {
& & & & final boolean append = (mode&MODE_APPEND) != 0;
& & & & File f = makeFilename(getFilesDir(), name);
& & & & try {
& & & & & & FileOutputStream fos = new FileOutputStream(f, append);
& & & & & & setFilePermissionsFromMode(f.getPath(), mode, 0);
& & & & & &
& & & & } catch (FileNotFoundException e) {
& & & & File parent = f.getParentFile();
& & & & parent.mkdir();
& & & & FileUtils.setPermissions(
& & & & & & parent.getPath(),
& & & & & & FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
& & & & & & -1, -1);
& & & & FileOutputStream fos = new FileOutputStream(f, append);
& & & & setFilePermissionsFromMode(f.getPath(), mode, 0);
& & @Override
& & public boolean deleteFile(String name) {
& & & & File f = makeFilename(getFilesDir(), name);
& & & & return f.delete();
& @Override
& & public File getFilesDir() {
& & & & synchronized (mSync) {
& & & & & & if (mFilesDir == null) {
& & & & & & & & mFilesDir = new File(getDataDirFile(), &files&);
& & & & & & }
& & & & & & if (!mFilesDir.exists()) {
& & & & & & & & if(!mFilesDir.mkdirs()) {
& & & & & & & & & & Log.w(TAG, &Unable to create files directory&);
& & & & & & & & & &
& & & & & & & & }
& & & & & & & & FileUtils.setPermissions(
& & & & & & & & & & & & mFilesDir.getPath(),
& & & & & & & & & & & & FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
& & & & & & & & & & & & -1, -1);
& & & & & & }
& & & & & & return mFilesD
&@Override
& & public void startActivity(Intent intent) {
& & & & if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
& & & & & & throw new AndroidRuntimeException(
& & & & & & & & & & &Calling startActivity() from outside of an Activity &
& & & & & & & & & & + & context requires the FLAG_ACTIVITY_NEW_TASK flag.&
& & & & & & & & & & + & Is this really what you want?&);
& & & & mMainThread.getInstrumentation().execStartActivity(
& & & & & & getOuterContext(), mMainThread.getApplicationThread(), null, null, intent, -1);
& & @Override
& & public void sendBroadcast(Intent intent, String receiverPermission) {
& & & & String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
& & & & try {
& & & & & & ActivityManagerNative.getDefault().broadcastIntent(
& & & & & & & & mMainThread.getApplicationThread(), intent, resolvedType, null,
& & & & & & & & Activity.RESULT_OK, null, null, receiverPermission, false, false);
& & & & } catch (RemoteException e) {
& &@Override
& & public ComponentName startService(Intent service) {
& & & & try {
& & & & & & ComponentName cn = ActivityManagerNative.getDefault().startService(
& & & & & & & & mMainThread.getApplicationThread(), service,
& & & & & & & & service.resolveTypeIfNeeded(getContentResolver()));
& & & & & & if (cn != null && cn.getPackageName().equals(&!&)) {
& & & & & & & & throw new SecurityException(
& & & & & & & & & & & & &Not allowed to start service & + service
& & & & & & & & & & & & + & without permission & + cn.getClassName());
& & & & & & }
& & & & & &
& & & & } catch (RemoteException e) {
& & & & & &
& & @Override
& & public boolean stopService(Intent service) {
& & & & try {
& & & & & & int res = ActivityManagerNative.getDefault().stopService(
& & & & & & & & mMainThread.getApplicationThread(), service,
& & & & & & & & service.resolveTypeIfNeeded(getContentResolver()));
& & & & & & if (res & 0) {
& & & & & & & & throw new SecurityException(
& & & & & & & & & & & & &Not allowed to stop service & + service);
& & & & & & }
& & & & & & return res != 0;
& & & & } catch (RemoteException e) {
& & & & & &
& & @Override
& & public boolean bindService(Intent service, ServiceConnection conn,
& & & & & & int flags) {
& & & & IServiceC
& & & & if (mPackageInfo != null) {
& & & & & & sd = mPackageInfo.getServiceDispatcher(conn, getOuterContext(),
& & & & & & & & & & mMainThread.getHandler(), flags);
& & & & } else {
& & & & & & throw new RuntimeException(&Not supported in system context&);
& & & & try {
& & & & & & int res = ActivityManagerNative.getDefault().bindService(
& & & & & & & & mMainThread.getApplicationThread(), getActivityToken(),
& & & & & & & & service, service.resolveTypeIfNeeded(getContentResolver()),
& & & & & & & & sd, flags);
& & & & & & if (res & 0) {
& & & & & & & & throw new SecurityException(
& & & & & & & & & & & & &Not allowed to bind to service & + service);
& & & & & & }
& & & & & & return res != 0;
& & & & } catch (RemoteException e) {
& & & & & &
& & @Override
& & public void unbindService(ServiceConnection conn) {
& & & & if (mPackageInfo != null) {
& & & & & & IServiceConnection sd = mPackageInfo.forgetServiceDispatcher(
& & & & & & & & & & getOuterContext(), conn);
& & & & & & try {
& & & & & & & & ActivityManagerNative.getDefault().unbindService(sd);
& & & & & & } catch (RemoteException e) {
& & & & & & }
& & & & } else {
& & & & & & throw new RuntimeException(&Not supported in system context&);
& &&@Override
& & public Object getSystemService(String name) {
& & & & if (WINDOW_SERVICE.equals(name)) {
& & & & & & return WindowManagerImpl.getDefault();
& & & & } else if (LAYOUT_INFLATER_SERVICE.equals(name)) {
& & & & & & synchronized (mSync) {
& & & & & & & & LayoutInflater inflater = mLayoutI
& & & & & & & & if (inflater != null) {
& & & & & & & & & &
& & & & & & & & }
& & & & & & & & mLayoutInflater = inflater =
& & & & & & & & & & PolicyManager.makeNewLayoutInflater(getOuterContext());
& & & & & & & &
& & & & & & }
& & & & } else if (ACTIVITY_SERVICE.equals(name)) {
& & & & & & return getActivityManager();
& & & & } else if (INPUT_METHOD_SERVICE.equals(name)) {
& & & & & & return InputMethodManager.getInstance(this);
& & & & } else if (ALARM_SERVICE.equals(name)) {
& & & & & & return getAlarmManager();
& & & & } else if (ACCOUNT_SERVICE.equals(name)) {
& & & & & & return getAccountManager();
& & & & } else if (POWER_SERVICE.equals(name)) {
& & & & & & return getPowerManager();
& & & & } else if (CONNECTIVITY_SERVICE.equals(name)) {
& & & & & & return getConnectivityManager();
& & & & } else if (THROTTLE_SERVICE.equals(name)) {
& & & & & & return getThrottleManager();
& & & & } else if (WIFI_SERVICE.equals(name)) {
& & & & & & return getWifiManager();
& & & & } else if (NOTIFICATION_SERVICE.equals(name)) {
& & & & & & return getNotificationManager();
& & & & } else if (KEYGUARD_SERVICE.equals(name)) {
& & & & & & return new KeyguardManager();
& & & & } else if (ACCESSIBILITY_SERVICE.equals(name)) {
& & & & & & return AccessibilityManager.getInstance(this);
& & & & } else if (LOCATION_SERVICE.equals(name)) {
& & & & & & return getLocationManager();
& & & & } else if (SEARCH_SERVICE.equals(name)) {
& & & & & & return getSearchManager();
& & & & } else if (SENSOR_SERVICE.equals(name)) {
& & & & & & return getSensorManager();
& & & & } else if (STORAGE_SERVICE.equals(name)) {
& & & & & & return getStorageManager();
& & & & } else if (VIBRATOR_SERVICE.equals(name)) {
& & & & & & return getVibrator();
& & & & } else if (STATUS_BAR_SERVICE.equals(name)) {
& & & & & & synchronized (mSync) {
& & & & & & & & if (mStatusBarManager == null) {
& & & & & & & & & & mStatusBarManager = new StatusBarManager(getOuterContext());
& & & & & & & & }
& & & & & & & & return mStatusBarM
& & & & & & }
& & & & } else if (AUDIO_SERVICE.equals(name)) {
& & & & & & return getAudioManager();
& & & & } else if (TELEPHONY_SERVICE.equals(name)) {
& & & & & & return getTelephonyManager();
& & & & } else if (CLIPBOARD_SERVICE.equals(name)) {
& & & & & & return getClipboardManager();
& & & & } else if (WALLPAPER_SERVICE.equals(name)) {
& & & & & & return getWallpaperManager();
& & & & } else if (DROPBOX_SERVICE.equals(name)) {
& & & & & & return getDropBoxManager();
& & & & } else if (DEVICE_POLICY_SERVICE.equals(name)) {
& & & & & & return getDevicePolicyManager();
& & & & } else if (UI_MODE_SERVICE.equals(name)) {
& & & & & & return getUiModeManager();
& & & & } else if (DOWNLOAD_SERVICE.equals(name)) {
& & & & & & return getDownloadManager();
& & & & } else if (NFC_SERVICE.equals(name)) {
& & & & & & return getNfcManager();
ContextWrapper类&:该类只是对Context类的一种,该类的构造函数包含了一个真正的Context引用,即ContextIml对象源码:public class ContextWrapper extends Context {
Context mB
public ContextWrapper(Context base) {
* Set the base context for this ContextWrapper.
All calls will then be
* delegated to the base context.
* IllegalStateException if a base context has already been set.
* @param base The new base context for this wrapper.
protected void attachBaseContext(Context base) {
if (mBase != null) {
throw new IllegalStateException(&Base context already set&);
* @return the base context as set by the constructor or setBaseContext
public Context getBaseContext() {
public AssetManager getAssets() {
return mBase.getAssets();
public Resources getResources()
return mBase.getResources();
public PackageManager getPackageManager() {
return mBase.getPackageManager();
public ContentResolver getContentResolver() {
return mBase.getContentResolver();
public Looper getMainLooper() {
return mBase.getMainLooper();
public Context getApplicationContext() {
return mBase.getApplicationContext();
public void setTheme(int resid) {
mBase.setTheme(resid);
public Resources.Theme getTheme() {
return mBase.getTheme();
public ClassLoader getClassLoader() {
return mBase.getClassLoader();
public String getPackageName() {
return mBase.getPackageName();
public ApplicationInfo getApplicationInfo() {
return mBase.getApplicationInfo();
public String getPackageResourcePath() {
return mBase.getPackageResourcePath();
public String getPackageCodePath() {
return mBase.getPackageCodePath();
/** @hide */
public File getSharedPrefsFile(String name) {
return mBase.getSharedPrefsFile(name);
public SharedPreferences getSharedPreferences(String name, int mode) {
return mBase.getSharedPreferences(name, mode);
public FileInputStream openFileInput(String name)
throws FileNotFoundException {
return mBase.openFileInput(name);
public FileOutputStream openFileOutput(String name, int mode)
throws FileNotFoundException {
return mBase.openFileOutput(name, mode);
public boolean deleteFile(String name) {
return mBase.deleteFile(name);
ContextThemeWrapper类&:
该类内部包含了(Theme)相关的接口,即android:theme属性指定的。只有Activity需要主题,Service不需要主题, 所以Service直接继承于ContextWrapper类。
* A ContextWrapper that allows you to modify the theme from what is in the
* wrapped context.
public class ContextThemeWrapper extends ContextWrapper {
private Context mB
private int mThemeR
private Resources.Theme mT
private LayoutInflater mI
public ContextThemeWrapper() {
super(null);
public ContextThemeWrapper(Context base, int themeres) {
super(base);
mThemeResource =
@Override protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
mBase = newB
@Override public void setTheme(int resid) {
mThemeResource =
initializeTheme();
@Override public Resources.Theme getTheme() {
if (mTheme != null) {
if (mThemeResource == 0) {
mThemeResource = com.android.internal.R.style.T
initializeTheme();
@Override public Object getSystemService(String name) {
if (LAYOUT_INFLATER_SERVICE.equals(name)) {
if (mInflater == null) {
mInflater = LayoutInflater.from(mBase).cloneInContext(this);
return mBase.getSystemService(name);
* Called by {@link #setTheme} and {@link #getTheme} to apply a theme
* resource to the current Theme object.
Can override to change the
* default (simple) behavior.
This method will not be called in multiple
* threads simultaneously.
* @param theme The Theme object being modified.
* @param resid The theme style resource being applied to &var&theme&/var&.
* @param first Set to true if this is the first time a style is being
applied to &var&theme&/var&.
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
theme.applyStyle(resid, true);
private void initializeTheme() {
final boolean first = mTheme ==
if (first) {
mTheme = getResources().newTheme();
Resources.Theme theme = mBase.getTheme();
if (theme != null) {
mTheme.setTo(theme);
onApplyThemeResource(mTheme, mThemeResource, first);
Activity类 、Service类 、Application类上都是Context子类。
Activity类源码(部分):
public class Activity extends ContextThemeWrapper
implements LayoutInflater.Factory,
Window.Callback, KeyEvent.Callback,
OnCreateContextMenuListener, ComponentCallbacks {
private static final String TAG = &Activity&;& public static long getInstanceCount() {
& & & & return sInstanceC
& & /** Return the intent that started this activity. */
& & public Intent getIntent() {
& & & & return mI
& & &* Change the intent returned by {@link #getIntent}. &This holds a&
& & &* reference it does not copy it. &Often used in&
& & &* conjunction with {@link #onNewIntent}.&
& & &* @param newIntent The new Intent object to return from getIntent&
& & &* @see #getIntent
& & &* @see #onNewIntent
& & public void setIntent(Intent newIntent) {
& & & & mIntent = newI
& & /** Return the application that owns this activity. */
& & public final Application getApplication() {
& & & & return mA
& & /** Is this activity embedded inside of another activity? */
& & public final boolean isChild() {
& & & & return mParent !=
& & /** Return the parent activity if this view is an embedded child. */
& & public final Activity getParent() {
& & & & return mP
& & /** Retrieve the window manager for showing custom windows. */
& & public WindowManager getWindowManager() {
& & & & return mWindowM
& & &* Called when the activity is starting. &This is where most initialization
& & &* should go: calling {@link #setContentView(int)} to inflate the
& & &* activity's UI, using {@link #findViewById} to programmatically interact
& & &* with widgets in the UI, calling
& & &* {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve
& & &* cursors for data being displayed, etc.
& & &* &p&You can call {@link #finish} from within this function, in
& & &* which case onDestroy() will be immediately called without any of the rest
& & &* of the activity lifecycle ({@link #onStart}, {@link #onResume},
& & &* {@link #onPause}, etc) executing.
& & &* &p&&em&Derived classes must call through to the super class's
& & &* implementation of this method. &If they do not, an exception will be
& & &* thrown.&/em&&/p&
& & &* @param savedInstanceState If the activity is being re-initialized after
& & &* & & previously being shut down then this Bundle contains the data it most
& & &* & & recently supplied in {@link #onSaveInstanceState}. &&b&&i&Note: Otherwise it is null.&/i&&/b&
& & &* @see #onStart
& & &* @see #onSaveInstanceState
& & &* @see #onRestoreInstanceState
& & &* @see #onPostCreate
& & protected void onCreate(Bundle savedInstanceState) {
& & & & mVisibleFromClient = !mWindow.getWindowStyle().getBoolean(
& & & & & & & & com.android.internal.R.styleable.Window_windowNoDisplay, false);
& & & & mCalled =
private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) {
& & & & final Dialog dialog = onCreateDialog(dialogId, args);
& & & & if (dialog == null) {
& & & & & &
& & & & dialog.dispatchOnCreate(state);
& & }& & protected void onDestroy() {
& & & & mCalled =
& & & & // dismiss any dialogs we are managing.
& & & & if (mManagedDialogs != null) {
& & & & & & final int numDialogs = mManagedDialogs.size();
& & & & & & for (int i = 0; i & numD i++) {
& & & & & & & & final ManagedDialog md = mManagedDialogs.valueAt(i);
& & & & & & & & if (md.mDialog.isShowing()) {
& & & & & & & & & & md.mDialog.dismiss();
& & & & & & & & }
& & & & & & }
& & & & & & mManagedDialogs =
& & & & // close any cursors we are managing.
& & & & synchronized (mManagedCursors) {
& & & & & & int numCursors = mManagedCursors.size();
& & & & & & for (int i = 0; i & numC i++) {
& & & & & & & & ManagedCursor c = mManagedCursors.get(i);
& & & & & & & & if (c != null) {
& & & & & & & & & & c.mCursor.close();
& & & & & & & & }
& & & & & & }
& & & & & & mManagedCursors.clear();
& & & & // Close any open search dialog
& & & & if (mSearchManager != null) {
& & & & & & mSearchManager.stopSearch();
& & &* Called when a key was pressed down and not handled by any of the views
& & &* inside of the activity. So, for example, key presses while the cursor&
& & &* is inside a TextView will not trigger the event (unless it is a navigation
& & &* to another object) because TextView handles its own key presses.
& & &* &p&If the focused view didn't want this event, this method is called.
& & &* &p&The default implementation takes care of {@link KeyEvent#KEYCODE_BACK}
& & &* by calling {@link #onBackPressed()}, though the behavior varies based
& & &* on the application compatibility mode: for
& & &* {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications,
& & &* it will set up the dispatch to call {@link #onKeyUp} where the action
& & &* for earlier applications, it will perform the
& & &* action immediately in on-down, as those versions of the platform
& & &* behaved.
& & &* &p&Other additional default key handling may be performed
& & &* if configured with {@link #setDefaultKeyMode}.
& & &* @return Return &code&true&/code& to prevent this event from being propagated
& & &* further, or &code&false&/code& to indicate that you have not handled&
& & &* this event and it should continue to be propagated.
& & &* @see #onKeyUp
& & &* @see android.view.KeyEvent
& & public boolean onKeyDown(int keyCode, KeyEvent event) &{
& & & & if (keyCode == KeyEvent.KEYCODE_BACK) {
& & & & & & if (getApplicationInfo().targetSdkVersion
& & & & & & & & & & &= Build.VERSION_CODES.ECLAIR) {
& & & & & & & & event.startTracking();
& & & & & & } else {
& & & & & & & & onBackPressed();
& & & & & & }
& & & & & &
& & & & if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) {
& & & & & &
& & & & } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) {
& & & & & & if (getWindow().performPanelShortcut(Window.FEATURE_OPTIONS_PANEL,&
& & & & & & & & & & keyCode, event, Menu.FLAG_ALWAYS_PERFORM_CLOSE)) {
& & & & & & & &
& & & & & & }
& & & & & &
& & & & } else {
& & & & & & // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_*
& & & & & & boolean clearSpannable =
& & & & & &
& & & & & & if ((event.getRepeatCount() != 0) || event.isSystem()) {
& & & & & & & & clearSpannable =
& & & & & & & & handled =
& & & & & & } else {
& & & & & & & & handled = TextKeyListener.getInstance().onKeyDown(
& & & & & & & & & & & & null, mDefaultKeySsb, keyCode, event);
& & & & & & & & if (handled && mDefaultKeySsb.length() & 0) {
& & & & & & & & & & // something useable has been typed - dispatch it now.
& & & & & & & & & & final String str = mDefaultKeySsb.toString();
& & & & & & & & & & clearSpannable =
& & & & & & & & & &&
& & & & & & & & & & switch (mDefaultKeyMode) {
& & & & & & & & & & case DEFAULT_KEYS_DIALER:
& & & & & & & & & & & & Intent intent = new Intent(Intent.ACTION_DIAL, &Uri.parse(&tel:& + str));
& & & & & & & & & & & & intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
& & & & & & & & & & & & startActivity(intent); & &
& & & & & & & & & & & &
& & & & & & & & & & case DEFAULT_KEYS_SEARCH_LOCAL:
& & & & & & & & & & & & startSearch(str, false, null, false);
& & & & & & & & & & & &
& & & & & & & & & & case DEFAULT_KEYS_SEARCH_GLOBAL:
& & & & & & & & & & & & startSearch(str, false, null, true);
& & & & & & & & & & & &
& & & & & & & & & & }
& & & & & & & & }
& & & & & & }
& & & & & & if (clearSpannable) {
& & & & & & & & mDefaultKeySsb.clear();
& & & & & & & & mDefaultKeySsb.clearSpans();
& & & & & & & & Selection.setSelection(mDefaultKeySsb,0);
& & & & & & }
& & & & & &
& & &* Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent)
& & &* KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle
& & &* the event).
& & public boolean onKeyLongPress(int keyCode, KeyEvent event) {
& & public boolean onKeyUp(int keyCode, KeyEvent event) {
& & & & if (getApplicationInfo().targetSdkVersion
& & & & & & & & &= Build.VERSION_CODES.ECLAIR) {
& & & & & & if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
& & & & & & & & & & && !event.isCanceled()) {
& & & & & & & & onBackPressed();
& & & & & & & &
& & & & & & }
& & &* Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent)
& & &* KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle
& & &* the event).
& & public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
& & &* Called when the activity has detected the user's press of the back
& & &* key. &The default implementation simply finishes the current activity,
& & &* but you can override this to do whatever you want.
& & public void onBackPressed() {
& & & & finish();
& &&& @Override
& & public void startActivity(Intent intent) {
& & & & startActivityForResult(intent, -1);
& & public void startActivityFromChild(Activity child, Intent intent,&
& & & & & & int requestCode) {
& & & & Instrumentation.ActivityResult ar =
& & & & & & mInstrumentation.execStartActivity(
& & & & & & & & this, mMainThread.getApplicationThread(), mToken, child,
& & & & & & & & intent, requestCode);
& & & & if (ar != null) {
& & & & & & mMainThread.sendActivityResult(
& & & & & & & & mToken, child.mEmbeddedID, requestCode,
& & & & & & & & ar.getResultCode(), ar.getResultData());
& &public void finish() {
& & & & if (mParent == null) {
& & & & & & int resultC
& & & & & & Intent resultD
& & & & & & synchronized (this) {
& & & & & & & & resultCode = mResultC
& & & & & & & & resultData = mResultD
& & & & & & }
& & & & & & if (Config.LOGV) Log.v(TAG, &Finishing self: token=& + mToken);
& & & & & & try {
& & & & & & & & if (ActivityManagerNative.getDefault()
& & & & & & & & & & .finishActivity(mToken, resultCode, resultData)) {
& & & & & & & & & & mFinished =
& & & & & & & & }
& & & & & & } catch (RemoteException e) {
& & & & & & & & // Empty
& & & & & & }
& & & & } else {
& & & & & & mParent.finishFromChild(this);
& public void finishFromChild(Activity child) {
& & & & finish();
& & &* Force finish another activity that you had previously started with
& & &* {@link #startActivityForResult}.
& & &* @param requestCode The request code of the activity that you had
& & &* & & & & & & & & & &given to startActivityForResult(). &If there are multiple
& & &* & & & & & & & & & &activities started with this request code, they
& & &* & & & & & & & & & &will all be finished.
& & public void finishActivity(int requestCode) {
& & & & if (mParent == null) {
& & & & & & try {
& & & & & & & & ActivityManagerNative.getDefault()
& & & & & & & & & & .finishSubActivity(mToken, mEmbeddedID, requestCode);
& & & & & & } catch (RemoteException e) {
& & & & & & & & // Empty
& & & & & & }
& & & & } else {
& & & & & & mParent.finishActivityFromChild(this, requestCode);
$T.total > 0 && $T.page <= $T.pageNum}
{#foreach $T.data as r}
{$T.r.formt_tm}{#if $T.r.nickname}{#else}匿名{#/if}
{$T.r.content}
{#if $T.page > 1 && $T.pageNum > 1)
$T.s_num > 2}
{#for index = $T.s_num to $T.e_num}
$T.pageNum > $T.pageNavSize+ 2 && $T.s_num != $T.pageNum - $T.pageNavSize}
{#if $T.pageNum > 1}
{#if $T.pageNum != $T.page && $T.pageNum > 1}
<a href="javascript:void(0);" page="{$T.page 下一页
您的回应...
也许你感兴趣
(window.slotbydup=window.slotbydup || []).push({
id: '3465635',
container: s,
size: '120,240',
display: 'float'
(C)2012 本站提供的内容来源于广大网络用户,我们不保证内容的正确性。如果转载了您的内容,希望删除的请联系我们!

我要回帖

更多关于 oninitdialog 函数 的文章

 

随机推荐