private void init() { setId(R.id.pathview); setLayoutParams(toolbarLayoutParams()); from(getContext()).inflate(R.layout.widget_pathview, this, true); mPathContainer = (PathHorizontalScrollView) findViewById(R.id.pathview_path_container); mButtonRight = findViewById(R.id.pathview_button_right); View buttonManualLeft = findViewById(R.id.pathview_manual_button_left); View buttonManualRight = findViewById(R.id.pathview_manual_button_right); mManualText = (EditText) findViewById(R.id.pathview_manual_text); mButtonRight.setOnClickListener(mSwitchToManualOnClickListener); buttonManualLeft.setOnClickListener(mCloseManualInputClickListener); buttonManualRight.setOnClickListener(mApplyManualInputClickListener); mManualText.setOnEditorActionListener(mOnEditorActionListener); mManualText.setCustomSelectionActionModeCallback(mEditorActionModeCallback); // XML doesn't always work mManualText.setInputType(TYPE_TEXT_VARIATION_URI | TYPE_TEXT_FLAG_NO_SUGGESTIONS); scheduleSetRightEdgeRangeListener(); // Setup CheatSheets setup(mButtonRight); setup(buttonManualRight); setup(buttonManualLeft); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // go full screen getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); supportRequestWindowFeature(Window.FEATURE_NO_TITLE); // requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); mHomeWatcher = new HomeWatcher(getApplicationContext()); mHomeWatcher.setOnHomePressedListener( new OnHomePressedListener() { @Override public void onHomePressed() { // home key is pressed... Toast.makeText(getApplicationContext(), "Not Suitable Button", Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(getApplicationContext(), MainActivity.class); finish(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); } @Override public void onHomeLongPressed() { // home key is Long pressed... Toast.makeText(getApplicationContext(), "Not Suitable Button", Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(getApplicationContext(), MainActivity.class); // make activity sleep a while and start again // SystemClock.sleep(2000);//3senconds // try { // Thread.sleep(3000); // } catch (InterruptedException e) { // e.printStackTrace(); // } finish(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); } }); mHomeWatcher.startWatch(); // pin box purify myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); pw = (EditText) findViewById(R.id.pw); pw.setTypeface(Typeface.DEFAULT); pw.setTransformationMethod(new PasswordTransformationMethod()); // disable softkeyboard imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(pw.getWindowToken(), 0); // Text copy and paste Solution for future use pw.setCustomSelectionActionModeCallback( new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case android.R.id.copy: int min = 0; int max = pw.getText().length(); if (pw.isFocused()) { final int selStart = pw.getSelectionStart(); final int selEnd = pw.getSelectionEnd(); min = Math.max(0, Math.min(selStart, selEnd)); max = Math.max(0, Math.max(selStart, selEnd)); } // Perform your definition lookup with the selected text final CharSequence selectedText = pw.getText().subSequence(min, max); String text = selectedText.toString(); myClip = ClipData.newPlainText("text", text); myClipboard.setPrimaryClip(myClip); Toast.makeText(getApplicationContext(), "Text Copied", Toast.LENGTH_SHORT).show(); // Finish and close the ActionMode mode.finish(); return true; case android.R.id.cut: // custom code to get cut functionality according // to customer requirement return true; case android.R.id.paste: // custom code to get paste functionality according // to customer requirement return true; default: break; } return false; } @Override public void onDestroyActionMode(ActionMode actionMode) {} }); // _______________________________________// // initialize views db = new DBHelper(getApplicationContext()); print = new PrintService(); pers = new PersonalSale(); try { db.truncateQueue(); db.truncateRec(); print.stopService(); PersonalSale personal = new PersonalSale(); Intent alarmIntent = new Intent(this, PrintService.class); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, 0); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); pers.killAlarm(pi, am); } catch (NullPointerException e) { e.printStackTrace(); } monitor = (TextView) findViewById(R.id.monitor); login = (Button) findViewById(R.id.login); login.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Starting login processing if (!pw.getText().toString().isEmpty()) { LoginAsync login = new LoginAsync(); String pin = pw.getText().toString(); login.execute(pin); // loginPro(pw.getText().toString()); } else monitor.setText("Empty Pin"); } }); }
public ActionBarMenuItem setIsSearchField(boolean value) { if (value && searchField == null) { searchField = new EditText(getContext()); searchField.setTextSize(18); searchField.setTextColor(0xffffffff); searchField.setSingleLine(true); searchField.setBackgroundResource(R.drawable.search_light_states); searchField.setPadding(0, 0, 0, 0); searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); if (android.os.Build.VERSION.SDK_INT < 11) { searchField.setOnCreateContextMenuListener( new OnCreateContextMenuListener() { public void onCreateContextMenu( ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { menu.clear(); } }); } else { searchField.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; } }); } searchField.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { AndroidUtilities.hideKeyboard(searchField); } return false; } }); searchField.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) { if (listener != null) { listener.onTextChanged(searchField); } } @Override public void afterTextChanged(Editable s) {} }); /* ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn); if (img != null) { img.setImageResource(R.drawable.ic_msg_btn_cross_custom); } */ try { Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.set(searchField, R.drawable.search_carret); } catch (Exception e) { // nothing to do } if (Build.VERSION.SDK_INT >= 11) { searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH); searchField.setTextIsSelectable(false); } else { searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH); } parentMenu.addView(searchField, 0); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) searchField.getLayoutParams(); layoutParams.weight = 1; layoutParams.width = 0; layoutParams.gravity = Gravity.CENTER_VERTICAL; layoutParams.height = AndroidUtilities.dp(36); layoutParams.rightMargin = AndroidUtilities.dp(22); layoutParams.leftMargin = AndroidUtilities.dp(6); searchField.setLayoutParams(layoutParams); searchField.setVisibility(GONE); } isSearchField = value; return this; }