List of usage examples for android.view View setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:cn.fantasee.swipwmenulistview.swipelistview.SwipeListViewTouchListener.java
/** * Perform dismiss action/*from www. ja v a 2 s . c om*/ * * @param dismissView View * @param dismissPosition Position of list */ protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) { enableDisableViewGroup((ViewGroup) dismissView, false); final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime); if (doPendingDismiss) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --dismissAnimationRefCount; if (dismissAnimationRefCount == 0) { removePendingDismisses(originalHeight); } } }); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { enableDisableViewGroup((ViewGroup) dismissView, true); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:com.saarang.samples.apps.iosched.ui.BaseActivity.java
/** * Sets up the navigation drawer as appropriate. Note that the nav drawer will be * different depending on whether the attendee indicated that they are attending the * event on-site vs. attending remotely. *///from w w w . ja va 2s . c om private void setupNavDrawer() { // What nav drawer item should be selected? int selfItem = getSelfNavDrawerItem(); mDrawerLayout = (DrawerLayout) findViewById(com.saarang.samples.apps.iosched.R.id.drawer_layout); if (mDrawerLayout == null) { return; } mDrawerLayout.setStatusBarBackgroundColor( getResources().getColor(com.saarang.samples.apps.iosched.R.color.theme_primary_dark)); ScrimInsetsScrollView navDrawer = (ScrimInsetsScrollView) mDrawerLayout .findViewById(com.saarang.samples.apps.iosched.R.id.navdrawer); if (selfItem == NAVDRAWER_ITEM_INVALID) { // do not show a nav drawer if (navDrawer != null) { ((ViewGroup) navDrawer.getParent()).removeView(navDrawer); } mDrawerLayout = null; return; } if (navDrawer != null) { final View chosenAccountContentView = findViewById( com.saarang.samples.apps.iosched.R.id.chosen_account_content_view); final View chosenAccountView = findViewById(com.saarang.samples.apps.iosched.R.id.chosen_account_view); final int navDrawerChosenAccountHeight = getResources().getDimensionPixelSize( com.saarang.samples.apps.iosched.R.dimen.navdrawer_chosen_account_height); navDrawer.setOnInsetsCallback(new ScrimInsetsScrollView.OnInsetsCallback() { @Override public void onInsetsChanged(Rect insets) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) chosenAccountContentView .getLayoutParams(); lp.topMargin = insets.top; chosenAccountContentView.setLayoutParams(lp); ViewGroup.LayoutParams lp2 = chosenAccountView.getLayoutParams(); lp2.height = navDrawerChosenAccountHeight + insets.top; chosenAccountView.setLayoutParams(lp2); } }); } if (mActionBarToolbar != null) { mActionBarToolbar.setNavigationIcon(com.saarang.samples.apps.iosched.R.drawable.ic_drawer); mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mDrawerLayout.openDrawer(Gravity.START); } }); } mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerClosed(View drawerView) { // run deferred action, if we have one if (mDeferredOnDrawerClosedRunnable != null) { mDeferredOnDrawerClosedRunnable.run(); mDeferredOnDrawerClosedRunnable = null; } if (mAccountBoxExpanded) { mAccountBoxExpanded = false; setupAccountBoxToggle(); } onNavDrawerStateChanged(false, false); } @Override public void onDrawerOpened(View drawerView) { onNavDrawerStateChanged(true, false); } @Override public void onDrawerStateChanged(int newState) { onNavDrawerStateChanged(isNavDrawerOpen(), newState != DrawerLayout.STATE_IDLE); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { onNavDrawerSlide(slideOffset); } }); mDrawerLayout.setDrawerShadow(com.saarang.samples.apps.iosched.R.drawable.drawer_shadow, Gravity.START); // populate the nav drawer with the correct items populateNavDrawer(); // When the user runs the app for the first time, we want to land them with the // navigation drawer open. But just the first time. if (!PrefUtils.isWelcomeDone(this)) { // first run of the app starts with the nav drawer open PrefUtils.markWelcomeDone(this); mDrawerLayout.openDrawer(Gravity.START); } }
From source file:android.support.v7ox.widget.Toolbar.java
private void addSystemView(View v, boolean allowHide) { final ViewGroup.LayoutParams vlp = v.getLayoutParams(); final LayoutParams lp; if (vlp == null) { lp = generateDefaultLayoutParams(); } else if (!checkLayoutParams(vlp)) { lp = generateLayoutParams(vlp);/*from w w w.ja v a 2s . co m*/ } else { lp = (LayoutParams) vlp; } lp.mViewType = LayoutParams.SYSTEM; if (allowHide && mExpandedActionView != null) { v.setLayoutParams(lp); mHiddenViews.add(v); } else { addView(v, lp); } }
From source file:com.appunite.list.GridView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Sets up mListPadding super.onMeasure(widthMeasureSpec, heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); if (widthMode == MeasureSpec.UNSPECIFIED) { if (mColumnWidth > 0) { widthSize = mColumnWidth + mListPadding.left + mListPadding.right; } else {/* w ww .ja v a 2s .c om*/ widthSize = mListPadding.left + mListPadding.right; } widthSize += getVerticalScrollbarWidth(); } int childWidth = widthSize - mListPadding.left - mListPadding.right; boolean didNotInitiallyFit = determineColumns(childWidth); int childHeight = 0; int childState = 0; mItemCount = mAdapter == null ? 0 : mAdapter.getCount(); final int count = mItemCount; if (count > 0) { final View child = obtainView(0, mIsScrap); LayoutParams p = (LayoutParams) child.getLayoutParams(); if (p == null) { p = (LayoutParams) generateDefaultLayoutParams(); child.setLayoutParams(p); } p.viewType = mAdapter.getItemViewType(0); p.forceAdd = true; int childHeightSpec = getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height); int childWidthSpec = getChildMeasureSpec(MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width); child.measure(childWidthSpec, childHeightSpec); childHeight = child.getMeasuredHeight(); childState = Compat.combineMeasuredStates(childState, Compat.getMeasuredState(child)); if (mRecycler.shouldRecycleViewType(p.viewType)) { mRecycler.addScrapView(child, -1); } } if (heightMode == MeasureSpec.UNSPECIFIED) { heightSize = mListPadding.top + mListPadding.bottom + childHeight + getVerticalFadingEdgeLength() * 2; } if (heightMode == MeasureSpec.AT_MOST) { int ourSize = mListPadding.top + mListPadding.bottom; final int numColumns = mNumColumns; for (int i = 0; i < count; i += numColumns) { ourSize += childHeight; if (i + numColumns < count) { ourSize += mVerticalSpacing; } if (ourSize >= heightSize) { ourSize = heightSize; break; } } heightSize = ourSize; } if (widthMode == MeasureSpec.AT_MOST && mRequestedNumColumns != AUTO_FIT) { int ourSize = (mRequestedNumColumns * mColumnWidth) + ((mRequestedNumColumns - 1) * mHorizontalSpacing) + mListPadding.left + mListPadding.right; if (ourSize > widthSize || didNotInitiallyFit) { widthSize |= MEASURED_STATE_TOO_SMALL; } } setMeasuredDimension(widthSize, heightSize); mWidthMeasureSpec = widthMeasureSpec; }
From source file:androidx.media.widget.MediaControlView2.java
private void updateTitleBarLayout() { if (mTitleBar != null) { int titleBarWidth = mTitleBar.getWidth(); View leftBar = mTitleBar.findViewById(R.id.title_bar_left); View rightBar = mTitleBar.findViewById(R.id.title_bar_right); int leftBarWidth = leftBar.getWidth(); int rightBarWidth = rightBar.getWidth(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) leftBar.getLayoutParams(); if (leftBarWidth + rightBarWidth > titleBarWidth) { params.width = titleBarWidth - rightBarWidth; mOriginalLeftBarWidth = leftBarWidth; } else if (leftBarWidth + rightBarWidth < titleBarWidth && mOriginalLeftBarWidth != 0) { params.width = mOriginalLeftBarWidth; mOriginalLeftBarWidth = 0;//from ww w .j a va 2s. c o m } leftBar.setLayoutParams(params); } }
From source file:com.android.calendar.agenda.AgendaFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int screenWidth = mActivity.getResources().getDisplayMetrics().widthPixels; View v = inflater.inflate(R.layout.agenda_fragment, null); mAgendaListView = (AgendaListView) v.findViewById(R.id.agenda_events_list); mAgendaListView.setClickable(true);//from w w w . j av a 2 s. c o m if (savedInstanceState != null) { long instanceId = savedInstanceState.getLong(BUNDLE_KEY_RESTORE_INSTANCE_ID, -1); if (instanceId != -1) { mAgendaListView.setSelectedInstanceId(instanceId); } } View eventView = v.findViewById(R.id.agenda_event_info); if (!mShowEventDetailsWithAgenda) { eventView.setVisibility(View.GONE); } View topListView; // Set adapter & HeaderIndexer for StickyHeaderListView StickyHeaderListView lv = (StickyHeaderListView) v.findViewById(R.id.agenda_sticky_header_list); if (lv != null) { Adapter a = mAgendaListView.getAdapter(); lv.setAdapter(a); if (a instanceof HeaderViewListAdapter) { mAdapter = (AgendaWindowAdapter) ((HeaderViewListAdapter) a).getWrappedAdapter(); if (mLaunchedInShareMode) { mAdapter.launchInShareMode(true, mShouldSelectSingleEvent); mAgendaListView.launchInShareMode(true, mShouldSelectSingleEvent); if (mShareEventListener != null) { mAgendaListView.setShareEventListener(mShareEventListener); } } lv.setIndexer(mAdapter); lv.setHeaderHeightListener(mAdapter); } else if (a instanceof AgendaWindowAdapter) { mAdapter = (AgendaWindowAdapter) a; lv.setIndexer(mAdapter); lv.setHeaderHeightListener(mAdapter); } else { Log.wtf(TAG, "Cannot find HeaderIndexer for StickyHeaderListView"); } // Set scroll listener so that the date on the ActionBar can be set while // the user scrolls the view lv.setOnScrollListener(this); lv.setHeaderSeparator(getResources().getColor(R.color.agenda_list_separator_color), 1); topListView = lv; } else { topListView = mAgendaListView; } // Since using weight for sizing the two panes of the agenda fragment causes the whole // fragment to re-measure when the sticky header is replaced, calculate the weighted // size of each pane here and set it if (!mShowEventDetailsWithAgenda) { ViewGroup.LayoutParams params = topListView.getLayoutParams(); params.width = screenWidth; topListView.setLayoutParams(params); } else { ViewGroup.LayoutParams listParams = topListView.getLayoutParams(); listParams.width = screenWidth * 4 / 10; topListView.setLayoutParams(listParams); ViewGroup.LayoutParams detailsParams = eventView.getLayoutParams(); detailsParams.width = screenWidth - listParams.width; eventView.setLayoutParams(detailsParams); } return v; }
From source file:com.esri.squadleader.view.SquadLeaderActivity.java
private void setupActivity() { try {/*from w w w . j av a2s .c o m*/ ArcGISRuntime.setClientId(getString(R.string.clientId)); } catch (Throwable t) { Log.w(TAG, null, t); } ArcGISRuntime.License.setLicense(getString(R.string.licenseString)); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(SquadLeaderActivity.this); try { usernamePreference = sp.getString(getString(R.string.pref_username), usernamePreference); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } messageController = new MessageController(messagePortPreference, usernamePreference); chemLightController = new ChemLightController(messageController, usernamePreference); try { int wkid = Integer.parseInt( sp.getString(getString(R.string.pref_angularUnits), Integer.toString(AngularUnit.Code.DEGREE))); angularUnitPreference = (AngularUnit) AngularUnit.create(wkid); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } try { messagePortPreference = Integer.parseInt( sp.getString(getString(R.string.pref_messagePort), Integer.toString(messagePortPreference))); changePort(messagePortPreference); messageController.startReceiving(); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } try { positionReportsPreference = sp.getBoolean(getString(R.string.pref_positionReports), false); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } try { positionReportsPeriodPreference = Integer .parseInt(sp.getString(getString(R.string.pref_positionReportPeriod), Integer.toString(positionReportsPeriodPreference))); if (0 >= positionReportsPeriodPreference) { positionReportsPeriodPreference = PositionReportController.DEFAULT_PERIOD; sp.edit().putString(getString(R.string.pref_positionReportPeriod), Integer.toString(positionReportsPeriodPreference)).commit(); } } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } try { vehicleTypePreference = sp.getString(getString(R.string.pref_vehicleType), vehicleTypePreference); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } try { uniqueIdPreference = sp.getString(getString(R.string.pref_uniqueId), uniqueIdPreference); //Make sure this one gets set in case we just generated it sp.edit().putString(getString(R.string.pref_uniqueId), uniqueIdPreference).commit(); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } try { sicPreference = sp.getString(getString(R.string.pref_sic), sicPreference); } catch (Throwable t) { Log.d(TAG, "Couldn't get preference", t); } PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .registerOnSharedPreferenceChangeListener(preferenceChangeListener); // //TODO implement Geo URIs // Uri intentData = getIntent().getData(); // if (null != intentData) { // //intentData should be a Geo URI with a location to which we should navigate // } activityBinding = (ActivitySquadLeaderBinding) DataBindingUtil.setContentView(this, R.layout.activity_squad_leader); mainBinding = activityBinding.main; clearDisplayStrings(); adjustLayoutForOrientation(getResources().getConfiguration().orientation); final MapView mapView = (MapView) findViewById(R.id.map); mapView.setOnPanListener(new OnPanListener() { private static final long serialVersionUID = 0x58d30af8d168f63aL; @Override public void prePointerUp(float fromx, float fromy, float tox, float toy) { } @Override public void prePointerMove(float fromx, float fromy, float tox, float toy) { setFollowMe(false); } @Override public void postPointerUp(float fromx, float fromy, float tox, float toy) { } @Override public void postPointerMove(float fromx, float fromy, float tox, float toy) { } }); mapController = new MapController(mapView, getAssets(), new LayerErrorListener(this), this); mapController.setOnSingleTapListener(defaultOnSingleTapListener); northArrowView = (NorthArrowView) findViewById(R.id.northArrowView); northArrowView.setMapController(mapController); northArrowView.startRotation(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { try { instantiateMil2525CController(); } catch (IOException e) { Log.e(TAG, "Could not instantiate advanced symbol controller", e); } } spotReportController = new SpotReportController(mapController, messageController); positionReportController = new PositionReportController(mapController.getLocationController(), messageController, usernamePreference, vehicleTypePreference, uniqueIdPreference, sicPreference); positionReportController.setPeriod(positionReportsPeriodPreference); positionReportController.setEnabled(positionReportsPreference); mapController.getLocationController().addListener(new LocationListener() { @Override public void onLocationChanged(final Location location) { if (null != location) { //Do this in a thread in case we need to calculate the speed new Thread() { public void run() { Message msg = new Message(); msg.obj = location; locationChangeHandler.sendMessage(msg); } }.start(); } } @Override public void onStateChanged(LocationProviderState state) { } }); if (null != mapController.getLastMapConfig()) { String viewshedElevationPath = mapController.getLastMapConfig().getViewshedElevationPath(); if (null == viewshedElevationPath) { try { viewshedElevationPath = Utilities.readMapConfig(getApplicationContext(), getAssets()) .getViewshedElevationPath(); } catch (Throwable t) { Log.e(TAG, "Couldn't set up viewshed", t); } } createViewshedController(viewshedElevationPath); } mapController.addMapConfigListener(new MapConfigListener() { @Override public void mapConfigRead(MapConfig mapConfig) { String viewshedElevationPath = mapConfig.getViewshedElevationPath(); if (null == viewshedElevationPath) { try { viewshedElevationPath = Utilities.readMapConfig(getApplicationContext(), getAssets()) .getViewshedElevationPath(); } catch (Throwable t) { Log.e(TAG, "Couldn't set up viewshed", t); } } createViewshedController(viewshedElevationPath); } }); clockTimerTask = new TimerTask() { private final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { try { if (null != msg.obj) { mainBinding.setDisplayTime(String.format(getString(R.string.display_time), msg.obj)); } } catch (Throwable t) { Log.i(TAG, "Couldn't update time", t); } } }; @Override public void run() { if (null != mapController) { Message msg = new Message(); msg.obj = Utilities.DATE_FORMAT_MILITARY_ZULU.format(new Date()); handler.sendMessage(msg); } } }; clockTimer.schedule(clockTimerTask, 0, Utilities.ANIMATION_PERIOD_MS); ((RadioGroup) findViewById(R.id.radioGroup_chemLightButtons)) .setOnCheckedChangeListener(chemLightCheckedChangeListener); final BottomSheetBehavior<View> featurePopupBehavior = BottomSheetBehavior .from(findViewById(R.id.featurePopup)); bottomSheetBehavior_featurePopups = featurePopupBehavior; bottomSheetBehavior_featurePopups.setState(BottomSheetBehavior.STATE_HIDDEN); bottomSheetBehavior_featurePopups.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState) { case BottomSheetBehavior.STATE_COLLAPSED: case BottomSheetBehavior.STATE_HIDDEN: final View mainView = findViewById(R.id.main); final ViewGroup.LayoutParams layoutParams = mainView.getLayoutParams(); if (layoutParams instanceof ViewGroup.MarginLayoutParams) { Integer newBottomMargin = null; switch (newState) { case BottomSheetBehavior.STATE_COLLAPSED: newBottomMargin = featurePopupBehavior.getPeekHeight(); break; case BottomSheetBehavior.STATE_HIDDEN: newBottomMargin = 0; break; } if (null != newBottomMargin) { ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(0, 0, 0, newBottomMargin); mainView.setLayoutParams(layoutParams); } } } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { } }); popupsGroup = (ViewGroup) findViewById(R.id.linearLayout_popups); bottomSheetHeading = (TextView) findViewById(R.id.bottomSheetHeading); }
From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissListViewTouchListener.java
private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override/* ww w .jav a2 s .co m*/ public void onAnimationEnd(Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } mCallback.onDismiss(mListView, dismissPositions); ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation setAlpha(pendingDismiss.view, 1f); setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } mPendingDismisses.clear(); } } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:com.esri.squadleader.view.SquadLeaderActivity.java
private void adjustLayoutForOrientation(int orientation) { View displayView = findViewById(R.id.tableLayout_display); if (displayView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) displayView.getLayoutParams(); switch (orientation) { case Configuration.ORIENTATION_LANDSCAPE: { params.addRule(RelativeLayout.RIGHT_OF, R.id.toggleButton_grid); params.addRule(RelativeLayout.LEFT_OF, R.id.toggleButton_followMe); params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.imageButton_zoomOut); params.addRule(RelativeLayout.ABOVE, -1); break; }/*from ww w . jav a2 s . c o m*/ case Configuration.ORIENTATION_PORTRAIT: default: { params.addRule(RelativeLayout.RIGHT_OF, -1); params.addRule(RelativeLayout.LEFT_OF, R.id.imageButton_zoomIn); params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.imageButton_zoomIn); params.addRule(RelativeLayout.ABOVE, R.id.toggleButton_grid); } } displayView.setLayoutParams(params); } }
From source file:com.customdatepicker.time.TimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int viewRes = mVersion == Version.VERSION_1 ? R.layout.mdtp_time_picker_dialog : R.layout.mdtp_time_picker_dialog_v2; View view = inflater.inflate(viewRes, container, false); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.mdtp_time_picker_dialog).setOnKeyListener(keyboardListener); // If an accent color has not been set manually, get it from the context if (mAccentColor == -1) { mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); }/*from w ww. j av a2s . c o m*/ // if theme mode has not been set by java code, check if it is specified in Style.xml if (!mThemeDarkChanged) { mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark); } Resources res = getResources(); Context context = getActivity(); mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description); mSelectHours = res.getString(R.string.mdtp_select_hours); mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description); mSelectMinutes = res.getString(R.string.mdtp_select_minutes); mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description); mSelectSeconds = res.getString(R.string.mdtp_select_seconds); mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white); mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused); mHourView = (TextView) view.findViewById(R.id.mdtp_hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.mdtp_hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.mdtp_minutes_space); mMinuteView = (TextView) view.findViewById(R.id.mdtp_minutes); mMinuteView.setOnKeyListener(keyboardListener); mSecondSpaceView = (TextView) view.findViewById(R.id.mdtp_seconds_space); mSecondView = (TextView) view.findViewById(R.id.mdtp_seconds); mSecondView.setOnKeyListener(keyboardListener); mAmTextView = (TextView) view.findViewById(R.id.mdtp_am_label); mAmTextView.setOnKeyListener(keyboardListener); mPmTextView = (TextView) view.findViewById(R.id.mdtp_pm_label); mPmTextView.setOnKeyListener(keyboardListener); mAmPmLayout = view.findViewById(R.id.mdtp_ampm_layout); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mHapticFeedbackController = new HapticFeedbackController(getActivity()); if (mTimePicker != null) { mInitialTime = new Timepoint(mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds()); } mInitialTime = roundToNearest(mInitialTime); mTimePicker = (RadialPickerLayout) view.findViewById(R.id.mdtp_time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); tryVibrate(); } }); mSecondView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { setCurrentItemShowing(SECOND_INDEX, true, false, true); tryVibrate(); } }); mOkButton = (Button) view.findViewById(R.id.mdtp_ok); mOkButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { tryVibrate(); } notifyOnDateListener(); dismiss(); } }); mOkButton.setOnKeyListener(keyboardListener); mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium")); if (mOkString != null) mOkButton.setText(mOkString); else mOkButton.setText(mOkResid); mCancelButton = (Button) view.findViewById(R.id.mdtp_cancel); mCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium")); if (mCancelString != null) mCancelButton.setText(mCancelString); else mCancelButton.setText(mCancelResid); mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); // Enable or disable the AM/PM view. if (mIs24HourMode) { mAmPmLayout.setVisibility(View.GONE); } else { OnClickListener listener = new OnClickListener() { @Override public void onClick(View v) { // Don't do anything if either AM or PM are disabled if (isAmDisabled() || isPmDisabled()) return; tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } mTimePicker.setAmOrPm(amOrPm); } }; mAmTextView.setVisibility(View.GONE); mPmTextView.setVisibility(View.VISIBLE); mAmPmLayout.setOnClickListener(listener); if (mVersion == Version.VERSION_2) { mAmTextView.setText(mAmText); mPmTextView.setText(mPmText); mAmTextView.setVisibility(View.VISIBLE); } updateAmPmDisplay(mInitialTime.isAM() ? AM : PM); } // Disable seconds picker if (!mEnableSeconds) { mSecondView.setVisibility(View.GONE); view.findViewById(R.id.mdtp_separator_seconds).setVisibility(View.GONE); } // Disable minutes picker if (!mEnableMinutes) { mMinuteSpaceView.setVisibility(View.GONE); view.findViewById(R.id.mdtp_separator).setVisibility(View.GONE); } // Center stuff depending on what's visible boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; // Landscape layout is radically different if (isLandscape) { if (!mEnableMinutes && !mEnableSeconds) { // Just the hour // Put the hour above the center RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsHour.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view); paramsHour.addRule(RelativeLayout.CENTER_HORIZONTAL); mHourSpaceView.setLayoutParams(paramsHour); if (mIs24HourMode) { // Hour + Am/Pm indicator // Put the am / pm indicator next to the hour RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space); mAmPmLayout.setLayoutParams(paramsAmPm); } } else if (!mEnableSeconds && mIs24HourMode) { // Hour + Minutes // Put the separator above the center RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL); paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view); TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator); separatorView.setLayoutParams(paramsSeparator); } else if (!mEnableSeconds) { // Hour + Minutes + Am/Pm indicator // Put separator above the center RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL); paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view); TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator); separatorView.setLayoutParams(paramsSeparator); // Put the am/pm indicator below the separator RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsAmPm.addRule(RelativeLayout.CENTER_IN_PARENT); paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_center_view); mAmPmLayout.setLayoutParams(paramsAmPm); } else if (mIs24HourMode) { // Hour + Minutes + Seconds // Put the separator above the center RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL); paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space); TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator); separatorView.setLayoutParams(paramsSeparator); // Center the seconds RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT); mSecondSpaceView.setLayoutParams(paramsSeconds); } else { // Hour + Minutes + Seconds + Am/Pm Indicator // Put the seconds on the center RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT); mSecondSpaceView.setLayoutParams(paramsSeconds); // Put the separator above the seconds RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL); paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space); TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator); separatorView.setLayoutParams(paramsSeparator); // Put the Am/Pm indicator below the seconds RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); paramsAmPm.addRule(RelativeLayout.CENTER_HORIZONTAL); paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_seconds_space); mAmPmLayout.setLayoutParams(paramsAmPm); } } else if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) { // center first separator RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator); separatorView.setLayoutParams(paramsSeparator); } else if (!mEnableMinutes && !mEnableSeconds) { // center the hour RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT); mHourSpaceView.setLayoutParams(paramsHour); if (!mIs24HourMode) { RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space); paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.mdtp_hour_space); mAmPmLayout.setLayoutParams(paramsAmPm); } } else if (mEnableSeconds) { // link separator to minutes final View separator = view.findViewById(R.id.mdtp_separator); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.mdtp_minutes_space); paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); separator.setLayoutParams(paramsSeparator); if (!mIs24HourMode) { // center minutes RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT); mMinuteSpaceView.setLayoutParams(paramsMinutes); } else { // move minutes to right of center RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_center_view); mMinuteSpaceView.setLayoutParams(paramsMinutes); } } mAllowAutoAdvance = true; setHour(mInitialTime.getHour(), true); setMinute(mInitialTime.getMinute()); setSecond(mInitialTime.getSecond()); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder); mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<>(); } // Set the title (if any) TextView timePickerHeader = (TextView) view.findViewById(R.id.mdtp_time_picker_header); if (!mTitle.isEmpty()) { timePickerHeader.setVisibility(TextView.VISIBLE); timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault())); } // Set the theme at the end so that the initialize()s above don't counteract the theme. timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.mdtp_time_display_background).setBackgroundColor(mAccentColor); view.findViewById(R.id.mdtp_time_display).setBackgroundColor(mAccentColor); // Button text can have a different color if (mOkColor != -1) mOkButton.setTextColor(mOkColor); else mOkButton.setTextColor(mAccentColor); if (mCancelColor != -1) mCancelButton.setTextColor(mCancelColor); else mCancelButton.setTextColor(mAccentColor); if (getDialog() == null) { view.findViewById(R.id.mdtp_done_background).setVisibility(View.GONE); } int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background); int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color); int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray); int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray); mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground); view.findViewById(R.id.mdtp_time_picker_dialog) .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor); return view; }