List of usage examples for android.view Gravity CENTER_HORIZONTAL
int CENTER_HORIZONTAL
To view the source code for android.view Gravity CENTER_HORIZONTAL.
Click Source Link
From source file:com.goftagram.telegram.ui.PasscodeActivity.java
@Override public View createView(Context context) { if (type != 3) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); }/*from ww w . j a v a2 s . co m*/ actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } else if (id == pin_item) { currentPasswordType = 0; updateDropDownTextView(); } else if (id == password_item) { currentPasswordType = 1; updateDropDownTextView(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; if (type != 0) { ActionBarMenu menu = actionBar.createMenu(); menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); titleTextView = new TextView(context); titleTextView.setTextColor(0xff757575); if (type == 1) { if (UserConfig.passcodeHash.length() != 0) { titleTextView .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode)); } else { titleTextView.setText( LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode)); } } else { titleTextView .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode)); } titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); frameLayout.addView(titleTextView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER_HORIZONTAL; layoutParams.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams); 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); if (type == 1) { passcodeSetStep = 0; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); } else { passcodeSetStep = 1; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); } passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); frameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(90); layoutParams.height = AndroidUtilities.dp(36); layoutParams.leftMargin = AndroidUtilities.dp(40); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (passcodeSetStep == 0) { processNext(); return true; } else if (passcodeSetStep == 1) { processDone(); return true; } return false; } }); passwordEditText.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) { if (passwordEditText.length() == 4) { if (type == 2 && UserConfig.passcodeType == 0) { processDone(); } else if (type == 1 && currentPasswordType == 0) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } } } }); if (android.os.Build.VERSION.SDK_INT < 11) { passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { menu.clear(); } }); } else { 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; } }); } if (type == 1) { dropDownContainer = new ActionBarMenuItem(context, menu, R.drawable.bar_selector); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0); dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0); actionBar.addView(dropDownContainer); layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams(); layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; dropDownContainer.setLayoutParams(layoutParams); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown); layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.leftMargin = AndroidUtilities.dp(16); layoutParams.gravity = Gravity.CENTER_VERTICAL; layoutParams.bottomMargin = AndroidUtilities.dp(1); dropDown.setLayoutParams(layoutParams); } else { actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode)); } updateDropDownTextView(); } else { actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode)); frameLayout.setBackgroundColor(0xfff0f0f0); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); FrameLayout.LayoutParams 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 == changePasscodeRow) { presentFragment(new PasscodeActivity(1)); } else if (i == passcodeRow) { TextCheckCell cell = (TextCheckCell) view; if (UserConfig.passcodeHash.length() != 0) { UserConfig.passcodeHash = ""; UserConfig.appLocked = false; UserConfig.saveConfig(false); int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof TextSettingsCell) { TextSettingsCell textCell = (TextSettingsCell) child; textCell.setTextColor(0xffc6c6c6); break; } } cell.setChecked(UserConfig.passcodeHash.length() != 0); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.didSetPasscode); } else { presentFragment(new PasscodeActivity(1)); } } else if (i == autoLockRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock)); final NumberPicker numberPicker = new NumberPicker(getParentActivity()); numberPicker.setMinValue(0); numberPicker.setMaxValue(4); if (UserConfig.autoLockIn == 0) { numberPicker.setValue(0); } else if (UserConfig.autoLockIn == 60) { numberPicker.setValue(1); } else if (UserConfig.autoLockIn == 60 * 5) { numberPicker.setValue(2); } else if (UserConfig.autoLockIn == 60 * 60) { numberPicker.setValue(3); } else if (UserConfig.autoLockIn == 60 * 60 * 5) { numberPicker.setValue(4); } numberPicker.setFormatter(new NumberPicker.Formatter() { @Override public String format(int value) { if (value == 0) { return LocaleController.getString("Disabled", R.string.Disabled); } else if (value == 1) { return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1)); } else if (value == 2) { return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5)); } else if (value == 3) { return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1)); } else if (value == 4) { return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 5)); } return ""; } }); builder.setView(numberPicker); builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { which = numberPicker.getValue(); if (which == 0) { UserConfig.autoLockIn = 0; } else if (which == 1) { UserConfig.autoLockIn = 60; } else if (which == 2) { UserConfig.autoLockIn = 60 * 5; } else if (which == 3) { UserConfig.autoLockIn = 60 * 60; } else if (which == 4) { UserConfig.autoLockIn = 60 * 60 * 5; } listView.invalidateViews(); UserConfig.saveConfig(false); } }); showDialog(builder.create()); } else if (i == fingerprintRow) { UserConfig.useFingerprint = !UserConfig.useFingerprint; UserConfig.saveConfig(false); ((TextCheckCell) view).setChecked(UserConfig.useFingerprint); } } }); } return fragmentView; }
From source file:com.java2s.intents4.IntentsDemo4Activity.java
void addRow(final LinearLayout layout, String label, String hintStr, boolean addRadioGroup) { LinearLayout.LayoutParams rowLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1); if (addRadioGroup) { editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1); }/*from ww w . j a v a2s. c om*/ LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); row.setGravity(Gravity.CENTER_VERTICAL); TextView textView = new TextView(this); textView.setText(label); row.addView(textView); EditText editText = new EditText(this); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); editText.setHint(hintStr); editText.setLayoutParams(editTextLayoutParams); if (!isFirstTime) { editText.requestFocus(); } row.addView(editText); if (addRadioGroup) { LinearLayout groupLayout = new LinearLayout(this); groupLayout.setOrientation(LinearLayout.VERTICAL); groupLayout.setGravity(Gravity.CENTER_HORIZONTAL); RadioGroup group = new RadioGroup(this); group.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT)); final Button patternButton = new Button(this); patternButton.setText(pathPatterns[0]); patternButton.setTextSize(8); patternButton.setLayoutParams(buttonLayoutParams); patternButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String patternButtonText = patternButton.getText().toString().trim(); if (patternButtonText.equals(pathPatterns[0])) { patternButton.setText(pathPatterns[1]); } else if (patternButtonText.equals(pathPatterns[1])) { patternButton.setText(pathPatterns[2]); } else if (patternButtonText.equals(pathPatterns[2])) { patternButton.setText(pathPatterns[0]); } } }); groupLayout.addView(patternButton); row.addView(groupLayout); } Button button = new Button(this); button.setTextSize(10); button.setTypeface(null, Typeface.BOLD); button.setText("X"); button.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); button.setLayoutParams(buttonLayoutParams); button.setOnClickListener(new OnClickListener() { public void onClick(View view) { layout.removeView((LinearLayout) view.getParent()); } }); row.addView(button); row.setLayoutParams(rowLayoutParams); layout.addView(row); }
From source file:ir.besteveryeverapp.ui.PasscodeActivity.java
@Override public View createView(Context context) { if (type != 3) { actionBar.setBackButtonImage(ir.besteveryeverapp.telegram.R.drawable.ic_ab_back); }// w ww .j a v a 2 s . com actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } else if (id == pin_item) { currentPasswordType = 0; updateDropDownTextView(); } else if (id == password_item) { currentPasswordType = 1; updateDropDownTextView(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; if (type != 0) { ActionBarMenu menu = actionBar.createMenu(); menu.addItemWithWidth(done_button, ir.besteveryeverapp.telegram.R.drawable.ic_done, AndroidUtilities.dp(56)); titleTextView = new TextView(context); titleTextView.setTextColor(0xff757575); if (type == 1) { if (UserConfig.passcodeHash.length() != 0) { titleTextView.setText(LocaleController.getString("EnterNewPasscode", ir.besteveryeverapp.telegram.R.string.EnterNewPasscode)); } else { titleTextView.setText(LocaleController.getString("EnterNewFirstPasscode", ir.besteveryeverapp.telegram.R.string.EnterNewFirstPasscode)); } } else { titleTextView.setText(LocaleController.getString("EnterCurrentPasscode", ir.besteveryeverapp.telegram.R.string.EnterCurrentPasscode)); } titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); frameLayout.addView(titleTextView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER_HORIZONTAL; layoutParams.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams); 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); if (type == 1) { passcodeSetStep = 0; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); } else { passcodeSetStep = 1; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); } passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); frameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(90); layoutParams.height = AndroidUtilities.dp(36); layoutParams.leftMargin = AndroidUtilities.dp(40); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (passcodeSetStep == 0) { processNext(); return true; } else if (passcodeSetStep == 1) { processDone(); return true; } return false; } }); passwordEditText.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) { if (passwordEditText.length() == 4) { if (type == 2 && UserConfig.passcodeType == 0) { processDone(); } else if (type == 1 && currentPasswordType == 0) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } } } }); 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; } }); if (type == 1) { dropDownContainer = new ActionBarMenuItem(context, menu, //R.drawable.bar_selector_f SkinMan.barSelector(context)); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", ir.besteveryeverapp.telegram.R.string.PasscodePIN), 0); dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword", ir.besteveryeverapp.telegram.R.string.PasscodePassword), 0); actionBar.addView(dropDownContainer); layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams(); layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; dropDownContainer.setLayoutParams(layoutParams); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setTypeface(FontManager.instance().getTypeface()); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, ir.besteveryeverapp.telegram.R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown); layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.leftMargin = AndroidUtilities.dp(16); layoutParams.gravity = Gravity.CENTER_VERTICAL; layoutParams.bottomMargin = AndroidUtilities.dp(1); dropDown.setLayoutParams(layoutParams); } else { actionBar.setTitle( LocaleController.getString("Passcode", ir.besteveryeverapp.telegram.R.string.Passcode)); } updateDropDownTextView(); } else { actionBar.setTitle( LocaleController.getString("Passcode", ir.besteveryeverapp.telegram.R.string.Passcode)); frameLayout.setBackgroundColor(0xfff0f0f0); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); FrameLayout.LayoutParams 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 == changePasscodeRow) { presentFragment(new PasscodeActivity(1)); } else if (i == passcodeRow) { TextCheckCell cell = (TextCheckCell) view; if (UserConfig.passcodeHash.length() != 0) { UserConfig.passcodeHash = ""; UserConfig.appLocked = false; UserConfig.saveConfig(false); int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof TextSettingsCell) { TextSettingsCell textCell = (TextSettingsCell) child; textCell.setTextColor(0xffc6c6c6); break; } } cell.setChecked(UserConfig.passcodeHash.length() != 0); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.didSetPasscode); } else { presentFragment(new PasscodeActivity(1)); } } else if (i == autoLockRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AutoLock", ir.besteveryeverapp.telegram.R.string.AutoLock)); final NumberPicker numberPicker = new NumberPicker(getParentActivity()); numberPicker.setMinValue(0); numberPicker.setMaxValue(4); if (UserConfig.autoLockIn == 0) { numberPicker.setValue(0); } else if (UserConfig.autoLockIn == 60) { numberPicker.setValue(1); } else if (UserConfig.autoLockIn == 60 * 5) { numberPicker.setValue(2); } else if (UserConfig.autoLockIn == 60 * 60) { numberPicker.setValue(3); } else if (UserConfig.autoLockIn == 60 * 60 * 5) { numberPicker.setValue(4); } numberPicker.setFormatter(new NumberPicker.Formatter() { @Override public String format(int value) { if (value == 0) { return LocaleController.getString("AutoLockDisabled", ir.besteveryeverapp.telegram.R.string.AutoLockDisabled); } else if (value == 1) { return LocaleController.formatString("AutoLockInTime", ir.besteveryeverapp.telegram.R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1)); } else if (value == 2) { return LocaleController.formatString("AutoLockInTime", ir.besteveryeverapp.telegram.R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5)); } else if (value == 3) { return LocaleController.formatString("AutoLockInTime", ir.besteveryeverapp.telegram.R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1)); } else if (value == 4) { return LocaleController.formatString("AutoLockInTime", ir.besteveryeverapp.telegram.R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 5)); } return ""; } }); builder.setView(numberPicker); builder.setNegativeButton( LocaleController.getString("Done", ir.besteveryeverapp.telegram.R.string.Done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { which = numberPicker.getValue(); if (which == 0) { UserConfig.autoLockIn = 0; } else if (which == 1) { UserConfig.autoLockIn = 60; } else if (which == 2) { UserConfig.autoLockIn = 60 * 5; } else if (which == 3) { UserConfig.autoLockIn = 60 * 60; } else if (which == 4) { UserConfig.autoLockIn = 60 * 60 * 5; } listView.invalidateViews(); UserConfig.saveConfig(false); } }); showDialog(builder.create()); } else if (i == fingerprintRow) { UserConfig.useFingerprint = !UserConfig.useFingerprint; UserConfig.saveConfig(false); ((TextCheckCell) view).setChecked(UserConfig.useFingerprint); } } }); } NightModeUtil.dark(fragmentView); FontManager.instance().setTypefaceImmediate(fragmentView); return fragmentView; }
From source file:widgets.Graphical_Range.java
public Graphical_Range(tracerengine Trac, Activity context, String address, String name, int id, int dev_id, String state_key, String url, String usage, String parameters, String model_id, int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params) throws JSONException { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.address = address; this.url = url; this.dev_id = dev_id; this.id = id; this.state_key = state_key; this.usage = usage; this.update = update; this.wname = name; this.myself = this; this.session_type = session_type; this.place_id = place_id; this.place_type = place_type; this.context = context; stateThread = 1;/* ww w . j a va 2 s . c om*/ this.stateS = getResources().getText(R.string.State).toString(); mytag = "Graphical_Range(" + dev_id + ")"; this.params = params; login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); //get parameters JSONObject jparam = new JSONObject(parameters.replaceAll(""", "\"")); command = jparam.getString("command"); valueMin = jparam.getInt("valueMin"); valueMax = jparam.getInt("valueMax"); range = valueMax - valueMin; scale = 100 / range; try { test_unite = jparam.getString("unit"); } catch (JSONException e) { test_unite = "%"; } if (test_unite == null || test_unite.length() == 0) { test_unite = "%"; } String[] model = model_id.split("\\."); type = model[0]; //linearlayout horizontal body bodyPanHorizontal = new LinearLayout(context); bodyPanHorizontal.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.CENTER_VERTICAL)); bodyPanHorizontal.setOrientation(LinearLayout.HORIZONTAL); //right panel with different info and seekbars rightPan = new FrameLayout(context); rightPan.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); rightPan.setPadding(0, 0, 10, 0); // panel leftPan = new LinearLayout(context); leftPan.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.BOTTOM)); leftPan.setOrientation(LinearLayout.VERTICAL); leftPan.setGravity(Gravity.CENTER_VERTICAL); leftPan.setPadding(4, 5, 0, 0); state = new TextView(context); state.setTextColor(Color.BLACK); state.setPadding(20, 0, 0, 0); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); //first seekbar variator seekBarVaria = new SeekBar(context); seekBarVaria.setProgress(0); seekBarVaria.setMax(valueMax - valueMin); seekBarVaria.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); seekBarVaria.setProgressDrawable(getResources().getDrawable(R.drawable.bgseekbarvaria)); seekBarVaria.setThumb(getResources().getDrawable(R.drawable.buttonseekbar)); seekBarVaria.setThumbOffset(-3); seekBarVaria.setOnSeekBarChangeListener(this); seekBarVaria.setPadding(0, 0, 15, 7); leftPan.addView(state); leftPan.addView(seekBarVaria); rightPan.addView(leftPan); bodyPanHorizontal.addView(rightPan); super.LL_topPan.removeView(super.LL_featurePan); super.LL_infoPan.addView(bodyPanHorizontal); handler = new Handler() { @Override public void handleMessage(Message msg) { /// Deprecated method to die ///////////////////////////////////////// if (activate) { Tracer.d(mytag, "Handler receives a request to die "); //That seems to be a zombie removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself /////////////////////////////////////////////////////////////////// } else { int new_val = 0; if (msg.what == 9999) { //state_engine send us a signal to notify value changed if (session == null) return; try { Tracer.d(mytag, "Handler receives a new value from cache_engine <" + session.getValue() + ">"); new_val = Integer.parseInt(session.getValue()); } catch (Exception e) { new_val = 0; } //#1649 //Value min and max should be the limit of the widget if (new_val <= valueMin) { state.setText(stateS + valueMin + " " + test_unite); } else if (new_val > valueMin && new_val < valueMax) { state.setText(stateS + new_val + " " + test_unite); } else if (new_val >= valueMax) { state.setText(stateS + valueMax + " " + test_unite); } state.setAnimation(animation); new SBAnim(seekBarVaria.getProgress(), new_val - valueMin).execute(); } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "state engine disappeared ===> Harakiri !"); session = null; realtime = false; removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } } }; //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (Tracer.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ }
From source file:cn.com.caronwer.activity.CertificationActivity.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_left_white: if (mLl_cer1.getVisibility() == View.GONE) { mLl_cer1.setVisibility(View.VISIBLE); mLl_cer2.setVisibility(View.GONE); } else {/*ww w . j av a2s .c o m*/ finish(); } break; case R.id.bv_queren: //? posData(); break; case R.id.pv_sfz: // Toast.makeText(this, "??", Toast.LENGTH_SHORT).show(); imgType = 0; menuWindow = new SelectPicPopupWindow(CertificationActivity.this, itemsOnClick); menuWindow.showAtLocation(findViewById(R.id.activity_rebuild_psd), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); break; case R.id.pv_jsz: // Toast.makeText(this, "??", Toast.LENGTH_SHORT).show(); imgType = 1; menuWindow = new SelectPicPopupWindow(CertificationActivity.this, itemsOnClick); menuWindow.showAtLocation(findViewById(R.id.activity_rebuild_psd), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); break; case R.id.pv_xsz: // Toast.makeText(this, "??", Toast.LENGTH_SHORT).show(); imgType = 2; menuWindow = new SelectPicPopupWindow(CertificationActivity.this, itemsOnClick); menuWindow.showAtLocation(findViewById(R.id.activity_rebuild_psd), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); break; case R.id.pv_cl: // Toast.makeText(this, "?", Toast.LENGTH_SHORT).show(); imgType = 3; menuWindow = new SelectPicPopupWindow(CertificationActivity.this, itemsOnClick); menuWindow.showAtLocation(findViewById(R.id.activity_rebuild_psd), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); break; case R.id.bv_next: String name = mEt_name.getText().toString(); String cardid = mEt_cardNo.getText().toString(); String jiasz = mEt_drivingLicense.getText().toString(); String xingsz = mEt_roadPermit.getText().toString(); String cheph = mEt_carNumber.getText().toString(); int chelx = VehType; //String gps = mEt_gps.getText().toString(); if (name.isEmpty() || cardid.isEmpty() || jiasz.isEmpty() || cheph.isEmpty() || xingsz.isEmpty() //|| gps.isEmpty() ) { Toast.makeText(CertificationActivity.this, "??", Toast.LENGTH_SHORT).show(); } else { mJsonObject.addProperty("UserName", name); mJsonObject.addProperty("IDNumber", cardid); mJsonObject.addProperty("UserId", SPtils.getString(this, "UserId", "00000000-0000-0000-0000-000000000000")); mJsonObject.addProperty("DriverId", jiasz); mJsonObject.addProperty("VehicleNo", cheph); mJsonObject.addProperty("TravelCard", xingsz); mJsonObject.addProperty("VehType", chelx); //mJsonObject.addProperty("GpsNo", gps); mLl_cer1.setVisibility(View.GONE); mLl_cer2.setVisibility(View.VISIBLE); } break; } }
From source file:com.inductivebiblestudyapp.ui.dialogs.SimpleTooltipDialog.java
/** Adjusts the location of the dialog and positions the arrow. * /*from w ww .ja v a2s .co m*/ * @param dialog The dialog * @param rootView The rootView of the dialog * @param anchorLocation An X =0, Y=1 array of the anchor location via getLocationOnScreen. * @param anchorDimens An X =0, Y=1 array of anchor size in pixels * @param centered Whether to center the dialog or not. */ protected void adjustView(Dialog dialog, View rootView, int[] anchorLocation, int[] anchorDimens, boolean centered) { final int X_INDEX = 0; final int Y_INDEX = 1; try { int[] screenSize = new int[2]; getScreenDimens(screenSize); rootView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); final int rootWidth = rootView.getMeasuredWidth(); final int rootHeight = rootView.getMeasuredHeight(); final int[] screenCenter = new int[] { screenSize[X_INDEX] / 2, screenSize[Y_INDEX] / 2 }; //we have not displayed it yet, so we cannot measure location. //Instead, we will estimate based on Gravity.CENTER x and y final int[] estRootLocation = new int[] { screenCenter[X_INDEX] - rootWidth / 2, screenCenter[Y_INDEX] - rootHeight / 2 }; //if not left, right final boolean anchorToLeft = screenCenter[X_INDEX] >= anchorLocation[X_INDEX]; //if not top, bottom final boolean anchorToTop = screenCenter[Y_INDEX] >= anchorLocation[Y_INDEX]; WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); // lets start by calculating our midpoint //the horizontal center of the anchor relative to left side of screen final int anchorMidpointX = anchorLocation[X_INDEX] + anchorDimens[X_INDEX] / 2; //were the arrow margin should go. int arrowMarginLeft = 0; if (centered) { wmlp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; arrowMarginLeft = anchorMidpointX - estRootLocation[X_INDEX]; } else { //LEFT required if manually positioning. wmlp.gravity = Gravity.TOP | Gravity.LEFT; //center our dialog under our anchor as best as possible int dialogPosFromLeft = anchorMidpointX - rootWidth / 2; //check our values are sane. if (dialogPosFromLeft + rootWidth >= screenSize[X_INDEX]) { dialogPosFromLeft = screenSize[X_INDEX] - rootWidth; } else if (dialogPosFromLeft <= 0) { dialogPosFromLeft = 1; } wmlp.x = dialogPosFromLeft; arrowMarginLeft = anchorMidpointX - dialogPosFromLeft; } //horizontal positions are now calculated, now let's align our dialog vertically to be directly above our view. //the position from the top of the screen, to place the dialog. int desiredPosFromTop = 0; //the arrow params LinearLayout.LayoutParams arrowParams = null; if (anchorToTop) { //position ourself above. desiredPosFromTop = anchorLocation[Y_INDEX] + anchorDimens[Y_INDEX] - getStatusBarHeight(); mDownArrow.setVisibility(View.GONE); arrowParams = (LinearLayout.LayoutParams) mUpArrow.getLayoutParams(); } else { desiredPosFromTop = anchorLocation[Y_INDEX] - rootHeight - getStatusBarHeight(); mUpArrow.setVisibility(View.GONE); arrowParams = (LinearLayout.LayoutParams) mDownArrow.getLayoutParams(); } arrowParams.leftMargin = arrowMarginLeft; if (desiredPosFromTop >= screenSize[Y_INDEX]) { wmlp.y = screenSize[Y_INDEX] - 1; } else if (desiredPosFromTop <= 0) { wmlp.y = 1; } else { wmlp.y = desiredPosFromTop; } dialog.getWindow().setAttributes(wmlp); //force change, even at runtime. } catch (Exception e) { e.printStackTrace(); } }
From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.activities.MainActivity.java
private void initTransparentView() { /* Avoid displaying infographic if the home button has been pushed */ Intent intent = getIntent();//from w w w . j a va2 s . c om displayInfographic = intent.getBooleanExtra(EXTRA_DISPLAY_INFOGRAPHIC, true); System.out.println("Display info " + displayInfographic); if (!displayInfographic) { LinearLayout linear = (LinearLayout) findViewById(R.id.transparentLayer); linear.setVisibility(View.INVISIBLE); return; } /* Setup the OK button */ Button okButton = (Button) findViewById(R.id.okButton); if (okButton != null) { okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("OK button pushed"); Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_down); LinearLayout linear = (LinearLayout) findViewById(R.id.transparentLayer); linear.startAnimation(animation); linear.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getBaseContext(), "Apasa pe simbolurile din jurul tau", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); /* Display initial seek bar value */ Rect thumbRect = seekBar.getThumb().getBounds(); seekBarValue.setX(thumbRect.exactCenterX()); DecimalFormat dm = new DecimalFormat("###,###.###"); seekBarValue.setText(" " + String.valueOf(dm.format(CommManager.aroundTotalSum)) + " EURO "); seekBarValue.setVisibility(View.VISIBLE); seekBarValue.startAnimation(animationFadeIn); } }); } /* Send request to get the init data */ CommManager.requestInitData(new ICommManagerResponse() { @Override public void processResponse(JSONObject response) { MainActivity.this.receiveInitData(response); } @Override public void onErrorOccurred(String errorMsg) { Toast.makeText(MainActivity.this, "Eroare conectare la server", Toast.LENGTH_SHORT).show(); } }); }
From source file:com.github.rubensousa.bottomsheetbuilder.BottomSheetBuilder.java
public View createView() { if (mMenu == null) { throw new IllegalStateException("You need to provide at least one Menu" + "or a Menu resource id"); }//www . j ava 2 s .c o m if (mCoordinatorLayout == null) { throw new IllegalStateException( "You need to provide a coordinatorLayout" + "so the view can be placed on it"); } View sheet = mAdapterBuilder.createView(mItemTextColor, mTitleTextColor, mBackgroundDrawable, mBackgroundColor, mDividerBackground, mItemBackground, mIconTintColor, mItemClickListener); ViewCompat.setElevation(sheet, mContext.getResources().getDimensionPixelSize(R.dimen.bottomsheet_elevation)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sheet.findViewById(R.id.fakeShadow).setVisibility(View.GONE); } CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams( CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.CENTER_HORIZONTAL; layoutParams.setBehavior(new BottomSheetBehavior()); if (mContext.getResources().getBoolean(R.bool.tablet_landscape)) { layoutParams.width = mContext.getResources().getDimensionPixelSize(R.dimen.bottomsheet_width); } mCoordinatorLayout.addView(sheet, layoutParams); mCoordinatorLayout.postInvalidate(); return sheet; }
From source file:com.b44t.ui.PasscodeActivity.java
@Override public View createView(Context context) { actionBar/*from w ww .jav a 2 s . c o m*/ .setBackButtonImage(screen == SCREEN0_SETTINGS ? R.drawable.ic_ab_back : R.drawable.ic_close_white); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } else if (id == pin_item) { currentPasswordType = 0; updateDropDownTextView(); } else if (id == password_item) { currentPasswordType = 1; updateDropDownTextView(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; if (screen != SCREEN0_SETTINGS) { ActionBarMenu menu = actionBar.createMenu(); menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); titleTextView = new TextView(context); titleTextView.setTextColor(0xff757575); if (screen == SCREEN1_ENTER_CODE1) { if (UserConfig.passcodeHash.length() != 0) { titleTextView .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode)); } else { titleTextView.setText( LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode)); } } else { titleTextView .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode)); } titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); frameLayout.addView(titleTextView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER_HORIZONTAL; layoutParams.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams); 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); if (screen == SCREEN1_ENTER_CODE1) { passcodeSetStep = 0; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); } else { passcodeSetStep = 1; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); } passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); frameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(90); layoutParams.height = AndroidUtilities.dp(36); layoutParams.leftMargin = AndroidUtilities.dp(40); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (passcodeSetStep == 0) { processNext(); return true; } else if (passcodeSetStep == 1) { processDone(); return true; } return false; } }); passwordEditText.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) { if (passwordEditText.length() == 4) { if (screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) { processDone(); } else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } } } }); 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; } }); if (screen == SCREEN1_ENTER_CODE1) { dropDownContainer = new ActionBarMenuItem(context, menu, 0); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0); dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0); actionBar.addView(dropDownContainer); layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams(); layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; dropDownContainer.setLayoutParams(layoutParams); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown); layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.leftMargin = AndroidUtilities.dp(16); layoutParams.gravity = Gravity.CENTER_VERTICAL; layoutParams.bottomMargin = AndroidUtilities.dp(1); dropDown.setLayoutParams(layoutParams); } else { actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode)); } updateDropDownTextView(); } else { actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode)); frameLayout.setBackgroundColor(0xfff0f0f0); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); FrameLayout.LayoutParams 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 == changePasscodeRow) { presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1)); } else if (i == passcodeOnOffRow) { TextCheckCell cell = (TextCheckCell) view; if (UserConfig.passcodeHash.length() != 0) { UserConfig.passcodeHash = ""; UserConfig.appLocked = false; UserConfig.saveConfig(false); int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof TextSettingsCell) { TextSettingsCell textCell = (TextSettingsCell) child; textCell.setTextColor(0xffc6c6c6); break; } } cell.setChecked(UserConfig.passcodeHash.length() != 0); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.didSetPasscode); } else { presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1)); } } else if (i == autoLockRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock)); final NumberPicker numberPicker = new NumberPicker(getParentActivity()); numberPicker.setMinValue(0); numberPicker.setMaxValue(4); if (UserConfig.autoLockIn == 0) { numberPicker.setValue(0); } else if (UserConfig.autoLockIn == 60) { numberPicker.setValue(1); } else if (UserConfig.autoLockIn == 60 * 5) { numberPicker.setValue(2); } else if (UserConfig.autoLockIn == 60 * 60) { numberPicker.setValue(3); } else if (UserConfig.autoLockIn == 60 * 60 * 5) { numberPicker.setValue(4); } numberPicker.setFormatter(new NumberPicker.Formatter() { @Override public String format(int value) { if (value == 0) { return LocaleController.getString("Disabled", R.string.Disabled); } else if (value == 1) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Minutes, 1, 1); } else if (value == 2) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Minutes, 5, 5); } else if (value == 3) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Hours, 1, 1); } else if (value == 4) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Hours, 5, 5); } return ""; } }); numberPicker.setWrapSelectorWheel(false); builder.setView(numberPicker); builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { which = numberPicker.getValue(); if (which == 0) { UserConfig.autoLockIn = 0; } else if (which == 1) { UserConfig.autoLockIn = 60; } else if (which == 2) { UserConfig.autoLockIn = 60 * 5; } else if (which == 3) { UserConfig.autoLockIn = 60 * 60; } else if (which == 4) { UserConfig.autoLockIn = 60 * 60 * 5; } listView.invalidateViews(); UserConfig.saveConfig(false); } }); showDialog(builder.create()); } else if (i == fingerprintRow) { UserConfig.useFingerprint = !UserConfig.useFingerprint; UserConfig.saveConfig(false); ((TextCheckCell) view).setChecked(UserConfig.useFingerprint); } } }); } return fragmentView; }
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//from w ww . ja v a 2s.c o m 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; }