android.content.ComponentCallbacks Java Examples

The following examples show how to use android.content.ComponentCallbacks. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: atlas   Author: alibaba   File: FrameworkLifecycleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void started() {
     RuntimeVariables.androidApplication.registerActivityLifecycleCallbacks(new ActivityLifeCycleObserver());
     RuntimeVariables.androidApplication.registerComponentCallbacks(new ComponentCallbacks() {
         @Override
         public void onConfigurationChanged(Configuration newConfig) {
             if (RuntimeVariables.delegateResources != null) {
                 RuntimeVariables.delegateResources.updateConfiguration(newConfig, RuntimeVariables.delegateResources.getDisplayMetrics());
             }
         }

         @Override
         public void onLowMemory() {

         }
     });


}
 
Example #2
Source Project: Hangar   Author: corcoran   File: ColorPickerDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
public ColorPickerDialog(Context context, int initialColor) {
super(context);
      context.registerComponentCallbacks(new ComponentCallbacks() {
         @Override
         public void onConfigurationChanged(Configuration newConfig) {
             setUp(mOldColor.getColor(), mNewColor.getColor());
             setAlphaSliderVisible(mAlphaSliderEnabled);
             setHexValueEnabled(mHexValueEnabled);
         }
         @Override
         public void onLowMemory() {
         }
      });

      init(initialColor);
  }
 
Example #3
Source Project: WanAndroid   Author: chejdj   File: DisplayUtils.java    License: MIT License 5 votes vote down vote up
public static void setCustomDensity(@NonNull Activity activity, @NonNull final Application application) {
    DisplayMetrics appDisplayMetrics = application.getResources().getDisplayMetrics();
    if (sNoncompatDensity == 0) {
        sNoncompatDensity = appDisplayMetrics.density;
        sNoncompatScaledDensity = appDisplayMetrics.scaledDensity;
        // 防止系统切换后不起作用
        application.registerComponentCallbacks(new ComponentCallbacks() {
            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                if (newConfig != null && newConfig.fontScale > 0) {
                    sNoncompatScaledDensity = application.getResources().getDisplayMetrics().scaledDensity;
                }
            }

            @Override
            public void onLowMemory() {

            }
        });
    }
    float targetDensity = appDisplayMetrics.widthPixels / 360;
    // 防止字体变小
    float targetScaleDensity = targetDensity * (sNoncompatScaledDensity / sNoncompatDensity);
    int targetDensityDpi = (int) (160 * targetDensity);

    appDisplayMetrics.density = targetDensity;
    appDisplayMetrics.scaledDensity = targetScaleDensity;
    appDisplayMetrics.densityDpi = targetDensityDpi;

    final DisplayMetrics activityDisplayMetrics = activity.getResources().getDisplayMetrics();
    activityDisplayMetrics.density = targetDensity;
    activityDisplayMetrics.scaledDensity = targetScaleDensity;
    activityDisplayMetrics.densityDpi = targetDensityDpi;
}
 
Example #4
Source Project: android_9.0.0_r45   Author: lulululbj   File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@CallSuper
public void onConfigurationChanged(Configuration newConfig) {
    Object[] callbacks = collectComponentCallbacks();
    if (callbacks != null) {
        for (int i=0; i<callbacks.length; i++) {
            ((ComponentCallbacks)callbacks[i]).onConfigurationChanged(newConfig);
        }
    }
}
 
Example #5
Source Project: android_9.0.0_r45   Author: lulululbj   File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@CallSuper
public void onLowMemory() {
    Object[] callbacks = collectComponentCallbacks();
    if (callbacks != null) {
        for (int i=0; i<callbacks.length; i++) {
            ((ComponentCallbacks)callbacks[i]).onLowMemory();
        }
    }
}
 
Example #6
Source Project: YCAudioPlayer   Author: yangchong211   File: DensityUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setDensity(@NonNull Application application) {
    //获取application的DisplayMetrics
    //DisplayMetrics 类提供了一种关于显示的通用信息,如显示大小,分辨率和字体。
    appDisplayMetrics = application.getResources().getDisplayMetrics();
    //获取状态栏高度
    barHeight = StatusBarUtils.getStatusBarHeight(application);

    if (appDensity == 0) {
        //初始化的时候赋值
        appDensity = appDisplayMetrics.density;
        appScaledDensity = appDisplayMetrics.scaledDensity;

        //添加字体变化的监听
        application.registerComponentCallbacks(new ComponentCallbacks() {
            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                //字体改变后,将appScaledDensity重新赋值
                if (newConfig != null && newConfig.fontScale > 0) {
                    appScaledDensity = BaseApplication.getInstance().getResources()
                            .getDisplayMetrics().scaledDensity;
                }
            }

            @Override
            public void onLowMemory() {

            }
        });
    }
}
 
Example #7
Source Project: Collection-Android   Author: usernameyangyan   File: Density.java    License: MIT License 5 votes vote down vote up
/**
 * 设计稿的宽度,以dp为单位,后面需要以f(浮点型)比如375f
 * @param application
 * @param width
 */
public static void setDensity(@NonNull final Application application, float width) {
    appDisplayMetrics = application.getResources().getDisplayMetrics();
    WIDTH = width;
    registerActivityLifecycleCallbacks(application);

    if (appDensity == 0) {
        //初始化的时候赋值
        appDensity = appDisplayMetrics.density;
        appScaledDensity = appDisplayMetrics.scaledDensity;

        //添加字体变化的监听
        application.registerComponentCallbacks(new ComponentCallbacks() {
            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                //字体改变后,将appScaledDensity重新赋值
                if (newConfig != null && newConfig.fontScale > 0) {
                    appScaledDensity = application.getResources().getDisplayMetrics().scaledDensity;
                }
            }

            @Override
            public void onLowMemory() {
            }
        });
    }
}
 
Example #8
Source Project: HaoReader   Author: Invinciblelee   File: DensityAdaption.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void setCustomDensity(@NonNull AppCompatActivity activity, @NonNull final Application application) {
    final DisplayMetrics appDisplayMetrics = application.getResources().getDisplayMetrics();

    if (sNonCompatDensity == 0) {
        sNonCompatDensity = appDisplayMetrics.density;
        sNonCompatScaledDensity = appDisplayMetrics.scaledDensity;
        application.registerComponentCallbacks(new ComponentCallbacks() {
            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                if (newConfig != null && newConfig.fontScale > 0) {
                    sNonCompatScaledDensity = application.getResources().getDisplayMetrics().scaledDensity;
                }
            }

            @Override
            public void onLowMemory() {

            }
        });
    }

    final float targetDensity;
    Configuration configuration = activity.getResources().getConfiguration(); //获取设置的配置信息
    if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
        targetDensity = appDisplayMetrics.widthPixels / 360f;
    } else {
        targetDensity = appDisplayMetrics.heightPixels / 640f;
    }
    final float targetScaledDensity = targetDensity * (sNonCompatScaledDensity / sNonCompatDensity);
    final int targetDensityDpi = (int) (160 * targetDensity);

    appDisplayMetrics.density = targetDensity;
    appDisplayMetrics.scaledDensity = targetScaledDensity;
    appDisplayMetrics.densityDpi = targetDensityDpi;

    final DisplayMetrics activityDisplayMetrics = activity.getResources().getDisplayMetrics();
    activityDisplayMetrics.density = targetDensity;
    activityDisplayMetrics.scaledDensity = targetScaledDensity;
    activityDisplayMetrics.densityDpi = targetDensityDpi;
}
 
Example #9
Source Project: delion   Author: derry   File: UmaSessionStats.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts a new session for logging.
 * @param tabModelSelector A TabModelSelector instance for recording tab counts on page loads.
 * If null, UmaSessionStats does not record page loads and tab counts.
 */
public void startNewSession(TabModelSelector tabModelSelector) {
    ensureNativeInitialized();

    mTabModelSelector = tabModelSelector;
    if (mTabModelSelector != null) {
        mComponentCallbacks = new ComponentCallbacks() {
            @Override
            public void onLowMemory() {
                // Not required
            }

            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                mKeyboardConnected = newConfig.keyboard != Configuration.KEYBOARD_NOKEYS;
            }
        };
        mContext.registerComponentCallbacks(mComponentCallbacks);
        mKeyboardConnected = mContext.getResources().getConfiguration()
                .keyboard != Configuration.KEYBOARD_NOKEYS;
        mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelector) {
            @Override
            public void onPageLoadFinished(Tab tab) {
                recordPageLoadStats(tab);
            }
        };
    }

    nativeUmaResumeSession(sNativeUmaSessionStats);
    NetworkChangeNotifier.addConnectionTypeObserver(this);
    updatePreferences();
    updateMetricsServiceState();
}
 
Example #10
Source Project: AndroidChromium   Author: JackyAndroid   File: UmaSessionStats.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts a new session for logging.
 * @param tabModelSelector A TabModelSelector instance for recording tab counts on page loads.
 * If null, UmaSessionStats does not record page loads and tab counts.
 */
public void startNewSession(TabModelSelector tabModelSelector) {
    ensureNativeInitialized();

    mTabModelSelector = tabModelSelector;
    if (mTabModelSelector != null) {
        mComponentCallbacks = new ComponentCallbacks() {
            @Override
            public void onLowMemory() {
                // Not required
            }

            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                mKeyboardConnected = newConfig.keyboard != Configuration.KEYBOARD_NOKEYS;
            }
        };
        mContext.registerComponentCallbacks(mComponentCallbacks);
        mKeyboardConnected = mContext.getResources().getConfiguration()
                .keyboard != Configuration.KEYBOARD_NOKEYS;
        mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelector) {
            @Override
            public void onPageLoadFinished(Tab tab) {
                recordPageLoadStats(tab);
            }
        };
    }

    nativeUmaResumeSession(sNativeUmaSessionStats);
    updatePreferences();
    updateMetricsServiceState();
}
 
Example #11
Source Project: 365browser   Author: mogoweb   File: UmaSessionStats.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts a new session for logging.
 * @param tabModelSelector A TabModelSelector instance for recording tab counts on page loads.
 * If null, UmaSessionStats does not record page loads and tab counts.
 */
public void startNewSession(TabModelSelector tabModelSelector) {
    ensureNativeInitialized();

    mTabModelSelector = tabModelSelector;
    if (mTabModelSelector != null) {
        mComponentCallbacks = new ComponentCallbacks() {
            @Override
            public void onLowMemory() {
                // Not required
            }

            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                mKeyboardConnected = newConfig.keyboard != Configuration.KEYBOARD_NOKEYS;
            }
        };
        mContext.registerComponentCallbacks(mComponentCallbacks);
        mKeyboardConnected = mContext.getResources().getConfiguration()
                .keyboard != Configuration.KEYBOARD_NOKEYS;
        mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelector) {
            @Override
            public void onPageLoadFinished(Tab tab) {
                recordPageLoadStats(tab);
            }
        };
    }

    nativeUmaResumeSession(sNativeUmaSessionStats);
    updatePreferences();
    updateMetricsServiceState();
    DefaultBrowserInfo.logDefaultBrowserStats();
}
 
Example #12
Source Project: 365browser   Author: mogoweb   File: ViewConfigurationHelper.java    License: Apache License 2.0 5 votes vote down vote up
private void registerListener() {
    ContextUtils.getApplicationContext().registerComponentCallbacks(
            new ComponentCallbacks() {
                @Override
                public void onConfigurationChanged(Configuration configuration) {
                    updateNativeViewConfigurationIfNecessary();
                }

                @Override
                public void onLowMemory() {
                }
            });
}
 
Example #13
Source Project: android-chromium   Author: eduplus   File: DeviceDisplayInfo.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void registerListener() {
    mAppContext.registerComponentCallbacks(
        new ComponentCallbacks() {
            @Override
            public void onConfigurationChanged(Configuration configuration) {
                updateNativeSharedDisplayInfo();
            }

            @Override
            public void onLowMemory() {
            }
    });
}
 
Example #14
Source Project: android-chromium   Author: kevin-smets   File: DeviceDisplayInfo.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void registerListener() {
    mAppContext.registerComponentCallbacks(
        new ComponentCallbacks() {
            @Override
            public void onConfigurationChanged(Configuration configuration) {
                updateNativeSharedDisplayInfo();
            }

            @Override
            public void onLowMemory() {
            }
    });
}
 
Example #15
Source Project: android_9.0.0_r45   Author: lulululbj   File: Application.java    License: Apache License 2.0 4 votes vote down vote up
public void registerComponentCallbacks(ComponentCallbacks callback) {
    synchronized (mComponentCallbacks) {
        mComponentCallbacks.add(callback);
    }
}
 
Example #16
Source Project: android_9.0.0_r45   Author: lulululbj   File: Application.java    License: Apache License 2.0 4 votes vote down vote up
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
    synchronized (mComponentCallbacks) {
        mComponentCallbacks.remove(callback);
    }
}
 
Example #17
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ContextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(14)
public static void registerComponentCallbacks(ComponentCallbacks callback) {
    Base.getContext().registerComponentCallbacks(callback);
}
 
Example #18
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ContextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(14)
public static void unregisterComponentCallbacks(ComponentCallbacks callback) {
    Base.getContext().unregisterComponentCallbacks(callback);
}
 
Example #19
Source Project: BtPlayer   Author: YuntaoWei   File: DelegateApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void registerComponentCallbacks(ComponentCallbacks callback) {
    app.registerComponentCallbacks(callback);
}
 
Example #20
Source Project: BtPlayer   Author: YuntaoWei   File: DelegateApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
    app.unregisterComponentCallbacks(callback);
}
 
Example #21
Source Project: AndroidDownload   Author: roomanl   File: DelegateApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void registerComponentCallbacks(ComponentCallbacks callback) {
    app.registerComponentCallbacks(callback);
}
 
Example #22
Source Project: AndroidDownload   Author: roomanl   File: DelegateApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
    app.unregisterComponentCallbacks(callback);
}
 
Example #23
Source Project: condom   Author: oasisfeng   File: CondomApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override public void registerComponentCallbacks(final ComponentCallbacks callback) {
	if (SDK_INT >= ICE_CREAM_SANDWICH) mApplication.registerComponentCallbacks(callback);
}
 
Example #24
Source Project: condom   Author: oasisfeng   File: CondomApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override public void unregisterComponentCallbacks(final ComponentCallbacks callback) {
	if (SDK_INT >= ICE_CREAM_SANDWICH) mApplication.unregisterComponentCallbacks(callback);
}
 
Example #25
Source Project: AndroidDemo   Author: HBU   File: customApp.java    License: MIT License 4 votes vote down vote up
@Override
public void registerComponentCallbacks(ComponentCallbacks callback) {
    Log.d(TAG, "registerComponentCallbacks");
    super.registerComponentCallbacks(callback);
}
 
Example #26
Source Project: AndroidDemo   Author: HBU   File: customApp.java    License: MIT License 4 votes vote down vote up
@Override
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
    Log.d(TAG, "unregisterComponentCallbacks");
    super.unregisterComponentCallbacks(callback);
}
 
Example #27
Source Project: MiPushFramework   Author: MiPushFramework   File: CondomContext.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override public void registerComponentCallbacks(final ComponentCallbacks callback) {
	if (SDK_INT >= ICE_CREAM_SANDWICH) mApplication.registerComponentCallbacks(callback);
}
 
Example #28
Source Project: MiPushFramework   Author: MiPushFramework   File: CondomContext.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override public void unregisterComponentCallbacks(final ComponentCallbacks callback) {
	if (SDK_INT >= ICE_CREAM_SANDWICH) mApplication.unregisterComponentCallbacks(callback);
}
 
Example #29
Source Project: RxAppState   Author: jenzz   File: FakeApplication.java    License: MIT License 4 votes vote down vote up
@Override
public void registerComponentCallbacks(ComponentCallbacks callback) {
  if (callback instanceof ComponentCallbacks2) {
    componentCallbacks.add((ComponentCallbacks2) callback);
  }
}
 
Example #30
Source Project: RxAppState   Author: jenzz   File: FakeApplication.java    License: MIT License 4 votes vote down vote up
@Override
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
  if (callback instanceof ComponentCallbacks2) {
    componentCallbacks.remove(callback);
  }
}