List of usage examples for android.widget NumberPicker setMinValue
public void setMinValue(int minValue)
From source file:com.b44t.ui.PasscodeActivity.java
@Override public View createView(Context context) { actionBar/*www . j a va2s . co 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.cafemember.ui.PasscodeActivity.java
@Override public View createView(Context context) { if (type != 3) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); }/*from w ww . j ava 2s. c o 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, 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.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("AutoLockDisabled", R.string.AutoLockDisabled); } 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:kr.wdream.ui.PasscodeActivity.java
@Override public View createView(Context context) { Log.d(LOG_TAG, "createView"); if (type != 3) { actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back); }/*from w w w. j a v a 2 s . c om*/ 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, kr.wdream.storyshop.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", kr.wdream.storyshop.R.string.EnterNewPasscode)); } else { titleTextView.setText(LocaleController.getString("EnterNewFirstPasscode", kr.wdream.storyshop.R.string.EnterNewFirstPasscode)); } } else { titleTextView.setText(LocaleController.getString("EnterCurrentPasscode", kr.wdream.storyshop.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, 0); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", kr.wdream.storyshop.R.string.PasscodePIN), 0); dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword", kr.wdream.storyshop.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, kr.wdream.storyshop.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", kr.wdream.storyshop.R.string.Passcode)); } updateDropDownTextView(); } else { actionBar.setTitle(LocaleController.getString("Passcode", kr.wdream.storyshop.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", kr.wdream.storyshop.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", kr.wdream.storyshop.R.string.AutoLockDisabled); } else if (value == 1) { return LocaleController.formatString("AutoLockInTime", kr.wdream.storyshop.R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1)); } else if (value == 2) { return LocaleController.formatString("AutoLockInTime", kr.wdream.storyshop.R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5)); } else if (value == 3) { return LocaleController.formatString("AutoLockInTime", kr.wdream.storyshop.R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1)); } else if (value == 4) { return LocaleController.formatString("AutoLockInTime", kr.wdream.storyshop.R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 5)); } return ""; } }); builder.setView(numberPicker); builder.setNegativeButton( LocaleController.getString("Done", kr.wdream.storyshop.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:ir.besteveryeverapp.ui.PasscodeActivity.java
@Override public View createView(Context context) { if (type != 3) { actionBar.setBackButtonImage(ir.besteveryeverapp.telegram.R.drawable.ic_ab_back); }//from w w w. j a va2s . c o 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, 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:org.telegram.ui.ProfileNotificationsActivity.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/*w w w. ja v a 2 s .c o m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5)); frameLayout.addView(listView); final 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, View view, final int i, long l) { if (i == settingsVibrateRow) { 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("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("SystemDefault", R.string.SystemDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long) }, 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 (which == 0) { editor.putInt("vibrate_" + dialog_id, 2); } else if (which == 1) { editor.putInt("vibrate_" + dialog_id, 0); } else if (which == 2) { editor.putInt("vibrate_" + dialog_id, 4); } else if (which == 3) { editor.putInt("vibrate_" + dialog_id, 1); } else if (which == 4) { editor.putInt("vibrate_" + dialog_id, 3); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsNotificationsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems( new CharSequence[] { LocaleController.getString("Default", R.string.Default), LocaleController.getString("Enabled", R.string.Enabled), LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("notify2_" + dialog_id, which); if (which == 2) { NotificationsController.getInstance() .removeNotificationsForDialog(dialog_id); } MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0); editor.commit(); TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict .get(dialog_id); if (dialog != null) { dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); if (which == 2) { dialog.notify_settings.mute_until = Integer.MAX_VALUE; } } if (listView != null) { listView.invalidateViews(); } NotificationsController.updateServerNotificationsSettings(dialog_id); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsSoundRow) { try { 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)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Uri currentSound = null; String defaultPath = null; Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; if (defaultUri != null) { defaultPath = defaultUri.getPath(); } String path = preferences.getString("sound_path_" + dialog_id, 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, 12); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == settingsLedRow) { 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 (preferences.contains("color_" + dialog_id)) { colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00)); } else { if ((int) dialog_id < 0) { colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00)); } else { colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 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(); editor.putInt("color_" + dialog_id, colorPickerView.getColor()); editor.commit(); listView.invalidateViews(); } }); 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(); editor.putInt("color_" + dialog_id, 0); editor.commit(); listView.invalidateViews(); } }); builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), 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(); editor.remove("color_" + dialog_id); editor.commit(); listView.invalidateViews(); } }); showDialog(builder.create()); } else if (i == settingsPriorityRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority)); builder.setItems( new CharSequence[] { LocaleController.getString("SettingsDefault", R.string.SettingsDefault), 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) { if (which == 0) { which = 3; } else { which--; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("priority_" + dialog_id, which).commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == smartRow) { if (getParentActivity() == null) { return; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount == 0) { notifyMaxCount = 2; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2 .getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); TextView textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost", R.string.SmartNotificationsSoundAtMost)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity()); numberPickerTimes.setMinValue(1); numberPickerTimes.setMaxValue(10); numberPickerTimes.setValue(notifyMaxCount); linearLayout2.addView(numberPickerTimes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerTimes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsTimes", R.string.SmartNotificationsTimes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsWithin", R.string.SmartNotificationsWithin)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity()); numberPickerMinutes.setMinValue(1); numberPickerMinutes.setMaxValue(10); numberPickerMinutes.setValue(notifyDelay / 60); linearLayout2.addView(numberPickerMinutes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerMinutes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsMinutes", R.string.SmartNotificationsMinutes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit() .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue()) .commit(); preferences.edit() .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60) .commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled", R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit(); if (listView != null) { listView.invalidateViews(); } } }); showDialog(builder.create()); } } }); return fragmentView; }
From source file:com.softminds.matrixcalculator.dialog_activity.FunctionMaker.java
@Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false); if (isDark)//from www.ja v a 2 s . com setTheme(R.style.AppThemeDarkDialog); else setTheme(R.style.AppThemeDialog); super.onCreate(savedInstanceState); setContentView(R.layout.activity_function_maker); //Grab all Control References Button proceed = findViewById(R.id.ConfirmMakeFunction); final NumberPicker expo = findViewById(R.id.FunctionMakerExponent); final NumberPicker deg = findViewById(R.id.FunctionMakerDegree); final EditText coefficient = findViewById(R.id.MainCoefficientFiller); //Put Properties to Number Picker expo.setValue(1); expo.setMinValue(1); expo.setMaxValue(9); deg.setMinValue(1); deg.setMaxValue(7); deg.setValue(1); //Grab Default References final TextView ConstSign = findViewById(R.id.ConstantSign); final TextView FirstAuto = findViewById(R.id.FirstXAuto); FirstAuto.setText(ConvertToExponent(getString(R.string.X))); final TextView Const = findViewById(R.id.ConstantValueFunction); //Grab all Inactive TextViews final TextView Term1 = findViewById(R.id.CreatedXAuto1); Term1.setText(null); Term1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term1; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term2 = findViewById(R.id.CreatedXAuto2); Term2.setText(null); Term2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term2; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term3 = findViewById(R.id.CreatedXAuto3); Term3.setText(null); Term3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term3; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term4 = findViewById(R.id.CreatedXAuto4); Term4.setText(null); Term4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term4; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term5 = findViewById(R.id.CreatedXAuto5); Term5.setText(null); Term5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term5; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term6 = findViewById(R.id.CreatedXAuto6); Term6.setText(null); Term6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term6; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); //All Inactive Signs and Setting Click to Change Sign final TextView Sign1 = findViewById(R.id.AutoSign1); Sign1.setText(null); Sign1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign1); } }); final TextView Sign2 = findViewById(R.id.AutoSign2); Sign2.setText(null); Sign2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign2); } }); final TextView Sign3 = findViewById(R.id.AutoSign3); Sign3.setText(null); Sign3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign3); } }); final TextView Sign4 = findViewById(R.id.AutoSign4); Sign4.setText(null); Sign4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign4); } }); final TextView Sign5 = findViewById(R.id.AutoSign5); Sign5.setText(null); Sign5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign5); } }); final TextView Sign6 = findViewById(R.id.AutoSign6); Sign6.setText(null); Sign6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign6); } }); //Set Click Listener to each deg.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int i) { //Degree maker will be here switch (numberPicker.getValue()) { case 7: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term6.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign6.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.X))); Sign3.setText("+"); Term4.setText(ConvertToExponent(getString(R.string.X))); Sign4.setText("+"); Term5.setText(ConvertToExponent(getString(R.string.X))); Sign5.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); break; case 6: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term5.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign5.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.X))); Sign3.setText("+"); Term4.setText(ConvertToExponent(getString(R.string.X))); Sign4.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Sign6.setText(null); Term6.setText(null); break; case 5: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term4.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign4.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.X))); Sign3.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Term5.setText(null); Term6.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 4: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign3.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 3: Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Term2.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign2.setText("+"); Term3.setText(null); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign3.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 2: Term1.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign1.setText("+"); Term2.setText(null); Term3.setText(null); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign2.setText(null); Sign3.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 1: Term1.setText(null); Sign1.setText(null); Term2.setText(null); Term3.setText(null); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign2.setText(null); Sign3.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; } } }); expo.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int i) { if (CurrentTermCoefficient != null) { if (CurrentTermCoefficient.getText().toString().contains("x")) { String order = CurrentTermCoefficient.getText().toString(); String SubString = order.substring(0, order.indexOf("x") + 1); //Get Everything except from Exponent String SubString2 = SubString + String.valueOf(numberPicker.getValue()); CurrentTermCoefficient.setText(ConvertToExponent(SubString2)); } } else { Toast.makeText(getApplicationContext(), R.string.Warning12, Toast.LENGTH_SHORT).show(); numberPicker.setValue(2); } } }); //EditText KeyChange Listener coefficient.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (CurrentTermCoefficient == null) { Toast.makeText(getApplicationContext(), R.string.Warning12, Toast.LENGTH_SHORT).show(); return true; } else { if (CurrentTermCoefficient.getText().toString().contains("x")) { String res = coefficient.getText().toString() + "x" + String.valueOf(expo.getValue()); CurrentTermCoefficient.setText(ConvertToExponent(res)); } else CurrentTermCoefficient.setText(coefficient.getText().toString()); return false; } } }); //default Changers ConstSign.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(ConstSign); } }); //default Coefficient FirstAuto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = FirstAuto; FirstAuto.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); //Constant changer Const.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Const; Const.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); //SetterListener proceed.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Function EndUserCreation = GetMainFunction(deg.getValue(), Float.parseFloat(Const.getText().toString()), SignReturner(ConstSign)); ((GlobalValues) getApplication()).SendToGlobal(EndUserCreation); Log.d("Function is :", EndUserCreation.toString()); setResult(1452); finish(); } }); }
From source file:hu.fnf.devel.atlas.Atlas.java
public void onMonthClick(View v) { AlertDialog.Builder picker = new AlertDialog.Builder(this); View pick = getLayoutInflater().inflate(R.layout.number_picker, null); Calendar now = new GregorianCalendar(TimeZone.getDefault()); String[] date = AtlasData.config.getString(AtlasData.CONFIG_DATE, "1900.01").split("\\."); NumberPicker y = (NumberPicker) pick.findViewById(R.id.yearpicker); y.setMaxValue(now.get(Calendar.YEAR)); y.setMinValue(1900); y.setValue(Integer.valueOf(date[0])); NumberPicker m = (NumberPicker) pick.findViewById(R.id.monthpicker); m.setMaxValue(12);// w w w . j av a 2s . c o m m.setMinValue(1); m.setValue(Integer.valueOf(date[1])); picker.setView(pick); dialog = picker.create(); dialog.show(); }
From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java
public void changeFrequency(View view) { // called from UI panel final AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this, R.style.AppCompatAlertDialogStyle); final View changeFrequencyAlert = getLayoutInflater().inflate(R.layout.activity_home_changefrequency, null, false);// w w w. ja v a2 s . c o m final NumberPicker numberPicker = (NumberPicker) changeFrequencyAlert.findViewById(R.id.numberPicker); final int frequency_sec = getUploadFrequencySec(); numberPicker.setMinValue(MIN_FREQUENCY_SEC); numberPicker.setMaxValue(MAX_FREQUENCY_SEC); numberPicker.setValue(frequency_sec); alertDialog.setView(changeFrequencyAlert); alertDialog.setCancelable(false).setTitle("Change the Frequency of Data Being Sent (in Seconds)") .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { final int value = numberPicker.getValue(); if (value != frequency_sec) { setUploadFrequencySec(value); startObdScan(); startPublishingProbeData(); } } }).setNegativeButton("Cancel", null).show(); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
public void TimeLapseDialog() { if (isRecording) return;//from w w w . j av a 2s . c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()); interval = Integer.valueOf(prefs.getString("timelapseInterval", "0")); measurementVal = Integer.valueOf(prefs.getString("timelapseMeasurementVal", "0")); // show time lapse settings timeLapseDialog = new TimeLapseDialog(ApplicationScreen.instance); timeLapseDialog.setContentView(R.layout.plugin_capture_video_timelapse_dialog); final NumberPicker np = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker1); np.setMaxValue(16); np.setMinValue(0); np.setValue(interval); np.setDisplayedValues(stringInterval); np.setWrapSelectorWheel(false); np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final NumberPicker np2 = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker2); np2.setMaxValue(2); np2.setMinValue(0); np2.setValue(measurementVal); np2.setWrapSelectorWheel(false); np2.setDisplayedValues(stringMeasurement); np2.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final Switch sw = (Switch) timeLapseDialog.findViewById(R.id.timelapse_switcher); // disable/enable controls in dialog sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!sw.isChecked()) { swChecked = false; } else { swChecked = true; } } }); np2.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); np.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); // disable control in dialog by default if (!swChecked) { sw.setChecked(false); } else { sw.setChecked(true); } timeLapseDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (swChecked) { measurementVal = np2.getValue(); interval = np.getValue(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ApplicationScreen.getMainContext()); Editor editor = prefs.edit(); editor.putString("timelapseMeasurementVal", String.valueOf(measurementVal)); editor.putString("timelapseInterval", String.valueOf(interval)); editor.commit(); timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_active)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } else { timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_inactive)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } } }); timeLapseDialog.show(); }
From source file:com.bt.heliniumstudentapp.GradesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) { mainContext = (AppCompatActivity) getActivity(); gradesLayout = inflater.inflate(R.layout.fragment_grades, viewGroup, false); boolean pass = true; if (gradesHtml == null) { termFocus = Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); yearFocus = 0;/*from w w w.jav a2 s. c o m*/ if (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("pref_general_class", "0")) == 0) { try { //TODO Improve maxYear = Integer.parseInt(((TextView) mainContext.findViewById(R.id.tv_class_hd)).getText() .toString().replaceAll("\\D+", "")); } catch (NumberFormatException e) { pass = false; MainActivity.drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true); MainActivity.FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); final AlertDialog.Builder classDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); classDialogBuilder.setTitle(R.string.error); classDialogBuilder.setMessage(R.string.error_class); classDialogBuilder.setCancelable(false); classDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mainContext.startActivity(new Intent(mainContext, SettingsActivity.class)); } }); classDialogBuilder.setNegativeButton(android.R.string.cancel, null); final AlertDialog classDialog = classDialogBuilder.create(); classDialog.setCanceledOnTouchOutside(false); classDialog.show(); classDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); classDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); } } else { maxYear = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("pref_general_class", "1")); } } if (pass) { MainActivity.setToolbarTitle(mainContext, getString(R.string.grades), null); gradesELV = (ExpandableListView) gradesLayout.findViewById(R.id.lv_course_fg); final boolean online = MainActivity.isOnline(); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) == null) { //TODO Simpler if (online) { getGrades(termFocus, HeliniumStudentApp.df_date().format(new Date()), HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else { //TODO Display empty GradesFragment with retry option Toast.makeText(mainContext, getString(R.string.database_no), Toast.LENGTH_SHORT).show(); MainActivity.drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true); MainActivity.FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); } } else if (online && gradesHtml == null && PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_grades_init", true)) { getGrades(termFocus, HeliniumStudentApp.df_date().format(new Date()), HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else { if (gradesHtml == null) gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null); if (online) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } ((SwipeRefreshLayout) gradesLayout).setColorSchemeResources(MainActivity.accentSecondaryColor, MainActivity.accentPrimaryColor, MainActivity.primaryColor); ((SwipeRefreshLayout) gradesLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); gradesELV.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { int previousPosition = -1; @Override public void onGroupExpand(int position) { if (position != previousPosition) gradesELV.collapseGroup(previousPosition); previousPosition = position; } }); gradesELV.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { //Just a little easter egg int clickCount = 1; @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int position, long id) { if (clickCount >= 80) { Toast.makeText(mainContext, "Is this what you wanted?", Toast.LENGTH_SHORT).show(); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://youtu.be/dQw4w9WgXcQ"))); } else { switch (clickCount) { case 2: Toast.makeText(mainContext, "Good for you!", Toast.LENGTH_SHORT).show(); break; case 10: Toast.makeText(mainContext, "You're really proud of that, aren't you?", Toast.LENGTH_SHORT).show(); break; case 20: Toast.makeText(mainContext, "It's really not that big of a deal...", Toast.LENGTH_SHORT) .show(); break; case 40: Toast.makeText(mainContext, "You can stop now.", Toast.LENGTH_SHORT).show(); break; case 50: Toast.makeText(mainContext, "Please...", Toast.LENGTH_SHORT).show(); case 60: Toast.makeText(mainContext, "F* OFF!", Toast.LENGTH_SHORT).show(); break; } } clickCount++; return false; } }); MainActivity.prevIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (MainActivity.isOnline()) { if (termFocus != 1) { termFocus--; getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus), HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE); } } else { final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null && yearFocus == 0 && termFocus > databaseFocus) { yearFocus = 0; termFocus = databaseFocus; gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.historyIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (MainActivity.isOnline()) { if (maxYear != 1) { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE); final AlertDialog.Builder gradesDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); final View gradesLayout = View.inflate(mainContext, R.layout.dialog_grades, null); gradesDialogBuilder.setTitle(getString(R.string.year, maxYear)); final NumberPicker yearNP = (NumberPicker) gradesLayout.findViewById(R.id.np_year_dg); gradesDialogBuilder.setView(gradesLayout); //TODO Listen for year change. gradesDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (MainActivity.isOnline()) { final int oldValue = yearFocus; yearFocus = yearNP.getValue() - maxYear; getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus), oldValue + HeliniumStudentApp.FOCUS_YEAR, HeliniumStudentApp.ACTION_REFRESH_IN); } else { Toast.makeText(mainContext, getString(R.string.error_conn_no), Toast.LENGTH_SHORT).show(); } } }); yearNP.setMinValue(1); yearNP.setMaxValue(maxYear); yearNP.setValue(maxYear); java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields(); for (java.lang.reflect.Field pf : pickerFields) { if (pf.getName().equals("mSelectionDivider")) { pf.setAccessible(true); try { pf.set(yearNP, new ColorDrawable(ContextCompat.getColor(mainContext, MainActivity.accentPrimaryColor))); } catch (IllegalArgumentException | IllegalAccessException ignored) { } break; /*} else if(pf.getName().equals("mSelectorWheelPaint")) { pf.setAccessible(true); try { ((Paint) pf.get(yearNP)) .setColor(getColor(MainActivity.themePrimaryTextColor)); } catch (IllegalArgumentException | IllegalAccessException ignored) {}*/ //FIXME Doesn't work... yet } else if (pf.getName().equals("mInputText")) { pf.setAccessible(true); try { ((EditText) pf.get(yearNP)).setTextColor(ContextCompat.getColor(mainContext, MainActivity.themePrimaryTextColor)); } catch (IllegalArgumentException | IllegalAccessException ignored) { } } } yearNP.invalidate(); gradesDialogBuilder.setNegativeButton(android.R.string.cancel, null); AlertDialog gradesDialog = gradesDialogBuilder.create(); gradesDialog.setCanceledOnTouchOutside(true); gradesDialog.show(); gradesDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor( ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); gradesDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor( ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); } } else { final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null && yearFocus != 0 || termFocus != databaseFocus) { yearFocus = 0; termFocus = databaseFocus; gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.nextIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (MainActivity.isOnline()) { if (termFocus != 4) { termFocus++; getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus), HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE); } } else { final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null && yearFocus == 0 && termFocus < databaseFocus) { yearFocus = 0; termFocus = databaseFocus; gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE); } } } }); } return gradesLayout; }