use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project platform_frameworks_base by android.
the class Spinner method onRestoreInstanceState.
@Override
public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
if (ss.showDropdown) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto != null) {
final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (!mPopup.isShowing()) {
mPopup.show(getTextDirection(), getTextAlignment());
}
final ViewTreeObserver vto = getViewTreeObserver();
if (vto != null) {
vto.removeOnGlobalLayoutListener(this);
}
}
};
vto.addOnGlobalLayoutListener(listener);
}
}
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project JamsMusicPlayer by psaravan.
the class LauncherActivity method onCreate.
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppThemeNoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mContext = this;
mActivity = this;
mApp = (Common) mContext.getApplicationContext();
mHandler = new Handler();
//Increment the start count. This value will be used to determine when the library should be rescanned.
int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();
//Save the dimensions of the layout for later use on KitKat devices.
final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
try {
int[] screenDimens = new int[2];
int screenHeight = 0;
int screenWidth = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
//API levels 14, 15 and 16.
screenDimens = getTrueDeviceResolution();
screenWidth = screenDimens[0];
screenHeight = screenDimens[1];
} else {
//API levels 17+.
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
screenHeight = metrics.heightPixels;
screenWidth = metrics.widthPixels;
}
int layoutHeight = launcherRootView.getHeight();
int layoutWidth = launcherRootView.getWidth();
int extraHeight = screenHeight - layoutHeight;
int extraWidth = screenWidth = layoutWidth;
mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight).commit();
mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();
} catch (Exception e) {
e.printStackTrace();
}
}
});
//Build the music library based on the user's scan frequency preferences.
int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
//Launch the appropriate activity based on the "FIRST RUN" flag.
if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {
//Create the default Playlists directory if it doesn't exist.
File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
playlistsDirectory.mkdir();
}
//Disable equalizer for HTC devices by default.
if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true && Build.PRODUCT.contains("HTC")) {
mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
}
//Send out a test broadcast to initialize the homescreen/lockscreen widgets.
sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
} else if (mApp.isBuildingLibrary()) {
buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);
buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
buildingLibraryInfoText.setPaintFlags(buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
buildingLibraryMainText.setPaintFlags(buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
buildingLibraryMainText.setText(R.string.jams_is_building_library);
buildingLibraryLayout.setVisibility(View.VISIBLE);
//Initialize the runnable that will fire once the scan process is complete.
mHandler.post(scanFinishedCheckerRunnable);
} else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {
buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);
buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
buildingLibraryInfoText.setPaintFlags(buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
buildingLibraryMainText.setPaintFlags(buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
initScanProcess(0);
} else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true) || (scanFrequency == 0 && mApp.isScanFinished() == false) || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0) || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0) || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0) || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {
buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);
buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
buildingLibraryInfoText.setPaintFlags(buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
buildingLibraryMainText.setPaintFlags(buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
initScanProcess(1);
} else {
//Check if this activity was called from Settings.
if (getIntent().hasExtra("UPGRADE")) {
if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
mExplicitShowTrialFragment = true;
} else {
mExplicitShowTrialFragment = false;
}
}
//initInAppBilling();
launchMainActivity();
}
//Fire away a report to Google Analytics.
try {
if (mApp.isGoogleAnalyticsEnabled() == true) {
EasyTracker easyTracker = EasyTracker.getInstance(this);
easyTracker.send(// Event category (required)
MapBuilder.createEvent(// Event category (required)
"Jams startup.", // Event action (required)
"User started Jams.", // Event label
"User started Jams.", // Event value
null).build());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project 9GAG by Mixiaoxiao.
the class MxxPagerSlidingTabStrip method notifyDataSetChanged.
public void notifyDataSetChanged() {
tabsContainer.removeAllViews();
tabCount = pager.getAdapter().getCount();
for (int i = 0; i < tabCount; i++) {
if (pager.getAdapter() instanceof IconTabProvider) {
addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
} else {
addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
}
}
updateTabStyles();
checkedTabWidths = false;
getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
currentPosition = pager.getCurrentItem();
scrollToChild(currentPosition, 0);
}
});
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android_frameworks_base by ParanoidAndroid.
the class RecentsVerticalScrollView method update.
private void update() {
for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
View v = mLinearLayout.getChildAt(i);
addToRecycledViews(v);
mAdapter.recycleView(v);
}
LayoutTransition transitioner = getLayoutTransition();
setLayoutTransition(null);
mLinearLayout.removeAllViews();
// Once we can clear the data associated with individual item views,
// we can get rid of the removeAllViews() and the code below will
// recycle them.
Iterator<View> recycledViews = mRecycledViews.iterator();
for (int i = 0; i < mAdapter.getCount(); i++) {
View old = null;
if (recycledViews.hasNext()) {
old = recycledViews.next();
recycledViews.remove();
old.setVisibility(VISIBLE);
}
final View view = mAdapter.getView(i, old, mLinearLayout);
if (mPerformanceHelper != null) {
mPerformanceHelper.addViewCallback(view);
}
OnTouchListener noOpListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
};
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mCallback.dismiss();
}
});
// We don't want a click sound when we dimiss recents
view.setSoundEffectsEnabled(false);
OnClickListener launchAppListener = new OnClickListener() {
public void onClick(View v) {
mCallback.handleOnClick(view);
}
};
RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) view.getTag();
final View thumbnailView = holder.thumbnailView;
OnLongClickListener longClickListener = new OnLongClickListener() {
public boolean onLongClick(View v) {
final View anchorView = view.findViewById(R.id.app_description);
mCallback.handleLongPress(view, anchorView, thumbnailView);
return true;
}
};
thumbnailView.setClickable(true);
thumbnailView.setOnClickListener(launchAppListener);
thumbnailView.setOnLongClickListener(longClickListener);
// We don't want to dismiss recents if a user clicks on the app title
// (we also don't want to launch the app either, though, because the
// app title is a small target and doesn't have great click feedback)
final View appTitle = view.findViewById(R.id.app_label);
appTitle.setContentDescription(" ");
appTitle.setOnTouchListener(noOpListener);
final View calloutLine = view.findViewById(R.id.recents_callout_line);
if (calloutLine != null) {
calloutLine.setOnTouchListener(noOpListener);
}
mLinearLayout.addView(view);
}
setLayoutTransition(transitioner);
// Scroll to end after initial layout.
final OnGlobalLayoutListener updateScroll = new OnGlobalLayoutListener() {
public void onGlobalLayout() {
mLastScrollPosition = scrollPositionOfMostRecent();
scrollTo(0, mLastScrollPosition);
final ViewTreeObserver observer = getViewTreeObserver();
if (observer.isAlive()) {
observer.removeOnGlobalLayoutListener(this);
}
}
};
getViewTreeObserver().addOnGlobalLayoutListener(updateScroll);
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android_frameworks_base by ParanoidAndroid.
the class Spinner method onRestoreInstanceState.
@Override
public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
if (ss.showDropdown) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto != null) {
final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (!mPopup.isShowing()) {
mPopup.show(getTextDirection(), getTextAlignment());
}
final ViewTreeObserver vto = getViewTreeObserver();
if (vto != null) {
vto.removeOnGlobalLayoutListener(this);
}
}
};
vto.addOnGlobalLayoutListener(listener);
}
}
}
Aggregations