List of usage examples for android.widget RelativeLayout CENTER_IN_PARENT
int CENTER_IN_PARENT
To view the source code for android.widget RelativeLayout CENTER_IN_PARENT.
Click Source Link
From source file:processing.core.PApplet.java
/** Called with the activity is first created. */ @Override/*from w w w.j av a 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); // println("PApplet.onCreate()"); if (DEBUG) println("onCreate() happening here: " + Thread.currentThread().getName()); // commented to use fragments /* * Window window = getWindow(); * * // Take up as much area as possible * requestWindowFeature(Window.FEATURE_NO_TITLE); * window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, * WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); * * // This does the actual full screen work * window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, * WindowManager.LayoutParams.FLAG_FULLSCREEN); */ DisplayMetrics dm = new DisplayMetrics(); this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); displayWidth = dm.widthPixels; displayHeight = dm.heightPixels; // println("density is " + dm.density); // println("densityDpi is " + dm.densityDpi); if (DEBUG) println("display metrics: " + dm); // println("screen size is " + screenWidth + "x" + screenHeight); // LinearLayout layout = new LinearLayout(this); // layout.setOrientation(LinearLayout.VERTICAL | // LinearLayout.HORIZONTAL); // viewGroup = new ViewGroup(); // surfaceView.setLayoutParams(); // viewGroup.setLayoutParams(LayoutParams.) // RelativeLayout layout = new RelativeLayout(this); // RelativeLayout overallLayout = new RelativeLayout(this); // RelativeLayout.LayoutParams lp = new // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.FILL_PARENT); // lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId()); // layout.setGravity(RelativeLayout.CENTER_IN_PARENT); int sw = sketchWidth(); int sh = sketchHeight(); if (sketchRenderer().equals(JAVA2D)) { surfaceView = new SketchSurfaceView(this.getActivity(), sw, sh); } else if (sketchRenderer().equals(P2D) || sketchRenderer().equals(P3D)) { surfaceView = new SketchSurfaceViewGL(this.getActivity(), sw, sh, sketchRenderer().equals(P3D)); } // g = ((SketchSurfaceView) surfaceView).getGraphics(); // surfaceView.setLayoutParams(new LayoutParams(sketchWidth(), // sketchHeight())); // layout.addView(surfaceView); // surfaceView.setVisibility(1); // println("visibility " + surfaceView.getVisibility() + " " + // SurfaceView.VISIBLE); // layout.addView(surfaceView); // AttributeSet as = new AttributeSet(); // RelativeLayout.LayoutParams lp = new // RelativeLayout.LayoutParams(layout, as); // lp.addRule(android.R.styleable.ViewGroup_Layout_layout_height, // layout.add // lp.addRule(, arg1) // layout.addView(surfaceView, sketchWidth(), sketchHeight()); // new // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.FILL_PARENT); if (sw == displayWidth && sh == displayHeight) { // If using the full screen, don't embed inside other layouts // window.setContentView(surfaceView); no para fragments } else { // If not using full screen, setup awkward view-inside-a-view so // that // the sketch can be centered on screen. (If anyone has a more // efficient // way to do this, please file an issue on Google Code, otherwise // you // can keep your "talentless hack" comments to yourself. Ahem.) RelativeLayout overallLayout = new RelativeLayout(this.getActivity()); overallLayout.setBackgroundColor(0x00000000); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); LinearLayout layout = new LinearLayout(this.getActivity()); layout.setBackgroundColor(0x00000000); layout.addView(surfaceView, sketchWidth(), sketchHeight()); overallLayout.addView(layout, lp); // window.setContentView(overallLayout); no para fragments } /* * // Here we use Honeycomb API (11+) to hide (in reality, just make the * status icons into small dots) // the status bar. Since the core is * still built against API 7 (2.1), we use introspection to get // the * setSystemUiVisibility() method from the view class. Method * visibilityMethod = null; try { visibilityMethod = * surfaceView.getClass().getMethod("setSystemUiVisibility", new Class[] * { int.class}); } catch (NoSuchMethodException e) { // Nothing to do. * This means that we are running with a version of Android previous to * Honeycomb. } if (visibilityMethod != null) { try { // This is * equivalent to calling: * //surfaceView.setSystemUiVisibility(View.STATUS_BAR_HIDDEN); // The * value of View.STATUS_BAR_HIDDEN is 1. * visibilityMethod.invoke(surfaceView, new Object[] { 1 }); } catch * (InvocationTargetException e) { } catch (IllegalAccessException e) { * } } window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, * WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // layout.addView(surfaceView, lp); // surfaceView.setLayoutParams(new LayoutParams(sketchWidth(), // sketchHeight())); // RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams() // layout.addView(surfaceView, new LayoutParams(arg0) // TODO probably don't want to set these here, can't we wait for // surfaceChanged()? // removing this in 0187 // width = screenWidth; // height = screenHeight; // int left = (screenWidth - iwidth) / 2; // int right = screenWidth - (left + iwidth); // int top = (screenHeight - iheight) / 2; // int bottom = screenHeight - (top + iheight); // surfaceView.setPadding(left, top, right, bottom); // android:layout_width // window.setContentView(surfaceView); // set full screen // code below here formerly from init() // millisOffset = System.currentTimeMillis(); // moved to the variable // declaration finished = false; // just for clarity // this will be cleared by draw() if it is not overridden looping = true; redraw = true; // draw this guy once firstMotion = true; // these need to be inited before setup sizeMethods = new RegisteredMethods(); preMethods = new RegisteredMethods(); drawMethods = new RegisteredMethods(); postMethods = new RegisteredMethods(); mouseEventMethods = new RegisteredMethods(); keyEventMethods = new RegisteredMethods(); disposeMethods = new RegisteredMethods(); Context context = this.getActivity().getApplicationContext(); sketchPath = context.getFilesDir().getAbsolutePath(); // Looper.prepare(); handler = new Handler(); // println("calling loop()"); // Looper.loop(); // println("done with loop() call, will continue..."); start(); return surfaceView; }
From source file:com.repkap11.repcast.activities.LocalPlayerActivity.java
private void updateMetadata(boolean visible) { Point displaySize;//from w w w. j ava 2 s . c om if (!visible) { mDescriptionView.setVisibility(View.GONE); mTitleView.setVisibility(View.GONE); mAuthorView.setVisibility(View.GONE); displaySize = Utils.getDisplaySize(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(displaySize.x, displaySize.y + getSupportActionBar().getHeight()); lp.addRule(RelativeLayout.CENTER_IN_PARENT); mVideoView.setLayoutParams(lp); mVideoView.invalidate(); } else { MediaMetadata mm = mSelectedMedia.getMetadata(); mDescriptionView.setText(mSelectedMedia.getCustomData().optString(VideoProvider.KEY_DESCRIPTION)); mTitleView.setText(mm.getString(MediaMetadata.KEY_TITLE)); mAuthorView.setText(mm.getString(MediaMetadata.KEY_SUBTITLE)); mDescriptionView.setVisibility(View.VISIBLE); mTitleView.setVisibility(View.VISIBLE); mAuthorView.setVisibility(View.VISIBLE); displaySize = Utils.getDisplaySize(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(displaySize.x, (int) (displaySize.x * mAspectRatio)); lp.addRule(RelativeLayout.BELOW, R.id.toolbar); //lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); mVideoView.setLayoutParams(lp); mVideoView.invalidate(); } }
From source file:org.zywx.wbpalmstar.engine.universalex.EUExBase.java
protected final void adptLayoutParams(RelativeLayout.LayoutParams rParms, FrameLayout.LayoutParams outParm) { if (null == rParms) { return;/*from w ww.ja v a2 s . c om*/ } int TRUE = RelativeLayout.TRUE; int ALIGN_PARENT_LEFT = RelativeLayout.ALIGN_PARENT_LEFT; int ALIGN_PARENT_TOP = RelativeLayout.ALIGN_PARENT_TOP; int ALIGN_PARENT_RIGHT = RelativeLayout.ALIGN_PARENT_RIGHT; int ALIGN_PARENT_BOTTOM = RelativeLayout.ALIGN_PARENT_BOTTOM; int CENTER_IN_PARENT = RelativeLayout.CENTER_IN_PARENT; int CENTER_HORIZONTAL = RelativeLayout.CENTER_HORIZONTAL; int CENTER_VERTICAL = RelativeLayout.CENTER_VERTICAL; try { int[] rules = rParms.getRules(); if (rules[ALIGN_PARENT_LEFT] == TRUE) { outParm.gravity |= Gravity.LEFT; } if (rules[ALIGN_PARENT_TOP] == TRUE) { outParm.gravity |= Gravity.TOP; } if (rules[ALIGN_PARENT_RIGHT] == TRUE) { outParm.gravity |= Gravity.RIGHT; } if (rules[ALIGN_PARENT_BOTTOM] == TRUE) { outParm.gravity |= Gravity.BOTTOM; } if (rules[CENTER_IN_PARENT] == TRUE) { outParm.gravity |= Gravity.CENTER; } if (rules[CENTER_HORIZONTAL] == TRUE) { outParm.gravity |= Gravity.CENTER_HORIZONTAL; } if (rules[CENTER_VERTICAL] == TRUE) { outParm.gravity |= Gravity.CENTER_VERTICAL; } } catch (Exception e) { ; } }
From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java
/** * Shows footer view./*from ww w.ja va 2 s .co m*/ * * @param show * {@code true} or {@code false}. * @param text * the message you want to set. * @param center * {@code true} or {@code false}. */ @SuppressLint("InlinedApi") private void showFooterView(boolean show, String text, boolean center) { if (show) { mFooterView.setText(text); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); if (!center) lp.addRule(RelativeLayout.ABOVE, R.id.afc_view_files_footer_view); mViewFilesContainer.setLayoutParams(lp); lp = (RelativeLayout.LayoutParams) mFooterView.getLayoutParams(); lp.addRule(RelativeLayout.CENTER_IN_PARENT, center ? 1 : 0); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, center ? 0 : 1); mFooterView.setLayoutParams(lp); mFooterView.setVisibility(View.VISIBLE); } else mFooterView.setVisibility(View.GONE); }
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 w w . j a v a 2s . 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; }
From source file:com.haibison.android.anhuu.FragmentFiles.java
/** * Shows footer view./*w w w.j a v a2s . c o m*/ * * @param show * {@code true} or {@code false}. * @param text * the message you want to set. * @param center * {@code true} or {@code false}. */ @SuppressLint("InlinedApi") private void showFooterView(boolean show, String text, boolean center) { if (show) { mFooterView.setText(text); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); if (!center) lp.addRule(RelativeLayout.ABOVE, R.id.anhuu_f5be488d_view_files_footer_view); mViewFilesContainer.setLayoutParams(lp); lp = (RelativeLayout.LayoutParams) mFooterView.getLayoutParams(); lp.addRule(RelativeLayout.CENTER_IN_PARENT, center ? 1 : 0); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, center ? 0 : 1); mFooterView.setLayoutParams(lp); mFooterView.setVisibility(View.VISIBLE); } else mFooterView.setVisibility(View.GONE); }
From source file:org.dkf.jmule.activities.MainActivity.java
private void updateHeader(Fragment fragment) { try {// w w w .ja v a2 s.com RelativeLayout placeholder = (RelativeLayout) getActionBar().getCustomView(); if (placeholder != null && placeholder.getChildCount() > 0) { placeholder.removeAllViews(); } if (fragment instanceof MainFragment) { View header = ((MainFragment) fragment).getHeader(this); if (placeholder != null && header != null) { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); placeholder.addView(header, params); } } } catch (Exception e) { log.error("Error updating main header", e); } }
From source file:info.tellmetime.TellmetimeActivity.java
private void resizeClock() { final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock); // Set width of #mClock layout to the screen's shorter edge size, so clock is not // expanded in landscape mode, but has rather somewhat a square shape. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); lp.width = mShorterEdge;/*from w w w.j av a 2 s . c o m*/ mClock.setLayoutParams(lp); final float mItemSize = mShorterEdge / mClock.getChildCount(); final int mRowMargin = (int) -(mItemSize / 2.2); // Scale text size according to shorter edge and set spacing between rows. for (int i = 0; i < mClock.getChildCount(); i++) { LinearLayout row = (LinearLayout) mClock.getChildAt(i); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams(); params.bottomMargin = mRowMargin; row.setLayoutParams(params); for (int j = 0; j < row.getChildCount(); j++) ((TextView) row.getChildAt(j)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize); } LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams(); params.bottomMargin = 0; lastRow.setLayoutParams(params); TextView twenty = (TextView) findViewById(R.id.twenty); params = (LinearLayout.LayoutParams) twenty.getLayoutParams(); params.leftMargin = 0; twenty.setLayoutParams(params); // Inflates minutes indicators and attaches them to main view. FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators); minutesLayout.removeAllViews(); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final boolean isLandscape = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT); if (!isLandscape) { layoutParams.addRule(RelativeLayout.BELOW, R.id.clock); layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3, getResources().getDisplayMetrics()); } minutesLayout.setLayoutParams(layoutParams); ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) ((TextView) minutesDots.getChildAt(i)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize); }
From source file:com.skytree.epubtest.BookViewActivity.java
public void showIndicator() { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) progressBar.getLayoutParams(); params.addRule(RelativeLayout.CENTER_IN_PARENT, -1); progressBar.setLayoutParams(params); progressBar.setVisibility(View.VISIBLE); }
From source file:nu.yona.timepicker.time.TimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.mdtp_dual_time_picker_dialog, container, false); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.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 w w . j ava 2 s . 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); if (mIsDualScreenMode) { view.findViewById(R.id.next_backgroud).setVisibility(View.VISIBLE); tabHost = (TabHost) view.findViewById(R.id.tabHost); tabHost.findViewById(R.id.tabHost); tabHost.setOnTabChangedListener(this); tabHost.setup(); setNewTab(tabHost, getString(R.string.from), R.string.from, R.id.time_picker, 0); setNewTab(tabHost, getString(R.string.to), R.string.to, R.id.time_picker_end, 1); tabHost.setCurrentTab(0); } else { ((TextView) view.findViewById(R.id.previous)).setText(getString(R.string.mdtp_cancel)); view.findViewById(R.id.done_background).setVisibility(View.VISIBLE); } doneBackgroudnView = view.findViewById(R.id.done_background); nextBackgroundView = view.findViewById(R.id.next_backgroud); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourView.setTypeface(TypefaceHelper.get(context, Utils.OSWALD_LIGHT)); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mHourSpaceViewEnd = (TextView) view.findViewById(R.id.hour_space_end); mHourViewEnd = (TextView) view.findViewById(R.id.hours_end); mHourViewEnd.setOnKeyListener(keyboardListener); mHourViewEnd.setTypeface(TypefaceHelper.get(context, Utils.OSWALD_LIGHT)); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteSpaceViewEnd = (TextView) view.findViewById(R.id.minutes_space_end); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mMinuteView.setTypeface(TypefaceHelper.get(context, Utils.OSWALD_LIGHT)); mMinuteViewEnd = (TextView) view.findViewById(R.id.minutes_end); mMinuteViewEnd.setOnKeyListener(keyboardListener); mMinuteViewEnd.setTypeface(TypefaceHelper.get(context, Utils.OSWALD_LIGHT)); mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space); mSecondView = (TextView) view.findViewById(R.id.seconds); mSecondView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mHapticFeedbackController = new HapticFeedbackController(getActivity()); mInitialTime = roundToNearest(mInitialTime); mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode); mTimePickerEnd = (RadialPickerLayout) view.findViewById(R.id.time_picker_end); mTimePickerEnd.setOnValueSelectedListener(this); mTimePickerEnd.setOnKeyListener(keyboardListener); //mTimePickerEnd.setVisibility(View.GONE); if (mSecondTime != null) { mTimePickerEnd.initialize(getActivity(), this, mSecondTime, mIs24HourMode); } int currentItemShowing = HOUR_INDEX; int currentItemShowingEnd = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } /*if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING_END)) { currentItemShowingEnd = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING_END); }*/ setCurrentItemShowing(currentItemShowing, false, true, true); setCurrentItemShowing(currentItemShowingEnd, false, true, true); mTimePicker.invalidate(); mTimePickerEnd.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabHost.getCurrentTab() == 1) { tabHost.setCurrentTab(0); } else { setCurrentItemShowing(HOUR_INDEX, true, false, true); } tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabHost.getCurrentTab() == 1) { tabHost.setCurrentTab(0); } else { setCurrentItemShowing(MINUTE_INDEX, true, false, true); tryVibrate(); } } }); mSecondView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { setCurrentItemShowing(SECOND_INDEX, true, false, true); tryVibrate(); } }); mHourViewEnd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabHost.getCurrentTab() == 0) { tabHost.setCurrentTab(1); } else { setCurrentItemShowing(HOUR_INDEX, true, false, true); tryVibrate(); } } }); mMinuteViewEnd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabHost.getCurrentTab() == 0) { tabHost.setCurrentTab(1); } else { 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.ok); mOkButton.setOnClickListener(clickListener); mOkButton.setOnKeyListener(keyboardListener); mOkButton.setTypeface(TypefaceHelper.get(context, Utils.ROBOTO_MEDIUM)); if (mOkString != null) mOkButton.setText(mOkString); else mOkButton.setText(mOkResid); mErrorMsg = (TextView) view.findViewById(R.id.time_picker_error_msg); mPreviousButton = (Button) view.findViewById(R.id.previous); mPreviousButton.setOnClickListener(clickListener); mNextButton = (Button) view.findViewById(R.id.next); mNextButton.setOnClickListener(clickListener); mCancelButton = (Button) view.findViewById(R.id.cancel); mCancelButton.setOnClickListener(clickListener); mCancelButton.setTypeface(TypefaceHelper.get(context, Utils.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. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); } else { mAmPmTextView.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialTime.isAM() ? AM : PM); mAmPmHitspace.setOnClickListener(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); } }); } // Disable seconds picker if (!mEnableSeconds) { mSecondSpaceView.setVisibility(View.GONE); view.findViewById(R.id.separator_seconds).setVisibility(View.GONE); } // Center stuff depending on what's visible if (mIs24HourMode && !mEnableSeconds) { // 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.separator); separatorView.setLayoutParams(paramsSeparator); } else if (mEnableSeconds) { // link separator to minutes final View separator = view.findViewById(R.id.separator); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.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.center_view); mMinuteSpaceView.setLayoutParams(paramsMinutes); } } mAllowAutoAdvance = true; setHour(mFirstTime.getHour(), true); setMinute(mFirstTime.getMinute()); setSecond(mFirstTime.getSecond()); setHourEnd(mSecondTime.getHour(), true); setMinuteEnd(mSecondTime.getMinute()); setSecondEnd(mSecondTime.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) 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. mOkButton.setTextColor(mAccentColor); mCancelButton.setTextColor(mAccentColor); //timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.time_display_background) .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.mdtp_white)); view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor); view.findViewById(R.id.time_display_end).setBackgroundColor(mAccentColor); if (getDialog() == null) { view.findViewById(R.id.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); mTimePickerEnd.setBackgroundColor(mThemeDark ? lightGray : circleBackground); view.findViewById(R.id.time_picker_dialog) .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor); return view; }