List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:terse.a1.TerseActivity.java
void SetContentViewWithHomeButtonAndScroll(View v) { Button btn = new Button(this); btn.setText("[HOME]"); // btn.setTextSize(15); // btn.setHeight(25); // btn.setMaxHeight(25); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Perform action on clicks startTerseActivity("/Top", ""); };//from ww w.j a va 2s. c om }); LinearLayout linear = new LinearLayout(this); linear.setOrientation(LinearLayout.VERTICAL); linear.addView(btn); linear.addView(v); ScrollView scrollv = new ScrollView(this); scrollv.addView(linear); setContentView(scrollv); }
From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout window = new LinearLayout(mActivity); window.setLayoutParams(CommonLayouts.FULL_SCREEN); window.setOrientation(LinearLayout.VERTICAL); LinearLayout socialBox = new LinearLayout(mActivity); socialBox.setLayoutParams(CommonLayouts.FULL_WIDTH); socialBox.setOrientation(LinearLayout.HORIZONTAL); socialBox.setWeightSum(1.0f * DISPLAYED_SERVICES); /** Google **/ ImageButton google = new ImageButton(mActivity); google.setImageResource(R.drawable.google); google.setOnClickListener(mGoogleClickListener); google.setLayoutParams(/*from w w w. j av a 2s . co m*/ new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); google.setAdjustViewBounds(true); socialBox.addView(google); /** Facebook **/ ImageButton facebook = new ImageButton(mActivity); facebook.setImageResource(R.drawable.facebook); facebook.setOnClickListener(mFacebookClickListener); facebook.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); facebook.setAdjustViewBounds(true); socialBox.addView(facebook); /** Phone Number **/ ImageButton phone = new ImageButton(mActivity); phone.setImageResource(R.drawable.phone); phone.setOnClickListener(mPhoneClickListener); phone.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); phone.setAdjustViewBounds(true); //socialBox.addView(phone); /** List of known accounts **/ TextView chooseService = new TextView(mActivity); chooseService.setText("Choose a service to connect."); chooseService.setVisibility(View.GONE); chooseService.setLayoutParams(CommonLayouts.FULL_SCREEN); chooseService.setTextSize(20); mAccountAdapter = new AccountAdapter(getActivity()); mAccountList = new ListView(getActivity()); mAccountList.setAdapter(mAccountAdapter); mAccountList.setPadding(6, 10, 6, 0); mAccountList.setLayoutParams(CommonLayouts.FULL_SCREEN); mAccountList.setEmptyView(chooseService); /** Put it together **/ window.addView(socialBox); window.addView(mAccountList); window.addView(chooseService); initialize(); return window; }
From source file:org.telegram.ui.TwoStepVerificationActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*w ww.ja v a 2s .c om*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { processDone(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ActionBarMenu menu = actionBar.createMenu(); doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); scrollView = new ScrollView(context); scrollView.setFillViewport(true); frameLayout.addView(scrollView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; scrollView.setLayoutParams(layoutParams); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); scrollView.addView(linearLayout); ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams(); layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT; layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT; linearLayout.setLayoutParams(layoutParams2); titleTextView = new TextView(context); //titleTextView.setTextColor(0xff757575); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); linearLayout.addView(titleTextView); LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = Gravity.CENTER_HORIZONTAL; layoutParams3.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams3); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); //passwordEditText.setTextColor(0xff000000); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); linearLayout.addView(passwordEditText); layoutParams3 = (LinearLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams3.topMargin = AndroidUtilities.dp(32); layoutParams3.height = AndroidUtilities.dp(36); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); layoutParams3.gravity = Gravity.TOP | Gravity.LEFT; layoutParams3.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams3); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) { processDone(); return true; } return false; } }); passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); bottomTextView = new TextView(context); //bottomTextView.setTextColor(0xff757575); bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP); bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo)); linearLayout.addView(bottomTextView); layoutParams3 = (LinearLayout.LayoutParams) bottomTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP; layoutParams3.topMargin = AndroidUtilities.dp(30); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); bottomTextView.setLayoutParams(layoutParams3); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL); linearLayout.addView(linearLayout2); layoutParams3 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.MATCH_PARENT; linearLayout2.setLayoutParams(layoutParams3); bottomButton = new TextView(context); bottomButton.setTextColor(0xff4d83b3); bottomButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM); bottomButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip)); bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0); linearLayout2.addView(bottomButton); layoutParams3 = (LinearLayout.LayoutParams) bottomButton.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM; layoutParams3.bottomMargin = AndroidUtilities.dp(14); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); bottomButton.setLayoutParams(layoutParams3); bottomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (type == 0) { if (currentPassword.has_recovery) { needShowProgress(); TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { needHideProgress(); if (error == null) { final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response; AlertDialog.Builder builder = new AlertDialog.Builder( getParentActivity()); builder.setMessage(LocaleController.formatString("RestoreEmailSent", R.string.RestoreEmailSent, res.email_pattern)); builder.setTitle( LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity( 1); fragment.currentPassword = currentPassword; fragment.currentPassword.email_unconfirmed_pattern = res.email_pattern; fragment.passwordSetState = 4; presentFragment(fragment); } }); Dialog dialog = showDialog(builder.create()); if (dialog != null) { dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false); } } else { if (error.text.startsWith("FLOOD_WAIT")) { int time = Utilities.parseInt(error.text); String timeString; if (time < 60) { timeString = LocaleController.formatPluralString("Seconds", time); } else { timeString = LocaleController.formatPluralString("Minutes", time / 60); } showAlertWithText( LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString)); } else { showAlertWithText( LocaleController.getString("AppName", R.string.AppName), error.text); } } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin); } else { showAlertWithText( LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestorePasswordNoEmailText", R.string.RestorePasswordNoEmailText)); } } else { if (passwordSetState == 4) { showAlertWithText( LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestoreEmailTroubleText", R.string.RestoreEmailTroubleText)); } else { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("YourEmailSkipWarningText", R.string.YourEmailSkipWarningText)); builder.setTitle( LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning)); builder.setPositiveButton( LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { email = ""; setNewPassword(false); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } } }); if (type == 0) { progressView = new FrameLayout(context); frameLayout.addView(progressView); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; progressView.setLayoutParams(layoutParams); progressView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; progressView.setLayoutParams(layoutParams); listView = new ListView(context); listView.setDivider(null); listView.setEmptyView(progressView); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter = new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == setPasswordRow || i == changePasswordRow) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1); fragment.currentPasswordHash = currentPasswordHash; fragment.currentPassword = currentPassword; presentFragment(fragment); } else if (i == setRecoveryEmailRow || i == changeRecoveryEmailRow) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1); fragment.currentPasswordHash = currentPasswordHash; fragment.currentPassword = currentPassword; fragment.emailOnly = true; fragment.passwordSetState = 3; presentFragment(fragment); } else if (i == turnPasswordOffRow || i == abortPasswordRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TurnPasswordOffQuestion", R.string.TurnPasswordOffQuestion)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setNewPassword(true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); updateRows(); actionBar.setTitle(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification)); titleTextView.setText( LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword)); } else if (type == 1) { setPasswordSetState(passwordSetState); } return fragmentView; }
From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestSection.java
/** * Creates the main section. Subclasses must call super#createMainSection() immediately to * guarantee that Views are added in the correct order. * * @param sectionName Title to display for the section. *//*from w w w . ja v a 2 s .co m*/ private LinearLayout prepareMainSection(String sectionName) { // The main section is a vertical linear layout that subclasses can append to. LinearLayout mainSectionLayout = new LinearLayout(getContext()); mainSectionLayout.setOrientation(VERTICAL); LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT); mainParams.weight = 1; addView(mainSectionLayout, mainParams); // The title is always displayed for the row at the top of the main section. mTitleView = new TextView(getContext()); mTitleView.setText(sectionName); ApiCompatibilityUtils.setTextAppearance(mTitleView, R.style.PaymentsUiSectionHeader); mainSectionLayout.addView(mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // Create the two TextViews for showing the summary text. mSummaryLeftTextView = new TextView(getContext()); mSummaryLeftTextView.setId(R.id.payments_left_summary_label); ApiCompatibilityUtils.setTextAppearance(mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText); mSummaryRightTextView = new TextView(getContext()); ApiCompatibilityUtils.setTextAppearance(mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText); ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END); // The main TextView sucks up all the available space. LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); leftLayoutParams.weight = 1; LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart(rightLayoutParams, getContext().getResources().getDimensionPixelSize(R.dimen.payments_section_small_spacing)); // The summary section displays up to two TextViews side by side. mSummaryLayout = new LinearLayout(getContext()); mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams); mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams); mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); setSummaryText(null, null); createMainSectionContent(mainSectionLayout); return mainSectionLayout; }
From source file:org.telegram.ui.NotificationsSettingsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*from ww w . j av a 2s. co m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new FrameLayout(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); FrameLayout frameLayout = (FrameLayout) fragmentView; listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); frameLayout.addView(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setAdapter(new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, final View view, final int i, long l) { boolean enabled = false; if (i == messageAlertRow || i == groupAlertRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (i == messageAlertRow) { enabled = preferences.getBoolean("EnableAll", true); editor.putBoolean("EnableAll", !enabled); } else if (i == groupAlertRow) { enabled = preferences.getBoolean("EnableGroup", true); editor.putBoolean("EnableGroup", !enabled); } editor.commit(); updateServerNotificationsSettings(i == groupAlertRow); } else if (i == messagePreviewRow || i == groupPreviewRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (i == messagePreviewRow) { enabled = preferences.getBoolean("EnablePreviewAll", true); editor.putBoolean("EnablePreviewAll", !enabled); } else if (i == groupPreviewRow) { enabled = preferences.getBoolean("EnablePreviewGroup", true); editor.putBoolean("EnablePreviewGroup", !enabled); } editor.commit(); updateServerNotificationsSettings(i == groupPreviewRow); } else if (i == messageSoundRow || i == groupSoundRow) { try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); Uri currentSound = null; String defaultPath = null; Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; if (defaultUri != null) { defaultPath = defaultUri.getPath(); } if (i == messageSoundRow) { String path = preferences.getString("GlobalSoundPath", defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } } else if (i == groupSoundRow) { String path = preferences.getString("GroupSoundPath", defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); startActivityForResult(tmpIntent, i); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == resetNotificationsRow) { if (reseting) { return; } reseting = true; TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { MessagesController.getInstance().enableJoined = true; reseting = false; SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); if (listView != null) { listView.invalidateViews(); } if (getParentActivity() != null) { Toast toast = Toast .makeText(getParentActivity(), LocaleController.getString("ResetNotificationsText", R.string.ResetNotificationsText), Toast.LENGTH_SHORT); toast.show(); } } }); } }); } else if (i == inappSoundRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppSounds", true); editor.putBoolean("EnableInAppSounds", !enabled); editor.commit(); } else if (i == inappVibrateRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppVibrate", true); editor.putBoolean("EnableInAppVibrate", !enabled); editor.commit(); } else if (i == inappPreviewRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppPreview", true); editor.putBoolean("EnableInAppPreview", !enabled); editor.commit(); } else if (i == inchatSoundRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInChatSound", true); editor.putBoolean("EnableInChatSound", !enabled); editor.commit(); NotificationsController.getInstance().setInChatSoundEnabled(!enabled); } else if (i == inappPriorityRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppPriority", false); editor.putBoolean("EnableInAppPriority", !enabled); editor.commit(); } else if (i == contactJoinedRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableContactJoined", true); MessagesController.getInstance().enableJoined = !enabled; editor.putBoolean("EnableContactJoined", !enabled); editor.commit(); } else if (i == pinnedMessageRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("PinnedMessages", true); editor.putBoolean("PinnedMessages", !enabled); editor.commit(); } else if (i == androidAutoAlertRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableAutoNotifications", false); editor.putBoolean("EnableAutoNotifications", !enabled); editor.commit(); } else if (i == badgeNumberRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("badgeNumber", true); editor.putBoolean("badgeNumber", !enabled); editor.commit(); NotificationsController.getInstance().setBadgeEnabled(!enabled); } else if (i == notificationsServiceConnectionRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); enabled = preferences.getBoolean("pushConnection", true); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("pushConnection", !enabled); editor.commit(); if (!enabled) { ConnectionsManager.getInstance().setPushConnectionEnabled(true); } else { ConnectionsManager.getInstance().setPushConnectionEnabled(false); } } else if (i == notificationsServiceRow) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); enabled = preferences.getBoolean("pushService", true); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("pushService", !enabled); editor.commit(); if (!enabled) { ApplicationLoader.startPushService(); } else { ApplicationLoader.stopPushService(); } /*if (!enabled) { } else { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { final SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("pushService", false); editor.commit(); listView.invalidateViews(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ((TextCheckCell) view).setChecked(true); } }); showDialog(builder.create()); }*/ } else if (i == messageLedRow || i == groupLedRow) { if (getParentActivity() == null) { return; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity()); linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (i == messageLedRow) { colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00)); } else if (i == groupLedRow) { colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00)); } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); TextColorCell textCell = (TextColorCell) view; if (i == messageLedRow) { editor.putInt("MessagesLed", colorPickerView.getColor()); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), colorPickerView.getColor(), true); } else if (i == groupLedRow) { editor.putInt("GroupLed", colorPickerView.getColor()); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), colorPickerView.getColor(), true); } editor.commit(); } }); builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); TextColorCell textCell = (TextColorCell) view; if (i == messageLedRow) { editor.putInt("MessagesLed", 0); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), 0, true); } else if (i == groupLedRow) { editor.putInt("GroupLed", 0); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), 0, true); } editor.commit(); listView.invalidateViews(); } }); showDialog(builder.create()); } else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification)); builder.setItems( new CharSequence[] { LocaleController.getString("NoPopup", R.string.NoPopup), LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn), LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff), LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (i == messagePopupNotificationRow) { editor.putInt("popupAll", which); } else if (i == groupPopupNotificationRow) { editor.putInt("popupGroup", which); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == messageVibrateRow || i == groupVibrateRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate)); builder.setItems( new CharSequence[] { LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled), LocaleController.getString("VibrationDefault", R.string.VibrationDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long), LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); String param = "vibrate_messages"; if (i == groupVibrateRow) { param = "vibrate_group"; } if (which == 0) { editor.putInt(param, 2); } else if (which == 1) { editor.putInt(param, 0); } else if (which == 2) { editor.putInt(param, 1); } else if (which == 3) { editor.putInt(param, 3); } else if (which == 4) { editor.putInt(param, 4); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == messagePriorityRow || i == groupPriorityRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority)); builder.setItems(new CharSequence[] { LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (i == messagePriorityRow) { preferences.edit().putInt("priority_messages", which).commit(); } else if (i == groupPriorityRow) { preferences.edit().putInt("priority_group", which).commit(); } if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == repeatRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications)); builder.setItems( new CharSequence[] { LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled), LocaleController.formatPluralString("Minutes", 5), LocaleController.formatPluralString("Minutes", 10), LocaleController.formatPluralString("Minutes", 30), LocaleController.formatPluralString("Hours", 1), LocaleController.formatPluralString("Hours", 2), LocaleController.formatPluralString("Hours", 4) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int minutes = 0; if (which == 1) { minutes = 5; } else if (which == 2) { minutes = 10; } else if (which == 3) { minutes = 30; } else if (which == 4) { minutes = 60; } else if (which == 5) { minutes = 60 * 2; } else if (which == 6) { minutes = 60 * 4; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("repeat_messages", minutes).commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(!enabled); } } }); return fragmentView; }
From source file:org.cryptsecure.Utility.java
/** * Sets the content view with custom title. This is necessary for a holo * layout where a custom title bar is normally not permitted. * /* www . j a v a 2s .co m*/ * @param activity * the activity * @param resIdMainLayout * the res id main layout * @param resIdTitle * the res id title * @return the linear layout */ public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout, int resIdTitle) { Context context = activity.getApplicationContext(); // Inflate the given layouts LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View titleView = (View) inflaterInfo.inflate(resIdTitle, null); View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null); // Own custom title bar // // ATTENTION: // ADD THIS TO THEME <item name="android:windowNoTitle">true</item> activity.requestWindowFeature(Window.FEATURE_NO_TITLE); // We can ONLY disable the original title bar because you cannot combine // HOLO theme with a CUSTOM title bar :( // So we make our own title bar instead! // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP: // ADD TO MANIFEST // android:theme="@android:style/Theme.NoTitleBar" // THE FOLLOWING IS NOT WORKING WITH HOLO // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.activity_main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // R.layout.title_main); // Create title layout LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout titleLayout = new LinearLayout(context); titleLayout.setOrientation(LinearLayout.VERTICAL); titleLayout.addView(titleView); titleLayout.setLayoutParams(lpTitle); // Create main layout LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout mainLayout = new LinearLayout(context); mainLayout.setOrientation(LinearLayout.VERTICAL); mainLayout.addView(mainView); mainLayout.setLayoutParams(lpMain); // Create root outer layout LinearLayout outerLayout = new LinearLayout(context); outerLayout.setOrientation(LinearLayout.VERTICAL); outerLayout.addView(titleLayout); outerLayout.addView(mainLayout); // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0)); // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0)); // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255)); // lpSectionInnerLeft.setMargins(20, 5, 0, 15); // LinearLayout.LayoutParams lpSectionInnerRight = new // LinearLayout.LayoutParams( // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f); // lpSectionInnerRight.setMargins(0, 5, 15, 15); // After setting NO TITLE .. apply the layout activity.setContentView(outerLayout); return mainLayout; }
From source file:org.telegram.ui.ChannelEditActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/* w ww. j a va 2 s . co m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (donePressed) { return; } if (nameTextView.length() == 0) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(nameTextView, 2, 0); return; } donePressed = true; if (avatarUpdater.uploadingAvatar != null) { createAfterUpload = true; progressDialog = new ProgressDialog(getParentActivity()); progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { createAfterUpload = false; progressDialog = null; donePressed = false; try { dialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); progressDialog.show(); return; } if (!currentChat.title.equals(nameTextView.getText().toString())) { MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString()); } if (info != null && !info.about.equals(descriptionTextView.getText().toString())) { MessagesController.getInstance().updateChannelAbout(chatId, descriptionTextView.getText().toString(), info); } if (signMessages != currentChat.signatures) { currentChat.signatures = true; MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages); } if (uploadedAvatar != null) { MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar); } else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) { MessagesController.getInstance().changeChatAvatar(chatId, null); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); LinearLayout linearLayout; fragmentView = new ScrollView(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); linearLayout = new LinearLayout(context); scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit)); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); FrameLayout frameLayout = new FrameLayout(context); linearLayout2.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(32)); avatarDrawable.setInfo(5, null, null, false); avatarDrawable.setDrawPhoto(true); frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12)); avatarImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; if (avatar != null) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { avatarUpdater.openCamera(); } else if (i == 1) { avatarUpdater.openGallery(); } else if (i == 2) { avatar = null; uploadedAvatar = null; avatarImage.setImage(avatar, "50_50", avatarDrawable); } } }); showDialog(builder.create()); } }); nameTextView = new EditText(context); if (currentChat.megagroup) { nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName)); } else { nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName)); } nameTextView.setMaxLines(4); nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //nameTextView.setHintTextColor(0xff979797); nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); InputFilter[] inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(100); nameTextView.setFilters(inputFilters); AndroidUtilities.clearCursorDrawable(nameTextView); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0, LocaleController.isRTL ? 96 : 16, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false); avatarImage.invalidate(); } }); View lineView = new View(context); lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider)); linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1)); linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); descriptionTextView = new EditText(context); descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //descriptionTextView.setHintTextColor(0xff979797); descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6)); descriptionTextView.setBackgroundDrawable(null); descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(255); descriptionTextView.setFilters(inputFilters); descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder", R.string.DescriptionOptionalPlaceholder)); AndroidUtilities.clearCursorDrawable(descriptionTextView); linearLayout2.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6)); descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) { doneButton.performClick(); return true; } return false; } }); descriptionTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { } }); ShadowSectionCell sectionCell = new ShadowSectionCell(context); sectionCell.setSize(20); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (currentChat.megagroup || !currentChat.megagroup) { frameLayout = new FrameLayout(context); frameLayout.setElevation(AndroidUtilities.dp(2)); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); typeCell = new TextSettingsCell(context); updateTypeCell(); typeCell.setForeground(R.drawable.list_selector); frameLayout.addView(typeCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); lineView = new View(context); lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider)); linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1)); frameLayout = new FrameLayout(context); frameLayout.setElevation(AndroidUtilities.dp(2)); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (!currentChat.megagroup) { TextCheckCell textCheckCell = new TextCheckCell(context); textCheckCell.setForeground(R.drawable.list_selector); textCheckCell.setTextAndCheck( LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages), signMessages, false); frameLayout.addView(textCheckCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); textCheckCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signMessages = !signMessages; ((TextCheckCell) v).setChecked(signMessages); } }); TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context); //infoCell.setBackgroundResource(R.drawable.greydivider); infoCell.setText( LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo)); linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } else { adminCell = new TextSettingsCell(context); updateAdminCell(); adminCell.setForeground(R.drawable.list_selector); frameLayout.addView(adminCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); adminCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putInt("chat_id", chatId); args.putInt("type", 1); presentFragment(new ChannelUsersActivity(args)); } }); sectionCell = new ShadowSectionCell(context); sectionCell.setSize(20); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); /*if (!currentChat.creator) { sectionCell.setBackgroundResource(R.drawable.greydivider_bottom); }*/ } } if (currentChat.creator) { frameLayout = new FrameLayout(context); frameLayout.setElevation(AndroidUtilities.dp(2)); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); TextSettingsCell textCell = new TextSettingsCell(context); textCell.setTextColor(0xffed3d39); textCell.setBackgroundResource(R.drawable.list_selector); if (currentChat.megagroup) { textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false); } else { textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false); } frameLayout.addView(textCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); textCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (currentChat.megagroup) { builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert)); } else { builder.setMessage( LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert)); } builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, -(long) chatId); } else { NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); } MessagesController.getInstance().deleteUserFromChat(chatId, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), info); finishFragment(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context); //infoCell.setBackgroundResource(R.drawable.greydivider_bottom); if (currentChat.megagroup) { infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo)); } else { infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo)); } linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } nameTextView.setText(currentChat.title); nameTextView.setSelection(nameTextView.length()); if (info != null) { descriptionTextView.setText(info.about); } if (currentChat.photo != null) { avatar = currentChat.photo.photo_small; avatarImage.setImage(avatar, "50_50", avatarDrawable); } else { avatarImage.setImageDrawable(avatarDrawable); } return fragmentView; }
From source file:com.wit.and.dialog.internal.BaseDialog.java
/** * <h5><i>protected View onCreateDialogView(LayoutInflater inflater, * ViewGroup container, Bundle savedInstanceState)</i></h5> * <p>//ww w . jav a2 s . c om * Create the dialog main view into which will be placed title, body and * buttons view. * </p> * * @param inflater Layout inflater. * @param container Inflated dialog main view. * @param savedInstanceState Saved state. * @return Inflated dialog view. */ protected View onCreateDialogView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout layout = new LinearLayout(inflater.getContext()); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.setOrientation(LinearLayout.VERTICAL); return layout; }
From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showThemeDialog() { final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme()); Resources resources = getResources(); float density = ResourceUtils.obtainDensity(resources); ScrollView scrollView = new ScrollView(this); LinearLayout outer = new LinearLayout(this); outer.setOrientation(LinearLayout.VERTICAL); int outerPadding = (int) (16f * density); outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding); scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme) .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create(); View.OnClickListener listener = v -> { int index = (int) v.getTag(); if (index != checkedItem) { Preferences.setTheme(Preferences.VALUES_THEME[index]); recreate();// w w w . j a va 2 s .c om } dialog.dismiss(); }; int circleSize = (int) (56f * density); int itemPadding = (int) (12f * density); LinearLayout inner = null; for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) { if (i % 3 == 0) { inner = new LinearLayout(this); inner.setOrientation(LinearLayout.HORIZONTAL); outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER); layout.setBackgroundResource( ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0)); layout.setPadding(0, itemPadding, 0, itemPadding); layout.setOnClickListener(listener); layout.setTag(i); inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); View view = new View(this); int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0]; int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1]; int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2]; Resources.Theme theme = getResources().newTheme(); theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true); TypedArray typedArray = theme .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr }); view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0), typedArray.getColor(2, 0))); typedArray.recycle(); if (C.API_LOLLIPOP) { view.setElevation(6f * density); } layout.addView(view, circleSize, circleSize); TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setText(Preferences.ENTRIES_THEME[i]); if (C.API_LOLLIPOP) { textView.setAllCaps(true); textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f); } else { textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f); } textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(0, (int) (8f * density), 0, 0); layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) { if (Preferences.ENTRIES_THEME.length % 3 == 1) { inner.addView(new View(this), 0, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } inner.addView(new View(this), new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } } dialog.show(); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeView(boolean icon, boolean watcher, boolean closeable, float density) { int size = (int) (48f * density); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView iconView = null;//from w w w . j a v a 2 s .c o m if (icon) { iconView = new ImageView(context); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); linearLayout.addView(iconView, (int) (24f * density), size); } TextView textView = makeCommonTextView(false); linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1)); WatcherView watcherView = null; if (watcher) { watcherView = new WatcherView(context); linearLayout.addView(watcherView, size, size); } ImageView closeView = null; if (!watcher && closeable) { closeView = new ImageView(context); closeView.setScaleType(ImageView.ScaleType.CENTER); closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0)); closeView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); linearLayout.addView(closeView, size, size); closeView.setOnClickListener(closeButtonListener); } ViewHolder holder = new ViewHolder(); holder.icon = iconView; holder.text = textView; holder.extra = watcherView != null ? watcherView : closeView; linearLayout.setTag(holder); int layoutLeftDp = 0; int layoutRightDp = 0; int textLeftDp; int textRightDp; if (C.API_LOLLIPOP) { textLeftDp = 16; textRightDp = 16; if (icon) { layoutLeftDp = 16; textLeftDp = 32; } if (watcher || closeable) { layoutRightDp = 4; textRightDp = 8; } } else { textLeftDp = 8; textRightDp = 8; if (icon) { layoutLeftDp = 8; textLeftDp = 6; textView.setAllCaps(true); } if (watcher || closeable) { layoutRightDp = 0; textRightDp = 0; } } linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0); textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0); return linearLayout; }